aiaf Posted November 24, 2015 Posted November 24, 2015 Hello, Im trying to execute some code(in App Loop()) that updates my game objects every 5 seconds. I tried implementing a timer using functions from Time api, but i wasnt very succesfull. If someone have some code like this that works ill be happy to see. So i went on and used Leadwerks thread: Mutex *mutex = NULL; long Updater::tick = 0; Object* UpdateTick(Object* object) { while(1) { mutex->Lock(); Updater::tick++; System::Print("tick: " + String(Updater::tick)); mutex->Unlock(); Leadwerks::Time::Delay(5000); } return NULL; } Updater::Updater(std::vector<Unit *> *units) { this->units = units; mutex = Mutex::Create(); thread = Thread::Create(UpdateTick); } Is it possible to pass an custom object to the Thread EntryPoint ? static Thread* Create(Object* EntryPoint(Object* o), Object* o=NULL) Something like Thread::Create(UpdateTick, myObjectHere). I think im missing something, maybe is another way of dooing this. Thanks Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station
shadmar Posted November 24, 2015 Posted November 24, 2015 something like this would do the trick: In Start(): lasttime=0 In Loop(): if Time:GetCurrent()-5000>lasttime then lasttime=Time:GetCurrent() ...do stuff you want to happen every 5sec end 2 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.