track recorder

F60c8f6e3eed786eb071eb2cf6f9d5e7
0
Gundark 101 May 23, 2011 at 00:26

I’m working on a flight sim ( in Unity if that matters ) and so far it’s not bad. But I would like to implement track recorder ( like ones in Il-2 or Lock-on ), so that i could watch track and be able to switch cameras.
One possibility is to create an array of positions and use it as a waypoints. But I don’t feel that this is the complete solution, becouse i need to record all events in game. Could someone point me where to look? Any hint, (possibly an simple code example ), anything to start with?

3 Replies

Please log in or register to post a reply.

6837d514b487de395be51432d9cdd078
0
TheNut 179 May 23, 2011 at 17:49

You pretty much have to periodically record state information. Simulation time, positional data, landing gear state, flaps, engine state, fuel, wind, etc. You need to record down all the possible states and then construct a way to serialize that information. The laziest approach to this is to define a struct that has all the possible state information.

struct StateData
{
     unsigned int time; // time in millisec since start of simulation
     vector3 position;
     vector3 windVelocity;
     float fuel;
     bool landingGearRetracted;
}

The problem with this approach is that it can consume far more memory than needed. For instance, landing gear usually only gets retracted once during flight, so it doesn’t make sense to record it every time. A solution to this is to modify the struct like so

class Property
{
public:
     unsigned int Id;

     virtual const char *Serialize () {} = 0;
     virtual unsigned int Deseralize (const char *data) {} = 0;
};

class PositionProperty : public Property
{
public:
     vector3 Data;

     PositionProperty () : Id(0) {}

     virtual const char *Serialize ()
     {
          // Serialize vector3 Data member to string for output to file
     }

     virtual unsigned int Deseralize (const char *data)
     {
          // Deserialize vector3 Data member from string to vector3
          return 12;
     }
};

class FuelProperty : public Property
{
public:
     float Data;

     FuelProperty () : Id(1) {}

     virtual const char *Serialize () // same thing here as was done for position
     virtual unsigned int Deseralize (const char *data)  // same thing here as was done for position
};

struct StateData
{
     unsigned int time;
     vector<Property *> property;
}

Position and fuel properties were provided as examples here, but you can define as many state properties as you need. At each interval you record the properties that have changed. If only positional data has changed since the last record, then you only record positional data. This keeps the record file down to a minimum.

The unique id of each property helps you deserialize the information from disk back into your program later. 0 in this example maps to positional data and so you deserailize the next 12 bytes (4 bytes per vector component [X,Y,Z]) into a positional property object. The position property class returns that it has read 12 bytes of data and so the file parser will advance 12 bytes and begin processing the next property.

Keep in mind there are holes in the implementation here, but I think there’s enough here to steer you onto a possible solution.

F60c8f6e3eed786eb071eb2cf6f9d5e7
0
Gundark 101 May 24, 2011 at 06:18

Thank you, this will do for the start.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Jun 02, 2011 at 02:07

What you do is record the controls, dont record anything else, everything else should stay in synch as long as the input (the airoplane controls) is exact.