Hi, everyone!
I'm in the process of building a MMO RTS game (yes, a very niche subgenre!). I have some general architecture questions of how to handle some more complex use-cases, but in particular - game state.
You see, players queue up actions of things they would like to do to manage their empire. This can be things like:
- Construct an infrastructure project
- Send a fleet to attack a player
- Send cargo craft to trade between planets
- Research technologies
.etc.
I originally started writing this in PHP before realising that the real-time requirement on the server-side was just going to be too difficult to handle/solve. So what do I mean by "real-time" in this post?
Let's say for example that a player starts constructing some infrastructure. While that building is being constructed, their planet is attacked and their available resources is diminished to a point where they can no longer sustain all the activities on their planet (let's assume they're researching some technology whilst also constructing a building). The logic here, is that the system will use a FIFO approach, whereby - each item being produced/created, starting from the end, will be paused until there are enough resources to continue constructing the remaining items, at which point, once those are completed, the next item in the list would then be resumed.
Similarly, let's say that a player has those same items in progress, and they complete some research that improves construction time for any buildings. At that point, I would then need to update those constructon projects by reducing their total time to completion.
Where this gets tricky (and why it's quite challenging (although not imkpossible) in PHP with say, backend queue servers), is that when these events occur, the system needs to recognise it's impact across the game's state. In this instance, I would need to then update those running processes and disable the right ones, whilst also doing things like notifying the player, updating the UI.etc.
I'm curious how you would best solve this using Elixir. My view here is that I'd have all these long-running processes (some could take hours, or even days), and somehow manage them by sending them messages to pause/cancel/stop.etc.