diff options
| author | Shauren <shauren.trinity@gmail.com> | 2013-05-30 20:57:07 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2013-05-30 20:57:07 +0200 |
| commit | adb78862da66b13984c6494befdffbf5da0cdbe6 (patch) | |
| tree | 1514857a0131189194c251b7045d234a2bf45d86 /src/server/collision | |
| parent | cf23793b4b04cfe12f6fc1441a7d9f8192f7dfa6 (diff) | |
| parent | 3a697d4c9f5e9f2fa9c3b08c8e103d90472a871a (diff) | |
Merge branch 'master' of github.com:TrinityCore/TrinityCore into 4.3.4
Conflicts:
src/server/game/Achievements/AchievementMgr.cpp
src/server/game/Entities/Unit/Unit.cpp
src/server/game/Entities/Vehicle/Vehicle.cpp
src/server/game/Handlers/ItemHandler.cpp
src/server/game/Handlers/MailHandler.cpp
src/server/game/Server/Protocol/Opcodes.cpp
src/server/game/Server/Protocol/Opcodes.h
src/server/scripts/Commands/cs_misc.cpp
Diffstat (limited to 'src/server/collision')
| -rw-r--r-- | src/server/collision/Management/VMapManager2.cpp | 3 | ||||
| -rw-r--r-- | src/server/collision/Maps/MapTree.cpp | 74 | ||||
| -rw-r--r-- | src/server/collision/Maps/MapTree.h | 3 | ||||
| -rw-r--r-- | src/server/collision/Maps/TileAssembler.cpp | 32 | ||||
| -rw-r--r-- | src/server/collision/Maps/TileAssembler.h | 4 | ||||
| -rw-r--r-- | src/server/collision/Models/WorldModel.cpp | 55 |
6 files changed, 94 insertions, 77 deletions
diff --git a/src/server/collision/Management/VMapManager2.cpp b/src/server/collision/Management/VMapManager2.cpp index 8a1bd346957..6355dbcf4ce 100644 --- a/src/server/collision/Management/VMapManager2.cpp +++ b/src/server/collision/Management/VMapManager2.cpp @@ -96,7 +96,10 @@ namespace VMAP std::string mapFileName = getMapFileName(mapId); StaticMapTree* newTree = new StaticMapTree(mapId, basePath); if (!newTree->InitMap(mapFileName, this)) + { + delete newTree; return false; + } instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, newTree)).first; } diff --git a/src/server/collision/Maps/MapTree.cpp b/src/server/collision/Maps/MapTree.cpp index 7dbfcd78bc9..dc12bb68e0d 100644 --- a/src/server/collision/Maps/MapTree.cpp +++ b/src/server/collision/Maps/MapTree.cpp @@ -119,8 +119,9 @@ namespace VMAP return intersectionCallBack.result; } - StaticMapTree::StaticMapTree(uint32 mapID, const std::string &basePath) - : iMapID(mapID), iIsTiled(false), iTreeValues(0), iBasePath(basePath) + StaticMapTree::StaticMapTree(uint32 mapID, const std::string &basePath) : + iMapID(mapID), iIsTiled(false), iTreeValues(NULL), + iNTreeValues(0), iBasePath(basePath) { if (iBasePath.length() > 0 && iBasePath[iBasePath.length()-1] != '/' && iBasePath[iBasePath.length()-1] != '\\') { @@ -273,54 +274,49 @@ namespace VMAP bool StaticMapTree::InitMap(const std::string &fname, VMapManager2* vm) { VMAP_DEBUG_LOG(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : initializing StaticMapTree '%s'", fname.c_str()); - bool success = true; + bool success = false; std::string fullname = iBasePath + fname; FILE* rf = fopen(fullname.c_str(), "rb"); if (!rf) return false; - else + + char chunk[8]; + char tiled = '\0'; + + if (readChunk(rf, chunk, VMAP_MAGIC, 8) && fread(&tiled, sizeof(char), 1, rf) == 1 && + readChunk(rf, chunk, "NODE", 4) && iTree.readFromFile(rf)) { - char chunk[8]; - //general info - if (!readChunk(rf, chunk, VMAP_MAGIC, 8)) success = false; - char tiled = '\0'; - if (success && fread(&tiled, sizeof(char), 1, rf) != 1) success = false; - iIsTiled = bool(tiled); - // Nodes - if (success && !readChunk(rf, chunk, "NODE", 4)) success = false; - if (success) success = iTree.readFromFile(rf); - if (success) - { - iNTreeValues = iTree.primCount(); - iTreeValues = new ModelInstance[iNTreeValues]; - } + iNTreeValues = iTree.primCount(); + iTreeValues = new ModelInstance[iNTreeValues]; + success = readChunk(rf, chunk, "GOBJ", 4); + } + + iIsTiled = bool(tiled); - if (success && !readChunk(rf, chunk, "GOBJ", 4)) success = false; - // global model spawns - // only non-tiled maps have them, and if so exactly one (so far at least...) - ModelSpawn spawn; + // global model spawns + // only non-tiled maps have them, and if so exactly one (so far at least...) + ModelSpawn spawn; #ifdef VMAP_DEBUG - TC_LOG_DEBUG(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : map isTiled: %u", static_cast<uint32>(iIsTiled)); + TC_LOG_DEBUG(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : map isTiled: %u", static_cast<uint32>(iIsTiled)); #endif - if (!iIsTiled && ModelSpawn::readFromFile(rf, spawn)) + if (!iIsTiled && ModelSpawn::readFromFile(rf, spawn)) + { + WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name); + VMAP_DEBUG_LOG(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : loading %s", spawn.name.c_str()); + if (model) { - WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name); - VMAP_DEBUG_LOG(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : loading %s", spawn.name.c_str()); - if (model) - { - // assume that global model always is the first and only tree value (could be improved...) - iTreeValues[0] = ModelInstance(spawn, model); - iLoadedSpawns[0] = 1; - } - else - { - success = false; - VMAP_ERROR_LOG(LOG_FILTER_GENERAL, "StaticMapTree::InitMap() : could not acquire WorldModel pointer for '%s'", spawn.name.c_str()); - } + // assume that global model always is the first and only tree value (could be improved...) + iTreeValues[0] = ModelInstance(spawn, model); + iLoadedSpawns[0] = 1; + } + else + { + success = false; + VMAP_ERROR_LOG(LOG_FILTER_GENERAL, "StaticMapTree::InitMap() : could not acquire WorldModel pointer for '%s'", spawn.name.c_str()); } - - fclose(rf); } + + fclose(rf); return success; } diff --git a/src/server/collision/Maps/MapTree.h b/src/server/collision/Maps/MapTree.h index e97c44d089e..c66893da82f 100644 --- a/src/server/collision/Maps/MapTree.h +++ b/src/server/collision/Maps/MapTree.h @@ -85,7 +85,8 @@ namespace VMAP struct AreaInfo { - AreaInfo(): result(false), ground_Z(-G3D::inf()) {} + AreaInfo(): result(false), ground_Z(-G3D::inf()), flags(0), adtId(0), + rootId(0), groupId(0) {} bool result; float ground_Z; uint32 flags; diff --git a/src/server/collision/Maps/TileAssembler.cpp b/src/server/collision/Maps/TileAssembler.cpp index a73e5ed4dc3..b2d381b0ffd 100644 --- a/src/server/collision/Maps/TileAssembler.cpp +++ b/src/server/collision/Maps/TileAssembler.cpp @@ -152,23 +152,25 @@ namespace VMAP uint32 x, y; StaticMapTree::unpackTileID(tile->first, x, y); tilefilename << std::setw(2) << x << '_' << std::setw(2) << y << ".vmtile"; - FILE* tilefile = fopen(tilefilename.str().c_str(), "wb"); - // file header - if (success && fwrite(VMAP_MAGIC, 1, 8, tilefile) != 8) success = false; - // write number of tile spawns - if (success && fwrite(&nSpawns, sizeof(uint32), 1, tilefile) != 1) success = false; - // write tile spawns - for (uint32 s=0; s<nSpawns; ++s) + if (FILE* tilefile = fopen(tilefilename.str().c_str(), "wb")) { - if (s) - ++tile; - const ModelSpawn &spawn2 = map_iter->second->UniqueEntries[tile->second]; - success = success && ModelSpawn::writeToFile(tilefile, spawn2); - // MapTree nodes to update when loading tile: - std::map<uint32, uint32>::iterator nIdx = modelNodeIdx.find(spawn2.ID); - if (success && fwrite(&nIdx->second, sizeof(uint32), 1, tilefile) != 1) success = false; + // file header + if (success && fwrite(VMAP_MAGIC, 1, 8, tilefile) != 8) success = false; + // write number of tile spawns + if (success && fwrite(&nSpawns, sizeof(uint32), 1, tilefile) != 1) success = false; + // write tile spawns + for (uint32 s=0; s<nSpawns; ++s) + { + if (s) + ++tile; + const ModelSpawn &spawn2 = map_iter->second->UniqueEntries[tile->second]; + success = success && ModelSpawn::writeToFile(tilefile, spawn2); + // MapTree nodes to update when loading tile: + std::map<uint32, uint32>::iterator nIdx = modelNodeIdx.find(spawn2.ID); + if (success && fwrite(&nIdx->second, sizeof(uint32), 1, tilefile) != 1) success = false; + } + fclose(tilefile); } - fclose(tilefile); } // break; //test, extract only first map; TODO: remvoe this line } diff --git a/src/server/collision/Maps/TileAssembler.h b/src/server/collision/Maps/TileAssembler.h index a11ce272d62..56cb7600e4f 100644 --- a/src/server/collision/Maps/TileAssembler.h +++ b/src/server/collision/Maps/TileAssembler.h @@ -40,6 +40,7 @@ namespace VMAP private: G3D::Matrix3 iRotation; public: + ModelPosition(): iScale(0.0f) { } G3D::Vector3 iPos; G3D::Vector3 iDir; float iScale; @@ -74,7 +75,8 @@ namespace VMAP std::vector<G3D::Vector3> vertexArray; class WmoLiquid* liquid; - GroupModel_Raw() : liquid(0) {} + GroupModel_Raw() : mogpflags(0), GroupWMOID(0), liquidflags(0), + liquid(NULL) {} ~GroupModel_Raw(); bool Read(FILE* f); diff --git a/src/server/collision/Models/WorldModel.cpp b/src/server/collision/Models/WorldModel.cpp index ca0f95c74e3..3c72cb80308 100644 --- a/src/server/collision/Models/WorldModel.cpp +++ b/src/server/collision/Models/WorldModel.cpp @@ -205,35 +205,48 @@ namespace VMAP bool WmoLiquid::writeToFile(FILE* wf) { - bool result = true; - if (result && fwrite(&iTilesX, sizeof(uint32), 1, wf) != 1) result = false; - if (result && fwrite(&iTilesY, sizeof(uint32), 1, wf) != 1) result = false; - if (result && fwrite(&iCorner, sizeof(Vector3), 1, wf) != 1) result = false; - if (result && fwrite(&iType, sizeof(uint32), 1, wf) != 1) result = false; - uint32 size = (iTilesX + 1)*(iTilesY + 1); - if (result && fwrite(iHeight, sizeof(float), size, wf) != size) result = false; - size = iTilesX*iTilesY; - if (result && fwrite(iFlags, sizeof(uint8), size, wf) != size) result = false; + bool result = false; + if (fwrite(&iTilesX, sizeof(uint32), 1, wf) == 1 && + fwrite(&iTilesY, sizeof(uint32), 1, wf) == 1 && + fwrite(&iCorner, sizeof(Vector3), 1, wf) == 1 && + fwrite(&iType, sizeof(uint32), 1, wf) == 1) + { + uint32 size = (iTilesX + 1) * (iTilesY + 1); + if (fwrite(iHeight, sizeof(float), size, wf) == size) + { + size = iTilesX*iTilesY; + result = fwrite(iFlags, sizeof(uint8), size, wf) == size; + } + } + return result; } bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid* &out) { - bool result = true; + bool result = false; WmoLiquid* liquid = new WmoLiquid(); - if (result && fread(&liquid->iTilesX, sizeof(uint32), 1, rf) != 1) result = false; - if (result && fread(&liquid->iTilesY, sizeof(uint32), 1, rf) != 1) result = false; - if (result && fread(&liquid->iCorner, sizeof(Vector3), 1, rf) != 1) result = false; - if (result && fread(&liquid->iType, sizeof(uint32), 1, rf) != 1) result = false; - uint32 size = (liquid->iTilesX + 1)*(liquid->iTilesY + 1); - liquid->iHeight = new float[size]; - if (result && fread(liquid->iHeight, sizeof(float), size, rf) != size) result = false; - size = liquid->iTilesX * liquid->iTilesY; - liquid->iFlags = new uint8[size]; - if (result && fread(liquid->iFlags, sizeof(uint8), size, rf) != size) result = false; + + if (fread(&liquid->iTilesX, sizeof(uint32), 1, rf) == 1 && + fread(&liquid->iTilesY, sizeof(uint32), 1, rf) == 1 && + fread(&liquid->iCorner, sizeof(Vector3), 1, rf) == 1 && + fread(&liquid->iType, sizeof(uint32), 1, rf) == 1) + { + uint32 size = (liquid->iTilesX + 1) * (liquid->iTilesY + 1); + liquid->iHeight = new float[size]; + if (fread(liquid->iHeight, sizeof(float), size, rf) == size) + { + size = liquid->iTilesX * liquid->iTilesY; + liquid->iFlags = new uint8[size]; + result = fread(liquid->iFlags, sizeof(uint8), size, rf) == size; + } + } + if (!result) delete liquid; - out = liquid; + else + out = liquid; + return result; } |
