2007-11-04 03:34:51 +00:00
/*
2012-03-17 20:01:54 +00:00
Copyright ( C ) 1999 - 2007 id Software , Inc . and contributors .
For a list of contributors , see the accompanying CONTRIBUTORS file .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
This file is part of GtkRadiant .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
GtkRadiant is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
GtkRadiant is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
You should have received a copy of the GNU General Public License
along with GtkRadiant ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*/
2007-11-04 03:34:51 +00:00
# ifndef __Q_SHARED_H
# define __Q_SHARED_H
// q_shared.h -- included first by ALL program modules.
// these are the definitions that have no dependance on
// central system services, and can be used by any part
// of the program without any state issues.
// A user mod should never modify this file
2012-03-17 20:01:54 +00:00
# define Q3_VERSION "DOOM 0.01"
2007-11-04 03:34:51 +00:00
// alignment macros for SIMD
2012-03-17 20:01:54 +00:00
# define ALIGN_ON
# define ALIGN_OFF
2007-11-04 03:34:51 +00:00
# ifdef _WIN32
# pragma warning(disable : 4018) // signed/unsigned mismatch
# pragma warning(disable : 4032)
# pragma warning(disable : 4051)
2012-03-17 20:01:54 +00:00
# pragma warning(disable : 4057) // slightly different base types
# pragma warning(disable : 4100) // unreferenced formal parameter
2007-11-04 03:34:51 +00:00
# pragma warning(disable : 4115)
2012-03-17 20:01:54 +00:00
# pragma warning(disable : 4125) // decimal digit terminates octal escape sequence
# pragma warning(disable : 4127) // conditional expression is constant
2007-11-04 03:34:51 +00:00
# pragma warning(disable : 4136)
# pragma warning(disable : 4201)
# pragma warning(disable : 4214)
# pragma warning(disable : 4244)
2012-03-17 20:01:54 +00:00
# pragma warning(disable : 4305) // truncation from const double to float
# pragma warning(disable : 4310) // cast truncates constant value
2007-11-04 03:34:51 +00:00
# pragma warning(disable : 4514)
2012-03-17 20:01:54 +00:00
# pragma warning(disable : 4711) // selected for automatic inline expansion
# pragma warning(disable : 4220) // varargs matches remaining parameters
2007-11-04 03:34:51 +00:00
# endif
# include <assert.h>
# include <math.h>
# include <stdio.h>
# include <stdarg.h>
# include <string.h>
# include <stdlib.h>
# include <time.h>
# include <ctype.h>
2012-03-17 20:01:54 +00:00
# ifdef _WIN32 // mac doesn't have malloc.h
# include <malloc.h> // for _alloca()
2007-11-04 03:34:51 +00:00
# endif
# ifdef _WIN32
//#pragma intrinsic( memset, memcpy )
# endif
// this is the define for determining if we have an asm version of a C function
2012-03-17 20:01:54 +00:00
# if ( defined _M_IX86 || defined __i386__ ) && !defined __sun__ && !defined __LCC__
# define id386 1
2007-11-04 03:34:51 +00:00
# else
2012-03-17 20:01:54 +00:00
# define id386 0
2007-11-04 03:34:51 +00:00
# endif
// for windows fastcall option
2012-03-17 20:01:54 +00:00
# define QDECL
2007-11-04 03:34:51 +00:00
//======================= WIN32 DEFINES =================================
# ifdef _WIN32
2012-03-17 20:01:54 +00:00
# define MAC_STATIC
2007-11-04 03:34:51 +00:00
# undef QDECL
2012-03-17 20:01:54 +00:00
# define QDECL __cdecl
2007-11-04 03:34:51 +00:00
// buildstring will be incorporated into the version string
# ifdef NDEBUG
# ifdef _M_IX86
2012-03-17 20:01:54 +00:00
# define CPUSTRING "win-x86"
2007-11-04 03:34:51 +00:00
# elif defined _M_ALPHA
2012-03-17 20:01:54 +00:00
# define CPUSTRING "win-AXP"
2007-11-04 03:34:51 +00:00
# endif
# else
# ifdef _M_IX86
2012-03-17 20:01:54 +00:00
# define CPUSTRING "win-x86-debug"
2007-11-04 03:34:51 +00:00
# elif defined _M_ALPHA
2012-03-17 20:01:54 +00:00
# define CPUSTRING "win-AXP-debug"
2007-11-04 03:34:51 +00:00
# endif
# endif
2012-03-17 20:01:54 +00:00
# define PATH_SEP '\\'
2007-11-04 03:34:51 +00:00
//======================= MAC OS X SERVER DEFINES =====================
2018-01-20 11:06:23 +00:00
# elif defined( __MACH__ ) && defined( __APPLE__ )
2007-11-04 03:34:51 +00:00
# define MAC_STATIC
# ifdef __ppc__
2012-03-17 20:01:54 +00:00
# define CPUSTRING "MacOSXS-ppc"
2007-11-04 03:34:51 +00:00
# elif defined __i386__
2012-03-17 20:01:54 +00:00
# define CPUSTRING "MacOSXS-i386"
2007-11-04 03:34:51 +00:00
# else
2012-03-17 20:01:54 +00:00
# define CPUSTRING "MacOSXS-other"
2007-11-04 03:34:51 +00:00
# endif
2012-03-17 20:01:54 +00:00
# define PATH_SEP ' / '
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define GAME_HARD_LINKED
# define CGAME_HARD_LINKED
# define UI_HARD_LINKED
2007-11-04 03:34:51 +00:00
# define _alloca alloca
# undef ALIGN_ON
# undef ALIGN_OFF
2012-03-17 20:01:54 +00:00
# define ALIGN_ON # pragma align( 16 )
# define ALIGN_OFF # pragma align()
2007-11-04 03:34:51 +00:00
# ifdef __cplusplus
2012-03-17 20:01:54 +00:00
extern " C " {
2007-11-04 03:34:51 +00:00
# endif
2012-03-17 20:01:54 +00:00
void * osxAllocateMemory ( long size ) ;
void osxFreeMemory ( void * pointer ) ;
2007-11-04 03:34:51 +00:00
# ifdef __cplusplus
2012-03-17 20:01:54 +00:00
}
2007-11-04 03:34:51 +00:00
# endif
//======================= MAC DEFINES =================================
2017-08-30 11:37:53 +00:00
# elif defined( __MACOS__ )
2007-11-04 03:34:51 +00:00
2017-08-30 11:51:04 +00:00
// the mac compiler can't handle >32k of locals, so we
// just waste space and make big arrays static...
2012-03-17 20:01:54 +00:00
# define MAC_STATIC static
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define CPUSTRING "MacOS-PPC"
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define PATH_SEP ':'
2007-11-04 03:34:51 +00:00
void Sys_PumpEvents ( void ) ;
2018-01-20 11:06:23 +00:00
# elif defined( __MRC__ )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define MAC_STATIC
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define CPUSTRING "MacOS-PPC"
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define PATH_SEP ':'
2007-11-04 03:34:51 +00:00
void Sys_PumpEvents ( void ) ;
# undef QDECL
2012-03-17 20:01:54 +00:00
# define QDECL __cdecl
2007-11-04 03:34:51 +00:00
# define _alloca alloca
//======================= LINUX DEFINES =================================
2017-08-30 11:37:53 +00:00
# elif defined( __linux__ )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define MAC_STATIC
2007-11-04 03:34:51 +00:00
# ifdef __i386__
2012-03-17 20:01:54 +00:00
# define CPUSTRING "linux-i386"
2007-11-04 03:34:51 +00:00
# elif defined __axp__
2012-03-17 20:01:54 +00:00
# define CPUSTRING "linux-alpha"
2007-11-04 03:34:51 +00:00
# else
2012-03-17 20:01:54 +00:00
# define CPUSTRING "linux-other"
2007-11-04 03:34:51 +00:00
# endif
2012-03-17 20:01:54 +00:00
# define PATH_SEP ' / '
2007-11-04 03:34:51 +00:00
2017-08-30 11:49:35 +00:00
//======================= FreeBSD DEFINES =================================
2017-08-30 11:37:53 +00:00
# elif defined( __FreeBSD__ )
2017-08-30 11:49:35 +00:00
# define MAC_STATIC
# ifdef __i386__
# define CPUSTRING "FreeBSD-i386"
# else
# define CPUSTRING "FreeBSD-other"
# endif
# define PATH_SEP ' / '
2007-11-04 03:34:51 +00:00
//=============================================================
2017-08-30 11:37:53 +00:00
# else
# error unknown architecture
# endif
2012-03-17 20:01:54 +00:00
typedef enum { qfalse , qtrue } qboolean ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
typedef unsigned char byte ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define EQUAL_EPSILON 0.001
2013-07-07 14:14:29 +00:00
typedef void * fileHandle_t ;
2007-11-04 03:34:51 +00:00
typedef enum {
INVALID_JOINT = - 1
} jointHandle_t ;
# ifndef NULL
2012-03-17 20:01:54 +00:00
# define NULL ( (void *)0 )
2007-11-04 03:34:51 +00:00
# endif
2012-03-17 20:01:54 +00:00
# define MAX_QINT 0x7fffffff
# define MIN_QINT ( -MAX_QINT - 1 )
2007-11-04 03:34:51 +00:00
# ifndef max
# define max( x, y ) ( ( ( x ) > ( y ) ) ? ( x ) : ( y ) )
# define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) )
# endif
# ifndef sign
2012-03-17 20:01:54 +00:00
# define sign( f ) ( ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 0 ) )
2007-11-04 03:34:51 +00:00
# endif
// angle indexes
2012-03-17 20:01:54 +00:00
# define PITCH 0 // up / down
# define YAW 1 // left / right
# define ROLL 2 // fall over
2007-11-04 03:34:51 +00:00
// the game guarantees that no string from the network will ever
// exceed MAX_STRING_CHARS
2012-03-17 20:01:54 +00:00
# define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
# define MAX_STRING_TOKENS 256 // max tokens resulting from Cmd_TokenizeString
# define MAX_TOKEN_CHARS 1024 // max length of an individual token
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define MAX_INFO_STRING 1024
# define MAX_INFO_KEY 1024
# define MAX_INFO_VALUE 1024
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define MAX_QPATH 64 // max length of a quake game pathname
# define MAX_OSPATH 128 // max length of a filesystem pathname
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define MAX_NAME_LENGTH 32 // max length of a client name
2007-11-04 03:34:51 +00:00
// paramters for command buffer stuffing
typedef enum {
2012-03-17 20:01:54 +00:00
EXEC_NOW , // don't return until completed, a VM should NEVER use this,
// because some commands might cause the VM to be unloaded...
EXEC_INSERT , // insert at current position, but don't run yet
EXEC_APPEND // add to end of the command buffer (normal case)
2007-11-04 03:34:51 +00:00
} cbufExec_t ;
//
// these aren't needed by any of the VMs. put in another header?
//
2012-03-17 20:01:54 +00:00
# define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# undef ERR_FATAL // malloc.h on unix
2007-11-04 03:34:51 +00:00
// parameters to the main Error routine
typedef enum {
ERR_NONE ,
2012-03-17 20:01:54 +00:00
ERR_FATAL , // exit the entire game with a popup window
ERR_DROP , // print to console and disconnect from game
ERR_DISCONNECT , // don't kill server
ERR_NEED_CD // pop up the need-cd dialog
2007-11-04 03:34:51 +00:00
} errorParm_t ;
// font rendering values used by ui and cgame
2012-03-17 20:01:54 +00:00
# define PROP_GAP_WIDTH 3
# define PROP_SPACE_WIDTH 8
# define PROP_HEIGHT 27
# define PROP_SMALL_SIZE_SCALE 0.75
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define BLINK_DIVISOR 200
# define PULSE_DIVISOR 75
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define UI_LEFT 0x00000000 // default
# define UI_CENTER 0x00000001
# define UI_RIGHT 0x00000002
# define UI_FORMATMASK 0x00000007
# define UI_SMALLFONT 0x00000010
# define UI_BIGFONT 0x00000020 // default
# define UI_GIANTFONT 0x00000040
# define UI_DROPSHADOW 0x00000800
# define UI_BLINK 0x00001000
# define UI_INVERSE 0x00002000
# define UI_PULSE 0x00004000
2007-11-04 03:34:51 +00:00
/*
2012-03-17 20:01:54 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
MATHLIB
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
# ifdef __cplusplus // so we can include this in C code
# define SIDE_FRONT 0
# define SIDE_BACK 1
# define SIDE_ON 2
# define SIDE_CROSS 3
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define Q_PI 3.14159265358979323846
2007-11-04 03:34:51 +00:00
# ifndef M_PI
2012-03-17 20:01:54 +00:00
# define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
2007-11-04 03:34:51 +00:00
# endif
# include "math_vector.h"
# include "math_angles.h"
# include "math_matrix.h"
# include "math_quaternion.h"
2012-03-17 20:01:54 +00:00
class idVec3 ; // for defining vectors
typedef idVec3 & vec3_p ; // for passing vectors as function arguments
typedef const idVec3 & vec3_c ; // for passing vectors as const function arguments
class angles_t ; // for defining angle vectors
typedef angles_t & angles_p ; // for passing angles as function arguments
typedef const angles_t & angles_c ; // for passing angles as const function arguments
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
class mat3_t ; // for defining matrices
typedef mat3_t & mat3_p ; // for passing matrices as function arguments
typedef const mat3_t & mat3_c ; // for passing matrices as const function arguments
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define NUMVERTEXNORMALS 162
extern idVec3 bytedirs [ NUMVERTEXNORMALS ] ;
2007-11-04 03:34:51 +00:00
// all drawing is done to a 640*480 virtual screen size
// and will be automatically scaled to the real resolution
2012-03-17 20:01:54 +00:00
# define SCREEN_WIDTH 640
# define SCREEN_HEIGHT 480
# define TINYCHAR_WIDTH ( SMALLCHAR_WIDTH )
# define TINYCHAR_HEIGHT ( SMALLCHAR_HEIGHT / 2 )
# define SMALLCHAR_WIDTH 8
# define SMALLCHAR_HEIGHT 16
# define BIGCHAR_WIDTH 16
# define BIGCHAR_HEIGHT 16
# define GIANTCHAR_WIDTH 32
# define GIANTCHAR_HEIGHT 48
extern idVec4 colorBlack ;
extern idVec4 colorRed ;
extern idVec4 colorGreen ;
extern idVec4 colorBlue ;
extern idVec4 colorYellow ;
extern idVec4 colorMagenta ;
extern idVec4 colorCyan ;
extern idVec4 colorWhite ;
extern idVec4 colorLtGrey ;
extern idVec4 colorMdGrey ;
extern idVec4 colorDkGrey ;
# define Q_COLOR_ESCAPE '^'
# define Q_IsColorString( p ) ( p && *( p ) == Q_COLOR_ESCAPE && *( ( p ) + 1 ) && *( ( p ) + 1 ) != Q_COLOR_ESCAPE )
# define COLOR_BLACK '0'
# define COLOR_RED '1'
# define COLOR_GREEN '2'
# define COLOR_YELLOW '3'
# define COLOR_BLUE '4'
# define COLOR_CYAN '5'
# define COLOR_MAGENTA '6'
# define COLOR_WHITE '7'
# define ColorIndex( c ) ( ( ( c ) - '0' ) & 7 )
# define S_COLOR_BLACK "^0"
# define S_COLOR_RED "^1"
# define S_COLOR_GREEN "^2"
# define S_COLOR_YELLOW "^3"
# define S_COLOR_BLUE "^4"
# define S_COLOR_CYAN "^5"
# define S_COLOR_MAGENTA "^6"
# define S_COLOR_WHITE "^7"
extern idVec4 g_color_table [ 8 ] ;
# define MAKERGB( v, r, g, b ) v[0] = r; v[1] = g; v[2] = b
# define MAKERGBA( v, r, g, b, a ) v[0] = r; v[1] = g; v[2] = b; v[3] = a
# define DEG2RAD( a ) ( ( ( a ) * M_PI ) / 180.0F )
# define RAD2DEG( a ) ( ( ( a ) * 180.0f ) / M_PI )
2007-11-04 03:34:51 +00:00
struct cplane_s ;
2012-03-17 20:01:54 +00:00
extern idVec3 vec3_origin ;
extern idVec4 vec4_origin ;
extern mat3_t axisDefault ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define nanmask ( 255 << 23 )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define IS_NAN( x ) ( ( ( *(int *)&x ) & nanmask ) == nanmask )
2007-11-04 03:34:51 +00:00
float Q_fabs ( float f ) ;
2012-03-17 20:01:54 +00:00
float Q_rsqrt ( float f ) ; // reciprocal square root
2007-11-04 03:34:51 +00:00
# define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) )
signed char ClampChar ( int i ) ;
signed short ClampShort ( int i ) ;
// this isn't a real cheap function to call!
int DirToByte ( const idVec3 & dir ) ;
void ByteToDir ( int b , vec3_p dir ) ;
2012-03-17 20:01:54 +00:00
# define DotProduct( a,b ) ( ( a )[0] * ( b )[0] + ( a )[1] * ( b )[1] + ( a )[2] * ( b )[2] )
# define VectorSubtract( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1],( c )[2] = ( a )[2] - ( b )[2] )
# define VectorAdd( a,b,c ) ( ( c )[0] = ( a )[0] + ( b )[0],( c )[1] = ( a )[1] + ( b )[1],( c )[2] = ( a )[2] + ( b )[2] )
# define VectorCopy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2] )
2007-11-04 03:34:51 +00:00
//#define VectorCopy(a,b) ((b).x=(a).x,(b).y=(a).y,(b).z=(a).z])
2012-03-17 20:01:54 +00:00
# define VectorScale( v, s, o ) ( ( o )[0] = ( v )[0] * ( s ),( o )[1] = ( v )[1] * ( s ),( o )[2] = ( v )[2] * ( s ) )
# define VectorMA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ) )
# define CrossProduct( a,b,c ) ( ( c )[0] = ( a )[1] * ( b )[2] - ( a )[2] * ( b )[1],( c )[1] = ( a )[2] * ( b )[0] - ( a )[0] * ( b )[2],( c )[2] = ( a )[0] * ( b )[1] - ( a )[1] * ( b )[0] )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define DotProduct4( x,y ) ( ( x )[0] * ( y )[0] + ( x )[1] * ( y )[1] + ( x )[2] * ( y )[2] + ( x )[3] * ( y )[3] )
# define VectorSubtract4( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1],( c )[2] = ( a )[2] - ( b )[2],( c )[3] = ( a )[3] - ( b )[3] )
# define VectorAdd4( a,b,c ) ( ( c )[0] = ( a )[0] + ( b )[0],( c )[1] = ( a )[1] + ( b )[1],( c )[2] = ( a )[2] + ( b )[2],( c )[3] = ( a )[3] + ( b )[3] )
# define VectorCopy4( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2],( b )[3] = ( a )[3] )
# define VectorScale4( v, s, o ) ( ( o )[0] = ( v )[0] * ( s ),( o )[1] = ( v )[1] * ( s ),( o )[2] = ( v )[2] * ( s ),( o )[3] = ( v )[3] * ( s ) )
# define VectorMA4( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ),( o )[3] = ( v )[3] + ( b )[3] * ( s ) )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define VectorClear( a ) ( ( a )[0] = ( a )[1] = ( a )[2] = 0 )
# define VectorNegate( a,b ) ( ( b )[0] = -( a )[0],( b )[1] = -( a )[1],( b )[2] = -( a )[2] )
# define VectorSet( v, x, y, z ) ( ( v )[0] = ( x ), ( v )[1] = ( y ), ( v )[2] = ( z ) )
# define Vector4Copy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2],( b )[3] = ( a )[3] )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define SnapVector( v ) {v[0] = (int)v[0]; v[1] = (int)v[1]; v[2] = (int)v[2]; }
2007-11-04 03:34:51 +00:00
float NormalizeColor ( vec3_c in , vec3_p out ) ;
int VectorCompare ( vec3_c v1 , vec3_c v2 ) ;
float VectorLength ( vec3_c v ) ;
float Distance ( vec3_c p1 , vec3_c p2 ) ;
float DistanceSquared ( vec3_c p1 , vec3_c p2 ) ;
2012-03-17 20:01:54 +00:00
float VectorNormalize ( vec3_p v ) ; // returns vector length
void VectorNormalizeFast ( vec3_p v ) ; // does NOT return vector length, uses rsqrt approximation
2007-11-04 03:34:51 +00:00
float VectorNormalize2 ( vec3_c v , vec3_p out ) ;
2012-03-17 20:01:54 +00:00
void VectorInverse ( vec3_p v ) ;
2007-11-04 03:34:51 +00:00
void VectorRotate ( vec3_c in , mat3_c matrix , vec3_p out ) ;
2012-03-17 20:01:54 +00:00
void VectorPolar ( vec3_p v , float radius , float theta , float phi ) ;
void VectorSnap ( vec3_p v ) ;
void Vector53Copy ( const idVec5_t & in , vec3_p out ) ;
void Vector5Scale ( const idVec5_t & v , float scale , idVec5_t & out ) ;
void Vector5Add ( const idVec5_t & va , const idVec5_t & vb , idVec5_t & out ) ;
void VectorRotate3 ( vec3_c vIn , vec3_c vRotation , vec3_p out ) ;
void VectorRotate3Origin ( vec3_c vIn , vec3_c vRotation , vec3_c vOrigin , vec3_p out ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
int Q_log2 ( int val ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
int Q_rand ( int * seed ) ;
float Q_random ( int * seed ) ;
float Q_crandom ( int * seed ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define random() ( ( rand() & 0x7fff ) / ( (float)0x7fff ) )
# define crandom() ( 2.0 * ( random() - 0.5 ) )
2007-11-04 03:34:51 +00:00
float Q_rint ( float in ) ;
2012-03-17 20:01:54 +00:00
void vectoangles ( vec3_c value1 , angles_p angles ) ;
2007-11-04 03:34:51 +00:00
void AnglesToAxis ( angles_c angles , mat3_p axis ) ;
void AxisCopy ( mat3_c in , mat3_p out ) ;
2012-03-17 20:01:54 +00:00
qboolean AxisRotated ( mat3_c in ) ; // assumes a non-degenerate axis
2007-11-04 03:34:51 +00:00
int SignbitsForNormal ( vec3_c normal ) ;
int BoxOnPlaneSide ( const Bounds & b , struct cplane_s * p ) ;
2012-03-17 20:01:54 +00:00
float AngleMod ( float a ) ;
float LerpAngle ( float from , float to , float frac ) ;
float AngleSubtract ( float a1 , float a2 ) ;
void AnglesSubtract ( angles_c v1 , angles_c v2 , angles_p v3 ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
float AngleNormalize360 ( float angle ) ;
float AngleNormalize180 ( float angle ) ;
float AngleDelta ( float angle1 , float angle2 ) ;
2007-11-04 03:34:51 +00:00
qboolean PlaneFromPoints ( idVec4 & plane , vec3_c a , vec3_c b , vec3_c c ) ;
void ProjectPointOnPlane ( vec3_p dst , vec3_c p , vec3_c normal ) ;
void RotatePointAroundVector ( vec3_p dst , vec3_c dir , vec3_c point , float degrees ) ;
void RotateAroundDirection ( mat3_p axis , float yaw ) ;
void MakeNormalVectors ( vec3_c forward , vec3_p right , vec3_p up ) ;
// perpendicular vector could be replaced by this
2012-03-17 20:01:54 +00:00
int PlaneTypeForNormal ( vec3_c normal ) ;
2007-11-04 03:34:51 +00:00
void MatrixMultiply ( mat3_c in1 , mat3_c in2 , mat3_p out ) ;
2012-03-17 20:01:54 +00:00
void MatrixInverseMultiply ( mat3_c in1 , mat3_c in2 , mat3_p out ) ; // in2 is transposed during multiply
2007-11-04 03:34:51 +00:00
void MatrixTransformVector ( vec3_c in , mat3_c matrix , vec3_p out ) ;
void MatrixProjectVector ( vec3_c in , mat3_c matrix , vec3_p out ) ; // Places the vector into a new coordinate system.
2012-03-17 20:01:54 +00:00
void AngleVectors ( angles_c angles , vec3_p forward , vec3_p right , vec3_p up ) ;
2007-11-04 03:34:51 +00:00
void PerpendicularVector ( vec3_p dst , vec3_c src ) ;
float TriangleArea ( vec3_c a , vec3_c b , vec3_c c ) ;
2012-03-17 20:01:54 +00:00
# endif // __cplusplus
2007-11-04 03:34:51 +00:00
//=============================================
float Com_Clamp ( float min , float max , float value ) ;
2012-03-17 20:01:54 +00:00
# define FILE_HASH_SIZE 1024
2007-11-04 03:34:51 +00:00
int Com_HashString ( const char * fname ) ;
2012-03-17 20:01:54 +00:00
char * Com_SkipPath ( char * pathname ) ;
2007-11-04 03:34:51 +00:00
// it is ok for out == in
2012-03-17 20:01:54 +00:00
void Com_StripExtension ( const char * in , char * out ) ;
2007-11-04 03:34:51 +00:00
// "extension" should include the dot: ".map"
2012-03-17 20:01:54 +00:00
void Com_DefaultExtension ( char * path , int maxSize , const char * extension ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
int Com_ParseInfos ( const char * buf , int max , char infos [ ] [ MAX_INFO_STRING ] ) ;
2007-11-04 03:34:51 +00:00
/*
2012-03-17 20:01:54 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
SCRIPT PARSING
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2007-11-04 03:34:51 +00:00
// this just controls the comment printing, it doesn't actually load a file
void Com_BeginParseSession ( const char * filename ) ;
void Com_EndParseSession ( void ) ;
int Com_GetCurrentParseLine ( void ) ;
// Will never return NULL, just empty strings.
// An empty string will only be returned at end of file.
// ParseOnLine will return empty if there isn't another token on this line
// this funny typedef just means a moving pointer into a const char * buffer
2012-03-17 20:01:54 +00:00
const char * Com_Parse ( const char * ( * data_p ) ) ;
const char * Com_ParseOnLine ( const char * ( * data_p ) ) ;
const char * Com_ParseRestOfLine ( const char * ( * data_p ) ) ;
2007-11-04 03:34:51 +00:00
void Com_UngetToken ( void ) ;
# ifdef __cplusplus
2012-03-17 20:01:54 +00:00
void Com_MatchToken ( const char * ( * buf_p ) , const char * match , qboolean warning = qfalse ) ;
2007-11-04 03:34:51 +00:00
# else
2012-03-17 20:01:54 +00:00
void Com_MatchToken ( const char * ( * buf_p ) , const char * match , qboolean warning ) ;
2007-11-04 03:34:51 +00:00
# endif
void Com_ScriptError ( const char * msg , . . . ) ;
void Com_ScriptWarning ( const char * msg , . . . ) ;
2012-03-17 20:01:54 +00:00
void Com_SkipBracedSection ( const char * ( * program ) ) ;
void Com_SkipRestOfLine ( const char * ( * data ) ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
float Com_ParseFloat ( const char * ( * buf_p ) ) ;
int Com_ParseInt ( const char * ( * buf_p ) ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
void Com_Parse1DMatrix ( const char * ( * buf_p ) , int x , float * m ) ;
void Com_Parse2DMatrix ( const char * ( * buf_p ) , int y , int x , float * m ) ;
void Com_Parse3DMatrix ( const char * ( * buf_p ) , int z , int y , int x , float * m ) ;
2007-11-04 03:34:51 +00:00
//=====================================================================================
# ifdef __cplusplus
2012-03-17 20:01:54 +00:00
extern " C " {
2007-11-04 03:34:51 +00:00
# endif
2012-03-17 20:01:54 +00:00
void QDECL Com_sprintf ( char * dest , int size , const char * fmt , . . . ) ;
2007-11-04 03:34:51 +00:00
// mode parm for FS_FOpenFile
typedef enum {
FS_READ ,
FS_WRITE ,
FS_APPEND ,
FS_APPEND_SYNC
} fsMode_t ;
typedef enum {
FS_SEEK_CUR ,
FS_SEEK_END ,
FS_SEEK_SET
} fsOrigin_t ;
//=============================================
int Q_isprint ( int c ) ;
int Q_islower ( int c ) ;
int Q_isupper ( int c ) ;
int Q_isalpha ( int c ) ;
// portable case insensitive compare
2012-03-17 20:01:54 +00:00
int Q_stricmp ( const char * s1 , const char * s2 ) ;
int Q_strncmp ( const char * s1 , const char * s2 , int n ) ;
int Q_stricmpn ( const char * s1 , const char * s2 , int n ) ;
char * Q_strlwr ( char * s1 ) ;
char * Q_strupr ( char * s1 ) ;
char * Q_strrchr ( const char * string , int c ) ;
2007-11-04 03:34:51 +00:00
// buffer size safe library replacements
2012-03-17 20:01:54 +00:00
void Q_strncpyz ( char * dest , const char * src , int destsize ) ;
void Q_strcat ( char * dest , int size , const char * src ) ;
2007-11-04 03:34:51 +00:00
// strlen that discounts Quake color sequences
int Q_PrintStrlen ( const char * string ) ;
// removes color sequences from string
char * Q_CleanStr ( char * string ) ;
2012-03-17 20:01:54 +00:00
int Com_Filter ( const char * filter , const char * name , int casesensitive ) ;
2007-11-04 03:34:51 +00:00
const char * Com_StringContains ( const char * str1 , const char * str2 , int casesensitive ) ;
//=============================================
2012-03-17 20:01:54 +00:00
short BigShort ( short l ) ;
short LittleShort ( short l ) ;
int BigLong ( int l ) ;
int LittleLong ( int l ) ;
float BigFloat ( float l ) ;
float LittleFloat ( float l ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
void Swap_Init ( void ) ;
2013-05-03 06:57:29 +00:00
char * QDECL va ( const char * format , . . . ) ;
2007-11-04 03:34:51 +00:00
# ifdef __cplusplus
2012-03-17 20:01:54 +00:00
}
2007-11-04 03:34:51 +00:00
# endif
//=============================================
# ifdef __cplusplus
//
// mapfile parsing
//
typedef struct ePair_s {
2012-03-17 20:01:54 +00:00
char * key ;
char * value ;
2007-11-04 03:34:51 +00:00
} ePair_t ;
typedef struct mapSide_s {
2012-03-17 20:01:54 +00:00
char material [ MAX_QPATH ] ;
idVec4 plane ;
idVec4 textureVectors [ 2 ] ;
2007-11-04 03:34:51 +00:00
} mapSide_t ;
typedef struct {
2012-03-17 20:01:54 +00:00
int numSides ;
mapSide_t * * sides ;
2007-11-04 03:34:51 +00:00
} mapBrush_t ;
typedef struct {
2012-03-17 20:01:54 +00:00
idVec3 xyz ;
float st [ 2 ] ;
2007-11-04 03:34:51 +00:00
} patchVertex_t ;
typedef struct {
2012-03-17 20:01:54 +00:00
char material [ MAX_QPATH ] ;
int width , height ;
patchVertex_t * patchVerts ;
2007-11-04 03:34:51 +00:00
} mapPatch_t ;
typedef struct {
2012-03-17 20:01:54 +00:00
char modelName [ MAX_QPATH ] ;
float matrix [ 16 ] ;
2007-11-04 03:34:51 +00:00
} mapModel_t ;
typedef struct mapPrimitive_s {
2012-03-17 20:01:54 +00:00
int numEpairs ;
ePair_t * * ePairs ;
2007-11-04 03:34:51 +00:00
// only one of these will be non-NULL
2012-03-17 20:01:54 +00:00
mapBrush_t * brush ;
mapPatch_t * patch ;
mapModel_t * model ;
2007-11-04 03:34:51 +00:00
} mapPrimitive_t ;
typedef struct mapEntity_s {
2012-03-17 20:01:54 +00:00
int numPrimitives ;
mapPrimitive_t * * primitives ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
int numEpairs ;
ePair_t * * ePairs ;
2007-11-04 03:34:51 +00:00
} mapEntity_t ;
typedef struct {
2012-03-17 20:01:54 +00:00
int numEntities ;
mapEntity_t * * entities ;
2007-11-04 03:34:51 +00:00
} mapFile_t ;
// the order of entities, brushes, and sides will be maintained, the
// lists won't be swapped on each load or save
mapFile_t * ParseMapFile ( const char * text ) ;
void FreeMapFile ( mapFile_t * mapFile ) ;
void WriteMapFile ( const mapFile_t * mapFile , FILE * f ) ;
// key names are case-insensitive
2012-03-17 20:01:54 +00:00
const char * ValueForMapEntityKey ( const mapEntity_t * ent , const char * key ) ;
float FloatForMapEntityKey ( const mapEntity_t * ent , const char * key ) ;
qboolean GetVectorForMapEntityKey ( const mapEntity_t * ent , const char * key , idVec3 & vec ) ;
2007-11-04 03:34:51 +00:00
typedef struct {
2012-03-17 20:01:54 +00:00
idVec3 xyz ;
idVec2 st ;
idVec3 normal ;
idVec3 tangents [ 2 ] ;
byte smoothing [ 4 ] ; // colors for silhouette smoothing
2007-11-04 03:34:51 +00:00
} drawVert_t ;
typedef struct {
2012-03-17 20:01:54 +00:00
int width , height ;
drawVert_t * verts ;
2007-11-04 03:34:51 +00:00
} drawVertMesh_t ;
// Tesselate a map patch into smoothed, drawable vertexes
// MaxError of around 4 is reasonable
drawVertMesh_t * SubdivideMapPatch ( const mapPatch_t * patch , float maxError ) ;
2012-03-17 20:01:54 +00:00
# endif // __cplusplus
2007-11-04 03:34:51 +00:00
//=========================================
# ifdef __cplusplus
2012-03-17 20:01:54 +00:00
extern " C " {
2007-11-04 03:34:51 +00:00
# endif
2012-03-17 20:01:54 +00:00
void QDECL Com_Error ( int level , const char * error , . . . ) ;
void QDECL Com_Printf ( const char * msg , . . . ) ;
void QDECL Com_DPrintf ( const char * msg , . . . ) ;
2007-11-04 03:34:51 +00:00
# ifdef __cplusplus
2012-03-17 20:01:54 +00:00
}
2007-11-04 03:34:51 +00:00
# endif
typedef struct {
2012-03-17 20:01:54 +00:00
qboolean frameMemory ;
int currentElements ;
int maxElements ; // will reallocate and move when exceeded
void * * elements ;
2007-11-04 03:34:51 +00:00
} growList_t ;
// you don't need to init the growlist if you don't mind it growing and moving
// the list as it expands
2012-03-17 20:01:54 +00:00
void Com_InitGrowList ( growList_t * list , int maxElements ) ;
int Com_AddToGrowList ( growList_t * list , void * data ) ;
void * Com_GrowListElement ( const growList_t * list , int index ) ;
int Com_IndexForGrowListElement ( const growList_t * list , const void * element ) ;
2007-11-04 03:34:51 +00:00
//
// key / value info strings
//
char * Info_ValueForKey ( const char * s , const char * key ) ;
void Info_RemoveKey ( char * s , const char * key ) ;
void Info_SetValueForKey ( char * s , const char * key , const char * value ) ;
qboolean Info_Validate ( const char * s ) ;
2012-03-17 20:01:54 +00:00
void Info_NextPair ( const char * ( * s ) , char key [ MAX_INFO_KEY ] , char value [ MAX_INFO_VALUE ] ) ;
2007-11-04 03:34:51 +00:00
// get cvar defs, collision defs, etc
//#include "../shared/interface.h"
// get key code numbers for events
//#include "../shared/keycodes.h"
# ifdef __cplusplus
// get the polygon winding functions
//#include "../shared/windings.h"
// get the flags class
//#include "../shared/idflags.h"
2012-03-17 20:01:54 +00:00
# endif // __cplusplus
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# endif // __Q_SHARED_H