internal.h

来自「著名物理引擎Hawk的源代码」· C头文件 代码 · 共 367 行

H
367
字号
/* internal.h, HAWK game engine
 *
 * Copyright 1997-1998 by Phil Frisbie, Jr.
 * for Hawk Software
 *
 */

#ifndef INTERNAL_H
#define INTERNAL_H

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "hawk.h"
#include "memory.h"
#include "vector.h"
#include "pakfile.h"

#ifdef __cplusplus
extern "C" {
#endif

/* to create the hawk.log file */
#define DEBUG_LOG

#define	HAWK_VERSION		0.8
#define MAX_OBJECTS		4096
#define GAME_TICKS		30
#define	ANIMATE_TICKS	10

/* texture formats */
#define PACKED_TEXTURE	2
#define RGB_TEXTURE		3
#define RGBA_TEXTURE	4

#define IS_FONT			0x10000
#define IS_SKY			0x20000

#define ANIM_TEX_FRAMES		32
#define ANIM_TEX_MASK		(ANIM_TEX_FRAMES - 1)
#define ANIM_TEX_DISP		0.05
#define AnimTexIndex( x )   (((x) >> 3) & ANIM_TEX_MASK)

/* Texture */
typedef struct
{
    char		name[32];	/* name of the texture */
	int			type;		/* type of texture=texinfo.flags  */
    int			width;		/* width of texture */
    int			height;		/* height of texture */
	int			number;		/* OpenGL texture number */
	int			ntextures;	/* number of animation frames */
} TEXTURE;

/* Lightmap */
typedef struct
{
    int			width;		/* width of texture */
    int			height;		/* height of texture */
	int			xoff;		/* x offset for glTexSubImage2D */
	int			yoff;		/* y offset for glTexSubImage2D */
	int			number;		/* OpenGL texture number */
} LIGHTMAP;

/* generic textured points */
typedef struct
{
	vec3_t		v;			/* vertex coordinate */
	vec2_t		t;			/* texture coordinate */
	vec2_t		lm;			/* lightmap texture coordinate */
	vec_t		pad;		/* for alignment, pads to 32 bytes */
} TPOINT;

/* Surface */
typedef struct
{
	char		name[32];	/* name of texture */
	int			textype;	/* type of texture */
	vec3_t		normal;		/* normal of surface */
	float		dist;		/* distance from origin */
	int			type;		/* type of surface */
	int			mode;		/* for glBegin */
	int			firstpoint;	/* offset to first point in list of points */
	int			numpoints;	/* number of points */
	int			texture;	/* texture number */
	int			ntextures;	/* number of textures for animated textures */
	unsigned char	color[4];/* color of surface if not textured */
	int			light;		/* light map number */
	vec3_t		mins;		/* for collision detection? */
	vec3_t		maxs;		/*  */
	int			tag;		/* tag ID */
} SURFACE;

/* to keep track of loaded files */
typedef struct
{
    char		name[256];	/* name of the file */
	int			number;		/* number of the object/texture/etc */
} LOADEDFILE;

/* Model */
typedef struct
{
	BOOL			used;		/* This model struct is being used */
	int				nframes;	/* Number of animation frames */
	char			*frames;	/* Pointer to frame info */
	int				framesize;	/* Size of each frame */
	int				texture[6];	/* OpenGL texture numbers */
	int				nglcmds;	/* Number of GL commands */
	int				*glcmds;	/* Pointer to GL commands */
} MODEL;

/* BSP file info */
typedef struct
{
	int			nummodels;
	dmodel_t	*dmodels;
	int			visdatasize;
	byte		*dvisdata;
	int			lightdatasize;
	byte		*dlightdata;
	int			entdatasize;
	char		*dentdata;
	int			numleafs;
	dleaf_t		*dleafs;
	int			numplanes;
	dplane_t	*dplanes;
	int			numvertexes;
	dvertex_t	*dvertexes;
	int			numnodes;
	dnode_t		*dnodes;
	int			numtexinfo;
	texinfo_t	*texinfo;
	int			numfaces;
	dface_t		*dfaces;
	int			numedges;
	dedge_t		*dedges;
	int			numleaffaces;
	unsigned short		*dleaffaces;
	int			numleafbrushes;
	unsigned short		*dleafbrushes;
	int			numsurfedges;
	int			*dsurfedges;
	int			numbrushes;
	dbrush_t	*dbrushes;
	int			numbrushsides;
	dbrushside_t	*dbrushsides;
	int			numareas;
	darea_t		*dareas;
	int			numareaportals;
	dareaportal_t	*dareaportals;
	byte		*dpop;
} BSPFILE;

/* Level info for HAWK engine */
typedef struct
{
	int			npoints;	/* number of points */
	TPOINT		*points;	/* pointer to list of points */
	int			nsurf;		/* number of surfaces */
	SURFACE		*surf;		/* pointer to surfaces */
	int			nmodels;	/* number of models */
	MODEL		*models;	/* pointer to models */
	int			background;	/* background texture */
	int			console;	/* console texture */
	int			ntextures;	/* number of textures loaded */
	TEXTURE		*textures;	/* pointer to list of textures */
	int			nlighttex;	/* number of lightmap textures loaded */
	LIGHTMAP	*lighttex;	/* pointer to list of lightmap textures */
	int			nsurflist;	/* number of surfaces */
	char		*surflist;	/* pointer to list of surfaces to render */
	char		*texlist;	/* pointer to list of textures to render */
} LEVEL;

/* Particle */
typedef struct
{
	vec_t	size;		/* size of particle */
	vec3_t	center;		/* location */
	vec3_t	move;		/* initial movement vector/speed */
	vec3_t	decay;		/* movement decay per gameframe */
	vec3_t	color;		/* RGB color */
	vec3_t	colorchange;/* RGB color change per frame */
	int		birth;		/* time in gameframes when created */
	int		death;		/* time in gameframes to delete */
	BOOL	solid;		/* is particle solid (TRUE) or translucent (FALSE)? */
	BOOL	alive;		/* is particle alive (in use)? */
	BOOL	gravity;	/* is particle affected by gravity? */
	void	*next;		/* next particle in chain */
	void	*prev;		/* previous particle in chain */
} PARTICLE;

/* Engine settings */
typedef struct
{
	float		version;	/* HAWK engine version */
	int			mode;		/* OpenGL settings, texture type, alpha, etc. */
	int			w;			/* window/screen width */
	int			h;			/* window/screen height */
	unsigned int	colorbits;	/* 16 or 24 */
	int			zbufferbits;/* 16 or 24 or 32 */
	int			gamestart;	/* game frames at gamestart */
	int			gameframes;	/* total number of game frames elasped since start */
	int			curframes;	/* how many game frames elasped since last render */
	int			animframes;	/* how many animation frames since the last update */
	float		fps;		/* current rendering rate */
	int			leafschecked;/* for debugging bspTrace */
	int			surfschecked;/* for debugging bspTrace */
	BOOL		starting;	/* engine is starting- for special effects, etc. */
	BOOL		running;	/* is engine running */
	BOOL		paused;		/* is engine paused */
	BOOL		stopping;	/* is stopping down- for special effects and cleanup */
	BOOL		texture;	/* render with texture */
	BOOL		light;		/* render with lighting */
	BOOL		mouse;		/* render mouse pointer */
	BOOL		sight;		/* render gunsight */
	int			texturescale;/* scale textures by 1/texturescale when loading */
	float		gamma;		/* gamma correction for textures */
	int			pointtex;	/* texture number for point texture */
	int			logotex;	/* texture number for the HAWK logo */
	char		*GLvendor;	/* OpenGL vendor string */
	char		*GLrenderer;/* OpenGL renderer string */
	int			pointEXT;	/* OpenGL driver supports GL_EXT_point_parameters */
	int			multitexEXT;/* OpenGL driver supports GL_ARB_multitexture */
} ENGINE;

typedef struct
{
	char		*vendor;	/* CPU vendor string */
	int			type;		/* CPU class, Pentium, Pentium II, etc. */
	int			speed;		/* CPU speed in MHz */
	BOOL		hasMMX;	/* CPU supports MMX instructions */
	BOOL		has3DNow;/* CPU supports 3DNow instructions */
} CPU;

/* Animation control */
typedef struct
{
	BOOL		used;		/* Is this animation in use? */
	BOOL		loop;		/* Is animation looped? */
	BOOL		smooth;		/* Smoothly transition into next animation? */
	float		speed;		/* Playback speed, default 1.0 */
	int			dfirst;		/* First frame of default animation sequence */
	int			dlast;		/* Last frame of default animation sequence */
	int			cframe;		/* Current frame */
	int			next;		/* Next frame, for interpolation */
	int			cfirst;		/* First frame of current animation sequence */
	int			clast;		/* Last frame of current animation sequence */
	int			nfirst;		/* First frame for next animation sequence */
	int			nlast;		/* Last frame for next animation sequence */
	int			nstart;		/* When to start next animation (-1 for NOW, or gametime) */
} ANIMATION;

/* Global variables */

extern ENGINE		Engine; /* various settings */
extern CPU			Cpu;	/* CPU info */
extern LEVEL		Level;	/* level info */
extern GAMELEVEL	GLevel;	/* level info shared with game.dll */
extern int			Done;	/* signals app exit */
extern byte			*pvs[MAX_MAP_LEAFS];/* uncompressed pvs data */
extern byte			*phs[MAX_MAP_LEAFS];/* uncompressed phs data */
extern GAMEDLL_EXPORT	*GAMEDLL;	/* export info from game.dll */
extern BSPFILE		BSP;	/* BSP file information */

/* internal global functions */
/* hawk.c */
void logf(char *str, ...);
BOOL HAWK_LoadMap(char *);
void HAWK_Init(int, int, int, int, int);
void HAWK_Update(void);
void HAWK_Render(void);
void HAWK_Start(void);
void HAWK_Stop(void);
void HAWK_SetTexScale(int);
void HAWK_SetGamma(float);
void reshape(int, int);
void Setup_OpenGL(void);

/* cpu.c */
void cpuID(void);

/* model.c */
int modelLoad(char *modelname);

/* load.c */
int loadTexture(char *filename, TEXTURE *t);

/* engine.c */
void engUpdate(void);

/* bsp.c */
int	bspPointInLeafnum(vec3_t point);
dleaf_t *bspPointInLeaf(vec3_t point);
BOOL bspClipRay(vec3_t start, vec3_t end, int contentmask);
int bspPointcontents(vec3_t point);
BOOL bspInPVS(vec3_t p1, vec3_t p2);
BOOL bspInPHS(vec3_t p1, vec3_t p2);
TRACE *bspTraceRay(vec3_t start, vec3_t end, OBJECT *passent, int contentmask);
TRACE *bspTraceBBox(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, OBJECT *passent, int contentmask);
TRACE *bspTraceSphere(vec3_t start, vec3_t radius, vec3_t end, OBJECT *passent, int contentmask);

/* object.c */
OBJECT *objAdd(void);
void objDelete(OBJECT *o);

/* particle.c */
void partMakeSplash(vec3_t center, int number, int type, vec3_t color);
void partMakeTrail(vec3_t start, vec3_t end, int type, vec3_t color);

/* render.c */
void renTextPrint(char *str, ...);
void renDrawMessage(int size, int startX, int startY, char *string, ... );
void renDrawCursor(void);
void renBlendScreen(unsigned char r, unsigned char g,
					unsigned char b, unsigned char a);

/* animate.c */
void animUpdate(int animation);
void animInit(void);
int animAdd(void);
void animDelete(int animation);
void animSetDefault(int animation, int first, int last);
void animSetNext(int animation, int first, int last, int start);
void animSetLoop(int animation, BOOL loop);
int animGetCurrentFrame(int animation);
int animGetNextFrame(int animation);
void animSetCurrentFrame(int animation, int frame);

/* light.c */
void lightGetObject(OBJECT *o, vec3_t color);
BOOL lightGetObjectDynamic(OBJECT *o, vec3_t color, vec3_t normal);
void lightUpdate(void);

/* texture.c */
int texBuildMipmaps(int components, int width, int height, unsigned char *data);
void texScaleImage(int widthin, int heightin, unsigned char *datain,
			   int widthout, int heightout, unsigned char *dataout);
int texBuildTex(int components, int width, int height, unsigned char *data);
int texBuildLightmap(int components, int width, int height, unsigned char *data);

/* sound.c */
int soundLoad(char *name);
void playSoundi(int sound, float pan, float volume, BOOL looped);
void playSound3Di(int sound, OBJECT *obj, float volume, BOOL looped);
void playSound(char *name, float pan, float volume);
void sndStop(int wave);
void sndUpdate(void);


/* misc functions */
/* fast float to int rounding, based on a post to rec.games.programmer
by Glenn Corpes, glennc@cix.co.uk */
/* make sure your floats never exceed 1<<23 (8,388,608.0) or are negative */
/* I don't know if this is fully portable or not- Phil */
static __inline int F_TO_I(float f)
{
	f += (1<<23);
	return *((int *)&f) & 0x7fffff;
}

#ifdef __cplusplus
}
#endif

#endif /* INTERNAL_H */

⌨️ 快捷键说明

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