1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
/*
Copyright (C) 2003-2006 Andrey Nazarov
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "sv_local.h"
#include "q_fifo.h"
#define MVD_Malloc( size ) Z_TagMalloc( size, TAG_MVD )
#define MVD_Mallocz( size ) Z_TagMallocz( size, TAG_MVD )
#define MVD_CopyString( s ) Z_TagCopyString( s, TAG_MVD )
#define FOR_EACH_MVD( mvd ) \
LIST_FOR_EACH( mvd_t, mvd, &mvd_channel_list, entry )
#define FOR_EACH_MVDCL( cl, mvd ) \
LIST_FOR_EACH( mvd_client_t, cl, &(mvd)->clients, entry )
#define EDICT_MVDCL( ent ) (( mvd_client_t * )( (ent)->client ))
#define CS_NUM( c, n ) ( ( char * )(c) + (n) * MAX_QPATH )
#define MVD_InfoSet( var, val ) \
Cvar_FullSet( var, val, CVAR_SERVERINFO|CVAR_GAME, FROM_CODE )
// game features MVD client supports
#define MVD_FEATURES (GMF_CLIENTNUM|GMF_PROPERINUSE|GMF_WANT_ALL_DISCONNECTS)
#define LAYOUT_MSEC 3000
typedef enum {
LAYOUT_NONE, // no layout at all
LAYOUT_FOLLOW, // display chase target name
LAYOUT_SCORES, // layout of the MVD dummy
LAYOUT_OLDSCORES, // saved at intermission time
LAYOUT_MENU, // MVD main menu
LAYOUT_CLIENTS, // MVD clients list
LAYOUT_CHANNELS // MVD channel list
} mvd_layout_t;
#define FLOOD_SAMPLES 16
#define FLOOD_MASK ( FLOOD_SAMPLES - 1 )
typedef struct mvd_cs_s {
struct mvd_cs_s *next;
int index;
char string[1];
} mvd_cs_t;
typedef struct {
player_state_t ps;
qboolean inuse;
char name[16];
mvd_cs_t *configstrings;
} mvd_player_t;
typedef struct {
/* =================== */
player_state_t ps;
int ping;
int clientNum;
/* =================== */
list_t entry;
struct mvd_s *mvd;
client_t *cl;
qboolean admin;
unsigned begin_time;
mvd_player_t *target, *oldtarget;
int chase_mask;
float fov;
int uf;
mvd_layout_t layout_type;
unsigned layout_time;
int layout_cursor;
unsigned floodSamples[FLOOD_SAMPLES];
unsigned floodHead;
unsigned floodTime;
usercmd_t lastcmd;
//short delta_angles[3];
int jump_held;
} mvd_client_t;
#define MAX_MVD_NAME 16
typedef enum {
MVD_DEAD, // no gamestate received yet, unusable for observers
MVD_WAITING, // buffering more frames, stalled
MVD_READING, // reading frames
MVD_NUM_STATES
} mvd_state_t;
struct gtv_s;
// FIXME: entire struct is > 400 K in size!
// need to eliminate those large static arrays below...
typedef struct mvd_s {
list_t entry;
mvd_state_t state;
int id;
char name[MAX_MVD_NAME];
struct gtv_s *gtv;
qboolean (*read_frame)( struct mvd_s * );
qboolean (*forward_cmd)( mvd_client_t * );
// demo related variables
qhandle_t demorecording;
char *demoname;
// delay buffer
fifo_t delay;
size_t msglen;
unsigned num_packets, min_packets;
unsigned underflows, overflows;
unsigned framenum;
// game state
char gamedir[MAX_QPATH];
char mapname[MAX_QPATH];
int servercount;
int maxclients;
edict_pool_t pool;
cm_t cm;
vec3_t spawnOrigin;
vec3_t spawnAngles;
int pm_type;
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]; // 133 K
edict_t edicts[MAX_EDICTS]; // 266 K
mvd_player_t *players; // [maxclients]
mvd_player_t *dummy; // &players[clientNum]
int numplayers; // number of active players in frame
int clientNum;
mvd_flags_t flags;
char layout[MAX_STRING_CHARS];
char oldscores[MAX_STRING_CHARS]; // layout is copied here
qboolean intermission;
qboolean dirty;
// UDP client list
list_t clients;
} mvd_t;
//
// mvd_client.c
//
extern list_t mvd_channel_list;
extern mvd_t mvd_waitingRoom;
extern qboolean mvd_dirty;
#ifdef _DEBUG
extern cvar_t *mvd_shownet;
#endif
void MVD_Destroyf( mvd_t *mvd, const char *fmt, ... )
q_noreturn q_printf( 2, 3 );
void MVD_Shutdown( void );
mvd_t *MVD_SetChannel( int arg );
void MVD_File_g( genctx_t *ctx );
void MVD_Spawn_f( void );
void MVD_StreamedStop_f( void );
void MVD_StreamedRecord_f( void );
void MVD_Register( void );
int MVD_Frame( void );
//
// mvd_parse.c
//
void MVD_ParseMessage( mvd_t *mvd );
void MVD_ParseEntityString( mvd_t *mvd, const char *data );
void MVD_FreePlayer( mvd_player_t *player );
//
// mvd_game.c
//
extern mvd_client_t *mvd_clients; // [maxclients]
void MVD_SwitchChannel( mvd_client_t *client, mvd_t *mvd );
void MVD_RemoveClient( client_t *client );
void MVD_BroadcastPrintf( mvd_t *mvd, int level,
int mask, const char *fmt, ... ) q_printf( 4, 5 );
void MVD_PrepWorldFrame( void );
void MVD_GameClientNameChanged( edict_t *ent, const char *name );
void MVD_GameClientDrop( edict_t *ent, const char *reason );
|