From 739adad3d5743bb3c6bf30e13092d5f3ff25f334 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 13 Jan 2024 13:42:03 +0900 Subject: [PATCH] [skin] Clean up the API a little Only the renderer-specific functions are in the plugin functions struct, and only the client functions are global. --- include/QF/plugin/vid_render.h | 13 ++++--------- include/QF/skin.h | 5 +++++ libs/models/skin.c | 8 ++++---- libs/scene/scene.c | 5 +++-- libs/video/renderer/vid_render_gl.c | 10 +++------- libs/video/renderer/vid_render_glsl.c | 10 +++------- libs/video/renderer/vid_render_sw.c | 10 +++------- libs/video/renderer/vid_render_vulkan.c | 10 +++------- nq/source/cl_ents.c | 12 +++++------- nq/source/cl_parse.c | 5 ++--- qw/source/cl_ents.c | 10 ++++------ qw/source/cl_parse.c | 8 ++++---- 12 files changed, 43 insertions(+), 63 deletions(-) diff --git a/include/QF/plugin/vid_render.h b/include/QF/plugin/vid_render.h index 4e7dfc0e7..22b884c37 100644 --- a/include/QF/plugin/vid_render.h +++ b/include/QF/plugin/vid_render.h @@ -38,7 +38,7 @@ struct plitem_s; struct cvar_s; struct scene_s; -struct skin_s; +typedef struct skin_s skin_t; struct particle_s; struct mod_alias_ctx_s; @@ -70,14 +70,9 @@ typedef struct vid_model_funcs_s { int alias_cache; void (*Mod_SpriteLoadFrames) (struct mod_sprite_ctx_s *sprite_ctx); - void (*Skin_Free) (struct skin_s *skin); - struct skin_s *(*Skin_SetColormap) (struct skin_s *skin, int cmap); - struct skin_s *(*Skin_SetSkin) (struct skin_s *skin, int cmap, - const char *skinname); - void (*Skin_SetupSkin) (struct skin_s *skin, int cmap); - void (*Skin_SetTranslation) (int cmap, int top, int bottom); - void (*Skin_ProcessTranslation) (int cmap, const byte *translation); - void (*Skin_InitTranslations) (void); + void (*skin_setupskin) (skin_t *skin, int cmap); + void (*skin_processtranslation) (int cmap, const byte *translation); + void (*skin_inittranslations) (void); } vid_model_funcs_t; struct tex_s; diff --git a/include/QF/skin.h b/include/QF/skin.h index 4d65c8830..d73753f08 100644 --- a/include/QF/skin.h +++ b/include/QF/skin.h @@ -59,4 +59,9 @@ typedef struct skin_s { int auxtex; } skin_t; +void Skin_Free (skin_t *skin); +skin_t *Skin_SetColormap (skin_t *skin, int cmap); +skin_t *Skin_SetSkin (skin_t *skin, int cmap, const char *skinname); +void Skin_SetTranslation (int cmap, int top, int bottom); + #endif//__QF_skin_h diff --git a/libs/models/skin.c b/libs/models/skin.c index 00de5e0bf..38007583f 100644 --- a/libs/models/skin.c +++ b/libs/models/skin.c @@ -127,7 +127,7 @@ Skin_SetTranslation (int cmap, int top, int bottom) else dest[BOTTOM_RANGE + i] = bottom + 15 - i; } - m_funcs->Skin_ProcessTranslation (cmap, translations[cmap - 1]); + m_funcs->skin_processtranslation (cmap, translations[cmap - 1]); } skin_t * @@ -142,7 +142,7 @@ Skin_SetColormap (skin_t *skin, int cmap) } if (cmap) skin->colormap = translations[cmap - 1]; - m_funcs->Skin_SetupSkin (skin, cmap); + m_funcs->skin_setupskin (skin, cmap); return skin; } @@ -228,7 +228,7 @@ Skin_SetSkin (skin_t *skin, int cmap, const char *skinname) skin = new_skin (); skin->texels = tex; skin->name = name; - m_funcs->Skin_SetupSkin (skin, cmap); + m_funcs->skin_setupskin (skin, cmap); return skin; } @@ -260,7 +260,7 @@ Skin_Init (void) qfZoneScoped (true); Sys_RegisterShutdown (skin_shutdown, 0); skin_cache = Hash_NewTable (127, skin_getkey, skin_free, 0, 0); - m_funcs->Skin_InitTranslations (); + m_funcs->skin_inittranslations (); } VISIBLE int diff --git a/libs/scene/scene.c b/libs/scene/scene.c index 5ebdd464b..9c64c561c 100644 --- a/libs/scene/scene.c +++ b/libs/scene/scene.c @@ -36,8 +36,9 @@ #endif #include "QF/mathlib.h" -#include "QF/sys.h" #include "QF/model.h" +#include "QF/skin.h" +#include "QF/sys.h" #include "QF/plugin/vid_render.h" @@ -81,7 +82,7 @@ destroy_renderer (void *_renderer, ecs_registry_t *reg) { renderer_t *renderer = _renderer; if (renderer->skin) { - mod_funcs->Skin_Free (renderer->skin); + Skin_Free (renderer->skin); } } diff --git a/libs/video/renderer/vid_render_gl.c b/libs/video/renderer/vid_render_gl.c index 845ca21e7..3188f7c93 100644 --- a/libs/video/renderer/vid_render_gl.c +++ b/libs/video/renderer/vid_render_gl.c @@ -171,13 +171,9 @@ static vid_model_funcs_t model_funcs = { .alias_cache = 1, .Mod_SpriteLoadFrames = gl_Mod_SpriteLoadFrames, - .Skin_Free = Skin_Free, - .Skin_SetColormap = Skin_SetColormap, - .Skin_SetSkin = Skin_SetSkin, - .Skin_SetupSkin = gl_Skin_SetupSkin, - .Skin_SetTranslation = Skin_SetTranslation, - .Skin_ProcessTranslation = gl_Skin_ProcessTranslation, - .Skin_InitTranslations = gl_Skin_InitTranslations, + .skin_setupskin = gl_Skin_SetupSkin, + .skin_processtranslation = gl_Skin_ProcessTranslation, + .skin_inittranslations = gl_Skin_InitTranslations, }; static void diff --git a/libs/video/renderer/vid_render_glsl.c b/libs/video/renderer/vid_render_glsl.c index 9a649aa31..5c5d1ad68 100644 --- a/libs/video/renderer/vid_render_glsl.c +++ b/libs/video/renderer/vid_render_glsl.c @@ -82,13 +82,9 @@ static vid_model_funcs_t model_funcs = { .alias_cache = 0, .Mod_SpriteLoadFrames = glsl_Mod_SpriteLoadFrames, - .Skin_Free = Skin_Free, - .Skin_SetColormap = Skin_SetColormap, - .Skin_SetSkin = Skin_SetSkin, - .Skin_SetupSkin = glsl_Skin_SetupSkin, - .Skin_SetTranslation = Skin_SetTranslation, - .Skin_ProcessTranslation = glsl_Skin_ProcessTranslation, - .Skin_InitTranslations = glsl_Skin_InitTranslations, + .skin_setupskin = glsl_Skin_SetupSkin, + .skin_processtranslation = glsl_Skin_ProcessTranslation, + .skin_inittranslations = glsl_Skin_InitTranslations, }; static void diff --git a/libs/video/renderer/vid_render_sw.c b/libs/video/renderer/vid_render_sw.c index ab8a66256..cfccfab81 100644 --- a/libs/video/renderer/vid_render_sw.c +++ b/libs/video/renderer/vid_render_sw.c @@ -91,13 +91,9 @@ static vid_model_funcs_t model_funcs = { .alias_cache = 1, .Mod_SpriteLoadFrames = sw_Mod_SpriteLoadFrames, - .Skin_Free = Skin_Free, - .Skin_SetColormap = Skin_SetColormap, - .Skin_SetSkin = Skin_SetSkin, - .Skin_SetupSkin = sw_Skin_SetupSkin, - .Skin_SetTranslation = Skin_SetTranslation, - .Skin_ProcessTranslation = sw_Skin_ProcessTranslation, - .Skin_InitTranslations = sw_Skin_InitTranslations, + .skin_setupskin = sw_Skin_SetupSkin, + .skin_processtranslation = sw_Skin_ProcessTranslation, + .skin_inittranslations = sw_Skin_InitTranslations, }; static void diff --git a/libs/video/renderer/vid_render_vulkan.c b/libs/video/renderer/vid_render_vulkan.c index c894aa811..fd961a828 100644 --- a/libs/video/renderer/vid_render_vulkan.c +++ b/libs/video/renderer/vid_render_vulkan.c @@ -523,13 +523,9 @@ static vid_model_funcs_t model_funcs = { .alias_cache = 0, .Mod_SpriteLoadFrames = vulkan_Mod_SpriteLoadFrames, - .Skin_Free = Skin_Free, - .Skin_SetColormap = Skin_SetColormap, - .Skin_SetSkin = Skin_SetSkin, - .Skin_SetupSkin = vulkan_Skin_SetupSkin, - .Skin_SetTranslation = Skin_SetTranslation, - .Skin_ProcessTranslation = vulkan_Skin_ProcessTranslation, - .Skin_InitTranslations = vulkan_Skin_InitTranslations, + .skin_setupskin = vulkan_Skin_SetupSkin, + .skin_processtranslation = vulkan_Skin_ProcessTranslation, + .skin_inittranslations = vulkan_Skin_InitTranslations, }; static void diff --git a/nq/source/cl_ents.c b/nq/source/cl_ents.c index 1f1cdcfd0..ae17908f8 100644 --- a/nq/source/cl_ents.c +++ b/nq/source/cl_ents.c @@ -158,7 +158,7 @@ set_entity_model (int ent_ind, int modelindex) SET_ADD (&cl_forcelink, ent_ind); animation->nolerp = 1; // don't try to lerp when the model has changed if (ent_ind <= cl.maxclients) { - renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, ent_ind); + renderer->skin = Skin_SetColormap (renderer->skin, ent_ind); } } @@ -236,8 +236,7 @@ CL_RelinkEntities (void) if (SET_TEST_MEMBER (&cl_forcelink, i) || new->colormap != old->colormap) { old->colormap = new->colormap; - renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, - new->colormap); + renderer->skin = Skin_SetColormap (renderer->skin, new->colormap); } if (SET_TEST_MEMBER (&cl_forcelink, i) || new->skinnum != old->skinnum) { @@ -249,10 +248,9 @@ CL_RelinkEntities (void) .bottom = cl.players[i - 1].bottomcolor, }; Ent_SetComponent (ent.id, ent.base + scene_colormap, ent.reg, &colormap); - renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, - i); - mod_funcs->Skin_SetTranslation (i, cl.players[i - 1].topcolor, - cl.players[i - 1].bottomcolor); + renderer->skin = Skin_SetColormap (renderer->skin, i); + Skin_SetTranslation (i, cl.players[i - 1].topcolor, + cl.players[i - 1].bottomcolor); } } diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index f2b7cf54e..738dc73a2 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -938,11 +938,10 @@ CL_ParseServerMessage (void) byte bot = col & 0xf; if (top != cl.players[i].topcolor || bot != cl.players[i].bottomcolor) - mod_funcs->Skin_SetTranslation (i + 1, top, bot); + Skin_SetTranslation (i + 1, top, bot); cl.players[i].topcolor = top; cl.players[i].bottomcolor = bot; - renderer->skin - = mod_funcs->Skin_SetColormap (renderer->skin, i + 1); + renderer->skin = Skin_SetColormap (renderer->skin, i + 1); Sbar_UpdateInfo (i); } break; diff --git a/qw/source/cl_ents.c b/qw/source/cl_ents.c index a7aabed31..1626f99a7 100644 --- a/qw/source/cl_ents.c +++ b/qw/source/cl_ents.c @@ -222,14 +222,12 @@ CL_LinkPacketEntities (void) .bottom = player->bottomcolor, }; Ent_SetComponent (ent.id, ent.base + scene_colormap, ent.reg, &colormap); - renderer->skin - = mod_funcs->Skin_SetSkin (renderer->skin, new->colormap, + renderer->skin = Skin_SetSkin (renderer->skin, new->colormap, player->skinname->value); - renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, - new->colormap); + renderer->skin = Skin_SetColormap (renderer->skin, + new->colormap); } else { - renderer->skin = mod_funcs->Skin_SetColormap (renderer->skin, - 0); + renderer->skin = Skin_SetColormap (renderer->skin, 0); Ent_RemoveComponent (ent.id, ent.base + scene_colormap, ent.reg); } } diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index 37a754536..c96a7acf0 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -324,7 +324,7 @@ Model_NextDownload (void) if (strequal (cl.model_name[i], "progs/player.mdl") && cl_world.models.a[i]->type == mod_alias) { info_key = pmodel_name; - //XXX mod_funcs->Skin_Player_Model (cl_world.models.a[i]); + //XXX Skin_Player_Model (cl_world.models.a[i]); } if (strequal (cl.model_name[i], "progs/eyes.mdl") && cl_world.models.a[i]->type == mod_alias) @@ -1021,11 +1021,11 @@ CL_ProcessUserInfo (int slot, player_info_t *player) const char *spec = Info_ValueForKey (player->userinfo, "*spectator"); player->spectator = spec && *spec; - mod_funcs->Skin_SetTranslation (slot + 1, player->topcolor, + Skin_SetTranslation (slot + 1, player->topcolor, player->bottomcolor); - player->skin = mod_funcs->Skin_SetSkin (player->skin, slot + 1, + player->skin = Skin_SetSkin (player->skin, slot + 1, player->skinname->value); - player->skin = mod_funcs->Skin_SetColormap (player->skin, slot + 1); + player->skin = Skin_SetColormap (player->skin, slot + 1); Sbar_UpdateInfo (slot); }