⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hawk.h

📁 著名物理引擎Hawk的源代码
💻 H
字号:
/* hawk.h, HAWK game engine
 *
 * Copyright 1997-1998 by Phil Frisbie, Jr.
 * for Hawk Software
 *
 */

#ifndef HAWK_H
#define HAWK_H

#ifdef __cplusplus
extern "C" {
#endif

typedef unsigned char byte;
#include "qfiles.h"

#ifdef WIN32
#pragma warning (disable:4244)				/* disable double to float conversion warnings */
#pragma warning (disable:4305)				/* disable constant double to float conversion warnings */
#define M_PI		(float)3.14159265		/* Windows does not define PI */
#define M_PI_2		(float)1.57079632
#endif

#ifndef BOOL
typedef int BOOL;
#define TRUE	1
#define FALSE	0
#endif

#ifndef MAX
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#endif

#ifndef NULL
#define NULL	(void *)(0)
#endif

typedef float vec_t;
typedef vec_t vec2_t[2];
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];

/* Misc defines */

#define STOPPED_LIMIT	0.1
#define MAX_VIEWS		2
#define FAST			2.0
#define RAD(x)			(float)((x) * M_PI / (float)180.0)

/* memory tags to allow dynamic memory to be cleaned up */
#define	TAG_GAME		1	/* clear when unloading the dll */
#define	TAG_LEVEL		2	/* clear when loading a new level */

/* GSURFACE */
typedef struct
{
	char		name[32];	/* name of texture */
	int			textype;	/* type of texture */
	vec3_t		normal;		/* normal of surface */
	float		dist;		/* distance from origin */
} GSURFACE;

/* Trace */
typedef struct
{
	BOOL		allsolid;	/* if true, plane is not valid */
	BOOL		startsolid;	/* if true, the initial point was in a solid area */
	float		fraction;	/* time completed, 1.0 = didn't hit anything */
	vec3_t		endpos;		/* final position */
	GSURFACE	*surface;	/* surface hit */
	int			contents;	/* contents on other side of surface hit */
} TRACE;

/* the generic object structure */
typedef struct object
{
	int			type;		/* object type */
	int			height;		/* height */
	int			radius;		/* radius of object */
	int			mass;		/* mass of object */
	vec3_t		mins;		/* minimum point */
	vec3_t		maxs;		/* maximum point */
	vec3_t		origin;		/* position of feet */
	vec3_t		angles;		/* rotation angles */
	vec3_t		movedir;	/* direction to move in */
	int			inleaf;		/* in leaf number */
	float		pitch;		/* neck angle */
	float		acc;		/* acceleration */
	float		turn;		/* turning speed */
	float		speed;		/* speed along heading */
	float		maxspeed;	/* maximum speed */
	float		strafeSpeed;/* speed perpendicular to heading */
	float		vertSpeed;	/* up/down speed */
	char		*classname;	/* class name */
	int			health;		/* health value */
	int			model;		/* index to model info */
	int			skin;		/* skin to use with model */
	int			weapon;		/* index into weapon model info */
	int			animation;	/* index into animation info */
	struct object	*owner;	/* pointer to the owner(another object) of this object */
	void		*misc;		/* used with particle objects, points to particles */
	void		(*update)(struct object *obj);/* update function to be called */
	int			param[4];	/* effect's param */
	int			event;		/* event mask */
	int			lastevent;	/* copy of event mask from last frame */
	int			tag;		/* tag ID */
	struct object	*next;	/* pointer to next object */
	struct object	*prev;	/* pointer to previous object */
	TRACE		*trace;		/* TRACE info for collision detection */
	void		*dev1;		/* pointer to developer supplied structure */
	void		*dev2;		/* pointer to developer supplied structure */
	void		*dev3;		/* pointer to developer supplied structure */
} OBJECT;

