I am making my first game and I have realised that I don’t know how I should structure my game loop.
Currently it’s done this way:
I have 2 controllers (or state machines, call however you want) on the server – 1 for lobby and 1 for game. They have some states inside. I have controllers with same names and states on client.
Controllers on server send to particular clients through remotes signals to change state.
With this simple concept I immediately got some problems:
- Let’s imagine we are currently at state where timer on client ticks and updates how much time is left for the finish of the voting. Now, when player enters the game, he can’t simply start his timer – he needs a timestamp of start of the timer for timers to be synced. So for that reason I am not just sending signal to client, but I also started to send some additional information.
Then I got another problem:
- My game controller has state “Hiding” and state “Round” and some other states. On “Hiding” I call some functions, enable some UI and so on. On “Round” I also do it. And I allow players to join the round if they were not in it. Now if player joins in the moment of “Hiding” state I need to call some functions in his client controller from previous states (enable some UI that relates to all game, enable some scripts that are also related to all game, fire some signals and so on). With the same time some of functions I don’t need to call (enable some temporary UI that was related only to states before and so on). But if player joins in the moment of “Round” state, he needs to also do all this things, but he also needs to call all required functions from state “Hiding” and this chain goes on.
It becomes a mess and I start to realize that I don’t know how to structure all of that. Maybe I don’t even need controllers and there are easier ways? Please, share some of your experience.