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.

Newcomers DBPro Corner / Help with the Timer() statement please...

Author
Message
mbaucco
18
Years of Service
User Offline
Joined: 6th Nov 2005
Location:
Posted: 19th Jun 2007 21:09
I am trying to rotate a cube at a constant rate using the following code:


For some reason this does nothing, but the same code without the 3d commands works fine. Can anyone help? Here is the code without the 3d:




Thanks,
Matt
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Jun 2007 21:13
Try updating the 3D screen with the Sync On and Sync commands.

TDK_Man

Cloggy
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 19th Jun 2007 22:24 Edited at: 19th Jun 2007 22:24
The problem is you are rotating the cube by 90 degrees each time so it never looks like it is moving.

Set it to 10.0 and you see it rotate.



D3DFunc - Superfast Antialiased text & much much more
mbaucco
18
Years of Service
User Offline
Joined: 6th Nov 2005
Location:
Posted: 19th Jun 2007 22:49
Thanks for the replies but neither suggestion helped I'm afraid. I just don't understand why the code would work without the 3d commands but not work with them in it.

Thanks,
Matt
Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 20th Jun 2007 00:47
Change "If nElapsed = 250" to "If nElapsed => 250", because the timer won't always (and rarely will) be exactly equal to 250 at the time it hits that if statement.


Cloggy
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 20th Jun 2007 01:27
Maybe you should try a completely different tack. This has code borrowed from someone else (Nicholas Thompson I think).

It is a much better method for timer based movement.



You multiply all your movements by frameTime#. That way they remain constant regardless of PC speed.

Hope this helps.

D3DFunc - Superfast Antialiased text & much much more
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 20th Jun 2007 09:59 Edited at: 20th Jun 2007 10:03
Here is a method that takes less math per loop.



It's set up to spin the cube 100 degrees per second.


Come see the WIP!
mbaucco
18
Years of Service
User Offline
Joined: 6th Nov 2005
Location:
Posted: 20th Jun 2007 17:32
Thank you all very much for the help! I ended up using the solution Cash offered and it works perfectly.

-Matt
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 21st Jun 2007 04:22
Cool Be sure and put this

Quote: "timeStamp#=timer()-time"


under your Sync statement or it won't work right. Also, I made 'timeStamp#' a global variable so that I can access it anywhere in the program.

I use timer control for everything - movement, rotation, animation. I'd never do it any other way.


Come see the WIP!
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 21st Jun 2007 16:20
@WindowsKiller -
Yes, I am well aware of that. If you look at the line that it's used, it's used with all floating point numbers. I can recast it once, when I calculate timeStamp#, or I can recast it every single time I use it in an equation. I use it hundreds of times per loop, hundreds of integer to float casts wouldn't be very smart.


Come see the WIP!
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 25th Jun 2007 05:01
Timer Based is THE ONLY way to go.

I just got back into DBPro and my first halfway decent creation was pretty - mechanical - decent - BUT with the lack of timer based stuff through out - I totally rethought the whole scenario - and started again. The results - Much smoother - and all things that move do just as much action /distance etc regardless of PC speed! Very Cool!

Now if I could code my media loading routines to do a trick like that! hahah

Jason

Know way to many languages - Master of none
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 28th Jun 2007 14:29
WindowsKiller, if he used timeStamp# 100s of times per loop, it would be faster. You wouldn't make it an integer because while it may be faster at this very moment, you'd lose more and more speed every time you use timeStamp#

I would never optimize if it meant that I couldn't add new code without defeating the purpose of the optimization.

You never really know a person until you look at their google autocomplete entries.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 28th Jun 2007 19:31
Why would using a FLOAT (something#) get slower each loop? Is Dark Basic Sloppy with Floats or something?

Thanx - Just trying to prevent writing mucky code. Hard enough without creating new problems

thank you in advance.

Know way too many languages - Master of none
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Jun 2007 22:10
Quote: "Why would using a FLOAT (something#) get slower each loop?"

It wouldn't, but converting and integer to a float 100 times is slower than converting once and reusing the result - that's what was meant.

However, they are each only seeing their own side of the picture. IF the amount of time used by these calculations is large enough to have a noticeable effect on the speed of the code, and IF there is a mixture of floating and integer maths that needs the timings, THEN MAYBE it might be worthwhile to store the timer difference in BOTH float AND integer format so that you can use the appropriate one at each place in the code.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 28th Jun 2007 23:02
I agree with that sort of thinking. In fact - If I can "foresee" needing a calulated result of anykind over and over - OR - (usually) see a pattern after entering a few times - I'll try to make the "math" part create a "base" result I can use over and over and save the repetition.

Thanks for clarifying what was meant
Jason

Know way too many languages - Master of none
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 29th Jun 2007 10:40 Edited at: 29th Jun 2007 10:42
Quote: "only made it a float to save one cast when calculating timeFrame#"


In a game that uses timer based movement and animation, you'll access timeStamp# lots of times, hundreds in my case.

Everything in DBP that involves angles, position, or animation frames uses floating point math. If you use integers with any of these commands you risk making everything look choppy. Having to typecast every time is much slower than type casting once. Every single time you pass an integer to a float parameter DBP has to type cast it.

If you're going to make a program, you should do it right the first time so that it is expandable and efficient. I created that code snippet so that no matter how he used it, it would be as fast as possible.

I don't know why you're trying to argue WindowsKiller, my logic is sound and I am very experienced with timer based operations and I am a stickler for efficiency.


Come see the WIP!
vibe runner
18
Years of Service
User Offline
Joined: 7th Aug 2006
Location: The Future
Posted: 29th Jun 2007 15:55
As an aside, let me plug the M1 plug-ins http://www.matrix1.demon.co.uk/

One of the functions is HITIMER(), highly accurate, unlike the standard TIMER()

Moreover, you will find, unlike *so* many other plug-in suites, that there are many useful plugins. Check them out, you won't be sorry.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Jun 2007 23:57
Actually, the utility plug-ins are best picked up from the DLL forum (they replace all commands in the old utility plug-in, and provide a whole lot more).

The array, data and map plug-ins can be picked up from my site until I roll them into the utility set - sadly, I'm taking far too long to do it

BTW, I'll be releasing the latest updates later this weekend. I need to include something new in addition to the few fixes that have been required.

Attila
FPSC Reloaded TGC Backer
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location:
Posted: 30th Jun 2007 15:04
If the rotation is regular but can although be frame based try this code, it will work in DB and DBPro:


Login to post a reply

Server time is: 2024-09-27 01:21:08
Your offset time is: 2024-09-27 01:21:08