Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[ALL]Fix TickCount initialization


Growlith1223
 Share

Recommended Posts

In normal versions of Eclipse(for those who have no idea what im talking about, the engine uses GetTickCount directly instead of checking to see if the value is = to or < than 0) the Tick value can go lower than 0 and cause the engine to crash from Longs not being able to use negative values.
To fix this it's rather simple, and I'll show you how! :D

OK, so first thing you should do is decide to use timeGetTime instead because it will last longer, and its more accurate.

the next thing you should do is go into where you have your server/client loop and copy/paste this in:
```
Public Function GetTick() As Long

    Const MAX_INT As Long = 2147483647

    If GetTickCount < 0 Then
        GetTick = MAX_INT + GetTickCount
    Else
    GetTick = GetTickCount
    End If

End Function

```
after that, go into said loop and find where it says Tick = GetTickCount. and change that GetTickCount to just GetTick!
you're for the most part done, you will have to find all the areas that are calling GetTickCount and change it to that GetTick function! this will ensure the value is ALWAYS a positive value to ensure that it won't error after a long host(keeping the server up for days would eventually crash it due to said negative value).

Anywho, lemme know if you get confused by this tutorial and i'll help you in any way I can!
Link to comment
Share on other sites

@'YourBestNightmare':

> Constant in function. I have not touched VB6 for years, but I am sure you will go to programmer hell for doing this.

I don't see any problem here, it's only being used within that sub specifically not to mention that's like dims are horrible in subs, wtf are you on about.
Link to comment
Share on other sites

@'Growlith1223':

> @'YourBestNightmare':
>
> > Constant in function. I have not touched VB6 for years, but I am sure you will go to programmer hell for doing this.
>
> I don't see any problem here, it's only being used within that sub specifically not to mention that's like dims are horrible in subs, wtf are you on about.

You want to defend your code? Okay, leaving this thread, I have nothing to talk about with you then.
Link to comment
Share on other sites

@'YourBestNightmare':

> @'Growlith1223':
>
> > @'YourBestNightmare':
> >
> > > Constant in function. I have not touched VB6 for years, but I am sure you will go to programmer hell for doing this.
> >
> > I don't see any problem here, it's only being used within that sub specifically not to mention that's like dims are horrible in subs, wtf are you on about.
>
> You want to defend your code? Okay, leaving this thread, I have nothing to talk about with you then.

you're complaining over nothing then leave over nothing, why were you here to begin with?
Link to comment
Share on other sites

I'd put this in modConstants, honestly.

```
Const MAX_INT As Long = 2147483647
```
Or replace it with

```
Dim MAX_INT as Long = 2147483647
```
It's not a particularly good idea or best practice to declare constants inside a method, seeing how they can be run several times. A constant should only ever be declared ONCE during your program's flow. Redefining a constant a couple hundred+ times per second is not a good idea, I'm surprised VB6 even lets you do that.
Link to comment
Share on other sites

I've tested this and there was literally no change in performance nor cpu/memory usage. I done Const MAX_INT within the method because there's no point in making it a global constant since this is the only thing using it. There was literally no ms change in doing what I've done so I went with it. god damn I finally release a tutorial in nearly 3 years and nothing but complaints.
Link to comment
Share on other sites

It's unlikely to make a difference in speed, seeing how it's declared only within the scope of your method. Doesn't mean you should not be able to take criticism on poor coding practices and improve though. Imagine if everyone just did their own thing "because it works right?" in critical software. There's a reason coding standards were made and why best practices exist.

Criticism is not complaining.
Link to comment
Share on other sites

So what you're essentially saying is using my own standard is bad…? ok, fine this is my last tutorial lol.

EDIT: also I know complaints was the wrong word. either way, if I can't use my own standard then there's no point in posting tutorials anymore, I shouldn't have to follow this "Coding standard" instead of my own. >_>
Link to comment
Share on other sites

  • 8 months later...
from my testing of having my comp up for about 1-2 months, any engine i have thrown this into has never crashed, there might be a mishap with it resetting back to 0 but it's fairly easy to fix with a small skip of one cycle and to fix that desync, you would just need to reposition everyone
Link to comment
Share on other sites

VB6 was good for awhile, .NET has finally matured and time to move on. :P Even though the IDE sucked, the speed and performance of VB6 was better for many years after Microsoft abandoned it.

Can't you just use a .DLL like Thomas coded in a new way to handle the tick count using timeGetTime which utilizes a new method of keeping track of the time, rather than using the plain old GetTickCount. This is also better and harder to hack I have noticed.
Link to comment
Share on other sites

you do realize that even .NET Environment.TickCount also has the issue of going negative?

also if you're using getTickCount OR timeGetTime in .net then you need to learn how to code in .net
both getTickCount and timeGetTime have the issue of roll-backing into a negative value, ere-go crashing everything.
Link to comment
Share on other sites

@'Helladen':

> VB6 was good for awhile, .NET has finally matured and time to move on. :P Even though the IDE sucked, the speed and performance of VB6 was better for many years after Microsoft abandoned it.
>
> Can't you just use a .DLL like Thomas coded in a new way to handle the tick count using timeGetTime which utilizes a new method of keeping track of the time, rather than using the plain old GetTickCount. This is also better and harder to hack I have noticed.

But yet still continues to use VB6\. You said in another thread that was deleted about moving on and going 3D and within about 2 hours of posting it you released a new update for mirage source on hitspark.
Link to comment
Share on other sites

@'BeNjO':

> But yet still continues to use VB6\. You said in another thread that was deleted about moving on and going 3D and within about 2 hours of posting it you released a new update for mirage source on hitspark.

I am using Visual Basic 6 for now. The updater I made for Nin Online is in .NET - I can write in .NET and OO too. I just have a lot of work that I would throw away if I rewrote the engine in a new language. I am utilizing my resources effectively here, not restarting when there is no need. But yes, I am moving tools and such over to .NET and getting more experienced in the language.
Link to comment
Share on other sites

@'Growlith1223':

> you do realize that even .NET Environment.TickCount also has the issue of going negative?
>
> also if you're using getTickCount OR timeGetTime in .net then you need to learn how to code in .net
> both getTickCount and timeGetTime have the issue of roll-backing into a negative value, ere-go crashing everything.

You can use unsigned ints or go for a long for the API calls. And, Enviorment.TickCount's MSDN page provides a way of converting the negative to a >0 value.
Link to comment
Share on other sites

  • 7 months later...
I've found a Public Declare Function GetTick Lib "kernel32" () As Long on modGeneral then I just put a ' before it
Then it gave me this error:
![](http://i.imgur.com/X15VpjL.png)
and I added it below the line I've commented before:
Public Declare Function GetTickCount Lib "kernel32" () As Long
and it compiled with no errors, but is it ok to do that or it will give me another error in the future?
Link to comment
Share on other sites

you'll want to keep that GetTickCount declare, that sub gets a system interval, the GetTick function i made checks to see if it rolled back, as after about 10 or so days, it rolls back to a very large negative value, causing crashes at that point, my getTick is like a wrapper over that value, so it ensures it is ALWAYS a positive value.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...