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.

Dark GDK / Timer + movement

Author
Message
Cpt Skydiver
17
Years of Service
User Offline
Joined: 23rd Mar 2007
Location: Behind my computer?!
Posted: 26th Mar 2008 14:57 Edited at: 26th Mar 2008 15:15
hello all,

ok i've been busy with some movement code including acceleration & slowdown but...

Without a timer the movement isnt the same on different computers and I have NO idea how I should implement this timer code (which i found in another post) made by jason into my movement code so it moves time based.

this is my movement code


and this is the post which includes the timer made by jason


he stated that you could always use logic based on Clock->Time_Elapsed but how

I tried alot and...... nothing changed

thanks to anyone who can help me out

Nick

Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 26th Mar 2008 15:47
could you provide a link or the nae of the topic you retrieved that code from ?

it looks like somthign i should implement into my system (have allready been told i should use a timer to do these thigns but havn;'t had a chance to look into , and while i am waiting for jason to get back to me on somthign he is looking at fixing i would like to learn a new programing technique and mabye i can play about with it and figure out how to explain implementing it )
Cpt Skydiver
17
Years of Service
User Offline
Joined: 23rd Mar 2007
Location: Behind my computer?!
Posted: 26th Mar 2008 15:50
here's the link http://forum.thegamecreators.com/?m=forum_view&t=124204&b=22

and it would be great if you could help me
I also read that it was better to use a timer coz else speed would be different on other computers which I dont want

TheeLord
16
Years of Service
User Offline
Joined: 23rd Jan 2008
Location: Chicago
Posted: 26th Mar 2008 17:15
You can use dbGetTime() and use the difference to an old get time value from the last frame to simply create a Percentage of a second variable. Take the speed variable and multiply it by the percentage of a second variable each second to calculate how far the object should move in that frame.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Mar 2008 17:31 Edited at: 26th Mar 2008 17:33
Hi Guys - You Honor Me Greatly! Much Appreciated! Love seeing my code in conversation! - BTW - I picked up another tip - the forums - and I use now to prevent HUGE time_elapsed (paused game, initial startup or whatever) .. updated JGC_CLOCK stuff:


(this lib is a work in progress - and this code isn't published yet - so snag it if you need it from here - not from the source code published here: http://code.google.com/p/darkgdkoop/ unless the file date is AFTER this thread post's date
jgc_clock.h


jgc_clock.cpp



Now - the question seems to be What the hell do I do with Time_Elapsed? LOL - I'll try to explain the same way that was exmplained to me in the DBPro forums... I'm not sure - but I THINK BatVink published a newletter with a GREAT "Timers" tutorial.. it didn't coer moving objects per say (there are a few threads about this also for sure) but I just learned alot from that little "Timer Primer" LOL

Ok... For lack of a better word - you are ONLY missing what I call the Multiplier.

We KNOW how much time elapsed from one frame to the next - ALL we need to do is have a number that describes "How Much Per Milli Second do We Want to Move or Animate?" (random, arbitrary, ...um... just experiment to get that "SweetSpot" you need to get things to move or animate right)

I do something like this in my header file:

psuedo_code.h



So all you need to do is REALLY just:

dbMoveObject(ObjID, ciCar_SpeedMult * Clock->Time_ElapsedFloat);

(The float thing allows you to use a value that's already converted from int to float for efficienciy reasons - so you can use OFTEN and not incur the overhead of turning the INTEGER Time_Elapsed to a float each time... (Even though you might not have been aware it was costing you CPU cycles).

Another CPU cycle saver ... is... Well... imagine a FPS game.
You might have the ability to to move forward AND sideways....
Or... you might need to move MANY "bad guys" in one FRAME who all have the same "Speed". Tip: Calculate the SPEED * TIMEELAPSED ONCE! then let them all share the result so you aren't recalculating this value. In it of itself its not expensive from a CPU cycle thing - but these things add up quickly... like when you go from testing 2 bad guys to 100 of them!

Hope this helps a bit!

Cpt Skydiver
17
Years of Service
User Offline
Joined: 23rd Mar 2007
Location: Behind my computer?!
Posted: 26th Mar 2008 17:52
thanks alot for your help

I think I understand most of it but when I implement the code i get this nice little error


and can i also multiply my fSpeed with Clock->Time_ElapsedFloat instead of the ciCar_SpeedMult?
or would that have totally wrong results (i want it so that the object actually accelerates and not only moves)

thanks alot already

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Mar 2008 18:14
Quote: "The following reply was posted by Cpt Skydiver into Dark GDK to a thread you are watching:

thanks alot for your help

I think I understand most of it but when I implement the code i get this nice little error


and can i also multiply my fSpeed with Clock->Time_ElapsedFloat instead of the ciCar_SpeedMult?
or would that have totally wrong results (i want it so that the object actually accelerates and not only moves)

thanks alot already
"


1st - the compiler error - did you do
because that initializes the class correctly. Make sure you do this somewhere so that "Clock" is available where you need - it - global, a namespace or whatever.

2nd - Is this legit?


YES - but you will have to experiment ALL OVER AGAIN to find both your CarSpeed's and your MyThottleSpeedFloat's values - meaning... Throttoe of 100 MIGHT have worked in the past for full speed... it might be 1.0001f or something.

In other words - YOU GOT THIS BRO! Now you just need to experiment and get the magic values that make the game play how you want. Takes a lot of time to get that sweet spot.

One trick that seems like a lot of work but it USUALLY worth it is writing a lick of code that

1: Display Time_Elapsed, SPEEDMULTIPLIER, and THROTTLE values on the display ALL the time...

2: add a RESET keypress that moves the "Car" or whatever to is ORIGINAL spot so you don't need to keep restarting the application (taks awhile sometimes for me)

3: add keypress that can add to or subtract from SPEEDMULTIPLER and your THROTTLE values -

this way you can interactively play with the numbers and get the results you want by simply experimenting... Write those numbers down when you get them, and then add a constant to your program to reuse em later.

Then Comment out the code that helped you do all this - don't delete it... because you might have to use it again... especially if you change the "SCALE" of your models and whatnot as that screwes the whole thing up and you need to recalculate everything again.

Cpt Skydiver
17
Years of Service
User Offline
Joined: 23rd Mar 2007
Location: Behind my computer?!
Posted: 26th Mar 2008 18:23
yes I did call

just before the main loop (as it was stated in your post in the other thread)
i also placed Clock->Update(); inside the main loop

so... i dont know what could be wrong

thanks for the other part if i get that last error away everything should be as i wanted it to be

Cpt Skydiver
17
Years of Service
User Offline
Joined: 23rd Mar 2007
Location: Behind my computer?!
Posted: 26th Mar 2008 19:01
sorry for the double post but my older posts have not yet appeared as they have to be approved

jason i think the error has *something* to do with the FLOAT in the Clock->Time_ElapsedFloat as i did not had the error with your OLDER clock from the other thread. is there a fix or workaround or do you know a solution?

thanks alot

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Mar 2008 19:02
Quote: "
yes I did call

just before the main loop (as it was stated in your post in the other thread)
i also placed Clock->Update(); inside the main loop

so... i dont know what could be wrong

thanks for the other part if i get that last error away everything should be as i wanted it to be
"


Ok - YAHOO ME NOW if you can. (instant Messenger) I'll fix you up in a jiffy.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Mar 2008 19:04
YAHOO ME LOL.... Instant Messenger - let's iron that bug out sooner than later

should only take but 5-10 minutes...

Cpt Skydiver
17
Years of Service
User Offline
Joined: 23rd Mar 2007
Location: Behind my computer?!
Posted: 26th Mar 2008 19:32
ok thanks ALOT!!! for all the help

I left some stuff from a older time code which is stupid ... and you placed the Clock = new JGC_CLOCK();(<-just before main loop) & JGC_CLOCK *Clock;(<- global) in the right place

now im gonna tweak as much as needed

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Mar 2008 19:35
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 17th Jul 2008 14:34
i have implemented this timing movement in my code, but having objects move from A to B is now a bit jerky at times, wheras before it was quiet smooth.

Is this a "side effect" of timer code?
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 17th Jul 2008 16:13
Just a question is time based movement 100% accurate ?? ie: i want to move 100 units in 53.06 secs ,it will reach the exactly 100 units ?? or something like 100.843 ?
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 17th Jul 2008 17:04
It depends, Jason's code uses dbTimer() which isn't 100% accurate, but for most things it should be sufficient, if you need greater accuracy then use the performance timer instead. Using this will get you far greater accuracy, and if your loop happens to end at this 53.06 mark then yes your object will move more or less 100 units depending on float accuracy. But I'd imagine most games would use one of the two methods so I wouldn't worry about it.

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 17th Jul 2008 17:22
mhmhm the thing is that i have to move 5.47619055779207460 units in 0.11298787341077525 seconds, and stuff like that.
Those are 'double' and the dbPositionObject funtion takes floats
So i assume that it will never be 100 % exact, wich sucks

My problem is that i have a tonz of that kind of movement during like one minute, and when everything ends , there is a difference of like 0.2 units with the final distance, so if i have to move 800 units ,after 60 secs ,it moved 800.2 (Even 800.4) units

If anyone dont understand what im talking about i can make a more detailed post
Cheers and thanks
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Jul 2008 17:32
First of all, I'm wondering what it is that requires such accuracy?

Second, are you predicating your positions based on previous position or is it viable to calculate it based on an initial position and the total time since time zero?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 17th Jul 2008 17:39
Hi
You can imagine something like a race.
I have an initial position XYZ ,then i have data that looks like:
Move 5.47619055779207460 units in 0.11298787341077525 seconds
Move 10.73333349327246600 units in 0.25373733403220916 seconds
etc etc ,and so on.
Until i reach the finish line (distance) wich is something like an integet number like 800.
As you may see ,it takes like 53.something seconds to reach the finish line, right now when i reach it ,myobject moved something like 800.201234568 units and not the exact 800.

What i was wondering if this kind of exactitude is posible (floats)

Cheers and thanks for your help

*im not a native english speaker so sorry for my spelling
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Jul 2008 17:44
Considering that the tick timer is only accurate to 1/1000th of a second, I'd be inclined to doubt that that kind of accuracy is possible.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 17th Jul 2008 17:49
bad news, maybe using the PerformanceTimer() would help?
I think that calls the QueryPerformanceCounter() function
Anyone has used the timeGetTime() function ?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Jul 2008 17:58
You'd probably need to run the QueryPerformanceFrequency function in order to determine how precise any given machine can be. And indications are that some systems may not support a high resolution timer.

Ah, for the old days when there were 18.5 ticks per second. What precision.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 17th Jul 2008 18:07
Yeah ive read a couple of stuff about the QueryPerformanceFrequency and QueryPerformanceCounter ...
I think that i will stick to GetTickCount().
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 17th Jul 2008 18:09
in my case i just want to move an object from X position 80 to X position 100. I want the speed increment to be the same on every PC. Hence i am using this timer function.

However the problem is that whilst before the object moved smoothly across the screen, with the timer it starts smoothly, then moves jerkily halfway through, then goes on smoothly. is there a way to fix this?
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 17th Jul 2008 18:29
bjadams
Could you post some code ?
I would glad to help you
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 17th Jul 2008 18:55
here is my sample code.
a sphere moves from right to left side of the screen.
i want the sphere to move the same speed in the same amount of time on different pc systems.


FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 17th Jul 2008 21:47
It looks fine in my PC so i cant help
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Jul 2008 07:37
Hi folks! In dx land I've beeen forced to look at other timer functions. dbTimer, like Dark coder mentioned, isn't perfect but should suffice for most games.

Talking with one coder - he noticed that GetTick was faster (from overhead point of view) compared to queryPerformance. Also, in another article I googled (sorry no references), this gentleman explained a rather complex method for getting near perfect time - only laptop power savings things might throw off. Basically, as was mentioned above - QueryPerformance timer was used - along with some logic that used CPU ticks, and then verified "drift" and self corrected. I personally think this is overkill, but I'm also thinking it depends on your needs of the application. When I think typical video game - I think simple is worth quite a bit sometimes - and using canned dbTimer and GetTick fits that bill for me ... so far. Let me point out that Windows is not capable of REALTIME anyways... it's not a flaw - it wasn't designed to be. It can get close - but it's just not built from the ground up to be a REALTIME system. (though I'm saying this with scientific applications in mind where realtime need to be dead on!) there are "RealTime" apps that have a bit of tolerance - and again - depending on the application I think this is more than acceptable.

With regards to ... I believe FERSIS' need for double precision, I must say this is a noble goal - however the entire DirectX library - DX9 anyway - from what I've seen so far, and most definately in DarkGDK - is that the majority of the structures from vertex through UV, and DarkGDK Object "positioning" and "rotation" (Matrix transforms of varying flavors I'm learning is what they are) are all based on 32bit floats.

One reason for this might be the fact that on a 32bit processor, these values are processed much quicker. also the data "size" consideration compared to using double precision.

Now on a 64bit platform, in 64 bit mode (truly running 64bit assembly/endian) I believe that processing 64bit (double precision) MIGHT even be faster than the float data type if history is a trustworthy guide.

In my days of assembly programming I learned the how's and whys of aligned data versus unaligned data, and native "cpu data commands" versus non-native. this nonmenclature is a little different than what we normally think of using the word "native". Behind the scenes - (whether RISC based or not) - when the CPU can grab a full "memory location" (width of bus in one fetch...as is possible with an aligned float or int, or dword in memory) this data fetch happens in less cycles than if its unaligned. "Native" in that the CPU does what it does best... grab the whole 32bits - YANK! The non-native nonmenclature stands for what happens when say a 32bit number is not aligned, say 16bits in one "memory location...consisting of 32bits actually, multiples of 4 the way we normally think of ram) needs to happen in multiple fetches - the loorder 16bits, then the highorder 16bits... both need to be extrolated and "put together" THEN processed - albeit a math function or what have you.

ALL THIS GIBBERISH MEANS is its more likely you'll get that 64bit precision in a 3d renderer someday (or now perhaps some already do this..and I'm sure some do... but not dx9 for sure) when 64 Protected mode is the norm, the code running is true 64bit mode, and video cards can access the full width of the memory bus (which they probably can now). that's when all the 64bit endian stuff will be falling into place. It took32bit stuff awhile to be really used right - and I think it will be the same with64bit stuff - at least for PC's and gaming, gfx cards etc.

Now if this technology is already here - (I think it is we just don't have it in dx9, I dont think 10, and definately not in DarkGDK due to being dx9 based) - then I won't be surprised.

I think the jittering that Fersis is talking about could be more about trying to mix "double precision" with "floats" and rounding is messing him up - or the code is hitting major "lines of executed code" differences from one frame to the next. Meaning in one frame ...say 1000 lines get run, next frame 3000, etc.. (possibly..BTW...just arbitrary numbers for an example) ... I think if he sticks with 32bit numbers accross the board - keeps the code tight ... and possibly a faster PC - it should balance out.


My last PC I wrote all that DarkGDK OOP code on had some jitters - and the same with my raw DX9 code - then others ran the SAME code on other machines - that were faster - and they didn't see any jitter - and even doubted me ...or rightfully insulted my PC LOL

So - hang in there. I'm really glad you (FerSis) Are attacking timer based code with a vengence! Good Show!

--Jason

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 18th Jul 2008 09:41
Thanks for taking a look at my code FERSIS.

So you think all is ok with it, nothing in the wrong place?
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 18th Jul 2008 15:21
JASON:
Lovely explanation Jason
I understand what you say.. i was flying too close to the sun!
In fact ,i want to use float precision BUT another programmer wants double so.. its good to know that the little difference its something normal and not my ugly code

BJADAMS:
Your code is fine ,timer based movement its not always smooth,
theres always a minimal difference, but its far better that not using it at all.

This is a awesome subject by the way.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Jul 2008 17:31
Thanx Fersis - now my little Appendum - I ended up staying with QueryPerformance in the end - because according to my on screen "fps" and "delays between individual frames" It seemed more consistant.

I have this "millisecond since last frame" debug info - and granted it flies by so fast its hard to gauge - but with query perf, I get 3.5, 3.2, 3.8, 3.4 (arbitrary example) versus using get tick i tend to get things like: 3.0, 0, 4.5, 2.1

I hope you see the trend I mean. I think GetTick is less overhead but from the time measuring - it APPEARS that Query causes a smoother dilly (being only change in code - using tick vs. qperf)

It could be nothing at all though because I've heard developers warn against having your benchmark code measure before and after a function call - and how this can be "untrustworthy" due to how the cache might fire the stuff off or something...

--Jason

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 18th Jul 2008 18:32
So QueryPerformance ?
Are you gonna update your Clock class with QueryPerformance instead of dbtimer() ?
just asking
Ive read that its not always accurate on multi core processors, is this right ?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Jul 2008 20:35 Edited at: 19th Jul 2008 15:31
Well - the multiprocessor thing I can't attest to and I'd not put to much stock into either one. I'd experiment. It'd be best if there was some sort of clock class that allowed you to have one code base and switch between them easily... like this (unsupported for drop ip replacement for DarkGDK OOP jfc_clock.* - though should be ok)

jfc_clock.h (DirectX9 compat - aug2007 - no DarkGDK code in here)


Note - some of the query code was cut-n-paste and worked in from some random blog how to use query perf thread I stumbled across in my google mission.

For those of you who have seen the DarkGDK oop code "Jegas Game Classes etc" this code style should be fairly consistant.

[edited to fix the "not all paths return a value" warning.]

jfc_clock.cpp


Have fun! Hint: See Constructor - parameter 1. Also notice the different "default" data types in each mode. Same functionality though 98% (BTW 95% of statistics are made on the fly) <LOL>

--Jason

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 18th Jul 2008 20:47
Does the new CLOCK work as before?

that is putting this call before the main loop:

JGC_CLOCK *Clock = new JGC_CLOCK();

and using this as multiplier:

Clock->Time_ElapsedFloat
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Jul 2008 21:28 Edited at: 18th Jul 2008 21:36
Hi BJAdams!

...um... almost JGC in this case is JFC, and (other dx9 stufg I have is JDX in place of JGC. Aside from naming.... and the parameter in the constructor to choose a time mechanism (GetTickCount or Queryperformance timer..._) yeah its basically the same with some new feature. (Old stuff works the same)



so those are the new names. also there is this "how long been instantiated" functionailty with a reset. This means you can have your main "Clock" and also use the same class sorta like a TIMER for an event ... Like a game object (like a bullet) might have a instance of clock created when its "fired" or launched - and as the "time alive" increases - you might change the gfx, tradjectory, or whatever. Might be overkill too - I realize that - but - I saw the feature in the thread that had the Query stuff so I implemented it. I still use my timers - but ... hey.. more tools the better

(Does this message help at all?)
[edit] change the JGC to JFC as is should be in the code block...doh [/edit]

--Jason

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 19th Jul 2008 09:07
I think we miss this file:

#include "jfc_string.h"
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Jul 2008 11:18
Ok....

Here is my latest gambit of string stuff:

jfc_string.h


jfc_string.cpp


And for the Unicode stuff...
jfc_stringw.h


jfc_stringw.cpp


Hope this helps
--Jason

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 19th Jul 2008 14:41
works fine now. THANKS A LOT, i will do some furthur testing to see if everything runs smoother with this dbTimer()-less version!
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 19th Jul 2008 14:49
i am getting a warning error:

jfc_clock.cpp(172) : warning C4715: 'JFC_CLOCK::Milliseconds' : not all control paths return a value

any ideas?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Jul 2008 15:32
yeah - one of the control paths dwasn't returning a value - Its fixed - snag jfc_clock.cpp again ...

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 19th Jul 2008 18:51
fix?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Jul 2008 19:01
I fixed it.
I editted the source in the post with the jfc_clock.cpp code

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 19th Jul 2008 19:11
thanks a lot for all your support
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Jul 2008 20:14
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 19th Jul 2008 21:42
Jason, you have got to be in the top three most helpful people here.
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 21st Jul 2008 17:24
I have a little and silly question:
where the Clock->Update(); must be? after o before the movement?
Let me explain
(Pseudo code follows):

is this the correct order ??
or it can be :


or


Thanks
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Jul 2008 19:50
Either way should be fine

I personally like the Clock update at the top of the render - but it really doesn't make a difference...

I prefer the top because - from human point of view (namely mine) It seems to me that it makes sense to ask "how much time elapsed since I asked last" at the top of my render "loop" ... this in my feeble mind seems better... but I'm not positive it is or isn't.

--Jason

P.S. sounds like overall you're making rpogress with this timer stuff! Good show!

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 21st Jul 2008 20:06 Edited at: 21st Jul 2008 20:06
Thanks for your reply.
I would love to say : 'yeah im making a progress here'...
but nope.

im doing something like this :


So well i do that , and if for example i say: i want to move 200 units (dDistance = 200; ) on 2.5 seconds (dTimeToTravel = 2.5f) it takes something like 2.507650491 seconds and it travels something like 200.5971 instead of 200.
So im not making any progress
Cheers man and thanks for your help.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Jul 2008 21:55
First - I don't understand why you'd takeelapsed time and div by 1000 (get seconds?) then do math with result? I'd try to keep the number "raw" as I return it and use it like that OR multiple * 0.001 versus divide (executes faster)

Also - rounding is not going to allow you to get that PERFECT a movement where adding up each "render cycle"'s time slice (time elapsed) = TOTAL DESIRED move in allotted time frame.

You might need to record your starting location - and clock Time (in milli since midnight, or tick or whatever) when you "start" and each move look at the TOTAL TIME ELAPSED since you STARTED and calculate the new position like that.

The way you're doing it now - is how I do it - with the goal being to get smooth movement from PC to PC - one code base. I'm not trying to get perfect numerical/physic's ish movement like you seem to be after. (This is why many (most) physic engines have a "heart beat" system so they have a constant of "time" to work with versus trying to calc time slices)

Good Luck! Stick to it - you'll get it!

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 21st Jul 2008 22:27
Quote: "
physic engines have a "heart beat" system so they have a constant of "time" to work with versus trying to calc time slices
"

wow, i finnally know why is that "heart beat" used , i always wondered why , thanks jason for teaching me that(Every day we learn a new thing)

Login to post a reply

Server time is: 2024-09-30 03:17:25
Your offset time is: 2024-09-30 03:17:25