mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 22:37:45 +00:00
commit
a155420786
6 changed files with 86 additions and 32 deletions
|
@ -65,8 +65,20 @@ public:
|
||||||
return pFile;
|
return pFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void purge()
|
||||||
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
_purge();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _purge()
|
||||||
|
{
|
||||||
|
m_lgbCache.clear();
|
||||||
|
m_sgbCache.clear();
|
||||||
|
m_pcbCache.clear();
|
||||||
|
//std::cout << "Purged PCB/SGB/LGB cache \n";
|
||||||
|
}
|
||||||
template< typename T >
|
template< typename T >
|
||||||
std::shared_ptr< T > loadFile( const std::string& filepath )
|
std::shared_ptr< T > loadFile( const std::string& filepath )
|
||||||
{
|
{
|
||||||
|
@ -80,10 +92,7 @@ private:
|
||||||
m_totalFiles++;
|
m_totalFiles++;
|
||||||
if( m_totalFiles % 1000 == 0 )
|
if( m_totalFiles % 1000 == 0 )
|
||||||
{
|
{
|
||||||
m_lgbCache.clear();
|
_purge();
|
||||||
m_sgbCache.clear();
|
|
||||||
m_pcbCache.clear();
|
|
||||||
std::cout << "Purged PCB/SGB/LGB cache \n";
|
|
||||||
m_totalFiles = 1;
|
m_totalFiles = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,16 @@ public:
|
||||||
waitForTasks();
|
waitForTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restart( bool cancel = false, unsigned int maxJobs = 0 )
|
||||||
|
{
|
||||||
|
if( cancel )
|
||||||
|
m_threadpool.cancel();
|
||||||
|
|
||||||
|
m_threadpool.complete();
|
||||||
|
|
||||||
|
m_threadpool.addWorkers( maxJobs );
|
||||||
|
}
|
||||||
|
|
||||||
void exportZone(const ExportedZone& zone, ExportFileType exportFileTypes)
|
void exportZone(const ExportedZone& zone, ExportFileType exportFileTypes)
|
||||||
{
|
{
|
||||||
m_threadpool.queue( [zone, exportFileTypes]()
|
m_threadpool.queue( [zone, exportFileTypes]()
|
||||||
|
@ -32,14 +42,17 @@ public:
|
||||||
|
|
||||||
void exportGroup( const std::string& zoneName, const ExportedGroup& group, ExportFileType exportFileTypes )
|
void exportGroup( const std::string& zoneName, const ExportedGroup& group, ExportFileType exportFileTypes )
|
||||||
{
|
{
|
||||||
if( exportFileTypes & ExportFileType::WavefrontObj )
|
m_threadpool.queue( [zoneName, group, exportFileTypes]()
|
||||||
{
|
{
|
||||||
m_threadpool.queue( [zoneName, group](){ ObjExporter::exportGroup( zoneName, group ); } );
|
if( exportFileTypes & ExportFileType::WavefrontObj )
|
||||||
}
|
{
|
||||||
// if( exportFileTypes & ExportFileType::Navmesh )
|
ObjExporter::exportGroup( zoneName, group );
|
||||||
// {
|
}
|
||||||
// m_threadpool.queue( [zoneName, group](){ NavmeshExporter::exportGroup( zoneName, group ); } );
|
if( exportFileTypes & ExportFileType::Navmesh )
|
||||||
// }
|
{
|
||||||
|
NavmeshExporter::exportGroup( zoneName, group );
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForTasks()
|
void waitForTasks()
|
||||||
|
|
|
@ -335,7 +335,7 @@ struct LGB_GROUP
|
||||||
entries.push_back( std::make_shared< LGB_EOBJ_ENTRY >( buf, entryOffset ) );
|
entries.push_back( std::make_shared< LGB_EOBJ_ENTRY >( buf, entryOffset ) );
|
||||||
break;
|
break;
|
||||||
case LgbEntryType::CollisionBox:
|
case LgbEntryType::CollisionBox:
|
||||||
entries.push_back( std::make_shared< LGB_COLLISION_BOX_ENTRY >( buf, entryOffset ) );
|
//entries.push_back( std::make_shared< LGB_COLLISION_BOX_ENTRY >( buf, entryOffset ) );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//std::cout << "\t\tUnknown SGB entry! Group: " << name << " type: " << ( int )type << " index: " << i << " entryOffset: " << entryOffset << "\n";
|
//std::cout << "\t\tUnknown SGB entry! Group: " << name << " type: " << ( int )type << " index: " << i << " entryOffset: " << entryOffset << "\n";
|
||||||
|
|
|
@ -156,16 +156,36 @@ int main( int argc, char* argv[] )
|
||||||
std::vector< std::string > argVec( argv + 1, argv + argc );
|
std::vector< std::string > argVec( argv + 1, argv + argc );
|
||||||
std::string zoneName = "r2t2";
|
std::string zoneName = "r2t2";
|
||||||
|
|
||||||
noObj = std::remove_if( argVec.begin(), argVec.end(), []( auto arg )
|
noObj = std::find_if( argVec.begin(), argVec.end(), []( auto arg )
|
||||||
{ return arg == "--no-obj"; } ) != argVec.end();
|
{ return arg == "--no-obj"; } ) != argVec.end();
|
||||||
bool dumpAllZones = std::remove_if( argVec.begin(), argVec.end(), []( auto arg )
|
bool dumpAllZones = std::find_if( argVec.begin(), argVec.end(), []( auto arg )
|
||||||
{ return arg == "--dump-all"; } ) != argVec.end();
|
{ return arg == "--dump-all"; } ) != argVec.end();
|
||||||
bool generateNavmesh = std::remove_if( argVec.begin(), argVec.end(), []( auto arg )
|
bool generateNavmesh = std::find_if( argVec.begin(), argVec.end(), []( auto arg )
|
||||||
{ return arg == "--navmesh"; } ) != argVec.end();
|
{ return arg == "--navmesh"; } ) != argVec.end();
|
||||||
bool splitByGroup = std::remove_if( argVec.begin(), argVec.end(), []( auto arg )
|
bool splitByGroup = std::find_if( argVec.begin(), argVec.end(), []( auto arg )
|
||||||
{ return arg == "--split-by-group"; }) != argVec.end();
|
{ return arg == "--split-by-group"; }) != argVec.end();
|
||||||
bool splitByZone = std::remove_if( argVec.begin(), argVec.end(), []( auto arg )
|
bool splitByZone = std::find_if( argVec.begin(), argVec.end(), []( auto arg )
|
||||||
{ return arg == "--split-by-zone"; }) != argVec.end();
|
{ return arg == "--split-by-zone"; }) != argVec.end();
|
||||||
|
int nJobs = std::thread::hardware_concurrency();
|
||||||
|
if( auto it = std::find_if( argVec.begin(), argVec.end(), []( auto arg )
|
||||||
|
{ return arg == "--jobs"; }); it != argVec.end() )
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto it2 = ( it + 1 );
|
||||||
|
nJobs = std::stoi( *it2 );
|
||||||
|
if( nJobs < 0 )
|
||||||
|
throw std::runtime_error( "Number of jobs < 0\n" );
|
||||||
|
}
|
||||||
|
catch( std::exception& e )
|
||||||
|
{
|
||||||
|
std::cout << e.what() << "\n";
|
||||||
|
std::cout << "Invalid number of jobs " << nJobs << "\n";
|
||||||
|
std::cout << "--jobs <numberOfJobs>\n";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
int exportFileType = 0;
|
int exportFileType = 0;
|
||||||
if( !noObj )
|
if( !noObj )
|
||||||
exportFileType |= ExportFileType::WavefrontObj;
|
exportFileType |= ExportFileType::WavefrontObj;
|
||||||
|
@ -190,10 +210,10 @@ int main( int argc, char* argv[] )
|
||||||
}
|
}
|
||||||
catch( std::exception& e )
|
catch( std::exception& e )
|
||||||
{
|
{
|
||||||
printf( "Unable to initialise EXD!\n Usage: pcb_reader <teri> \"path/to/FINAL FANTASY XIV - A REALM REBORN/game/sqpack\" [--no-obj, --dump-all, --navmesh]\n" );
|
printf( "Unable to initialise EXD!\n Usage: pcb_reader <teri> \"path/to/FINAL FANTASY XIV - A REALM REBORN/game/sqpack\" [--no-obj, --dump-all, --navmesh, --jobs #]\n" );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ExportMgr exportMgr;
|
ExportMgr exportMgr( nJobs );
|
||||||
zoneNameToPath( zoneName );
|
zoneNameToPath( zoneName );
|
||||||
|
|
||||||
if( dumpAllZones )
|
if( dumpAllZones )
|
||||||
|
@ -206,6 +226,7 @@ int main( int argc, char* argv[] )
|
||||||
zoneDumpList.emplace( zoneName );
|
zoneDumpList.emplace( zoneName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int zoneCount = 0;
|
||||||
for( auto zoneName : zoneDumpList )
|
for( auto zoneName : zoneDumpList )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -496,10 +517,14 @@ int main( int argc, char* argv[] )
|
||||||
}
|
}
|
||||||
exportMgr.exportZone( exportedZone, static_cast< ExportFileType >( exportFileType ) );
|
exportMgr.exportZone( exportedZone, static_cast< ExportFileType >( exportFileType ) );
|
||||||
|
|
||||||
|
printf( "Built export struct for %s in %lu seconds \n",
|
||||||
printf( "Exported %s in %lu seconds \n",
|
|
||||||
zoneName.c_str(),
|
zoneName.c_str(),
|
||||||
std::chrono::duration_cast< std::chrono::seconds >( std::chrono::high_resolution_clock::now() - entryStartTime ).count() );
|
std::chrono::duration_cast< std::chrono::seconds >( std::chrono::high_resolution_clock::now() - entryStartTime ).count() );
|
||||||
|
if( zoneCount++ % nJobs == 0 )
|
||||||
|
{
|
||||||
|
exportMgr.restart();
|
||||||
|
pCache->purge();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch( std::exception& e )
|
catch( std::exception& e )
|
||||||
{
|
{
|
||||||
|
@ -508,6 +533,7 @@ int main( int argc, char* argv[] )
|
||||||
printf( "Usage: pcb_reader2 territory \"path/to/game/sqpack/ffxiv\"\n" );
|
printf( "Usage: pcb_reader2 territory \"path/to/game/sqpack/ffxiv\"\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pCache->purge();
|
||||||
exportMgr.waitForTasks();
|
exportMgr.waitForTasks();
|
||||||
std::cout << "\n\n\n";
|
std::cout << "\n\n\n";
|
||||||
|
|
||||||
|
|
|
@ -87,14 +87,19 @@ bool TiledNavmeshGenerator::init( const std::string& path )
|
||||||
|
|
||||||
TiledNavmeshGenerator::~TiledNavmeshGenerator()
|
TiledNavmeshGenerator::~TiledNavmeshGenerator()
|
||||||
{
|
{
|
||||||
if( m_mesh )
|
delete m_mesh;
|
||||||
delete m_mesh;
|
delete m_chunkyMesh;
|
||||||
if( m_chunkyMesh )
|
|
||||||
delete m_chunkyMesh;
|
|
||||||
|
|
||||||
if( m_ctx )
|
if( m_triareas )
|
||||||
delete m_ctx;
|
delete[] m_triareas;
|
||||||
|
if( m_solid )
|
||||||
|
delete m_solid;
|
||||||
|
delete m_ctx;
|
||||||
|
|
||||||
|
rcFreeContourSet( m_cset );
|
||||||
|
rcFreeCompactHeightfield(m_chf);
|
||||||
|
rcFreePolyMesh( m_pmesh );
|
||||||
|
rcFreePolyMeshDetail( m_dmesh );
|
||||||
dtFreeNavMesh( m_navMesh );
|
dtFreeNavMesh( m_navMesh );
|
||||||
dtFreeNavMeshQuery( m_navQuery );
|
dtFreeNavMeshQuery( m_navQuery );
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,14 @@ public:
|
||||||
|
|
||||||
auto dir = fs::current_path().string() + "/pcb_export/" + zone.name + "/";
|
auto dir = fs::current_path().string() + "/pcb_export/" + zone.name + "/";
|
||||||
auto fileName = dir + zone.name;
|
auto fileName = dir + zone.name;
|
||||||
|
auto objName = fileName + ".obj";
|
||||||
|
|
||||||
std::error_code e;
|
std::error_code e;
|
||||||
if( !fs::exists( fileName, e ) )
|
if( !fs::exists( objName, e ) )
|
||||||
ObjExporter::exportZone( zone );
|
ObjExporter::exportZone( zone );
|
||||||
|
{
|
||||||
TiledNavmeshGenerator gen;
|
TiledNavmeshGenerator gen;
|
||||||
|
|
||||||
auto objName = fileName + ".obj";
|
|
||||||
if( !gen.init( objName ) )
|
if( !gen.init( objName ) )
|
||||||
{
|
{
|
||||||
printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", zone.name.c_str() );
|
printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", zone.name.c_str() );
|
||||||
|
@ -48,6 +48,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
gen.saveNavmesh( zone.name );
|
gen.saveNavmesh( zone.name );
|
||||||
|
}
|
||||||
|
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
printf( "[Navmesh] Finished exporting %s in %lu ms\n",
|
printf( "[Navmesh] Finished exporting %s in %lu ms\n",
|
||||||
|
@ -64,15 +65,15 @@ public:
|
||||||
|
|
||||||
auto dir = fs::current_path().string() + "/pcb_export/" + zoneName + "/";
|
auto dir = fs::current_path().string() + "/pcb_export/" + zoneName + "/";
|
||||||
auto fileName = dir + zoneName + "_" + group.name;
|
auto fileName = dir + zoneName + "_" + group.name;
|
||||||
|
auto objName = fileName + ".obj";
|
||||||
|
|
||||||
std::error_code e;
|
std::error_code e;
|
||||||
if( !fs::exists( fileName, e ) )
|
if( !fs::exists( objName, e ) )
|
||||||
ObjExporter::exportGroup( zoneName, group );
|
ObjExporter::exportGroup( zoneName, group );
|
||||||
|
|
||||||
|
|
||||||
TiledNavmeshGenerator gen;
|
TiledNavmeshGenerator gen;
|
||||||
|
|
||||||
auto objName = fileName + ".obj";
|
|
||||||
if( !gen.init( objName ) )
|
if( !gen.init( objName ) )
|
||||||
{
|
{
|
||||||
printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", fileName.c_str() );
|
printf( "[Navmesh] failed to init TiledNavmeshGenerator for file '%s'\n", fileName.c_str() );
|
||||||
|
|
Loading…
Add table
Reference in a new issue