Reactive Behavior

In previous articles I only mentioned turn-based games for simplicity. But if this architecture can only handle turn-based games, it’s not really helpful. Let’s see what we can do about it.

Blocking v.s. Non-blocking

In blocking behavior, the game system notifies clients and waits for feedback inside a step.
In non-blocking behavior, the game system reacts to every client’s feedback/input.
There’s not that much difference between blocking and non-blocking behavior. All we have to do is redefine the step.
We can define the step as a trigger. That means player feedback pushes the game forward. The game system waits for triggers. And with a little trick we can have reactive system.
Let’s see an example.

Here 4 players can play cards freely, either place a card from hand to table, or activate a card effect.
When entering this phase, the game system notifies all players to start a session locally, and DO NOT wait for feedback.
Now one player clicks a card and sends the feedback to game system. The message includes the choice and trigger.
When game system receives the feedback, it runs the logic of the given trigger with the message sent as input.
In the end, whenever a player performs an action, the system will always respond.

But here’s a warning. Since players can send messages to game system at the same time, you need to handle concurrency correctly.

Streaming v.s. Non-streaming

If we can achieve non-blocking behavior, we can make any game we want, right?
For example, for FPS game, we can use the same way to implement the logic.
If you have a perfect network, the answer is yes. If you just run the games on local host, it can work.
However, there’s something completely different. I will define two terms:
streaming game: user input is continuous.
non-streaming game: user input is discrete.

Chess is obvious discrete. You think for some time and make a decision.
MOBA is also discrete. You can make several moves during one second, but the number won’t be more than 6, I bet.
FPS is continuous. You press W and your character keeps moving forward. You move your mouse and your character rotates.

Why the architecture can’t handle continuous games? Because the way how synchronization is done.
The data structure updates and instructions must be within reasonable number, or else player may experience frequent lags on the Internet.

In non-streaming games, since user input is discrete, the number can be controlled.
In streaming games, the continuous input will generate huge number of instructions. Each time you rotate your camera, a thousand instructions. Boom.
And notice that in MOBA you move your camera too, but this won’t change the scene. So that’s only locally changing something and that can work.