Search Unity

How to calculate the game changes fast in loading screen before game start

Discussion in 'Scripting' started by Michelle_Ca, Oct 10, 2019.

  1. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    I have a simulation game where the players can leave the game and close the application and when they return the game should be as if it was working all the time, as if the variables were constantly changing all the time I do this by calculating the time between close and back

    The game will be multiplayer and linked to a PlayFab server for storing data and using time
    I have some ideas to achieve that :
    - unbind view, recalculate models, bind view back
    - or update time component few times
    - or push few values to time thread.
    what i need to separate architecture to Data/Logic/View layers and after game resumes update only Data/Logic layers

    i just need your advice to choose the best game architecture for this case,and where can I learn the steps to work on this, any educational source or explanation of this situation?
     
    Last edited: Oct 11, 2019
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Can you please restate your question more clearly? I don't know what you're saying in your title, nor what you're actually describing with your 3 layers you envision or what you mean by "using time".
     
    Michelle_Ca likes this.
  3. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Thank you for trying to help !
    I have a simulation game where the players can leave the game and close the application and when they return the game should be as if it was working all the time, as if the variables were constantly changing all the time I do this by calculating the time between close and back but the question here is : How do I use this time difference to make the game calculate all changes quickly before the loading screen?
     
  4. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    I mean, when the players return to the game, it should appear to them as if the application was running in the background of the device all the time and the game was continuing to work all the time, which means a significant change in the values and movement of elements within the game
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I do a small amount of this with skill training in my game. When the game is running I periodically apply training to whatever skill is being trained, and record a timestamp by converting DateTime.Now.Ticks to seconds and saving that. Whenever I recalculate the amount of applied training to the skill, I compare the last timestamp to the current timestamp and add the amount of time between those numbers to the amount of time the skill has trained. So it doesn't matter if I last updated the skill 3 seconds ago or 3 years ago, it works the same.

    So I don't actually differentiate between offline time and online time for that system, nor do I specifically try to track how long the game has been offline. Your idea sounds more complicated, but you might be able to still do something similar.
     
    Michelle_Ca likes this.
  6. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    If you cannot let it run all the time like an MMORPG all you have left is to fake it. As long as 1 person is online keep the game running as is, if the first person comes back after absence of all players calculate the time you want to simulate and then only update the key indicators a player would notice.

    Depending on how complex your game is you also maybe can get away with simply letting the game run without rendering once the first player reconnects, as this should be faster than doing it inclusive rendering.

    However if this is also not feasible you need to decide how accurate it must be:
    Simple: Update all variables by delta gain/loss* time
    Complex and fairly accurate: Build a decision graph, where each node is a key point in time, each edge represent a time frame without a major decision in between, ensure the graph is acyclic, order the nodes by their time value and then evaluate the graph (or do build it step by step, which is more memory and cpu friendly but a little bit more complex to grasp). Then simply let the simulation run on the graph by walking along it. On each node decide what happens next, calculate the delta time/distance to the next node, update all variables with delta gain/loss * time. Repeat until you reach your current point in time (so essentially what this does is to run the whole game by skipping similar sections in time which means less evaluations)
     
    Michelle_Ca likes this.
  7. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Thank you for this useful idea !