/* View */
typedef struct
{
	int			type;		/* view type */
	int			scrX, scrY;	/* bottem-left corner of view */
	int			width, height;/* width and height of view */
	float		angle;		/* view angle */
	float		scaling;	/* for in/out effects, 1 is full size */
	OBJECT		*object;	/* Object which carries the camera */
	float		hangle;		/* Direction relative to obj dir */
	float		vangle;		/* vertical angle */
	vec3_t		cam;		/* 'camera' point */
	vec3_t		look;		/* point to look at */
	vec3_t		clipl;		/* left clipping plane */
	vec3_t		clipr;		/* right clipping plane */
	vec3_t		clipb;		/* bottom clipping plane */
	vec3_t		clipt;		/* top clipping plane */
	int			needblend;	/* render with blend effect */
	float		blendcolor[4];/* RGBA color of blend */
	int			weapon;		/* index into model info for view weapon */
	int			animation;	/* index into weapon animation info */
	void		*dev1;		/* pointer to developer supplied structure */
	void		*dev2;		/* pointer to developer supplied structure */
	void		*dev3;		/* pointer to developer supplied structure */
} VIEW;

/* Game level info for game.dll */
typedef struct
{
	char		*message;	/* level name */
	float		force;		/* default force(friction) */
	float		gravity;	/* default gravity */
	char		*sky;		/* sky texture base name */
	vec_t		skyrotate;	/* speed of sky rotation */
	vec3_t		skyaxis;	/* angle of sky rotation */
	vec_t		skyangle;	/* the last sky angle */
	char		*nextmap;	/* name of next map */
	int			cdtrack;	/* the number of the music CD track to play */
	int			nobjects;	/* number of objects */
	OBJECT		*objects;	/* pointer to objects */
	int			nview;		/* number of views */
	VIEW		*view[MAX_VIEWS];/* array of views */
	void		*dev1;		/* pointer to developer supplied structure */
	void		*dev2;		/* pointer to developer supplied structure */
	void		*dev3;		/* pointer to developer supplied structure */
} GAMELEVEL;

typedef struct
{
	/* shared structures */
	GAMELEVEL	*Level;

	/* output functions */
	void		(*Screenprintf)(int type, char *string, ...);
		/* PlaySoundi() plays a sound previously loaded with SoundLoad() */
		/* pan is from -1.0f for full left, to 1.0f for right, 0.0f for center */
		/* voulume is from 1.0f for full, to 0.0f for mute */
		/* If looped is TRUE, sound will play until StopSoundi is issued */
	void		(*PlaySoundi)(int sound, float pan, float volume, BOOL looped);
		/* PlaySound3Di plays a sound previously loaded with SoundLoad() */
		/* at the location of obj */
	void		(*PlaySound3Di)(int sound, OBJECT *obj, float volume, BOOL looped);
		/* StopSound stops a looping sound */
	void		(*StopSoundi)(int sound);
		/* SoundLoad loads the sound, and returns a handle to it */
	int			(*SoundLoad)(char *name);
		/* PlaySound() loads and plays a seldom used sound */
		/* Use SoundLoad and PlaySoundi for frequently used sounds */
	void		(*PlaySound)(char *name, float pan, float volume);

	/* collision detection */
	BOOL		(*ClipRay)(vec3_t start, vec3_t end, int contentmask);
	int			(*Pointcontents)(vec3_t point);
	BOOL		(*InPVS)(vec3_t p1, vec3_t p2);
	BOOL		(*InPHS)(vec3_t p1, vec3_t p2);
	TRACE		*(*TraceRay)(vec3_t start, vec3_t end, OBJECT *passent, int contentmask);
	TRACE		*(*TraceBBox)(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, OBJECT *passent, int contentmask);
	TRACE		*(*TraceSphere)(vec3_t start, vec3_t radius, vec3_t end, OBJECT *passent, int contentmask);

	/* object management */
	OBJECT		*(*ObjectAdd)(void);
	void		(*ObjectDelete)(OBJECT *o);
	int			(*ModelLoad)(char *modelname);

	/* animation control */
	int			(*AnimationAdd)(void);
	void		(*AnimationDelete)(int animation);
	void		(*AnimationSetDefault)(int animation, int first, int last);
	void		(*AnimationSetNext)(int animation, int first, int last, int start);
	void		(*AnimationSetLoop)(int animation, BOOL loop);
	int			(*AnimationGetCurrentFrame)(int animation);
	int			(*AnimationGetNextFrame)(int animation);
	void		(*AnimationSetCurrentFrame)(int animation, int frame);


	/* particle effects */
	void		(*Splash)(vec3_t center, int number, int type, vec3_t color);
	void		(*Trail)(vec3_t start, vec3_t end, int type, vec3_t color);

	/* memory allocation */
	void		*(*TempMalloc)(int size);
	void		(*TempFree)(void *block);
	void		*(*TagMalloc)(int size, int tag);
	void		(*FreeTags)(int tag);

} GAMEDLL_IMPORT;

