2019-10-21 23:24:26 +02:00
|
|
|
#include "InstanceObjectCache.h"
|
2021-11-27 00:53:57 +01:00
|
|
|
#include "Exd/ExdData.h"
|
2019-10-21 23:24:26 +02:00
|
|
|
|
|
|
|
#include <datReader/DatCategories/bg/pcb.h>
|
|
|
|
#include <datReader/DatCategories/bg/lgb.h>
|
|
|
|
#include <datReader/DatCategories/bg/sgb.h>
|
|
|
|
#include <GameData.h>
|
|
|
|
#include <File.h>
|
|
|
|
#include <DatCat.h>
|
|
|
|
#include <ExdData.h>
|
|
|
|
#include <ExdCat.h>
|
|
|
|
#include <Exd.h>
|
|
|
|
|
2020-01-05 20:36:52 +11:00
|
|
|
#include <Logging/Logger.h>
|
2020-03-01 01:00:57 +11:00
|
|
|
#include <Service.h>
|
2020-01-05 20:36:52 +11:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
Sapphire::InstanceObjectCache::InstanceObjectCache()
|
2019-10-21 23:24:26 +02:00
|
|
|
{
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& exdData = Common::Service< Sapphire::Data::ExdData >::ref();
|
2022-01-27 21:24:54 +01:00
|
|
|
auto idList = exdData.getIdList< Excel::TerritoryType >();
|
2019-10-21 23:24:26 +02:00
|
|
|
|
|
|
|
size_t count = 0;
|
|
|
|
for( const auto& id : idList )
|
|
|
|
{
|
|
|
|
// show some loading indication...
|
|
|
|
if( count++ % 10 == 0 )
|
|
|
|
std::cout << ".";
|
|
|
|
|
2022-01-27 21:24:54 +01:00
|
|
|
auto territoryType = exdData.getRow< Excel::TerritoryType >( id );
|
2019-10-21 23:24:26 +02:00
|
|
|
if( !territoryType )
|
|
|
|
continue;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto path = territoryType->getString( territoryType->data().LVB );
|
2019-10-21 23:24:26 +02:00
|
|
|
|
|
|
|
if( path.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
path = std::string( "bg/" ) + path.substr( 0, path.find( "/level/" ) );
|
|
|
|
|
|
|
|
// TODO: it does feel like this needs to be streamlined into the datReader instead of being done here...
|
|
|
|
std::string bgLgbPath( path + "/level/bg.lgb" );
|
|
|
|
std::string planmapLgbPath( path + "/level/planmap.lgb" );
|
2022-01-22 11:34:56 +01:00
|
|
|
std::string planeventLgbPath( path + "/level/planevent.lgb" );
|
2019-10-21 23:24:26 +02:00
|
|
|
std::vector< char > bgSection;
|
|
|
|
std::vector< char > planmapSection;
|
2022-01-22 11:34:56 +01:00
|
|
|
std::vector< char > planeventSection;
|
2019-10-21 23:24:26 +02:00
|
|
|
|
2020-01-05 20:36:52 +11:00
|
|
|
std::unique_ptr< xiv::dat::File > bgFile;
|
|
|
|
std::unique_ptr< xiv::dat::File > planmap_file;
|
2022-01-22 11:34:56 +01:00
|
|
|
std::unique_ptr< xiv::dat::File > planevent_file;
|
2020-01-05 20:36:52 +11:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
bgFile = exdData.getGameData()->getFile( bgLgbPath );
|
|
|
|
planmap_file = exdData.getGameData()->getFile( planmapLgbPath );
|
2022-01-22 11:34:56 +01:00
|
|
|
planevent_file = exdData.getGameData()->getFile( planeventLgbPath );
|
2020-01-05 20:36:52 +11:00
|
|
|
}
|
|
|
|
catch( std::runtime_error& )
|
|
|
|
{
|
|
|
|
// ignore files that aren't found
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-21 23:24:26 +02:00
|
|
|
|
2020-01-05 20:36:52 +11:00
|
|
|
bgSection = bgFile->access_data_sections().at( 0 );
|
2019-10-21 23:24:26 +02:00
|
|
|
planmapSection = planmap_file->access_data_sections().at( 0 );
|
2022-01-22 11:34:56 +01:00
|
|
|
planeventSection = planevent_file->access_data_sections().at( 0 );
|
2019-10-21 23:24:26 +02:00
|
|
|
|
|
|
|
std::vector< std::string > stringList;
|
|
|
|
|
|
|
|
uint32_t offset1 = 0x20;
|
|
|
|
|
|
|
|
LGB_FILE bgLgb( &bgSection[ 0 ], "bg" );
|
|
|
|
LGB_FILE planmapLgb( &planmapSection[ 0 ], "planmap" );
|
2022-01-22 11:34:56 +01:00
|
|
|
LGB_FILE planeventLgb( &planeventSection[ 0 ], "planevent" );
|
2019-10-21 23:24:26 +02:00
|
|
|
|
2022-01-22 11:34:56 +01:00
|
|
|
std::vector< LGB_FILE > lgbList{ bgLgb, planmapLgb, planeventLgb };
|
2019-10-21 23:24:26 +02:00
|
|
|
uint32_t max_index = 0;
|
|
|
|
|
|
|
|
for( const auto& lgb : lgbList )
|
|
|
|
{
|
|
|
|
for( const auto& group : lgb.groups )
|
|
|
|
{
|
|
|
|
for( const auto& pEntry : group.entries )
|
|
|
|
{
|
2022-01-30 22:32:03 +01:00
|
|
|
|
2019-10-21 23:24:26 +02:00
|
|
|
if( pEntry->getType() == LgbEntryType::MapRange )
|
|
|
|
{
|
2020-01-11 18:20:06 +11:00
|
|
|
auto pMapRange = std::reinterpret_pointer_cast< LGB_MAP_RANGE_ENTRY >( pEntry );
|
|
|
|
m_mapRangeCache.insert( id, pMapRange );
|
2019-10-21 23:24:26 +02:00
|
|
|
}
|
|
|
|
else if( pEntry->getType() == LgbEntryType::ExitRange )
|
|
|
|
{
|
2020-01-11 18:20:06 +11:00
|
|
|
auto pExitRange = std::reinterpret_pointer_cast< LGB_EXIT_RANGE_ENTRY >( pEntry );
|
|
|
|
m_exitRangeCache.insert( id, pExitRange );
|
2019-10-21 23:24:26 +02:00
|
|
|
}
|
|
|
|
else if( pEntry->getType() == LgbEntryType::PopRange )
|
|
|
|
{
|
2020-01-11 18:20:06 +11:00
|
|
|
auto pPopRange = std::reinterpret_pointer_cast< LGB_POP_RANGE_ENTRY >( pEntry );
|
|
|
|
m_popRangeCache.insert( id, pPopRange );
|
2019-10-21 23:24:26 +02:00
|
|
|
}
|
2022-02-05 23:31:35 +01:00
|
|
|
else if( pEntry->getType() == LgbEntryType::CollisionBox )
|
2022-01-18 08:03:49 +01:00
|
|
|
{
|
2022-02-05 23:31:35 +01:00
|
|
|
//auto pEObj = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry );
|
2022-01-18 08:03:49 +01:00
|
|
|
|
2022-02-05 23:31:35 +01:00
|
|
|
//Logger::debug( "CollisionBox {}", pEntry->header.nameOffset );
|
2022-01-18 08:03:49 +01:00
|
|
|
}
|
2022-01-23 23:00:50 +01:00
|
|
|
else if( pEntry->getType() == LgbEntryType::EventObject )
|
|
|
|
{
|
|
|
|
auto pEObj = std::reinterpret_pointer_cast< LGB_EOBJ_ENTRY >( pEntry );
|
|
|
|
m_eobjCache.insert( 0, pEObj );
|
|
|
|
}
|
|
|
|
else if( pEntry->getType() == LgbEntryType::EventNpc )
|
|
|
|
{
|
|
|
|
auto pENpc = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry );
|
|
|
|
m_enpcCache.insert( 0, pENpc );
|
|
|
|
}
|
2022-01-30 22:32:03 +01:00
|
|
|
else if( pEntry->getType() == LgbEntryType::EventRange )
|
|
|
|
{
|
|
|
|
auto pEventRange = std::reinterpret_pointer_cast< LGB_EVENT_RANGE_ENTRY >( pEntry );
|
|
|
|
m_eventRangeCache.insert( 0, pEventRange );
|
|
|
|
}
|
2019-10-21 23:24:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "\n";
|
2020-01-05 20:36:52 +11:00
|
|
|
|
|
|
|
Logger::debug(
|
2022-01-30 22:32:03 +01:00
|
|
|
"InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {} EventNpc: {} EventRange: {}",
|
|
|
|
m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size(), m_enpcCache.size(), m_eventRangeCache.size()
|
2020-01-05 20:36:52 +11:00
|
|
|
);
|
2019-10-21 23:24:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Sapphire::InstanceObjectCache::MapRangePtr
|
|
|
|
Sapphire::InstanceObjectCache::getMapRange( uint16_t zoneId, uint32_t mapRangeId )
|
|
|
|
{
|
|
|
|
return m_mapRangeCache.get( zoneId, mapRangeId );
|
|
|
|
}
|
|
|
|
|
|
|
|
Sapphire::InstanceObjectCache::ExitRangePtr
|
|
|
|
Sapphire::InstanceObjectCache::getExitRange( uint16_t zoneId, uint32_t exitRangeId )
|
|
|
|
{
|
|
|
|
return m_exitRangeCache.get( zoneId, exitRangeId );
|
|
|
|
}
|
|
|
|
|
|
|
|
Sapphire::InstanceObjectCache::PopRangePtr
|
|
|
|
Sapphire::InstanceObjectCache::getPopRange( uint16_t zoneId, uint32_t popRangeId )
|
|
|
|
{
|
|
|
|
return m_popRangeCache.get( zoneId, popRangeId );
|
2022-01-23 23:00:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Sapphire::InstanceObjectCache::EObjPtr
|
|
|
|
Sapphire::InstanceObjectCache::getEObj( uint32_t eObjId )
|
|
|
|
{
|
|
|
|
return m_eobjCache.get( 0, eObjId );
|
|
|
|
}
|
|
|
|
|
|
|
|
Sapphire::InstanceObjectCache::ENpcPtr
|
|
|
|
Sapphire::InstanceObjectCache::getENpc( uint32_t eNpcId )
|
|
|
|
{
|
|
|
|
return m_enpcCache.get( 0, eNpcId );
|
2022-01-30 22:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Sapphire::InstanceObjectCache::EventRangePtr Sapphire::InstanceObjectCache::getEventRange( uint32_t eventRangeId )
|
|
|
|
{
|
|
|
|
return m_eventRangeCache.get( 0, eventRangeId );
|
|
|
|
}
|