🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Pausing parsing

Started by
5 comments, last by Salec 21 years ago
I have two functions which require the parsing of scripts to be delayed. The function wait(time) should pause parsing the script for specified time while the game loop remains running (all effects such as fades continue). Another function, delay(time), will do the same however the game loop is pauses as well (everything stops). My question is how can I pause the parsing of a script block? I''ve looked through the docs and haven''t been able to find anything. Any advice would be appreciated.
Advertisement
If you parse the script one line at a time through every iteration of the game loop (I don''t know if you do this). A good function to use is

#include <time.h>

unsigned int TimeToPause;

unsinged int AmountToPause; //in milliseconds

int main()
{
TimeToPause = GetTickCount() + AmountToPause;
while (1)
{
if (GetTickCount() >= TimeToPause)
//statements to be runned after the pause

//other statements to process
}
return 1;
}

Hope this helps
Right now I do the entire code for whatever user defined function that gets called when an event is fired. I do this instead of once an iteration because there is alot of simple code that takes up close to no time at all (most of it is just modifying variables) so i don''t see a point in running one statement per frame when I can call all of them and have no difference in speed but rather be done parsing and free up that memory.
quote: Original post by Salec
I have two functions which require the parsing of scripts to be delayed. The function wait(time) should pause parsing the script for specified time while the game loop remains running (all effects such as fades continue). Another function, delay(time), will do the same however the game loop is pauses as well (everything stops). My question is how can I pause the parsing of a script block? I''ve looked through the docs and haven''t been able to find anything. Any advice would be appreciated.

Um, which docs? What scripting and programming languages are you using, and in what context?



[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]
That would be helpful wouldn''t it. lol. The scripting language i''m using is Lua 5.0. You can get information as well as documentation at www.lua.org
You''ll perhaps want to use the yield keyword and the coroutine support, I expect. The return values from yield could be the time to wait before you call resume on that coroutine.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]
coroutines are the way to go. It's not exactly simple, but it's working:

function LuaStartThread( Func )  if ( Func == nil ) then    return 1;  end  co_event = coroutine.create( Func );  local rresult, second_value = coroutine.resume( co_event, 0 );  if ( second_value == nil ) then    -- Thread done    co_event = nil;    return 1;  end  return 0;end-- Continueing a suspended scriptfunction LuaContinueThread( co_event, ElapsedTime )  local result, second_value = coroutine.resume( co_event, ElapsedTime );  if ( second_value == nil ) then    -- Thread done	co_event = nil;    return 1;  end  return 0;end-- Wait, has to be called from a script which was started via LuaStartThreadfunction Wait( Ticks )  co_ElapsedTicks = 0;  while ( co_ElapsedTicks < Ticks ) do    local  Result = coroutine.yield( Ticks );    co_ElapsedTicks = co_ElapsedTicks + Result;  end  co_ElapsedTicks = co_ElapsedTicks - Ticks;end 


[edited by - Endurion on June 25, 2003 10:24:40 AM]

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement