diff options
author | maximius <none@none> | 2009-10-17 15:35:07 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:35:07 -0700 |
commit | 26b5e033ffde3d161382fc9addbfa99738379641 (patch) | |
tree | a344f369ca32945f787a02dee35c3dbe342bed7e /src/game/CellImpl.h | |
parent | f21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff) |
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget
--HG--
branch : trunk
Diffstat (limited to 'src/game/CellImpl.h')
-rw-r--r-- | src/game/CellImpl.h | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/src/game/CellImpl.h b/src/game/CellImpl.h index ff2b0343c69..659ffd48eb6 100644 --- a/src/game/CellImpl.h +++ b/src/game/CellImpl.h @@ -17,16 +17,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #ifndef TRINITY_CELLIMPL_H #define TRINITY_CELLIMPL_H - #include <cmath> - #include "Cell.h" #include "Map.h" #include "Object.h" - inline Cell::Cell(CellPair const& p) { data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS; @@ -36,7 +32,6 @@ inline Cell::Cell(CellPair const& p) data.Part.nocreate = 0; data.Part.reserved = 0; } - template<class LOCK_TYPE,class T, class CONTAINER> inline void Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const @@ -44,19 +39,16 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi const CellPair &standing_cell = l.i_cellPair; if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) return; - uint16 district = (District)this->data.Part.reserved; if(district == CENTER_DISTRICT) { m.Visit(l, visitor); return; } - // 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; - switch( district ) { case ALL_DISTRICT: @@ -117,7 +109,6 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi break; } } - // loop the cell range for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++) { @@ -131,7 +122,6 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi } } } - template<class LOCK_TYPE,class T, class CONTAINER> inline void Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, float radius, float x_off, float y_off) const @@ -139,9 +129,7 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi const CellPair &standing_cell = l.i_cellPair; if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) return; - int left = 0, right = 0, upper = 0, lower = 0; - // Origin = (CENTER_GRID_CELL_OFFSET, CENTER_GRID_CELL_OFFSET) if(CENTER_GRID_CELL_OFFSET - x_off < radius) ++right; @@ -151,21 +139,17 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi ++upper; if(CENTER_GRID_CELL_OFFSET + y_off < radius) ++lower; - if(!left && !right && !upper && !lower) { m.Visit(l, visitor); return; } - CellPair begin_cell = standing_cell; CellPair end_cell = standing_cell; - begin_cell << left; //note: need change << if left > 1 begin_cell -= lower; end_cell >> right; end_cell += upper; - // loop the cell range for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++) { @@ -179,20 +163,16 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi } } } - inline int CellHelper(const float radius) { if(radius < 1.0f) return 0; - return (int)ceilf(radius/SIZE_OF_GRID_CELL); } - inline CellArea Cell::CalculateCellArea(const WorldObject &obj, float radius) { if(radius <= 0.0f) return CellArea(); - //we should increase search radius by object's radius, otherwise //we could have problems with huge creatures, which won't attack nearest players etc radius += obj.GetObjectSize(); @@ -200,23 +180,18 @@ inline CellArea Cell::CalculateCellArea(const WorldObject &obj, float radius) //TODO: add more correct/generic method for this task const float x_offset = (obj.GetPositionX() - CENTER_GRID_CELL_OFFSET)/SIZE_OF_GRID_CELL; const float y_offset = (obj.GetPositionY() - CENTER_GRID_CELL_OFFSET)/SIZE_OF_GRID_CELL; - const float x_val = floor(x_offset + CENTER_GRID_CELL_ID + 0.5f); const float y_val = floor(y_offset + CENTER_GRID_CELL_ID + 0.5f); - const float x_off = (x_offset - x_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; const float y_off = (y_offset - y_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; - const float tmp_diff = radius - CENTER_GRID_CELL_OFFSET; //lets calculate upper/lower/right/left corners for cell search int right = CellHelper(tmp_diff + x_off); int left = CellHelper(tmp_diff - x_off); int upper = CellHelper(tmp_diff + y_off); int lower = CellHelper(tmp_diff - y_off); - return CellArea(right, left, upper, lower); } - template<class LOCK_TYPE, class T, class CONTAINER> inline void Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const WorldObject &obj, float radius) const @@ -224,7 +199,6 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi const CellPair &standing_cell = l.i_cellPair; if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) return; - //no jokes here... Actually placing ASSERT() here was good idea, but //we had some problems with DynamicObjects, which pass radius = 0.0f (DB issue?) //maybe it is better to just return when radius <= 0.0f? @@ -236,7 +210,6 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi //lets limit the upper value for search radius if(radius > 333.0f) radius = 333.0f; - //lets calculate object coord offsets from cell borders. CellArea area = Cell::CalculateCellArea(obj, radius); //if radius fits inside standing cell @@ -245,10 +218,8 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi m.Visit(l, visitor); return; } - CellPair begin_cell = standing_cell; CellPair end_cell = standing_cell; - area.ResizeBorders(begin_cell, end_cell); //visit all cells, found in CalculateCellArea() //if radius is known to reach cell area more than 4x4 then we should call optimized VisitCircle @@ -259,11 +230,9 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi VisitCircle(l, visitor, m, begin_cell, end_cell); return; } - //ALWAYS visit standing cell first!!! Since we deal with small radiuses //it is very essential to call visitor for standing cell firstly... m.Visit(l, visitor); - // loop the cell range for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++) { @@ -281,7 +250,6 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi } } } - template<class LOCK_TYPE, class T, class CONTAINER> inline void Cell::VisitCircle(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const CellPair& begin_cell, const CellPair& end_cell) const @@ -291,7 +259,6 @@ Cell::VisitCircle(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINE //lets calculate x_start/x_end coords for central strip... const uint32 x_start = begin_cell.x_coord + x_shift; const uint32 x_end = end_cell.x_coord - x_shift; - //visit central strip with constant width... for(uint32 x = x_start; x <= x_end; ++x) { @@ -304,12 +271,10 @@ Cell::VisitCircle(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINE m.Visit(lock, visitor); } } - //if x_shift == 0 then we have too small cell area, which were already //visited at previous step, so just return from procedure... if(x_shift == 0) return; - uint32 y_start = end_cell.y_coord; uint32 y_end = begin_cell.y_coord; //now we are visiting borders of an octagon... @@ -327,7 +292,6 @@ Cell::VisitCircle(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINE r_zone_left.data.Part.nocreate = l->data.Part.nocreate; CellLock<LOCK_TYPE> lock_left(r_zone_left, cell_pair_left); m.Visit(lock_left, visitor); - //right trapezoid cell visit CellPair cell_pair_right(x_end + step, y); Cell r_zone_right(cell_pair_right); |