GetTime()
Is there a more precise function GetTime ()?
When I call GetTime () every millisecond, I don't get the exact time, about 5-10 milliseconds are wasted. Rather, GetTime () returns the same value several times, and then immediately returns + 5-10 milliseconds. .888 .888 .888 .891 .892 .893 .893 .893 etc |
Code:
GetTime() - GetTickTime() Code:
debugprofilestop() Why do you need such precision? |
To answer the question directly, GetTime() is cached at the start of every frame.
PS: Be careful if you use debugprofilestop(). The number resets if anyone runs debugprofilestart(). |
I want to organize the work of a loop with a dynamic load on the frame. To avoid stuttering when working with the "for" operator. For this, it is desirable to have accurate data.
|
Quote:
|
Quote:
|
|
There is such code:
Lua Code:
But it does not work as expected. Assault GetTime() returns always the same value inside the frame. Later try to check using "anim:SetScript("OnLoop", ...)", he seems to have no such restrictions. |
This is what I've come up with.
Lua Code:
Usage: AsyncPairs(Table, Limit, OnIterate[, OnFinish]) Limit is in milliseconds. OnIterate and OnFinish are callbacks with the later being optional. |
If I understood correctly "Debug profiling" works constantly. debugprofilestop () just returns its running time?
|
@SDPhantom thanks for xpcall, never used such a useful feature before :). And also does not eat up performance.
I decided to abandon OnUpdate in favor of C_Timer, it turned out to be a little cheaper. In addition to this, you can run multiple loops in parallel and they work great. Possibly the engine runs them in different threads, since the load does not grow proportionally. And thanks to the inversely proportional dependence on the delta-time of the frame, work on a system of different performance is simply excellent.:banana: Probably we still need to work on smoothing the start. With very high productivity, you can get a noticeable drawdown, which is different from the working one. |
If you don't mind use a lib, you may check the example for Continue() in the Scorpio - asynchronous framework, the async frame work is designed to smooth the operation of codes and make the fps stable.
The async framework is also designed based on the debugprofilestop. The lib can be used as an API lib, works like : Lua Code:
I prefer the Lua's coroutine compares to the callback since the logic can be put together |
Quote:
Based on my practice, beautiful code in most cases ~= fast code. :) |
Quote:
I. The cost of the coroutine's creation is much bigger than call a function, so I build a thread pool to re-use them, you may check the PLoop/Threading.lua#L53-L135, that's an example how to build a thread pool in Lua(Normally people do this in C part, the logic is a little complex). I use __Async__ to wrap the functions, so they can be processed in re-used coroutines. II. The cost of the coroutine context's switch, the cost is tiny but I can't say that can be ignored, it's a price for putting the logic together. For async codes, they are processed in several phases, that's why I build a framework for them, I use a task schedule manager to control all those async tasks, so the process can be seperated into several phases without dropping the fps. So I don't try to reduce the corotuine's switch cost since I can do nothing about it, I just manage the time slice of async tasks to make the game smooth. And that's what can't be done with normal Lua functions, since we can't yield/resume them. For daily works, the main reason of using coroutines is to avoid the callbacks, but for now the callback mechanism is more popular in the WOW, since most logic is not that complex compares to daily works. And it's a really hard job to make an useful coroutine framework. For me, the beauty and readability is important, and some useful mechanism can be bring in like get user input directly Scorpio the-user-interaction-apis and much more. |
Quote:
The idea of these two functions is a misnomer. There isn't some "profiling" code behind them. One stores the current time in memory and the other compares that with the current time. Quote:
Quote:
A general rule of thumb I follow. OnUpdate when you have a long task that you need to spread out over time. C_Timer when you have a small task that needs to be repeated, but not as frequent. Quote:
What a coroutine does is lets you pause execution of its assigned function and resume it later. Its more specialized use is for multi-stage functions that have a list of multiple heavy purpose tasks you want to spread over time. |
All times are GMT -6. The time now is 06:11 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI