1 #include "playerdemo.qh"
6 #include "playerdemo.qh"
7 #include <common/state.qh>
11 .float playerdemo_mode;
12 .float playerdemo_starttime;
13 .float playerdemo_time;
14 const float PLAYERDEMO_MODE_OFF = 0;
15 const float PLAYERDEMO_MODE_READING = 1;
16 const float PLAYERDEMO_MODE_WRITING = 2;
17 void playerdemo_init(entity this)
19 this.playerdemo_mode = PLAYERDEMO_MODE_OFF;
21 void playerdemo_shutdown(entity this)
23 if(this.playerdemo_mode != PLAYERDEMO_MODE_OFF)
25 LOG_INFO("playerdemo: ", this.netname, " closed");
26 fclose(this.playerdemo_fh);
28 this.playerdemo_mode = 0;
30 void playerdemo_open_read(entity this, string f)
32 playerdemo_shutdown(this);
33 this.playerdemo_mode = PLAYERDEMO_MODE_READING;
34 this.playerdemo_fh = fopen(f, FILE_READ);
35 this.playerdemo_starttime = time - 1;
36 this.playerdemo_time = stof(fgets(this.playerdemo_fh));
37 this.playerdemo_time += this.playerdemo_starttime;
38 set_movetype(this, MOVETYPE_NONE);
39 LOG_INFO("playerdemo: ", this.netname, " reading from ", f);
41 void playerdemo_open_write(entity this, string f)
43 playerdemo_shutdown(this);
44 this.playerdemo_mode = PLAYERDEMO_MODE_WRITING;
45 this.playerdemo_fh = fopen(f, FILE_WRITE);
46 this.playerdemo_starttime = time - 1;
47 LOG_INFO("playerdemo: ", this.netname, " writing to ", f);
48 LOG_INFO("WARNING: playerdemo file format is incomplete and not stable yet. DO NOT RELY ON IT!");
50 #define PLAYERDEMO_FIELD(ent,func,t,f) func##t(ent,f,#f);
51 #define PLAYERDEMO_FIELDS(ent,func) \
52 PLAYERDEMO_FIELD(ent,func,originvector,origin) \
53 PLAYERDEMO_FIELD(ent,func,vector,angles) \
54 PLAYERDEMO_FIELD(ent,func,sizevector,mins) \
55 PLAYERDEMO_FIELD(ent,func,sizevector,maxs) \
56 PLAYERDEMO_FIELD(ent,func,vector,v_angle) \
57 PLAYERDEMO_FIELD(ent,func,modelstring,model) \
58 PLAYERDEMO_FIELD(ent,func,string,playermodel) \
59 PLAYERDEMO_FIELD(ent,func,float,skin) \
60 PLAYERDEMO_FIELD(ent,func,string,playerskin) \
61 PLAYERDEMO_FIELD(ent,func,float,frame) \
62 PLAYERDEMO_FIELD(ent,func,float,effects) \
63 /* PLAYERDEMO_FIELD(ent,func,float,switchweapon) */ \
64 PLAYERDEMO_FIELD(CS(ent),func,float,button0) /* TODO: PHYS_INPUT_BUTTON_ATCK */ \
65 PLAYERDEMO_FIELD(CS(ent),func,float,button3) /* TODO: PHYS_INPUT_BUTTON_ATCK2 */ \
66 PLAYERDEMO_FIELD(CS(ent),func,float,button5) /* TODO: PHYS_INPUT_BUTTON_CROUCH */ \
67 PLAYERDEMO_FIELD(CS(ent),func,float,button6) /* TODO: PHYS_INPUT_BUTTON_HOOK */ \
68 PLAYERDEMO_FIELD(CS(ent),func,float,buttonuse) /* TODO: PHYS_INPUT_BUTTON_USE */ \
69 PLAYERDEMO_FIELD(ent,func,float,flags) \
72 void playerdemo_write_originvector(entity this, .vector f, string name)
74 fputs(this.playerdemo_fh, strcat(vtos(this.(f)), "\n"));
76 void playerdemo_write_sizevector(entity this, .vector f, string name)
78 fputs(this.playerdemo_fh, strcat(vtos(this.(f)), "\n"));
80 void playerdemo_write_vector(entity this, .vector f, string name)
82 fputs(this.playerdemo_fh, strcat(vtos(this.(f)), "\n"));
84 void playerdemo_write_string(entity this, .string f, string name)
86 fputs(this.playerdemo_fh, strcat(this.(f), "\n"));
88 void playerdemo_write_modelstring(entity this, .string f, string name)
90 fputs(this.playerdemo_fh, strcat(this.(f), "\n"));
92 void playerdemo_write_float(entity this, .float f, string name)
94 fputs(this.playerdemo_fh, strcat(ftos(this.(f)), "\n"));
96 void playerdemo_write(entity this)
98 if(this.playerdemo_mode != PLAYERDEMO_MODE_WRITING)
100 fputs(this.playerdemo_fh, strcat(ftos(time - this.playerdemo_starttime), "\n"));
101 PLAYERDEMO_FIELDS(this, playerdemo_write_)
103 void playerdemo_read_originvector(entity this, .vector f, string name)
105 setorigin(this, stov(fgets(this.playerdemo_fh)));
107 void playerdemo_read_sizevector(entity this, .vector f, string name)
109 this.(f) = stov(fgets(this.playerdemo_fh));
110 setsize(this, this.mins, this.maxs);
112 void playerdemo_read_vector(entity this, .vector f, string name)
114 this.(f) = stov(fgets(this.playerdemo_fh));
116 void playerdemo_read_string(entity this, .string f, string name)
118 string s = fgets(this.playerdemo_fh);
125 this.(f) = strzone(s);
128 void playerdemo_read_modelstring(entity this, .string f, string name)
130 string s = fgets(this.playerdemo_fh);
134 void playerdemo_read_float(entity this, .float f, string name)
136 this.(f) = stof(fgets(this.playerdemo_fh));
138 float playerdemo_read(entity this)
140 if(this.playerdemo_mode != PLAYERDEMO_MODE_READING)
142 if(this.playerdemo_time < 0)
146 while(time >= this.playerdemo_time)
148 PLAYERDEMO_FIELDS(this, playerdemo_read_)
150 time = this.playerdemo_time;
151 PlayerPreThink(this);
152 // not running physics though... this is just so we can run weapon stuff
153 PlayerPostThink(this);
155 this.playerdemo_time = stof(fgets(this.playerdemo_fh));
156 if(this.playerdemo_time == 0)
158 this.playerdemo_time = -1;
161 this.playerdemo_time += this.playerdemo_starttime;
163 this.velocity = '0 0 0';
164 CS(this).movement = '0 0 0';
165 this.dmg_take = 0; // so screen doesn't stay blurry
167 this.dmg_inflictor = NULL;