GetTickCount wrapping after 24.8 days
#1

What's the reasoning behind this change? I assume the most common use of GetTickCount is to find the time between two events, but this change will break that functionality. For example if two times are 5 seconds (5000ms) apart, it doesn't matter if the numbers are (if interpreted as signed) negative or positive, subtracting the first from the second will give 5000.
For example:
pawn Код:
new first = 0x7FFFF05F,
        second = 0x800003E7;

    printf("Signed operation\n\t%i - %i = %i", second, first, second - first);
    printf("Unsigned operation\n\t%s - %s = %s", ustr(Unsigned:second), ustr(Unsigned:first), ustr(usub(Unsigned:second, Unsigned:first)));
gives
Quote:

[16:16:13] Signed operation
-2147482649 - 2147479647 = 5000
[16:16:13] Unsigned operation
2147484647 - 2147479647 = 5000

If the times wrap from 0 to cellmax however, it's possible to get two times which are 5 seconds apart which, when subtracted, give a large negative value.
For example:
pawn Код:
new first = 0x7FFFF05F,
        second = 0x000003E8;

    printf("%i - %i = %i", second, first, second - first);
gives
Quote:

1000 - 2147479647 = -2147478647

Reply
#2

The reason for it is that the millisecond timer returned by GetTickCount is the same timer synced between the server, the clients and GTA. This timer is used to sync things like traffic lights and wave heights etc. Unfortunately, SA is not designed to deal with a negative timer value and problems start to arise such as the one with the cinematic camera.

I agree though it's not very desirable for it to wrap to 0 and I will probably have to find another solution.
Reply
#3

Well lets say that most of servers usually are not up for 24.8 days. Its just to make sure and it doesnt matter that much . If your server really was online for e.g. 50 days - you wouldnt mind if something went wrong twice during that time period, would you ?
Reply
#4

Quote:
Originally Posted by Rainmaker
Well lets say that most of servers usually are not up for 24.8 days. Its just to make sure and it doesnt matter that much . If your server really was online for e.g. 50 days - you wouldnt mind if something went wrong twice during that time period, would you ?
He asked, so I guess he would mind.
Reply
#5

Quote:
Originally Posted by Rainmaker
If your server really was online for e.g. 50 days - you wouldnt mind if something went wrong twice during that time period, would you ?
It's about efficiency.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)