Qbasicnews.com

Full Version: CPU specific delay
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am looking for help with a delay that will run in the background that keeps my game running at a certain speed no matter what speed the computer is. The reason for this is that I spent a long time making an rpg on my 133mhz computer, and now that I have a newer one it is running so fast all of the animations blend together and the characters move at lightning speed...which make the game completely unplayable on faster machines.
I also need to know how to keep the speed the same on slow and fast processors. Smile
how are you delaying now?
The TIMER function gives you the number of seconds it's been since midnight to 2 decimal places.

You can use it to delay for a certain amount of time. For example:[syntax="qbasic"]PRINT "Waiting 1.5 seconds... ";

startTime! = TIMER
DO
t! = TIMER

' In case we happen to pass midnight while delaying:
IF t! < startTime! THEN t! = t! + 86400

LOOP UNTIL t! >= startTime! + 1.5

PRINT "done."
END[/syntax]
As long as you don't need more than about 18 FPS, this method will work fine. Otherwise you'll probably have to use a library.
That does not work, what happens if I do that is everything will just stop for x ammount of msecs and then go back to the game, I just want to be able to slow down the speed at which the computer processes the game. Maybe something running in the background even, but I have relsofts msec delay, but it is not helping me in the way i want it to, even with the real-time delay on it still playes too fast on higher end computers.
Quote:I just want to be able to slow down the speed at which the computer processes the game. Maybe something running in the background even
Guess what happens with "something running in the background"? When multiple programs are running on a single CPU, the programs have to take turns with the CPU. The execution of your program is constantly being interrupted.

Either way your program is slowed down because it's being briefly paused and then resumed many many times a second. It makes no difference what's doing it, whether it's a loop within your program, or an entirely different program running in the background.

So it's ultimately the same thing. The method I showed you really can slow down your program just like you want - you just have to delay for a tiny amount of time really often, that's all. That's basically how it's done in modern commercial games. Relsoft's msec delay would be perfect for what you want! I don't understand how you think it's not helping you. You must not know how to use it properly.

If you're still averse to adding timed delay loops to your program, there always mo'slo, but it costs money... Alternatively you could run your game in DosBox, which is plenty slow and allows you to set the virtual CPU speed.
It doesn't have to be external, I was just saying that all the real time delays, similar to what you posted, just doesnt work...I have tried many combinations and even have delays after everygraphics placement, and every key stroke, but I cant seem to get it slowed down...the reason for this is that the time between each delay is still running ultra fast...I'll check out those programs tonight, cant right now cause I'm at work, but if anyone has another idea as to how to do do this let me know.
Quote:I have tried many combinations and even have delays after everygraphics placement, and every key stroke, but I cant seem to get it slowed down...
Did you try asking for help with that?

Quote:the reason for this is that the time between each delay is still running ultra fast
No, that's not it. Adding timed (*) delay loops caps the maximum speed of the program. Meaning, if you delay for exactly .05 seconds each frame, you'll get 20 fps or less even on the fastest computer ever made - it won't matter how quickly the program is executing between delay loops.

The only way it could go faster than you intend is if you're doing something wrong.

(*) You were delaying for a set amount of time, right? Not something like "FOR n = 1 TO 1000: NEXT n", right?
Is it a MSDOS game? Add VSync and your game will run at 60 fps.



http://faq.qbasicnews.com/?blast=VerticalRetraceGeneral
you could use the old-fashioned V-Sync delay

[syntax="qbasic"]WAIT &H3DA,8,8 'Ready the delay
WAIT &H3DA,8 'Cause the delay[/syntax]

That should do a slight about 1/2 second pause...not sure of teh actual time....it is cpu dependant, which makes it dynamic to every system, giving you a general delay

Oz~
Pages: 1 2