Search Unity

Any Example/Tutorial on "Replay" - doing battle in small program and only rendering results...

Discussion in 'General Discussion' started by micahneveu, Feb 2, 2021.

  1. micahneveu

    micahneveu

    Joined:
    Jul 4, 2019
    Posts:
    7
    Hi all! (again),
    This is the next part of my previous question. With the help of the community here, I'm taking the path of writing my combat engine as a callable application that will output the events that occurred during the battle, organized by the "time" they occurred.

    Does anyone know of a tutorial or a place to start, what I want to do is this:
    CombatEngine runs battles between players "offline" and generates a battle report.
    The player uses unity to load the battle report and watch the outcome, so I'm thinking I'd need something generated like:
    time: 00.00.030 ship X fires missile #1 from vector3 with vector3
    time: 00.00.100 ship Y destroys missile #1 at vector3 with <effect> whatever...

    Any tutorials or hints on how I might start this? Basically, having an event for everything I want to happen goes without saying, but if there is some work already done on this sort of thing, that would be beneficial.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Just brain storming...

    If I didn't need any Unity features, like physics, for the combat I might just execute the combat in its own thread. Since it is offline it doesn't need to be time or framerate dependent. As you're simulating the battle you log everything needed to replay it. Once the battle is complete you pass the results back to the main thread, probably in a concurrentqueue. You might actually have one or more threads that just wait for incoming battles to simulate from another concurrentqueue, run through them as fast as possible, and send results back to the main thread.

    If it needs Unity features and needs to run like a regular Unity game, I might write everything needed to set up the battle to a temp file. Have the main game/application launch a headless build to simulate the battle, and pass the temp file as a command line argument. The temp file is read, the battle is run, and all movements/actions are logged. At the end of the battle the results are written to another file. The main game/app reads this file for the results to send to the players to replay. You could replace the file reading/writing with either use of a database or use of real time networking. The file way is just the simplest to implement. Which way you'd do it really depends on at what scale you need this system to function. (If you're simulating thousands of battles at once, with millions per day, you'd take a different approach than if you were simulating an occasional battle here and there)

    Good luck