-// Andreas Kirsch 07\r
-\r
-#include "quakedef.h"\r
-#include "cl_dyntexture.h"\r
-\r
-typedef struct dyntexture_s {\r
- // everything after DYNAMIC_TEXTURE_PATH_PREFIX\r
- char name[ MAX_QPATH + 32 ];\r
- // texture pointer (points to r_texture_white at first)\r
- rtexture_t *texture;\r
-} dyntexture_t;\r
-\r
-static dyntexture_t dyntextures[ MAX_DYNAMIC_TEXTURE_COUNT ];\r
-static unsigned dyntexturecount;\r
-\r
-#define DEFAULT_DYNTEXTURE r_texture_grey128\r
-\r
-static dyntexture_t * cl_finddyntexture( const char *name ) {\r
- unsigned i;\r
- dyntexture_t *dyntexture = NULL;\r
-\r
- // sanity checks - make sure its actually a dynamic texture path\r
- if( !name || !*name || strncmp( name, CLDYNTEXTUREPREFIX, sizeof( CLDYNTEXTUREPREFIX ) - 1 ) != 0 ) {\r
- // TODO: print a warning or something\r
- if( developer.integer > 0 ) {\r
- Con_Printf( "cl_finddyntexture: Bad dynamic texture name '%s'\n", name );\r
- }\r
- return NULL;\r
- }\r
-\r
- for( i = 0 ; i < dyntexturecount ; i++ ) {\r
- dyntexture = &dyntextures[ i ];\r
- if( dyntexture->name && strcmp( dyntexture->name, name ) == 0 ) {\r
- return dyntexture;\r
- }\r
- }\r
-\r
- if( dyntexturecount == MAX_DYNAMIC_TEXTURE_COUNT ) {\r
- // TODO: warn or expand the array, etc.\r
- return NULL;\r
- }\r
- dyntexture = &dyntextures[ dyntexturecount++ ];\r
- strlcpy( dyntexture->name, name, sizeof( dyntexture->name ) );\r
- dyntexture->texture = DEFAULT_DYNTEXTURE;\r
- return dyntexture;\r
-}\r
-\r
-rtexture_t * CL_GetDynTexture( const char *name ) {\r
- dyntexture_t *dyntexture = cl_finddyntexture( name );\r
- if( dyntexture ) {\r
- return dyntexture->texture;\r
- } else {\r
- return NULL;\r
- }\r
-}\r
-\r
-void CL_LinkDynTexture( const char *name, rtexture_t *texture ) {\r
- dyntexture_t *dyntexture;\r
- cachepic_t *cachepic;\r
- skinframe_t *skinframe;\r
-\r
- dyntexture = cl_finddyntexture( name );\r
- if( !dyntexture ) {\r
- Con_Printf( "CL_LinkDynTexture: internal error in cl_finddyntexture!\n" );\r
- return;\r
- }\r
- // TODO: assert dyntexture != NULL!\r
- if( dyntexture->texture != texture ) {\r
- dyntexture->texture = texture;\r
-\r
- cachepic = Draw_CachePic( name, false );\r
- // TODO: assert cachepic and skinframe should be valid pointers...\r
- // TODO: assert cachepic->tex = dyntexture->texture\r
- cachepic->tex = texture;\r
- // update cachepic's size, too\r
- cachepic->width = R_TextureWidth( texture );\r
- cachepic->height = R_TextureHeight( texture );\r
-\r
- // update skinframes\r
- skinframe = NULL;\r
- while( (skinframe = R_SkinFrame_FindNextByName( skinframe, name )) != NULL ) {\r
- skinframe->base = texture;\r
- // simply reset the compare* attributes of skinframe\r
- skinframe->comparecrc = 0;\r
- skinframe->comparewidth = skinframe->compareheight = 0;\r
- // this is kind of hacky\r
- }\r
- }\r
-}\r
-\r
-void CL_UnlinkDynTexture( const char *name ) {\r
- CL_LinkDynTexture( name, DEFAULT_DYNTEXTURE );\r
-}\r
-\r