Separate .dll for game simulation

Context: Hello, Unity refugee here. I am 2 years into my Unity mobile game and recently considered switching due to recent developments. Defold seems to be a good alternative as a Unity dev (aside from having to adapt to Lua) and supports many features that I used in Unity (PlayFab, Spine, GPGS, Flatbuffers). One thing I am unsure of is how I am going to translate my game structure to Defold.
Current game workflow: My game is a realtime multiplayer game that uses a cross-platform deterministic simulation so that the games only have to share inputs. I have a separate console application project written in C# that uses a fixed-point arithmetic library with custom physics to achieve determinism. The project is built as a .dll and is shipped with both the client and the server to ensure they are running the same logic to prevent desyncs.
Question: How would I achieve this workflow in Defold? Do I rebuild the game in Lua/C++ and add it as an extension?

Hello and welcome to Defold!

Good question! I don’t think you’d need to rebuild the whole thing in Lua/C++. I’m pretty sure it’s possible to load that dll and interface with it through a thin layer of C++ and some Lua bindings. This kind of solution is not really my expertise, but I think for instance @JCash can provide valuable input.

1 Like

As @britzl mentioned, it should be possible for you to load the library using C++.

As for calling into the C# code, I don’t know too much about that. But googling about “Calling C# from C++” does produce some results. As long as you can make that work, it should work well.

Currently, we have an issue with not having the .dll’s in a path when running directly from the editor, but we’ll look into this shortly-


Thank you for the responses! I took a look at my options to call C++ code from C# and wasn’t sure if I was satisfied with them. The way my simulation works is that it generates events as the simulation continues on. Unity listens to these events and will render the content accordingly depending on what the content is. Just from a quick search, it seems that I would have to create an IPC with Named Pipes to achieve similar functionality. On the surface, this appears to be difficult to debug and maintain in the long run. If I were to make a change to Defold, I might just move the simulation to C++.