* Remove CellLock class and all cell-level thread locking.
** It was wasting CPU power as cell-level locking is not needed. ** Our multithreading is on map-level, not cell-level. ** CellLock was just a 'proxy' between Cell and CellPair and in some cases carried redundant data. ** Some minor cleanup in Cell::Visit/Map::Visit. --HG-- branch : trunk
This commit is contained in:
+24
-31
@@ -37,18 +37,17 @@ inline Cell::Cell(CellPair const& p)
|
||||
data.Part.reserved = 0;
|
||||
}
|
||||
|
||||
template<class LOCK_TYPE,class T, class CONTAINER>
|
||||
template<class T, class CONTAINER>
|
||||
inline void
|
||||
Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const
|
||||
Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const
|
||||
{
|
||||
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);
|
||||
m.Visit(*this, visitor);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,9 +124,8 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi
|
||||
{
|
||||
CellPair cell_pair(x,y);
|
||||
Cell r_zone(cell_pair);
|
||||
r_zone.data.Part.nocreate = l->data.Part.nocreate;
|
||||
CellLock<LOCK_TYPE> lock(r_zone, cell_pair);
|
||||
m.Visit(lock, visitor);
|
||||
r_zone.data.Part.nocreate = this->data.Part.nocreate;
|
||||
m.Visit(r_zone, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,11 +169,10 @@ inline CellArea Cell::CalculateCellArea(float x, float y, float radius)
|
||||
return CellArea(right, left, upper, lower);
|
||||
}
|
||||
|
||||
template<class LOCK_TYPE, class T, class CONTAINER>
|
||||
template<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
|
||||
Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, float radius, float x_off, float y_off) const
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -184,7 +181,7 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi
|
||||
//maybe it is better to just return when radius <= 0.0f?
|
||||
if (radius <= 0.0f)
|
||||
{
|
||||
m.Visit(l, visitor);
|
||||
m.Visit(*this, visitor);
|
||||
return;
|
||||
}
|
||||
//lets limit the upper value for search radius
|
||||
@@ -196,7 +193,7 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi
|
||||
//if radius fits inside standing cell
|
||||
if (!area)
|
||||
{
|
||||
m.Visit(l, visitor);
|
||||
m.Visit(*this, visitor);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -210,13 +207,13 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi
|
||||
//there are nothing to optimize because SIZE_OF_GRID_CELL is too big...
|
||||
if (((end_cell.x_coord - begin_cell.x_coord) > 4) && ((end_cell.y_coord - begin_cell.y_coord) > 4))
|
||||
{
|
||||
VisitCircle(l, visitor, m, begin_cell, end_cell);
|
||||
VisitCircle(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);
|
||||
m.Visit(*this, visitor);
|
||||
|
||||
// loop the cell range
|
||||
for (uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x)
|
||||
@@ -228,26 +225,25 @@ Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &vi
|
||||
if(cell_pair != standing_cell)
|
||||
{
|
||||
Cell r_zone(cell_pair);
|
||||
r_zone.data.Part.nocreate = l->data.Part.nocreate;
|
||||
CellLock<LOCK_TYPE> lock(r_zone, cell_pair);
|
||||
m.Visit(lock, visitor);
|
||||
r_zone.data.Part.nocreate = this->data.Part.nocreate;
|
||||
m.Visit(r_zone, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class LOCK_TYPE, class T, class CONTAINER>
|
||||
template<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
|
||||
Cell::Visit(const CellPair& l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const WorldObject &obj, float radius) const
|
||||
{
|
||||
//we should increase search radius by object's radius, otherwise
|
||||
//we could have problems with huge creatures, which won't attack nearest players etc
|
||||
Cell::Visit(l, visitor, m, radius + obj.GetObjectSize(), obj.GetPositionX(), obj.GetPositionY());
|
||||
Visit(l, visitor, m, radius + obj.GetObjectSize(), obj.GetPositionX(), obj.GetPositionY());
|
||||
}
|
||||
|
||||
template<class LOCK_TYPE, class T, class CONTAINER>
|
||||
template<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
|
||||
Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const CellPair& begin_cell, const CellPair& end_cell) const
|
||||
{
|
||||
//here is an algorithm for 'filling' circum-squared octagon
|
||||
uint32 x_shift = (uint32)ceilf((end_cell.x_coord - begin_cell.x_coord) * 0.3f - 0.5f);
|
||||
@@ -262,9 +258,8 @@ Cell::VisitCircle(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINE
|
||||
{
|
||||
CellPair cell_pair(x,y);
|
||||
Cell r_zone(cell_pair);
|
||||
r_zone.data.Part.nocreate = l->data.Part.nocreate;
|
||||
CellLock<LOCK_TYPE> lock(r_zone, cell_pair);
|
||||
m.Visit(lock, visitor);
|
||||
r_zone.data.Part.nocreate = this->data.Part.nocreate;
|
||||
m.Visit(r_zone, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,16 +282,14 @@ Cell::VisitCircle(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINE
|
||||
//e.g. filling 2 trapezoids after filling central cell strip...
|
||||
CellPair cell_pair_left(x_start - step, y);
|
||||
Cell r_zone_left(cell_pair_left);
|
||||
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);
|
||||
r_zone_left.data.Part.nocreate = this->data.Part.nocreate;
|
||||
m.Visit(r_zone_left, visitor);
|
||||
|
||||
//right trapezoid cell visit
|
||||
CellPair cell_pair_right(x_end + step, y);
|
||||
Cell r_zone_right(cell_pair_right);
|
||||
r_zone_right.data.Part.nocreate = l->data.Part.nocreate;
|
||||
CellLock<LOCK_TYPE> lock_right(r_zone_right, cell_pair_right);
|
||||
m.Visit(lock_right, visitor);
|
||||
r_zone_right.data.Part.nocreate = this->data.Part.nocreate;
|
||||
m.Visit(r_zone_right, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user