Skip to content

Commit c48624d

Browse files
committed
Fixed dispenser screens breaking outlines.
1 parent 1e190a0 commit c48624d

2 files changed

Lines changed: 49 additions & 34 deletions

File tree

CastingEssentials/Modules/Graphics.cpp

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
static constexpr auto STENCIL_INDEX_MASK = 0xFC;
3333

34-
static CGlowObjectManager* s_LocalGlowObjectManager;
35-
3634
// Should we use a hook to disable IStudioRender::ForcedMaterialOverride?
3735
static bool s_DisableForcedMaterialOverride = false;
3836

@@ -565,6 +563,8 @@ void Graphics::BuildExtraGlowData(CGlowObjectManager* glowMgr)
565563
for (int i = 0; i < glowMgr->m_GlowObjectDefinitions.Count(); i++)
566564
{
567565
auto& current = glowMgr->m_GlowObjectDefinitions[i];
566+
if (current.IsUnused())
567+
continue;
568568

569569
m_ExtraGlowData.emplace_back(&current);
570570
auto& currentExtra = m_ExtraGlowData.back();
@@ -696,6 +696,43 @@ void Graphics::BuildExtraGlowData(CGlowObjectManager* glowMgr)
696696
});
697697
}
698698

699+
if (ce_outlines_debug->GetBool())
700+
{
701+
int conIndex = 0;
702+
engine->Con_NPrintf(conIndex++, "Glow object count: %zi/%i", m_ExtraGlowData.size(), glowMgr->m_GlowObjectDefinitions.Count());
703+
for (int i = 0; i < glowMgr->m_GlowObjectDefinitions.Count(); i++)
704+
{
705+
auto& current = glowMgr->m_GlowObjectDefinitions[i];
706+
707+
int extraIndex = -1;
708+
for (size_t k = 0; k < m_ExtraGlowData.size(); k++)
709+
{
710+
if (m_ExtraGlowData[k].m_Base == &current)
711+
extraIndex = (int)k;
712+
}
713+
714+
const char* prefix = i == glowMgr->m_nFirstFreeSlot ? "FIRST FREE --> " : "";
715+
if (current.IsUnused())
716+
{
717+
//glowMgr->m_GlowObjectDefinitions.Remove(i--);
718+
engine->Con_NPrintf(conIndex++, "%sUnused: next free %i [%i]", prefix, current.m_nNextFreeSlot, i);
719+
}
720+
else
721+
{
722+
auto ent = current.m_hEntity.Get();
723+
Assert(ent);
724+
725+
char buffer[128];
726+
sprintf_s(buffer, "Glow object %i (extra %i)", i, extraIndex);
727+
NDebugOverlay::Text(ent->GetAbsOrigin(), buffer, false, NDEBUG_PERSIST_TILL_NEXT_FRAME);
728+
engine->Con_NPrintf(conIndex++, "%sGlow object: %s [i %i, extra %i, entindex %i]", prefix, ent->GetClientClass()->GetName(), i, extraIndex, ent->entindex());
729+
}
730+
}
731+
732+
if (glowMgr->m_nFirstFreeSlot == CGlowObjectManager::GlowObjectDefinition_t::END_OF_FREE_LIST)
733+
engine->Con_NPrintf(conIndex++, "=== NEW ELEMENT REQUIRED ===");
734+
}
735+
699736
// Build ourselves a map of move children (we need extra glow data before we can do this)
700737
BuildMoveChildLists();
701738
}
@@ -776,8 +813,6 @@ void Graphics::DrawInfills(CMatRenderContextPtr& pRenderContext)
776813
if (!currentExtra.m_InfillEnabled)
777814
continue;
778815

