]> icculus.org git repositories - divverent/darkplaces.git/blob - server.h
optimized entity updates substantially (or rather, UpdateEnd), nice speedup
[divverent/darkplaces.git] / server.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // server.h
21
22 #ifndef SERVER_H
23 #define SERVER_H
24
25 typedef struct
26 {
27         int                     maxclients;
28         int                     maxclientslimit;
29         struct client_s *clients;               // [maxclients]
30         int                     serverflags;            // episode completion information
31         qboolean        changelevel_issued;     // cleared when at SV_SpawnServer
32 } server_static_t;
33
34 //=============================================================================
35
36 typedef enum {ss_loading, ss_active} server_state_t;
37
38 typedef struct
39 {
40         qboolean        active;                         // false if only a net client
41
42         qboolean        paused;
43         qboolean        loadgame;                       // handle connections specially
44
45         double          time;
46
47         double          frametime;
48
49         int                     lastcheck;                      // used by PF_checkclient
50         double          lastchecktime;
51
52         char            name[64];                       // map name
53         char            modelname[64];          // maps/<name>.bsp, for model_precache[0]
54         struct model_s  *worldmodel;
55         char            *model_precache[MAX_MODELS];    // NULL terminated
56         struct model_s  *models[MAX_MODELS];
57         char            *sound_precache[MAX_SOUNDS];    // NULL terminated
58         char            *lightstyles[MAX_LIGHTSTYLES];
59         int                     num_edicts;
60         int                     max_edicts;
61         edict_t         *edicts;                        // can NOT be array indexed, because
62                                                                         // edict_t is variable sized, but can
63                                                                         // be used to reference the world ent
64         server_state_t  state;                  // some actions are only valid during load
65
66         sizebuf_t       datagram;
67         qbyte           datagram_buf[MAX_DATAGRAM];
68
69         sizebuf_t       reliable_datagram;      // copied to all clients at end of frame
70         qbyte           reliable_datagram_buf[MAX_DATAGRAM];
71
72         sizebuf_t       signon;
73         qbyte           signon_buf[32768]; // LordHavoc: increased signon message buffer from 8192 to 32768
74 } server_t;
75
76
77 #define NUM_PING_TIMES          16
78 #define NUM_SPAWN_PARMS         16
79
80 typedef struct client_s
81 {
82         qboolean                active;                         // false = client is free
83         qboolean                spawned;                        // false = don't send datagrams
84         qboolean                dropasap;                       // has been told to go to another level
85         qboolean                sendsignon;                     // only valid before spawned
86
87 #ifndef NOROUTINGFIX
88         // LordHavoc: to make netquake protocol get through NAT routers, have to wait for client to ack
89         qboolean                waitingforconnect;      // waiting for connect from client (stage 1)
90         qboolean                sendserverinfo;         // send server info in next datagram (stage 2)
91 #endif
92
93         double                  last_message;           // reliable messages must be sent
94                                                                                 // periodically
95
96         struct qsocket_s *netconnection;        // communications handle
97
98         usercmd_t               cmd;                            // movement
99         vec3_t                  wishdir;                        // intended motion calced from cmd
100
101         sizebuf_t               message;                        // can be added to at any time,
102                                                                                 // copied and clear once per frame
103         qbyte                   msgbuf[MAX_MSGLEN];
104         edict_t                 *edict;                         // EDICT_NUM(clientnum+1)
105         char                    name[32];                       // for printing to other people
106         int                             colors;
107
108         float                   ping_times[NUM_PING_TIMES];
109         int                             num_pings;                      // ping_times[num_pings%NUM_PING_TIMES]
110         float                   ping;                           // LordHavoc: can be used for prediction or whatever...
111         float                   latency;                        // LordHavoc: specifically used for prediction, accounts for sys_ticrate too
112
113 // spawn parms are carried from level to level
114         float                   spawn_parms[NUM_SPAWN_PARMS];
115
116 // client known data for deltas
117         int                             old_frags;
118         int                             pmodel;
119
120 #ifdef QUAKEENTITIES
121         // delta compression state
122         float                   nextfullupdate[MAX_EDICTS];
123 #endif
124         // visibility state
125         float                   visibletime[MAX_EDICTS];
126
127 #ifndef QUAKEENTITIES
128         entity_database_t entitydatabase;
129         int                             entityframenumber; // incremented each time an entity frame is sent
130 #endif
131 } client_t;
132
133
134 //=============================================================================
135
136 // edict->movetype values
137 #define MOVETYPE_NONE                   0               // never moves
138 #define MOVETYPE_ANGLENOCLIP    1
139 #define MOVETYPE_ANGLECLIP              2
140 #define MOVETYPE_WALK                   3               // gravity
141 #define MOVETYPE_STEP                   4               // gravity, special edge handling
142 #define MOVETYPE_FLY                    5
143 #define MOVETYPE_TOSS                   6               // gravity
144 #define MOVETYPE_PUSH                   7               // no clip to world, push and crush
145 #define MOVETYPE_NOCLIP                 8
146 #define MOVETYPE_FLYMISSILE             9               // extra size to monsters
147 #define MOVETYPE_BOUNCE                 10
148 #define MOVETYPE_BOUNCEMISSILE  11              // bounce w/o gravity
149 #define MOVETYPE_FOLLOW                 12              // track movement of aiment
150
151 // edict->solid values
152 #define SOLID_NOT                               0               // no interaction with other objects
153 #define SOLID_TRIGGER                   1               // touch on edge, but not blocking
154 #define SOLID_BBOX                              2               // touch on edge, block
155 #define SOLID_SLIDEBOX                  3               // touch on edge, but not an onground
156 #define SOLID_BSP                               4               // bsp clip, touch on edge, block
157 // LordHavoc: corpse code
158 #define SOLID_CORPSE                    5               // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
159
160 // edict->deadflag values
161 #define DEAD_NO                                 0
162 #define DEAD_DYING                              1
163 #define DEAD_DEAD                               2
164
165 #define DAMAGE_NO                               0
166 #define DAMAGE_YES                              1
167 #define DAMAGE_AIM                              2
168
169 // edict->flags
170 #define FL_FLY                                  1
171 #define FL_SWIM                                 2
172 #define FL_CONVEYOR                             4
173 #define FL_CLIENT                               8
174 #define FL_INWATER                              16
175 #define FL_MONSTER                              32
176 #define FL_GODMODE                              64
177 #define FL_NOTARGET                             128
178 #define FL_ITEM                                 256
179 #define FL_ONGROUND                             512
180 #define FL_PARTIALGROUND                1024    // not all corners are valid
181 #define FL_WATERJUMP                    2048    // player jumping out of water
182 #define FL_JUMPRELEASED                 4096    // for jump debouncing
183
184 // entity effects
185
186 #define EF_BRIGHTFIELD                  1
187 #define EF_MUZZLEFLASH                  2
188 #define EF_BRIGHTLIGHT                  4
189 #define EF_DIMLIGHT                     8
190 // added EF_ effects:
191 #define EF_NODRAW                               16
192 #define EF_ADDITIVE                             32  // LordHavoc: Additive Rendering
193 #define EF_BLUE                                 64
194 #define EF_RED                                  128
195
196 #define SPAWNFLAG_NOT_EASY                      256
197 #define SPAWNFLAG_NOT_MEDIUM            512
198 #define SPAWNFLAG_NOT_HARD                      1024
199 #define SPAWNFLAG_NOT_DEATHMATCH        2048
200
201 //============================================================================
202
203 extern cvar_t teamplay;
204 extern cvar_t skill;
205 extern cvar_t deathmatch;
206 extern cvar_t coop;
207 extern cvar_t fraglimit;
208 extern cvar_t timelimit;
209 extern cvar_t pausable;
210 extern cvar_t sv_deltacompress;
211 extern cvar_t sv_maxvelocity;
212 extern cvar_t sv_gravity;
213 extern cvar_t sv_nostep;
214 extern cvar_t sv_friction;
215 extern cvar_t sv_edgefriction;
216 extern cvar_t sv_stopspeed;
217 extern cvar_t sv_maxspeed;
218 extern cvar_t sv_accelerate;
219 extern cvar_t sv_idealpitchscale;
220 extern cvar_t sv_aim;
221 extern cvar_t sv_predict;
222 extern cvar_t sv_stepheight;
223 extern cvar_t sv_jumpstep;
224
225 extern server_static_t svs;                             // persistant server info
226 extern server_t sv;                                     // local server
227
228 extern client_t *host_client;
229
230 extern jmp_buf host_abortserver;
231
232 extern edict_t *sv_player;
233
234 //===========================================================
235
236 void SV_Init (void);
237
238 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
239 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
240 void SV_StartSound (edict_t *entity, int channel, char *sample, int volume, float attenuation);
241
242 void SV_DropClient (qboolean crash);
243
244 void SV_SendClientMessages (void);
245 void SV_ClearDatagram (void);
246
247 int SV_ModelIndex (char *name);
248
249 void SV_SetIdealPitch (void);
250
251 void SV_AddUpdates (void);
252
253 void SV_ClientThink (void);
254 void SV_AddClientToServer (struct qsocket_s     *ret);
255
256 void SV_ClientPrintf (char *fmt, ...);
257 void SV_BroadcastPrintf (char *fmt, ...);
258
259 void SV_Physics (void);
260
261 qboolean SV_CheckBottom (edict_t *ent);
262 qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink);
263
264 void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg);
265
266 void SV_MoveToGoal (void);
267
268 void SV_CheckForNewClients (void);
269 void SV_RunClients (void);
270 void SV_SaveSpawnparms (void);
271 void SV_SpawnServer (char *server);
272
273 #endif
274