Skip to main content
gamedev.net
🔒 Locked

Timer/Thread Question?

Started by NGN 5 replies 500+ views
Original Post
NGN
NGN
Hi everybody!!! I'm trying to develop an Simple RTS. I use OpenGL. Language: C++ Platform: Linux, but I want a portable game who can run or Linux and Windows. My problem: I have a Mage, this Mage can heal himself when he lost some HP by using some magic. At this point everything is ok. Now I want to limit the magic, when the Mage use the Heal Magic, this magic must be lock for 10 seconds. After 10 second if he want to use this magic again he can. And in this 10 second, I don want to application to be freeze, the Mage can attack, be attacked, etc... I'm not able to see if I'm better to use a Timer, run a loop in another thread and raise an event. So if anybody can help me on this point, it will be realy appreciated!!!! For your information I don know who to do portable Thread in C++. Thanks!!!!
SoulSpectre
SoulSpectre
why not just time stamp the magic use? If the character tries to use it again, check the current time against the time stamp stored.
kdogg
kdogg
I'm a very pro-thread programmer, but in this case i think SoulSpectre's advise is the best solution.
kdogg
kdogg
I see where you're coming from now on the multi-threaded theory. Still, for only one attribute that happens on a regular interval, it seems like it would be simpler to put a section in your game loop that will check the hit points to see if they're more than 50 points from the maximum and then check the last time heal was called, if necessary. If it gets to the point that you have hundreds of things timing out, then it might be worth it to create a dedicated timer thread, but you're looking at a lot of overhead to replace about 10 lines of code in your game loop if you're only checking if heal can be called again.

If you haven't done any multithreaded programming before, there's a strong possibility that you're using non thread safe functions in your code without even knowing it. Plus, it can be a little tricky to get linux threads running on a windows box. (It can be tricky to get windows threads running on a windows box, too.)
SoulSpectre
SoulSpectre
If the effect is automatic, you need a update method for your objects, each frame the update method for all your objects are called. Just have the update method perform the automatic effects.
NGN
NGN
Hi,

I think you're right! I will put it in game loop. For now I will not have a lot of automatic action like this. It will be faster for me to continue on the project.

I will still continue to check for Threading, and I will test it in a test project when I will have the time.

Thanks!!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.