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) {
24 LOG_INFO("playerdemo: ", this.netname, " closed");
25 fclose(this.playerdemo_fh);
27 this.playerdemo_mode = 0;
29 void playerdemo_open_read(entity this, string f)
31 playerdemo_shutdown(this);
32 this.playerdemo_mode = PLAYERDEMO_MODE_READING;
33 this.playerdemo_fh = fopen(f, FILE_READ);
34 this.playerdemo_starttime = time - 1;
35 this.playerdemo_time = stof(fgets(this.playerdemo_fh));
36 this.playerdemo_time += this.playerdemo_starttime;
37 set_movetype(this, MOVETYPE_NONE);
38 LOG_INFO("playerdemo: ", this.netname, " reading from ", f);
40 void playerdemo_open_write(entity this, string f)
42 playerdemo_shutdown(this);
43 this.playerdemo_mode = PLAYERDEMO_MODE_WRITING;
44 this.playerdemo_fh = fopen(f, FILE_WRITE);
45 this.playerdemo_starttime = time - 1;
46 LOG_INFO("playerdemo: ", this.netname, " writing to ", f);
47 LOG_INFO("WARNING: playerdemo file format is incomplete and not stable yet. DO NOT RELY ON IT!");
49 #define PLAYERDEMO_FIELD(ent, func, t, f) func##t(ent, f, #f);
50 #define PLAYERDEMO_FIELDS(ent, func) \
51 PLAYERDEMO_FIELD(ent, func, originvector, origin) \
52 PLAYERDEMO_FIELD(ent, func, vector, angles) \
53 PLAYERDEMO_FIELD(ent, func, sizevector, mins) \
54 PLAYERDEMO_FIELD(ent, func, sizevector, maxs) \
55 PLAYERDEMO_FIELD(ent, func, vector, v_angle) \
56 PLAYERDEMO_FIELD(ent, func, modelstring, model) \
57 PLAYERDEMO_FIELD(ent, func, string, playermodel) \
58 PLAYERDEMO_FIELD(ent, func, float, skin) \
59 PLAYERDEMO_FIELD(ent, func, string, playerskin) \
60 PLAYERDEMO_FIELD(ent, func, float, frame) \
61 PLAYERDEMO_FIELD(ent, func, float, effects) \
62 /* PLAYERDEMO_FIELD(ent,func,float,switchweapon) */ \
63 PLAYERDEMO_FIELD(CS(ent), func, float, button0) /* TODO: PHYS_INPUT_BUTTON_ATCK */ \
64 PLAYERDEMO_FIELD(CS(ent), func, float, button3) /* TODO: PHYS_INPUT_BUTTON_ATCK2 */ \
65 PLAYERDEMO_FIELD(CS(ent), func, float, button5) /* TODO: PHYS_INPUT_BUTTON_CROUCH */ \
66 PLAYERDEMO_FIELD(CS(ent), func, float, button6) /* TODO: PHYS_INPUT_BUTTON_HOOK */ \
67 PLAYERDEMO_FIELD(CS(ent), func, float, buttonuse) /* TODO: PHYS_INPUT_BUTTON_USE */ \
68 PLAYERDEMO_FIELD(ent, func, float, flags) \
71 void playerdemo_write_originvector(entity this, .vector f, string name)
73 fputs(this.playerdemo_fh, strcat(vtos(this.(f)), "\n"));
75 void playerdemo_write_sizevector(entity this, .vector f, string name)
77 fputs(this.playerdemo_fh, strcat(vtos(this.(f)), "\n"));
79 void playerdemo_write_vector(entity this, .vector f, string name)
81 fputs(this.playerdemo_fh, strcat(vtos(this.(f)), "\n"));
83 void playerdemo_write_string(entity this, .string f, string name)
85 fputs(this.playerdemo_fh, strcat(this.(f), "\n"));
87 void playerdemo_write_modelstring(entity this, .string f, string name)
89 fputs(this.playerdemo_fh, strcat(this.(f), "\n"));
91 void playerdemo_write_float(entity this, .float f, string name)
93 fputs(this.playerdemo_fh, strcat(ftos(this.(f)), "\n"));
95 void playerdemo_write(entity this)
97 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);
124 this.(f) = strzone(s);
127 void playerdemo_read_modelstring(entity this, .string f, string name)
129 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) {
143 if (this.playerdemo_time < 0) {
148 while (time >= this.playerdemo_time) {
149 PLAYERDEMO_FIELDS(this, playerdemo_read_)
151 time = this.playerdemo_time;
152 PlayerPreThink(this);
153 // not running physics though... this is just so we can run weapon stuff
154 PlayerPostThink(this);
156 this.playerdemo_time = stof(fgets(this.playerdemo_fh));
157 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;