779-
//const auto& current = m_GlowObjectDefinitions->Element(i);
780-
781816
ShaderStencilState_t stencilState;
782817
stencilState.m_bEnable = !ce_infills_debug->GetBool();
783818
stencilState.m_nReferenceValue = (currentExtra.m_StencilIndex << 2) | 1;
@@ -895,10 +930,9 @@ void CGlowObjectManager::GlowObjectDefinition_t::DrawModel()
895930
C_BaseEntity *pAttachment = ent->FirstMoveChild();
896931
while (pAttachment != NULL)
897932
{
898-
if (!s_LocalGlowObjectManager->HasGlowEffect(pAttachment) && pAttachment->ShouldDraw())
899-
{
933+
if (pAttachment->ShouldDraw())
900934
pAttachment->DrawModel(STUDIO_RENDER);
901-
}
935+
902936
pAttachment = pAttachment->NextMovePeer();
903937
}
904938
}
@@ -987,7 +1021,6 @@ void Graphics::DrawGlowOccluded(int nSplitScreenSlot, CMatRenderContextPtr& pRen
9871021

9881022
pRenderContext->OverrideDepthFunc(false, SHADER_DEPTHFUNC_NEAREROREQUAL)
9891023
#else // 2-pass as a proof of concept so I can take a nice screenshot.
990-
pRenderContext->OverrideDepthEnable(true, false);
9911024

9921025
ShaderStencilState_t stencilState;
9931026
stencilState.m_bEnable = true;
@@ -1009,6 +1042,7 @@ void Graphics::DrawGlowOccluded(int nSplitScreenSlot, CMatRenderContextPtr& pRen
10091042
if (current.m_Base->IsUnused() || !current.m_Base->ShouldDraw(nSplitScreenSlot) || !current.m_Base->m_bRenderWhenOccluded || current.m_Base->m_bRenderWhenUnoccluded)
10101043
continue;
10111044

1045+
pRenderContext->OverrideDepthEnable(true, false);
10121046
current.m_Base->DrawModel();
10131047
}
10141048
}
@@ -1118,38 +1152,19 @@ void Graphics::CleanupGlowObjectDefinitions(CGlowObjectManager* glowMgr)
11181152
{
11191153
auto& current = glowMgr->m_GlowObjectDefinitions[i];
11201154

1121-
if (current.IsUnused())
1155+
if (!current.IsUnused() && !current.m_hEntity.Get())
11221156
{
1123-
glowMgr->m_nFirstFreeSlot = i;
1124-
current.m_nNextFreeSlot = next;
1125-
next = i;
1126-
//glowMgr->m_GlowObjectDefinitions.Remove(i);
1157+
PluginWarning("Found NULL entity in glow object list @ %i. Removing.\n", i);
1158+
glowMgr->UnregisterGlowObject(i);
11271159
}
1128-
}
1129-
}
1130-
1131-
if (ce_outlines_debug->GetBool())
1132-
{
1133-
int conIndex = 0;
1134-
engine->Con_NPrintf(conIndex++, "Glow object count: %i", glowMgr->m_GlowObjectDefinitions.Count());
1135-
for (int i = 0; i < glowMgr->m_GlowObjectDefinitions.Count(); i++)
1136-
{
1137-
auto& current = glowMgr->m_GlowObjectDefinitions[i];
11381160

1139-
const char* prefix = i == glowMgr->m_nFirstFreeSlot ? "FIRST FREE --> " : "";
11401161
if (current.IsUnused())
11411162
{
1142-
//glowMgr->m_GlowObjectDefinitions.Remove(i--);
1143-
engine->Con_NPrintf(conIndex++, "%sUnused: next free %i [%i]", prefix, current.m_nNextFreeSlot, i);
1144-
}
1145-
else
1146-
{
1147-
engine->Con_NPrintf(conIndex++, "%sGlow object: [%i]", prefix, i);
1163+
glowMgr->m_nFirstFreeSlot = i;
1164+
current.m_nNextFreeSlot = next;
1165+
next = i;
11481166
}
11491167
}
1150-
1151-
if (glowMgr->m_nFirstFreeSlot == END_OF_FREE_LIST)
1152-
engine->Con_NPrintf(conIndex++, "=== NEW ELEMENT REQUIRED ===");
11531168
}
11541169
}
11551170

CastingEssentials/PluginBase/CastingPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "Modules/SteamTools.h"
3131
#include "Modules/TeamNames.h"
3232

33-
const char* const PLUGIN_VERSION_ID = "r17 beta7";
33+
const char* const PLUGIN_VERSION_ID = "r17 beta8";
3434
const char* const PLUGIN_FULL_VERSION = strdup(strprintf("%s %s", PLUGIN_NAME, PLUGIN_VERSION_ID).c_str());
3535

3636
class CastingPlugin final : public Plugin

0 commit comments

Comments
 (0)