mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-30 17:13:47 +00:00
feat(Core/Grids): Implement visibility notifier (#15919)
* Cherry-picked from TrinityCore (unable to find author)
This commit is contained in:
@@ -26,6 +26,42 @@
|
||||
#include "Timer.h"
|
||||
#include "Util.h"
|
||||
|
||||
#define DEFAULT_VISIBILITY_NOTIFY_PERIOD 1000
|
||||
|
||||
class AC_GAME_API GridInfo
|
||||
{
|
||||
public:
|
||||
GridInfo();
|
||||
GridInfo(std::chrono::seconds expiry, bool unload = true);
|
||||
TimeTracker const& getTimeTracker() const { return i_timer; }
|
||||
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock; }
|
||||
void setUnloadExplicitLock(bool on) { i_unloadExplicitLock = on; }
|
||||
void setUnloadReferenceLock(bool on) { i_unloadReferenceLock = on; }
|
||||
void incUnloadActiveLock() { ++i_unloadActiveLockCount; }
|
||||
void decUnloadActiveLock() { if (i_unloadActiveLockCount) --i_unloadActiveLockCount; }
|
||||
|
||||
void setTimer(TimeTracker const& pTimer) { i_timer = pTimer; }
|
||||
void ResetTimeTracker(time_t interval) { i_timer.Reset(interval); }
|
||||
void UpdateTimeTracker(time_t diff) { i_timer.Update(diff); }
|
||||
PeriodicTimer& getRelocationTimer() { return vis_Update; }
|
||||
private:
|
||||
TimeTracker i_timer;
|
||||
PeriodicTimer vis_Update;
|
||||
|
||||
uint16 i_unloadActiveLockCount : 16; // lock from active object spawn points (prevent clone loading)
|
||||
bool i_unloadExplicitLock : 1; // explicit manual lock or config setting
|
||||
bool i_unloadReferenceLock : 1; // lock from instance map copy
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRID_STATE_INVALID = 0,
|
||||
GRID_STATE_ACTIVE = 1,
|
||||
GRID_STATE_IDLE = 2,
|
||||
GRID_STATE_REMOVAL = 3,
|
||||
MAX_GRID_STATE = 4
|
||||
} grid_state_t;
|
||||
|
||||
template
|
||||
<
|
||||
uint32 N,
|
||||
@@ -37,10 +73,10 @@ class NGrid
|
||||
{
|
||||
public:
|
||||
typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> GridType;
|
||||
NGrid(uint32 id, int32 x, int32 y)
|
||||
: i_gridId(id), i_x(x), i_y(y), i_GridObjectDataLoaded(false)
|
||||
{
|
||||
}
|
||||
NGrid(uint32 id, int32 x, int32 y, std::chrono::seconds 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)
|
||||
{ }
|
||||
|
||||
GridType& GetGridType(const uint32 x, const uint32 y)
|
||||
{
|
||||
@@ -55,6 +91,9 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]] uint32 GetGridId() const { return i_gridId; }
|
||||
void SetGridId(uint32 id) { i_gridId = id; }
|
||||
[[nodiscard]] grid_state_t GetGridState() const { return i_cellstate; }
|
||||
void SetGridState(grid_state_t s) { i_cellstate = s; }
|
||||
[[nodiscard]] int32 getX() const { return i_x; }
|
||||
[[nodiscard]] int32 getY() const { return i_y; }
|
||||
|
||||
@@ -65,6 +104,16 @@ public:
|
||||
[[nodiscard]] bool isGridObjectDataLoaded() const { return i_GridObjectDataLoaded; }
|
||||
void setGridObjectDataLoaded(bool pLoaded) { i_GridObjectDataLoaded = pLoaded; }
|
||||
|
||||
GridInfo* getGridInfoRef() { return &i_GridInfo; }
|
||||
TimeTracker const& getTimeTracker() const { return i_GridInfo.getTimeTracker(); }
|
||||
bool getUnloadLock() const { return i_GridInfo.getUnloadLock(); }
|
||||
void setUnloadExplicitLock(bool on) { i_GridInfo.setUnloadExplicitLock(on); }
|
||||
void setUnloadReferenceLock(bool on) { i_GridInfo.setUnloadReferenceLock(on); }
|
||||
void incUnloadActiveLock() { i_GridInfo.incUnloadActiveLock(); }
|
||||
void decUnloadActiveLock() { i_GridInfo.decUnloadActiveLock(); }
|
||||
void ResetTimeTracker(std::chrono::seconds interval) { i_GridInfo.ResetTimeTracker(interval.count()); }
|
||||
void UpdateTimeTracker(std::chrono::seconds diff) { i_GridInfo.UpdateTimeTracker(diff.count()); }
|
||||
|
||||
/*
|
||||
template<class SPECIFIC_OBJECT> void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
@@ -103,11 +152,23 @@ public:
|
||||
GetGridType(x, y).Visit(visitor);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
uint32 GetWorldObjectCountInNGrid() 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>();
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 i_gridId;
|
||||
GridInfo i_GridInfo;
|
||||
GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> > i_Reference;
|
||||
int32 i_x;
|
||||
int32 i_y;
|
||||
grid_state_t i_cellstate;
|
||||
GridType i_cells[N][N];
|
||||
bool i_GridObjectDataLoaded;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user