|
-
Dec 9th, 2003, 01:42 PM
#1
Thread Starter
Lively Member
Timers for a game
I am currently trying to make a game in DirectX, but I was just wondering if there was anything better then using timers, because i thought I read before that Timers weren't really good for games.
-
Dec 9th, 2003, 02:20 PM
#2
transcendental analytic
alternatively you could call sleep to delay, or use settimer functions or multimedia timers, depends really what you're upto
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 9th, 2003, 02:26 PM
#3
Thread Starter
Lively Member
Well I used timers for the first version I made of the game, where the timers handled moving, so that hitting more then one key wouldn't jam the program. Is there a function to maybe do something like:
[Highlight=VB]
..Main Code..
if wait is done then
dostuff
startwait 15milliseconds
end if
-
Dec 9th, 2003, 02:29 PM
#4
transcendental analytic
no, but assign a variable say wait=gettickcount()+15 and wait til wait is less than gettickcount()
btw gettickcount may not be that accurate, so you might have to choose another timer (such as multimedia timer or performancecounter)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 9th, 2003, 03:20 PM
#5
Just remember that the GetTickCount API has diffrent resolution on diffrent Win plattforms.....
-
Dec 9th, 2003, 05:21 PM
#6
Fanatic Member
Excuse me NoteMe? That would really screw some of my programs! Is it lower in older platforms? Is it always a millisecond after such and such point?
Don't pay attention to this signature, it's contradictory.
-
Dec 9th, 2003, 05:25 PM
#7
Sorry to screw up your apps...but it is true.....look it up on MSDN. Older Win versions have a really bad resolution on the GetTickCount API.....
-
Dec 9th, 2003, 05:33 PM
#8
Fanatic Member
VB Code:
public sub Wait(Milliseconds as long)
dim EndTime as long
EndTime = GetTickCount+Milliseconds
While GetTickCount < EndTime
DoEvents
Wend
end sub
now picture a program using that consistently when your resolution is actually more along the lines of deciseconds (a tenth). Although I really don't think I have to worry about it cause everyone I know has 98+ ... and I don't use it TOO much...
Don't pay attention to this signature, it's contradictory.
-
Dec 9th, 2003, 05:39 PM
#9
If I can remember it right it was something like
Win2k/Xp = 10 ms
WinMe = 20 ms
Win98 = 40ms
Win95 = 50ms
Or something like that...
-
Dec 9th, 2003, 05:43 PM
#10
Fanatic Member
But is it always calculated in milliseconds?
or are you just saying it updates less frequently? because that's fine by me.
Don't pay attention to this signature, it's contradictory.
-
Dec 9th, 2003, 05:45 PM
#11
Frenzied Member
Try this:
VB Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim Pause As Boolean 'check if game is paused
Dim Running As Boolean 'check if game is started
Dim Fps As Double 'current fps
Dim FrameCount As Long 'count frames between fps update
Private Sub Form_Load()
Me.Show 'show the window
Running = True 'no the game is on
Main 'start main loop
End Sub
Private Sub Main() 'the main loop
Dim TempTime As Long 'to keep track of time
While Running 'is the game running?
If TempTime <= GetTickCount Then 'is it time to calc next frame?
TempTime = GetTickCount + 10 'set next tick time
While Pause 'is the game paused?
DoEvents 'infinit loop
Wend
'Code goes here.
FrameCount = FrameCount + 1 'fps counter
If Fps + 1000 <= GetTickCount Then
Me.Caption = "Fps: " & Round(1000 / ((GetTickCount - Fps + 0.00001) / FrameCount), 0)
Fps = GetTickCount
FrameCount = 0
End If
End If
DoEvents 'handle win msgs
Wend
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Running = False 'game over
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyP Then 'pause code
If Pause = False Then
Pause = True
Me.Caption = "Paused"
ElseIf Pause = True Then
Pause = False
End If
End If
End Sub
-
Dec 9th, 2003, 05:51 PM
#12
Yes it always updates in milliseconds.....but not every millisecond....if you want it more accurat....try using querreryperformmace something....API
-
Dec 9th, 2003, 05:53 PM
#13
Fanatic Member
Ok, whew! I thought you meant that it actually saved 10 seconds as 100, instead of 10000. Which would ahve made all waits a BIT longer
Don't pay attention to this signature, it's contradictory.
-
Dec 9th, 2003, 05:56 PM
#14
Hehe...no no no..but if you have a waith for 10ms and the app is running on an old OS the waith will probably be more like 50ms....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|