typedef struct
{
	void	(*GameUpdate)(int curframes, int totalframes);
	int		(*ParseEntities)(char *entdata, int datasize);
	void	(*SpawnObject)(int entity);
	float	G_dllversion;
	char	*G_dllvendor;
	char	*G_dllname;
} GAMEDLL_EXPORT;

/* make array indexing more intuitive */
enum {S, T};
enum {X, Y, Z, W};
enum {R, G, B, A};
#define SHIFT	3

/* Screen text types */
#define	PRINT_LOW		0				/* pickup messages */
#define	PRINT_MEDIUM	1				/* death messages */
#define	PRINT_HIGH		2				/* critical messages */
#define	PRINT_CHAT		3				/* chat messages */

/* sound channels */
#define	CHAN_CENTER		0
#define	CHAN_LEFT		-1
#define	CHAN_RIGHT		1

/* content masks */
#define	CONTENTS_SOLID			1		/* an eye is never valid in a solid */
#define	CONTENTS_WINDOW			2		/* translucent, but not watery */
#define	CONTENTS_AUX			4
#define	CONTENTS_LAVA			8
#define	CONTENTS_SLIME			16
#define	CONTENTS_WATER			32
#define	CONTENTS_MIST			64
#define	LAST_VISIBLE_CONTENTS	64
#define VISIBLE_MASK			(LAST_VISIBLE_CONTENTS<<1) - 1
#define	CONTENTS_AREAPORTAL		0x8000
#define	CONTENTS_PLAYERCLIP		0x10000
#define	CONTENTS_MONSTERCLIP	0x20000
#define	CONTENTS_CURRENT_0		0x40000
#define	CONTENTS_CURRENT_90		0x80000
#define	CONTENTS_CURRENT_180	0x100000
#define	CONTENTS_CURRENT_270	0x200000
#define	CONTENTS_CURRENT_UP		0x400000
#define	CONTENTS_CURRENT_DOWN	0x800000
#define	CONTENTS_ORIGIN			0x1000000
#define	CONTENTS_MONSTER		0x2000000
#define	CONTENTS_DEADMONSTER	0x4000000
#define	CONTENTS_DETAIL			0x8000000
#define	CONTENTS_TRANSLUCENT	0x10000000
#define	CONTENTS_LADDER			0x20000000

#define	MASK_ALL			(-1)
#define	MASK_SOLID			(CONTENTS_SOLID|CONTENTS_WINDOW)
#define	MASK_PLAYERSOLID	(CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER)
#define	MASK_DEADSOLID		(CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW)
#define	MASK_MONSTERSOLID	(CONTENTS_SOLID|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER)
#define	MASK_WATER			(CONTENTS_WATER|CONTENTS_LAVA|CONTENTS_SLIME)
#define	MASK_OPAQUE			(CONTENTS_SOLID|CONTENTS_SLIME|CONTENTS_LAVA)
#define	MASK_SHOT			(CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEADMONSTER)
#define MASK_CURRENT		(CONTENTS_CURRENT_0|CONTENTS_CURRENT_90|CONTENTS_CURRENT_180|CONTENTS_CURRENT_270|CONTENTS_CURRENT_UP|CONTENTS_CURRENT_DOWN)


