diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-06-06 11:21:01 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-06-06 11:21:01 +0200 |
commit | d2ddcd7b36a93f76f11941e240d2907bdc414e53 (patch) | |
tree | 202a54c01ac1fe667470f304fc92933e0495ea7d /src/server | |
parent | f04cc7a8cb53f0d19b8fd24671333112cf5f3cf8 (diff) |
Core/Grids: Remove unused template parameter from Grid class
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/game/Grids/Dynamic/TypeContainer.h | 9 | ||||
-rw-r--r-- | src/server/game/Grids/Grid.h | 53 | ||||
-rw-r--r-- | src/server/game/Grids/GridDefines.h | 8 | ||||
-rw-r--r-- | src/server/game/Grids/GridLoader.h | 76 | ||||
-rw-r--r-- | src/server/game/Grids/GridStates.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Grids/NGrid.cpp | 4 | ||||
-rw-r--r-- | src/server/game/Grids/NGrid.h | 36 | ||||
-rw-r--r-- | src/server/game/Maps/Map.cpp | 2 |
8 files changed, 57 insertions, 133 deletions
diff --git a/src/server/game/Grids/Dynamic/TypeContainer.h b/src/server/game/Grids/Dynamic/TypeContainer.h index 78ed885d7b7..ff49e047415 100644 --- a/src/server/game/Grids/Dynamic/TypeContainer.h +++ b/src/server/game/Grids/Dynamic/TypeContainer.h @@ -65,14 +65,17 @@ struct TypeListContainer template <typename ObjectType> static constexpr bool TypeExists = std::disjunction_v<std::is_same<ObjectType, Types>...>; + template <typename ObjectType> + using ValueType = typename UnderlyingContainer<ObjectType>::ValueType; + template <typename ObjectType> requires TypeExists<ObjectType> - bool Insert(ObjectType* object) + bool Insert(ValueType<ObjectType> object) { return UnderlyingContainer<ObjectType>::Insert(Data.template FindContainer<ObjectType>(), object); } template <typename ObjectType> requires TypeExists<ObjectType> - bool Remove(ObjectType* object) + bool Remove(ValueType<ObjectType> object) { return UnderlyingContainer<ObjectType>::Remove(Data.template FindContainer<ObjectType>(), object); } @@ -84,7 +87,7 @@ struct TypeListContainer } template <typename ObjectType> requires TypeExists<ObjectType> && requires { typename UnderlyingContainer<ObjectType>::KeyType; } - ObjectType* Find(typename UnderlyingContainer<ObjectType>::KeyType const& key) const + ValueType<ObjectType> Find(typename UnderlyingContainer<ObjectType>::KeyType const& key) const { return UnderlyingContainer<ObjectType>::Find(Data.template FindContainer<ObjectType>(), key); } diff --git a/src/server/game/Grids/Grid.h b/src/server/game/Grids/Grid.h index 6b13b07949b..ac2f3f01a5f 100644 --- a/src/server/game/Grids/Grid.h +++ b/src/server/game/Grids/Grid.h @@ -33,19 +33,13 @@ #include "Errors.h" #include "TypeContainerVisitor.h" -// forward declaration -template<class A, class T, class O> class GridLoader; - template < -class ACTIVE_OBJECT, class WORLD_OBJECT_CONTAINER, class GRID_OBJECT_CONTAINER > class Grid { - // allows the GridLoader to access its internals - template<class A, class T, class O> friend class GridLoader; public: /** destructor to clean up its resources. This includes unloading the @@ -55,7 +49,8 @@ class Grid /** an object of interested enters the grid */ - template<class SPECIFIC_OBJECT> void AddWorldObject(SPECIFIC_OBJECT *obj) + template<class SPECIFIC_OBJECT> + void AddWorldObject(SPECIFIC_OBJECT *obj) { i_objects.template Insert<SPECIFIC_OBJECT>(obj); ASSERT(obj->IsInGrid()); @@ -64,25 +59,14 @@ class Grid /** an object of interested exits the grid */ //Actually an unlink is enough, no need to go through the container - //template<class SPECIFIC_OBJECT> void RemoveWorldObject(SPECIFIC_OBJECT *obj) + //template<class SPECIFIC_OBJECT> + //void RemoveWorldObject(SPECIFIC_OBJECT *obj) //{ // ASSERT(obj->GetGridRef().isValid()); - // i_objects.template remove<SPECIFIC_OBJECT>(obj); + // i_objects.template Remove<SPECIFIC_OBJECT>(obj); // ASSERT(!obj->GetGridRef().isValid()); //} - /** Refreshes/update the grid. This required for remote grids. - */ - //void RefreshGrid(void) { /* TBI */} - - /** Locks a grid. Any object enters must wait until the grid is unlock. - */ - //void LockGrid(void) { /* TBI */ } - - /** Unlocks the grid. - */ - //void UnlockGrid(void) { /* TBI */ } - // Visit grid objects template<class T> void Visit(TypeContainerVisitor<T, GRID_OBJECT_CONTAINER> &visitor) @@ -99,16 +83,16 @@ class Grid /** Returns the number of object within the grid. */ - //unsigned int ActiveObjectsInGrid(void) const { return i_objects.template Count<ACTIVE_OBJECT>(); } template<class T> - uint32 GetWorldObjectCountInGrid() const + std::size_t GetWorldObjectCountInGrid() const { - return uint32(i_objects.template Size<T>()); + return i_objects.template Size<T>(); } /** Inserts a container type object into the grid. */ - template<class SPECIFIC_OBJECT> void AddGridObject(SPECIFIC_OBJECT *obj) + template<class SPECIFIC_OBJECT> + void AddGridObject(SPECIFIC_OBJECT *obj) { i_container.template Insert<SPECIFIC_OBJECT>(obj); ASSERT(obj->IsInGrid()); @@ -116,28 +100,25 @@ class Grid /** Removes a containter type object from the grid */ - //template<class SPECIFIC_OBJECT> void RemoveGridObject(SPECIFIC_OBJECT *obj) + //template<class SPECIFIC_OBJECT> + //void RemoveGridObject(SPECIFIC_OBJECT *obj) //{ // ASSERT(obj->GetGridRef().isValid()); - // i_container.template remove<SPECIFIC_OBJECT>(obj); + // i_container.template Remove<SPECIFIC_OBJECT>(obj); // ASSERT(!obj->GetGridRef().isValid()); //} - /*bool NoWorldObjectInGrid() const + /** Returns the number of container type object within the grid. + */ + template<class T> + std::size_t GetGridObjectCountInGrid() const { - return i_objects.GetElements().isEmpty(); + return i_container.template Size<T>(); } - bool NoGridObjectInGrid() const - { - return i_container.GetElements().isEmpty(); - }*/ private: - GRID_OBJECT_CONTAINER i_container; WORLD_OBJECT_CONTAINER i_objects; - //typedef std::set<void*> ActiveGridObjects; - //ActiveGridObjects m_activeGridObjects; }; #endif diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index 821597bf57c..08b1a6d7cf5 100644 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -91,11 +91,11 @@ extern template struct TypeListContainer<GridRefManagerContainer, Player, Creatu typedef TypeListContainer<GridRefManagerContainer, GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/, AreaTrigger, SceneObject, Conversation> GridTypeMapContainer; typedef TypeListContainer<GridRefManagerContainer, Player, Creature/*pets*/, Corpse/*resurrectable*/, DynamicObject/*farsight target*/> WorldTypeMapContainer; -extern template class Grid<Player, WorldTypeMapContainer, GridTypeMapContainer>; -extern template class NGrid<MAX_NUMBER_OF_CELLS, Player, WorldTypeMapContainer, GridTypeMapContainer>; +extern template class Grid<WorldTypeMapContainer, GridTypeMapContainer>; +extern template class NGrid<MAX_NUMBER_OF_CELLS, WorldTypeMapContainer, GridTypeMapContainer>; -typedef Grid<Player, WorldTypeMapContainer, GridTypeMapContainer> GridType; -typedef NGrid<MAX_NUMBER_OF_CELLS, Player, WorldTypeMapContainer, GridTypeMapContainer> NGridType; +typedef Grid<WorldTypeMapContainer, GridTypeMapContainer> GridType; +typedef NGrid<MAX_NUMBER_OF_CELLS, WorldTypeMapContainer, GridTypeMapContainer> NGridType; template<uint32 LIMIT> struct CoordPair diff --git a/src/server/game/Grids/GridLoader.h b/src/server/game/Grids/GridLoader.h deleted file mode 100644 index 46ac3d446ac..00000000000 --- a/src/server/game/Grids/GridLoader.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef TRINITY_GRIDLOADER_H -#define TRINITY_GRIDLOADER_H - -/** - @class GridLoader - The GridLoader is working in conjuction with the Grid and responsible - for loading and unloading object-types (one or more) when objects - enters a grid. Unloading is scheduled and might be canceled if - an interested object re-enters. GridLoader does not do the actuall - loading and unloading but implements as a template pattern that - delicate its loading and unloading for the actualy loader and unloader. - GridLoader manages the grid (both local and remote). - */ - -//I cannot see why this cannot be replaced by a Grid::Visit -/* -#include "Define.h" -#include "Grid.h" -#include "TypeContainerVisitor.h" - -template -< -class ACTIVE_OBJECT, -class WORLD_OBJECT_TYPES, -class GRID_OBJECT_TYPES -> -class GridLoader -{ - public: - - // Loads the grid - template<class LOADER> - void Load(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, LOADER &loader) - { - grid.LockGrid(); - loader.Load(grid); - grid.UnlockGrid(); - } - - // Stop the grid - template<class STOPER> - void Stop(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, STOPER &stoper) - { - grid.LockGrid(); - stoper.Stop(grid); - grid.UnlockGrid(); - } - - // Unloads the grid - template<class UNLOADER> - void Unload(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, UNLOADER &unloader) - { - grid.LockGrid(); - unloader.Unload(grid); - grid.UnlockGrid(); - } -}; -*/ -#endif diff --git a/src/server/game/Grids/GridStates.cpp b/src/server/game/Grids/GridStates.cpp index c1bccae62a0..fd3ba338ce5 100644 --- a/src/server/game/Grids/GridStates.cpp +++ b/src/server/game/Grids/GridStates.cpp @@ -31,7 +31,7 @@ void ActiveState::Update(Map& map, NGridType& grid, GridInfo& info, uint32 diff) info.UpdateTimeTracker(diff); if (info.getTimeTracker().Passed()) { - if (!grid.GetWorldObjectCountInNGrid<Player>() && !map.ActiveObjectsNearGrid(grid)) + if (!grid.HasWorldObjectsInNGrid<Player>() && !map.ActiveObjectsNearGrid(grid)) { ObjectGridStoper worker; TypeContainerVisitor<ObjectGridStoper, GridTypeMapContainer> visitor(worker); diff --git a/src/server/game/Grids/NGrid.cpp b/src/server/game/Grids/NGrid.cpp index ff6cfc34c60..831c4f938bf 100644 --- a/src/server/game/Grids/NGrid.cpp +++ b/src/server/game/Grids/NGrid.cpp @@ -29,8 +29,8 @@ GridInfo::GridInfo(time_t expiry, bool unload /*= true */) : i_timer(expiry), vi { } -template class Grid<Player, WorldTypeMapContainer, GridTypeMapContainer>; -template class NGrid<MAX_NUMBER_OF_CELLS, Player, WorldTypeMapContainer, GridTypeMapContainer>; +template class Grid<WorldTypeMapContainer, GridTypeMapContainer>; +template class NGrid<MAX_NUMBER_OF_CELLS, WorldTypeMapContainer, GridTypeMapContainer>; template struct TC_GAME_API TypeListContainer<GridRefManagerContainer, GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/, AreaTrigger, SceneObject, Conversation>; template struct TC_GAME_API TypeListContainer<GridRefManagerContainer, Player, Creature/*pets*/, Corpse/*resurrectable*/, DynamicObject/*farsight target*/>; diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h index 2babe75cc88..e9f22057e04 100644 --- a/src/server/game/Grids/NGrid.h +++ b/src/server/game/Grids/NGrid.h @@ -63,14 +63,13 @@ typedef enum template < uint32 N, -class ACTIVE_OBJECT, class WORLD_OBJECT_CONTAINER, class GRID_OBJECT_CONTAINER > class NGrid { public: - typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_CONTAINER, GRID_OBJECT_CONTAINER> GridType; + typedef Grid<WORLD_OBJECT_CONTAINER, GRID_OBJECT_CONTAINER> GridType; NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true) : i_gridId(id), i_GridInfo(GridInfo(expiry, unload)), i_x(x), i_y(y), i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false) @@ -162,29 +161,46 @@ class NGrid GetGridType(x, y).Visit(visitor); } - //This gets the player count in grid - //I disable this to avoid confusion (active object usually means something else) - /* - uint32 GetActiveObjectCountInGrid() const + template<class T> + std::size_t GetWorldObjectCountInNGrid() const { uint32 count = 0; for (uint32 x = 0; x < N; ++x) for (uint32 y = 0; y < N; ++y) - count += i_cells[x][y].ActiveObjectsInGrid(); + count += i_cells[x][y].template GetWorldObjectCountInGrid<T>(); return count; } - */ template<class T> - uint32 GetWorldObjectCountInNGrid() const + std::size_t GetGridObjectCountInNGrid() const { uint32 count = 0; for (uint32 x = 0; x < N; ++x) for (uint32 y = 0; y < N; ++y) - count += i_cells[x][y].template GetWorldObjectCountInGrid<T>(); + count += i_cells[x][y].template GetGridObjectCountInGrid<T>(); return count; } + template<class T> + bool HasWorldObjectsInNGrid() const + { + for (uint32 x = 0; x < N; ++x) + for (uint32 y = 0; y < N; ++y) + if (i_cells[x][y].template GetWorldObjectCountInGrid<T>() != 0) + return true; + return false; + } + + template<class T> + bool HasGridObjectsInNGrid() const + { + for (uint32 x = 0; x < N; ++x) + for (uint32 y = 0; y < N; ++y) + if (i_cells[x][y].template GetGridObjectCountInGrid<T>() != 0) + return true; + return false; + } + private: uint32 i_gridId; GridInfo i_GridInfo; diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 92f0753c2aa..41d19ba4e4c 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -1577,7 +1577,7 @@ bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll) if (!unloadAll) { //pets, possessed creatures (must be active), transport passengers - if (ngrid.GetWorldObjectCountInNGrid<Creature>()) + if (ngrid.HasWorldObjectsInNGrid<Creature>()) return false; if (ActiveObjectsNearGrid(ngrid)) |