Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: strange behaviour if the Sleep function  (Read 3543 times)

0 Members and 1 Guest are viewing this topic.

Akusa

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 46
    • View Profile
strange behaviour if the Sleep function
« on: February 10, 2009, 12:15:15 PM »

hi, i discovered yesterday a strange behaviour of my sleep function.
Till yesterday, this code worked correctly:

Code: [Select]
method ShowPort(PortraitName, Place, Slide)
{
if (loc_Portrait!=null)
{
Game.UnloadObject(loc_Portrait);
}
if ((Place != 1) && (Place != 2) && (Place != 3))
{
Place = 2;
}
loc_Portrait = Game.LoadWindow("windows\Portrait.window");
loc_Picture = loc_Portrait.GetControl("Picture");
loc_Picture.Text = "IM ACTIVE!";
loc_Picture.SetImage(PortraitName);
NO_CONTROL = true;
if (Slide == true)
{
if (Place == 1)
{
for (var j=0; j<128; j=j+1)
{
loc_Portrait.SkipTo(-256+(4*j), 768);
Sleep(2);
}
}
if (Place == 2)
{
loc_Portrait.SkipTo(512, 768);
}
if (Place == 3)
{
for (var i=0; i<128; i=i+1)
{
loc_Portrait.SkipTo(1290-(4*i), 768);
Sleep(2);
}
}
}
NO_CONTROL = false;
}

But since yesterday my sleep function doesn't work correct anymore. As you maybe see, this script changes the position of the window every 2 milliseconds 128 times. strangely this worked till yesterday but now it looks like i can enter any low sleep values but it always takes arround 2-3 seconds for this loop to complete. using larger values are working fine, for example 1000ms but it looks like it doesnt matter if i say Sleep(2) or Sleep(15).....  :-\

[EDIT:] Strangly enough, after i posted it, i tryed it a second time and now it works again. But then i closed the Wintermute Project Manager, and now the problem returned ???
« Last Edit: February 10, 2009, 12:33:59 PM by Akusa »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: strange behaviour if the Sleep function
« Reply #1 on: February 10, 2009, 01:03:35 PM »

Scripts are updated in every frame. So for example if your game runs at 60 FPS, they are updated approximately every 16 milliseconds. For that reason using smaller sleep values isn't recommended and will give you results dependant on framerate, which is a bad thing(tm).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Akusa

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 46
    • View Profile
Re: strange behaviour if the Sleep function
« Reply #2 on: February 10, 2009, 03:13:01 PM »

Hm... this interesting.

but I'm testing my game in window mode and it runs at 2200-2300fps, so such huge slowdowns with the Sleep-function shouldn't really happen at all at this rate. Also i find it strange that sometimes it work and sometimes it does not.
but a artificial 60fps limitation (maybe the graphic driver) could really be the problem, 16ms x 128 are around 2,1 seconds, and its more or less the time the window needs to move.

Maybe you should write into the documentation that Sleep() is framerate dependent?

But anyway good to know, now i have to think about a possible solution. But on the other hand its not really gameplay relative and i already found a big bug that could happen during the animation and it was only an eyecandy, so if i can't find a solution, its not a real problem.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: strange behaviour if the Sleep function
« Reply #3 on: February 10, 2009, 03:26:16 PM »

Well, Sleep is not framerate dependent. But if you use too little values (which you shouldn't do in any case), the engine doesn't have a chance to execute the code after Sleep early enough.
That's because of how the scripting system works. Sleep temporarily freezes the script until next update (i.e. next frame).

So, Sleep is not framerate dependant in general, but the minimal recognizable time is.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.032 seconds with 18 queries.