Home | History | Annotate | Download | only in WinQuake
      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 // quakedef.h -- primary header for client
     21 
     22 //#define	GLTEST			// experimental stuff
     23 
     24 #define	QUAKE_GAME			// as opposed to utilities
     25 
     26 #define	VERSION				1.09
     27 #define	GLQUAKE_VERSION		1.00
     28 #define	D3DQUAKE_VERSION	0.01
     29 #define	WINQUAKE_VERSION	0.996
     30 #define	LINUX_VERSION		1.30
     31 #define	X11_VERSION			1.10
     32 
     33 //define	PARANOID			// speed sapping error checking
     34 
     35 #define GLQUAKE
     36 #define USE_OPENGLES
     37 #define id386 0
     38 
     39 #ifdef QUAKE2
     40 #define	GAMENAME	"id1"		// directory to look in by default
     41 #else
     42 #define	GAMENAME	"id1"
     43 #endif
     44 
     45 #include <math.h>
     46 #include <string.h>
     47 #include <stdarg.h>
     48 #include <stdio.h>
     49 #include <stdlib.h>
     50 #include <setjmp.h>
     51 
     52 #if defined(_WIN32) && !defined(WINDED)
     53 
     54 #if defined(_M_IX86)
     55 #define __i386__	1
     56 #endif
     57 
     58 void	VID_LockBuffer (void);
     59 void	VID_UnlockBuffer (void);
     60 
     61 #else
     62 
     63 #define	VID_LockBuffer()
     64 #define	VID_UnlockBuffer()
     65 
     66 #endif
     67 
     68 #if !defined id386
     69 #if defined __i386__ // && !defined __sun__
     70 #define id386	1
     71 #else
     72 #define id386	0
     73 #endif
     74 #endif
     75 
     76 #if id386
     77 #define UNALIGNED_OK	1	// set to 0 if unaligned accesses are not supported
     78 #else
     79 #define UNALIGNED_OK	0
     80 #endif
     81 
     82 // !!! if this is changed, it must be changed in d_ifacea.h too !!!
     83 #define CACHE_SIZE	32		// used to align key data structures
     84 
     85 #define UNUSED(x)	(x = x)	// for pesky compiler / lint warnings
     86 
     87 #define	MINIMUM_MEMORY			0x550000
     88 #define	MINIMUM_MEMORY_LEVELPAK	(MINIMUM_MEMORY + 0x100000)
     89 
     90 #define MAX_NUM_ARGVS	50
     91 
     92 // up / down
     93 #define	PITCH	0
     94 
     95 // left / right
     96 #define	YAW		1
     97 
     98 // fall over
     99 #define	ROLL	2
    100 
    101 
    102 #define	MAX_QPATH		64			// max length of a quake game pathname
    103 #define	MAX_OSPATH		128			// max length of a filesystem pathname
    104 
    105 #define	ON_EPSILON		0.1			// point on plane side epsilon
    106 
    107 #define	MAX_MSGLEN		8000		// max length of a reliable message
    108 #define	MAX_DATAGRAM	1024		// max length of unreliable message
    109 
    110 //
    111 // per-level limits
    112 //
    113 #define	MAX_EDICTS		600			// FIXME: ouch! ouch! ouch!
    114 #define	MAX_LIGHTSTYLES	64
    115 #define	MAX_MODELS		256			// these are sent over the net as bytes
    116 #define	MAX_SOUNDS		256			// so they cannot be blindly increased
    117 
    118 #define	SAVEGAME_COMMENT_LENGTH	39
    119 
    120 #define	MAX_STYLESTRING	64
    121 
    122 //
    123 // stats are integers communicated to the client by the server
    124 //
    125 #define	MAX_CL_STATS		32
    126 #define	STAT_HEALTH			0
    127 #define	STAT_FRAGS			1
    128 #define	STAT_WEAPON			2
    129 #define	STAT_AMMO			3
    130 #define	STAT_ARMOR			4
    131 #define	STAT_WEAPONFRAME	5
    132 #define	STAT_SHELLS			6
    133 #define	STAT_NAILS			7
    134 #define	STAT_ROCKETS		8
    135 #define	STAT_CELLS			9
    136 #define	STAT_ACTIVEWEAPON	10
    137 #define	STAT_TOTALSECRETS	11
    138 #define	STAT_TOTALMONSTERS	12
    139 #define	STAT_SECRETS		13		// bumped on client side by svc_foundsecret
    140 #define	STAT_MONSTERS		14		// bumped by svc_killedmonster
    141 
    142 // stock defines
    143 
    144 #define	IT_SHOTGUN				1
    145 #define	IT_SUPER_SHOTGUN		2
    146 #define	IT_NAILGUN				4
    147 #define	IT_SUPER_NAILGUN		8
    148 #define	IT_GRENADE_LAUNCHER		16
    149 #define	IT_ROCKET_LAUNCHER		32
    150 #define	IT_LIGHTNING			64
    151 #define IT_SUPER_LIGHTNING      128
    152 #define IT_SHELLS               256
    153 #define IT_NAILS                512
    154 #define IT_ROCKETS              1024
    155 #define IT_CELLS                2048
    156 #define IT_AXE                  4096
    157 #define IT_ARMOR1               8192
    158 #define IT_ARMOR2               16384
    159 #define IT_ARMOR3               32768
    160 #define IT_SUPERHEALTH          65536
    161 #define IT_KEY1                 131072
    162 #define IT_KEY2                 262144
    163 #define	IT_INVISIBILITY			524288
    164 #define	IT_INVULNERABILITY		1048576
    165 #define	IT_SUIT					2097152
    166 #define	IT_QUAD					4194304
    167 #define IT_SIGIL1               (1<<28)
    168 #define IT_SIGIL2               (1<<29)
    169 #define IT_SIGIL3               (1<<30)
    170 #define IT_SIGIL4               (1<<31)
    171 
    172 //===========================================
    173 //rogue changed and added defines
    174 
    175 #define RIT_SHELLS              128
    176 #define RIT_NAILS               256
    177 #define RIT_ROCKETS             512
    178 #define RIT_CELLS               1024
    179 #define RIT_AXE                 2048
    180 #define RIT_LAVA_NAILGUN        4096
    181 #define RIT_LAVA_SUPER_NAILGUN  8192
    182 #define RIT_MULTI_GRENADE       16384
    183 #define RIT_MULTI_ROCKET        32768
    184 #define RIT_PLASMA_GUN          65536
    185 #define RIT_ARMOR1              8388608
    186 #define RIT_ARMOR2              16777216
    187 #define RIT_ARMOR3              33554432
    188 #define RIT_LAVA_NAILS          67108864
    189 #define RIT_PLASMA_AMMO         134217728
    190 #define RIT_MULTI_ROCKETS       268435456
    191 #define RIT_SHIELD              536870912
    192 #define RIT_ANTIGRAV            1073741824
    193 #define RIT_SUPERHEALTH         2147483648
    194 
    195 //MED 01/04/97 added hipnotic defines
    196 //===========================================
    197 //hipnotic added defines
    198 #define HIT_PROXIMITY_GUN_BIT 16
    199 #define HIT_MJOLNIR_BIT       7
    200 #define HIT_LASER_CANNON_BIT  23
    201 #define HIT_PROXIMITY_GUN   (1<<HIT_PROXIMITY_GUN_BIT)
    202 #define HIT_MJOLNIR         (1<<HIT_MJOLNIR_BIT)
    203 #define HIT_LASER_CANNON    (1<<HIT_LASER_CANNON_BIT)
    204 #define HIT_WETSUIT         (1<<(23+2))
    205 #define HIT_EMPATHY_SHIELDS (1<<(23+3))
    206 
    207 //===========================================
    208 
    209 #define	MAX_SCOREBOARD		16
    210 #define	MAX_SCOREBOARDNAME	32
    211 
    212 #define	SOUND_CHANNELS		8
    213 
    214 // This makes anyone on id's net privileged
    215 // Use for multiplayer testing only - VERY dangerous!!!
    216 // #define IDGODS
    217 
    218 #include "common.h"
    219 #include "bspfile.h"
    220 #include "vid.h"
    221 #include "sys.h"
    222 #include "zone.h"
    223 #include "mathlib.h"
    224 
    225 typedef struct
    226 {
    227 	vec3_t	origin;
    228 	vec3_t	angles;
    229 	int		modelindex;
    230 	int		frame;
    231 	int		colormap;
    232 	int		skin;
    233 	int		effects;
    234 } entity_state_t;
    235 
    236 
    237 #include "wad.h"
    238 #include "draw.h"
    239 #include "cvar.h"
    240 #include "screen.h"
    241 #include "net.h"
    242 #include "protocol.h"
    243 #include "cmd.h"
    244 #include "sbar.h"
    245 #include "sound.h"
    246 #include "render.h"
    247 #include "client.h"
    248 #include "progs.h"
    249 #include "server.h"
    250 
    251 #ifdef GLQUAKE
    252 #include "gl_model.h"
    253 #else
    254 #include "model.h"
    255 #include "d_iface.h"
    256 #endif
    257 
    258 #include "input.h"
    259 #include "world.h"
    260 #include "keys.h"
    261 #include "console.h"
    262 #include "view.h"
    263 #include "menu.h"
    264 #include "crc.h"
    265 #include "cdaudio.h"
    266 
    267 #ifdef GLQUAKE
    268 #include "glquake.h"
    269 #else
    270 #define GLCHECK(PROMPT) do {} while(0)
    271 #endif
    272 
    273 //=============================================================================
    274 
    275 // the host system specifies the base of the directory tree, the
    276 // command line parms passed to the program, and the amount of memory
    277 // available for the program to use
    278 
    279 typedef struct
    280 {
    281 	const char	*basedir;
    282 	const char	*cachedir;		// for development over ISDN lines
    283 	int		argc;
    284 	const char	**argv;
    285 	void	*membase;
    286 	int		memsize;
    287 } quakeparms_t;
    288 
    289 
    290 //=============================================================================
    291 
    292 
    293 
    294 extern qboolean noclip_anglehack;
    295 
    296 
    297 //
    298 // host
    299 //
    300 extern	quakeparms_t host_parms;
    301 
    302 extern	cvar_t		sys_ticrate;
    303 extern	cvar_t		sys_nostdout;
    304 extern	cvar_t		developer;
    305 
    306 extern	qboolean	host_initialized;		// true if into command execution
    307 extern	double		host_frametime;
    308 extern	byte		*host_basepal;
    309 extern	byte		*host_colormap;
    310 extern	int			host_framecount;	// incremented every frame, never reset
    311 extern	double		realtime;			// not bounded in any way, changed at
    312 										// start of every frame, never reset
    313 
    314 void Host_ClearMemory (void);
    315 void Host_ServerFrame (void);
    316 void Host_InitCommands (void);
    317 void Host_Init (quakeparms_t *parms);
    318 void Host_Shutdown(void);
    319 void Host_Error (const char *error, ...);
    320 void Host_EndGame (const char *message, ...);
    321 void Host_Frame (float time);
    322 void Host_Quit_f (void);
    323 void Host_ClientCommands (const char *fmt, ...);
    324 void Host_ShutdownServer (qboolean crash);
    325 
    326 extern qboolean		msg_suppress_1;		// suppresses resolution and cache size console output
    327 										//  an fullscreen DIB focus gain/loss
    328 extern int			current_skill;		// skill level for currently loaded level (in case
    329 										//  the user changes the cvar while the level is
    330 										//  running, this reflects the level actually in use)
    331 
    332 extern qboolean		isDedicated;
    333 
    334 extern int			minimum_memory;
    335 
    336 //
    337 // chase
    338 //
    339 extern	cvar_t	chase_active;
    340 
    341 void Chase_Init (void);
    342 void Chase_Reset (void);
    343 void Chase_Update (void);
    344 
    345 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);
    346 
    347 // Linux versions of msdos CRT functions
    348 #define stricmp strcasecmp
    349 
    350 // Helper functions for OpenGL ES
    351 void DrawQuad_NoTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h);
    352 void DrawQuad(GLfloat x, GLfloat y, GLfloat w, GLfloat h, GLfloat u, GLfloat v, GLfloat uw, GLfloat vh);
    353 
    354 void shadowLoadIdentity( GLfloat* m);
    355 void shadowRotatef( GLfloat* m, GLfloat a, GLfloat x, GLfloat y, GLfloat z);
    356 void shadowTranslatef( GLfloat* m, GLfloat x, GLfloat y, GLfloat z);
    357 
    358 #ifdef USE_OPENGLES
    359 // Reimplementation of OpenGL functions that are missing in OpenGL ES
    360 
    361 #define GL_INTENSITY				0x8049
    362 
    363 void glColor3f(GLfloat r, GLfloat g, GLfloat b);
    364 void glColor4fv(GLfloat* pColor);
    365 
    366 #define VERTEXARRAYSIZE 2048
    367 
    368 extern float gVertexBuffer[VERTEXARRAYSIZE];
    369 extern float gColorBuffer[VERTEXARRAYSIZE];
    370 extern float gTexCoordBuffer[VERTEXARRAYSIZE];
    371 
    372 #endif // USE_OPENGLES
    373 
    374 void glTexImage2DHelper( GLenum target,
    375 	 GLint level,
    376 	 GLint internalformat,
    377 	 GLsizei width,
    378 	 GLsizei height,
    379 	 GLint border,
    380 	 GLenum format,
    381 	 GLenum type,
    382 	 const GLvoid *pixels );
    383 
    384 // Forward declarations:
    385 
    386 qboolean VID_Is8bit(void);
    387 void GL_SubdivideSurface (msurface_t *fa);
    388 void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr);
    389 int R_LightPoint (vec3_t p);
    390 void R_DrawBrushModel (entity_t *e);
    391 void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
    392 void R_AnimateLight (void);
    393 void V_CalcBlend (void);
    394 void R_DrawWorld (void);
    395 void R_RenderDlights(void);
    396 void R_DrawParticles (void);
    397 void R_DrawWaterSurfaces (void);
    398 void R_RenderBrushPoly (msurface_t *fa);
    399 void R_InitParticles (void);
    400 void GL_Upload8_EXT (byte *data, int width, int height,  qboolean mipmap, qboolean alpha);
    401 void R_ClearParticles (void);
    402 void GL_BuildLightmaps (void);
    403 void EmitWaterPolys (msurface_t *fa);
    404 void EmitSkyPolys (msurface_t *fa);
    405 void EmitBothSkyLayers (msurface_t *fa);
    406 void R_DrawSkyChain (msurface_t *s);
    407 qboolean R_CullBox (vec3_t mins, vec3_t maxs);
    408 void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
    409 void R_RotateForEntity (entity_t *e);
    410 void R_StoreEfrags (efrag_t **ppefrag);
    411 void GL_Set2D (void);
    412 
    413 // Poor Man's Profiler
    414 // (And general loging.)
    415 
    416 void PMP_Begin(const char* fmt,...);
    417 void PMP_Event(const char* fmt,...);
    418 void PMP_End(const char* fmt,...);
    419 
    420 #define PMPLOG(ARGS) PMP_Event ARGS
    421 #define PMPWARNING(ARGS) PMP_Event ARGS
    422 #define PMPERROR(ARGS) PMP_Event ARGS
    423 
    424 // #define ENABLE_PMP
    425 
    426 #ifdef ENABLE_PMP
    427 
    428 #define PMPBEGIN(ARGS) PMP_Begin ARGS
    429 #define PMPEVENT(ARGS) PMP_Event ARGS
    430 #define PMPEND(ARGS) PMP_End ARGS
    431 
    432 #else
    433 
    434 #define PMPBEGIN(ARGS) ((void) 0)
    435 #define PMPEVENT(ARGS) ((void) 0)
    436 #define PMPEND(ARGS) ((void) 0)
    437 
    438 #endif
    439 
    440 // Measure fastest / slowest frames
    441 typedef struct frameTime_ {
    442     int frame;
    443 	float time;
    444 } frameTime;
    445 
    446 extern frameTime fastestFrame;
    447 extern frameTime slowestFrame;
    448 
    449 void InitFrameTimes();
    450 
    451 // Feature configuration
    452 
    453 #define SUPPORT_8BIT_MIPMAPGENERATION
    454 
    455 #ifdef SUPPORT_8BIT_MIPMAPGENERATION
    456 extern unsigned char d_15to8table[65536];
    457 #endif // SUPPORT_8BIT_MIPMAPGENERATION
    458 
    459