Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alternative to GetTickCount
#26
The other game is the original Mirage Online Smile And yes, I'm applying this tutorial to the sucker as the code between MO 3.0.4 and MS are fairly similar at this stage Smile
Reply
#27
I used this, but removed it since I changed my timers/counters to work differently. Instead, I just added a check every server loop that :

if timeGetTime > LasttimeGetTime Then Unload Server

Works fine - a reset every that many days isn't going to hurt anyone, especially with a rebooting tool, and you don't have to double-up on all your counter sizes. :wink:
Reply
#28
Quote:So yeah.. It's an elusive little bug, and 4 extra bytes for the 7 or so timers that are required.. (Someone help me here.. not sure about the number of timers in MS servers..) But I don't think 28 extra bytes hurts much.. (Just my humble opinion)

Yeah thats not a problem at all, but I use tons of timers for the characters and base the timers off of at what tick they will end, not how long they last and gradually decrease them (prevents having to constantly modify the values and can maintain accuracy).

I'm having a hard time seeing why it would continue to cause a problem after it rolls over... you know why it happens or have any general idea what could cause it? My only guess is the timer system described above that I avoid using, but that should be fixed just by resetting the server itself... *shrugs*
Reply
#29
Okay, I don't know why the hell I didn't think of this earlier. It just randomly came to me a while ago. Hope you like it, Verrigan. :wink:

Basically, this wrapper will take all the pros of this system and eliminate most all of the cons (adds slight overhead, but hardly anything to worry about). What you do is make one call to initialize it, which will create an offset value that will allow your program to start at the smallest signed 32-bit value (which is -(2^31)), or a VB Long.

This doesn't let you run your program for an ungodly amount of time like what Verrigan posted does, but it will let your program run for 2 ^ 32 milliseconds (about 50 days). So you have a roll-over time of your program being up for 50 days, not the computer being on for 25 days.

Demo project:

Code:
Private GetSystemTimeOffset As Currency
Private Declare Sub GetSystemTime Lib "KERNEL32.DLL" Alias "GetSystemTimeAsFileTime" (ByRef lpSystemTimeAsFileTime As Currency)

Private Sub InitGetTickCount()

    'Get the initial time
    GetSystemTime GetSystemTimeOffset
    GetSystemTimeOffset = (GetSystemTimeOffset + (2 ^ 31)) -1

End Sub

Private Function GetTickCount() As Long
Dim CurrentTime As Currency

    'Return the system time as a long
    GetSystemTime CurrentTime
    GetTickCount = CurrentTime - GetSystemTimeOffset

End Function

Private Sub Form_Load()

    InitGetTickCount
    Me.Show
    Do
        Me.Caption = GetTickCount
        DoEvents
    Loop While Me.WindowState = 0
    Unload Me
    End

End Sub

I do a quick -1 on the init up there just in case rounding takes a turn for the worst and creates an overflow. I don't think you'll be sad about loosing 1 millisecond. :wink:

Pros:
- Retain 32-bit timers (not as widely used in MS, but if you use Time Based Modeling you will have a timer for just about everything)
- Based on the application's time running, not the computer's (although still, the 64-bit timer would've probably never rolled over)

Cons:
- Slightly more overhead (about 10% slower, but its so fast as it is in the first place)

To be honest, I can't remember how much MS uses tickcount-based timers (ie timers that count based on the system's tick count, not by "counting down"), but I believe it is quite minimal, so this may not benefit MS greatly, but I'm sure some people will find use for it. Big Grin
Reply
#30
Had a quick read through, but if anyone adds this you will need to convert anything you save as gettickcount to currency.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#31
Actually, this is in FPO, I think all you had to do was define one thing as currency and then change all the gettickcount calls. It works though, so w/e.
Reply
#32
I have to disagree.

Trying to push a currency value into a long is gonna hurt.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#33
Robin Wrote:I have to disagree.

Trying to push a currency value into a long is gonna hurt.

I'll check my source later, but I have this 100% on the server working, and I think I only changed a few things to currency..

I forget. Oh well. It's been forever since I added it. I could be wrong, my memory isn't the best.
Reply
#34
OMG! Verrigan lives! xD

Yeah, it was tested successfully on FPO back when Shan was hosting the server. His machine had been up way too long with no restart and all non-admin characters were getting booted for packet flooding. I told Verrigan about it, and he asked me to add this to test his theory, and luckily his theory was correct and it stopped the booting.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)