SpacetimeDB and single-player #3289
Replies: 1 comment
-
Hey, currently you need to duplicate your logic to make it work sadly. For my case I have used an adapter pattern for the data flow on the frontend, so it can easily switch between singleplayer and multiplayer mode. The view layer just uses the interface, and you decide which implementation you want to use. I am using react native and zustand for the client state. It is pretty much the same abstraction (actions, selectors) as what Stdb provides (reducers, subsriptions). Zustand just uses the types which the Stdb SDK provides to create it's own "tables" using a factory. Sadly there is no workaround without running an instance on the client as far as I know. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello you all.
I think some of you have come to the same realization, but it would be very cool to also use SpacetimeDB in single-player games. As it stands now, we can start a SpacetimeDB runtime environment, inject our own custom game logic module, and let players connect to it. This would also be the same for single-player, where starting the runtime environment happens on the client's computer.
The real question is how this can be accomplished. From my research, the best way to do this right now is to launch a child process from within the game to start up the runtime environment & injecting server module. After that, the same code to connect game clients to the SpacetimeDB server can then take place, only then with
localhost
instead of another hardware device. This is similar how Minecraft does it, but I see no other option how to do it otherwise now.This whole system to spawn child processes, try to keep these alive, and terminate them when the player stops playing single-player, feels very fragile. My question is whether there is a better approach to use SpacetimeDB for single-player to reduce game developer time and code duplication? Or if some other system is in the pipeline for this? Or that this isn't the priority of SpacetimeDB, as it is a game server framework after all.
I'm very curious what the answer would be for this far-fetched idea.
Beta Was this translation helpful? Give feedback.
All reactions