From 5ec3a47e102a60270ba18049bc44c584cf1de118 Mon Sep 17 00:00:00 2001 From: rpolzer Date: Tue, 5 Oct 2010 10:57:07 +0200 Subject: [PATCH] q3map2 is now waring free --- libs/l_net/l_net.c | 8 +-- libs/l_net/l_net.h | 6 +- libs/l_net/l_net_berkley.c | 16 +++-- libs/l_net/l_net_wins.c | 8 +-- libs/mathlib/m4x4.c | 13 ++-- libs/picomodel.h | 14 ++-- libs/picomodel/lwo/envelope.c | 2 +- libs/picomodel/lwo/lwio.c | 6 +- libs/picomodel/lwo/lwo2.c | 10 +-- libs/picomodel/lwo/lwo2.h | 8 +-- libs/picomodel/lwo/lwob.c | 31 +++++++-- libs/picomodel/picointernal.c | 18 ++--- libs/picomodel/picointernal.h | 20 +++--- libs/picomodel/picomodel.c | 10 +-- libs/picomodel/pm_3ds.c | 14 ++-- libs/picomodel/pm_ase.c | 9 +-- libs/picomodel/pm_fm.c | 38 +++++++++-- libs/picomodel/pm_lwo.c | 4 +- libs/picomodel/pm_md2.c | 29 ++++---- libs/picomodel/pm_md3.c | 25 ++++--- libs/picomodel/pm_mdc.c | 29 ++++---- libs/picomodel/pm_ms3d.c | 19 +++--- libs/picomodel/pm_obj.c | 8 +-- libs/picomodel/pm_terrain.c | 10 +-- tools/quake3/common/cmdlib.c | 8 +-- tools/quake3/common/cmdlib.h | 6 +- tools/quake3/common/imagelib.c | 5 +- tools/quake3/common/inout.c | 48 ++++++------- tools/quake3/common/unzip.c | 13 +++- tools/quake3/q3map2/bsp.c | 8 +-- tools/quake3/q3map2/game__null.h | 98 +++++++++++++++++++++++++++ tools/quake3/q3map2/image.c | 6 +- tools/quake3/q3map2/leakfile.c | 6 +- tools/quake3/q3map2/light.c | 4 +- tools/quake3/q3map2/light_bounce.c | 4 +- tools/quake3/q3map2/light_trace.c | 46 ++----------- tools/quake3/q3map2/light_ydnar.c | 48 +++++++++---- tools/quake3/q3map2/lightmaps_ydnar.c | 20 +++--- tools/quake3/q3map2/map.c | 4 +- tools/quake3/q3map2/model.c | 8 +-- tools/quake3/q3map2/path_init.c | 4 +- tools/quake3/q3map2/q3map2.h | 9 +-- tools/quake3/q3map2/surface.c | 2 +- tools/quake3/q3map2/surface_extra.c | 2 +- tools/quake3/q3map2/surface_meta.c | 79 +++++---------------- tools/quake3/q3map2/tjunction.c | 4 +- tools/quake3/q3map2/vis.c | 8 +-- 47 files changed, 454 insertions(+), 341 deletions(-) create mode 100644 tools/quake3/q3map2/game__null.h diff --git a/libs/l_net/l_net.c b/libs/l_net/l_net.c index 878e6a4..ca730d0 100644 --- a/libs/l_net/l_net.c +++ b/libs/l_net/l_net.c @@ -43,7 +43,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define qfalse 0 #ifdef _DEBUG -void WinPrint(char *str, ...) +void WinPrint(const char *str, ...) { va_list argptr; char text[4096]; @@ -55,7 +55,7 @@ void WinPrint(char *str, ...) printf(text); } #else -void WinPrint(char *str, ...) +void WinPrint(const char *str, ...) { } #endif @@ -323,7 +323,7 @@ void Net_Disconnect(socket_t *sock) // Returns: - // Changes Globals: - //=========================================================================== -void Net_StringToAddress(char *string, address_t *address) +void Net_StringToAddress(const char *string, address_t *address) { strcpy(address->ip, string); } //end of the function Net_StringToAddress @@ -620,7 +620,7 @@ char *NMSG_ReadString(netmessage_t *msg) if (c == 0) break; string[l] = c; l++; - } while (l < sizeof(string)-1); + } while ((size_t) l < sizeof(string)-1); string[l] = 0; return string; } //end of the function NMSG_ReadString diff --git a/libs/l_net/l_net.h b/libs/l_net/l_net.h index 0009601..6c54833 100644 --- a/libs/l_net/l_net.h +++ b/libs/l_net/l_net.h @@ -73,12 +73,14 @@ typedef struct socket_s struct socket_s *prev, *next; //prev and next socket in a list } socket_t; +void WinPrint(const char *format, ...); + //compare addresses int Net_AddressCompare(address_t *addr1, address_t *addr2); //gives the address of a socket void Net_SocketToAddress(socket_t *sock, address_t *address); //converts a string to an address -void Net_StringToAddress(char *string, address_t *address); +void Net_StringToAddress(const char *string, address_t *address); //set the address ip port void Net_SetAddressPort(address_t *address, int port); //send a message to the given socket @@ -118,7 +120,7 @@ float NMSG_ReadFloat(netmessage_t *msg); char *NMSG_ReadString(netmessage_t *msg); //++timo FIXME: the WINS_ things are not necessary, they can be made portable arther easily -char *WINS_ErrorMessage(int error); +const char *WINS_ErrorMessage(int error); #ifdef __cplusplus } diff --git a/libs/l_net/l_net_berkley.c b/libs/l_net/l_net_berkley.c index 19d670b..edc06fa 100644 --- a/libs/l_net/l_net_berkley.c +++ b/libs/l_net/l_net_berkley.c @@ -41,8 +41,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include #include +#include +#include +#include #define SOCKET_ERROR -1 #define INVALID_SOCKET -1 @@ -112,7 +116,7 @@ ERROR_STRUCT errlist[] = { // Returns: - // Changes Globals: - //=========================================================================== -char *WINS_ErrorMessage(int error) +const char *WINS_ErrorMessage(int error) { int search = 0; @@ -121,7 +125,7 @@ char *WINS_ErrorMessage(int error) for (search = 0; errlist[search].errstr; search++) { if (error == errlist[search].errnum) - return (char *)errlist[search].errstr; + return errlist[search].errstr; } //end for return "Unknown error"; @@ -139,7 +143,6 @@ int WINS_Init(void) char buff[MAXHOSTNAMELEN]; struct sockaddr_s addr; char *p; - int r; /* linux doesn't have anything to initialize for the net "Windows .. built for the internet .. the internet .. built with unix" @@ -365,7 +368,7 @@ int WINS_Listen(int socket) //=========================================================================== int WINS_Accept(int socket, struct sockaddr_s *addr) { - int addrlen = sizeof (struct sockaddr_s); + socklen_t addrlen = sizeof (struct sockaddr_s); int newsocket; qboolean _true = 1; @@ -496,7 +499,7 @@ int WINS_CheckNewConnections(void) //=========================================================================== int WINS_Read(int socket, byte *buf, int len, struct sockaddr_s *addr) { - int addrlen = sizeof (struct sockaddr_s); + socklen_t addrlen = sizeof (struct sockaddr_s); int ret; if (addr) @@ -583,6 +586,7 @@ int WINS_Broadcast (int socket, byte *buf, int len) int WINS_Write(int socket, byte *buf, int len, struct sockaddr_s *addr) { int ret, written; + ret = 0; if (addr) { @@ -670,7 +674,7 @@ int WINS_StringToAddr(char *string, struct sockaddr_s *addr) //=========================================================================== int WINS_GetSocketAddr(int socket, struct sockaddr_s *addr) { - int addrlen = sizeof(struct sockaddr_s); + socklen_t addrlen = sizeof(struct sockaddr_s); unsigned int a; memset(addr, 0, sizeof(struct sockaddr_s)); diff --git a/libs/l_net/l_net_wins.c b/libs/l_net/l_net_wins.c index faf7d88..1b365da 100644 --- a/libs/l_net/l_net_wins.c +++ b/libs/l_net/l_net_wins.c @@ -136,19 +136,13 @@ ERROR_STRUCT errlist[] = { {-1, NULL} }; -#ifdef _DEBUG -void WinPrint(char *str, ...); -#else -void WinPrint(char *str, ...); -#endif - //=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== -char *WINS_ErrorMessage(int error) +const char *WINS_ErrorMessage(int error) { int search = 0; diff --git a/libs/mathlib/m4x4.c b/libs/mathlib/m4x4.c index b2c2db7..3b11461 100644 --- a/libs/mathlib/m4x4.c +++ b/libs/mathlib/m4x4.c @@ -1626,20 +1626,21 @@ void m4_submat( m4x4_t mr, m3x3_t mb, int i, int j ) { if ( ti < i ) idst = ti; + else if ( ti > i ) + idst = ti-1; else - if ( ti > i ) - idst = ti-1; + continue; for ( tj = 0; tj < 4; tj++ ) { if ( tj < j ) jdst = tj; + else if ( tj > j ) + jdst = tj-1; else - if ( tj > j ) - jdst = tj-1; + continue; - if ( ti != i && tj != j ) - mb[idst*3 + jdst] = mr[ti*4 + tj ]; + mb[idst*3 + jdst] = mr[ti*4 + tj ]; } } } diff --git a/libs/picomodel.h b/libs/picomodel.h index bb47be0..1e6f892 100644 --- a/libs/picomodel.h +++ b/libs/picomodel.h @@ -175,16 +175,16 @@ enum /* convenience (makes it easy to add new params to the callbacks) */ #define PM_PARAMS_CANLOAD \ - char *fileName, const void *buffer, int bufSize + const char *fileName, const void *buffer, int bufSize #define PM_PARAMS_LOAD \ - char *fileName, int frameNum, const void *buffer, int bufSize + const char *fileName, int frameNum, const void *buffer, int bufSize #define PM_PARAMS_CANSAVE \ void #define PM_PARAMS_SAVE \ - char *fileName, picoModel_t *model + const char *fileName, picoModel_t *model /* pico file format module structure */ struct picoModule_s @@ -211,13 +211,13 @@ int PicoError( void ); void PicoSetMallocFunc( void *(*func)( size_t ) ); void PicoSetFreeFunc( void (*func)( void* ) ); -void PicoSetLoadFileFunc( void (*func)( char*, unsigned char**, int* ) ); +void PicoSetLoadFileFunc( void (*func)( const char*, unsigned char**, int* ) ); void PicoSetFreeFileFunc( void (*func)( void* ) ); void PicoSetPrintFunc( void (*func)( int, const char* ) ); const picoModule_t **PicoModuleList( int *numModules ); -picoModel_t *PicoLoadModel( char *name, int frameNum ); +picoModel_t *PicoLoadModel( const char *name, int frameNum ); typedef size_t (*PicoInputStreamReadFunc)(void* inputStream, unsigned char* buffer, size_t length); picoModel_t* PicoModuleLoadModelStream( const picoModule_t* module, void* inputStream, PicoInputStreamReadFunc inputStreamRead, size_t streamLength, int frameNum, const char *fileName ); @@ -242,8 +242,8 @@ int PicoAdjustSurface( picoSurface_t *surface, int numVertexes, int numSTA /* setter functions */ -void PicoSetModelName( picoModel_t *model, char *name ); -void PicoSetModelFileName( picoModel_t *model, char *fileName ); +void PicoSetModelName( picoModel_t *model, const char *name ); +void PicoSetModelFileName( picoModel_t *model, const char *fileName ); void PicoSetModelFrameNum( picoModel_t *model, int frameNum ); void PicoSetModelNumFrames( picoModel_t *model, int numFrames ); void PicoSetModelData( picoModel_t *model, void *data ); diff --git a/libs/picomodel/lwo/envelope.c b/libs/picomodel/lwo/envelope.c index 0b8ef4e..3720a8e 100644 --- a/libs/picomodel/lwo/envelope.c +++ b/libs/picomodel/lwo/envelope.c @@ -44,7 +44,7 @@ Read an ENVL chunk from an LWO2 file. lwEnvelope *lwGetEnvelope( picoMemStream_t *fp, int cksize ) { lwEnvelope *env; - lwKey *key; + lwKey *key = NULL; lwPlugin *plug; unsigned int id; unsigned short sz; diff --git a/libs/picomodel/lwo/lwio.c b/libs/picomodel/lwo/lwio.c index 9853c55..63e9af7 100644 --- a/libs/picomodel/lwo/lwio.c +++ b/libs/picomodel/lwo/lwio.c @@ -311,7 +311,7 @@ int sgetI1( unsigned char **bp ) i = **bp; if ( i > 127 ) i -= 256; flen += 1; - *bp++; + (*bp)++; return i; } @@ -349,7 +349,7 @@ unsigned char sgetU1( unsigned char **bp ) if ( flen == FLEN_ERROR ) return 0; c = **bp; flen += 1; - *bp++; + (*bp)++; return c; } @@ -422,7 +422,7 @@ char *sgetS0( unsigned char **bp ) if ( flen == FLEN_ERROR ) return NULL; - len = strlen( buf ) + 1; + len = strlen( (const char *) buf ) + 1; if ( len == 1 ) { flen += 2; *bp += 2; diff --git a/libs/picomodel/lwo/lwo2.c b/libs/picomodel/lwo/lwo2.c index ff83d5c..56c756c 100644 --- a/libs/picomodel/lwo/lwo2.c +++ b/libs/picomodel/lwo/lwo2.c @@ -76,13 +76,13 @@ can be used to diagnose the cause. If you don't need this information, failID and failpos can be NULL. ====================================================================== */ -lwObject *lwGetObject( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) +lwObject *lwGetObject( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) { lwObject *object; lwLayer *layer; lwNode *node; - unsigned int id, formsize, type, cksize; - int i, rlen; + unsigned int id, formsize, type; + int i, rlen, cksize; /* open the file */ @@ -233,7 +233,7 @@ lwObject *lwGetObject( char *filename, picoMemStream_t *fp, unsigned int *failID /* end of the file? */ - if ( formsize <= _pico_memstream_tell( fp ) - 8 ) break; + if ( formsize <= (unsigned int) (_pico_memstream_tell( fp ) - 8) ) break; /* get the next chunk header */ @@ -270,7 +270,7 @@ Fail: return NULL; } -int lwValidateObject( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) +int lwValidateObject( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) { unsigned int id, formsize, type; diff --git a/libs/picomodel/lwo/lwo2.h b/libs/picomodel/lwo/lwo2.h index 29724cc..e5b9611 100644 --- a/libs/picomodel/lwo/lwo2.h +++ b/libs/picomodel/lwo/lwo2.h @@ -539,8 +539,8 @@ typedef struct st_lwObject { void lwFreeLayer( lwLayer *layer ); void lwFreeObject( lwObject *object ); -lwObject *lwGetObject( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); -int lwValidateObject( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); +lwObject *lwGetObject( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); +int lwValidateObject( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); /* pntspols.c */ @@ -600,8 +600,8 @@ lwSurface *lwDefaultSurface( void ); lwSurface *lwGetSurface5( picoMemStream_t *fp, int cksize, lwObject *obj ); int lwGetPolygons5( picoMemStream_t *fp, int cksize, lwPolygonList *plist, int ptoffset ); -lwObject *lwGetObject5( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); -int lwValidateObject5( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); +lwObject *lwGetObject5( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); +int lwValidateObject5( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ); /* list.c */ diff --git a/libs/picomodel/lwo/lwob.c b/libs/picomodel/lwo/lwob.c index 0b7c372..2d0522d 100644 --- a/libs/picomodel/lwo/lwob.c +++ b/libs/picomodel/lwo/lwob.c @@ -70,7 +70,7 @@ static int add_clip( char *s, lwClip **clist, int *nclips ) clip->saturation.val = 1.0f; clip->gamma.val = 1.0f; - if ( p = strstr( s, "(sequence)" )) { + if ((p = strstr( s, "(sequence)" ))) { p[ -1 ] = 0; clip->type = ID_ISEQ; clip->source.seq.prefix = s; @@ -81,7 +81,7 @@ static int add_clip( char *s, lwClip **clist, int *nclips ) clip->source.still.name = s; } - *nclips++; + (*nclips)++; clip->index = *nclips; lwListAdd( (void *) clist, clip ); @@ -188,8 +188,8 @@ Read an lwSurface from an LWOB file. lwSurface *lwGetSurface5( picoMemStream_t *fp, int cksize, lwObject *obj ) { lwSurface *surf; - lwTexture *tex; - lwPlugin *shdr; + lwTexture *tex = NULL; + lwPlugin *shdr = NULL; char *s; float v[ 3 ]; unsigned int id, flags; @@ -352,11 +352,14 @@ lwSurface *lwGetSurface5( picoMemStream_t *fp, int cksize, lwObject *obj ) break; case ID_TFLG: + if(!tex) goto Fail; flags = getU2( fp ); + i = -1; if ( flags & 1 ) i = 0; if ( flags & 2 ) i = 1; if ( flags & 4 ) i = 2; + if(i < 0) goto Fail; tex->axis = i; if ( tex->type == ID_IMAP ) tex->param.imap.axis = i; @@ -373,21 +376,25 @@ lwSurface *lwGetSurface5( picoMemStream_t *fp, int cksize, lwObject *obj ) break; case ID_TSIZ: + if(!tex) goto Fail; for ( i = 0; i < 3; i++ ) tex->tmap.size.val[ i ] = getF4( fp ); break; case ID_TCTR: + if(!tex) goto Fail; for ( i = 0; i < 3; i++ ) tex->tmap.center.val[ i ] = getF4( fp ); break; case ID_TFAL: + if(!tex) goto Fail; for ( i = 0; i < 3; i++ ) tex->tmap.falloff.val[ i ] = getF4( fp ); break; case ID_TVEL: + if(!tex) goto Fail; for ( i = 0; i < 3; i++ ) v[ i ] = getF4( fp ); tex->tmap.center.eindex = add_tvel( tex->tmap.center.val, v, @@ -395,44 +402,53 @@ lwSurface *lwGetSurface5( picoMemStream_t *fp, int cksize, lwObject *obj ) break; case ID_TCLR: + if(!tex) goto Fail; if ( tex->type == ID_PROC ) for ( i = 0; i < 3; i++ ) tex->param.proc.value[ i ] = getU1( fp ) / 255.0f; break; case ID_TVAL: + if(!tex) goto Fail; tex->param.proc.value[ 0 ] = getI2( fp ) / 256.0f; break; case ID_TAMP: + if(!tex) goto Fail; if ( tex->type == ID_IMAP ) tex->param.imap.amplitude.val = getF4( fp ); break; case ID_TIMG: + if(!tex) goto Fail; s = getS0( fp ); tex->param.imap.cindex = add_clip( s, &obj->clip, &obj->nclips ); break; case ID_TAAS: + if(!tex) goto Fail; tex->param.imap.aa_strength = getF4( fp ); tex->param.imap.aas_flags = 1; break; case ID_TREF: + if(!tex) goto Fail; tex->tmap.ref_object = getbytes( fp, sz ); break; case ID_TOPC: + if(!tex) goto Fail; tex->opacity.val = getF4( fp ); break; case ID_TFP0: + if(!tex) goto Fail; if ( tex->type == ID_IMAP ) tex->param.imap.wrapw.val = getF4( fp ); break; case ID_TFP1: + if(!tex) goto Fail; if ( tex->type == ID_IMAP ) tex->param.imap.wraph.val = getF4( fp ); break; @@ -446,6 +462,7 @@ lwSurface *lwGetSurface5( picoMemStream_t *fp, int cksize, lwObject *obj ) break; case ID_SDAT: + if(!shdr) goto Fail; shdr->data = getbytes( fp, sz ); break; @@ -583,7 +600,7 @@ to diagnose the cause. If you don't need this information, failID and failpos can be NULL. ====================================================================== */ -lwObject *lwGetObject5( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) +lwObject *lwGetObject5( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) { lwObject *object; lwLayer *layer; @@ -665,7 +682,7 @@ lwObject *lwGetObject5( char *filename, picoMemStream_t *fp, unsigned int *failI /* end of the file? */ - if ( formsize <= _pico_memstream_tell( fp ) - 8 ) break; + if ( formsize <= (unsigned int) (_pico_memstream_tell( fp ) - 8) ) break; /* get the next chunk header */ @@ -693,7 +710,7 @@ Fail: return NULL; } -int lwValidateObject5( char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) +int lwValidateObject5( const char *filename, picoMemStream_t *fp, unsigned int *failID, int *failpos ) { unsigned int id, formsize, type; diff --git a/libs/picomodel/picointernal.c b/libs/picomodel/picointernal.c index 2221492..f08a996 100644 --- a/libs/picomodel/picointernal.c +++ b/libs/picomodel/picointernal.c @@ -52,7 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* function pointers */ void *(*_pico_ptr_malloc )( size_t ) = malloc; void (*_pico_ptr_free )( void* ) = free; -void (*_pico_ptr_load_file )( char*, unsigned char**, int* ) = NULL; +void (*_pico_ptr_load_file )( const char*, unsigned char**, int* ) = NULL; void (*_pico_ptr_free_file )( void* ) = NULL; void (*_pico_ptr_print )( int, const char* ) = NULL; @@ -193,7 +193,7 @@ void _pico_free( void *ptr ) /* _pico_load_file: * wrapper around the loadfile function pointer */ -void _pico_load_file( char *name, unsigned char **buffer, int *bufSize ) +void _pico_load_file( const char *name, unsigned char **buffer, int *bufSize ) { /* sanity checks */ if( name == NULL ) @@ -266,7 +266,7 @@ void _pico_first_token( char *str ) if( !str || !*str ) return; while( *str && !isspace( *str ) ) - *str++; + str++; *str = '\0'; } @@ -555,7 +555,7 @@ float _pico_big_float( float src ) /* _pico_stristr: * case-insensitive strstr. -sea */ -char *_pico_stristr( char *str, const char *substr ) +const char *_pico_stristr( const char *str, const char *substr ) { const size_t sublen = strlen(substr); while (*str) @@ -738,7 +738,7 @@ void _pico_parse_skip_white( picoParser_t *p, int *hasLFs ) /* _pico_new_parser: * allocates a new ascii parser object. */ -picoParser_t *_pico_new_parser( picoByte_t *buffer, int bufSize ) +picoParser_t *_pico_new_parser( const picoByte_t *buffer, int bufSize ) { picoParser_t *p; @@ -761,8 +761,8 @@ picoParser_t *_pico_new_parser( picoByte_t *buffer, int bufSize ) return NULL; } /* setup */ - p->buffer = buffer; - p->cursor = buffer; + p->buffer = (const char *) buffer; + p->cursor = (const char *) buffer; p->bufSize = bufSize; p->max = p->buffer + bufSize; p->curLine = 1; /* sea: new */ @@ -798,7 +798,7 @@ void _pico_free_parser( picoParser_t *p ) int _pico_parse_ex( picoParser_t *p, int allowLFs, int handleQuoted ) { int hasLFs = 0; - char *old; + const char *old; /* sanity checks */ if( p == NULL || p->buffer == NULL || @@ -1218,7 +1218,7 @@ int _pico_parse_vec4_def( picoParser_t *p, picoVec4_t out, picoVec4_t def ) /* _pico_new_memstream: * allocates a new memorystream object. */ -picoMemStream_t *_pico_new_memstream( picoByte_t *buffer, int bufSize ) +picoMemStream_t *_pico_new_memstream( const picoByte_t *buffer, int bufSize ) { picoMemStream_t *s; diff --git a/libs/picomodel/picointernal.h b/libs/picomodel/picointernal.h index 6ede9f6..10769e3 100644 --- a/libs/picomodel/picointernal.h +++ b/libs/picomodel/picointernal.h @@ -78,22 +78,22 @@ extern "C" /* types */ typedef struct picoParser_s { - char *buffer; + const char *buffer; int bufSize; char *token; int tokenSize; int tokenMax; - char *cursor; - char *max; + const char *cursor; + const char *max; int curLine; } picoParser_t; typedef struct picoMemStream_s { - picoByte_t *buffer; + const picoByte_t *buffer; int bufSize; - picoByte_t *curPos; + const picoByte_t *curPos; int flag; } picoMemStream_t; @@ -104,7 +104,7 @@ extern const picoModule_t *picoModules[]; extern void *(*_pico_ptr_malloc)( size_t ); extern void (*_pico_ptr_free)( void* ); -extern void (*_pico_ptr_load_file)( char*, unsigned char**, int* ); +extern void (*_pico_ptr_load_file)( const char*, unsigned char**, int* ); extern void (*_pico_ptr_free_file)( void* ); extern void (*_pico_ptr_print)( int, const char* ); @@ -120,7 +120,7 @@ char *_pico_clone_alloc( const char *str ); void _pico_free( void *ptr ); /* files */ -void _pico_load_file( char *name, unsigned char **buffer, int *bufSize ); +void _pico_load_file( const char *name, unsigned char **buffer, int *bufSize ); void _pico_free_file( void *buffer ); /* strings */ @@ -129,7 +129,7 @@ char *_pico_strltrim( char *str ); char *_pico_strrtrim( char *str ); int _pico_strchcount( char *str, int ch ); void _pico_printf( int level, const char *format, ... ); -char *_pico_stristr( char *str, const char *substr ); +const char *_pico_stristr( const char *str, const char *substr ); void _pico_unixify( char *path ); int _pico_nofname( const char *path, char *dest, int destSize ); const char *_pico_nopath( const char *path ); @@ -168,7 +168,7 @@ short _pico_little_short( short src ); float _pico_little_float( float src ); /* pico ascii parser */ -picoParser_t *_pico_new_parser( picoByte_t *buffer, int bufSize ); +picoParser_t *_pico_new_parser( const picoByte_t *buffer, int bufSize ); void _pico_free_parser( picoParser_t *p ); int _pico_parse_ex( picoParser_t *p, int allowLFs, int handleQuoted ); char *_pico_parse_first( picoParser_t *p ); @@ -189,7 +189,7 @@ int _pico_parse_vec4( picoParser_t *p, picoVec4_t out); int _pico_parse_vec4_def( picoParser_t *p, picoVec4_t out, picoVec4_t def); /* pico memory stream */ -picoMemStream_t *_pico_new_memstream( picoByte_t *buffer, int bufSize ); +picoMemStream_t *_pico_new_memstream( const picoByte_t *buffer, int bufSize ); void _pico_free_memstream( picoMemStream_t *s ); int _pico_memstream_read( picoMemStream_t *s, void *buffer, int len ); int _pico_memstream_getc( picoMemStream_t *s ); diff --git a/libs/picomodel/picomodel.c b/libs/picomodel/picomodel.c index 078dce3..aed467c 100644 --- a/libs/picomodel/picomodel.c +++ b/libs/picomodel/picomodel.c @@ -114,7 +114,7 @@ PicoSetLoadFileFunc() sets the ptr to the file load function */ -void PicoSetLoadFileFunc( void (*func)( char*, unsigned char**, int* ) ) +void PicoSetLoadFileFunc( void (*func)( const char*, unsigned char**, int* ) ) { if( func != NULL ) _pico_ptr_load_file = func; @@ -148,7 +148,7 @@ void PicoSetPrintFunc( void (*func)( int, const char* ) ) -picoModel_t *PicoModuleLoadModel( const picoModule_t* pm, char* fileName, picoByte_t* buffer, int bufSize, int frameNum ) +picoModel_t *PicoModuleLoadModel( const picoModule_t* pm, const char* fileName, picoByte_t* buffer, int bufSize, int frameNum ) { char *modelFileName, *remapFileName; @@ -199,7 +199,7 @@ PicoLoadModel() the meat and potatoes function */ -picoModel_t *PicoLoadModel( char *fileName, int frameNum ) +picoModel_t *PicoLoadModel( const char *fileName, int frameNum ) { const picoModule_t **modules, *pm; picoModel_t *model; @@ -753,7 +753,7 @@ picoSurface_t *PicoFindSurface( PicoSet*() Setter Functions ----------------------------------------------------------------------------*/ -void PicoSetModelName( picoModel_t *model, char *name ) +void PicoSetModelName( picoModel_t *model, const char *name ) { if( model == NULL || name == NULL ) return; @@ -765,7 +765,7 @@ void PicoSetModelName( picoModel_t *model, char *name ) -void PicoSetModelFileName( picoModel_t *model, char *fileName ) +void PicoSetModelFileName( picoModel_t *model, const char *fileName ) { if( model == NULL || fileName == NULL ) return; diff --git a/libs/picomodel/pm_3ds.c b/libs/picomodel/pm_3ds.c index 49a05f1..5ec21bf 100644 --- a/libs/picomodel/pm_3ds.c +++ b/libs/picomodel/pm_3ds.c @@ -166,20 +166,17 @@ T3dsChunk; */ static int _3ds_canload( PM_PARAMS_CANLOAD ) { - T3dsChunk *chunk; - - /* to keep the compiler happy */ - *fileName = *fileName; + const T3dsChunk *chunk; /* sanity check */ - if (bufSize < sizeof(T3dsChunk)) + if (bufSize < (int) sizeof(T3dsChunk)) return PICO_PMV_ERROR_SIZE; /* get pointer to 3ds header chunk */ - chunk = (T3dsChunk *)buffer; + chunk = (const T3dsChunk *)buffer; /* check data length */ - if (bufSize < _pico_little_long(chunk->len)) + if (bufSize < (int) _pico_little_long(chunk->len)) return PICO_PMV_ERROR_SIZE; /* check 3ds magic */ @@ -736,7 +733,8 @@ static picoModel_t *_3ds_load( PM_PARAMS_LOAD ) /* initialize persistant vars (formerly static) */ pers.model = model; - pers.bufptr = (picoByte_t *)buffer; + pers.bufptr = (picoByte_t *)_pico_alloc(bufSize); + memcpy(pers.bufptr, buffer, bufSize); pers.basename = (char *)basename; pers.maxofs = bufSize; pers.cofs = 0L; diff --git a/libs/picomodel/pm_ase.c b/libs/picomodel/pm_ase.c index 985ea8a..31c448e 100644 --- a/libs/picomodel/pm_ase.c +++ b/libs/picomodel/pm_ase.c @@ -221,11 +221,8 @@ static int _ase_canload( PM_PARAMS_CANLOAD ) if( bufSize < 80 ) return PICO_PMV_ERROR_SIZE; - /* keep the friggin compiler happy */ - *fileName = *fileName; - /* create pico parser */ - p = _pico_new_parser( (picoByte_t*) buffer, bufSize ); + p = _pico_new_parser( (const picoByte_t*) buffer, bufSize ); if( p == NULL ) return PICO_PMV_ERROR_MEMORY; @@ -552,7 +549,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ) return NULL; \ } /* create a new pico parser */ - p = _pico_new_parser( (picoByte_t *)buffer,bufSize ); + p = _pico_new_parser( (const picoByte_t *)buffer,bufSize ); if (p == NULL) return NULL; /* create a new pico model */ @@ -868,7 +865,7 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD ) else if( !_pico_stricmp( p->token, "*material" ) ) { aseSubMaterial_t* subMaterial = NULL; - picoShader_t *shader; + picoShader_t *shader = NULL; int level = 1, index; char materialName[ 1024 ]; float transValue = 0.0f, shineValue = 1.0f; diff --git a/libs/picomodel/pm_fm.c b/libs/picomodel/pm_fm.c index 4e64fe6..1065160 100644 --- a/libs/picomodel/pm_fm.c +++ b/libs/picomodel/pm_fm.c @@ -66,10 +66,11 @@ typedef struct index_DUP_LUT_s static int _fm_canload( PM_PARAMS_CANLOAD ) { fm_t fm; - unsigned char *bb; + unsigned char *bb, *bb0; int fm_file_pos; - bb = (unsigned char *) buffer; + bb0 = bb = (picoByte_t*) _pico_alloc(bufSize); + memcpy(bb, buffer, bufSize); // Header fm.fm_header_hdr = (fm_chunk_header_t *) bb; @@ -82,6 +83,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Header Ident incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_IDENT; } @@ -91,6 +93,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Header Version incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_VERSION; } @@ -105,6 +108,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Skin Ident incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_IDENT; } @@ -114,6 +118,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Skin Version incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_VERSION; } @@ -128,6 +133,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM ST Ident incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_IDENT; } @@ -137,6 +143,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM ST Version incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_VERSION; } @@ -151,6 +158,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Tri Ident incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_IDENT; } @@ -160,6 +168,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Tri Version incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_VERSION; } @@ -174,6 +183,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Frame Ident incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_IDENT; } @@ -183,6 +193,7 @@ static int _fm_canload( PM_PARAMS_CANLOAD ) #ifdef FM_DBG _pico_printf( PICO_WARNING, "FM Frame Version incorrect\n"); #endif + _pico_free(bb0); return PICO_PMV_ERROR_VERSION; } @@ -211,7 +222,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) fm_xyz_st_t *triangle; fm_frame_t *frame; - picoByte_t *bb; + picoByte_t *bb, *bb0; picoModel_t *picoModel; picoSurface_t *picoSurface; picoShader_t *picoShader; @@ -220,7 +231,8 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) picoColor_t color; - bb = (picoByte_t*) buffer; + bb0 = bb = (picoByte_t*) _pico_alloc(bufSize); + memcpy(bb, buffer, bufSize); // Header Header fm.fm_header_hdr = (fm_chunk_header_t *) bb; @@ -228,12 +240,14 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) if( (strcmp(fm.fm_header_hdr->ident, FM_HEADERCHUNKNAME)) ) { _pico_printf( PICO_WARNING, "FM Header Ident incorrect\n"); + _pico_free(bb0); return NULL; } if( _pico_little_long( fm.fm_header_hdr->version ) != FM_HEADERCHUNKVER ) { _pico_printf( PICO_WARNING, "FM Header Version incorrect\n"); + _pico_free(bb0); return NULL; } @@ -243,12 +257,14 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) if( (strcmp(fm.fm_skin_hdr->ident, FM_SKINCHUNKNAME)) ) { _pico_printf( PICO_WARNING, "FM Skin Ident incorrect\n"); + _pico_free(bb0); return NULL; } if( _pico_little_long( fm.fm_skin_hdr->version ) != FM_SKINCHUNKVER ) { _pico_printf( PICO_WARNING, "FM Skin Version incorrect\n"); + _pico_free(bb0); return NULL; } @@ -258,12 +274,14 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) if( (strcmp(fm.fm_st_hdr->ident, FM_STCOORDCHUNKNAME)) ) { _pico_printf( PICO_WARNING, "FM ST Ident incorrect\n"); + _pico_free(bb0); return NULL; } if( _pico_little_long( fm.fm_st_hdr->version ) != FM_STCOORDCHUNKVER ) { _pico_printf( PICO_WARNING, "FM ST Version incorrect\n"); + _pico_free(bb0); return NULL; } @@ -273,12 +291,14 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) if( (strcmp(fm.fm_tri_hdr->ident, FM_TRISCHUNKNAME)) ) { _pico_printf( PICO_WARNING, "FM Tri Ident incorrect\n"); + _pico_free(bb0); return NULL; } if( _pico_little_long( fm.fm_tri_hdr->version ) != FM_TRISCHUNKVER ) { _pico_printf( PICO_WARNING, "FM Tri Version incorrect\n"); + _pico_free(bb0); return NULL; } @@ -288,12 +308,14 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) if( (strcmp(fm.fm_frame_hdr->ident, FM_FRAMESCHUNKNAME)) ) { _pico_printf( PICO_WARNING, "FM Frame Ident incorrect\n"); + _pico_free(bb0); return NULL; } if( _pico_little_long( fm.fm_frame_hdr->version ) != FM_FRAMESCHUNKVER ) { _pico_printf( PICO_WARNING, "FM Frame Version incorrect\n"); + _pico_free(bb0); return NULL; } @@ -325,12 +347,14 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) if( fm_head->numFrames < 1 ) { _pico_printf( PICO_ERROR, "%s has 0 frames!", fileName ); + _pico_free(bb0); return NULL; } if( frameNum < 0 || frameNum >= fm_head->numFrames ) { _pico_printf( PICO_ERROR, "Invalid or out-of-range FM frame specified" ); + _pico_free(bb0); return NULL; } @@ -371,7 +395,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) texCoord->t = _pico_little_short( texCoord[i].t ); } // set Skin Name - strncpy(skinname, (unsigned char *) fm.fm_skin, FM_SKINPATHSIZE ); + strncpy(skinname, (const char *) fm.fm_skin, FM_SKINPATHSIZE ); #ifdef FM_VERBOSE_DBG // Print out md2 values @@ -387,6 +411,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) if( picoModel == NULL ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model" ); + _pico_free(bb0); return NULL; } @@ -402,6 +427,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model surface" ); PicoFreeModel( picoModel ); + _pico_free(bb0); return NULL; } @@ -413,6 +439,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model shader" ); PicoFreeModel( picoModel ); + _pico_free(bb0); return NULL; } @@ -644,6 +671,7 @@ static picoModel_t *_fm_load( PM_PARAMS_LOAD ) _pico_free(p_index_LUT_DUPS); /* return the new pico model */ + _pico_free(bb0); return picoModel; } diff --git a/libs/picomodel/pm_lwo.c b/libs/picomodel/pm_lwo.c index e36bb6f..09cdde9 100644 --- a/libs/picomodel/pm_lwo.c +++ b/libs/picomodel/pm_lwo.c @@ -79,7 +79,7 @@ static int _lwo_canload( PM_PARAMS_CANLOAD ) int ret; /* create a new pico memorystream */ - s = _pico_new_memstream( (picoByte_t *)buffer, bufSize ); + s = _pico_new_memstream( (const picoByte_t *)buffer, bufSize ); if (s == NULL) { return PICO_PMV_ERROR_MEMORY; @@ -139,7 +139,7 @@ static picoModel_t *_lwo_load( PM_PARAMS_LOAD ) } /* create a new pico memorystream */ - s = _pico_new_memstream( (picoByte_t *)buffer, bufSize ); + s = _pico_new_memstream( (const picoByte_t *)buffer, bufSize ); if (s == NULL) { return NULL; diff --git a/libs/picomodel/pm_md2.c b/libs/picomodel/pm_md2.c index bf78a99..d53f702 100644 --- a/libs/picomodel/pm_md2.c +++ b/libs/picomodel/pm_md2.c @@ -300,20 +300,17 @@ float md2_normals[ MD2_NUMVERTEXNORMALS ][ 3 ] = static int _md2_canload( PM_PARAMS_CANLOAD ) { - md2_t *md2; - - /* to keep the compiler happy */ - *fileName = *fileName; + const md2_t *md2; /* sanity check */ - if( bufSize < ( sizeof( *md2 ) * 2) ) + if( (size_t) bufSize < ( sizeof( *md2 ) * 2) ) return PICO_PMV_ERROR_SIZE; /* set as md2 */ - md2 = (md2_t*) buffer; + md2 = (const md2_t*) buffer; /* check md2 magic */ - if( *((int*) md2->magic) != *((int*) MD2_MAGIC) ) + if( *((const int*) md2->magic) != *((const int*) MD2_MAGIC) ) return PICO_PMV_ERROR_IDENT; /* check md2 version */ @@ -344,7 +341,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) md2Triangle_t *triangle; md2XyzNormal_t *vertex; - picoByte_t *bb; + picoByte_t *bb, *bb0; picoModel_t *picoModel; picoSurface_t *picoSurface; picoShader_t *picoShader; @@ -354,14 +351,16 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) /* set as md2 */ - bb = (picoByte_t*) buffer; - md2 = (md2_t*) buffer; + bb0 = bb = (picoByte_t*) _pico_alloc(bufSize); + memcpy(bb, buffer, bufSize); + md2 = (md2_t*) bb; /* check ident and version */ - if( *((int*) md2->magic) != *((int*) MD2_MAGIC) || _pico_little_long( md2->version ) != MD2_VERSION ) + if( *((const int*) md2->magic) != *((const int*) MD2_MAGIC) || _pico_little_long( md2->version ) != MD2_VERSION ) { /* not an md2 file (todo: set error) */ _pico_printf( PICO_ERROR, "%s is not an MD2 File!", fileName ); + _pico_free(bb0); return NULL; } @@ -390,12 +389,14 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) if( md2->numFrames < 1 ) { _pico_printf( PICO_ERROR, "%s has 0 frames!", fileName ); + _pico_free(bb0); return NULL; } if( frameNum < 0 || frameNum >= md2->numFrames ) { _pico_printf( PICO_ERROR, "Invalid or out-of-range MD2 frame specified" ); + _pico_free(bb0); return NULL; } @@ -429,7 +430,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) } // set Skin Name - strncpy(skinname, (bb + md2->ofsSkins), MD2_MAX_SKINNAME ); + strncpy(skinname, (const char *) (bb + md2->ofsSkins), MD2_MAX_SKINNAME ); // Print out md2 values _pico_printf(PICO_VERBOSE,"Skins: %d Verts: %d STs: %d Triangles: %d Frames: %d\nSkin Name \"%s\"\n", md2->numSkins, md2->numXYZ, md2->numST, md2->numTris, md2->numFrames, &skinname ); @@ -443,6 +444,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) if( picoModel == NULL ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model" ); + _pico_free(bb0); return NULL; } @@ -458,6 +460,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model surface" ); PicoFreeModel( picoModel ); + _pico_free(bb0); return NULL; } @@ -469,6 +472,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model shader" ); PicoFreeModel( picoModel ); + _pico_free(bb0); return NULL; } @@ -644,6 +648,7 @@ static picoModel_t *_md2_load( PM_PARAMS_LOAD ) _pico_free(p_index_LUT_DUPS); /* return the new pico model */ + _pico_free(bb0); return picoModel; } diff --git a/libs/picomodel/pm_md3.c b/libs/picomodel/pm_md3.c index 55022b2..b22704d 100644 --- a/libs/picomodel/pm_md3.c +++ b/libs/picomodel/pm_md3.c @@ -145,21 +145,18 @@ by one structure only. static int _md3_canload( PM_PARAMS_CANLOAD ) { - md3_t *md3; + const md3_t *md3; - /* to keep the compiler happy */ - *fileName = *fileName; - /* sanity check */ - if( bufSize < ( sizeof( *md3 ) * 2) ) + if( (size_t) bufSize < ( sizeof( *md3 ) * 2) ) return PICO_PMV_ERROR_SIZE; /* set as md3 */ - md3 = (md3_t*) buffer; + md3 = (const md3_t*) buffer; /* check md3 magic */ - if( *((int*) md3->magic) != *((int*) MD3_MAGIC) ) + if( *((const int*) md3->magic) != *((const int*) MD3_MAGIC) ) return PICO_PMV_ERROR_IDENT; /* check md3 version */ @@ -180,7 +177,7 @@ loads a quake3 arena md3 model file. static picoModel_t *_md3_load( PM_PARAMS_LOAD ) { int i, j; - picoByte_t *bb; + picoByte_t *bb, *bb0; md3_t *md3; md3Surface_t *surface; md3Shader_t *shader; @@ -204,13 +201,15 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ) /* set as md3 */ - bb = (picoByte_t*) buffer; - md3 = (md3_t*) buffer; + bb0 = bb = (picoByte_t*) _pico_alloc(bufSize); + memcpy(bb, buffer, bufSize); + md3 = (md3_t*) bb; /* check ident and version */ if( *((int*) md3->magic) != *((int*) MD3_MAGIC) || _pico_little_long( md3->version ) != MD3_VERSION ) { /* not an md3 file (todo: set error) */ + _pico_free(bb0); return NULL; } @@ -229,12 +228,14 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ) if( md3->numFrames < 1 ) { _pico_printf( PICO_ERROR, "MD3 with 0 frames" ); + _pico_free(bb0); return NULL; } if( frameNum < 0 || frameNum >= md3->numFrames ) { _pico_printf( PICO_ERROR, "Invalid or out-of-range MD3 frame specified" ); + _pico_free(bb0); return NULL; } @@ -308,6 +309,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ) if( picoModel == NULL ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model" ); + _pico_free(bb0); return NULL; } @@ -329,6 +331,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model surface" ); PicoFreeModel( picoModel ); /* sea */ + _pico_free(bb0); return NULL; } @@ -344,6 +347,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model shader" ); PicoFreeModel( picoModel ); + _pico_free(bb0); return NULL; } @@ -403,6 +407,7 @@ static picoModel_t *_md3_load( PM_PARAMS_LOAD ) } /* return the new pico model */ + _pico_free(bb0); return picoModel; } diff --git a/libs/picomodel/pm_mdc.c b/libs/picomodel/pm_mdc.c index 27e612e..d1243b2 100644 --- a/libs/picomodel/pm_mdc.c +++ b/libs/picomodel/pm_mdc.c @@ -417,21 +417,18 @@ by one structure only. static int _mdc_canload( PM_PARAMS_CANLOAD ) { - mdc_t *mdc; + const mdc_t *mdc; - - /* to keep the compiler happy */ - *fileName = *fileName; /* sanity check */ - if( bufSize < ( sizeof( *mdc ) * 2) ) + if( (size_t) bufSize < ( sizeof( *mdc ) * 2) ) return PICO_PMV_ERROR_SIZE; /* set as mdc */ - mdc = (mdc_t*) buffer; + mdc = (const mdc_t*) buffer; /* check mdc magic */ - if( *((int*) mdc->magic) != *((int*) MDC_MAGIC) ) + if( *((const int*) mdc->magic) != *((const int*) MDC_MAGIC) ) return PICO_PMV_ERROR_IDENT; /* check mdc version */ @@ -452,7 +449,7 @@ loads a Return to Castle Wolfenstein mdc model file. static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) { int i, j; - picoByte_t *bb; + picoByte_t *bb, *bb0; mdc_t *mdc; mdcSurface_t *surface; mdcShader_t *shader; @@ -460,8 +457,8 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) mdcFrame_t *frame; mdcTriangle_t *triangle; mdcVertex_t *vertex; - mdcXyzCompressed_t *vertexComp; - short *mdcShort, *mdcCompVert; + mdcXyzCompressed_t *vertexComp = NULL; + short *mdcShort, *mdcCompVert = NULL; double lat, lng; picoModel_t *picoModel; @@ -478,13 +475,15 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) /* set as mdc */ - bb = (picoByte_t*) buffer; - mdc = (mdc_t*) buffer; + bb0 = bb = (picoByte_t*) _pico_alloc(bufSize); + memcpy(bb, buffer, bufSize); + mdc = (mdc_t*) bb; /* check ident and version */ if( *((int*) mdc->magic) != *((int*) MDC_MAGIC) || _pico_little_long( mdc->version ) != MDC_VERSION ) { /* not an mdc file (todo: set error) */ + _pico_free(bb0); return NULL; } @@ -504,12 +503,14 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) if( mdc->numFrames < 1 ) { _pico_printf( PICO_ERROR, "MDC with 0 frames" ); + _pico_free(bb0); return NULL; } if( frameNum < 0 || frameNum >= mdc->numFrames ) { _pico_printf( PICO_ERROR, "Invalid or out-of-range MDC frame specified" ); + _pico_free(bb0); return NULL; } @@ -608,6 +609,7 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) if( picoModel == NULL ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model" ); + _pico_free(bb0); return NULL; } @@ -629,6 +631,7 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model surface" ); PicoFreeModel( picoModel ); /* sea */ + _pico_free(bb0); return NULL; } @@ -644,6 +647,7 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR, "Unable to allocate a new model shader" ); PicoFreeModel( picoModel ); + _pico_free(bb0); return NULL; } @@ -728,6 +732,7 @@ static picoModel_t *_mdc_load( PM_PARAMS_LOAD ) } /* return the new pico model */ + _pico_free(bb0); return picoModel; } diff --git a/libs/picomodel/pm_ms3d.c b/libs/picomodel/pm_ms3d.c index cf411ee..8626bee 100644 --- a/libs/picomodel/pm_ms3d.c +++ b/libs/picomodel/pm_ms3d.c @@ -165,18 +165,15 @@ TMsKeyframe; */ static int _ms3d_canload( PM_PARAMS_CANLOAD ) { - TMsHeader *hdr; + const TMsHeader *hdr; - /* to keep the compiler happy */ - *fileName = *fileName; - /* sanity check */ - if (bufSize < sizeof(TMsHeader)) + if ((size_t) bufSize < sizeof(TMsHeader)) return PICO_PMV_ERROR_SIZE; /* get ms3d header */ - hdr = (TMsHeader *)buffer; + hdr = (const TMsHeader *)buffer; /* check ms3d magic */ if (strncmp(hdr->magic,"MS3D000000",10) != 0) @@ -206,7 +203,7 @@ static unsigned char *GetWord( unsigned char *bufptr, int *out ) static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ) { picoModel_t *model; - unsigned char *bufptr; + unsigned char *bufptr, *bufptr0; int shaderRefs[ MS3D_MAX_GROUPS ]; int numGroups; int numMaterials; @@ -226,8 +223,10 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ) PicoSetModelName( model, fileName ); PicoSetModelFileName( model, fileName ); + bufptr0 = bufptr = (picoByte_t*) _pico_alloc(bufSize); + memcpy(bufptr, buffer, bufSize); /* skip header */ - bufptr = (unsigned char *)buffer + sizeof(TMsHeader); + bufptr += sizeof(TMsHeader); /* get number of vertices */ bufptr = GetWord( bufptr,&numVerts ); @@ -288,6 +287,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ) { _pico_printf( PICO_ERROR,"Vertex %d index %d out of range (%d, max %d)",i,k,triangle->vertexIndices[k],numVerts-1); PicoFreeModel( model ); + _pico_free(bufptr0); return NULL; /* yuck */ } } @@ -322,6 +322,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ) if (surface == NULL) { PicoFreeModel( model ); + _pico_free(bufptr0); return NULL; } /* do surface setup */ @@ -415,6 +416,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ) if (shader == NULL) { PicoFreeModel( model ); + _pico_free(bufptr0); return NULL; } /* scale shader colors */ @@ -473,6 +475,7 @@ static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ) #endif } /* return allocated pico model */ + _pico_free(bufptr0); return model; // return NULL; } diff --git a/libs/picomodel/pm_obj.c b/libs/picomodel/pm_obj.c index d5b1500..7f269fa 100644 --- a/libs/picomodel/pm_obj.c +++ b/libs/picomodel/pm_obj.c @@ -87,7 +87,7 @@ static int _obj_canload( PM_PARAMS_CANLOAD ) /* appearing at the beginning of wavefront objects */ /* alllocate a new pico parser */ - p = _pico_new_parser( (picoByte_t *)buffer,bufSize ); + p = _pico_new_parser( (const picoByte_t *)buffer,bufSize ); if (p == NULL) return PICO_PMV_ERROR_MEMORY; @@ -535,7 +535,7 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ) return NULL; \ } /* alllocate a new pico parser */ - p = _pico_new_parser( (picoByte_t *)buffer,bufSize ); + p = _pico_new_parser( (const picoByte_t *)buffer,bufSize ); if (p == NULL) return NULL; /* create a new pico model */ @@ -688,8 +688,8 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ) int ivt[ 4 ], has_vt = 0; int ivn[ 4 ], has_vn = 0; int have_quad = 0; - int slashcount; - int doubleslash; + int slashcount = 0; + int doubleslash = 0; int i; if(curSurface == NULL) diff --git a/libs/picomodel/pm_terrain.c b/libs/picomodel/pm_terrain.c index a54a834..b316711 100644 --- a/libs/picomodel/pm_terrain.c +++ b/libs/picomodel/pm_terrain.c @@ -302,11 +302,8 @@ static int _terrain_canload( PM_PARAMS_CANLOAD ) picoParser_t *p; - /* keep the friggin compiler happy */ - *fileName = *fileName; - /* create pico parser */ - p = _pico_new_parser( (picoByte_t*) buffer, bufSize ); + p = _pico_new_parser( (const picoByte_t*) buffer, bufSize ); if( p == NULL ) return PICO_PMV_ERROR_MEMORY; @@ -355,11 +352,8 @@ static picoModel_t *_terrain_load( PM_PARAMS_LOAD ) picoColor_t color; - /* keep the friggin compiler happy */ - *fileName = *fileName; - /* create pico parser */ - p = _pico_new_parser( (picoByte_t*) buffer, bufSize ); + p = _pico_new_parser( (const picoByte_t*) buffer, bufSize ); if( p == NULL ) return NULL; diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index 4eb9592..4e84b20 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -193,7 +193,7 @@ void SetQdirFromPath( const char *path ) } strncpy (qdir, path, c+len+count-path); Sys_Printf ("qdir: %s\n", qdir); - for ( i = 0; i < strlen( qdir ); i++ ) + for ( i = 0; i < (int) strlen( qdir ); i++ ) { if ( qdir[i] == '\\' ) qdir[i] = '/'; @@ -206,7 +206,7 @@ void SetQdirFromPath( const char *path ) { strncpy (gamedir, path, c+1-path); - for ( i = 0; i < strlen( gamedir ); i++ ) + for ( i = 0; i < (int) strlen( gamedir ); i++ ) { if ( gamedir[i] == '\\' ) gamedir[i] = '/'; @@ -250,7 +250,7 @@ char *ExpandArg (const char *path) char *ExpandPath (const char *path) { static char full[1024]; - if (!qdir) + if (!*qdir) Error ("ExpandPath called without qdir set"); if (path[0] == '/' || path[0] == '\\' || path[1] == ':') { strcpy( full, path ); @@ -263,7 +263,7 @@ char *ExpandPath (const char *path) char *ExpandGamePath (const char *path) { static char full[1024]; - if (!qdir) + if (!*qdir) Error ("ExpandGamePath called without qdir set"); if (path[0] == '/' || path[0] == '\\' || path[1] == ':') { strcpy( full, path ); diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index 5fc38cf..37890b4 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -99,7 +99,11 @@ void ExpandWildcards( int *argc, char ***argv ); double I_FloatTime( void ); -void Error( const char *error, ... ); +void Error( const char *error, ... ) +#ifdef __GNUC__ +__attribute__((noreturn)) +#endif +; int CheckParm( const char *check ); FILE *SafeOpenWrite( const char *filename ); diff --git a/tools/quake3/common/imagelib.c b/tools/quake3/common/imagelib.c index 9e52f1e..31e3185 100644 --- a/tools/quake3/common/imagelib.c +++ b/tools/quake3/common/imagelib.c @@ -527,6 +527,7 @@ void LoadPCX( const char *filename, byte **pic, byte **palette, int *width, int for( y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1 ) { /* do a scanline */ + runLength = 0; for( x=0; x <= pcx->xmax; ) { /* RR2DO2 */ @@ -1133,7 +1134,7 @@ void LoadTGA (const char *name, byte **pixels, int *width, int *height) // // load the file // - nLen = vfsLoadFile ( ( char * ) name, (void **)&buffer, 0); + nLen = vfsLoadFile ( name, (void **)&buffer, 0); if (nLen == -1) { Error ("Couldn't read %s", name); @@ -1183,8 +1184,6 @@ void WriteTGA (const char *filename, byte *data, int width, int height) { void WriteTGAGray (const char *filename, byte *data, int width, int height) { byte buffer[18]; - int i; - int c; FILE *f; memset (buffer, 0, 18); diff --git a/tools/quake3/common/inout.c b/tools/quake3/common/inout.c index c56a9f5..9f7005a 100644 --- a/tools/quake3/common/inout.c +++ b/tools/quake3/common/inout.c @@ -71,8 +71,8 @@ xmlNodePtr xml_NodeForVec( vec3_t v ) char buf[1024]; sprintf (buf, "%f %f %f", v[0], v[1], v[2]); - ret = xmlNewNode (NULL, "point"); - xmlNodeSetContent (ret, buf); + ret = xmlNewNode (NULL, (xmlChar*)"point"); + xmlNodeSetContent (ret, (xmlChar*)buf); return ret; } @@ -96,7 +96,7 @@ void xml_SendNode (xmlNodePtr node) // l_net library defines an upper limit of MAX_NETMESSAGE // there are some size check errors, so we use MAX_NETMESSAGE-10 to be safe // if the size of the buffer exceeds MAX_NETMESSAGE-10 we'll send in several network messages - while (pos < xml_buf->use) + while (pos < (int)xml_buf->use) { // what size are we gonna send now? (xml_buf->use - pos < MAX_NETMESSAGE - 10) ? (size = xml_buf->use - pos) : (size = MAX_NETMESSAGE - 10); @@ -152,15 +152,15 @@ void xml_Select (char *msg, int entitynum, int brushnum, qboolean bError) // now build a proper "select" XML node sprintf (buf, "Entity %i, Brush %i: %s", entitynum, brushnum, msg); - node = xmlNewNode (NULL, "select"); - xmlNodeSetContent (node, buf); + node = xmlNewNode (NULL, (xmlChar*)"select"); + xmlNodeSetContent (node, (xmlChar*)buf); level[0] = (int)'0' + (bError ? SYS_ERR : SYS_WRN) ; level[1] = 0; - xmlSetProp (node, "level", (char *)&level); + xmlSetProp (node, (xmlChar*)"level", (xmlChar *)&level); // a 'select' information sprintf (buf, "%i %i", entitynum, brushnum); - select = xmlNewNode (NULL, "brush"); - xmlNodeSetContent (select, buf); + select = xmlNewNode (NULL, (xmlChar*)"brush"); + xmlNodeSetContent (select, (xmlChar*)buf); xmlAddChild (node, select); xml_SendNode (node); @@ -178,15 +178,15 @@ void xml_Point (char *msg, vec3_t pt) char buf[1024]; char level[2]; - node = xmlNewNode (NULL, "pointmsg"); - xmlNodeSetContent (node, msg); + node = xmlNewNode (NULL, (xmlChar*)"pointmsg"); + xmlNodeSetContent (node, (xmlChar*)msg); level[0] = (int)'0' + SYS_ERR; level[1] = 0; - xmlSetProp (node, "level", (char *)&level); + xmlSetProp (node, (xmlChar*)"level", (xmlChar *)&level); // a 'point' node sprintf (buf, "%g %g %g", pt[0], pt[1], pt[2]); - point = xmlNewNode (NULL, "point"); - xmlNodeSetContent (point, buf); + point = xmlNewNode (NULL, (xmlChar*)"point"); + xmlNodeSetContent (point, (xmlChar*)buf); xmlAddChild (node, point); xml_SendNode (node); @@ -203,11 +203,11 @@ void xml_Winding (char *msg, vec3_t p[], int numpoints, qboolean die) char level[2]; int i; - node = xmlNewNode (NULL, "windingmsg"); - xmlNodeSetContent (node, msg); + node = xmlNewNode (NULL, (xmlChar*)"windingmsg"); + xmlNodeSetContent (node, (xmlChar*)msg); level[0] = (int)'0' + SYS_ERR; level[1] = 0; - xmlSetProp (node, "level", (char *)&level); + xmlSetProp (node, (xmlChar*)"level", (xmlChar *)&level); // a 'winding' node sprintf( buf, "%i ", numpoints); for(i = 0; i < numpoints; i++) @@ -219,8 +219,8 @@ void xml_Winding (char *msg, vec3_t p[], int numpoints, qboolean die) strcat( buf, smlbuf); } - winding = xmlNewNode (NULL, "winding"); - xmlNodeSetContent (winding, buf); + winding = xmlNewNode (NULL, (xmlChar*)"winding"); + xmlNodeSetContent (winding, (xmlChar*)buf); xmlAddChild (node, winding); xml_SendNode (node); @@ -242,7 +242,7 @@ void Broadcast_Setup( const char *dest ) char sMsg[1024]; Net_Setup(); - Net_StringToAddress((char *)dest, &address); + Net_StringToAddress(dest, &address); brdcst_socket = Net_Connect(&address, 0); if (brdcst_socket) { @@ -288,19 +288,19 @@ void FPrintf (int flag, char *buf) if (!bGotXML) { // initialize - doc = xmlNewDoc("1.0"); - doc->children = xmlNewDocRawNode(doc, NULL, "q3map_feedback", NULL); + doc = xmlNewDoc((xmlChar*)"1.0"); + doc->children = xmlNewDocRawNode(doc, NULL, (xmlChar*)"q3map_feedback", NULL); bGotXML = qtrue; } - node = xmlNewNode (NULL, "message"); + node = xmlNewNode (NULL, (xmlChar*)"message"); { gchar* utf8 = g_locale_to_utf8(buf, -1, NULL, NULL, NULL); - xmlNodeSetContent(node, utf8); + xmlNodeSetContent(node, (xmlChar*)utf8); g_free(utf8); } level[0] = (int)'0' + flag; level[1] = 0; - xmlSetProp (node, "level", (char *)&level ); + xmlSetProp (node, (xmlChar*)"level", (xmlChar *)&level ); xml_SendNode (node); } diff --git a/tools/quake3/common/unzip.c b/tools/quake3/common/unzip.c index 63878e6..41b09cb 100644 --- a/tools/quake3/common/unzip.c +++ b/tools/quake3/common/unzip.c @@ -1635,10 +1635,12 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file, /* we check the magic */ if (err==UNZ_OK) + { if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) err=UNZ_ERRNO; else if (uMagic!=0x02014b50) err=UNZ_BADZIPFILE; + } if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) err=UNZ_ERRNO; @@ -1715,10 +1717,12 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file, uSizeRead = extraFieldBufferSize; if (lSeek!=0) + { if (fseek(s->file,lSeek,SEEK_CUR)==0) lSeek=0; else err=UNZ_ERRNO; + } if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) err=UNZ_ERRNO; @@ -1740,10 +1744,12 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file, uSizeRead = commentBufferSize; if (lSeek!=0) + { if (fseek(s->file,lSeek,SEEK_CUR)==0) lSeek=0; else err=UNZ_ERRNO; + } if ((file_info.size_file_comment>0) && (commentBufferSize>0)) if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) err=UNZ_ERRNO; @@ -1906,10 +1912,12 @@ static int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar, if (err==UNZ_OK) + { if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) err=UNZ_ERRNO; else if (uMagic!=0x04034b50) err=UNZ_BADZIPFILE; + } if (unzlocal_getShort(s->file,&uData) != UNZ_OK) err=UNZ_ERRNO; @@ -3407,7 +3415,7 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf /* compute minimum size table less than or equal to l bits */ z = g - w; - z = z > (uInt)l ? l : z; /* table size upper limit */ + z = z > (uInt)l ? (uInt)l : z; /* table size upper limit */ if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ { /* too few codes for k-w bit table */ f -= a + 1; /* deduct codes from patterns left */ @@ -3445,7 +3453,10 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf /* set up table entry in r */ r.bits = (Byte)(k - w); if (p >= v + n) + { r.exop = 128 + 64; /* out of values--invalid code */ + r.base = 0; + } else if (*p < s) { r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */ diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index 37ff876..214f62f 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -340,12 +340,12 @@ void ProcessWorldModel( void ) Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" ); Sys_FPrintf( SYS_NOXML, "**********************\n" ); polyline = LeakFile( tree ); - leaknode = xmlNewNode( NULL, "message" ); - xmlNodeSetContent( leaknode, "MAP LEAKED\n" ); + leaknode = xmlNewNode( NULL, (xmlChar*)"message" ); + xmlNodeSetContent( leaknode, (xmlChar*)"MAP LEAKED\n" ); xmlAddChild( leaknode, polyline ); level[0] = (int) '0' + SYS_ERR; level[1] = 0; - xmlSetProp( leaknode, "level", (char*) &level ); + xmlSetProp( leaknode, (xmlChar*)"level", (xmlChar*) &level ); xml_SendNode( leaknode ); if( leaktest ) { @@ -458,7 +458,7 @@ void ProcessWorldModel( void ) VectorSet( normal, 0, 0, -1 ); /* create the flare surface (note shader defaults automatically) */ - DrawSurfaceForFlare( mapEntityNum, origin, normal, color, (char*) flareShader, lightStyle ); + DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle ); } } } diff --git a/tools/quake3/q3map2/game__null.h b/tools/quake3/q3map2/game__null.h new file mode 100644 index 0000000..c2f2484 --- /dev/null +++ b/tools/quake3/q3map2/game__null.h @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------------- + +Copyright (C) 1999-2007 id Software, Inc. and contributors. +For a list of contributors, see the accompanying CONTRIBUTORS file. + +This file is part of GtkRadiant. + +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. + +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. + +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 + +---------------------------------------------------------------------------------- + +This code has been altered significantly from its original form, to support +several games based on the Quake III Arena engine, in the form of "Q3Map2." + +------------------------------------------------------------------------------- */ + + + +/* marker */ +#ifndef GAME__NULL_H +#define GAME__NULL_H + + + +/* ------------------------------------------------------------------------------- + +content and surface flags +are in game_quake3.h + +------------------------------------------------------------------------------- */ + + + +/* ------------------------------------------------------------------------------- + +game_t struct + +------------------------------------------------------------------------------- */ + +{ + NULL, /* -game x */ + NULL, /* default base game data dir */ + NULL, /* unix home sub-dir */ + NULL, /* magic path word */ + NULL, /* shader directory */ + 0, /* max lightmapped surface verts */ + 0, /* max surface verts */ + 0, /* max surface indexes */ + qfalse, /* flares */ + NULL, /* default flare shader */ + qfalse, /* wolf lighting model? */ + 0, /* lightmap width/height */ + 0, /* lightmap gamma */ + 0, /* lightmap exposure */ + 0, /* lightmap compensate */ + 0, /* lightgrid scale */ + 0, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ + qfalse, /* disable shader lightstyles hack */ + qfalse, /* keep light entities on bsp */ + 0, /* default patchMeta subdivisions tolerance */ + qfalse, /* patch casting enabled */ + qfalse, /* compile deluxemaps */ + 0, /* deluxemaps default mode */ + 0, /* minimap size */ + 0, /* minimap sharpener */ + 0, /* minimap border */ + qfalse, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ + NULL, /* minimap name format */ + NULL, /* bsp file prefix */ + 0, /* bsp file version */ + qfalse, /* cod-style lump len/ofs order */ + NULL, /* bsp load function */ + NULL, /* bsp write function */ + + { + { NULL, 0, 0, 0, 0, 0, 0 } + } +} + + + +/* end marker */ +#endif + diff --git a/tools/quake3/q3map2/image.c b/tools/quake3/q3map2/image.c index 0ddcaf8..0289e77 100644 --- a/tools/quake3/q3map2/image.c +++ b/tools/quake3/q3map2/image.c @@ -99,7 +99,7 @@ note: this function is a total hack, as it reads/writes the png struct directly! typedef struct pngBuffer_s { byte *buffer; - int size, offset; + png_size_t size, offset; } pngBuffer_t; @@ -127,8 +127,8 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in png_struct *png; png_info *info, *end; pngBuffer_t pb; - int i, bitDepth, colorType, channels; - png_uint_32 w, h; + int bitDepth, colorType, channels; + png_uint_32 w, h, i; byte **rowPointers; diff --git a/tools/quake3/q3map2/leakfile.c b/tools/quake3/q3map2/leakfile.c index 51fda30..fc5a319 100644 --- a/tools/quake3/q3map2/leakfile.c +++ b/tools/quake3/q3map2/leakfile.c @@ -81,15 +81,15 @@ xmlNodePtr LeakFile (tree_t *tree) if (!linefile) Error ("Couldn't open %s\n", filename); - xml_node = xmlNewNode (NULL, "polyline"); + xml_node = xmlNewNode (NULL, (xmlChar*)"polyline"); count = 0; node = &tree->outside_node; while (node->occupied > 1) { int next; - portal_t *p, *nextportal; - node_t *nextnode; + portal_t *p, *nextportal = NULL; + node_t *nextnode = NULL; int s; // find the best portal exit diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 41bc1dc..3af7ddb 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1116,6 +1116,8 @@ int LightContributionToSample( trace_t *trace ) /* return to sender */ return 1; } + else + Error("Light of undefined type!"); /* VorteX: set noShadow color */ VectorScale(light->color, add, trace->colorNoShadow); @@ -1830,7 +1832,7 @@ void LightWorld( void ) vec3_t color; float f; int b, bt; - qboolean minVertex, minGrid, ps; + qboolean minVertex, minGrid; const char *value; diff --git a/tools/quake3/q3map2/light_bounce.c b/tools/quake3/q3map2/light_bounce.c index 6d7c54f..7db0061 100644 --- a/tools/quake3/q3map2/light_bounce.c +++ b/tools/quake3/q3map2/light_bounce.c @@ -414,7 +414,7 @@ subdivides a radiosity winding until it is smaller than subdivide, then generate static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, qboolean original, radWinding_t *rw, clipWork_t *cw ) { - int i, style; + int i, style = 0; float dist, area, value; vec3_t mins, maxs, normal, d1, d2, cross, color, gradient; light_t *light, *splash; @@ -539,7 +539,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw light->falloffTolerance = falloffTolerance; /* bouncing light? */ - if( bouncing == qfalse ) + if( !bouncing ) { /* handle first-pass lights in normal q3a style */ value = si->value; diff --git a/tools/quake3/q3map2/light_trace.c b/tools/quake3/q3map2/light_trace.c index d52f816..8e79244 100644 --- a/tools/quake3/q3map2/light_trace.c +++ b/tools/quake3/q3map2/light_trace.c @@ -521,13 +521,10 @@ void ClipTraceWinding( traceWinding_t *tw, vec4_t plane, traceWinding_t *front, mid.xyz[ k ] = -plane[ 3 ]; else mid.xyz[ k ] = a->xyz[ k ] + frac * (b->xyz[ k ] - a->xyz[ k ]); - - /* set texture coordinates */ - if( k > 1 ) - continue; - mid.st[ 0 ] = a->st[ 0 ] + frac * (b->st[ 0 ] - a->st[ 0 ]); - mid.st[ 1 ] = a->st[ 1 ] + frac * (b->st[ 1 ] - a->st[ 1 ]); } + /* set texture coordinates */ + mid.st[ 0 ] = a->st[ 0 ] + frac * (b->st[ 0 ] - a->st[ 0 ]); + mid.st[ 1 ] = a->st[ 1 ] + frac * (b->st[ 1 ] - a->st[ 1 ]); /* copy midpoint to front and back polygons */ front->v[ front->numVerts++ ] = mid; @@ -538,39 +535,6 @@ void ClipTraceWinding( traceWinding_t *tw, vec4_t plane, traceWinding_t *front, -/* -FilterPointToTraceNodes_r() - ydnar -debugging tool -*/ - -static int FilterPointToTraceNodes_r( vec3_t pt, int nodeNum ) -{ - float dot; - traceNode_t *node; - - - if( nodeNum < 0 || nodeNum >= numTraceNodes ) - return -1; - - node = &traceNodes[ nodeNum ]; - - if( node->type >= 0 ) - { - dot = DotProduct( pt, node->plane ) - node->plane[ 3 ]; - if( dot > -0.001f ) - FilterPointToTraceNodes_r( pt, node->children[ 0 ] ); - if( dot < 0.001f ) - FilterPointToTraceNodes_r( pt, node->children[ 1 ] ); - return -1; - } - - Sys_Printf( "%d ", nodeNum ); - - return nodeNum; -} - - - /* FilterTraceWindingIntoNodes_r() - ydnar filters a trace winding into the raytracing tree @@ -1257,7 +1221,7 @@ static void PopulateTraceNodes( void ) /* external model */ default: frame = IntForKey( e, "_frame" ); - model = LoadModel( (char*) value, frame ); + model = LoadModel( value, frame ); if( model == NULL ) continue; PopulateWithPicoModel( castShadows, model, transform ); @@ -1285,7 +1249,7 @@ static void PopulateTraceNodes( void ) /* external model */ default: frame = IntForKey( e, "_frame2" ); - model = LoadModel( (char*) value, frame ); + model = LoadModel( value, frame ); if( model == NULL ) continue; PopulateWithPicoModel( castShadows, model, transform ); diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index d1a5ca7..e176223 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -1154,13 +1154,16 @@ void MapRawLightmap( int rawLightmapNum ) if( MapQuad( lm, info, dv ) ) continue; - /* get drawverts and map first triangle */ - MapTriangle( lm, info, dv, mapNonAxial ); - - /* get drawverts and map second triangle */ - dv[ 1 ] = &verts[ pw[ r + 2 ] ]; - dv[ 2 ] = &verts[ pw[ r + 3 ] ]; - MapTriangle( lm, info, dv, mapNonAxial ); + for( mapNonAxial = 0; mapNonAxial < 2; mapNonAxial++ ) + { + /* get drawverts and map first triangle */ + MapTriangle( lm, info, dv, mapNonAxial ); + + /* get drawverts and map second triangle */ + dv[ 1 ] = &verts[ pw[ r + 2 ] ]; + dv[ 2 ] = &verts[ pw[ r + 3 ] ]; + MapTriangle( lm, info, dv, mapNonAxial ); + } } } @@ -1714,7 +1717,9 @@ static qboolean SubmapRawLuxel( rawLightmap_t *lm, int x, int y, float bx, float //% normal2 = SUPER_NORMAL( x, y ); } else - Sys_Printf( "WARNING: Spurious lightmap S vector\n" ); + { + Error( "Spurious lightmap S vector\n" ); + } VectorSubtract( origin2, origin, originVecs[ 0 ] ); //% VectorSubtract( normal2, normal, normalVecs[ 0 ] ); @@ -1974,8 +1979,9 @@ illuminates the luxels void IlluminateRawLightmap( int rawLightmapNum ) { - int i, t, x, y, sx, sy, size, llSize, ldSize, luxelFilterRadius, lightmapNum; + int i, t, x, y, sx, sy, size, luxelFilterRadius, lightmapNum; int *cluster, *cluster2, mapped, lighted, totalLighted; + size_t llSize, ldSize; rawLightmap_t *lm; surfaceInfo_t *info; qboolean filterColor, filterDir; @@ -2870,16 +2876,16 @@ void IlluminateVertexes( int num ) radVertLuxel[ 2 ] <= ambientColor[ 2 ] ) { /* nudge the sample point around a bit */ - for( x = 0; x < 4; x++ ) + for( x = 0; x < 5; x++ ) { /* two's complement 0, 1, -1, 2, -2, etc */ x1 = ((x >> 1) ^ (x & 1 ? -1 : 0)) + (x & 1); - for( y = 0; y < 4; y++ ) + for( y = 0; y < 5; y++ ) { y1 = ((y >> 1) ^ (y & 1 ? -1 : 0)) + (y & 1); - for( z = 0; z < 4; z++ ) + for( z = 0; z < 5; z++ ) { z1 = ((z >> 1) ^ (z & 1 ? -1 : 0)) + (z & 1); @@ -2892,6 +2898,21 @@ void IlluminateVertexes( int num ) trace.cluster = ClusterForPointExtFilter( origin, VERTEX_EPSILON, info->numSurfaceClusters, &surfaceClusters[ info->firstSurfaceCluster ] ); if( trace.cluster < 0 ) continue; + + /* r7 dirt */ + if( dirty && !bouncing ) + dirt = DirtForSample( &trace ); + else + dirt = 1.0f; + + /* jal: floodlight */ + floodLightAmount = 0.0f; + VectorClear( floodColor ); + if( floodlighty && !bouncing ) + { + floodLightAmount = floodlightIntensity * FloodLightForSample( &trace, floodlightDistance, floodlight_lowquality ); + VectorScale( floodlightRGB, floodLightAmount, floodColor ); + } /* trace */ LightingAtSample( &trace, ds->vertexStyles, colors ); @@ -3503,7 +3524,7 @@ void SetupEnvelopes( qboolean forGrid, qboolean fastFlag ) int i, x, y, z, x1, y1, z1; light_t *light, *light2, **owner; bspLeaf_t *leaf; - vec3_t origin, dir, mins, maxs, nullVector = { 0, 0, 0 }; + vec3_t origin, dir, mins, maxs; float radius, intensity; light_t *buckets[ 256 ]; @@ -3616,6 +3637,7 @@ void SetupEnvelopes( qboolean forGrid, qboolean fastFlag ) /* check for fast mode */ if( !(light->flags & LIGHT_FAST) && !(light->flags & LIGHT_FAST_TEMP) ) light->envelope = MAX_WORLD_COORD * 8.0f; + intensity = light->photons; /* hopefully not used */ } else { diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index d30906f..d315a78 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -291,8 +291,8 @@ static int CompareLightSurface( const void *a, const void *b ) /* get shaders */ - asi = surfaceInfos[ *((int*) a) ].si; - bsi = surfaceInfos[ *((int*) b) ].si; + asi = surfaceInfos[ *((const int*) a) ].si; + bsi = surfaceInfos[ *((const int*) b) ].si; /* dummy check */ if( asi == NULL ) @@ -861,8 +861,8 @@ static int CompareSurfaceInfo( const void *a, const void *b ) /* get surface info */ - aInfo = &surfaceInfos[ *((int*) a) ]; - bInfo = &surfaceInfos[ *((int*) b) ]; + aInfo = &surfaceInfos[ *((const int*) a) ]; + bInfo = &surfaceInfos[ *((const int*) b) ]; /* model first */ if( aInfo->modelindex < bInfo->modelindex ) @@ -2220,8 +2220,8 @@ static int CompareRawLightmap( const void *a, const void *b ) /* get lightmaps */ - alm = &rawLightmaps[ *((int*) a) ]; - blm = &rawLightmaps[ *((int*) b) ]; + alm = &rawLightmaps[ *((const int*) a) ]; + blm = &rawLightmaps[ *((const int*) b) ]; /* get min number of surfaces */ min = (alm->numLightSurfaces < blm->numLightSurfaces ? alm->numLightSurfaces : blm->numLightSurfaces); @@ -2281,8 +2281,8 @@ void StoreSurfaceLightmaps( void ) char dirname[ 1024 ], filename[ 1024 ]; shaderInfo_t *csi; char lightmapName[ 128 ]; - char *rgbGenValues[ 256 ]; - char *alphaGenValues[ 256 ]; + const char *rgbGenValues[ 256 ]; + const char *alphaGenValues[ 256 ]; /* note it */ @@ -3170,7 +3170,7 @@ void StoreSurfaceLightmaps( void ) if( rgbGenValues[ style ] == NULL ) { sprintf( key, "_style%drgbgen", style ); - rgbGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key ); + rgbGenValues[ style ] = ValueForKey( &entities[ 0 ], key ); if( rgbGenValues[ style ][ 0 ] == '\0' ) rgbGenValues[ style ] = "wave noise 0.5 1 0 5.37"; } @@ -3184,7 +3184,7 @@ void StoreSurfaceLightmaps( void ) if( alphaGenValues[ style ] == NULL ) { sprintf( key, "_style%dalphagen", style ); - alphaGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key ); + alphaGenValues[ style ] = ValueForKey( &entities[ 0 ], key ); } if( alphaGenValues[ style ][ 0 ] != '\0' ) sprintf( alphaGen, "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style ); diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 54f5444..3bc4e6f 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -837,7 +837,7 @@ static void ParseRawBrush( qboolean onlyLights ) int planenum; shaderInfo_t *si; vec_t shift[ 2 ]; - vec_t rotate; + vec_t rotate = 0; vec_t scale[ 2 ]; char name[ MAX_QPATH ]; char shader[ MAX_QPATH ]; @@ -1693,7 +1693,7 @@ void LoadMapFile( char *filename, qboolean onlyLights ) { FILE *file; brush_t *b; - int oldNumEntities, numMapBrushes; + int oldNumEntities = 0, numMapBrushes; /* note it */ diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index a394535..05213cf 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -78,9 +78,9 @@ PicoLoadFileFunc() callback for picomodel.lib */ -void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize ) +void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize ) { - *bufSize = vfsLoadFile( (const char*) name, (void**) buffer, 0 ); + *bufSize = vfsLoadFile( name, (void**) buffer, 0 ); } @@ -158,7 +158,7 @@ picoModel_t *LoadModel( const char *name, int frame ) Error( "MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS ); /* attempt to parse model */ - *pm = PicoLoadModel( (char*) name, frame ); + *pm = PicoLoadModel( name, frame ); /* if loading failed, make a bogus model to silence the rest of the warnings */ if( *pm == NULL ) @@ -169,7 +169,7 @@ picoModel_t *LoadModel( const char *name, int frame ) return NULL; /* set data */ - PicoSetModelName( *pm, (char*) name ); + PicoSetModelName( *pm, name ); PicoSetModelFrameNum( *pm, frame ); } diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 8674d87..e6b4d95 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -109,6 +109,7 @@ void LokiInitPaths( char *argv0 ) strcpy( installPath, "../" ); #else char temp[ MAX_OS_PATH ]; + char last0[ 2 ]; char *home; char *path; char *last; @@ -122,7 +123,7 @@ void LokiInitPaths( char *argv0 ) /* do some path divining */ strcpy( temp, argv0 ); - if( strrchr( temp, '/' ) ) + if( strrchr( argv0, '/' ) ) argv0 = strrchr( argv0, '/' ) + 1; else { @@ -130,6 +131,7 @@ void LokiInitPaths( char *argv0 ) path = getenv( "PATH" ); /* minor setup */ + last = last0; last[ 0 ] = path[ 0 ]; last[ 1 ] = '\0'; found = qfalse; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index b0e5f47..83c756d 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -522,7 +522,7 @@ general types ------------------------------------------------------------------------------- */ /* ydnar: for smaller structs */ -typedef char qb_t; +typedef unsigned char qb_t; /* ydnar: for q3map_tcMod */ @@ -1656,7 +1656,7 @@ tree_t *FaceBSP( face_t *list ); /* model.c */ void PicoPrintFunc( int level, const char *str ); -void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize ); +void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize ); picoModel_t *FindModel( const char *name, int frame ); picoModel_t *LoadModel( const char *name, int frame ); void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle ); @@ -1667,6 +1667,7 @@ void AddTriangleModels( entity_t *e ); mapDrawSurface_t *AllocDrawSurface( surfaceType_t type ); void FinishSurface( mapDrawSurface_t *ds ); void StripFaceSurface( mapDrawSurface_t *ds ); +void MaxAreaFaceSurface( mapDrawSurface_t *ds ); qboolean CalcSurfaceTextureRange( mapDrawSurface_t *ds ); qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis ); void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ); @@ -1679,7 +1680,7 @@ void ClearSurface( mapDrawSurface_t *ds ); void AddEntitySurfaceModels( entity_t *e ); mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w ); mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh ); -mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, char *flareShader, int lightStyle ); +mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle ); mapDrawSurface_t *DrawSurfaceForShader( char *shader ); void ClipSidesIntoTree( entity_t *e, tree_t *tree ); void MakeDebugPortalSurfs( tree_t *tree ); @@ -1949,7 +1950,7 @@ Q_EXTERN game_t games[] , #include "game_prophecy.h" /* vortex: prophecy game ( darkplaces q1 engine) */ , - { NULL } /* null game */ + #include "game__null.h" /* null game (must be last item) */ }; #endif Q_EXTERN game_t *game Q_ASSIGN( &games[ 0 ] ); diff --git a/tools/quake3/q3map2/surface.c b/tools/quake3/q3map2/surface.c index 920aff3..e72c012 100644 --- a/tools/quake3/q3map2/surface.c +++ b/tools/quake3/q3map2/surface.c @@ -1207,7 +1207,7 @@ DrawSurfaceForFlare() - ydnar creates a flare draw surface */ -mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, char *flareShader, int lightStyle ) +mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle ) { mapDrawSurface_t *ds; diff --git a/tools/quake3/q3map2/surface_extra.c b/tools/quake3/q3map2/surface_extra.c index 440fd94..5cadc1d 100644 --- a/tools/quake3/q3map2/surface_extra.c +++ b/tools/quake3/q3map2/surface_extra.c @@ -346,7 +346,7 @@ void LoadSurfaceExtraFile( const char *path ) } /* parse the file */ - ParseFromMemory( buffer, size ); + ParseFromMemory( (char *) buffer, size ); /* tokenize it */ while( 1 ) diff --git a/tools/quake3/q3map2/surface_meta.c b/tools/quake3/q3map2/surface_meta.c index be61dc8..0e300dd 100644 --- a/tools/quake3/q3map2/surface_meta.c +++ b/tools/quake3/q3map2/surface_meta.c @@ -771,6 +771,7 @@ void StripFaceSurface( mapDrawSurface_t *ds ) Error( "MAX_INDEXES exceeded for surface (%d > %d) (%d verts)", numIndexes, MAX_INDEXES, ds->numVerts ); /* try all possible orderings of the points looking for a non-degenerate strip order */ + ni = 0; for( r = 0; r < ds->numVerts; r++ ) { /* set rotation */ @@ -941,50 +942,6 @@ void MakeEntityMetaTriangles( entity_t *e ) -/* -PointTriangleIntersect() -assuming that all points lie in plane, determine if pt -is inside the triangle abc -code originally (c) 2001 softSurfer (www.softsurfer.com) -*/ - -#define MIN_OUTSIDE_EPSILON -0.01f -#define MAX_OUTSIDE_EPSILON 1.01f - -static qboolean PointTriangleIntersect( vec3_t pt, vec4_t plane, vec3_t a, vec3_t b, vec3_t c, vec3_t bary ) -{ - vec3_t u, v, w; - float uu, uv, vv, wu, wv, d; - - - /* make vectors */ - VectorSubtract( b, a, u ); - VectorSubtract( c, a, v ); - VectorSubtract( pt, a, w ); - - /* more setup */ - uu = DotProduct( u, u ); - uv = DotProduct( u, v ); - vv = DotProduct( v, v ); - wu = DotProduct( w, u ); - wv = DotProduct( w, v ); - d = uv * uv - uu * vv; - - /* calculate barycentric coordinates */ - bary[ 1 ] = (uv * wv - vv * wu) / d; - if( bary[ 1 ] < MIN_OUTSIDE_EPSILON || bary[ 1 ] > MAX_OUTSIDE_EPSILON ) - return qfalse; - bary[ 2 ] = (uv * wv - uu * wv) / d; - if( bary[ 2 ] < MIN_OUTSIDE_EPSILON || bary[ 2 ] > MAX_OUTSIDE_EPSILON ) - return qfalse; - bary[ 0 ] = 1.0f - (bary[ 1 ] + bary[ 2 ]); - - /* point is in triangle */ - return qtrue; -} - - - /* CreateEdge() sets up an edge structure from a plane and 2 points that the edge ab falls lies in @@ -1444,7 +1401,7 @@ static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, metaTriangle_t *tri, { int i, score, coincident, ai, bi, ci, oldTexRange[ 2 ]; float lmMax; - vec3_t mins, maxs, p; + vec3_t mins, maxs; qboolean inTexRange, es, et; mapDrawSurface_t old; @@ -1807,37 +1764,37 @@ static int CompareMetaTriangles( const void *a, const void *b ) /* shader first */ - if( ((metaTriangle_t*) a)->si < ((metaTriangle_t*) b)->si ) + if( ((const metaTriangle_t*) a)->si < ((const metaTriangle_t*) b)->si ) return 1; - else if( ((metaTriangle_t*) a)->si > ((metaTriangle_t*) b)->si ) + else if( ((const metaTriangle_t*) a)->si > ((const metaTriangle_t*) b)->si ) return -1; /* then fog */ - else if( ((metaTriangle_t*) a)->fogNum < ((metaTriangle_t*) b)->fogNum ) + else if( ((const metaTriangle_t*) a)->fogNum < ((const metaTriangle_t*) b)->fogNum ) return 1; - else if( ((metaTriangle_t*) a)->fogNum > ((metaTriangle_t*) b)->fogNum ) + else if( ((const metaTriangle_t*) a)->fogNum > ((const metaTriangle_t*) b)->fogNum ) return -1; /* then plane */ #if 0 - else if( npDegrees == 0.0f && ((metaTriangle_t*) a)->si->nonplanar == qfalse && - ((metaTriangle_t*) a)->planeNum >= 0 && ((metaTriangle_t*) a)->planeNum >= 0 ) + else if( npDegrees == 0.0f && ((const metaTriangle_t*) a)->si->nonplanar == qfalse && + ((const metaTriangle_t*) a)->planeNum >= 0 && ((const metaTriangle_t*) a)->planeNum >= 0 ) { - if( ((metaTriangle_t*) a)->plane[ 3 ] < ((metaTriangle_t*) b)->plane[ 3 ] ) + if( ((const metaTriangle_t*) a)->plane[ 3 ] < ((const metaTriangle_t*) b)->plane[ 3 ] ) return 1; - else if( ((metaTriangle_t*) a)->plane[ 3 ] > ((metaTriangle_t*) b)->plane[ 3 ] ) + else if( ((const metaTriangle_t*) a)->plane[ 3 ] > ((const metaTriangle_t*) b)->plane[ 3 ] ) return -1; - else if( ((metaTriangle_t*) a)->plane[ 0 ] < ((metaTriangle_t*) b)->plane[ 0 ] ) + else if( ((const metaTriangle_t*) a)->plane[ 0 ] < ((const metaTriangle_t*) b)->plane[ 0 ] ) return 1; - else if( ((metaTriangle_t*) a)->plane[ 0 ] > ((metaTriangle_t*) b)->plane[ 0 ] ) + else if( ((const metaTriangle_t*) a)->plane[ 0 ] > ((const metaTriangle_t*) b)->plane[ 0 ] ) return -1; - else if( ((metaTriangle_t*) a)->plane[ 1 ] < ((metaTriangle_t*) b)->plane[ 1 ] ) + else if( ((const metaTriangle_t*) a)->plane[ 1 ] < ((const metaTriangle_t*) b)->plane[ 1 ] ) return 1; - else if( ((metaTriangle_t*) a)->plane[ 1 ] > ((metaTriangle_t*) b)->plane[ 1 ] ) + else if( ((const metaTriangle_t*) a)->plane[ 1 ] > ((const metaTriangle_t*) b)->plane[ 1 ] ) return -1; - else if( ((metaTriangle_t*) a)->plane[ 2 ] < ((metaTriangle_t*) b)->plane[ 2 ] ) + else if( ((const metaTriangle_t*) a)->plane[ 2 ] < ((const metaTriangle_t*) b)->plane[ 2 ] ) return 1; - else if( ((metaTriangle_t*) a)->plane[ 2 ] > ((metaTriangle_t*) b)->plane[ 2 ] ) + else if( ((const metaTriangle_t*) a)->plane[ 2 ] > ((const metaTriangle_t*) b)->plane[ 2 ] ) return -1; } #endif @@ -1849,8 +1806,8 @@ static int CompareMetaTriangles( const void *a, const void *b ) VectorSet( bMins, 999999, 999999, 999999 ); for( i = 0; i < 3; i++ ) { - av = ((metaTriangle_t*) a)->indexes[ i ]; - bv = ((metaTriangle_t*) b)->indexes[ i ]; + av = ((const metaTriangle_t*) a)->indexes[ i ]; + bv = ((const metaTriangle_t*) b)->indexes[ i ]; for( j = 0; j < 3; j++ ) { if( metaVerts[ av ].xyz[ j ] < aMins[ j ] ) diff --git a/tools/quake3/q3map2/tjunction.c b/tools/quake3/q3map2/tjunction.c index f274f95..cde7ece 100644 --- a/tools/quake3/q3map2/tjunction.c +++ b/tools/quake3/q3map2/tjunction.c @@ -600,8 +600,8 @@ EdgeCompare int EdgeCompare( const void *elem1, const void *elem2 ) { float d1, d2; - d1 = ((originalEdge_t *)elem1)->length; - d2 = ((originalEdge_t *)elem2)->length; + d1 = ((const originalEdge_t *)elem1)->length; + d2 = ((const originalEdge_t *)elem2)->length; if ( d1 < d2 ) { return -1; diff --git a/tools/quake3/q3map2/vis.c b/tools/quake3/q3map2/vis.c index 0bc8313..6332113 100644 --- a/tools/quake3/q3map2/vis.c +++ b/tools/quake3/q3map2/vis.c @@ -102,9 +102,9 @@ the earlier information. */ int PComp (const void *a, const void *b) { - if ( (*(vportal_t **)a)->nummightsee == (*(vportal_t **)b)->nummightsee) + if ( (*(const vportal_t *const *)a)->nummightsee == (*(const vportal_t *const *)b)->nummightsee) return 0; - if ( (*(vportal_t **)a)->nummightsee < (*(vportal_t **)b)->nummightsee) + if ( (*(const vportal_t *const *)a)->nummightsee < (*(const vportal_t *const *)b)->nummightsee) return -1; return 1; } @@ -932,8 +932,8 @@ void LoadPortals (char *name) Error ("LoadPortals: reading portal %i", i); if (numpoints > MAX_POINTS_ON_WINDING) Error ("LoadPortals: portal %i has too many points", i); - if ( (unsigned)leafnums[0] > portalclusters - || (unsigned)leafnums[1] > portalclusters) + if (leafnums[0] > portalclusters + || leafnums[1] > portalclusters) Error ("LoadPortals: reading portal %i", i); if (fscanf (f, "%i ", &hint) != 1) Error ("LoadPortals: reading hint state"); -- 2.39.2