2010-06-05 00:59:25 +02:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2010-06-05 00:59:25 +02:00
*
2010-07-09 18:02:46 +02:00
* 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.
2010-06-05 00:59:25 +02:00
*
2010-07-09 18:02:46 +02:00
* 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.
2010-06-05 00:59:25 +02:00
*
2010-07-09 18:02:46 +02:00
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2010-06-05 00:59:25 +02:00
*/
#include "MapTree.h"
#include "ModelInstance.h"
#include "VMapManager2.h"
#include "VMapDefinitions.h"
2010-06-19 22:08:03 +02:00
#include "Log.h"
2013-01-22 19:30:52 +01:00
#include "Errors.h"
2016-06-04 11:26:57 +01:00
#include "Metric.h"
2010-06-05 00:59:25 +02:00
#include <string>
#include <sstream>
#include <iomanip>
2010-06-15 17:08:04 +02:00
#include <limits>
2010-06-05 00:59:25 +02:00
using G3D :: Vector3 ;
namespace VMAP
{
class MapRayCallback
{
public :
2017-01-21 14:44:31 +01:00
MapRayCallback ( ModelInstance * val , ModelIgnoreFlags ignoreFlags ) : prims ( val ), hit ( false ), flags ( ignoreFlags ) { }
2010-06-05 00:59:25 +02:00
bool operator ()( const G3D :: Ray & ray , uint32 entry , float & distance , bool pStopAtFirstHit = true )
{
2017-01-21 14:44:31 +01:00
bool result = prims [ entry ]. intersectRay ( ray , distance , pStopAtFirstHit , flags );
2010-07-10 05:14:05 +02:00
if ( result )
hit = true ;
return result ;
2010-06-05 00:59:25 +02:00
}
2010-07-10 05:14:05 +02:00
bool didHit () { return hit ; }
protected :
2011-09-15 14:08:17 +02:00
ModelInstance * prims ;
2010-07-10 05:14:05 +02:00
bool hit ;
2017-01-21 14:44:31 +01:00
ModelIgnoreFlags flags ;
2010-06-05 00:59:25 +02:00
};
class AreaInfoCallback
{
public :
2013-10-27 22:27:46 +01:00
AreaInfoCallback ( ModelInstance * val ) : prims ( val ) { }
2010-06-05 00:59:25 +02:00
void operator ()( const Vector3 & point , uint32 entry )
{
#ifdef VMAP_DEBUG
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "maps" , "AreaInfoCallback: trying to intersect '%s'" , prims [ entry ]. name . c_str ());
2010-06-05 00:59:25 +02:00
#endif
prims [ entry ]. intersectPoint ( point , aInfo );
}
2011-09-15 14:08:17 +02:00
ModelInstance * prims ;
2010-06-05 00:59:25 +02:00
AreaInfo aInfo ;
};
class LocationInfoCallback
{
public :
2013-10-27 22:27:46 +01:00
LocationInfoCallback ( ModelInstance * val , LocationInfo & info ) : prims ( val ), locInfo ( info ), result ( false ) { }
2010-06-05 00:59:25 +02:00
void operator ()( const Vector3 & point , uint32 entry )
{
#ifdef VMAP_DEBUG
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "maps" , "LocationInfoCallback: trying to intersect '%s'" , prims [ entry ]. name . c_str ());
2010-06-05 00:59:25 +02:00
#endif
if ( prims [ entry ]. GetLocationInfo ( point , locInfo ))
result = true ;
}
2011-09-15 14:08:17 +02:00
ModelInstance * prims ;
2010-06-05 00:59:25 +02:00
LocationInfo & locInfo ;
bool result ;
};
//=========================================================
std :: string StaticMapTree :: getTileFileName ( uint32 mapID , uint32 tileX , uint32 tileY )
{
std :: stringstream tilefilename ;
tilefilename . fill ( '0' );
2015-05-07 00:07:44 +02:00
tilefilename << std :: setw ( 4 ) << mapID << '_' ;
2011-07-29 14:18:28 +02:00
//tilefilename << std::setw(2) << tileX << '_' << std::setw(2) << tileY << ".vmtile";
tilefilename << std :: setw ( 2 ) << tileY << '_' << std :: setw ( 2 ) << tileX << ".vmtile" ;
2010-06-05 00:59:25 +02:00
return tilefilename . str ();
}
bool StaticMapTree :: getAreaInfo ( Vector3 & pos , uint32 & flags , int32 & adtId , int32 & rootId , int32 & groupId ) const
{
AreaInfoCallback intersectionCallBack ( iTreeValues );
iTree . intersectPoint ( pos , intersectionCallBack );
if ( intersectionCallBack . aInfo . result )
{
flags = intersectionCallBack . aInfo . flags ;
adtId = intersectionCallBack . aInfo . adtId ;
rootId = intersectionCallBack . aInfo . rootId ;
groupId = intersectionCallBack . aInfo . groupId ;
pos . z = intersectionCallBack . aInfo . ground_Z ;
return true ;
}
return false ;
}
bool StaticMapTree :: GetLocationInfo ( const Vector3 & pos , LocationInfo & info ) const
{
LocationInfoCallback intersectionCallBack ( iTreeValues , info );
iTree . intersectPoint ( pos , intersectionCallBack );
return intersectionCallBack . result ;
}
2018-04-27 20:23:52 +02:00
StaticMapTree :: StaticMapTree ( uint32 mapID , const std :: string & basePath )
: iMapID ( mapID ), iTreeValues ( NULL ), iNTreeValues ( 0 ), iBasePath ( basePath )
2010-06-05 00:59:25 +02:00
{
2012-02-15 16:42:05 +01:00
if ( iBasePath . length () > 0 && iBasePath [ iBasePath . length () - 1 ] != '/' && iBasePath [ iBasePath . length () - 1 ] != '\\' )
2010-06-05 00:59:25 +02:00
{
2011-07-29 14:18:28 +02:00
iBasePath . push_back ( '/' );
2010-06-05 00:59:25 +02:00
}
}
//=========================================================
//! Make sure to call unloadMap() to unregister acquired model references before destroying
StaticMapTree ::~ StaticMapTree ()
{
delete [] iTreeValues ;
}
//=========================================================
/**
2010-07-10 05:14:05 +02:00
If intersection is found within pMaxDist, sets pMaxDist to intersection distance and returns true.
Else, pMaxDist is not modified and returns false;
2010-06-05 00:59:25 +02:00
*/
2017-01-21 14:44:31 +01:00
bool StaticMapTree :: getIntersectionTime ( const G3D :: Ray & pRay , float & pMaxDist , bool pStopAtFirstHit , ModelIgnoreFlags ignoreFlags ) const
2010-06-05 00:59:25 +02:00
{
float distance = pMaxDist ;
2017-01-21 14:44:31 +01:00
MapRayCallback intersectionCallBack ( iTreeValues , ignoreFlags );
2010-06-05 00:59:25 +02:00
iTree . intersectRay ( pRay , intersectionCallBack , distance , pStopAtFirstHit );
2010-07-10 05:14:05 +02:00
if ( intersectionCallBack . didHit ())
pMaxDist = distance ;
2010-08-08 19:45:53 +02:00
return intersectionCallBack . didHit ();
2010-06-05 00:59:25 +02:00
}
//=========================================================
2017-01-21 14:44:31 +01:00
bool StaticMapTree :: isInLineOfSight ( const Vector3 & pos1 , const Vector3 & pos2 , ModelIgnoreFlags ignoreFlag ) const
2010-06-05 00:59:25 +02:00
{
float maxDist = ( pos2 - pos1 ). magnitude ();
2013-08-30 21:27:04 +01:00
// return false if distance is over max float, in case of cheater teleporting to the end of the universe
2014-05-25 15:33:56 +02:00
if ( maxDist == std :: numeric_limits < float >:: max () || ! std :: isfinite ( maxDist ))
2013-08-30 21:27:04 +01:00
return false ;
2010-06-15 17:08:04 +02:00
// valid map coords should *never ever* produce float overflow, but this would produce NaNs too
2010-06-19 17:26:12 +02:00
ASSERT ( maxDist < std :: numeric_limits < float >:: max ());
2010-06-05 00:59:25 +02:00
// prevent NaN values which can cause BIH intersection to enter infinite loop
if ( maxDist < 1e-10 f )
return true ;
// direction with length of 1
G3D :: Ray ray = G3D :: Ray :: fromOriginAndDirection ( pos1 , ( pos2 - pos1 ) / maxDist );
2017-01-21 14:44:31 +01:00
if ( getIntersectionTime ( ray , maxDist , true , ignoreFlag ))
2010-07-10 05:14:05 +02:00
return false ;
return true ;
2010-06-05 00:59:25 +02:00
}
//=========================================================
/**
When moving from pos1 to pos2 check if we hit an object. Return true and the position if we hit one
Return the hit pos or the original dest pos
*/
bool StaticMapTree :: getObjectHitPos ( const Vector3 & pPos1 , const Vector3 & pPos2 , Vector3 & pResultHitPos , float pModifyDist ) const
{
bool result = false ;
float maxDist = ( pPos2 - pPos1 ). magnitude ();
2010-06-15 17:08:04 +02:00
// valid map coords should *never ever* produce float overflow, but this would produce NaNs too
ASSERT ( maxDist < std :: numeric_limits < float >:: max ());
2010-06-05 00:59:25 +02:00
// prevent NaN values which can cause BIH intersection to enter infinite loop
if ( maxDist < 1e-10 f )
{
pResultHitPos = pPos2 ;
return false ;
}
Vector3 dir = ( pPos2 - pPos1 ) / maxDist ; // direction with length of 1
G3D :: Ray ray ( pPos1 , dir );
2010-07-10 05:14:05 +02:00
float dist = maxDist ;
2017-01-21 14:44:31 +01:00
if ( getIntersectionTime ( ray , dist , false , ModelIgnoreFlags :: Nothing ))
2010-06-05 00:59:25 +02:00
{
pResultHitPos = pPos1 + dir * dist ;
if ( pModifyDist < 0 )
{
if (( pResultHitPos - pPos1 ). magnitude () > - pModifyDist )
{
pResultHitPos = pResultHitPos + dir * pModifyDist ;
}
else
{
pResultHitPos = pPos1 ;
}
}
else
{
pResultHitPos = pResultHitPos + dir * pModifyDist ;
}
result = true ;
}
else
{
pResultHitPos = pPos2 ;
result = false ;
}
return result ;
}
//=========================================================
2010-07-27 17:29:33 +02:00
float StaticMapTree :: getHeight ( const Vector3 & pPos , float maxSearchDist ) const
2010-06-05 00:59:25 +02:00
{
2014-08-21 16:56:11 +02:00
float height = G3D :: finf ();
2011-04-29 20:47:02 +02:00
Vector3 dir = Vector3 ( 0 , 0 , - 1 );
2010-06-05 00:59:25 +02:00
G3D :: Ray ray ( pPos , dir ); // direction with length of 1
2010-07-27 17:29:33 +02:00
float maxDist = maxSearchDist ;
2017-01-21 14:44:31 +01:00
if ( getIntersectionTime ( ray , maxDist , false , ModelIgnoreFlags :: Nothing ))
2010-06-05 00:59:25 +02:00
{
2010-07-10 05:14:05 +02:00
height = pPos . z - maxDist ;
2010-06-05 00:59:25 +02:00
}
return ( height );
}
2018-02-24 21:07:08 +01:00
StaticMapTree :: TileFileOpenResult StaticMapTree :: OpenMapTileFile ( std :: string const & basePath , uint32 mapID , uint32 tileX , uint32 tileY , VMapManager2 * vm )
{
TileFileOpenResult result ;
result . Name = basePath + getTileFileName ( mapID , tileX , tileY );
result . File = fopen ( result . Name . c_str (), "rb" );
if ( ! result . File )
{
int32 parentMapId = vm -> getParentMapId ( mapID );
if ( parentMapId != - 1 )
{
result . Name = basePath + getTileFileName ( parentMapId , tileX , tileY );
result . File = fopen ( result . Name . c_str (), "rb" );
}
}
return result ;
}
2010-06-05 00:59:25 +02:00
//=========================================================
2017-01-22 12:06:02 +01:00
LoadResult StaticMapTree :: CanLoadMap ( const std :: string & vmapPath , uint32 mapID , uint32 tileX , uint32 tileY , VMapManager2 * vm )
2010-06-05 00:59:25 +02:00
{
std :: string basePath = vmapPath ;
2012-02-15 16:42:05 +01:00
if ( basePath . length () > 0 && basePath [ basePath . length () - 1 ] != '/' && basePath [ basePath . length () - 1 ] != '\\' )
2011-07-29 14:18:28 +02:00
basePath . push_back ( '/' );
2010-06-05 00:59:25 +02:00
std :: string fullname = basePath + VMapManager2 :: getMapFileName ( mapID );
2017-01-22 12:06:02 +01:00
LoadResult result = LoadResult :: Success ;
2011-09-15 14:08:17 +02:00
FILE * rf = fopen ( fullname . c_str (), "rb" );
2010-06-05 00:59:25 +02:00
if ( ! rf )
2017-01-22 12:06:02 +01:00
return LoadResult :: FileNotFound ;
2018-04-27 20:29:01 +02:00
2010-06-05 00:59:25 +02:00
char chunk [ 8 ];
2018-04-27 20:23:52 +02:00
if ( ! readChunk ( rf , chunk , VMAP_MAGIC , 8 ))
2010-06-05 00:59:25 +02:00
{
fclose ( rf );
2017-01-22 12:06:02 +01:00
return LoadResult :: VersionMismatch ;
2010-06-05 00:59:25 +02:00
}
2018-04-27 20:23:52 +02:00
FILE * tf = OpenMapTileFile ( basePath , mapID , tileX , tileY , vm ). File ;
if ( ! tf )
2019-02-16 17:37:16 +01:00
{
fclose ( rf );
2017-01-22 12:06:02 +01:00
return LoadResult :: FileNotFound ;
2019-02-16 17:37:16 +01:00
}
2018-04-27 20:23:52 +02:00
else
2010-06-05 00:59:25 +02:00
{
2017-01-22 12:06:02 +01:00
std :: string tilefile = basePath + getTileFileName ( mapID , tileX , tileY );
FILE * tf = fopen ( tilefile . c_str (), "rb" );
if ( ! tf )
result = LoadResult :: FileNotFound ;
else
{
if ( ! readChunk ( tf , chunk , VMAP_MAGIC , 8 ))
result = LoadResult :: VersionMismatch ;
fclose ( tf );
}
2010-06-05 00:59:25 +02:00
}
fclose ( rf );
2017-01-22 12:06:02 +01:00
return result ;
2010-06-05 00:59:25 +02:00
}
//=========================================================
2018-04-27 20:29:01 +02:00
bool StaticMapTree :: InitMap ( std :: string const & fname )
2010-06-05 00:59:25 +02:00
{
2018-04-02 20:05:08 +02:00
TC_LOG_DEBUG ( "maps" , "StaticMapTree::InitMap() : initializing StaticMapTree '%s'" , fname . c_str ());
2013-05-30 11:06:23 +02:00
bool success = false ;
2010-06-05 00:59:25 +02:00
std :: string fullname = iBasePath + fname ;
2011-09-15 14:08:17 +02:00
FILE * rf = fopen ( fullname . c_str (), "rb" );
2010-06-05 00:59:25 +02:00
if ( ! rf )
return false ;
2013-05-30 11:06:23 +02:00
char chunk [ 8 ];
2018-04-27 20:23:52 +02:00
if ( readChunk ( rf , chunk , VMAP_MAGIC , 8 ) &&
readChunk ( rf , chunk , "NODE" , 4 ) &&
iTree . readFromFile ( rf ))
2010-06-05 00:59:25 +02:00
{
2013-05-30 11:06:23 +02:00
iNTreeValues = iTree . primCount ();
iTreeValues = new ModelInstance [ iNTreeValues ];
2018-04-27 20:23:52 +02:00
success = true ;
2010-06-05 00:59:25 +02:00
}
2013-05-30 11:06:23 +02:00
2018-02-24 21:07:08 +01:00
if ( success )
{
success = readChunk ( rf , chunk , "SIDX" , 4 );
uint32 spawnIndicesSize = 0 ;
uint32 spawnId ;
uint32 spawnIndex ;
if ( success && fread ( & spawnIndicesSize , sizeof ( uint32 ), 1 , rf ) != 1 ) success = false ;
for ( uint32 i = 0 ; i < spawnIndicesSize && success ; ++ i )
{
if ( fread ( & spawnId , sizeof ( uint32 ), 1 , rf ) == 1 && fread ( & spawnIndex , sizeof ( uint32 ), 1 , rf ) == 1 )
iSpawnIndices [ spawnId ] = spawnIndex ;
else
success = false ;
}
}
2013-05-30 11:06:23 +02:00
fclose ( rf );
2010-06-05 00:59:25 +02:00
return success ;
}
//=========================================================
2011-09-15 14:08:17 +02:00
void StaticMapTree :: UnloadMap ( VMapManager2 * vm )
2010-06-05 00:59:25 +02:00
{
for ( loadedSpawnMap :: iterator i = iLoadedSpawns . begin (); i != iLoadedSpawns . end (); ++ i )
{
iTreeValues [ i -> first ]. setUnloaded ();
for ( uint32 refCount = 0 ; refCount < i -> second ; ++ refCount )
vm -> releaseModelInstance ( iTreeValues [ i -> first ]. name );
}
iLoadedSpawns . clear ();
iLoadedTiles . clear ();
}
//=========================================================
2011-09-15 14:08:17 +02:00
bool StaticMapTree :: LoadMapTile ( uint32 tileX , uint32 tileY , VMapManager2 * vm )
2010-06-05 00:59:25 +02:00
{
if ( ! iTreeValues )
{
2018-04-02 20:05:08 +02:00
TC_LOG_ERROR ( "misc" , "StaticMapTree::LoadMapTile() : tree has not been initialized [%u, %u]" , tileX , tileY );
2010-06-05 00:59:25 +02:00
return false ;
}
bool result = true ;
2018-02-24 21:07:08 +01:00
TileFileOpenResult fileResult = OpenMapTileFile ( iBasePath , iMapID , tileX , tileY , vm );
if ( fileResult . File )
2010-06-05 00:59:25 +02:00
{
2010-07-09 18:02:46 +02:00
char chunk [ 8 ];
2018-02-24 21:07:08 +01:00
if ( ! readChunk ( fileResult . File , chunk , VMAP_MAGIC , 8 ))
2010-07-09 18:02:46 +02:00
result = false ;
2011-03-08 16:42:00 +01:00
uint32 numSpawns = 0 ;
2018-02-24 21:07:08 +01:00
if ( result && fread ( & numSpawns , sizeof ( uint32 ), 1 , fileResult . File ) != 1 )
2010-06-05 00:59:25 +02:00
result = false ;
for ( uint32 i = 0 ; i < numSpawns && result ; ++ i )
{
// read model spawns
ModelSpawn spawn ;
2018-02-24 21:07:08 +01:00
result = ModelSpawn :: readFromFile ( fileResult . File , spawn );
2010-06-05 00:59:25 +02:00
if ( result )
{
// acquire model instance
2017-01-21 14:44:31 +01:00
WorldModel * model = vm -> acquireModelInstance ( iBasePath , spawn . name , spawn . flags );
2010-06-19 22:08:03 +02:00
if ( ! model )
2018-04-02 20:05:08 +02:00
TC_LOG_ERROR ( "misc" , "StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [%u, %u]" , tileX , tileY );
2010-06-05 00:59:25 +02:00
// update tree
2018-02-24 21:07:08 +01:00
auto spawnIndex = iSpawnIndices . find ( spawn . ID );
if ( spawnIndex != iSpawnIndices . end ())
2010-06-05 00:59:25 +02:00
{
2018-02-24 21:07:08 +01:00
uint32 referencedVal = spawnIndex -> second ;
2010-08-31 10:23:22 +02:00
if ( ! iLoadedSpawns . count ( referencedVal ))
2010-06-05 00:59:25 +02:00
{
2018-02-24 21:07:08 +01:00
if ( referencedVal >= iNTreeValues )
2010-08-31 10:23:22 +02:00
{
2018-04-02 20:05:08 +02:00
TC_LOG_ERROR ( "maps" , "StaticMapTree::LoadMapTile() : invalid tree element (%u/%u) referenced in tile %s" , referencedVal , iNTreeValues , fileResult . Name . c_str ());
2010-08-31 10:23:22 +02:00
continue ;
}
2015-02-27 22:56:29 +01:00
2010-08-31 10:23:22 +02:00
iTreeValues [ referencedVal ] = ModelInstance ( spawn , model );
iLoadedSpawns [ referencedVal ] = 1 ;
}
else
{
++ iLoadedSpawns [ referencedVal ];
2010-06-05 00:59:25 +02:00
#ifdef VMAP_DEBUG
2010-08-31 10:23:22 +02:00
if ( iTreeValues [ referencedVal ]. ID != spawn . ID )
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "maps" , "StaticMapTree::LoadMapTile() : trying to load wrong spawn in node" );
2010-08-31 10:23:22 +02:00
else if ( iTreeValues [ referencedVal ]. name != spawn . name )
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "maps" , "StaticMapTree::LoadMapTile() : name collision on GUID=%u" , spawn . ID );
2010-06-05 00:59:25 +02:00
#endif
2010-08-31 10:23:22 +02:00
}
2010-06-05 00:59:25 +02:00
}
2010-08-31 10:23:22 +02:00
else
result = false ;
2010-06-05 00:59:25 +02:00
}
}
iLoadedTiles [ packTileID ( tileX , tileY )] = true ;
2018-02-24 21:07:08 +01:00
fclose ( fileResult . File );
2010-06-05 00:59:25 +02:00
}
else
iLoadedTiles [ packTileID ( tileX , tileY )] = false ;
2016-06-04 11:26:57 +01:00
TC_METRIC_EVENT ( "map_events" , "LoadMapTile" ,
"Map: " + std :: to_string ( iMapID ) + " TileX: " + std :: to_string ( tileX ) + " TileY: " + std :: to_string ( tileY ));
2010-06-05 00:59:25 +02:00
return result ;
}
//=========================================================
2011-09-15 14:08:17 +02:00
void StaticMapTree :: UnloadMapTile ( uint32 tileX , uint32 tileY , VMapManager2 * vm )
2010-06-05 00:59:25 +02:00
{
uint32 tileID = packTileID ( tileX , tileY );
loadedTileMap :: iterator tile = iLoadedTiles . find ( tileID );
if ( tile == iLoadedTiles . end ())
{
2018-04-02 20:05:08 +02:00
TC_LOG_ERROR ( "misc" , "StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:%u X:%u Y:%u" , iMapID , tileX , tileY );
2010-06-05 00:59:25 +02:00
return ;
}
if ( tile -> second ) // file associated with tile
{
2018-02-24 21:07:08 +01:00
TileFileOpenResult fileResult = OpenMapTileFile ( iBasePath , iMapID , tileX , tileY , vm );
if ( fileResult . File )
2010-06-05 00:59:25 +02:00
{
bool result = true ;
2010-07-09 18:02:46 +02:00
char chunk [ 8 ];
2018-02-24 21:07:08 +01:00
if ( ! readChunk ( fileResult . File , chunk , VMAP_MAGIC , 8 ))
2010-07-09 18:02:46 +02:00
result = false ;
2010-06-05 00:59:25 +02:00
uint32 numSpawns ;
2018-02-24 21:07:08 +01:00
if ( fread ( & numSpawns , sizeof ( uint32 ), 1 , fileResult . File ) != 1 )
2010-06-05 00:59:25 +02:00
result = false ;
for ( uint32 i = 0 ; i < numSpawns && result ; ++ i )
{
// read model spawns
ModelSpawn spawn ;
2018-02-24 21:07:08 +01:00
result = ModelSpawn :: readFromFile ( fileResult . File , spawn );
2010-06-05 00:59:25 +02:00
if ( result )
{
// release model instance
vm -> releaseModelInstance ( spawn . name );
// update tree
2018-02-24 21:07:08 +01:00
auto spawnIndex = iSpawnIndices . find ( spawn . ID );
if ( spawnIndex == iSpawnIndices . end ())
2010-08-31 10:23:22 +02:00
result = false ;
else
2010-06-05 00:59:25 +02:00
{
2018-02-24 21:07:08 +01:00
uint32 referencedNode = spawnIndex -> second ;
2010-08-31 10:23:22 +02:00
if ( ! iLoadedSpawns . count ( referencedNode ))
2018-04-02 20:05:08 +02:00
TC_LOG_ERROR ( "misc" , "StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '%s' (ID:%u)" , spawn . name . c_str (), spawn . ID );
2010-08-31 10:23:22 +02:00
else if ( -- iLoadedSpawns [ referencedNode ] == 0 )
{
iTreeValues [ referencedNode ]. setUnloaded ();
iLoadedSpawns . erase ( referencedNode );
}
2010-06-05 00:59:25 +02:00
}
}
}
2018-02-24 21:07:08 +01:00
fclose ( fileResult . File );
2010-06-05 00:59:25 +02:00
}
}
iLoadedTiles . erase ( tile );
2016-06-04 11:26:57 +01:00
TC_METRIC_EVENT ( "map_events" , "UnloadMapTile" ,
"Map: " + std :: to_string ( iMapID ) + " TileX: " + std :: to_string ( tileX ) + " TileY: " + std :: to_string ( tileY ));
2010-06-05 00:59:25 +02:00
}
2015-10-12 14:13:50 +02:00
void StaticMapTree :: getModelInstances ( ModelInstance * & models , uint32 & count )
{
models = iTreeValues ;
count = iNTreeValues ;
}
2010-06-05 00:59:25 +02:00
}