Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Ext/Cell/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void CellExt::Serialize(T& Stm)
Stm
.Process(this->RadSites)
.Process(this->RadLevels)
.Process(this->CoveringLights)
.Process(this->InfantryCount)
;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Ext/Cell/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class CellExt final : public AbstractExt
}

std::vector<RadSiteClass*> RadSites {};
std::vector<RadLevel> RadLevels { };
int InfantryCount{ 0 };
std::vector<RadLevel> RadLevels {};
std::vector<LightSourceClass*> CoveringLights {};
int InfantryCount { 0 };

CellExt(CellClass* OwnerObject) : AbstractExt(OwnerObject)
{ }
Expand Down
94 changes: 94 additions & 0 deletions src/Ext/Cell/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,97 @@
pThis->DamageWall(RulesExt::Global()->AdjacentWallDamage);
return SkipGameCode;
}

#pragma region LightSource Optimize

DEFINE_HOOK(0x5547C8, LightSourceClass_CTOR_SetInCells, 0x5)
{
GET(LightSourceClass*, pThis, ESI);

for (CellRangeEnumerator cell(CellClass::Coord2Cell(pThis->Location), pThis->LightVisibility / Unsorted::LeptonsPerCell + 0.5); cell; ++cell)
{
const auto pCell = MapClass::Instance.TryGetCellAt(*cell);

if (!pCell)
continue;

const auto pCellExt = CellExt::ExtMap.Find(pCell);

Check warning on line 26 in src/Ext/Cell/Hooks.cpp

View workflow job for this annotation

GitHub Actions / build

'Container<CellExt>::Find': use the extension class's Fetch instead [D:\a\Phobos\Phobos\Phobos.vcxproj]
pCellExt->CoveringLights.emplace_back(pThis);
}

return 0;
}

DEFINE_HOOK(0x555176, LightSourceClass_DTOR_ResetInCells, 0x6)
{
GET(LightSourceClass*, pThis, ESI);

for (CellRangeEnumerator cell(CellClass::Coord2Cell(pThis->Location), pThis->LightVisibility / Unsorted::LeptonsPerCell + 0.5); cell; ++cell)
{
const auto pCell = MapClass::Instance.TryGetCellAt(*cell);

if (!pCell)
continue;

const auto pCellExt = CellExt::ExtMap.Find(pCell);

Check warning on line 44 in src/Ext/Cell/Hooks.cpp

View workflow job for this annotation

GitHub Actions / build

'Container<CellExt>::Find': use the extension class's Fetch instead [D:\a\Phobos\Phobos\Phobos.vcxproj]
const auto it = std::ranges::find(pCellExt->CoveringLights, pThis);

if (it != pCellExt->CoveringLights.cend())
pCellExt->CoveringLights.erase(it);
}

return 0;
}

DEFINE_HOOK_AGAIN(0x48444C, CellClass_ProcessColourComponents_LightSourceCount, 0x6)
DEFINE_HOOK(0x48427D, CellClass_ProcessColourComponents_LightSourceCount, 0x6)
{
GET(CellClass*, pThis, EDI);
const auto pExt = CellExt::Fetch(pThis);

R->ECX(static_cast<int>(pExt->CoveringLights.size()));
return R->Origin() + 0x6;
}

DEFINE_HOOK(0x48428B, CellClass_ProcessColourComponents_LightSourceItem, 0x6)
{
enum { ApplyItem = 0x484294 };

GET(CellClass*, pThis, EDI);
GET(int, idx, EAX);
const auto pExt = CellExt::Fetch(pThis);

R->ESI(pExt->CoveringLights[idx]);
return ApplyItem;
}

DEFINE_JUMP(LJMP, 0x4842DC, 0x4842E2) // Skip useless code

DEFINE_HOOK(0x554BF6, LightSourceClass_554AF0_Distance_Optimize, 0x5)
{
enum { InRange = 0x554C4B, OutOfRange = 0x554CE4 };

GET(LightSourceClass*, pThis, EDI);
REF_STACK(CellStruct, cell, STACK_OFFSET(0x30, -0x24));
const auto cellCoords = CellClass::Cell2Coord(cell);
const int diffX = pThis->Location.X - cellCoords.X;
const int diffY = pThis->Location.Y - cellCoords.Y;
const double distanceSqr = static_cast<double>(diffX) * diffX + static_cast<double>(diffY) * diffY;

if (static_cast<double>(distanceSqr) > static_cast<double>(pThis->LightVisibility) * pThis->LightVisibility)
return OutOfRange;

if (const auto pCell = MapClass::Instance.TryGetCellAt(cell))
{
pCell->MarkForRedraw();

if (const auto pBuilding = pCell->GetBuilding())
pBuilding->MarkForRedraw();
}

return InRange;
}

DEFINE_JUMP(LJMP, 0x554D0A, 0x554D16) // Skip GScreenClass::MarkNeedsRedraw(1);

#pragma endregion
Loading