diff options
author | Spp <spp@jorge.gr> | 2011-10-18 11:42:40 +0200 |
---|---|---|
committer | Spp <spp@jorge.gr> | 2011-10-18 11:42:40 +0200 |
commit | 805e14a4633d12cdab3f4e2cc5acb1743b6878dc (patch) | |
tree | be919115827989237eea3dedbbd5557f8adfe587 | |
parent | e5fb7f093f0362502af7a855e87c2cbabba60c48 (diff) |
Core/Grid: Replaced ambiguous operator overloads with functions (Makes it clear to read)
-rwxr-xr-x | src/server/game/Grids/Cells/Cell.h | 8 | ||||
-rwxr-xr-x | src/server/game/Grids/Cells/CellImpl.h | 33 | ||||
-rwxr-xr-x | src/server/game/Grids/GridDefines.h | 40 | ||||
-rwxr-xr-x | src/server/game/Grids/NGrid.h | 9 | ||||
-rwxr-xr-x | src/server/game/Maps/Map.cpp | 14 |
5 files changed, 59 insertions, 45 deletions
diff --git a/src/server/game/Grids/Cells/Cell.h b/src/server/game/Grids/Cells/Cell.h index a7fd879358e..56c4d96e427 100755 --- a/src/server/game/Grids/Cells/Cell.h +++ b/src/server/game/Grids/Cells/Cell.h @@ -51,10 +51,10 @@ struct CellArea void ResizeBorders(CellPair& begin_cell, CellPair& end_cell) const { - begin_cell << left_offset; - begin_cell -= lower_offset; - end_cell >> right_offset; - end_cell += upper_offset; + begin_cell.dec_x(left_offset); + begin_cell.dec_y(lower_offset); + end_cell.inc_x(right_offset); + end_cell.inc_y(upper_offset); } int right_offset; diff --git a/src/server/game/Grids/Cells/CellImpl.h b/src/server/game/Grids/Cells/CellImpl.h index d36892ffcb0..77cf6a0b5c0 100755 --- a/src/server/game/Grids/Cells/CellImpl.h +++ b/src/server/game/Grids/Cells/CellImpl.h @@ -50,7 +50,6 @@ Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &v } // set up the cell range based on the district - // the overloaded operators handle range checking CellPair begin_cell = standing_cell; CellPair end_cell = standing_cell; @@ -58,54 +57,54 @@ Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &v { case ALL_DISTRICT: { - begin_cell << 1; begin_cell -= 1; // upper left - end_cell >> 1; end_cell += 1; // lower right + begin_cell.dec_x(1); begin_cell.dec_y(1); // upper left + end_cell.inc_x(1); end_cell.inc_y(1); // lower right break; } case UPPER_LEFT_DISTRICT: { - begin_cell << 1; begin_cell -= 1; // upper left + begin_cell.dec_x(1); begin_cell.dec_y(1); // upper left break; } case UPPER_RIGHT_DISTRICT: { - begin_cell -= 1; // up - end_cell >> 1; // right + begin_cell.dec_y(1); // up + end_cell.inc_x(1); // right break; } case LOWER_LEFT_DISTRICT: { - begin_cell << 1; // left - end_cell += 1; // down + begin_cell.dec_x(1); // left + end_cell.inc_y(1); // down break; } case LOWER_RIGHT_DISTRICT: { - end_cell >> 1; end_cell += 1; // lower right + end_cell.inc_x(1); end_cell.inc_y(1); // lower right break; } case LEFT_DISTRICT: { - begin_cell -= 1; // up - end_cell >> 1; end_cell += 1; // lower right + begin_cell.dec_y(1); // up + end_cell.inc_x(1); end_cell.inc_y(1); // lower right break; } case RIGHT_DISTRICT: { - begin_cell << 1; begin_cell -= 1; // upper left - end_cell += 1; // down + begin_cell.dec_x(1); begin_cell.dec_y(1); // upper left + end_cell.inc_y(1); // down break; } case UPPER_DISTRICT: { - begin_cell << 1; begin_cell -= 1; // upper left - end_cell >> 1; // right + begin_cell.dec_x(1); begin_cell.dec_y(1); // upper left + end_cell.inc_x(1); // right break; } case LOWER_DISTRICT: { - begin_cell << 1; // left - end_cell >> 1; end_cell += 1; // lower right + begin_cell.dec_x(1); // left + end_cell.inc_x(1); end_cell.inc_y(1); // lower right break; } default: diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index 66eabf77400..0bd5a2db71c 100755 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -74,18 +74,24 @@ typedef TypeMapContainer<AllWorldObjectTypes> WorldTypeMapContainer; template<const unsigned int LIMIT> struct CoordPair { - CoordPair(uint32 x=0, uint32 y=0) : x_coord(x), y_coord(y) {} - CoordPair(const CoordPair<LIMIT> &obj) : x_coord(obj.x_coord), y_coord(obj.y_coord) {} - bool operator == (const CoordPair<LIMIT> &obj) const { return (obj.x_coord == x_coord && obj.y_coord == y_coord); } - bool operator != (const CoordPair<LIMIT> &obj) const { return !operator == (obj); } - CoordPair<LIMIT>& operator=(const CoordPair<LIMIT> &obj) + CoordPair(uint32 x=0, uint32 y=0) + : x_coord(x) + , y_coord(y) + {} + + CoordPair(const CoordPair<LIMIT> &obj) + : x_coord(obj.x_coord) + , y_coord(obj.y_coord) + {} + + CoordPair<LIMIT> & operator=(const CoordPair<LIMIT> &obj) { x_coord = obj.x_coord; y_coord = obj.y_coord; return *this; } - void operator<<(const uint32 val) + void dec_x(uint32 val) { if (x_coord > val) x_coord -= val; @@ -93,15 +99,15 @@ struct CoordPair x_coord = 0; } - void operator>>(const uint32 val) + void inc_x(uint32 val) { - if (x_coord+val < LIMIT) + if (x_coord + val < LIMIT) x_coord += val; else x_coord = LIMIT - 1; } - void operator-=(const uint32 val) + void dec_y(uint32 val) { if (y_coord > val) y_coord -= val; @@ -109,9 +115,9 @@ struct CoordPair y_coord = 0; } - void operator+=(const uint32 val) + void inc_y(uint32 val) { - if (y_coord+val < LIMIT) + if (y_coord + val < LIMIT) y_coord += val; else y_coord = LIMIT - 1; @@ -121,6 +127,18 @@ struct CoordPair uint32 y_coord; }; +template<const unsigned int LIMIT> +bool operator==(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2) +{ + return (p1.x_coord == p2.x_coord && p1.y_coord == p2.y_coord); +} + +template<const unsigned int LIMIT> +bool operator!=(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2) +{ + return !(p1 == p2); +} + typedef CoordPair<MAX_NUMBER_OF_GRIDS> GridPair; typedef CoordPair<TOTAL_NUMBER_OF_CELLS_PER_MAP> CellPair; diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h index cd2345e439d..4d087d5a03f 100755 --- a/src/server/game/Grids/NGrid.h +++ b/src/server/game/Grids/NGrid.h @@ -87,15 +87,13 @@ class NGrid const GridType& operator()(unsigned short x, unsigned short y) const { - ASSERT(x < N); - ASSERT(y < N); + ASSERT(x < N && y < N); return i_cells[x][y]; } GridType& operator()(unsigned short x, unsigned short y) { - ASSERT(x < N); - ASSERT(y < N); + ASSERT(x < N && y < N); return i_cells[x][y]; } @@ -168,8 +166,7 @@ class NGrid GridType& getGridType(const uint32 x, const uint32 y) { - ASSERT(x < N); - ASSERT(y < N); + ASSERT(x < N && y < N); return i_cells[x][y]; } diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 89049f39127..d40b826709e 100755 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -815,7 +815,7 @@ void Map::AddCreatureToMoveList(Creature* c, float x, float y, float z, float an if (_creatureToMoveLock) //can this happen? return; - if(c->_moveState == CREATURE_CELL_MOVE_NONE) + if (c->_moveState == CREATURE_CELL_MOVE_NONE) _creaturesToMove.push_back(c); c->SetNewCellPosition(x, y, z, ang); } @@ -825,7 +825,7 @@ void Map::RemoveCreatureFromMoveList(Creature* c) if (_creatureToMoveLock) //can this happen? return; - if(c->_moveState == CREATURE_CELL_MOVE_ACTIVE) + if (c->_moveState == CREATURE_CELL_MOVE_ACTIVE) c->_moveState = CREATURE_CELL_MOVE_INACTIVE; } @@ -952,7 +952,7 @@ bool Map::CreatureRespawnRelocation(Creature* c, bool diffGridOnly) Cell resp_cell(resp_val); //creature will be unloaded with grid - if(diffGridOnly && !c->GetCurrentCell().DiffGrid(resp_cell)) + if (diffGridOnly && !c->GetCurrentCell().DiffGrid(resp_cell)) return true; c->CombatStop(); @@ -2142,10 +2142,10 @@ bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const float viewDist = GetVisibilityRange(); int cell_range = (int)ceilf(viewDist / SIZE_OF_GRID_CELL) + 1; - cell_min << cell_range; - cell_min -= cell_range; - cell_max >> cell_range; - cell_max += cell_range; + cell_min.dec_x(cell_range); + cell_min.dec_y(cell_range); + cell_max.inc_x(cell_range); + cell_max.inc_y(cell_range); for (MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) { |