Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 1348 times)
0 Members and 1 Guest are viewing this topic.
Offline bitshit

Junior Member




Java games rock!!


« Posted 2005-12-15 11: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 Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2005-12-15 11: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 Member




Java games rock!!


« Reply #2 - Posted 2005-12-15 15: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 Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2005-12-15 15: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 16: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 Member




shiny.


« Reply #5 - Posted 2005-12-15 17: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 Member




Java games rock!!


« Reply #6 - Posted 2005-12-15 17: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: 38



« Reply #7 - Posted 2005-12-15 21: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 Member




Beyond mind, there is an awareness...


« Reply #8 - Posted 2005-12-16 09: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




Where's the Kaboom?


« Reply #9 - Posted 2005-12-17 03: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.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!