Hello guys!
This is my first post in this forum, I am not so used to do this, usually I always find solutions to my problems but this time, I already invested a huge amount of time and I struggle.
I am working on a cooperative 2.5D platformer, using only web technologies. You can find the last version here => https://dev.compositethegame.com/en (IF YOU ARE NOT IN EUROPE, YOU WILL EXPERIENCE HIGH LATENCY AND ITS NOT REALLY PLAYABLE, that's why I am here)
All the code of this project is open source and is hosted here => https://github.com/benjaminbours/Composite/tree/level-builder-core-back
So basically, in term of design, I followed, mainly this => https://www.gabrielgambetta.com/, so I have an authoritative server, and client side prediction. On the URL of the project I shared before, if you are close to Strasbourg in France, you might have the chance to experience the best possible experience, where the game is performant enough and not too laggy.
So basically, my issue is that some people were complaining about latency issues or performance issues. Digging more into it, what is consuming most of the client resources is state reconciliation and state interpolation / display state. Correct me if I am wrong but I think what I did so far is that, I am delaying the state displayed, depending of the latency, which in case of low latency is find and provide a good experience, because all state corrections are applied off screen and I only display clean game state to the client. In case of high latency it sucks hard, it's either unplayable because it's too much delayed, or the prediction history buffer is exploding the memory because it has to keep a lot of states in memory to correct when receiving an update from the server.
My design is obviously bad, I feel I miss something. I know in the code I provided, the interpolation usage is terrible. I can see there are so many rooms for optimizations and to have more control over the performance accordingly with the latency but I really struggle to make it.
I tried another mechanism, that would be to not have a prediction history but to apply state correction over multiple frames with interpolation direction on the displayed state. It was not successful, again I probably managed it poorly but it was an increasing differences between the state to correct and the corrections.
And even snapping completely the position to force them, in case of players collisions, it creates multiple weird teleportation, for probably 1 seconds before it stabilizes. Its not the kind of snap that is accetable, I would have expect one very quick teleportation, not my player being project to the 4 corners of the screen before getting to the correct position.
So to resume, despite my researches, the best result I had was delaying the display state accordingly with latency and correct offscreen. Other techniques, I failed to apply them.
I feel like I am not so far from somethings very performant and stable, but I could really use the eyes of an expert or somebody with experience in order to unlock the situation at this level, because it touches the core of the game. Then I will be able to focus more on the features and the many things the game is missing but I can't focus on something else while this issue, which is compromising the whole project potentially, is still there.
Most of the client side logic about game state management is in 2 files:
- https://github.com/benjaminbours/Composite/blob/level-builder-core-back/front/app/Game/GameStateManager.ts
- https://github.com/benjaminbours/Composite/blob/level-builder-core-back/front/app/Game/App.ts
Thanks in advance for your help 🙏
To really give you the maximum information, I know having a low latency game with a single server in Strasbourg is not viable, I am still developing the project. I plan at some point to have a region selector for people to connect on dedicated server in NA, EU, etc. It will help for sure, but I need to have something more stable than what I have now, before thinking about it. It would just hide some bad design in the development.