aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision/Maps/MapTree.h
diff options
context:
space:
mode:
authorStormBytePP <stormbyte@gmail.com>2015-08-15 02:19:10 +0200
committerStormBytePP <stormbyte@gmail.com>2015-08-16 21:23:15 +0200
commit1f66d719f2cbbcb144b5080c89dd73fcae261798 (patch)
tree6a3778749b629c92de95cef7eb3d1d8c2630bdc4 /src/common/Collision/Maps/MapTree.h
parent222eaccc51b8d358c7b60d8def40d6461244ed31 (diff)
Core/BuildSystem: Merge collision, debugging, threading, utilities and configuration into "common" which does not depend on shared anymore and moved database out of shared library
These changes enables to build tools only without even having MySQL installed
Diffstat (limited to 'src/common/Collision/Maps/MapTree.h')
-rw-r--r--src/common/Collision/Maps/MapTree.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h
new file mode 100644
index 00000000000..08bd5c3d3a1
--- /dev/null
+++ b/src/common/Collision/Maps/MapTree.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2008-2015 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 _MAPTREE_H
+#define _MAPTREE_H
+
+#include "Define.h"
+#include "BoundingIntervalHierarchy.h"
+#include <unordered_map>
+
+namespace VMAP
+{
+ class ModelInstance;
+ class GroupModel;
+ class VMapManager2;
+
+ struct LocationInfo
+ {
+ LocationInfo(): hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
+ const ModelInstance* hitInstance;
+ const GroupModel* hitModel;
+ float ground_Z;
+ };
+
+ class StaticMapTree
+ {
+ typedef std::unordered_map<uint32, bool> loadedTileMap;
+ typedef std::unordered_map<uint32, uint32> loadedSpawnMap;
+ private:
+ uint32 iMapID;
+ bool iIsTiled;
+ BIH iTree;
+ ModelInstance* iTreeValues; // the tree entries
+ uint32 iNTreeValues;
+
+ // Store all the map tile idents that are loaded for that map
+ // some maps are not splitted into tiles and we have to make sure, not removing the map before all tiles are removed
+ // empty tiles have no tile file, hence map with bool instead of just a set (consistency check)
+ loadedTileMap iLoadedTiles;
+ // stores <tree_index, reference_count> to invalidate tree values, unload map, and to be able to report errors
+ loadedSpawnMap iLoadedSpawns;
+ std::string iBasePath;
+
+ private:
+ bool getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit) const;
+ //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
+ public:
+ static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY);
+ static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; }
+ static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID>>16; tileY = ID&0xFF; }
+ static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY);
+
+ StaticMapTree(uint32 mapID, const std::string &basePath);
+ ~StaticMapTree();
+
+ bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2) const;
+ bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
+ float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
+ bool getAreaInfo(G3D::Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const;
+ bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const;
+
+ bool InitMap(const std::string &fname, VMapManager2* vm);
+ void UnloadMap(VMapManager2* vm);
+ bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
+ void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
+ bool isTiled() const { return iIsTiled; }
+ uint32 numLoadedTiles() const { return iLoadedTiles.size(); }
+ void getModelInstances(ModelInstance* &models, uint32 &count);
+
+ private:
+ StaticMapTree(StaticMapTree const& right) = delete;
+ StaticMapTree& operator=(StaticMapTree const& right) = delete;
+ };
+
+ struct AreaInfo
+ {
+ AreaInfo(): result(false), ground_Z(-G3D::finf()), flags(0), adtId(0),
+ rootId(0), groupId(0) { }
+ bool result;
+ float ground_Z;
+ uint32 flags;
+ int32 adtId;
+ int32 rootId;
+ int32 groupId;
+ };
+} // VMAP
+
+#endif // _MAPTREE_H