]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/picomodel/pm_3ds.c
Wean off #define
[xonotic/netradiant.git] / libs / picomodel / pm_3ds.c
index 64b77fe6713018f3c5ab25231bc3c297d5e39d61..1a8e88f1985a2fe04e122fecc35ada208879340b 100644 (file)
 
    ----------------------------------------------------------------------------- */
 
-
-
-/* marker */
-#define PM_3DS_C
-
 /* dependencies */
 #include "picointernal.h"
 
@@ -163,21 +158,18 @@ T3dsChunk;
  *  validates an autodesk 3ds model file.
  */
 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;
        }
 
@@ -397,6 +389,9 @@ static int GetMeshShader( T3dsLoaderPers *pers ){
                return 0;
        }
 
+       /* ydnar: trim to first whitespace */
+       _pico_first_token( shaderName );
+
        /* now that we have the shader name we need to go through all of */
        /* the shaders and check the name against each shader. when we */
        /* find a shader in our shader list that matches this name we */
@@ -418,7 +413,7 @@ static int GetMeshShader( T3dsLoaderPers *pers ){
                /* we have a valid map name ptr */
                if ( mapNamePtr != NULL ) {
                        char temp[128];
-                       char *name;
+                       const char *name;
 
                        /* copy map name to local buffer */
                        strcpy( mapName,mapNamePtr );
@@ -605,11 +600,14 @@ static int DoNextEditorDataChunk( T3dsLoaderPers *pers, long endofs ){
                        /* is used by the mesh. new material names are set HERE. */
                        /* but for now we skip the new material's name ... */
                        if ( pers->shader ) {
-                               char *name = (char *)( pers->bufptr + pers->cofs );
-                               PicoSetShaderName( pers->shader,name );
+                               char *name = (char*) ( pers->bufptr + pers->cofs );
+                               char *cleanedName = _pico_clone_alloc( name );
+                               _pico_first_token( cleanedName );
+                               PicoSetShaderName( pers->shader, cleanedName );
 #ifdef DEBUG_PM_3DS
-                               printf( "NewShader: '%s'\n",name );
+                               printf( "NewShader: '%s'\n", cleanedName );
 #endif
+                               _pico_free( cleanedName );
                        }
                }
                if ( chunk->id == CHUNK_MATDIFFUSE ) {
@@ -736,7 +734,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;