/* Object types */
#define O_UNUSED		0x00000000		/* unused */
#define O_SWIMMER		0x00000001		/* Tries to stay in water */
#define O_FLYER			0x00000002		/* Gravity does not apply to the object */
#define O_NOFRIC		0x00000004		/* No friction. Move until collision */
#define O_NOSLIDE		0x00000008		/* Object does not slide along a wall */
#define O_WALLCOL		0x00000010		/* Check wall collisions */
#define O_OBJCOL		0x00000020		/* Check obj collisions */
#define O_STRUCT		0x00000040		/* Special 'structure' collisions, not used?? */
#define O_PLAYER		0x00000080		/* Player object */
#define O_MONSTER		0x00000100		/* Monster or other player in multiplayer */
#define O_TRANS			0x00000200		/* Translucent object */
#define O_PROJECTILE	0x00000400		/* Projectile object */
#define O_INSTANT		0x00000800		/* Object has infinite speed (bullet) */
#define O_SPRITE		0x00001000		/* Sprite object (just has a texture) */
#define O_FULLBRIGHT	0x00002000		/* Render with no lighting */
#define O_PULSE			0x00004000		/* Render with pulsing lighting effect */
#define O_ITEM			0x00008000		/* Items that can be picked up */
#define O_FLARE			0x00010000		/* Render with a lens flare effect */
#define O_SHELL			0x00020000		/* Render with a shell effect, color in param[3] */
#define O_PARTICLE		0x00040000		/* Particle object, *misc points to particles */
#define O_MISC			0x00080000		/* Misc items with no special properties */
#define O_BSPMODEL		0x00100000		/* Object has a BSP model to render */

/* Object events */
#define EV_SHOOT		0x00000001		/* shoot weapon */
#define EV_CROUCH		0x00000002		/* crouch down */
#define EV_ACT3			0x00000004		/* action #3 */
#define EV_FAST			0x00000008		/* run or turn fast */
#define EV_FORWARD		0x00000010		/* move forward */
#define EV_BACKWARD		0x00000020		/* move backward */
#define EV_LEFT			0x00000040		/* strafe left */
#define EV_RIGHT		0x00000080		/* strafe right */
#define EV_UP			0x00000100		/* jump (or move up) */
#define EV_DOWN			0x00000200		/* move down */
#define EV_TURNLEFT		0x00000400		/* turn left */
#define EV_TURNRIGHT	0x00000800		/* turn right */
#define EV_LOOKUP		0x00001000		/* look up */
#define EV_LOOKDOWN		0x00002000		/* look down */
#define EV_DESTROY		0x10000000		/* object is to be deleted */

/* View types */
#define V_REAR			0x00000001		/* rear view */
#define V_EXTERNAL		0x00000002		/* external view */
#define V_ISOMETRIC		0x00000004		/* isometric view */

/* Texture types */

/* Surface types */
#define S_X				0x00000001		/* surface aligned along x axis(wall) */
#define S_Y				0x00000002		/* surface aligned along y axis(wall) */
#define S_Z				0x00000004		/* surface aligned along z axis(floor/ceiling) */
#define S_VERT			0x00000008		/* surface is vertical */
#define S_COL			0x00000010		/* col. det. works */
#define S_MOVABLE		0x00000020		/* surface is movable */
#define S_TRANS			0x00000040		/* surface is translucent */
#define S_TEXTURED		0x00000080		/* textured */
#define S_ONLYCOL		0x00000100		/* surface is for collision detection only, does not draw */

/* Engine modes */
#define EN_PALETTED		0x00000001		/* use EXT_paletted_texture textures */
#define EN_GLOBAL_PAL	0x00000002		/* use a global palette */
#define EN_FULL_SCREEN	0x00000004		/* run fullscreen */
#define EN_MIPMAPS		0x00000008		/* use mipmaps */
#define EN_LOAD_ALL		0x00000010		/* preload all textures */
#define EN_LIGHT		0x00000020		/* show lightmaps */

/* Misc */
#define DEFAULT_WIDTH	640
#define DEFAULT_HEIGHT	480
#define DEFAULT_WINDOW	0
#define DEFAULT_LIGHT	EN_LIGHT
#define DEFAULT_TEXSCALE	1
#define NO_MODEL		-1
#define NO_ANIMATION	-1
#define NO_FRAME		-1

#ifdef __cplusplus
}
#endif

#endif /* HAWK_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -