Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411471 Posts in 69369 Topics- by 58423 Members - Latest Member: antkind

April 23, 2024, 10:53:09 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)The grumpy old programmer room
Pages: 1 ... 243 244 [245] 246 247 ... 295
Print
Author Topic: The grumpy old programmer room  (Read 738576 times)
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #4880 on: July 06, 2015, 10:53:22 AM »

It's definitely slower than floating point, but I don't know by how much yet. I'm just getting to the point where I can profile and optimize it in a real-world situation.

Fixed point is relatively well known, but not in very widespread use as far as I know. Floating point is a better choice in most cases. Fixed's main advantage is consistency; float calculations will differ across platforms, so the same inputs to a game running on one system may give different results than on another system. Since fixed point uses only integer math, the calculations are universally identical.

The reason I've chosen it for this project is to be able to play back an input session anywhere to see the same game behavior. This is super useful for debugging (I have a system that logs all player inputs to disk as they happen, so if someone runs into a bug once, they can send me the gameplay session file, and I can play it back and reproduce the bug 100% of the time), recording/exporting gameplay footage (don't have to deal with real-time recording software which sometimes drops frames; the game can play back an input session in non-real-time, export a PNG for each frame and a WAV for audio, and those combine into a frame-perfect video), and high score verification (score server doesn't have to trust client's reported score or time; client just sends an input session, and the server simulates it to learn the result).
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4881 on: July 06, 2015, 11:52:56 AM »

The sony playstation actually had hardware fixed point support. That's about the last time I remember hearing about it natively supported.

The issues you are describing. Don't those really only come into play when switching hardware to a chip that treats floats different? Of course your use case of having someone send you a demo has exactly that problem but I'm just asking in case i'm overlooking a case where on the same computer you could have different results.
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #4882 on: July 06, 2015, 12:11:01 PM »

Yeah, different computers. The cases I'm thinking about are, for example, recording a replay on OS X and playing it back on Windows. One of my recent games used floating point and had a playback feature, and playback would desync in some cases if it wasn't done on the same OS as recording.

...actually, come to think of it, it's not necessarily a hardware thing. I'm pretty sure I got different results between Linux and Windows running on the same computer.
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #4883 on: July 06, 2015, 12:19:11 PM »

How is that possible? Huh? what do OS do? timing melding?
Logged

Boreal
Level 6
*


Reinventing the wheel


View Profile
« Reply #4884 on: July 06, 2015, 12:24:09 PM »

Basically, what happens is that IEEE instructions running on strictly-IEEE compliant (configured to use no extensions like 80-bit FPU registers) hardware should be consistent.  The hard part is making sure that you limit not only yourself, but also the compiler, to emitting that subset of possible FPU instructions.  For example, although the addition/multiplication instructions are IEEE and thus consistent, the combined multiply/add instruction (which optimizers will try to use) is not.

http://yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html

Differences between OSes are probably coming from optimization differences (i.e. different instruction usage) between compilers/interpreters for each platform.
« Last Edit: July 06, 2015, 12:32:36 PM by Boreal » Logged

"In software, the only numbers of significance are 0, 1, and N." - Josh Barczak

magma - Reconstructed Mantle API
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4885 on: July 06, 2015, 12:25:27 PM »

Yeah, different computers. The cases I'm thinking about are, for example, recording a replay on OS X and playing it back on Windows. One of my recent games used floating point and had a playback feature, and playback would desync in some cases if it wasn't done on the same OS as recording.

...actually, come to think of it, it's not necessarily a hardware thing. I'm pretty sure I got different results between Linux and Windows running on the same computer.

really? That seems really odd that there would be different performance across different os'es on the same hardware. Do you remember what compilers you were using?

I wonder if it would be the same or similar if you were to do something like use GCC/MingGW on the same computer as opposed to something like clang/msvc.

