Author |
Message |
Quan Chi2 Member of "Sexy Teenagers that Code" Group

Age:34 Gender: Joined: Mar 25 2005 Posts: 860 Location: NYC Offline
|
Posted: Fri Nov 25, 2005 8:26 am Post subject: What is EVENT_Tick in spawn.cpp? |
 |
|
|
|
What is it? What is EVENT_Tick? |
|
Back to top |
|
 |
Solo Ace Yeah, I'm in touch with reality...we correspond from time to time.

Age:37 Gender: Joined: Feb 06 2004 Posts: 2583 Location: The Netherlands Offline
|
Posted: Fri Nov 25, 2005 9:21 am Post subject: |
 |
|
|
|
It's used for "ticking" a player in the playerlist.
No, just kidding.
EVENT_Tick is an event "called" every... milisecond?
You can time for multiple events in it, just search the forums or check Underlord's tutorial. |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Fri Nov 25, 2005 9:31 am Post subject: |
 |
|
|
|
I thought it was every second. But it has been years since I've worked with MERV. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
Quan Chi2 Member of "Sexy Teenagers that Code" Group

Age:34 Gender: Joined: Mar 25 2005 Posts: 860 Location: NYC Offline
|
Posted: Fri Nov 25, 2005 10:18 am Post subject: |
 |
|
|
|
How would I make my plugin return to the arena that I did a command in?
like
i do
if(c->check("arenago"))
{
String Destination = c->final;
tell(makeChangeArena(Destination));
}
then i want it to come right back. What would I do then? |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Nov 25, 2005 10:44 am Post subject: |
 |
|
|
|
It's every second. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
Bjorn Novice
Joined: Apr 27 2004 Posts: 45 Offline
|
Posted: Fri Nov 25, 2005 1:34 pm Post subject: |
 |
|
|
|
It's every second and i'd also like to add that dont use this event to do any precise measurements of time since it will often be off by quite abit after awhile. |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sat Nov 26, 2005 2:31 pm Post subject: |
 |
|
|
|
why will it be "off by quite abit after awhile" ? |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Sat Nov 26, 2005 6:10 pm Post subject: |
 |
|
|
|
Bjorn wrote: | It's every second and i'd also like to add that dont use this event to do any precise measurements of time since it will often be off by quite abit after awhile. |
Bak wrote: | why will it be "off by quite abit after awhile" ? |
I am going to reply to this, but will do so in the context of Powerbot since I don't know how Merv does it.
Powerbot sends a TICK event to all modules at no more than once every 100ms. So if you need to check something "often", you can do so in response to this event. If you only need to check something "about once every second", you could count off 10 TICK events.
Inside the core, I am in a tight loop doing all the things the core needs to do (network recv/send, reliability layer, various module events). Each bot has its own thread, and to keep the threads from using 100% CPU when there's nothing happening, I call Sleep(5). This is sufficient to bring CPU usage down to 0% even with 20 bots with 10 modules each.
So why can't you count, say, 100 TICK events to get 10 seconds? Because any given thread (or process) is not guaranteed to get processing time, and also because Sleep(5) guarantees that you will NOT get back in for 5ms, but does not guarantee that it will not be longer. In fact under XP, I believe, that the foreground thread runs for 40ms before being interrupted (unless it gives up the slice by calling Sleep/Wait/GetMessage/etc), and a background thread runs for 20ms. So each TICK event might actually take 120ms, making 100 of them be more like 12 seconds.
So, if you need a very accurate 2500ms, for example, then you should (in Powerbot) use the TICK event, check GetTickCount() for yourself based on when the time interval started. You would get an accuracy between 2500 and 2600ms plus any delay caused by other processes. If you needed MUCH more accuracy than that, then you would need to create your own thread and call GetTickCount() very often to see when your interval had passed. However, you would probably then still need to sync up with the bot's thread, which would add 100+ms of sync time into the mix. Therefore it would not be worth it.
FYI: The Powerbot core also has a timer function. You can call SetTimer(t) and you wil get a TIMER event at t (or greater) ms in the future. The timer functionality is only as accurate as the TICK accuracy, but it's a little more convenient when you need lots of timed events. _________________ 4,691 irradiated haggis! |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sat Nov 26, 2005 9:39 pm Post subject: |
 |
|
|
|
That's reasonable, looks like that's how MERVBot does it too.
Uint32 time = getTime();
...
if (time - lastTick >= 100)
{
lastTick = time;
imports->talk(makeTick());
} |
Uint32 getTime()
{
return GetTickCount() / 10;
} |
If one wanted more accuracy (but possibly more than one tick per second on some instances) we could do:
if (time - lastTick >= 100)
{
lastTick += 100;
imports->talk(makeTick());
} |
This assumes lastTick is initialized properly. |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Sun Nov 27, 2005 2:22 am Post subject: |
 |
|
|
|
It's like if the bots are in a race. The starting gun is fired, but they probably won't start simultaneously with the gun because of the reaction time required to recognize that it is time to start and then actually start. _________________
 |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Sun Nov 27, 2005 2:13 pm Post subject: |
 |
|
|
|
Uhhh, thanks for the analogy. |
|
Back to top |
|
 |
|