]> git.xonotic.org Git - xonotic/darkplaces.git/blob - world.h
Add qdefs.h and qstats.h to split up quakedef.h. Make a lot of headers standalone...
[xonotic/darkplaces.git] / world.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 // world.h
21
22 #ifndef WORLD_H
23 #define WORLD_H
24
25 #include "qtypes.h"
26 #include "qdefs.h"
27 #include "cvar.h"
28 #include "com_list.h"
29 #include "collision.h"
30 #include "matrixlib.h"
31 #include "r_textures.h"
32 typedef struct model_s dp_model_t;
33
34 #define MOVE_NORMAL     0
35 #define MOVE_NOMONSTERS 1
36 #define MOVE_MISSILE    2
37 #define MOVE_WORLDONLY  3
38 #define MOVE_HITMODEL   4
39
40 #define AREA_GRID 128
41 #define AREA_GRIDNODES (AREA_GRID * AREA_GRID)
42
43 typedef struct link_s
44 {
45         llist_t list;
46         int entitynumber;
47 } link_t;
48
49 typedef struct world_physics_s
50 {
51         // for ODE physics engine
52         qbool ode; // if true then ode is activated
53         void *ode_world;
54         void *ode_space;
55         void *ode_contactgroup;
56         // number of constraint solver iterations to use (for dWorldQuickStep)
57         int ode_iterations;
58         // actual step (server frametime / ode_iterations)
59         vec_t ode_step;
60         // time we need to simulate, for constantstep
61         vec_t ode_time;
62         // stats
63         int ode_numobjects; // total objects cound
64         int ode_activeovjects; // active objects count
65         // max velocity for a 1-unit radius object at current step to prevent
66         // missed collisions
67         vec_t ode_movelimit;
68 }
69 world_physics_t;
70
71 struct prvm_prog_s;
72
73 typedef struct world_s
74 {
75         // convenient fields
76         char filename[MAX_QPATH];
77         vec3_t mins;
78         vec3_t maxs;
79         struct prvm_prog_s *prog;
80
81         int areagrid_stats_calls;
82         int areagrid_stats_nodechecks;
83         int areagrid_stats_entitychecks;
84
85         link_t areagrid[AREA_GRIDNODES];
86         link_t areagrid_outside;
87         vec3_t areagrid_bias;
88         vec3_t areagrid_scale;
89         vec3_t areagrid_mins;
90         vec3_t areagrid_maxs;
91         vec3_t areagrid_size;
92         int areagrid_marknumber;
93
94         // if the QC uses a physics engine, the data for it is here
95         world_physics_t physics;
96 }
97 world_t;
98
99 struct prvm_edict_s;
100
101 // cyclic doubly-linked list functions
102 void World_ClearLink(link_t *l);
103 void World_RemoveLink(link_t *l);
104 void World_InsertLinkBefore(link_t *l, link_t *before, int entitynumber);
105
106 void World_Init(void);
107 void World_Shutdown(void);
108
109 /// called after the world model has been loaded, before linking any entities
110 void World_SetSize(world_t *world, const char *filename, const vec3_t mins, const vec3_t maxs, struct prvm_prog_s *prog);
111 /// unlinks all entities (used before reallocation of edicts)
112 void World_UnlinkAll(world_t *world);
113
114 void World_PrintAreaStats(world_t *world, const char *worldname);
115
116 /// call before removing an entity, and before trying to move one,
117 /// so it doesn't clip against itself
118 void World_UnlinkEdict(struct prvm_edict_s *ent);
119
120 /// Needs to be called any time an entity changes origin, mins, maxs
121 void World_LinkEdict(world_t *world, struct prvm_edict_s *ent, const vec3_t mins, const vec3_t maxs);
122
123 /// \returns list of entities touching a box
124 int World_EntitiesInBox(world_t *world, const vec3_t mins, const vec3_t maxs, int maxlist, struct prvm_edict_s **list);
125
126 void World_Start(world_t *world);
127 void World_End(world_t *world);
128
129 // update physics
130 // this is called by SV_Physics
131 void World_Physics_Frame(world_t *world, double frametime, double gravity);
132
133 // change physics properties of entity
134 struct prvm_edict_s;
135 struct edict_odefunc_s;
136 void World_Physics_ApplyCmd(struct prvm_edict_s *ed, struct edict_odefunc_s *f);
137
138 // remove physics data from entity
139 // this is called by entity removal
140 void World_Physics_RemoveFromEntity(world_t *world, struct prvm_edict_s *ed);
141 void World_Physics_RemoveJointFromEntity(world_t *world, struct prvm_edict_s *ed);
142
143 #endif
144