edit : talked to one of the senior guys at work with a lot of hardware experience about this. The conversation really blew up and now I have about 200 pages of reading to do :D. It did come down to that you probably could get the same results on the same hardware but you would have to make sure the compiler behavior is set to act the same way for float operations. For instance there's a bunch of flags in visual studio for affecting how floats are calculated (accuracy vs performance).

« Last Edit: July 06, 2015, 02:43:48 PM by InfiniteStateMachine » Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #4886 on: July 06, 2015, 01:02:20 PM »

@boreal
Thanks!
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #4887 on: July 06, 2015, 02:20:21 PM »

Yes, it's ironic, but fixed point is useful mostly because there is no support for it. All the clever optimizations of floating point don't help consistency.

Also, transcendentals like sin/cos aren't required to be 100% accurate by the standards. Presumably fixed point users don't use sin/cos at all, or stick with something consistently wrong.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4888 on: July 06, 2015, 02:42:54 PM »

Yes, it's ironic, but fixed point is useful mostly because there is no support for it.

Haha very true :D
Logged

J-Snake
Level 10
*****


A fool with a tool is still a fool.


View Profile WWW
« Reply #4889 on: July 06, 2015, 03:34:45 PM »

If you intend to simulate newton mechanics then best approach has to imply an appropriate use of both, float and integer/fixed point. You use integers/fixed point mainly to store positions, while you compute force vectors etc. in floats.

