Growlith1223 Posted September 30, 2016 Author Share Posted September 30, 2016 ```Function GetTick() As Long Dim Result As Long Result = GetTickCount() If Result < 0 Then Result = Result + INT_MAX GetTick = ResultEnd Function```this is another way of doing it as well. im sure there are better ways of doing this but this is a more efficient way as it's not doing a double call on GetTickCount. and also, if you're really having performance issues with this, i suggest you optimize your code. Link to comment Share on other sites More sharing options...
Lavos Posted September 30, 2016 Share Posted September 30, 2016 @'Growlith1223':> ```> Function GetTick() As Long> Dim Result As Long> Result = GetTickCount()> If Result < 0 Then Result = Result + INT_MAX> GetTick = Result> End Function> > ```> this is another way of doing it as well. im sure there are better ways of doing this but this is a more efficient way as it's not doing a double call on GetTickCount. and also, if you're really having performance issues with this, i suggest you optimize your code.I have my engine ticks setup like this:```Public Function GetTick() As Long If GetTickCount < 0 Then GetTick = MAX_LONG + GetTickCount Else GetTick = GetTickCount End IfEnd Function```I think its much better now. Link to comment Share on other sites More sharing options...
Growlith1223 Posted September 30, 2016 Author Share Posted September 30, 2016 if you really want more efficiency, vb6 has this weird ass thing where, the function name counts as a variable and is returned upon exiting the function, not just giving it a value. so you COULD use the GetTick = GetTickCount then check the value of GetTick what not, it's a very miniscule overhead redundancy but hey, if you're hurting for memory, then you could save a few bytes with thisEDIT: example```Function GetTick() As Long GetTick = GetTickCount If GetTick < 0 Then GetTick = GetTick + MAX_LONGEnd Function``` Link to comment Share on other sites More sharing options...
Lief1606 Posted September 30, 2016 Share Posted September 30, 2016 Just one last question, is it ok if I just fix this in the server side? Link to comment Share on other sites More sharing options...
Growlith1223 Posted October 1, 2016 Author Share Posted October 1, 2016 You /should/ be fine? i don't remember there ever being an issue with doing this on one side only. Link to comment Share on other sites More sharing options...
Lavos Posted October 2, 2016 Share Posted October 2, 2016 @'Growlith1223':> You /should/ be fine? i don't remember there ever being an issue with doing this on one side only.Does it really conserve bytes just by removing a few lines of code?P.S: Thanks for the optimization idea, i managed to clean up a lot of code using the 64 bit-system timer. Link to comment Share on other sites More sharing options...
BeNjO Posted October 2, 2016 Share Posted October 2, 2016 @'frmgama':> Just one last question, is it ok if I just fix this in the server side?Do it in both client and server, as some people leave their computers on 24/7 hosting stuff and if their gettickcount is negative it may produce localised bugs and errors. Link to comment Share on other sites More sharing options...
Growlith1223 Posted October 2, 2016 Author Share Posted October 2, 2016 @Lavos, the bytes would be removed by not initializing a second variable, which is the Dim Result As Long, you can use the function name as the variable, being as it doesn't return until it exits out or hits the end of the function.As for the 64-bit timer, what do you mean? if you mean timeGetTime, that one still rolls back but it takes a little longer Link to comment Share on other sites More sharing options...
Lavos Posted October 3, 2016 Share Posted October 3, 2016 @'Growlith1223':> @Lavos, the bytes would be removed by not initializing a second variable, which is the Dim Result As Long, you can use the function name as the variable, being as it doesn't return until it exits out or hits the end of the function.> > As for the 64-bit timer, what do you mean? if you mean timeGetTime, that one still rolls back but it takes a little longerYou're right, I swapped TimeGetTime back out with using GetTickCount and it had a big difference in performance.Ended up using your method in the end. :D Link to comment Share on other sites More sharing options...
Growlith1223 Posted October 3, 2016 Author Share Posted October 3, 2016 only thing i will warn you about, is, i suggest checking to see if GetTick has rolled back, and do like a global value, check that global var if it's true, and if it is, reset all tmr vals to 0\. this will prevent everything from locking up as while it rolls back, this function makes sure it's always a positive, so if getTickCount = -MAX_LONG, then GetTick will = 0 because of that, and increment from there, resetting those tmr values will prevent everything from locking up, rendering, game logic, etc. Link to comment Share on other sites More sharing options...
Lavos Posted October 3, 2016 Share Posted October 3, 2016 @'Growlith1223':> only thing i will warn you about, is, i suggest checking to see if GetTick has rolled back, and do like a global value, check that global var if it's true, and if it is, reset all tmr vals to 0\. this will prevent everything from locking up as while it rolls back, this function makes sure it's always a positive, so if getTickCount = -MAX_LONG, then GetTick will = 0 because of that, and increment from there, resetting those tmr values will prevent everything from locking up, rendering, game logic, etc.Okay I have the function setup this way.```Public hasRollback as boolean``````Public Function GetTick() As Long GetTick = GetTickCount If GetTick < 0 Then GetTick = GetTick + MAX_LONG If hasRollback = True Then If GetTickCount = -MAX_LONG Then GetTick = 0 End If End IfEnd Function```how do you suppose i do a check with the boolean if it is true? Link to comment Share on other sites More sharing options...
Growlith1223 Posted October 3, 2016 Author Share Posted October 3, 2016 nono, you don't have to reset the GetTick, only the tmr variables within the Loop(both client and server), basically, that first if for GetTick < 0, create an End If and within that, just do HasRollBack = True. in the loop, around the beginning of the loop, check if HasRollback = True, if so, reset values and HasRollback = false Link to comment Share on other sites More sharing options...
Lavos Posted October 3, 2016 Share Posted October 3, 2016 ooooOOOO!OO!O!OOOOOOOOOooooO! brb im gunna do it now.* * *@'Growlith1223':> nono, you don't have to reset the GetTick, only the tmr variables within the Loop(both client and server), basically, that first if for GetTick < 0, create an End If and within that, just do HasRollBack = True. in the loop, around the beginning of the loop, check if HasRollback = True, if so, reset values and HasRollback = falseSo heres what i did.```Public Sub GameLoop() Dim FrameTime As Long Dim Tick As Long Dim TickFPS As Long Dim FPS As Long Dim i As Long Dim LoopI As Long Dim FogTmr As Long Dim ClockTmr As Long Dim Result As FMOD_RESULT MenuType = 1 ShadeOut = True If hasRollback = True Then ' reset timers FogTmr = 0 ClockTmr = 0 Menu_Alert_Timer = 0 TradeTimer = 0 LastUpdateTime_ElasticBars = 0 LastUpdateTime_GameInput = 0 LastUpdateTime_WalkTimer = 0 LastUpdateTime_MapAnim = 0 LastUpdateTime_Ping = 0 LastUpdateTime_TextureReset = 0 hasRollback = False End If```Etc. Etc.then ```Public Function GetTick() As Long GetTick = GetTickCount If GetTick < 0 Then hasRollback = True GetTick = GetTick + MAX_LONG End IfEnd Function```Do I have to reset timer from data type recs and other places as well?like player(myindex).attackTimer ? or Just the timers from the loop? Link to comment Share on other sites More sharing options...
Growlith1223 Posted October 4, 2016 Author Share Posted October 4, 2016 i would also do the timers for everything else if you know how, too tired to give an example Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now