Author |
Message |
Hakaku Server Help Squatter

Joined: Apr 07 2006 Posts: 299 Location: Canada Offline
|
Posted: 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. |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: 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) _________________ SubSpace Discretion: A Third Generation SubSpace Client |
|
Back to top |
|
 |
Hakaku Server Help Squatter

Joined: Apr 07 2006 Posts: 299 Location: Canada Offline
|
Posted: Fri Jul 11, 2008 12:17 pm Post subject: |
 |
|
|
|
Ok, then how do I record the time when the race begins and ends? |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sat Jul 12, 2008 12:06 am Post subject: |
 |
|
|
|
just like you would in any other program: GetTickCount on windows gettimeofday on linux |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sat Jul 12, 2008 11:19 am Post subject: |
 |
|
|
|
No, use ASSS's current_ticks(). It's in util.h. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: 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. |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: 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:
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 _________________
 |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sat Jul 12, 2008 2:25 pm Post subject: |
 |
|
|
|
all current_ticks does is call GetTickCount or gettimeofday... cut out the middle man |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: 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. |
|
Back to top |
|
 |
|