Server Help

ASSS Questions - Time

Hakaku - Thu Jul 10, 2008 1:42 pm
Post subject: Time
Alright, so I'm not too familiar with how to work time in ASSS. Basically, what I want to do, is start a timer (not a countdown one) when a race begins, then display the time once Player X enters a region (i.e. finish line or checkpoint) and then stop the timer.

To put this into context, I want to implement this into a simple race module which has already been outlined, I would just like to know how to create a timer that would display a player's result.
Bak - Fri Jul 11, 2008 10:31 am
Post subject:
you don't need to start a timer, just record the time when the race begins, record the time when the player enters the finish line region and subtract.

there's an enter region callback, although you'll want to tweak with the settings to make it check on every position packet instead of every second (probably better off making the finish line a safe zone so the client will send a packet as soon as he enters)
Hakaku - Fri Jul 11, 2008 12:17 pm
Post subject:
Ok, then how do I record the time when the race begins and ends?
Bak - Sat Jul 12, 2008 12:06 am
Post subject:
just like you would in any other program: GetTickCount on windows gettimeofday on linux
Dr Brain - Sat Jul 12, 2008 11:19 am
Post subject:
No, use ASSS's current_ticks(). It's in util.h.
Dr Brain - Sat Jul 12, 2008 11:22 am
Post subject:
Bak wrote:
(probably better off making the finish line a safe zone so the client will send a packet as soon as he enters)


By the way, that's not exactly what happens. All it means is the next packet will be reliable, not that it's send immediately. I used to use safe zones for all the warps in hyperspace but found that I didn't get any better results than not using safeties, for that reason.
D1st0rt - Sat Jul 12, 2008 12:05 pm
Post subject:
Here's the relevant portion from the (albeit old, I might not do it the same way if I was writing it now but it works) Hyperspace Racing module:
Code: Show/Hide
local void posUpdate(Player *p, byte *data, int len)

{

   race_pdata *rpd;

   struct C2SPosition *pos = (struct C2SPosition *)data;

   race_adata *ad = P_ARENA_DATA(p->arena, adkey);

   rpd = PPDATA(p, pdkey);



   if (p->arena == NULL)

      return;



   if (ad->status <= READY)

      return;



   if (rpd->status == PRE_CHECKPOINT)

   {

      if(checkPos(CHECKPOINT, pos->x >> 4, pos->y >> 4))

      {

         long dT = current_millis() - ad->startTime;

         checkPoint(p, dT);

      }

   }

   else if (rpd->status == POST_CHECKPOINT)

   {

      if(checkPos(FINISH, pos->x >> 4, pos->y >> 4))

      {

         long dT = current_millis() - ad->startTime;

         addFinish(p, dT);

      }

   }

}



local int checkPos(int loc,int x, int y)

{

   switch(loc)

   {

      case CHECKPOINT:

         return (abs(x - 506) < 20) && y > 655;

      break;

      case FINISH:

         return (abs(x - 506) < 20) && y < 361;

      break;

   }

   return 0;

}


where PosUpdate is the callback from Net->AddPacket
Bak - Sat Jul 12, 2008 2:25 pm
Post subject:
all current_ticks does is call GetTickCount or gettimeofday... cut out the middle man
Dr Brain - Sat Jul 12, 2008 4:00 pm
Post subject:
Bak wrote:
all current_ticks does is call GetTickCount or gettimeofday... cut out the middle man


And make the code harder to port? Why bother? The efficiency of one function call isn't relevant, and current_ticks() has the added advantage of being the compatible with all the position packet times.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group