Jump to content
The Dark Mod Forums

Recommended Posts

Posted

Hi,

I have noticed in the scripts many instances of waitFrame() were replaced at some point with wait(0.0166667).

Is waitFrame() reliable or should we better use wait(0.0166667) for some reason?

Many thanks in advance.

TDM_Modpack_Thumb.png

Posted

Used to be capped at 60 fps, so a frame was a known amount of time, or a reasonable amount of time at it's fastest rendering speed.

Now that we're uncapped, it could be muuuuch shorter. Too short.

That's my guess.

  • Like 3

I always assumed I'd taste like boot leather.

 

Posted

If Im not mistaken, sys.wait() works by checking every frame whether time elapsed > wait time. 0.01667 seems like a risky wait duration because if your frames are i.e. 0.0160s long the engine would presumably wait 0.0320s because that's the first check where time is greater than 0.01667. So your 60 fps script becomes something like 31 fps.

  • 2 years later...
Posted

Can anybody explain what is going on here?

Download the script attached to this post and place it in script/tdm_user_addons_tic_test.script

Script contents:

void user_addon_init_tic_test()
{
    float waitTime = sys.getTime() + 0.5;

    while (1)
    {
        if (sys.getTime() >= waitTime)
        {
            sys.println(waitTime - sys.getTime());
            waitTime = sys.getTime() + 0.5;
        }

        sys.waitFrame();
    }
}
  • Launch any mission
  • Check the console
  • Switch Uncap FPS On and Off and/or toy with the Max FPS
  • Go back to the mission and check the console

Can you see how the output varies greatly depending on the setting? I didn't expect a perfect zero every time by any means but since we are putting "time" to the test and not "frames" I expected consistent outputs regardless of the FPS settings.

This is what getTime() does in the source code:

void idThread::Event_GetTime( void ) {
	ReturnFloat( MS2SEC( gameLocal.realClientTime ) );
}

tdm_user_addons_tic_test.script

TDM_Modpack_Thumb.png

Posted

This is how wait() cascades in the source code:

void idThread::Event_Wait( float time ) {
	WaitSec( time );
}

void idThread::WaitSec( float time ) {
	WaitMS( SEC2MS( time ) );
}

void idThread::WaitMS( int time ) {
	Pause();
	waitingUntil = gameLocal.time + time;
}

realClientTime from getTime() and time from wait() seems to be the same at a point in Game_local:

// update the game time
framenum++;
previousTime = time;
time += idMath::Imax(int(timestepMs * g_timeModifier.GetFloat()), 1);
realClientTime = time;
this->minorTic = minorTic;

Therefore both getTime() and wait() are not reliable, at least, for precise timed events.

I truly hope someone makes me look like a fool! I don't want any of this to be true.

TDM_Modpack_Thumb.png

Posted

Thanks nbohr1more! It all is in there.

We are moving from:

  • (2.12) Vertical Sync No and Uncap FPS Off

to:

  • (2.13) Vertical Sync Yes and Uncap FPS On.

I don't personally care to be honest, but it is worth noting players will soon get marginal differences depending on their setup. It would be nice to measure 2.12 (capped 60fps) vs 2.13 (uncapped 300fps).

TDM_Modpack_Thumb.png

Posted

You cannot make engine do something at exact time moment.
But you can measure time with pretty good precision, at least up to millisecond of gameplay time.

I think if you do waitTime(0.5), then the script will resume at the first frame which happens after at least half a second passes. You never know how much later it will be. Without uncapped FPS it can be up to 16 ms later, with uncapped FPS the delay can be a bit more. This is already as good as it can be, because the engine certainly won't generate more game ticks just because your script wants to resume exactly after 0.5 seconds.

On the other hand, it is probably not a good idea to do something like this:

float deltaTime = 0.0;
while (???) {
   sys.wait(0.03);
   deltaTime += 0.03;
}

Because the error from repeated waits will accumulate.

But you can do something like this instead:

float deltaTime = 0.0;
float startTime = sys.getTime();
while (???) {
   sys.wait(0.03);
   deltaTime = sys.getTime() - startTime;
}

Here the error will no accumulate. At the moment when the script executes, deltaTime is exactly the amount of game time passed since start. And when the script waits, it can be off by at most (0.03 + game tick duration).

P.S. I did not check any of these statements, it's just how I understand the system.

Posted

Depending of course on the contest the way I see it is that if you use waitFrame() for, in example an animation, players with 300 FPS will get a faster animation than players with 60 FPS. If you however use wait(0.01667) all players will roughly get a similar speed (4% slower at 300 FPS according to the wiki).

As explained by stgatilov, problems can arise when wait(0.01667) accumulates and the code doesn't account for the extra delay. In example, I don't know, a wrongly setup tick of a clock.

  • Thanks 1

TDM_Modpack_Thumb.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • Goblin of Akenash

      Another goblin secrets episode on the way with the new update
      Focuses are:
      supporting 100% runs on shadow playstyles
      fixing the softlock
      and a tiny visual upgrade

      · 0 replies
    • STiFU

      Sorry for not being around enough lately. I am extremely busy at the moment. We are trying to build a home and the German bureaucracy is killing me! Meanwhile, child number 2 is underway. 🙂
      · 0 replies
    • cvlw

      Yo TDMers.
      It has been a while.  This past year or so I have encountered some tough family issues, became a grandfather, had a job change, and then Steam offered Dishonored and Dishonored 2 along with all DLC for like 5 dollars.  So... have played that.  What a game; highly recommend.
      I am looking to resume TDM activity soon.
      Clint
      · 2 replies
    • Airship-Ballet

      If anyone would like some ambient sounds for any of their work please do hit me up - I've tons of strings both physical and sampled that I love making loops with
      · 2 replies
×
×
  • Create New...