Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  incrementing variables  (Read 1500 times)
0 Members and 1 Guest are viewing this topic.
Offline bitshit

Junior Devvie




Java games rock!!


« Posted 2005-12-15 10:32:28 »

Hi,

I have a gameloop in which I increment a float variable (time) with the deltatime each iteration. As this time var is never reset during the play, won't this go out of bounds at one point or another? Im pretty sure its a common issue in gamedevelopment, so im curious how other game developers handle this...
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2005-12-15 10:55:27 »

It would, be I'd be interested to know why you're keeping tracking of the amount of total time that has passed in this way. If its for some game mechanic you could try tracking seconds and then storing them in a long (or better still just record the time the game started). That way you've got a fair amount of time before its likely to overflow Wink

Kev

Offline bitshit

Junior Devvie




Java games rock!!


« Reply #2 - Posted 2005-12-15 14:30:27 »

Well, I was using the time var for a physics simulation, actually a port to Java of what can be found here:
http://www.gaffer.org/articles/Timestep.html

But another case where it could let to problems is if you'd want to count the total number of frames drawn... ok it will take a very long time if you count it in a long, but eventually it would bail out...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2005-12-15 14:51:07 »

We are talking a seriously seriously long time here tho Smiley

Kev

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #4 - Posted 2005-12-15 15:00:48 »

More accurately, a signed 64bit long counting frames at 60Hz will take almost two and a half years before wrapping.  If if that causes a bug, tell the person who found it you don't believe them and ask them to reproduce it. Grin

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #5 - Posted 2005-12-15 16:25:27 »

it will never go out of bounds, the highest amount or lowest amount is not protected, so after 3.40282346638528860e+38 it will goto 1.40129846432481707e-45 resp, Float.MAX_VALUE Float.MIN_VALUE it's one nice big cirkel horray \o/

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline bitshit

Junior Devvie




Java games rock!!


« Reply #6 - Posted 2005-12-15 16:57:56 »

Quote
We are talking a seriously seriously long time here tho  Smiley

Quote
More accurately, a signed 64bit long counting frames at 60Hz will take almost two and a half years before wrapping.  If if that causes a bug, tell the person who found it you don't believe them and ask them to reproduce it.  Grin

Yeah... I'll just mark this one as not being an issue I guess  Tongue
Offline cylab

JGO Ninja


Medals: 55



« Reply #7 - Posted 2005-12-15 20:28:24 »

Quote
More accurately, a signed 64bit long counting frames at 60Hz will take almost two and a half years before wrapping
Well, actually it will take 4billion years  Grin

Mathias - I Know What [you] Did Last Summer!
Offline hvor2

Junior Devvie




Beyond mind, there is an awareness...


« Reply #8 - Posted 2005-12-16 08:38:24 »

More accurately, a signed 64bit long counting frames at 60Hz will take almost two and a half years before wrapping.  If if that causes a bug, tell the person who found it you don't believe them and ask them to reproduce it. Grin
Grin Grin Grin

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #9 - Posted 2005-12-17 02:20:42 »

it will never go out of bounds, the highest amount or lowest amount is not protected, so after 3.40282346638528860e+38 it will goto 1.40129846432481707e-45 resp, Float.MAX_VALUE Float.MIN_VALUE it's one nice big cirkel horray \o/

Actually it is quite likely that it will simply stop incrementing long before it gets near the max value.

Because the delta will be so small relative to the size of the time value that adding it won't even change the least significant bit so the time value remains the same before and after the addition.  It's the nature of floating point values.

Try adding 1 to a number in a loop but only keeping 2 significant digits in the total... once you get to 100 you are stuck Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!