Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (806)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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  
  strictfp for multiplayer games?  (Read 4662 times)
0 Members and 1 Guest are viewing this topic.
Offline noblemaster

« JGO Spiffy Duke »


Medals: 35
Projects: 11


Age of Conquest makes your day!


« Posted 2008-02-12 23:08:16 »

This question is bothering me for a while now. A Java VM should behave exactly the same on different platforms and hardware!? I believe that includes integer and floating point operations as well? A floating point multiplication will always return the same result no matter where it is executed? Correct?

"strictfp" implies otherwise? float might get treated differently on different platforms? I don't get it  Huh

I am asking because it is somewhat relevant to multiplayer gaming. Let's assume I have the same game state on multiple machines which I try to keep in sync. If these game states contain floating point variables, updating these floating point variables over time might result in different float values? E.g. one being 2.300000, the other 2.299999?

Do I need to use strictfp for all my float variables in the data model? Any experiences? Examples?


Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2008-02-12 23:30:28 »

Don't bother. 'regular' floating-point accuracy is more that enough.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline ryanm

Senior Devvie


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #2 - Posted 2008-02-13 01:15:17 »

Unless your calculations have intermediate values that are flirting with +/-(Double|Float).MAX_VALUE, strictfp won't make any difference. Thems be some seriously big/small numbers.

edit: whoops, should have been -MAX_VALUE, rather than MIN_VALUE
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline noblemaster

« JGO Spiffy Duke »


Medals: 35
Projects: 11


Age of Conquest makes your day!


« Reply #3 - Posted 2008-02-13 01:38:21 »

So, there is not difference unless I am in the MIN_VALUE/MAX_VALUE area? Seems every reference indicates possible differences:
http://en.wikipedia.org/wiki/Strictfp

Offline CommanderKeith
« Reply #4 - Posted 2008-02-13 01:58:39 »

From memory, the JVM guarantees math calculation uniformity across all hardware and OS's etc up to a threshold, so calc's will basically be the same, but maybe not for the last couple of decimal places. Strictfp makes those last couple of decimal places exactly the same across all JVM's.

This seems consistent with your wikipedia link definition.

Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2008-02-13 09:41:42 »

Syncing simulations where physics is concerned seems to require strictfp, I've tried it without and tiny differences add up - thats assuming your syncing via inputs rather than state.

Kev

Offline ryanm

Senior Devvie


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #6 - Posted 2008-02-13 10:14:02 »

So, there is not difference unless I am in the MIN_VALUE/MAX_VALUE area? Seems every reference indicates possible differences:
http://en.wikipedia.org/wiki/Strictfp

Hmmm, yeah. The documentation seems to suggest that it only makes a difference if there's under or overflow, but I don't see why the extra precision wouldn't make a difference in all calculations, however slight it may be.
Offline Orangy Tang

JGO Kernel


Medals: 57
Projects: 11


Monkey for a head


« Reply #7 - Posted 2008-02-13 10:16:02 »

Hmmm, yeah. The documentation seems to suggest that it only makes a difference if there's under or overflow, but I don't see why the extra precision wouldn't make a difference in all calculations, however slight it may be.
If you want to do a deterministic / lockstep simulation then those tiny differences are going to add up fast. You'll likely find they'll diverge rapidly.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (587 views)
2019-09-04 15:33:17

hadezbladez (5533 views)
2018-11-16 13:46:03

hadezbladez (2411 views)
2018-11-16 13:41:33

hadezbladez (5794 views)
2018-11-16 13:35:35

hadezbladez (1233 views)
2018-11-16 13:32:03

EgonOlsen (4669 views)
2018-06-10 19:43:48

EgonOlsen (5688 views)
2018-06-10 19:43:44

EgonOlsen (3205 views)
2018-06-10 19:43:20

DesertCoockie (4104 views)
2018-05-13 18:23:11

nelsongames (5125 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
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!