]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Add cl_dyntexture.h and .c (don't need to be added to the makefile or vc project...
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 23 Nov 2007 00:26:10 +0000 (00:26 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 23 Nov 2007 00:26:10 +0000 (00:26 +0000)
It supports getting the current texture handle for a dynamic texture path, linking a dynamic texture path to a texture handle and unlinking a dynamic texture path.
This is pretty transparent and it could be used for arbitrary dynamic textures (even ones that aren't updated but only linked dynamically into the game world - alias texture names).
This works for both skinframes and cachepics. Still contains lots of todos.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7713 d7cf8633-e32d-0410-b094-e92efae38249

cl_dyntexture.c [new file with mode: 0644]
cl_dyntexture.h [new file with mode: 0644]

diff --git a/cl_dyntexture.c b/cl_dyntexture.c
new file mode 100644 (file)
index 0000000..f2b6245
--- /dev/null
@@ -0,0 +1,83 @@
+// 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
+       // some sanity checks - and make sure its actually a dynamic texture path\r
+       if( !name || strncmp( name, DYNAMIC_TEXTURE_PATH_PREFIX, sizeof( DYNAMIC_TEXTURE_PATH_PREFIX ) - 1 ) != 0 ) {\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
+       // TODO: assert dyntexture != NULL!\r
+       if( dyntexture->texture != texture ) {\r
+               cachepic = Draw_CachePic( name, false );\r
+               skinframe = R_SkinFrame_Find( name, 0, 0, 0, 0, false );\r
+               // this is kind of hacky\r
+               // TODO: assert cachepic and skinframe should be valid pointers...\r
+\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
+               // TODO: assert skinframe->base = dyntexture->texture\r
+               skinframe->base = texture;\r
+               // simply reset the compare* attributes of skinframe\r
+               skinframe->comparecrc = 0;\r
+               skinframe->comparewidth = skinframe->compareheight = 0;\r
+\r
+               dyntexture->texture = texture;\r
+       }\r
+}\r
+\r
+void CL_UnlinkDynTexture( const char *name ) {\r
+       CL_LinkDynTexture( name, DEFAULT_DYNTEXTURE );\r
+}\r
+\r
diff --git a/cl_dyntexture.h b/cl_dyntexture.h
new file mode 100644 (file)
index 0000000..c513ab1
--- /dev/null
@@ -0,0 +1,18 @@
+// Andreas 'Black' Kirsch 07\r
+#ifndef CL_DYNTEXTURE_H\r
+#define CL_DYNTEXTURE_H\r
+\r
+#define DYNAMIC_TEXTURE_PATH_PREFIX                    "_dynamic/"\r
+#define MAX_DYNAMIC_TEXTURE_COUNT                      64\r
+\r
+// return a valid texture handle for a dynamic texture (might be filler texture if it hasnt been initialized yet)\r
+// textureflags will be ignored though for now [11/22/2007 Black]\r
+rtexture_t * CL_GetDynTexture( const char *name );\r
+\r
+// link a texture handle as dynamic texture and update texture handles in the renderer and draw_* accordingly\r
+void CL_LinkDynTexture( const char *name, rtexture_t *texture );\r
+\r
+// unlink a texture handle from its name\r
+void CL_UnlinkDynTexture( const char *name );\r
+\r
+#endif
\ No newline at end of file