From 902048134cf75a3f2b1ab08db41c81b8240196b5 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 3 May 2024 03:22:23 -0400 Subject: [PATCH] ODR protection for solar system states. --- sc2/src/uqm/state-modern.cpp | 88 ++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/sc2/src/uqm/state-modern.cpp b/sc2/src/uqm/state-modern.cpp index 3404282bb..1f73f4cac 100644 --- a/sc2/src/uqm/state-modern.cpp +++ b/sc2/src/uqm/state-modern.cpp @@ -13,60 +13,62 @@ #include #include - -struct Coord +namespace { - int x; - int y; + struct Coord + { + int x; + int y; - std::strong_ordering operator <=> ( const Coord & ) const= default; -}; + std::strong_ordering operator <=> ( const Coord & ) const= default; + }; -struct WorldState -{ - DWORD ScanRetrieveMask[NUM_SCAN_TYPES]; -}; + struct WorldState + { + DWORD ScanRetrieveMask[NUM_SCAN_TYPES]; + }; -struct WorldDescriptor -{ - int planetNumber; - int moonNumber; // -1 is world itself. + struct WorldDescriptor + { + int planetNumber; + int moonNumber; // -1 is world itself. - std::strong_ordering operator <=> ( const WorldDescriptor & ) const= default; -}; + std::strong_ordering operator <=> ( const WorldDescriptor & ) const= default; + }; -using SolarSystemTable= std::map< WorldDescriptor, WorldState >; -using GalaxyTable= std::map< Coord, SolarSystemTable >; + using SolarSystemTable= std::map< WorldDescriptor, WorldState >; + using GalaxyTable= std::map< Coord, SolarSystemTable >; -static auto & -galaxy() -{ - static GalaxyTable table; - return table; -} + auto & + galaxy() + { + static GalaxyTable table; + return table; + } -static auto -getCurrentCoord() -{ - const auto &star= *CurStarDescPtr; - const Coord pos{ .x{ star.star_pt.x }, .y{ star.star_pt.y } }; - return pos; -} + auto + getCurrentCoord() + { + const auto &star= *CurStarDescPtr; + const Coord pos{ .x{ star.star_pt.x }, .y{ star.star_pt.y } }; + return pos; + } -static auto & -getCurrentWorldMasks() -{ - const Coord pos= getCurrentCoord(); + auto & + getCurrentWorldMasks() + { + const Coord pos= getCurrentCoord(); - const int planet_index = (pSolarSysState->pBaseDesc->pPrevDesc - - pSolarSysState->PlanetDesc); - const int moon_index= (pSolarSysState->pOrbitalDesc->pPrevDesc - == pSolarSysState->SunDesc) - ? -1 - : (pSolarSysState->pOrbitalDesc - - pSolarSysState->MoonDesc); + const int planet_index = (pSolarSysState->pBaseDesc->pPrevDesc + - pSolarSysState->PlanetDesc); + const int moon_index= (pSolarSysState->pOrbitalDesc->pPrevDesc + == pSolarSysState->SunDesc) + ? -1 + : (pSolarSysState->pOrbitalDesc + - pSolarSysState->MoonDesc); - return galaxy()[ pos ][ { planet_index, moon_index } ].ScanRetrieveMask; + return galaxy()[ pos ][ { planet_index, moon_index } ].ScanRetrieveMask; + } } extern "C"