diff options
author | Spp <spp@jorge.gr> | 2012-02-23 13:06:35 +0100 |
---|---|---|
committer | Spp <spp@jorge.gr> | 2012-02-23 13:06:35 +0100 |
commit | 5cff9e071640bc47688b71bb264edd8267ba77c3 (patch) | |
tree | c599d12dfb7870d7c34a07490a930b3102c3d8ac /src/server/collision/BoundingIntervalHierarchyWrapper.h | |
parent | f0ca875a216eaab3d213feae8ba75c07795c9304 (diff) | |
parent | 9219625243bc9f63e5a152e6cda1043cfaade201 (diff) |
Merge branch 'master' into 4.x
Conflicts:
sql/base/auth_database.sql
src/server/authserver/Server/AuthSocket.cpp
src/server/game/AI/CoreAI/CombatAI.cpp
src/server/game/AuctionHouse/AuctionHouseMgr.cpp
src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp
src/server/game/DataStores/DBCStructure.h
src/server/game/DataStores/DBCfmt.h
src/server/game/Entities/Unit/Unit.cpp
src/server/game/Entities/Vehicle/Vehicle.cpp
src/server/game/Globals/ObjectMgr.cpp
src/server/game/Globals/ObjectMgr.h
src/server/game/Handlers/AuctionHouseHandler.cpp
src/server/game/Miscellaneous/SharedDefines.h
src/server/game/Movement/MotionMaster.cpp
src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
src/server/game/Quests/QuestDef.cpp
src/server/game/Server/Protocol/Opcodes.cpp
src/server/game/Server/WorldSocket.cpp
src/server/game/Spells/Spell.cpp
src/server/game/Spells/SpellEffects.cpp
src/server/game/Spells/SpellInfo.cpp
src/server/scripts/Outland/HellfireCitadel/MagtheridonsLair/boss_magtheridon.cpp
src/server/scripts/Spells/spell_quest.cpp
src/server/shared/Logging/Log.h
src/server/worldserver/worldserver.conf.dist
src/tools/vmap3_extractor/model.h
src/tools/vmap4_extractor/CMakeLists.txt
src/tools/vmap4_extractor/dbcfile.cpp
src/tools/vmap4_extractor/dbcfile.h
src/tools/vmap4_extractor/loadlib/loadlib.h
Diffstat (limited to 'src/server/collision/BoundingIntervalHierarchyWrapper.h')
-rw-r--r-- | src/server/collision/BoundingIntervalHierarchyWrapper.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/server/collision/BoundingIntervalHierarchyWrapper.h b/src/server/collision/BoundingIntervalHierarchyWrapper.h new file mode 100644 index 00000000000..e2252ca60c8 --- /dev/null +++ b/src/server/collision/BoundingIntervalHierarchyWrapper.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 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 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/>. + */ + +#ifndef _BIH_WRAP +#define _BIH_WRAP + +#include "G3D/Table.h" +#include "G3D/Array.h" +#include "G3D/Set.h" +#include "BoundingIntervalHierarchy.h" + + +template<class T, class BoundsFunc = BoundsTrait<T> > +class BIHWrap +{ + template<class RayCallback> + struct MDLCallback + { + const T* const* objects; + RayCallback& _callback; + + MDLCallback(RayCallback& callback, const T* const* objects_array ) : objects(objects_array), _callback(callback) {} + + bool operator() (const Ray& ray, uint32 Idx, float& MaxDist, bool /*stopAtFirst*/) + { + if (const T* obj = objects[Idx]) + return _callback(ray, *obj, MaxDist/*, stopAtFirst*/); + return false; + } + + void operator() (const Vector3& p, uint32 Idx) + { + if (const T* obj = objects[Idx]) + _callback(p, *obj); + } + }; + + typedef G3D::Array<const T*> ObjArray; + + BIH m_tree; + ObjArray m_objects; + G3D::Table<const T*, uint32> m_obj2Idx; + G3D::Set<const T*> m_objects_to_push; + int unbalanced_times; + +public: + BIHWrap() : unbalanced_times(0) {} + + void insert(const T& obj) + { + ++unbalanced_times; + m_objects_to_push.insert(&obj); + } + + void remove(const T& obj) + { + ++unbalanced_times; + uint32 Idx = 0; + const T * temp; + if (m_obj2Idx.getRemove(&obj, temp, Idx)) + m_objects[Idx] = NULL; + else + m_objects_to_push.remove(&obj); + } + + void balance() + { + if (unbalanced_times == 0) + return; + + unbalanced_times = 0; + m_objects.fastClear(); + m_obj2Idx.getKeys(m_objects); + m_objects_to_push.getMembers(m_objects); + + m_tree.build(m_objects, BoundsFunc::getBounds2); + } + + template<typename RayCallback> + void intersectRay(const Ray& ray, RayCallback& intersectCallback, float& maxDist) const + { + MDLCallback<RayCallback> temp_cb(intersectCallback, m_objects.getCArray()); + m_tree.intersectRay(ray, temp_cb, maxDist, true); + } + + template<typename IsectCallback> + void intersectPoint(const Vector3& point, IsectCallback& intersectCallback) const + { + MDLCallback<IsectCallback> callback(intersectCallback, m_objects.getCArray()); + m_tree.intersectPoint(point, callback); + } +}; + +#endif // _BIH_WRAP |