Trains.NET
Trains.NET copied to clipboard
[DRAFT!] Multiplayer with Blazor Server
This is very much a work in progress but I thought I'd share it as a draft PR for anyone interested in my progress.
I've successfully got Blazing Trains running in Blazor WASM inside a Blazor server site. I've got shared memory managed on the server and interop that sends data into the wasm runtime to update data in the game.
You can try it out at https://blazingservertrains.azurewebsites.net/
Here's trains running on three different devices at once. When I enter a number for the terrain seed in thje text field all three devices update.
Next step will be architecting the interop a little better and then shared track layout.
Notes about the gif above
- The window on the right is a VM running on Azure with no GPU, middle is my Mac Book Pro, left is a Pixel 3A device on the same wifi as the mac
- VM and Azure App service are both Australia South East
- When I edi tthe seed in VM, the mac updates the fastest, followed by VM, then a few seconds later the Pixel. This suggests that network latency is neglible here and the update time is CPU/GPU bound.
- I haven't merged in your code lately so I don't think this is AOT
Interesting. Piggy back-ing on blazor servers signalr connection to share data like this is definitely interesting, and in theory the solution could actually be "simple" - have ILayout and IMovableLayout implementations on the server that get picked up by DI instead of the ones in Trains.Net.Engine, and they do the JSInterop thing, and the rest is hisotry.
Though of course that would mean mixing my DI and ASP.NET Core's DI, and that is probably the hardest part 😁