Jump to content
Sign in to follow this  
mind

Execution based on time instead of frame rate

Recommended Posts

Dear BI community,

Fellow brothers-in-script! Your wisdom and intelligence is needed, to cast light on subject below.

Consider following code:

_func = {
for "_i" from 0 to 100 do {
	_t1 = diag_tickTime;
		sleep 0.2;
	_t2 = diag_tickTime;
	systemChat str (_t2 - _t1);
};
};
[] spawn _func;

This code indicates (by writing to system chat), the real time took by sleep command to finish.

If you would be so kind to try it out, you would notice HUGE differences between results,

This spikes can be seen when FPS changes dramatically. from 50 to 20 for example.

While FPS is stable, sleep working almost ideal.

it sometimes may take slightly less time and sometimes 5x more time to finish.

This is of course completely understandable, because of scheduled script execution mechanism arma have.

Now comes the question.

How one would get execution of script with PRECISE timing, from scheduled environment? Without any relation to current FPS.

I tried monitoring diag_tickTime, and fire event regularly with this kind of code

_func = {
for "_i" from 0 to 100 do {
	_time = diag_tickTime;
	_wait = 1;
	_t1 = diag_tickTime;
	waitUntil {diag_tickTime > (_time + _wait)};
	_t2 = diag_tickTime;
	systemChat str (_t2 - _t1);
};
};
[] spawn _func;

And it has slightly better results. But still way not perfect.

Peace. mind out.

P.S. I noticed some clues from KK blog regarding execFSM, does anyone know if it has any relation to topic?

Edited by mind

Share this post


Link to post
Share on other sites

What are you trying to do? Are you trying to synchronize script execution between all clients? Are you trying to run a script exactly at a certain time? (ie. when client has played for 5 mins run "myScript.sqf")

The easiest/best way I can think to do this is to addpublicVariableEventHandler to all clients, then publicVariable your variable from server. Near perfect sync

Share this post


Link to post
Share on other sites

Thank you for your answer DreadedEntity,

Such thing might be used in many ways. I am talking about, incorrect (IMHO) execution of sleep commands, where you are unable to offset frame rate impact on execution speed. And as result sleep command takes longer than it should.

Regarding eventHandlers, they of course useful, but not always. For example, i am making free roam camera where i camSetPos every 0.1 secs. eventHandler can’t make sure camSetPos will execute exactly once per 0.1 sec.

P.S. In unity there is following method "time.deltaTime" to offset FPS impact. Is there anything like that in ARMA, maybe some nasty workaround...

Edited by mind
added P.S.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×