add GameThreadPool

This commit is contained in:
savis
2026-01-05 17:20:12 +01:00
parent dbdfd57c41
commit 7718c65d7a
12 changed files with 575 additions and 285 deletions

View File

@@ -939,6 +939,13 @@ unsigned __GetWindowMode(bool windowed)
bool CPythonApplication::Create(PyObject * poSelf, const char * c_szName, int width, int height, int Windowed)
{
// Initialize Game Thread Pool first - required by other systems
CGameThreadPool* pThreadPool = CGameThreadPool::InstancePtr();
if (pThreadPool)
{
pThreadPool->Initialize();
}
NANOBEGIN
Windowed = CPythonSystem::Instance().IsWindowed() ? 1 : 0;
@@ -1250,6 +1257,9 @@ void CPythonApplication::Destroy()
m_kEftMgr.Destroy();
m_LightManager.Destroy();
// Game Thread Pool
CGameThreadPool::Instance().Destroy();
// DEFAULT_FONT
DefaultFont_Cleanup();
// END_OF_DEFAULT_FONT

View File

@@ -6,6 +6,7 @@
#include "eterLib/GrpDevice.h"
#include "eterLib/NetDevice.h"
#include "eterLib/GrpLightManager.h"
#include "eterLib/GameThreadPool.h"
#include "EffectLib/EffectManager.h"
#include "gamelib/RaceManager.h"
#include "gamelib/ItemManager.h"

View File

@@ -10,6 +10,7 @@
#endif
#include "eterLib/Util.h"
#include "EterLib/GameThreadPool.h"
#include "EterBase/lzo.h"
#include "PackLib/PackManager.h"
@@ -180,14 +181,16 @@ bool PackInitialize(const char * c_pszFolder)
const size_t packsPerThread = (packFiles.size() + numThreads - 1) / numThreads;
std::vector<std::thread> threads;
threads.reserve(numThreads); // Pre-allocate to prevent reallocation
std::atomic<size_t> failedCount(0);
// Create all threads first (prevents vector reallocation during emplace_back)
for (size_t t = 0; t < numThreads; ++t)
{
threads.emplace_back([&, t]() {
size_t start = t * packsPerThread;
size_t end = std::min(start + packsPerThread, packFiles.size());
size_t start = t * packsPerThread;
size_t end = std::min(start + packsPerThread, packFiles.size());
threads.emplace_back([&failedCount, &packFiles, c_pszFolder, start, end]() {
for (size_t i = start; i < end; ++i)
{
std::string packPath = std::format("{}/{}.pck", c_pszFolder, packFiles[i]);
@@ -296,6 +299,9 @@ static bool Main(HINSTANCE hInstance, LPSTR lpCmdLine)
return false;
}
// Create game thread pool singleton before CPythonApplication
static CGameThreadPool gameThreadPool;
auto app = new CPythonApplication;
app->Initialize (hInstance);
CPythonLauncher pyLauncher;