Skip to content

Commit

Permalink
Draw trigger by polygons in first if possible, otherwise as cuboid
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG committed Jan 2, 2024
1 parent fe79be6 commit 2619835
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
13 changes: 11 additions & 2 deletions cl_dll/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down
44 changes: 42 additions & 2 deletions cl_dll/tri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern IParticleMan *g_pParticleMan;
#undef min
#undef max

extern engine_studio_api_t IEngineStudio;

/*
=================
HUD_DrawNormalTriangles
Expand Down Expand Up @@ -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)
{
Expand All @@ -134,7 +174,7 @@ void DrawServerTriggers()
Vector absmin = origin + mins;
Vector absmax = origin + maxs;

DrawAACuboid(gEngfuncs.pTriAPI, absmin, absmax);
DrawPolyOrCuboid(ent->model, absmin, absmax);
}
}
}
Expand Down

0 comments on commit 2619835

Please sign in to comment.