From 26198359f1a45f2ece586c789a43f8062c185891 Mon Sep 17 00:00:00 2001 From: SmileyAG Date: Tue, 2 Jan 2024 05:32:04 +0400 Subject: [PATCH] Draw trigger by polygons in first if possible, otherwise as cuboid --- cl_dll/entity.cpp | 13 +++++++++++-- cl_dll/tri.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/cl_dll/entity.cpp b/cl_dll/entity.cpp index c5ceb91..a44de49 100644 --- a/cl_dll/entity.cpp +++ b/cl_dll/entity.cpp @@ -21,11 +21,14 @@ #include "particleman.h" +#include "com_model.h" #include "r_studioint.h" #undef min #undef max +extern engine_studio_api_t IEngineStudio; + extern IParticleMan *g_pParticleMan; void Game_AddObjects( void ); @@ -59,8 +62,14 @@ int CL_DLLEXPORT HUD_AddEntity( int type, struct cl_entity_s *ent, const char *m // show triggers that would be transferred from server-side with specific value in renderfx to differ it from other entities // update: there is a new implementation of displaying triggers that allows you to display even when planes is stripped due to optimizations in updated map compiler - // so this code will only work if the value 2 is specified in the cvar, but it should not be deleted imo - if ((ent->curstate.rendermode == kRenderTransColor) && (ent->curstate.renderfx == kRenderFxTrigger) && (gHUD.m_pShowServerTriggers->value == 2.0f) && !gHUD.IsTriggerForSinglePlayer(ent->curstate.rendercolor)) + // update 2: we use that code if we know that client is uses software engine and number model surfaces data is available + // for hardware engine there is more advanced code that can for example changing alpha per side + if ((gHUD.m_pShowServerTriggers->value > 0) && + (!IEngineStudio.IsHardware()) && + (ent->model && ent->model->nummodelsurfaces) && + (ent->curstate.rendermode == kRenderTransColor) && + (ent->curstate.renderfx == kRenderFxTrigger) && + !gHUD.IsTriggerForSinglePlayer(ent->curstate.rendercolor)) ent->curstate.renderamt = std::min(255.0f, std::max(0.0f, gHUD.m_pShowServerTriggersAlpha->value)); // hide corpses option diff --git a/cl_dll/tri.cpp b/cl_dll/tri.cpp index 1e180d1..6ba7eec 100644 --- a/cl_dll/tri.cpp +++ b/cl_dll/tri.cpp @@ -42,6 +42,8 @@ extern IParticleMan *g_pParticleMan; #undef min #undef max +extern engine_studio_api_t IEngineStudio; + /* ================= HUD_DrawNormalTriangles @@ -105,9 +107,47 @@ void DrawAACuboid(triangleapi_s *pTriAPI, Vector corner1, Vector corner2) pTriAPI->End(); } +void DrawPolyOrCuboid(model_t *model, Vector corner1, Vector corner2) +{ + auto pTriAPI = gEngfuncs.pTriAPI; + + if (model && !model->nummodelsurfaces) + { + DrawAACuboid(pTriAPI, corner1, corner2); + return; + } + + #ifndef SOFTWARE_BUILD + if (IEngineStudio.IsHardware() && model && model->nummodelsurfaces) + { + #define DrawPolygons(surfs) \ + for (int i = 0; i < model->nummodelsurfaces; ++i) \ + { \ + pTriAPI->Begin(TRI_POLYGON); \ + for (int j = 0; j < surfs[i].polys->numverts; ++j) \ + { \ + pTriAPI->Vertex3fv(surfs[i].polys->verts[j]); \ + } \ + pTriAPI->End(); \ + } + + if (gHUD.m_iEngineBuildNumber >= ENGINE_BUILD_ANNIVERSARY_FIRST) + { + const msurface_hw_25th_anniversary_t *surfs = (msurface_hw_25th_anniversary_t*)model->surfaces + model->firstmodelsurface; + DrawPolygons(surfs); + } + else + { + const msurface_t *surfs = model->surfaces + model->firstmodelsurface; + DrawPolygons(surfs); + } + } + #endif +} + void DrawServerTriggers() { - if ((gHUD.m_pShowServerTriggers->value > 0) && (gHUD.m_pShowServerTriggers->value != 2.0f)) + if (gHUD.m_pShowServerTriggers->value > 0) { for (int e = 0; e < MAX_EDICTS; ++e) { @@ -134,7 +174,7 @@ void DrawServerTriggers() Vector absmin = origin + mins; Vector absmax = origin + maxs; - DrawAACuboid(gEngfuncs.pTriAPI, absmin, absmax); + DrawPolyOrCuboid(ent->model, absmin, absmax); } } }