It is of fundamental importance to see that the actual point of floats is not consistency in terms of equidistant number distribution. That is why it actually doesn't matter much if the results can vary from machine to machine. If you use float, you are not about that type of consistency. You use float when you need to keep a small relative error in every range
(relative error = dx/x, where x is the intended number and dx is the error). Typical use are complex numerical computations
where the end results are intended to be as accurate as possible, but not necessarily precise (means the error patterns can change and fluctuate, but the errors are very small, that's the actual point here)

So what mainly speaks against the exclusive use of floats in games is the physical position of an object. Unlike vectors, positions cannot be measured in relative terms. For example if a vector is one foot shorter than the other then they will still look almost identical if they are a mile long. However if you stand at position A and add one foot to it, it will always look like a significant shift in position. So floats are of ill use in representing positions since their absolute error grows bigger the bigger the number gets, yet they are still used for the ease of use. While at the same time there is no justification for the same physical activity at position A to behave differently at position B. Each space should have equal rights, we ideally want an equidistant distribution of positional values.

« Last Edit: July 06, 2015, 04:08:24 PM by J-Snake » Logged

Independent game developer with an elaborate focus on interesting gameplay, rewarding depth of play and technical quality.<br /><br />Trap Them: http://store.steampowered.com/app/375930
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #4890 on: July 06, 2015, 03:44:39 PM »

where the end results are intended to be as precise as possible, but not necessarily accurate





For kids that peek over here  Who, Me?
Logged

J-Snake
Level 10
*****


A fool with a tool is still a fool.


View Profile WWW
« Reply #4891 on: July 06, 2015, 04:11:53 PM »

where the end results are intended to be as accurate as possible, but not necessarily precise
That's the correct version now and forever.
Logged

Independent game developer with an elaborate focus on interesting gameplay, rewarding depth of play and technical quality.<br /><br />Trap Them: http://store.steampowered.com/app/375930
Sik
Level 10
*****


View Profile WWW
« Reply #4892 on: July 06, 2015, 06:32:50 PM »

Basically, what happens is that IEEE instructions running on strictly-IEEE compliant (configured to use no extensions like 80-bit FPU registers) hardware should be consistent.  The hard part is making sure that you limit not only yourself, but also the compiler, to emitting that subset of possible FPU instructions.  For example, although the addition/multiplication instructions are IEEE and thus consistent, the combined multiply/add instruction (which optimizers will try to use) is not.

http://yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html

Differences between OSes are probably coming from optimization differences (i.e. different instruction usage) between compilers/interpreters for each platform.

Don't forget FPU control flags, those affect the way the FPU performs its calculations. This can also lead to that kind of differences, even within the same OS.
Logged
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #4893 on: July 07, 2015, 01:16:37 AM »

Aaaand don't forget the Visual Studio project settings, especially the floating point model. In my experience the change both the outcome and the performance of the code measurably.

That's why I always change it to "Fast" even in Debug builds - to get surprise-free results.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4894 on: July 07, 2015, 07:39:06 AM »

Basically, what happens is that IEEE instructions running on strictly-IEEE compliant (configured to use no extensions like 80-bit FPU registers) hardware should be consistent.  The hard part is making sure that you limit not only yourself, but also the compiler, to emitting that subset of possible FPU instructions.  For example, although the addition/multiplication instructions are IEEE and thus consistent, the combined multiply/add instruction (which optimizers will try to use) is not.

http://yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html

Differences between OSes are probably coming from optimization differences (i.e. different instruction usage) between compilers/interpreters for each platform.

Aaaand don't forget the Visual Studio project settings, especially the floating point model. In my experience the change both the outcome and the performance of the code measurably.

That's why I always change it to "Fast" even in Debug builds - to get surprise-free results.

Don't forget FPU control flags, those affect the way the FPU performs its calculations. This can also lead to that kind of differences, even within the same OS.


IIRC the visual studio settings are affecting whether the FPU flags are being used.


This is why I'm kind of interested to see if doing linux build with gcc and a mingw gcc build on windows would yield more consistent results. Assuming they use identical flags etc.


J-Snake, what you are describing is well known but a different issue than what's being discussed. What we would like is to consistently have the same inaccuracy.
Logged

J-Snake
Level 10
*****


A fool with a tool is still a fool.


View Profile WWW
« Reply #4895 on: July 07, 2015, 10:38:20 AM »

J-Snake, what you are describing is well known but a different issue than what's being discussed. What we would like is to consistently have the same inaccuracy.
Yet the average game programmer doesn't take it to heart, instead it is tried to fight the symptoms instead of tackling the core problem (I am not addressing Alex here, just a general note). I see that you want the "consistent inaccuracy" here to reproduce recorded game sessions exactly the same across different machines. But that shouldn't be your main motivation since the game is still inconsistent on the very same machine in terms of representation of space.
Logged

Independent game developer with an elaborate focus on interesting gameplay, rewarding depth of play and technical quality.<br /><br />Trap Them: http://store.steampowered.com/app/375930
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #4896 on: July 07, 2015, 11:27:16 AM »

I appreciate your pursuit of numeric perfection as a principle, but it's hard to take it seriously when it's presented this way. Different approaches to problems are something to be celebrated, not lamented. I don't think the approach you would prescribe is the correct thing for my situation, and that's OK! What I'm doing is deliberately different from a traditional physics system of the sort that would benefit from a more academic approach. If that was what I needed, I'd have been doing it very differently from the start, or using a prebuilt one.
« Last Edit: July 07, 2015, 12:55:38 PM by ThemsAllTook » Logged

J-Snake
Level 10
*****


A fool with a tool is still a fool.


View Profile WWW
« Reply #4897 on: July 07, 2015, 12:50:09 PM »

I don't think the approach you would prescribe is the correct thing for my situation
What would that approach be that is not the correct thing for your situation, to be more precise? I mainly suggested to know the domain limits of fixed point arithmetics, if that was some source of your problems.
Logged

Independent game developer with an elaborate focus on interesting gameplay, rewarding depth of play and technical quality.<br /><br />Trap Them: http://store.steampowered.com/app/375930
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #4898 on: July 07, 2015, 12:56:27 PM »

Scratch that part. I won't presume to know what you'd recommend.
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4899 on: July 07, 2015, 05:07:28 PM »

I thought j-snake was referring to my name while quoting me then I realized there are many Alex's in this thread :D
Logged

Pages: 1 ... 243 244 [245] 246 247 ... 295
Print
Jump to:  

Theme orange-lt created by panic