Zomis / Games

Many kinds of games, playable in both multiplayer or local play. Replays, spectator mode, and AIs.
https://games.zomis.net
MIT License
17 stars 5 forks source link

Use Kotlin SharedFlows #299

Open Zomis opened 2 years ago

Zomis commented 2 years ago

Kotlin SharedFlow can replace the communication between coroutines in GameFlowImpl instead of channels. Even more so, it should also make it possible to add more different listeners and separate the concerns even better.

Zomis commented 2 years ago

Actually, all event-related things can be SharedFlow instead of the current event-listeners (not to mention the feature system).

However, there are currently some separate branches and stashed changes in my working repository. Changing these things would cause lots of potential merge conflicts, but as all the changes (the diffs) are stored, I think it's worth it to just keep going and perform it. Besides, some branches contain work on the Vue client which will not be affected.

Zomis commented 2 years ago

This would be a good replacement for #41

Zomis commented 2 years ago

Actually, important thing to remember is that SharedFlows are asynchronous, so only time-irrelevant events should be converted to SharedFlows.

For example, pre-move events that allows listeners to add pre-randomised data are not possible with a SharedFlow, because they need to have the opportunity to change the state before the code moves on.

Zomis commented 2 years ago

Things that needs to have the opportunity to change state before code moves on can use a Deferred. This has now been introduced for PreMove and PreSetup.

However, currently these are being marked as completed after all GameListeners has handled the events. So if this would change to SharedFlows, it would be a lot more complicated to mark something as completed.