mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-06-13 19:07:45 +00:00
use cache in getterritorydetail; remove unused bgpath; avoid throwing exceptions when possible;
This commit is contained in:
parent
4f3f866531
commit
d5c4739a77
2 changed files with 60 additions and 47 deletions
|
@ -77,12 +77,11 @@ uint32_t TerritoryMgr::getNextInstanceId()
|
||||||
|
|
||||||
Excel::ExcelStructPtr< Excel::TerritoryType > TerritoryMgr::getTerritoryDetail( uint32_t territoryTypeId ) const
|
Excel::ExcelStructPtr< Excel::TerritoryType > TerritoryMgr::getTerritoryDetail( uint32_t territoryTypeId ) const
|
||||||
{
|
{
|
||||||
auto& exdData = Common::Service< Data::ExdData >::ref();
|
auto it = m_territoryTypeDetailCacheMap.find( territoryTypeId );
|
||||||
auto teri1 = exdData.getRow< Excel::TerritoryType >( territoryTypeId );
|
if( it == m_territoryTypeDetailCacheMap.end() )
|
||||||
if( !teri1 )
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return teri1;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TerritoryMgr::isInstanceContentTerritory( uint32_t territoryTypeId ) const
|
bool TerritoryMgr::isInstanceContentTerritory( uint32_t territoryTypeId ) const
|
||||||
|
@ -198,8 +197,6 @@ bool TerritoryMgr::createDefaultTerritories()
|
||||||
pPlaceName->getString( pPlaceName->data().Text.SGL ) );
|
pPlaceName->getString( pPlaceName->data().Text.SGL ) );
|
||||||
pZone->init();
|
pZone->init();
|
||||||
|
|
||||||
std::string bgPath = territoryInfo->getString( territoryData.LVB );
|
|
||||||
|
|
||||||
bool hasNaviMesh = pZone->getNaviProvider() != nullptr;
|
bool hasNaviMesh = pZone->getNaviProvider() != nullptr;
|
||||||
|
|
||||||
Logger::info( "{0}\t{1}\t{2}\t{3:<10}\t{4}\t{5}\t{6}",
|
Logger::info( "{0}\t{1}\t{2}\t{3:<10}\t{4}\t{5}\t{6}",
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
#include <ExdCat.h>
|
#include <ExdCat.h>
|
||||||
#include <Exd.h>
|
#include <Exd.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <execution>
|
||||||
|
|
||||||
#include <Logging/Logger.h>
|
#include <Logging/Logger.h>
|
||||||
#include <Service.h>
|
#include <Service.h>
|
||||||
#include <Util/UtilMath.h>
|
#include <Util/UtilMath.h>
|
||||||
|
@ -22,7 +25,7 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
|
||||||
auto idList = exdData.getIdList< Excel::TerritoryType >();
|
auto idList = exdData.getIdList< Excel::TerritoryType >();
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for( const auto& id : idList )
|
std::for_each( std::execution::seq, idList.begin(), idList.end() , [ & ]( int id )
|
||||||
{
|
{
|
||||||
// show some loading indication...
|
// show some loading indication...
|
||||||
if( count++ % 10 == 0 )
|
if( count++ % 10 == 0 )
|
||||||
|
@ -30,12 +33,12 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
|
||||||
|
|
||||||
auto territoryType = exdData.getRow< Excel::TerritoryType >( id );
|
auto territoryType = exdData.getRow< Excel::TerritoryType >( id );
|
||||||
if( !territoryType )
|
if( !territoryType )
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
auto path = territoryType->getString( territoryType->data().LVB );
|
auto path = territoryType->getString( territoryType->data().LVB );
|
||||||
|
|
||||||
if( path.empty() )
|
if( path.empty() )
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
path = std::string( "bg/" ) + path.substr( 0, path.find( "/level/" ) );
|
path = std::string( "bg/" ) + path.substr( 0, path.find( "/level/" ) );
|
||||||
|
|
||||||
|
@ -56,14 +59,18 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bgFile = exdData.getGameData()->getFile( bgLgbPath );
|
if( exdData.getGameData()->doesFileExist( bgLgbPath ) )
|
||||||
|
bgFile = exdData.getGameData()->getFile( bgLgbPath );
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
planmap_file = exdData.getGameData()->getFile( planmapLgbPath );
|
planmap_file = exdData.getGameData()->getFile( planmapLgbPath );
|
||||||
planevent_file = exdData.getGameData()->getFile( planeventLgbPath );
|
planevent_file = exdData.getGameData()->getFile( planeventLgbPath );
|
||||||
}
|
}
|
||||||
catch( std::runtime_error& )
|
catch( std::runtime_error& )
|
||||||
{
|
{
|
||||||
// ignore files that aren't found
|
// ignore files that aren't found
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bgSection = bgFile->access_data_sections().at( 0 );
|
bgSection = bgFile->access_data_sections().at( 0 );
|
||||||
|
@ -101,49 +108,58 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
|
||||||
{
|
{
|
||||||
for( const auto& pEntry : group.entries )
|
for( const auto& pEntry : group.entries )
|
||||||
{
|
{
|
||||||
|
switch( pEntry->getType() )
|
||||||
|
{
|
||||||
|
case LgbEntryType::MapRange:
|
||||||
|
{
|
||||||
|
auto pMapRange = std::reinterpret_pointer_cast< LGB_MAP_RANGE_ENTRY >( pEntry );
|
||||||
|
m_mapRangeCache.insert( id, pMapRange );
|
||||||
|
|
||||||
if( pEntry->getType() == LgbEntryType::MapRange )
|
break;
|
||||||
{
|
}
|
||||||
auto pMapRange = std::reinterpret_pointer_cast< LGB_MAP_RANGE_ENTRY >( pEntry );
|
case LgbEntryType::ExitRange:
|
||||||
m_mapRangeCache.insert( id, pMapRange );
|
{
|
||||||
}
|
auto pExitRange = std::reinterpret_pointer_cast< LGB_EXIT_RANGE_ENTRY >( pEntry );
|
||||||
else if( pEntry->getType() == LgbEntryType::ExitRange )
|
m_exitRangeCache.insert( id, pExitRange );
|
||||||
{
|
|
||||||
auto pExitRange = std::reinterpret_pointer_cast< LGB_EXIT_RANGE_ENTRY >( pEntry );
|
|
||||||
m_exitRangeCache.insert( id, pExitRange );
|
|
||||||
}
|
|
||||||
else if( pEntry->getType() == LgbEntryType::PopRange )
|
|
||||||
{
|
|
||||||
|
|
||||||
auto pPopRange = std::reinterpret_pointer_cast< LGB_POP_RANGE_ENTRY >( pEntry );
|
break;
|
||||||
m_popRangeCache.insert( id, pPopRange );
|
}
|
||||||
}
|
case LgbEntryType::PopRange:
|
||||||
else if( pEntry->getType() == LgbEntryType::CollisionBox )
|
{
|
||||||
{
|
auto pPopRange = std::reinterpret_pointer_cast< LGB_POP_RANGE_ENTRY >( pEntry );
|
||||||
//auto pEObj = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry );
|
m_popRangeCache.insert( id, pPopRange );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LgbEntryType::CollisionBox:
|
||||||
|
{
|
||||||
|
//auto pEObj = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry );
|
||||||
|
|
||||||
//Logger::debug( "CollisionBox {}", pEntry->header.nameOffset );
|
//Logger::debug( "CollisionBox {}", pEntry->header.nameOffset );
|
||||||
}
|
break;
|
||||||
else if( pEntry->getType() == LgbEntryType::EventObject )
|
}
|
||||||
{
|
case LgbEntryType::EventObject:
|
||||||
auto pEObj = std::reinterpret_pointer_cast< LGB_EOBJ_ENTRY >( pEntry );
|
{
|
||||||
m_eobjCache.insert( id, pEObj );
|
auto pEObj = std::reinterpret_pointer_cast< LGB_EOBJ_ENTRY >( pEntry );
|
||||||
}
|
m_eobjCache.insert( id, pEObj );
|
||||||
else if( pEntry->getType() == LgbEntryType::EventNpc )
|
break;
|
||||||
{
|
}
|
||||||
auto pENpc = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry );
|
case LgbEntryType::EventNpc:
|
||||||
m_enpcCache.insert( id, pENpc );
|
{
|
||||||
}
|
auto pENpc = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry );
|
||||||
else if( pEntry->getType() == LgbEntryType::EventRange )
|
m_enpcCache.insert( id, pENpc );
|
||||||
{
|
break;
|
||||||
auto pEventRange = std::reinterpret_pointer_cast< LGB_EVENT_RANGE_ENTRY >( pEntry );
|
}
|
||||||
m_eventRangeCache.insert( 0, pEventRange );
|
case LgbEntryType::EventRange:
|
||||||
|
{
|
||||||
|
auto pEventRange = std::reinterpret_pointer_cast< LGB_EVENT_RANGE_ENTRY >( pEntry );
|
||||||
|
m_eventRangeCache.insert( 0, pEventRange );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} );
|
||||||
std::cout << "\n";
|
|
||||||
|
|
||||||
Logger::debug(
|
Logger::debug(
|
||||||
"InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {} EventObj: {} EventNpc: {} EventRange: {}",
|
"InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {} EventObj: {} EventNpc: {} EventRange: {}",
|
||||||
|
|
Loading…
Add table
Reference in a new issue