00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _REPLAY_H
00026
00027 #include <stdio.h>
00028 #include <GL/gl.h>
00029 #include <GL/glu.h>
00030 #include <SDL/SDL.h>
00031 #ifdef __APPLE__
00032 #include <SDL_image/SDL_image.h>
00033 #else
00034 #include <SDL/SDL_image.h>
00035 #endif
00036 #include <string>
00037 #include <iostream>
00038 #include <fstream>
00039 #include <cmath>
00040 #include <cassert>
00041
00042 using namespace std;
00043
00044 #include <vamos/geometry/Three_Vector.h>
00045 #include <vamos/geometry/Three_Matrix.h>
00046
00047 #include "utility.h"
00048 #include "timer.h"
00049 #include "gamestate.h"
00050
00051 #include "globals.h"
00052
00053 #define MAX_PACKETS 83000
00054
00055
00056 #define FUNCTION_CHARS 50
00057
00058 #define MAX_STATES 3600
00059
00060 #define REPLAY_VERSION "VDRIFTREPLAYV06"
00061
00062 #define CHAR_FUNCNUM 0
00063 #define CHAR_STATE 1
00064 #define CHARDATA_SIZE 2
00065
00066 #define FUNCTION_NETCONTROL 255
00067 #define FUNCTION_STATEINFO 254
00068 #define FUNCTION_NOOP 253
00069 #define FUNCTION_PACKET_ARRAY 252
00070
00071
00072 #define STATE_FREQUENCY 1.0
00073
00074 #define DBG_REPLAY false
00075
00076 struct REPLAY_PACKET
00077 {
00078
00079
00080 unsigned char chardata[CHARDATA_SIZE];
00081 float val;
00082 float time;
00083
00084 };
00085
00086 struct FUNCTION_MEMORY
00087 {
00088 string func_name;
00089 float oldval;
00090 float newval;
00091 bool held;
00092 bool active;
00093 double lastupdateat;
00094 };
00095
00096 struct FUNCTION_MEMORY_SYNC
00097 {
00098 float oldval;
00099 float newval;
00100 bool held;
00101 bool active;
00102 double lastupdateat;
00103 };
00104
00105 class CARSTATE
00106 {
00107 public:
00108 double time;
00109
00110 Vamos_Geometry::Three_Vector chassispos;
00111 Vamos_Geometry::Three_Matrix chassisorientation;
00112 Vamos_Geometry::Three_Vector chassisvel;
00113 Vamos_Geometry::Three_Vector chassisangvel;
00114 double suspdisp[4];
00115 double suspcompvel[4];
00116 Vamos_Geometry::Three_Vector whlangvel[4];
00117 int gear;
00118 double enginespeed;
00119 double clutchspeed;
00120 double enginedrag;
00121 double tirespeed[4];
00122
00123 int segment;
00124
00125 FUNCTION_MEMORY_SYNC * funcmem;
00126 int fnum;
00127
00128 void CopyFrom(CARSTATE other);
00129
00130 void WriteToFile(FILE * fout);
00131 void WriteVector(Vamos_Geometry::Three_Vector wv, FILE * fout);
00132 void WriteMatrix(Vamos_Geometry::Three_Matrix wv, FILE * fout);
00133
00134 void ReadFromFile(FILE * fin);
00135 void ReadVector(Vamos_Geometry::Three_Vector &wv, FILE * fin);
00136 void ReadMatrix(Vamos_Geometry::Three_Matrix &wv, FILE * fin);
00137 };
00138
00139 class REPLAY
00140 {
00141 private:
00142 int num_packets;
00143 REPLAY_PACKET packet[MAX_PACKETS];
00144 FUNCTION_MEMORY * funcmem;
00145 int fnum;
00146 bool replay;
00147 FILE * rf;
00148 double timeindex;
00149 bool playing;
00150 int cur_packet;
00151 void PlayProcessFrame();
00152 float playend;
00153
00154 void WriteCarState();
00155 void RememberCarState();
00156 CARSTATE state_mem[MAX_STATES];
00157 int num_states;
00158 CARSTATE loadstate;
00159 bool state_to_load;
00160 int cur_state;
00161
00162 CARSTATE * GetNextState(double until);
00163 REPLAY_PACKET * GetNextPacket(double until);
00164
00165 bool ghostcar;
00166
00167 string replaycar;
00168 int replaypaint;
00169
00170 public:
00171 void BuildFuncMem(FUNCTION_MEMORY * &fmem, int & fnm);
00172
00173 REPLAY();
00174 ~REPLAY();
00175 void Clear();
00176 void Start();
00177 void AddRecord(string newdofunction, float newval, int newstate);
00178 void IncrementFrame();
00179 void Stop();
00180 float Recording();
00181
00182 bool PlayStart(string replayname);
00183 bool PlayStart(string replayname, bool ngc);
00184 void PlayStop();
00185 float Playing();
00186 int GetNumFuncs();
00187 FUNCTION_MEMORY GetFunc(int idx);
00188 int GetFuncIdx(string funcname);
00189 void PlayIncrement();
00190 double GetTime();
00191
00192 CARSTATE curstate;
00193 CARSTATE * LoadState();
00194
00195
00196 void Jump(double newtime);
00197
00198
00199 int Get_FuncChars() {return FUNCTION_CHARS;}
00200 int Get_CharState() {return CHAR_STATE;}
00201 int Get_CharFuncnum() {return CHAR_FUNCNUM;}
00202 int Get_FuncNetControl() {return FUNCTION_NETCONTROL;}
00203 int Get_FuncStateInfo() {return FUNCTION_STATEINFO;}
00204 int Get_FuncNoop() {return FUNCTION_NOOP;}
00205 int Get_FuncPacketArray() {return FUNCTION_PACKET_ARRAY;}
00206
00207
00208 void WriteHeader(FILE * rf, FUNCTION_MEMORY * fmem, int fnm, int carnumber);
00209 void WritePackets(FILE * rf, REPLAY_PACKET * pak, int pnum, CARSTATE * smem, int snum);
00210
00211 bool GhostCar() {return ghostcar;}
00212 string ReplayCar() {return replaycar;}
00213 int ReplayPaint() {return replaypaint;}
00214 };
00215
00216 #define _REPLAY_H
00217 #endif