mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Vmaps: Fixed getting map height near large gameobjects like LK platform
Updates #19865
(cherry picked from commit cfb0f9fb19)
This commit is contained in:
@@ -91,7 +91,7 @@ struct DynTreeImpl : public ParentTree/*, public Intersectable*/
|
||||
|
||||
void update(uint32 difftime)
|
||||
{
|
||||
if (!size())
|
||||
if (empty())
|
||||
return;
|
||||
|
||||
rebalance_timer.Update(difftime);
|
||||
@@ -134,11 +134,6 @@ void DynamicMapTree::balance()
|
||||
impl->balance();
|
||||
}
|
||||
|
||||
int DynamicMapTree::size() const
|
||||
{
|
||||
return impl->size();
|
||||
}
|
||||
|
||||
void DynamicMapTree::update(uint32 t_diff)
|
||||
{
|
||||
impl->update(t_diff);
|
||||
|
||||
@@ -50,7 +50,6 @@ public:
|
||||
void insert(const GameObjectModel&);
|
||||
void remove(const GameObjectModel&);
|
||||
bool contains(const GameObjectModel&) const;
|
||||
int size() const;
|
||||
|
||||
void balance();
|
||||
void update(uint32 diff);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#ifndef _REGULAR_GRID_H
|
||||
#define _REGULAR_GRID_H
|
||||
|
||||
|
||||
#include "Errors.h"
|
||||
#include "IteratorPair.h"
|
||||
#include <G3D/Ray.h>
|
||||
#include <G3D/Table.h>
|
||||
#include <G3D/BoundsTrait.h>
|
||||
#include <G3D/PositionTrait.h>
|
||||
|
||||
#include "Errors.h"
|
||||
#include <unordered_map>
|
||||
|
||||
template<class Node>
|
||||
struct NodeCreator{
|
||||
@@ -17,7 +16,7 @@ struct NodeCreator{
|
||||
template<class T,
|
||||
class Node,
|
||||
class NodeCreatorFunc = NodeCreator<Node>,
|
||||
/*class BoundsFunc = BoundsTrait<T>,*/
|
||||
class BoundsFunc = BoundsTrait<T>,
|
||||
class PositionFunc = PositionTrait<T>
|
||||
>
|
||||
class TC_COMMON_API RegularGrid2D
|
||||
@@ -31,16 +30,18 @@ public:
|
||||
#define HGRID_MAP_SIZE (533.33333f * 64.f) // shouldn't be changed
|
||||
#define CELL_SIZE float(HGRID_MAP_SIZE/(float)CELL_NUMBER)
|
||||
|
||||
typedef G3D::Table<const T*, Node*> MemberTable;
|
||||
typedef std::unordered_multimap<const T*, Node*> MemberTable;
|
||||
|
||||
MemberTable memberTable;
|
||||
Node* nodes[CELL_NUMBER][CELL_NUMBER];
|
||||
|
||||
RegularGrid2D(){
|
||||
RegularGrid2D()
|
||||
{
|
||||
memset(nodes, 0, sizeof(nodes));
|
||||
}
|
||||
|
||||
~RegularGrid2D(){
|
||||
~RegularGrid2D()
|
||||
{
|
||||
for (int x = 0; x < CELL_NUMBER; ++x)
|
||||
for (int y = 0; y < CELL_NUMBER; ++y)
|
||||
delete nodes[x][y];
|
||||
@@ -48,18 +49,27 @@ public:
|
||||
|
||||
void insert(const T& value)
|
||||
{
|
||||
G3D::Vector3 pos;
|
||||
PositionFunc::getPosition(value, pos);
|
||||
Node& node = getGridFor(pos.x, pos.y);
|
||||
node.insert(value);
|
||||
memberTable.set(&value, &node);
|
||||
G3D::AABox bounds;
|
||||
BoundsFunc::getBounds(value, bounds);
|
||||
Cell low = Cell::ComputeCell(bounds.low().x, bounds.low().y);
|
||||
Cell high = Cell::ComputeCell(bounds.high().x, bounds.high().y);
|
||||
for (int x = low.x; x <= high.x; ++x)
|
||||
{
|
||||
for (int y = low.y; y <= high.y; ++y)
|
||||
{
|
||||
Node& node = getGrid(x, y);
|
||||
node.insert(value);
|
||||
memberTable.insert(MemberTable::value_type(&value, &node));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remove(const T& value)
|
||||
{
|
||||
memberTable[&value]->remove(value);
|
||||
for (MemberTable::value_type& p : Trinity::Containers::MapEqualRange(memberTable, &value))
|
||||
p.second->remove(value);
|
||||
// Remove the member
|
||||
memberTable.remove(&value);
|
||||
memberTable.erase(&value);
|
||||
}
|
||||
|
||||
void balance()
|
||||
@@ -70,8 +80,8 @@ public:
|
||||
n->balance();
|
||||
}
|
||||
|
||||
bool contains(const T& value) const { return memberTable.containsKey(&value); }
|
||||
int size() const { return uint32(memberTable.size()); }
|
||||
bool contains(const T& value) const { return memberTable.count(&value) > 0; }
|
||||
bool empty() const { return memberTable.empty(); }
|
||||
|
||||
struct Cell
|
||||
{
|
||||
@@ -87,13 +97,6 @@ public:
|
||||
bool isValid() const { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER;}
|
||||
};
|
||||
|
||||
|
||||
Node& getGridFor(float fx, float fy)
|
||||
{
|
||||
Cell c = Cell::ComputeCell(fx, fy);
|
||||
return getGrid(c.x, c.y);
|
||||
}
|
||||
|
||||
Node& getGrid(int x, int y)
|
||||
{
|
||||
ASSERT(x < CELL_NUMBER && y < CELL_NUMBER);
|
||||
|
||||
Reference in New Issue
Block a user