/* * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version. * Copyright (C) 2008-2016 TrinityCore * Copyright (C) 2005-2009 MaNGOS */ #ifndef ACORE_NGRID_H #define ACORE_NGRID_H /** NGrid is nothing more than a wrapper of the Grid with an NxN cells */ #include "Grid.h" #include "GridReference.h" #include "Timer.h" #include "Util.h" template < uint32 N, class ACTIVE_OBJECT, class WORLD_OBJECT_TYPES, class GRID_OBJECT_TYPES > class NGrid { public: typedef Grid GridType; NGrid(uint32 id, int32 x, int32 y) : i_gridId(id), i_x(x), i_y(y), i_GridObjectDataLoaded(false) { } GridType& GetGridType(const uint32 x, const uint32 y) { ASSERT(x < N && y < N); return i_cells[x][y]; } [[nodiscard]] GridType const& GetGridType(const uint32 x, const uint32 y) const { ASSERT(x < N && y < N); return i_cells[x][y]; } [[nodiscard]] uint32 GetGridId() const { return i_gridId; } [[nodiscard]] int32 getX() const { return i_x; } [[nodiscard]] int32 getY() const { return i_y; } void link(GridRefManager >* pTo) { i_Reference.link(pTo, this); } [[nodiscard]] bool isGridObjectDataLoaded() const { return i_GridObjectDataLoaded; } void setGridObjectDataLoaded(bool pLoaded) { i_GridObjectDataLoaded = pLoaded; } /* template void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { GetGridType(x, y).AddWorldObject(obj); } template void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { GetGridType(x, y).RemoveWorldObject(obj); } template void AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { GetGridType(x, y).AddGridObject(obj); } template void RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { GetGridType(x, y).RemoveGridObject(obj); } */ // Visit all Grids (cells) in NGrid (grid) template void VisitAllGrids(TypeContainerVisitor >& visitor) { for (uint32 x = 0; x < N; ++x) for (uint32 y = 0; y < N; ++y) GetGridType(x, y).Visit(visitor); } // Visit a single Grid (cell) in NGrid (grid) template void VisitGrid(const uint32 x, const uint32 y, TypeContainerVisitor >& visitor) { GetGridType(x, y).Visit(visitor); } private: uint32 i_gridId; GridReference > i_Reference; int32 i_x; int32 i_y; GridType i_cells[N][N]; bool i_GridObjectDataLoaded; }; #endif