Hello,
I want to make a game using MonoGame (shocker, I know), and I know the gist of drawing things to the screen, the content pipeline, playing sounds…
But what I’m trying to do is lay a solid foundation for my game’s architecture. I’m working with a concept of a logic layer and view layers, and then a message queue to communicate between them. So far so good but what I’m trying to do with encoding is where my brain’s been thrashing a bit.
Before I continue, the reason I’m tackling this problem is because I want to (a) support network play eventually, and (b) have a foundation that lets me be productive cuz I’m one dev with other stuff I need to do (like a job).
The general idea was first to support an encoding of everything the view needs to know to draw to the screen each tick. The immediate fear is being drowned in encoding-decoding performance hits, but I’m not 100% familiar with the performance levels of these things so I thought I’d explore the option.
So, I was tossing around a couple of ideas. The first one was a byte-based solution–define encodings of messages in bytes, sorta like bytecode. The problem I ran into first was encoding data for the messages–this property has this value, that property has that value, etc. I could get reasonably small messages if I wanted 2-3 byte numbers*, but then encoding strings was going to be a pain. But the bigger speed bump was that Microsoft actually warns that binary deserialization is always dangerous for security reasons.
So then I figured I’d use JSON encoding. Again, I’m concerned about drowning in Serialization and Deserialization, but then I want to optimize for the biggest concern, which is network play, and if I can’t handle the Serialization and Deserialization locally, I can’t handle it over the network. So after some reading about how network play works, I figured if I do action messages that are sent once and status messages that are sent occasionally, I can give the view (local or network) enough information to chart out the course of things and predict what it needs to do. Obviously this is much less chatty then sending the state of the world every tick, and it has a bonus in that by treating the local view like a network client (at least in terms of serialization) I’ll be able to notice when things are bogged down by too much serialization.
Thank you for reading this far. My question is–of the above approaches, which seems best? Did I abandon anything too soon? Is there a gotcha lying around the corner? Is there a better way I’m missing?
Thanks for your time.
EDIT: I should also mention I want to do a lot of procedural generation of content and areas, and be able to push updates without recompiling, which is another reason I was looking at encodings.