Jump to content

Recommended Posts

Posted

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

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Posted

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

  • Upvote 2

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

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.

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.

×
×
  • Create New...