Professional Documents
Culture Documents
Dynamic Tree
Dynamic Tree
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright
information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DynamicTree.h"
#include "BoundingIntervalHierarchyWrapper.h"
#include "GameObjectModel.h"
#include "MapTree.h"
#include "ModelIgnoreFlags.h"
#include "ModelInstance.h"
#include "RegularGrid.h"
#include "Timer.h"
#include "VMapFactory.h"
#include "VMapMgr2.h"
#include "WorldModel.h"
#include <G3D/AABox.h>
#include <G3D/Ray.h>
#include <G3D/Vector3.h>
using VMAP::ModelInstance;
namespace
{
int CHECK_TREE_PERIOD = 200;
}
DynTreeImpl() :
rebalance_timer(CHECK_TREE_PERIOD),
unbalanced_times(0)
{
}
void balance()
{
base::balance();
unbalanced_times = 0;
}
rebalance_timer.Update(difftime);
if (rebalance_timer.Passed())
{
rebalance_timer.Reset(CHECK_TREE_PERIOD);
if (unbalanced_times > 0)
{
balance();
}
}
}
TimeTrackerSmall rebalance_timer;
int unbalanced_times;
};
DynamicMapTree::~DynamicMapTree()
{
delete impl;
}
void DynamicMapTree::balance()
{
impl->balance();
}
struct DynamicTreeIntersectionCallback
{
DynamicTreeIntersectionCallback(uint32 phasemask, VMAP::ModelIgnoreFlags
ignoreFlags) :
_didHit(false), _phaseMask(phasemask), _ignoreFlags(ignoreFlags) { }
private:
bool _didHit;
uint32 _phaseMask;
VMAP::ModelIgnoreFlags _ignoreFlags;
};
struct DynamicTreeAreaInfoCallback
{
DynamicTreeAreaInfoCallback(uint32 phaseMask) : _phaseMask(phaseMask) { }
private:
uint32 _phaseMask;
VMAP::AreaInfo _areaInfo;
};
struct DynamicTreeLocationInfoCallback
{
DynamicTreeLocationInfoCallback(uint32 phaseMask)
: _phaseMask(phaseMask), _hitModel(nullptr) {}
VMAP::LocationInfo& GetLocationInfo()
{
return _locationInfo;
}
GameObjectModel const* GetHitModel() const
{
return _hitModel;
}
private:
uint32 _phaseMask;
VMAP::LocationInfo _locationInfo;
GameObjectModel const* _hitModel;
};
result = true;
}
else
{
resultHit = endPos;
result = false;
}
return result;
}
bool DynamicMapTree::isInLineOfSight(float x1, float y1, float z1, float x2, float
y2, float z2, uint32 phasemask, VMAP::ModelIgnoreFlags ignoreFlags) const
{
G3D::Vector3 v1(x1, y1, z1), v2(x2, y2, z2);
return !callback.didHit();
}
if (callback.didHit())
{
return v.z - maxSearchDist;
}
else
{
return -G3D::finf();
}
}
data.areaInfo.emplace(0,
intersectionCallBack.GetLocationInfo().rootId,
intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags());
}
}