Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Determine computer speed?

Author
Message
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 28th Mar 2011 22:38
Is there a way for DBPro to determine if a program is running slowly or quickly?

I'm writing on two computers, a faster, newer one, and an older XP machine. When I get my movement good on the fast computer, it's sluggish on the older one. I'm not limiting the sync, I'm using timer based movement, and I can adjust my movement step size. But how can my program detect when it needs to change speeds?

SCREEN FPS doesn't seem to be reliable, I'm showing 350 fps, but I have to move the camera in much larger increments to make it look the same as on the faster computer.

Any thoughts?

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 28th Mar 2011 22:42
What does your timer based movement code look like?

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 29th Mar 2011 01:33
When I want a delay, it looks something like this...



But specifically, I'm moving a camera. With no delays, sync rate 0, and steps of .01, the camera moves pretty good on my fast machine. On my slow machine, it crawls along. If I bump the step size up to 1.0, then the slow machine moves well, but on the fast one the camera is out of control.

That's fine, they are different computers. But what's a good way to trap this? Should I run some sort of benchmark when my program starts? Maybe a huge FOR/NEXT loop, and compare the timer before and after?

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 29th Mar 2011 02:15
Quote: "But specifically, I'm moving a camera. With no delays, sync rate 0, and steps of .01, the camera moves pretty good on my fast machine. On my slow machine, it crawls along. If I bump the step size up to 1.0, then the slow machine moves well, but on the fast one the camera is out of control.

That's fine, they are different computers. But what's a good way to trap this? Should I run some sort of benchmark when my program starts? Maybe a huge FOR/NEXT loop, and compare the timer before and after?"

YES! Timer based movement!

Lets say your program is running at 30 frames per second, and you want your object to move 1 unit per frame. OK. That's 30 units per second. Now, if you move your object 1 unit per frame at 60 frames per second, your object is moving at 60 units per second.

So, instead of having distance per frame constant, have distance per second constant.

of course the function "screen fps()" isn't the best measure of framerate, so each frame, you want to use the "timer()" or "perftimer()" function, to get the number of millisecond elapsed since the last frame. Divide that by 1000 and you get the number of seconds it took for the frame to pass.
So... What I usually do is:

do
...code...
Duration#=(timer()-time_last_frame)*.001
move object n, speed_per_second*Duration#
time_last_frame=timer()
sync
loop


If you do that, then object n will move at the same speed per second, regardless of what computer you're on!
The important thing is that I'm updating time_last_frame at the end of the loop, so that there is *minimal time elapsed between the time you calculate "duration" and the time you update time_last_frame*
This is because... Well, if you update time_last_frame right before you calculate duration, you'll get a number that's pretty much equal, because timer_last_frame~=timer(), and timer()-timer()=0.

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 29th Mar 2011 05:35
Neuro Fuzzy - This is fantastic! And I didn't have to learn any math to understand it!

I had it stuck in my head that "timer-based" only applied to waiting a certain amount of time before performing the next action. Oh, how wrong!

When I use your code to adjust my camera movement, the program looks the same on both systems.

Elegant and effective. Thank you.

replywei
15
Years of Service
User Offline
Joined: 4th May 2011
Location:
Posted: 4th May 2011 10:10
Log manner by writing several important nodes in the Log and track the time with which to open faster code execution for a long time.

Offering Durablecomputer partsat Tmart.com
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th May 2011 15:27
SPAM!! Is there a Mod about?

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 5th May 2011 06:36 Edited at: 5th May 2011 06:37
Quote: "Lets say your program is running at 30 frames per second, and you want your object to move 1 unit per frame. OK. That's 30 units per second. Now, if you move your object 1 unit per frame at 60 frames per second, your object is moving at 60 units per second.

So, instead of having distance per frame constant, have distance per second constant. "



1. Put the Globals at the begining of the program.
2. Call FrameTimer() after every SYNC command.
3. Multiply all movments by FrameX#.

This will make the movement smaller or larger automatically depending on framerate. Movement per second will be constant.

And don't listen to any talk about "smoothing out" your movements its a total croc.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th May 2011 10:45
Quote: "This will make the movement smaller or larger automatically depending on framerate. Movement per second will be constant."

You know no matter how many different ways I try using TBM I always end up with some difference in speed on different machines and I know I don't have any code to show to back it up I have never found it to be 100% consistant. I think at the very least you need to use IanM's hitimer() function to increase the accuracy and by setting it to a higher rate than milliseconds. I found it much more consistant on different machines than the native timer() command.

Quote: "And don't listen to any talk about "smoothing out" your movements its a total croc."

I thought this discussion was finished and it would be a shame to ruin this thread with another huge discussion. Please agree to differ on this one but personally I found it helped in one of my projects and not in another. There are no hard and fast rules regarding TBM and certainly there is certainly nothing that can't be adapted to suit a particular problem.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 5th May 2011 11:45 Edited at: 5th May 2011 12:14
Quote: " I think at the very least you need to use IanM's hitimer() function"


Yep. I agree, very good point. I just try to keep examples as light as possible. This definitely helps in any case.


Quote: " Please agree to differ on this one but personally I found it helped in one of my projects and not in another."


In one hand you are talking about using a high precision timer, and in the other you mention intentionally using the wrong measurements, the average framerate. This is a contradiction. I can certainly differ with you, but I genuinely want to help. And If you remember that discussion you know I've looked into it, pulled it apart, and can prove I'm right. I want to give people accurate information when I help them. I don't want to steer anyone in the wrong direction, I felt mentioning this was important enough.

Smoothing is an accuracy tradeoff. If your game has bad lag spikes, it can make the game slow or speed up a little to make it seem less jittery. It makes objects making big jumps across the screen to where they should be, have smaller movement jumps when lag spikes appear. The problem is, speed isn't constant anymore. If you tried to network your game, people would see you slowing and speeding up, abnormally. This is not something you would see in Call of Duty, or Quake, etc.

Since you asked, I won't pursue this further unless invited.

Login to post a reply

Server time is: 2026-07-10 16:12:56
Your offset time is: 2026-07-10 16:12:56