Ported picomodel.c from 1.5

Improvements over 1.4/1.5 are in.
This commit is contained in:
Christophe Mateos 2016-12-04 01:43:28 +01:00
parent 3fb0a994e2
commit 41f9d3a1e1
4 changed files with 593 additions and 222 deletions

View file

@ -105,6 +105,7 @@ struct picoSurface_s
int numVertexes, maxVertexes; int numVertexes, maxVertexes;
picoVec3_t *xyz; picoVec3_t *xyz;
picoVec3_t *normal; picoVec3_t *normal;
picoIndex_t *smoothingGroup;
int numSTArrays, maxSTArrays; int numSTArrays, maxSTArrays;
picoVec2_t **st; picoVec2_t **st;
@ -216,6 +217,9 @@ const picoModule_t **PicoModuleList( int *numModules );
picoModel_t *PicoLoadModel( char *name, int frameNum ); picoModel_t *PicoLoadModel( 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);
/* model functions */ /* model functions */
picoModel_t *PicoNewModel( void ); picoModel_t *PicoNewModel( void );

View file

@ -161,35 +161,22 @@ void *_pico_realloc( void **ptr, size_t oldSize, size_t newSize ){
* as custom clone size (the string is cropped to fit into mem * as custom clone size (the string is cropped to fit into mem
* if needed). -sea * if needed). -sea
*/ */
char *_pico_clone_alloc( char *str, int size ){ char *_pico_clone_alloc(const char *str)
char *cloned; {
size_t cloneSize; char* cloned;
/* sanity check */ /* sanity check */
if ( str == NULL ) { if (str == NULL)
return NULL; return NULL;
}
/* set real size of cloned string */
cloneSize = ( size < 0 ) ? strlen( str ) : size;
/* allocate memory */ /* allocate memory */
cloned = _pico_alloc( cloneSize + 1 ); /* bugfix! */ cloned = _pico_alloc(strlen(str) + 1);
if ( cloned == NULL ) { if (cloned == NULL)
return NULL; return NULL;
}
/* zero out memory allocated by cloned string */
memset( cloned,0,cloneSize );
/* copy input string to cloned string */ /* copy input string to cloned string */
if ( cloneSize < strlen( str ) ) { strcpy(cloned, str);
memcpy( cloned,str,cloneSize );
cloned[ cloneSize ] = '\0';
}
else {
strcpy( cloned,str );
}
/* return ptr to cloned string */ /* return ptr to cloned string */
return cloned; return cloned;
} }

View file

@ -116,7 +116,7 @@ extern void ( *_pico_ptr_print )( int, const char* );
void *_pico_alloc( size_t size ); void *_pico_alloc( size_t size );
void *_pico_calloc( size_t num, size_t size ); void *_pico_calloc( size_t num, size_t size );
void *_pico_realloc( void **ptr, size_t oldSize, size_t newSize ); void *_pico_realloc( void **ptr, size_t oldSize, size_t newSize );
char *_pico_clone_alloc( char *str, int size ); char *_pico_clone_alloc( char *str/*, int size*/ );
void _pico_free( void *ptr ); void _pico_free( void *ptr );
/* files */ /* files */

File diff suppressed because it is too large Load diff