Core/Grids: Remove unused template parameter from Grid class

This commit is contained in:
Shauren
2025-06-06 11:21:01 +02:00
parent f04cc7a8cb
commit d2ddcd7b36
8 changed files with 63 additions and 139 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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*/>;

View File

@@ -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,21 +161,8 @@ 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
{
uint32 count = 0;
for (uint32 x = 0; x < N; ++x)
for (uint32 y = 0; y < N; ++y)
count += i_cells[x][y].ActiveObjectsInGrid();
return count;
}
*/
template<class T>
uint32 GetWorldObjectCountInNGrid() const
std::size_t GetWorldObjectCountInNGrid() const
{
uint32 count = 0;
for (uint32 x = 0; x < N; ++x)
@@ -185,6 +171,36 @@ class NGrid
return count;
}
template<class T>
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 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;

View File

@@ -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))