Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project settings to use soft float and fixed point backends for float type #7128

Closed
Shadowblitz16 opened this issue Jun 21, 2023 · 5 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Jun 21, 2023

Describe the project you are working on

Multiplayer game

Describe the problem or limitation you are having in your project

It would be nice if node's were deterministic and we could just sync input state
It would reduce network overhead and would make writing things like david snopek's sg physics not needed

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add backends for gdscript float...

  • hardware
  • software
  • fixed

Add option in project settings to change what one we use.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Hardware would be no different to what we have now
Software would be a software implementation of hardware
Fixed would be a fixed point number possibly configurable or just up to the godot developers

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

It would ensure everything that uses float in the engine can be set to be deterministic

@AThousandShips
Copy link
Member

AThousandShips commented Jun 21, 2023

Doing this as a project setting is going to be extremely difficult, I'd argue impossible, as GDScript relies on built in types that can't be changed like this, and it'd require every part of the engine using non-integers to somehow handle this

Even doing this for like Vector2/3/4 would not be simple

Doing this as a compilation option would be a different story, but using fixed point math would involve a lot of work to make it decently performant and redesigning essentially everything in the engine that involves it

If we simply do this only for the data types in GDScript, the issues making Variant and the built in types work with this aside, this will have to be converted whenever interacting with the other systems, as they can't be controlled by settings, which will cause confusion and rounding etc.

Now adding a fixed point type is an idea, to be used for things like transferring data

But to be frank I have no hopes that it will be either possible, or approved, to do any of this by a project setting, it would at minimum be an extreme bottleneck for performance, even if it just affects the GDScript part, and converts to the relevant floating point type into the engine

@zinnschlag
Copy link

Now adding a fixed point type is an idea, to be used for things like transferring data

Also useful for all kinds of game mechanic related data, e.g. item weights or currency. I meant to write a proposal for this feature, but I never got around to work out the details sufficiently.

@AThousandShips
Copy link
Member

We already have a 64.64 fixed point format available for internal use, but it doesn't have support for a number of things, it's in thirdparty/misc/r128, but doesn't support any of the math functions etc. save for sqrt AFIK, and a bit large for many use cases

@dsnopek
Copy link

dsnopek commented Jun 21, 2023

I don't think this is a practical thing that can be done. Whether or not we're using floats is compiled into the engine. To allow this to be a project setting, we'd need to use some abstraction instead of real floats, that would check this project setting on every math operation. This would slow down all uses of Godot (even when the project setting is set to "hardware floats"), when most projects don't need it.

Maybe this could be done as a compile-time settings, where you could compile a "soft float" or "fixed-point" build of the engine, but that would still require massive changes to most of the project's source code. Which, again, I don't think is worth it for a feature that isn't needed by most games.

FYI, I maintain a deterministic 2D physics engine for Godot that uses fixed-point math (it's main use-case is for multiplayer games using rollback netcode):

https://gitlab.com/snopek-games/sg-physics-2d

Rather than trying to change all of the engine, it just introduces some custom physics nodes, which is IMO far more maintainable. And then only folks who need it can use it! Of course, this only covers 2D, but anyone is welcome to make a GDExtension that does a similar thing for 3D, perhaps using soft floats (which I think would be a better fit for 3D than fixed-point).

@aaronfranke
Copy link
Member

aaronfranke commented Jun 22, 2023

As explained here, it's not possible to have float precision controlled by a project setting.

However, you can add "Double Precision" to your project.godot's config/features= list to prevent you from accidentally opening your Godot project with a single-precision build of Godot.

Making the entire engine deterministic is too ambitious of a goal. At most, it can be isolated to a specific system such as the physics engine.

Also note that double-precision is already really good, it's nearly a billion times better than single-precision and that is already good enough for most games.

@aaronfranke aaronfranke closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants