Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > Problem with Time based game (tick counter's acting wierd.. )


Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2006, 05:24 PM
RonenNess's Avatar
RonenNess RonenNess is offline
Centurion
 
Join Date: Mar 2006
Location: Israel
Posts: 150
Default Problem with Time based game (tick counter's acting wierd.. )


hi everyone.
im working on an rpg game engine, and im having a problem with the time based system.
i got like this :

Code:
'world time stuff
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long

'time system stuff
Dim Freq As Currency
Dim StartTime As Currency
Dim EndTime As Currency
Dim TimeElapse As Double
and in my main loop i have this :

Code:
Do While Running = True
 QueryPerformanceCounter StartTime

' all the game stuff comes here...

    QueryPerformanceCounter EndTime
    QueryPerformanceFrequency Freq
    TimeElapse = ((EndTime - StartTime) / Freq)
DoEvents
Loop
so now i basicly have "TimeElapse" which should be the time passed between eatch frame.
so i suppose to double everything in that value, right?
like Player.x = player.x + speed.x * TimeElapse

Now, the wired part is.. its somtimes work fast, and sometimes works really slow.. and i dont know why...
i mean, it sould work fine, and always at the same speed...
thats the whole idea of it now isnt it?
im using DX btw, maybe it has anything to do with it.


so anyone knows what can somehow effect the speed, or what im doing wrong?


thanks.
Reply With Quote
  #2  
Old 08-04-2006, 01:44 AM
AdrianDeAngelis's Avatar
AdrianDeAngelis AdrianDeAngelis is offline
Contributor
 
Join Date: May 2005
Location: Australia
Posts: 549
Default

1) Are the variables you multiply by TimeElapse single or greater precision? If Speed * TimeElapse is really small then it will look like things are moving fast/slow... that is the most obvious thing I can think of

2) No the TimeElapse will NEVER be exactly the same between processing cycles... If you do what I do and always have the TimeElapsed & FPS showing on the screen somewhere you will notice it often flits back and forth between increments of about n to n+15/20 milliseconds... use this to test if time is really running weird in your program or if it is just a variable rounding error.
__________________
Automation error... What do you mean automation error you %#@*&!$ thing!

Star Admiral: 3D tactical space sim *** New Version 0.38 10/01/09 ***
Damage, shields and special weapons systems
Reply With Quote
  #3  
Old 08-04-2006, 02:48 AM
RonenNess's Avatar
RonenNess RonenNess is offline
Centurion
 
Join Date: Mar 2006
Location: Israel
Posts: 150
Default

arr found the problem.
i forgot to do TimeElapse as public in my moudle and im using that TimeElapse in other classes, so VB just didnt find the variable and created new one with random left-over values in it.


but thanks anyway.
Reply With Quote
  #4  
Old 08-04-2006, 12:19 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

VB shouldn't create new ones if you use Option Explicit at the top of all your modules.
This helps prevent problems like this.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 08-04-2006, 03:06 PM
Alkatran's Avatar
Alkatran Alkatran is offline
Contributor
 
Join Date: Jun 2003
Posts: 539
Default

Option explicit is a MUST for programming anything decent! There is nothing more annoying than looking for an error only to find out you misspelled "chioce."

As soon as you read this, open VB and:
tools -> options -> turn on "Require Variable Declaration"
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->