diff --git a/deps/datReader/DatCategories/bg/lgb.h b/deps/datReader/DatCategories/bg/lgb.h index d0c3f29b..547d5b0e 100644 --- a/deps/datReader/DatCategories/bg/lgb.h +++ b/deps/datReader/DatCategories/bg/lgb.h @@ -1,5 +1,4 @@ -#ifndef _LGB_H -#define _LGB_H +#pragma once #include #include @@ -46,28 +45,25 @@ public: return header.type; }; - virtual ~LgbEntry() - { - }; + virtual ~LgbEntry(){}; }; - class LGB_BGPARTS_ENTRY : public LgbEntry { public: BgPartsData data; - std::string name; - std::string modelFileName; - std::string collisionFileName; + std::string_view name; + std::string_view modelFileName; + std::string_view collisionFileName; LGB_BGPARTS_ENTRY() = default; LGB_BGPARTS_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< BgPartsData* >( buf + offset ); - name = std::string( buf + offset + header.nameOffset ); - modelFileName = std::string( buf + offset + data.modelFileOffset ); - collisionFileName = std::string( buf + offset + data.collisionFileOffset ); + name = std::string_view( buf + offset + header.nameOffset ); + modelFileName = std::string_view( buf + offset + data.modelFileOffset ); + collisionFileName = std::string_view( buf + offset + data.collisionFileOffset ); }; }; @@ -75,72 +71,66 @@ class LGB_GIMMICK_ENTRY : public LgbEntry { public: GimmickData data; - std::string name; - std::string gimmickFileName; + std::string_view name; + std::string_view gimmickFileName; LGB_GIMMICK_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< GimmickData* >( buf + offset ); - name = std::string( buf + offset + header.nameOffset ); - gimmickFileName = std::string( buf + offset + data.gimmickFileOffset ); + name = std::string_view( buf + offset + header.nameOffset ); + gimmickFileName = std::string_view( buf + offset + data.gimmickFileOffset ); }; }; -struct LGB_ENPC_ENTRY : public LgbEntry -{ +struct LGB_ENPC_ENTRY : public LgbEntry { public: ENpcData data; - std::string name; + std::string_view name; - LGB_ENPC_ENTRY( char* buf, size_t offset ) : - LgbEntry( buf, offset ) + LGB_ENPC_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< ENpcData* >( buf + offset ); - name = std::string( buf + offset + header.nameOffset ); + name = std::string_view( buf + offset + header.nameOffset ); }; }; -struct LGB_EOBJ_ENTRY : public LgbEntry -{ +struct LGB_EOBJ_ENTRY : public LgbEntry { public: EObjData data; - std::string name; + std::string_view name; LGB_EOBJ_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< EObjData* >( buf + offset ); - name = std::string( buf + offset + header.nameOffset ); + name = std::string_view( buf + offset + header.nameOffset ); }; }; -struct LGB_MAP_RANGE_ENTRY : public LgbEntry -{ +struct LGB_MAP_RANGE_ENTRY : public LgbEntry { public: MapRangeData data; - std::string name; + std::string_view name; LGB_MAP_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< MapRangeData* >( buf + offset ); - name = std::string( buf + offset + header.nameOffset ); + name = std::string_view( buf + offset + header.nameOffset ); }; }; -struct LGB_EXIT_RANGE_ENTRY : public LgbEntry -{ +struct LGB_EXIT_RANGE_ENTRY : public LgbEntry { public: ExitRangeData data; - std::string name; + std::string_view name; LGB_EXIT_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< ExitRangeData* >( buf + offset ); - name = std::string( buf + offset + header.nameOffset ); + name = std::string_view( buf + offset + header.nameOffset ); }; }; -struct LGB_POP_RANGE_ENTRY : public LgbEntry -{ +struct LGB_POP_RANGE_ENTRY : public LgbEntry { public: PopRangeData data; @@ -150,8 +140,7 @@ public: }; }; -struct LGB_EVENT_RANGE_ENTRY : public LgbEntry -{ +struct LGB_EVENT_RANGE_ENTRY : public LgbEntry { public: EventRangeData data; @@ -224,7 +213,7 @@ struct LGB_GROUP if( layerSetReferencedList.LayerSetCount > 0 ) { refs.resize( layerSetReferencedList.LayerSetCount ); - memcpy( (char*)&refs[0], buf + offset + header.LayerSetRef + layerSetReferencedList.LayerSets, layerSetReferencedList.LayerSetCount * sizeof( LayerSetReferenced ) ); + std::memcpy( refs.data(), buf + offset + header.LayerSetRef + layerSetReferencedList.LayerSets, layerSetReferencedList.LayerSetCount * sizeof( LayerSetReferenced ) ); } entries.reserve( header.entryCount ); @@ -307,8 +296,7 @@ struct LGB_FILE_HEADER int32_t groupCount; }; -struct LGB_FILE -{ +struct LGB_FILE { LGB_FILE_HEADER header; std::vector< LGB_GROUP > groups; std::string m_name; @@ -325,11 +313,11 @@ struct LGB_FILE throw std::runtime_error( "Invalid LGB file!" ); constexpr auto baseOffset = sizeof( header ); + groups.reserve( header.groupCount ); for( size_t i = 0; i < header.groupCount; ++i ) { const auto groupOffset = baseOffset + *reinterpret_cast< int32_t* >( buf + ( baseOffset + i * 4 ) ); - const auto group = LGB_GROUP( buf, this, groupOffset ); - groups.push_back( group ); + groups.emplace_back( buf, this, groupOffset ); } }; }; @@ -367,5 +355,4 @@ std::map getLgbFiles( const std::string& dir ) return fileMap; } #endif -*/ -#endif \ No newline at end of file +*/ \ No newline at end of file diff --git a/src/common/Exd/ExdData.h b/src/common/Exd/ExdData.h index d8dcc7e2..c6da5514 100644 --- a/src/common/Exd/ExdData.h +++ b/src/common/Exd/ExdData.h @@ -48,6 +48,8 @@ namespace Sapphire::Data std::unordered_map< std::type_index, xiv::exd::Exd > m_sheets; std::unordered_map< std::type_index, std::string > m_name_cache; + std::unordered_map< std::type_index, std::vector< uint32_t > > m_idListCache; + std::unordered_map< std::type_index, std::unordered_map< uint32_t, std::shared_ptr< void > > > m_rowsCache; std::shared_ptr< xiv::dat::GameData > m_data; std::shared_ptr< xiv::exd::ExdData > m_exd_data; }; @@ -127,17 +129,36 @@ namespace Sapphire::Data template< typename T > std::vector< uint32_t > ExdData::getIdList() { + auto type = std::type_index( typeid( T ) ); + auto it = m_idListCache.find( type ); + if( it != m_idListCache.end() ) + { + return it->second; + } + auto sheet = getSheet< T >(); auto rows = sheet.get_rows(); std::vector< uint32_t > ids; + ids.reserve( rows.size() ); for( const auto& row : rows ) ids.push_back( row.first ); + + m_idListCache[ type ] = ids; return ids; } template< typename T > std::unordered_map< uint32_t, std::shared_ptr< Excel::ExcelStruct< T > > > ExdData::getRows() { - return getSheet< T >().template get_sheet_rows< T >(); + auto type = std::type_index( typeid( T ) ); + auto it = m_rowsCache.find( type ); + if( it != m_rowsCache.end() ) + { + return *reinterpret_cast< std::unordered_map< uint32_t, std::shared_ptr< Excel::ExcelStruct< T > > >* >( &it->second ); + } + + auto rows = getSheet< T >().template get_sheet_rows< T >(); + m_rowsCache[ type ] = *reinterpret_cast< std::unordered_map< uint32_t, std::shared_ptr< void > >* >( &rows ); + return rows; } }// namespace Sapphire::Data \ No newline at end of file diff --git a/src/tools/event_object_parser/main.cpp b/src/tools/event_object_parser/main.cpp index 65321d13..047ce449 100644 --- a/src/tools/event_object_parser/main.cpp +++ b/src/tools/event_object_parser/main.cpp @@ -337,7 +337,7 @@ int main( int argc, char* argv[] ) auto pGObjR = reinterpret_cast< LGB_GIMMICK_ENTRY* >( pGObj ); char* dataSection = nullptr; - auto file = g_gameData->getFile( pGObjR->gimmickFileName ); + auto file = g_gameData->getFile( std::string( pGObjR->gimmickFileName ) ); auto sections = file->get_data_sections(); dataSection = §ions.at( 0 )[ 0 ]; auto sgbFile = SGB_FILE( &dataSection[ 0 ] ); diff --git a/src/world/Territory/InstanceObjectCache.cpp b/src/world/Territory/InstanceObjectCache.cpp index 3f1f16ad..4fcd542b 100644 --- a/src/world/Territory/InstanceObjectCache.cpp +++ b/src/world/Territory/InstanceObjectCache.cpp @@ -45,9 +45,18 @@ Sapphire::InstanceObjectCache::InstanceObjectCache() continue; } - std::vector< char > bgSection( bgFile->access_data_sections().at( 0 ) ); - std::vector< char > planmapSection( planmap_file->access_data_sections().at( 0 ) ); - std::vector< char > planeventSection( planevent_file->access_data_sections().at( 0 ) ); + std::vector< char > bgSection; + bgSection.reserve( bgFile->access_data_sections().at( 0 ).size() ); + bgSection.assign( bgFile->access_data_sections().at( 0 ).begin(), bgFile->access_data_sections().at( 0 ).end() ); + + std::vector< char > planmapSection; + planmapSection.reserve( planmap_file->access_data_sections().at( 0 ).size() ); + planmapSection.assign( planmap_file->access_data_sections().at( 0 ).begin(), planmap_file->access_data_sections().at( 0 ).end() ); + + std::vector< char > planeventSection; + planeventSection.reserve( planevent_file->access_data_sections().at( 0 ).size() ); + planeventSection.assign( planevent_file->access_data_sections().at( 0 ).begin(), planevent_file->access_data_sections().at( 0 ).end() ); + LGB_FILE bgLgb( bgSection.data(), "bg" ); LGB_FILE planmapLgb( planmapSection.data(), "planmap" ); @@ -58,15 +67,24 @@ Sapphire::InstanceObjectCache::InstanceObjectCache() try { planner_file = loadFile( path + "/level/planner.lgb" ); - std::vector< char > plannerSection( planner_file->access_data_sections().at( 0 ) ); + + std::vector< char > plannerSection; + plannerSection.reserve( planner_file->access_data_sections().at( 0 ).size() ); + plannerSection.assign( planner_file->access_data_sections().at( 0 ).begin(), planner_file->access_data_sections().at( 0 ).end() ); + LGB_FILE plannerLgb( plannerSection.data(), "planner" ); lgbList.reserve( 4 ); - lgbList = { bgLgb, planmapLgb, planeventLgb, plannerLgb }; + lgbList.emplace_back( bgLgb ); + lgbList.emplace_back( planmapLgb ); + lgbList.emplace_back( planeventLgb ); + lgbList.emplace_back( plannerLgb ); } catch( std::runtime_error& ) { lgbList.reserve( 3 ); - lgbList = { bgLgb, planmapLgb, planeventLgb }; + lgbList.emplace_back( bgLgb ); + lgbList.emplace_back( planmapLgb ); + lgbList.emplace_back( planeventLgb ); } for( const auto& lgb : lgbList ) diff --git a/src/world/Territory/InstanceObjectCache.h b/src/world/Territory/InstanceObjectCache.h index 16f26559..9c48e681 100644 --- a/src/world/Territory/InstanceObjectCache.h +++ b/src/world/Territory/InstanceObjectCache.h @@ -19,7 +19,6 @@ struct LGB_EOBJ_ENTRY; struct LGB_ENPC_ENTRY; struct LGB_EVENT_RANGE_ENTRY; - namespace Sapphire { class Framework;