mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-23 10:17:44 +00:00
more cache and lgb update
This commit is contained in:
parent
76f540e881
commit
fc4bf84f84
5 changed files with 79 additions and 54 deletions
75
deps/datReader/DatCategories/bg/lgb.h
vendored
75
deps/datReader/DatCategories/bg/lgb.h
vendored
|
@ -1,5 +1,4 @@
|
||||||
#ifndef _LGB_H
|
#pragma once
|
||||||
#define _LGB_H
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -46,28 +45,25 @@ public:
|
||||||
return header.type;
|
return header.type;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~LgbEntry()
|
virtual ~LgbEntry(){};
|
||||||
{
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LGB_BGPARTS_ENTRY : public LgbEntry
|
class LGB_BGPARTS_ENTRY : public LgbEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BgPartsData data;
|
BgPartsData data;
|
||||||
std::string name;
|
std::string_view name;
|
||||||
std::string modelFileName;
|
std::string_view modelFileName;
|
||||||
std::string collisionFileName;
|
std::string_view collisionFileName;
|
||||||
|
|
||||||
LGB_BGPARTS_ENTRY() = default;
|
LGB_BGPARTS_ENTRY() = default;
|
||||||
|
|
||||||
LGB_BGPARTS_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
LGB_BGPARTS_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
||||||
{
|
{
|
||||||
data = *reinterpret_cast< BgPartsData* >( buf + offset );
|
data = *reinterpret_cast< BgPartsData* >( buf + offset );
|
||||||
name = std::string( buf + offset + header.nameOffset );
|
name = std::string_view( buf + offset + header.nameOffset );
|
||||||
modelFileName = std::string( buf + offset + data.modelFileOffset );
|
modelFileName = std::string_view( buf + offset + data.modelFileOffset );
|
||||||
collisionFileName = std::string( buf + offset + data.collisionFileOffset );
|
collisionFileName = std::string_view( buf + offset + data.collisionFileOffset );
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,72 +71,66 @@ class LGB_GIMMICK_ENTRY : public LgbEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GimmickData data;
|
GimmickData data;
|
||||||
std::string name;
|
std::string_view name;
|
||||||
std::string gimmickFileName;
|
std::string_view gimmickFileName;
|
||||||
|
|
||||||
LGB_GIMMICK_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
LGB_GIMMICK_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
||||||
{
|
{
|
||||||
data = *reinterpret_cast< GimmickData* >( buf + offset );
|
data = *reinterpret_cast< GimmickData* >( buf + offset );
|
||||||
name = std::string( buf + offset + header.nameOffset );
|
name = std::string_view( buf + offset + header.nameOffset );
|
||||||
gimmickFileName = std::string( buf + offset + data.gimmickFileOffset );
|
gimmickFileName = std::string_view( buf + offset + data.gimmickFileOffset );
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LGB_ENPC_ENTRY : public LgbEntry
|
struct LGB_ENPC_ENTRY : public LgbEntry {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
ENpcData data;
|
ENpcData data;
|
||||||
std::string name;
|
std::string_view name;
|
||||||
|
|
||||||
LGB_ENPC_ENTRY( char* buf, size_t offset ) :
|
LGB_ENPC_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
||||||
LgbEntry( buf, offset )
|
|
||||||
{
|
{
|
||||||
data = *reinterpret_cast< ENpcData* >( 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:
|
public:
|
||||||
EObjData data;
|
EObjData data;
|
||||||
std::string name;
|
std::string_view name;
|
||||||
|
|
||||||
LGB_EOBJ_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
LGB_EOBJ_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
||||||
{
|
{
|
||||||
data = *reinterpret_cast< EObjData* >( 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:
|
public:
|
||||||
MapRangeData data;
|
MapRangeData data;
|
||||||
std::string name;
|
std::string_view name;
|
||||||
|
|
||||||
LGB_MAP_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
LGB_MAP_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
||||||
{
|
{
|
||||||
data = *reinterpret_cast< MapRangeData* >( 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:
|
public:
|
||||||
ExitRangeData data;
|
ExitRangeData data;
|
||||||
std::string name;
|
std::string_view name;
|
||||||
|
|
||||||
LGB_EXIT_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
LGB_EXIT_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset )
|
||||||
{
|
{
|
||||||
data = *reinterpret_cast< ExitRangeData* >( 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:
|
public:
|
||||||
PopRangeData data;
|
PopRangeData data;
|
||||||
|
|
||||||
|
@ -150,8 +140,7 @@ public:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LGB_EVENT_RANGE_ENTRY : public LgbEntry
|
struct LGB_EVENT_RANGE_ENTRY : public LgbEntry {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
EventRangeData data;
|
EventRangeData data;
|
||||||
|
|
||||||
|
@ -224,7 +213,7 @@ struct LGB_GROUP
|
||||||
if( layerSetReferencedList.LayerSetCount > 0 )
|
if( layerSetReferencedList.LayerSetCount > 0 )
|
||||||
{
|
{
|
||||||
refs.resize( layerSetReferencedList.LayerSetCount );
|
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 );
|
entries.reserve( header.entryCount );
|
||||||
|
@ -307,8 +296,7 @@ struct LGB_FILE_HEADER
|
||||||
int32_t groupCount;
|
int32_t groupCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LGB_FILE
|
struct LGB_FILE {
|
||||||
{
|
|
||||||
LGB_FILE_HEADER header;
|
LGB_FILE_HEADER header;
|
||||||
std::vector< LGB_GROUP > groups;
|
std::vector< LGB_GROUP > groups;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
@ -325,11 +313,11 @@ struct LGB_FILE
|
||||||
throw std::runtime_error( "Invalid LGB file!" );
|
throw std::runtime_error( "Invalid LGB file!" );
|
||||||
|
|
||||||
constexpr auto baseOffset = sizeof( header );
|
constexpr auto baseOffset = sizeof( header );
|
||||||
|
groups.reserve( header.groupCount );
|
||||||
for( size_t i = 0; i < header.groupCount; ++i )
|
for( size_t i = 0; i < header.groupCount; ++i )
|
||||||
{
|
{
|
||||||
const auto groupOffset = baseOffset + *reinterpret_cast< int32_t* >( buf + ( baseOffset + i * 4 ) );
|
const auto groupOffset = baseOffset + *reinterpret_cast< int32_t* >( buf + ( baseOffset + i * 4 ) );
|
||||||
const auto group = LGB_GROUP( buf, this, groupOffset );
|
groups.emplace_back( buf, this, groupOffset );
|
||||||
groups.push_back( group );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -368,4 +356,3 @@ std::map<std::string, LGB_FILE> getLgbFiles( const std::string& dir )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
#endif
|
|
|
@ -48,6 +48,8 @@ namespace Sapphire::Data
|
||||||
|
|
||||||
std::unordered_map< std::type_index, xiv::exd::Exd > m_sheets;
|
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::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::dat::GameData > m_data;
|
||||||
std::shared_ptr< xiv::exd::ExdData > m_exd_data;
|
std::shared_ptr< xiv::exd::ExdData > m_exd_data;
|
||||||
};
|
};
|
||||||
|
@ -127,17 +129,36 @@ namespace Sapphire::Data
|
||||||
template< typename T >
|
template< typename T >
|
||||||
std::vector< uint32_t > ExdData::getIdList()
|
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 sheet = getSheet< T >();
|
||||||
auto rows = sheet.get_rows();
|
auto rows = sheet.get_rows();
|
||||||
std::vector< uint32_t > ids;
|
std::vector< uint32_t > ids;
|
||||||
|
ids.reserve( rows.size() );
|
||||||
for( const auto& row : rows ) ids.push_back( row.first );
|
for( const auto& row : rows ) ids.push_back( row.first );
|
||||||
|
|
||||||
|
m_idListCache[ type ] = ids;
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
std::unordered_map< uint32_t, std::shared_ptr< Excel::ExcelStruct< T > > > ExdData::getRows()
|
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
|
}// namespace Sapphire::Data
|
|
@ -337,7 +337,7 @@ int main( int argc, char* argv[] )
|
||||||
auto pGObjR = reinterpret_cast< LGB_GIMMICK_ENTRY* >( pGObj );
|
auto pGObjR = reinterpret_cast< LGB_GIMMICK_ENTRY* >( pGObj );
|
||||||
char* dataSection = nullptr;
|
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();
|
auto sections = file->get_data_sections();
|
||||||
dataSection = §ions.at( 0 )[ 0 ];
|
dataSection = §ions.at( 0 )[ 0 ];
|
||||||
auto sgbFile = SGB_FILE( &dataSection[ 0 ] );
|
auto sgbFile = SGB_FILE( &dataSection[ 0 ] );
|
||||||
|
|
|
@ -45,9 +45,18 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< char > bgSection( bgFile->access_data_sections().at( 0 ) );
|
std::vector< char > bgSection;
|
||||||
std::vector< char > planmapSection( planmap_file->access_data_sections().at( 0 ) );
|
bgSection.reserve( bgFile->access_data_sections().at( 0 ).size() );
|
||||||
std::vector< char > planeventSection( planevent_file->access_data_sections().at( 0 ) );
|
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 bgLgb( bgSection.data(), "bg" );
|
||||||
LGB_FILE planmapLgb( planmapSection.data(), "planmap" );
|
LGB_FILE planmapLgb( planmapSection.data(), "planmap" );
|
||||||
|
@ -58,15 +67,24 @@ Sapphire::InstanceObjectCache::InstanceObjectCache()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
planner_file = loadFile( path + "/level/planner.lgb" );
|
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" );
|
LGB_FILE plannerLgb( plannerSection.data(), "planner" );
|
||||||
|
|
||||||
lgbList.reserve( 4 );
|
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& )
|
} catch( std::runtime_error& )
|
||||||
{
|
{
|
||||||
lgbList.reserve( 3 );
|
lgbList.reserve( 3 );
|
||||||
lgbList = { bgLgb, planmapLgb, planeventLgb };
|
lgbList.emplace_back( bgLgb );
|
||||||
|
lgbList.emplace_back( planmapLgb );
|
||||||
|
lgbList.emplace_back( planeventLgb );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( const auto& lgb : lgbList )
|
for( const auto& lgb : lgbList )
|
||||||
|
|
|
@ -19,7 +19,6 @@ struct LGB_EOBJ_ENTRY;
|
||||||
struct LGB_ENPC_ENTRY;
|
struct LGB_ENPC_ENTRY;
|
||||||
struct LGB_EVENT_RANGE_ENTRY;
|
struct LGB_EVENT_RANGE_ENTRY;
|
||||||
|
|
||||||
|
|
||||||
namespace Sapphire
|
namespace Sapphire
|
||||||
{
|
{
|
||||||
class Framework;
|
class Framework;
|
||||||
|
|
Loading…
Add table
Reference in a new issue