From 6da976c195a355aa481e0a7d27d21795610c997d Mon Sep 17 00:00:00 2001 From: Saurtron Date: Wed, 18 Dec 2024 12:22:29 +0100 Subject: [PATCH 01/15] Make all immobiles have no radar drift. --- rts/Sim/Units/Unit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index 9f1ec62fbd..c5ea6ee424 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -555,7 +555,7 @@ float3 CUnit::GetErrorVector(int argAllyTeam) const const int atSightMask = losStatus[argAllyTeam]; const int isVisible = 2 * ((atSightMask & LOS_INLOS ) != 0 || teamHandler.Ally(argAllyTeam, allyteam)); // in LOS or allied, no error - const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && unitDef->IsBuildingUnit()); // seen ghosted building, no error + const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && unitDef->IsImmobileUnit()); // seen ghosted immobiles, no error const int isOnRadar = 8 * ((atSightMask & LOS_INRADAR) != 0 ); // current radar contact float errorMult = 0.0f; From 9dc230f9fa2ac0d7e2afedb7be35d016e8bd0376 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Sat, 21 Dec 2024 13:21:58 +0100 Subject: [PATCH 02/15] Apply same ghosting behavior for immobiles and buildings. --- rts/Rendering/Units/UnitDrawerData.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 8c56776cba..97854e2516 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -255,7 +255,7 @@ const icon::CIconData* CUnitDrawerData::GetUnitIcon(const CUnit* unit) // use the unit's custom icon if we can currently see it, // or have seen it before and did not lose contact since bool unitVisible = ((losStatus & (LOS_INLOS | LOS_INRADAR)) && ((losStatus & prevMask) == prevMask)); - unitVisible |= gameSetup->ghostedBuildings && unit->unitDef->IsBuildingUnit() && (losStatus & LOS_PREVLOS); + unitVisible |= gameSetup->ghostedBuildings && unit->unitDef->IsImmobileUnit() && (losStatus & LOS_PREVLOS); const bool customIcon = (unitVisible || gu->spectatingFullView); if (customIcon) @@ -585,7 +585,7 @@ void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) const UnitDef* unitDef = unit->unitDef; const UnitDef* decoyDef = unitDef->decoyDef; - const bool addNewGhost = unitDef->IsBuildingUnit() && gameSetup->ghostedBuildings; + const bool addNewGhost = unitDef->IsImmobileUnit() && gameSetup->ghostedBuildings; // TODO - make ghosted buildings per allyTeam - so they are correctly dealt with // when spectating @@ -640,7 +640,7 @@ void CUnitDrawerData::UnitEnteredLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->unitDef->IsBuildingUnit()) + if (gameSetup->ghostedBuildings && unit->unitDef->IsImmobileUnit()) spring::VectorErase(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u); if (allyTeam != gu->myAllyTeam) @@ -654,7 +654,7 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->unitDef->IsBuildingUnit()) + if (gameSetup->ghostedBuildings && unit->unitDef->IsImmobileUnit()) spring::VectorInsertUnique(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u, true); if (allyTeam != gu->myAllyTeam) From 29f345897d83e1aba23a25b4932cc67d597fae12 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Tue, 7 Jan 2025 13:45:25 +0100 Subject: [PATCH 03/15] Add unitDef->leavesRadarGhost to control units leaving radar ghosts behind. - Defaults to true for buildings --- rts/Lua/LuaUnitDefs.cpp | 1 + rts/Rendering/Units/UnitDrawerData.cpp | 8 ++++---- rts/Sim/Units/UnitDef.cpp | 3 +++ rts/Sim/Units/UnitDef.h | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rts/Lua/LuaUnitDefs.cpp b/rts/Lua/LuaUnitDefs.cpp index 7fc37b2e85..8d8c9a542b 100644 --- a/rts/Lua/LuaUnitDefs.cpp +++ b/rts/Lua/LuaUnitDefs.cpp @@ -727,6 +727,7 @@ ADD_BOOL("canAttackWater", canAttackWater); // CUSTOM ADD_FLOAT("seismicSignature", ud.seismicSignature); ADD_BOOL("stealth", ud.stealth); ADD_BOOL("sonarStealth", ud.sonarStealth); + ADD_BOOL("leavesRadarGhost", ud.leavesRadarGhost); ADD_FLOAT("mass", ud.mass); diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 97854e2516..bb4448cf7b 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -255,7 +255,7 @@ const icon::CIconData* CUnitDrawerData::GetUnitIcon(const CUnit* unit) // use the unit's custom icon if we can currently see it, // or have seen it before and did not lose contact since bool unitVisible = ((losStatus & (LOS_INLOS | LOS_INRADAR)) && ((losStatus & prevMask) == prevMask)); - unitVisible |= gameSetup->ghostedBuildings && unit->unitDef->IsImmobileUnit() && (losStatus & LOS_PREVLOS); + unitVisible |= gameSetup->ghostedBuildings && unit->unitDef->leavesRadarGhost && (losStatus & LOS_PREVLOS); const bool customIcon = (unitVisible || gu->spectatingFullView); if (customIcon) @@ -585,7 +585,7 @@ void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) const UnitDef* unitDef = unit->unitDef; const UnitDef* decoyDef = unitDef->decoyDef; - const bool addNewGhost = unitDef->IsImmobileUnit() && gameSetup->ghostedBuildings; + const bool addNewGhost = unitDef->leavesRadarGhost && gameSetup->ghostedBuildings; // TODO - make ghosted buildings per allyTeam - so they are correctly dealt with // when spectating @@ -640,7 +640,7 @@ void CUnitDrawerData::UnitEnteredLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->unitDef->IsImmobileUnit()) + if (gameSetup->ghostedBuildings && unit->unitDef->leavesRadarGhost) spring::VectorErase(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u); if (allyTeam != gu->myAllyTeam) @@ -654,7 +654,7 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->unitDef->IsImmobileUnit()) + if (gameSetup->ghostedBuildings && unit->unitDef->leavesRadarGhost) spring::VectorInsertUnique(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u, true); if (allyTeam != gu->myAllyTeam) diff --git a/rts/Sim/Units/UnitDef.cpp b/rts/Sim/Units/UnitDef.cpp index 82d530ae19..da4095b6f4 100644 --- a/rts/Sim/Units/UnitDef.cpp +++ b/rts/Sim/Units/UnitDef.cpp @@ -106,6 +106,7 @@ UnitDef::UnitDef() , seismicSignature(0.0f) , stealth(false) , sonarStealth(false) + , leavesRadarGhost(false) , buildRange3D(false) , buildDistance(16.0f) // 16.0f is the minimum distance between two 1x1 units , buildSpeed(0.0f) @@ -658,6 +659,8 @@ UnitDef::UnitDef(const LuaTable& udTable, const std::string& unitName, int id) if (IsImmobileUnit()) CreateYardMap(udTable.GetString("yardMap", "")); + leavesRadarGhost = udTable.GetBool("leavesRadarGhost", IsBuildingUnit()); + decalDef.Parse(udTable); canDropFlare = udTable.GetBool("canDropFlare", false); diff --git a/rts/Sim/Units/UnitDef.h b/rts/Sim/Units/UnitDef.h index 28d11a001d..b05a8a9eed 100644 --- a/rts/Sim/Units/UnitDef.h +++ b/rts/Sim/Units/UnitDef.h @@ -168,6 +168,7 @@ struct UnitDef: public SolidObjectDef float seismicSignature; bool stealth; bool sonarStealth; + bool leavesRadarGhost; bool buildRange3D; float buildDistance; From f3ea435d52aaeff71e34b887e394499e72bbab0b Mon Sep 17 00:00:00 2001 From: Saurtron Date: Tue, 7 Jan 2025 13:52:45 +0100 Subject: [PATCH 04/15] Add unit->staticRadarGhost to control radar ghosts having no drift. --- rts/Lua/LuaSyncedCtrl.cpp | 22 ++++++++++++++++++++++ rts/Lua/LuaSyncedCtrl.h | 1 + rts/Lua/LuaSyncedRead.cpp | 17 +++++++++++++++++ rts/Lua/LuaSyncedRead.h | 1 + rts/Sim/Units/Unit.cpp | 11 ++++++++++- rts/Sim/Units/Unit.h | 5 ++++- 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index 36567b7cda..6d813f77f5 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -181,6 +181,7 @@ bool LuaSyncedCtrl::PushEntries(lua_State* L) REGISTER_LUA_CFUNC(SetUnitStealth); REGISTER_LUA_CFUNC(SetUnitSonarStealth); REGISTER_LUA_CFUNC(SetUnitSeismicSignature); + REGISTER_LUA_CFUNC(SetUnitStaticRadarGhost); REGISTER_LUA_CFUNC(SetUnitAlwaysVisible); REGISTER_LUA_CFUNC(SetUnitUseAirLos); REGISTER_LUA_CFUNC(SetUnitMetalExtraction); @@ -2684,6 +2685,27 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L) return 0; } +/*** + * @function Spring.SetUnitStaticRadarGhost + * + * Set the radar ghost for the unit to have no drift. + * Only for units where unitDef has leavesRadarGhost enabled. + * + * @number unitID + * @bool staticRadarGhost + * @treturn nil + */ +int LuaSyncedCtrl::SetUnitStaticRadarGhost(lua_State* L) +{ + CUnit* unit = ParseUnit(L, __func__, 1); + + if (unit == nullptr) + return 0; + + unit->SetStaticRadarGhost(luaL_checkboolean(L, 2)); + return 0; +} + /*** * @function Spring.SetUnitAlwaysVisible * @number unitID diff --git a/rts/Lua/LuaSyncedCtrl.h b/rts/Lua/LuaSyncedCtrl.h index 09b64d0bb1..ab20a0821c 100644 --- a/rts/Lua/LuaSyncedCtrl.h +++ b/rts/Lua/LuaSyncedCtrl.h @@ -90,6 +90,7 @@ class LuaSyncedCtrl static int SetUnitStealth(lua_State* L); static int SetUnitSonarStealth(lua_State* L); static int SetUnitSeismicSignature(lua_State* L); + static int SetUnitStaticRadarGhost(lua_State* L); static int SetUnitAlwaysVisible(lua_State* L); static int SetUnitUseAirLos(lua_State* L); static int SetUnitResourcing(lua_State* L); diff --git a/rts/Lua/LuaSyncedRead.cpp b/rts/Lua/LuaSyncedRead.cpp index bd6ea4548c..f6f10934b2 100644 --- a/rts/Lua/LuaSyncedRead.cpp +++ b/rts/Lua/LuaSyncedRead.cpp @@ -215,6 +215,7 @@ bool LuaSyncedRead::PushEntries(lua_State* L) REGISTER_LUA_CFUNC(GetUnitArmored); REGISTER_LUA_CFUNC(GetUnitIsActive); REGISTER_LUA_CFUNC(GetUnitIsCloaked); + REGISTER_LUA_CFUNC(GetUnitStaticRadarGhost); REGISTER_LUA_CFUNC(GetUnitSelfDTime); REGISTER_LUA_CFUNC(GetUnitStockpile); REGISTER_LUA_CFUNC(GetUnitSensorRadius); @@ -3850,6 +3851,22 @@ int LuaSyncedRead::GetUnitSeismicSignature(lua_State* L) return 1; } +/*** + * + * @function Spring.GetUnitStaticRadarGhost + * @number unitID + * @treturn nil|number + */ +int LuaSyncedRead::GetUnitStaticRadarGhost(lua_State* L) +{ + const CUnit* const unit = ParseAllyUnit(L, __func__, 1); + if (unit == nullptr) + return 0; + + lua_pushboolean(L, unit->staticRadarGhost); + return 1; +} + /*** * * @function Spring.GetUnitSelfDTime diff --git a/rts/Lua/LuaSyncedRead.h b/rts/Lua/LuaSyncedRead.h index 9b7e27c140..cd35faa3ce 100644 --- a/rts/Lua/LuaSyncedRead.h +++ b/rts/Lua/LuaSyncedRead.h @@ -120,6 +120,7 @@ class LuaSyncedRead { static int GetUnitIsActive(lua_State* L); static int GetUnitIsCloaked(lua_State* L); static int GetUnitSeismicSignature(lua_State* L); + static int GetUnitStaticRadarGhost(lua_State* L); static int GetUnitSelfDTime(lua_State* L); static int GetUnitStockpile(lua_State* L); static int GetUnitSensorRadius(lua_State* L); diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index c5ea6ee424..0497889b30 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -295,6 +295,8 @@ void CUnit::PreInit(const UnitLoadParams& params) wantCloak |= unitDef->startCloaked; decloakDistance = unitDef->decloakDistance; + staticRadarGhost = unitDef->leavesRadarGhost; + flankingBonusMode = unitDef->flankingBonusMode; flankingBonusDir = unitDef->flankingBonusDir; flankingBonusMobility = unitDef->flankingBonusMobilityAdd * 1000; @@ -543,6 +545,11 @@ void CUnit::ForcedMove(const float3& newPos) } +void CUnit::SetStaticRadarGhost(bool isStatic) +{ + staticRadarGhost = isStatic && unitDef->leavesRadarGhost; +} + float3 CUnit::GetErrorVector(int argAllyTeam) const { @@ -555,7 +562,7 @@ float3 CUnit::GetErrorVector(int argAllyTeam) const const int atSightMask = losStatus[argAllyTeam]; const int isVisible = 2 * ((atSightMask & LOS_INLOS ) != 0 || teamHandler.Ally(argAllyTeam, allyteam)); // in LOS or allied, no error - const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && unitDef->IsImmobileUnit()); // seen ghosted immobiles, no error + const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && staticRadarGhost); // seen ghosted immobiles, no error const int isOnRadar = 8 * ((atSightMask & LOS_INRADAR) != 0 ); // current radar contact float errorMult = 0.0f; @@ -3013,6 +3020,8 @@ CR_REG_METADATA(CUnit, ( CR_MEMBER(isCloaked), CR_MEMBER(decloakDistance), + CR_MEMBER(staticRadarGhost), + CR_MEMBER(lastTerrainType), CR_MEMBER(curTerrainType), diff --git a/rts/Sim/Units/Unit.h b/rts/Sim/Units/Unit.h index fe4af49685..33ccb85424 100644 --- a/rts/Sim/Units/Unit.h +++ b/rts/Sim/Units/Unit.h @@ -190,6 +190,8 @@ class CUnit : public CSolidObject unsigned short CalcLosStatus(int allyTeam); void UpdateLosStatus(int allyTeam); + void SetStaticRadarGhost(bool isStatic); + void UpdateWeapons(); void UpdateWeaponVectors(); @@ -548,7 +550,8 @@ class CUnit : public CSolidObject bool isCloaked = false; // true if the unit currently wants to be cloaked bool wantCloak = false; - + // true if unitDef leavesRadarGhost and the unit ghost will have no drift + bool staticRadarGhost = false; // unsynced vars bool noMinimap = false; From fa85dd5c6531ff9bfa06586c9add48a1554e21eb Mon Sep 17 00:00:00 2001 From: Saurtron Date: Tue, 7 Jan 2025 16:21:16 +0100 Subject: [PATCH 05/15] Update building ghosts when unit->staticRadarGhost changes. --- rts/Lua/LuaSyncedCtrl.cpp | 4 ++++ rts/Rendering/Units/UnitDrawer.h | 1 + rts/Rendering/Units/UnitDrawerData.cpp | 33 +++++++++++++++++++++----- rts/Rendering/Units/UnitDrawerData.h | 2 ++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index 6d813f77f5..64a2b69475 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -28,6 +28,7 @@ #include "Rendering/Env/GrassDrawer.h" #include "Rendering/Env/IGroundDecalDrawer.h" #include "Rendering/Models/IModelParser.h" +#include "Rendering/Units/UnitDrawer.h" #include "Sim/Features/Feature.h" #include "Sim/Features/FeatureDef.h" #include "Sim/Features/FeatureDefHandler.h" @@ -2702,7 +2703,10 @@ int LuaSyncedCtrl::SetUnitStaticRadarGhost(lua_State* L) if (unit == nullptr) return 0; + bool prevValue = unit->staticRadarGhost; unit->SetStaticRadarGhost(luaL_checkboolean(L, 2)); + if (prevValue != unit->staticRadarGhost) + unitDrawer->SetUnitStaticRadarGhost(unit); return 0; } diff --git a/rts/Rendering/Units/UnitDrawer.h b/rts/Rendering/Units/UnitDrawer.h index 10f9c452f1..d8a45af69e 100644 --- a/rts/Rendering/Units/UnitDrawer.h +++ b/rts/Rendering/Units/UnitDrawer.h @@ -54,6 +54,7 @@ class CUnitDrawer : public CModelDrawerBase static const std::vector& GetUnsortedUnits() { return modelDrawerData->GetUnsortedObjects(); } static void ClearPreviousDrawFlags() { modelDrawerData->ClearPreviousDrawFlags(); } + static void SetUnitStaticRadarGhost(const CUnit* unit) { modelDrawerData->SetUnitStaticRadarGhost(unit); } public: // DrawUnit* virtual void DrawUnitNoTrans(const CUnit* unit, uint32_t preList, uint32_t postList, bool lodCall, bool noLuaCall) const = 0; diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index bb4448cf7b..5308cbbd31 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -255,7 +255,7 @@ const icon::CIconData* CUnitDrawerData::GetUnitIcon(const CUnit* unit) // use the unit's custom icon if we can currently see it, // or have seen it before and did not lose contact since bool unitVisible = ((losStatus & (LOS_INLOS | LOS_INRADAR)) && ((losStatus & prevMask) == prevMask)); - unitVisible |= gameSetup->ghostedBuildings && unit->unitDef->leavesRadarGhost && (losStatus & LOS_PREVLOS); + unitVisible |= gameSetup->ghostedBuildings && unit->staticRadarGhost && (losStatus & LOS_PREVLOS); const bool customIcon = (unitVisible || gu->spectatingFullView); if (customIcon) @@ -577,16 +577,16 @@ void CUnitDrawerData::RenderUnitCreated(const CUnit* unit, int cloaked) UpdateUnitIcon(unit, false, false); } -void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) +void CUnitDrawerData::UpdateGhosts(const CUnit* unit, const bool addNewGhost) { - RECOIL_DETAILED_TRACY_ZONE; + if (!gameSetup->ghostedBuildings) + return; + CUnit* u = const_cast(unit); const UnitDef* unitDef = unit->unitDef; const UnitDef* decoyDef = unitDef->decoyDef; - const bool addNewGhost = unitDef->leavesRadarGhost && gameSetup->ghostedBuildings; - // TODO - make ghosted buildings per allyTeam - so they are correctly dealt with // when spectating GhostSolidObject* gso = nullptr; @@ -615,10 +615,21 @@ void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) // (the ref-counter saves us come deletion time) savedData.deadGhostBuildings[allyTeam][gsoModel->type].push_back(gso); gso->IncRef(); + // remove prevlos for unit + if (u->losStatus[allyTeam] & LOS_PREVLOS) + u->losStatus[allyTeam] ^= LOS_PREVLOS; } spring::VectorErase(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(u)], u); } +} + +void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) +{ + RECOIL_DETAILED_TRACY_ZONE; + CUnit* u = const_cast(unit); + + UpdateGhosts(unit, unit->staticRadarGhost); DelObject(unit, true); UpdateUnitIcon(unit, false, true); @@ -654,7 +665,7 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->unitDef->leavesRadarGhost) + if (gameSetup->ghostedBuildings && unit->staticRadarGhost) spring::VectorInsertUnique(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u, true); if (allyTeam != gu->myAllyTeam) @@ -663,6 +674,16 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) UpdateUnitIcon(unit, false, false); } +void CUnitDrawerData::SetUnitStaticRadarGhost(const CUnit* unit) +{ + if (unit->staticRadarGhost) + return; + + const bool addNewGhost = gameSetup->ghostedBuildings; + + UpdateGhosts(unit, true); +} + void CUnitDrawerData::PlayerChanged(int playerNum) { RECOIL_DETAILED_TRACY_ZONE; diff --git a/rts/Rendering/Units/UnitDrawerData.h b/rts/Rendering/Units/UnitDrawerData.h index acd9ea43a5..0df0015362 100644 --- a/rts/Rendering/Units/UnitDrawerData.h +++ b/rts/Rendering/Units/UnitDrawerData.h @@ -60,6 +60,8 @@ class CUnitDrawerData : public CUnitDrawerDataBase { void UnitLeftLos(const CUnit* unit, int allyTeam) override; void PlayerChanged(int playerNum) override; + void UpdateGhosts(const CUnit* unit, const bool addNewGhost); + void SetUnitStaticRadarGhost(const CUnit* unit); public: class TempDrawUnit { CR_DECLARE_STRUCT(TempDrawUnit) From 7197698aba0af15e77165dd3e09189415baf332d Mon Sep 17 00:00:00 2001 From: Saurtron Date: Tue, 7 Jan 2025 19:18:05 +0100 Subject: [PATCH 06/15] Small refactor of UpdateGhosts and rename to UpdateUnitGhosts. --- rts/Rendering/Units/UnitDrawerData.cpp | 16 ++++++++++------ rts/Rendering/Units/UnitDrawerData.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 5308cbbd31..52958072c5 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -577,11 +577,12 @@ void CUnitDrawerData::RenderUnitCreated(const CUnit* unit, int cloaked) UpdateUnitIcon(unit, false, false); } -void CUnitDrawerData::UpdateGhosts(const CUnit* unit, const bool addNewGhost) +bool CUnitDrawerData::UpdateUnitGhosts(const CUnit* unit, const bool addNewGhost) { if (!gameSetup->ghostedBuildings) - return; + return false; + bool addedOwnAllyTeam = false; CUnit* u = const_cast(unit); const UnitDef* unitDef = unit->unitDef; @@ -618,10 +619,14 @@ void CUnitDrawerData::UpdateGhosts(const CUnit* unit, const bool addNewGhost) // remove prevlos for unit if (u->losStatus[allyTeam] & LOS_PREVLOS) u->losStatus[allyTeam] ^= LOS_PREVLOS; + if (allyTeam == gu->myAllyTeam) + addedOwnAllyTeam = true; + } spring::VectorErase(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(u)], u); } + return addedOwnAllyTeam; } void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) @@ -629,7 +634,7 @@ void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); - UpdateGhosts(unit, unit->staticRadarGhost); + UpdateUnitGhosts(unit, unit->staticRadarGhost); DelObject(unit, true); UpdateUnitIcon(unit, false, true); @@ -679,9 +684,8 @@ void CUnitDrawerData::SetUnitStaticRadarGhost(const CUnit* unit) if (unit->staticRadarGhost) return; - const bool addNewGhost = gameSetup->ghostedBuildings; - - UpdateGhosts(unit, true); + if (UpdateUnitGhosts(unit, true)) + UpdateUnitIcon(unit, false, true); } void CUnitDrawerData::PlayerChanged(int playerNum) diff --git a/rts/Rendering/Units/UnitDrawerData.h b/rts/Rendering/Units/UnitDrawerData.h index 0df0015362..8b0c3b942a 100644 --- a/rts/Rendering/Units/UnitDrawerData.h +++ b/rts/Rendering/Units/UnitDrawerData.h @@ -60,7 +60,7 @@ class CUnitDrawerData : public CUnitDrawerDataBase { void UnitLeftLos(const CUnit* unit, int allyTeam) override; void PlayerChanged(int playerNum) override; - void UpdateGhosts(const CUnit* unit, const bool addNewGhost); + bool UpdateUnitGhosts(const CUnit* unit, const bool addNewGhost); void SetUnitStaticRadarGhost(const CUnit* unit); public: class TempDrawUnit { From fcbb300d7185cf06cbeaaead1ec79ff696001ab3 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 10:14:54 +0100 Subject: [PATCH 07/15] Make leaving dead ghosts behind optional when staticRadarGhost is disabled. --- rts/Lua/LuaSyncedCtrl.cpp | 3 ++- rts/Rendering/Units/UnitDrawer.h | 2 +- rts/Rendering/Units/UnitDrawerData.cpp | 4 ++-- rts/Rendering/Units/UnitDrawerData.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index 64a2b69475..afa8328e0f 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -2694,6 +2694,7 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L) * * @number unitID * @bool staticRadarGhost + * @bool[opt] leaveDeadGhost leave a dead ghost behind if disabling and the unit had a live static ghost. * @treturn nil */ int LuaSyncedCtrl::SetUnitStaticRadarGhost(lua_State* L) @@ -2706,7 +2707,7 @@ int LuaSyncedCtrl::SetUnitStaticRadarGhost(lua_State* L) bool prevValue = unit->staticRadarGhost; unit->SetStaticRadarGhost(luaL_checkboolean(L, 2)); if (prevValue != unit->staticRadarGhost) - unitDrawer->SetUnitStaticRadarGhost(unit); + unitDrawer->SetUnitStaticRadarGhost(unit, luaL_optboolean(L, 3, false)); return 0; } diff --git a/rts/Rendering/Units/UnitDrawer.h b/rts/Rendering/Units/UnitDrawer.h index d8a45af69e..9d48359e7b 100644 --- a/rts/Rendering/Units/UnitDrawer.h +++ b/rts/Rendering/Units/UnitDrawer.h @@ -54,7 +54,7 @@ class CUnitDrawer : public CModelDrawerBase static const std::vector& GetUnsortedUnits() { return modelDrawerData->GetUnsortedObjects(); } static void ClearPreviousDrawFlags() { modelDrawerData->ClearPreviousDrawFlags(); } - static void SetUnitStaticRadarGhost(const CUnit* unit) { modelDrawerData->SetUnitStaticRadarGhost(unit); } + static void SetUnitStaticRadarGhost(const CUnit* unit, const bool leaveDeadGhost) { modelDrawerData->SetUnitStaticRadarGhost(unit, leaveDeadGhost); } public: // DrawUnit* virtual void DrawUnitNoTrans(const CUnit* unit, uint32_t preList, uint32_t postList, bool lodCall, bool noLuaCall) const = 0; diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 52958072c5..340837662f 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -679,12 +679,12 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) UpdateUnitIcon(unit, false, false); } -void CUnitDrawerData::SetUnitStaticRadarGhost(const CUnit* unit) +void CUnitDrawerData::SetUnitStaticRadarGhost(const CUnit* unit, const bool leaveDeadGhost) { if (unit->staticRadarGhost) return; - if (UpdateUnitGhosts(unit, true)) + if (UpdateUnitGhosts(unit, leaveDeadGhost)) UpdateUnitIcon(unit, false, true); } diff --git a/rts/Rendering/Units/UnitDrawerData.h b/rts/Rendering/Units/UnitDrawerData.h index 8b0c3b942a..54bb96c560 100644 --- a/rts/Rendering/Units/UnitDrawerData.h +++ b/rts/Rendering/Units/UnitDrawerData.h @@ -61,7 +61,7 @@ class CUnitDrawerData : public CUnitDrawerDataBase { void PlayerChanged(int playerNum) override; bool UpdateUnitGhosts(const CUnit* unit, const bool addNewGhost); - void SetUnitStaticRadarGhost(const CUnit* unit); + void SetUnitStaticRadarGhost(const CUnit* unit, const bool leaveDeadGhost); public: class TempDrawUnit { CR_DECLARE_STRUCT(TempDrawUnit) From 7e905e06cc1235e4821924391655f033052d0425 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 10:45:50 +0100 Subject: [PATCH 08/15] Check unit->staticRadarGhost instead of unitDef inside UnitEnteredLos. --- rts/Rendering/Units/UnitDrawerData.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 340837662f..1b4fd6de12 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -656,7 +656,7 @@ void CUnitDrawerData::UnitEnteredLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->unitDef->leavesRadarGhost) + if (gameSetup->ghostedBuildings && unit->staticRadarGhost) spring::VectorErase(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u); if (allyTeam != gu->myAllyTeam) @@ -702,4 +702,4 @@ void CUnitDrawerData::PlayerChanged(int playerNum) // force an erase (no-op) followed by an insert UpdateUnitIcon(unit, true, false); } -} \ No newline at end of file +} From e15c58063cfed82f5a9690177277a107fb881331 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 10:57:42 +0100 Subject: [PATCH 09/15] Rename unitDef.leavesRadarGhost, unit.staticRadarGhost to leavesGhost. - Also rename lua methods accordingly. --- rts/Lua/LuaSyncedCtrl.cpp | 18 +++++++++--------- rts/Lua/LuaSyncedCtrl.h | 2 +- rts/Lua/LuaSyncedRead.cpp | 8 ++++---- rts/Lua/LuaSyncedRead.h | 2 +- rts/Lua/LuaUnitDefs.cpp | 2 +- rts/Rendering/Units/UnitDrawer.h | 2 +- rts/Rendering/Units/UnitDrawerData.cpp | 12 ++++++------ rts/Rendering/Units/UnitDrawerData.h | 2 +- rts/Sim/Units/Unit.cpp | 10 +++++----- rts/Sim/Units/Unit.h | 6 +++--- rts/Sim/Units/UnitDef.cpp | 4 ++-- rts/Sim/Units/UnitDef.h | 2 +- 12 files changed, 35 insertions(+), 35 deletions(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index afa8328e0f..81da1b806b 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -182,7 +182,7 @@ bool LuaSyncedCtrl::PushEntries(lua_State* L) REGISTER_LUA_CFUNC(SetUnitStealth); REGISTER_LUA_CFUNC(SetUnitSonarStealth); REGISTER_LUA_CFUNC(SetUnitSeismicSignature); - REGISTER_LUA_CFUNC(SetUnitStaticRadarGhost); + REGISTER_LUA_CFUNC(SetUnitLeavesGhost); REGISTER_LUA_CFUNC(SetUnitAlwaysVisible); REGISTER_LUA_CFUNC(SetUnitUseAirLos); REGISTER_LUA_CFUNC(SetUnitMetalExtraction); @@ -2687,27 +2687,27 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L) } /*** - * @function Spring.SetUnitStaticRadarGhost + * @function Spring.SetUnitLeavesGhost * * Set the radar ghost for the unit to have no drift. - * Only for units where unitDef has leavesRadarGhost enabled. + * Only for units where unitDef has leavesGhost enabled. * * @number unitID - * @bool staticRadarGhost + * @bool leavesGhost * @bool[opt] leaveDeadGhost leave a dead ghost behind if disabling and the unit had a live static ghost. * @treturn nil */ -int LuaSyncedCtrl::SetUnitStaticRadarGhost(lua_State* L) +int LuaSyncedCtrl::SetUnitLeavesGhost(lua_State* L) { CUnit* unit = ParseUnit(L, __func__, 1); if (unit == nullptr) return 0; - bool prevValue = unit->staticRadarGhost; - unit->SetStaticRadarGhost(luaL_checkboolean(L, 2)); - if (prevValue != unit->staticRadarGhost) - unitDrawer->SetUnitStaticRadarGhost(unit, luaL_optboolean(L, 3, false)); + bool prevValue = unit->leavesGhost; + unit->SetLeavesGhost(luaL_checkboolean(L, 2)); + if (prevValue != unit->leavesGhost) + unitDrawer->SetUnitLeavesGhost(unit, luaL_optboolean(L, 3, false)); return 0; } diff --git a/rts/Lua/LuaSyncedCtrl.h b/rts/Lua/LuaSyncedCtrl.h index ab20a0821c..0d51634905 100644 --- a/rts/Lua/LuaSyncedCtrl.h +++ b/rts/Lua/LuaSyncedCtrl.h @@ -90,7 +90,7 @@ class LuaSyncedCtrl static int SetUnitStealth(lua_State* L); static int SetUnitSonarStealth(lua_State* L); static int SetUnitSeismicSignature(lua_State* L); - static int SetUnitStaticRadarGhost(lua_State* L); + static int SetUnitLeavesGhost(lua_State* L); static int SetUnitAlwaysVisible(lua_State* L); static int SetUnitUseAirLos(lua_State* L); static int SetUnitResourcing(lua_State* L); diff --git a/rts/Lua/LuaSyncedRead.cpp b/rts/Lua/LuaSyncedRead.cpp index f6f10934b2..bb035357b5 100644 --- a/rts/Lua/LuaSyncedRead.cpp +++ b/rts/Lua/LuaSyncedRead.cpp @@ -215,7 +215,7 @@ bool LuaSyncedRead::PushEntries(lua_State* L) REGISTER_LUA_CFUNC(GetUnitArmored); REGISTER_LUA_CFUNC(GetUnitIsActive); REGISTER_LUA_CFUNC(GetUnitIsCloaked); - REGISTER_LUA_CFUNC(GetUnitStaticRadarGhost); + REGISTER_LUA_CFUNC(GetUnitLeavesGhost); REGISTER_LUA_CFUNC(GetUnitSelfDTime); REGISTER_LUA_CFUNC(GetUnitStockpile); REGISTER_LUA_CFUNC(GetUnitSensorRadius); @@ -3853,17 +3853,17 @@ int LuaSyncedRead::GetUnitSeismicSignature(lua_State* L) /*** * - * @function Spring.GetUnitStaticRadarGhost + * @function Spring.GetUnitLeavesGhost * @number unitID * @treturn nil|number */ -int LuaSyncedRead::GetUnitStaticRadarGhost(lua_State* L) +int LuaSyncedRead::GetUnitLeavesGhost(lua_State* L) { const CUnit* const unit = ParseAllyUnit(L, __func__, 1); if (unit == nullptr) return 0; - lua_pushboolean(L, unit->staticRadarGhost); + lua_pushboolean(L, unit->leavesGhost); return 1; } diff --git a/rts/Lua/LuaSyncedRead.h b/rts/Lua/LuaSyncedRead.h index cd35faa3ce..c6ab7fc426 100644 --- a/rts/Lua/LuaSyncedRead.h +++ b/rts/Lua/LuaSyncedRead.h @@ -120,7 +120,7 @@ class LuaSyncedRead { static int GetUnitIsActive(lua_State* L); static int GetUnitIsCloaked(lua_State* L); static int GetUnitSeismicSignature(lua_State* L); - static int GetUnitStaticRadarGhost(lua_State* L); + static int GetUnitLeavesGhost(lua_State* L); static int GetUnitSelfDTime(lua_State* L); static int GetUnitStockpile(lua_State* L); static int GetUnitSensorRadius(lua_State* L); diff --git a/rts/Lua/LuaUnitDefs.cpp b/rts/Lua/LuaUnitDefs.cpp index 8d8c9a542b..a873f68f7f 100644 --- a/rts/Lua/LuaUnitDefs.cpp +++ b/rts/Lua/LuaUnitDefs.cpp @@ -727,7 +727,7 @@ ADD_BOOL("canAttackWater", canAttackWater); // CUSTOM ADD_FLOAT("seismicSignature", ud.seismicSignature); ADD_BOOL("stealth", ud.stealth); ADD_BOOL("sonarStealth", ud.sonarStealth); - ADD_BOOL("leavesRadarGhost", ud.leavesRadarGhost); + ADD_BOOL("leavesGhost", ud.leavesGhost); ADD_FLOAT("mass", ud.mass); diff --git a/rts/Rendering/Units/UnitDrawer.h b/rts/Rendering/Units/UnitDrawer.h index 9d48359e7b..8b42efc51a 100644 --- a/rts/Rendering/Units/UnitDrawer.h +++ b/rts/Rendering/Units/UnitDrawer.h @@ -54,7 +54,7 @@ class CUnitDrawer : public CModelDrawerBase static const std::vector& GetUnsortedUnits() { return modelDrawerData->GetUnsortedObjects(); } static void ClearPreviousDrawFlags() { modelDrawerData->ClearPreviousDrawFlags(); } - static void SetUnitStaticRadarGhost(const CUnit* unit, const bool leaveDeadGhost) { modelDrawerData->SetUnitStaticRadarGhost(unit, leaveDeadGhost); } + static void SetUnitLeavesGhost(const CUnit* unit, const bool leaveDeadGhost) { modelDrawerData->SetUnitLeavesGhost(unit, leaveDeadGhost); } public: // DrawUnit* virtual void DrawUnitNoTrans(const CUnit* unit, uint32_t preList, uint32_t postList, bool lodCall, bool noLuaCall) const = 0; diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 1b4fd6de12..1b0a320adc 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -255,7 +255,7 @@ const icon::CIconData* CUnitDrawerData::GetUnitIcon(const CUnit* unit) // use the unit's custom icon if we can currently see it, // or have seen it before and did not lose contact since bool unitVisible = ((losStatus & (LOS_INLOS | LOS_INRADAR)) && ((losStatus & prevMask) == prevMask)); - unitVisible |= gameSetup->ghostedBuildings && unit->staticRadarGhost && (losStatus & LOS_PREVLOS); + unitVisible |= gameSetup->ghostedBuildings && unit->leavesGhost && (losStatus & LOS_PREVLOS); const bool customIcon = (unitVisible || gu->spectatingFullView); if (customIcon) @@ -634,7 +634,7 @@ void CUnitDrawerData::RenderUnitDestroyed(const CUnit* unit) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); - UpdateUnitGhosts(unit, unit->staticRadarGhost); + UpdateUnitGhosts(unit, unit->leavesGhost); DelObject(unit, true); UpdateUnitIcon(unit, false, true); @@ -656,7 +656,7 @@ void CUnitDrawerData::UnitEnteredLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->staticRadarGhost) + if (gameSetup->ghostedBuildings && unit->leavesGhost) spring::VectorErase(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u); if (allyTeam != gu->myAllyTeam) @@ -670,7 +670,7 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->staticRadarGhost) + if (gameSetup->ghostedBuildings && unit->leavesGhost) spring::VectorInsertUnique(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u, true); if (allyTeam != gu->myAllyTeam) @@ -679,9 +679,9 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) UpdateUnitIcon(unit, false, false); } -void CUnitDrawerData::SetUnitStaticRadarGhost(const CUnit* unit, const bool leaveDeadGhost) +void CUnitDrawerData::SetUnitLeavesGhost(const CUnit* unit, const bool leaveDeadGhost) { - if (unit->staticRadarGhost) + if (unit->leavesGhost) return; if (UpdateUnitGhosts(unit, leaveDeadGhost)) diff --git a/rts/Rendering/Units/UnitDrawerData.h b/rts/Rendering/Units/UnitDrawerData.h index 54bb96c560..341466ce39 100644 --- a/rts/Rendering/Units/UnitDrawerData.h +++ b/rts/Rendering/Units/UnitDrawerData.h @@ -61,7 +61,7 @@ class CUnitDrawerData : public CUnitDrawerDataBase { void PlayerChanged(int playerNum) override; bool UpdateUnitGhosts(const CUnit* unit, const bool addNewGhost); - void SetUnitStaticRadarGhost(const CUnit* unit, const bool leaveDeadGhost); + void SetUnitLeavesGhost(const CUnit* unit, const bool leaveDeadGhost); public: class TempDrawUnit { CR_DECLARE_STRUCT(TempDrawUnit) diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index 0497889b30..aed11426aa 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -295,7 +295,7 @@ void CUnit::PreInit(const UnitLoadParams& params) wantCloak |= unitDef->startCloaked; decloakDistance = unitDef->decloakDistance; - staticRadarGhost = unitDef->leavesRadarGhost; + leavesGhost = unitDef->leavesGhost; flankingBonusMode = unitDef->flankingBonusMode; flankingBonusDir = unitDef->flankingBonusDir; @@ -545,9 +545,9 @@ void CUnit::ForcedMove(const float3& newPos) } -void CUnit::SetStaticRadarGhost(bool isStatic) +void CUnit::SetLeavesGhost(bool isStatic) { - staticRadarGhost = isStatic && unitDef->leavesRadarGhost; + leavesGhost = isStatic && unitDef->leavesGhost; } @@ -562,7 +562,7 @@ float3 CUnit::GetErrorVector(int argAllyTeam) const const int atSightMask = losStatus[argAllyTeam]; const int isVisible = 2 * ((atSightMask & LOS_INLOS ) != 0 || teamHandler.Ally(argAllyTeam, allyteam)); // in LOS or allied, no error - const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && staticRadarGhost); // seen ghosted immobiles, no error + const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && leavesGhost); // seen ghosted immobiles, no error const int isOnRadar = 8 * ((atSightMask & LOS_INRADAR) != 0 ); // current radar contact float errorMult = 0.0f; @@ -3020,7 +3020,7 @@ CR_REG_METADATA(CUnit, ( CR_MEMBER(isCloaked), CR_MEMBER(decloakDistance), - CR_MEMBER(staticRadarGhost), + CR_MEMBER(leavesGhost), CR_MEMBER(lastTerrainType), CR_MEMBER(curTerrainType), diff --git a/rts/Sim/Units/Unit.h b/rts/Sim/Units/Unit.h index 33ccb85424..fba9affc84 100644 --- a/rts/Sim/Units/Unit.h +++ b/rts/Sim/Units/Unit.h @@ -190,7 +190,7 @@ class CUnit : public CSolidObject unsigned short CalcLosStatus(int allyTeam); void UpdateLosStatus(int allyTeam); - void SetStaticRadarGhost(bool isStatic); + void SetLeavesGhost(bool isStatic); void UpdateWeapons(); void UpdateWeaponVectors(); @@ -550,8 +550,8 @@ class CUnit : public CSolidObject bool isCloaked = false; // true if the unit currently wants to be cloaked bool wantCloak = false; - // true if unitDef leavesRadarGhost and the unit ghost will have no drift - bool staticRadarGhost = false; + // true if the unit leaves static ghosts + bool leavesGhost = false; // unsynced vars bool noMinimap = false; diff --git a/rts/Sim/Units/UnitDef.cpp b/rts/Sim/Units/UnitDef.cpp index da4095b6f4..cbca6bc33d 100644 --- a/rts/Sim/Units/UnitDef.cpp +++ b/rts/Sim/Units/UnitDef.cpp @@ -106,7 +106,7 @@ UnitDef::UnitDef() , seismicSignature(0.0f) , stealth(false) , sonarStealth(false) - , leavesRadarGhost(false) + , leavesGhost(false) , buildRange3D(false) , buildDistance(16.0f) // 16.0f is the minimum distance between two 1x1 units , buildSpeed(0.0f) @@ -659,7 +659,7 @@ UnitDef::UnitDef(const LuaTable& udTable, const std::string& unitName, int id) if (IsImmobileUnit()) CreateYardMap(udTable.GetString("yardMap", "")); - leavesRadarGhost = udTable.GetBool("leavesRadarGhost", IsBuildingUnit()); + leavesGhost = udTable.GetBool("leavesGhost", IsBuildingUnit()); decalDef.Parse(udTable); diff --git a/rts/Sim/Units/UnitDef.h b/rts/Sim/Units/UnitDef.h index b05a8a9eed..b400c779cf 100644 --- a/rts/Sim/Units/UnitDef.h +++ b/rts/Sim/Units/UnitDef.h @@ -168,7 +168,7 @@ struct UnitDef: public SolidObjectDef float seismicSignature; bool stealth; bool sonarStealth; - bool leavesRadarGhost; + bool leavesGhost; bool buildRange3D; float buildDistance; From d3120daa144dcb84026577ebdf4af7ff9493d0f1 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 11:00:06 +0100 Subject: [PATCH 10/15] Allow unit->leaveGhost to be set also for units who didn't have it at unitdef initially. --- rts/Lua/LuaSyncedCtrl.cpp | 1 - rts/Sim/Units/Unit.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index 81da1b806b..82208d2dd7 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -2690,7 +2690,6 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L) * @function Spring.SetUnitLeavesGhost * * Set the radar ghost for the unit to have no drift. - * Only for units where unitDef has leavesGhost enabled. * * @number unitID * @bool leavesGhost diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index aed11426aa..28b7501d29 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -547,7 +547,7 @@ void CUnit::ForcedMove(const float3& newPos) void CUnit::SetLeavesGhost(bool isStatic) { - leavesGhost = isStatic && unitDef->leavesGhost; + leavesGhost = isStatic; } From a8a0c806efc98c347ca7c77a76d5ad2c375baf42 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 11:02:34 +0100 Subject: [PATCH 11/15] Rename SetLeavesGhost parameter to newLeavesGhost. --- rts/Sim/Units/Unit.cpp | 4 ++-- rts/Sim/Units/Unit.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index 28b7501d29..57a646a525 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -545,9 +545,9 @@ void CUnit::ForcedMove(const float3& newPos) } -void CUnit::SetLeavesGhost(bool isStatic) +void CUnit::SetLeavesGhost(bool newLeavesGhost) { - leavesGhost = isStatic; + leavesGhost = newLeavesGhost; } diff --git a/rts/Sim/Units/Unit.h b/rts/Sim/Units/Unit.h index fba9affc84..19ba427727 100644 --- a/rts/Sim/Units/Unit.h +++ b/rts/Sim/Units/Unit.h @@ -190,7 +190,7 @@ class CUnit : public CSolidObject unsigned short CalcLosStatus(int allyTeam); void UpdateLosStatus(int allyTeam); - void SetLeavesGhost(bool isStatic); + void SetLeavesGhost(bool newLeavesGhost); void UpdateWeapons(); void UpdateWeaponVectors(); From 493cba24b0f768ea07531b3560d7ad211388c568 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 11:03:55 +0100 Subject: [PATCH 12/15] Improve documentation for SetUnitLeavesGhost. --- rts/Lua/LuaSyncedCtrl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index 82208d2dd7..ba9386bfac 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -2689,7 +2689,9 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L) /*** * @function Spring.SetUnitLeavesGhost * - * Set the radar ghost for the unit to have no drift. + * Change the unit leavesGhost attribute. + * + * Controls unit having static radar ghosts. * * @number unitID * @bool leavesGhost From 0ec0141d6853f7014c53431e5766cab9e6c4630e Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 11:06:29 +0100 Subject: [PATCH 13/15] Rename UnitDrawer and UnitDrawerData SetUnitLeavesGhost to UnitLeavesGhostChanged. --- rts/Lua/LuaSyncedCtrl.cpp | 2 +- rts/Rendering/Units/UnitDrawer.h | 2 +- rts/Rendering/Units/UnitDrawerData.cpp | 2 +- rts/Rendering/Units/UnitDrawerData.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index ba9386bfac..88178f4a49 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -2708,7 +2708,7 @@ int LuaSyncedCtrl::SetUnitLeavesGhost(lua_State* L) bool prevValue = unit->leavesGhost; unit->SetLeavesGhost(luaL_checkboolean(L, 2)); if (prevValue != unit->leavesGhost) - unitDrawer->SetUnitLeavesGhost(unit, luaL_optboolean(L, 3, false)); + unitDrawer->UnitLeavesGhostChanged(unit, luaL_optboolean(L, 3, false)); return 0; } diff --git a/rts/Rendering/Units/UnitDrawer.h b/rts/Rendering/Units/UnitDrawer.h index 8b42efc51a..6e080c8f5c 100644 --- a/rts/Rendering/Units/UnitDrawer.h +++ b/rts/Rendering/Units/UnitDrawer.h @@ -54,7 +54,7 @@ class CUnitDrawer : public CModelDrawerBase static const std::vector& GetUnsortedUnits() { return modelDrawerData->GetUnsortedObjects(); } static void ClearPreviousDrawFlags() { modelDrawerData->ClearPreviousDrawFlags(); } - static void SetUnitLeavesGhost(const CUnit* unit, const bool leaveDeadGhost) { modelDrawerData->SetUnitLeavesGhost(unit, leaveDeadGhost); } + static void UnitLeavesGhostChanged(const CUnit* unit, const bool leaveDeadGhost) { modelDrawerData->UnitLeavesGhostChanged(unit, leaveDeadGhost); } public: // DrawUnit* virtual void DrawUnitNoTrans(const CUnit* unit, uint32_t preList, uint32_t postList, bool lodCall, bool noLuaCall) const = 0; diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 1b0a320adc..f76333506b 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -679,7 +679,7 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) UpdateUnitIcon(unit, false, false); } -void CUnitDrawerData::SetUnitLeavesGhost(const CUnit* unit, const bool leaveDeadGhost) +void CUnitDrawerData::UnitLeavesGhostChanged(const CUnit* unit, const bool leaveDeadGhost) { if (unit->leavesGhost) return; diff --git a/rts/Rendering/Units/UnitDrawerData.h b/rts/Rendering/Units/UnitDrawerData.h index 341466ce39..62aa5c84db 100644 --- a/rts/Rendering/Units/UnitDrawerData.h +++ b/rts/Rendering/Units/UnitDrawerData.h @@ -61,7 +61,7 @@ class CUnitDrawerData : public CUnitDrawerDataBase { void PlayerChanged(int playerNum) override; bool UpdateUnitGhosts(const CUnit* unit, const bool addNewGhost); - void SetUnitLeavesGhost(const CUnit* unit, const bool leaveDeadGhost); + void UnitLeavesGhostChanged(const CUnit* unit, const bool leaveDeadGhost); public: class TempDrawUnit { CR_DECLARE_STRUCT(TempDrawUnit) From afd9a077064a4c436263b5a98f623471e9046519 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 11:18:04 +0100 Subject: [PATCH 14/15] Just check gameSetup->ghostedBuildings when setting unit.leavesGhost. --- rts/Lua/LuaSyncedCtrl.cpp | 3 +++ rts/Rendering/Units/UnitDrawerData.cpp | 6 +++--- rts/Sim/Units/Unit.cpp | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index 88178f4a49..138164f857 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -2700,6 +2700,9 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L) */ int LuaSyncedCtrl::SetUnitLeavesGhost(lua_State* L) { + if (!gameSetup->ghostedBuildings) + return 0; + CUnit* unit = ParseUnit(L, __func__, 1); if (unit == nullptr) diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index f76333506b..48fe676de4 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -255,7 +255,7 @@ const icon::CIconData* CUnitDrawerData::GetUnitIcon(const CUnit* unit) // use the unit's custom icon if we can currently see it, // or have seen it before and did not lose contact since bool unitVisible = ((losStatus & (LOS_INLOS | LOS_INRADAR)) && ((losStatus & prevMask) == prevMask)); - unitVisible |= gameSetup->ghostedBuildings && unit->leavesGhost && (losStatus & LOS_PREVLOS); + unitVisible |= unit->leavesGhost && (losStatus & LOS_PREVLOS); const bool customIcon = (unitVisible || gu->spectatingFullView); if (customIcon) @@ -656,7 +656,7 @@ void CUnitDrawerData::UnitEnteredLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->leavesGhost) + if (unit->leavesGhost) spring::VectorErase(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u); if (allyTeam != gu->myAllyTeam) @@ -670,7 +670,7 @@ void CUnitDrawerData::UnitLeftLos(const CUnit* unit, int allyTeam) RECOIL_DETAILED_TRACY_ZONE; CUnit* u = const_cast(unit); //cleanup - if (gameSetup->ghostedBuildings && unit->leavesGhost) + if (unit->leavesGhost) spring::VectorInsertUnique(savedData.liveGhostBuildings[allyTeam][MDL_TYPE(unit)], u, true); if (allyTeam != gu->myAllyTeam) diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index 57a646a525..92f50d12db 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -295,7 +295,7 @@ void CUnit::PreInit(const UnitLoadParams& params) wantCloak |= unitDef->startCloaked; decloakDistance = unitDef->decloakDistance; - leavesGhost = unitDef->leavesGhost; + leavesGhost = gameSetup->ghostedBuildings && unitDef->leavesGhost; flankingBonusMode = unitDef->flankingBonusMode; flankingBonusDir = unitDef->flankingBonusDir; @@ -562,7 +562,7 @@ float3 CUnit::GetErrorVector(int argAllyTeam) const const int atSightMask = losStatus[argAllyTeam]; const int isVisible = 2 * ((atSightMask & LOS_INLOS ) != 0 || teamHandler.Ally(argAllyTeam, allyteam)); // in LOS or allied, no error - const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && leavesGhost); // seen ghosted immobiles, no error + const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && leavesGhost); // seen ghosted immobiles, no error const int isOnRadar = 8 * ((atSightMask & LOS_INRADAR) != 0 ); // current radar contact float errorMult = 0.0f; From f0462069b2b6d1b4dcd2ed63589fbd03a0eb4e56 Mon Sep 17 00:00:00 2001 From: saurtron Date: Sun, 12 Jan 2025 08:50:19 +0100 Subject: [PATCH 15/15] Avoid uneeded check for PREVLOS before clearing it Co-authored-by: sprunk --- rts/Rendering/Units/UnitDrawerData.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rts/Rendering/Units/UnitDrawerData.cpp b/rts/Rendering/Units/UnitDrawerData.cpp index 48fe676de4..bba8622a4d 100644 --- a/rts/Rendering/Units/UnitDrawerData.cpp +++ b/rts/Rendering/Units/UnitDrawerData.cpp @@ -616,9 +616,7 @@ bool CUnitDrawerData::UpdateUnitGhosts(const CUnit* unit, const bool addNewGhost // (the ref-counter saves us come deletion time) savedData.deadGhostBuildings[allyTeam][gsoModel->type].push_back(gso); gso->IncRef(); - // remove prevlos for unit - if (u->losStatus[allyTeam] & LOS_PREVLOS) - u->losStatus[allyTeam] ^= LOS_PREVLOS; + u->losStatus[allyTeam] &= ~LOS_PREVLOS; if (allyTeam == gu->myAllyTeam) addedOwnAllyTeam = true;