Working on running the game even in Telegram
This commit is contained in:
1 parent
5fcb1d1234
commit
e78429b600
9 files changed
+133
-60
No files matched your search
@@ -5,35 +5,52 @@ namespace ZL
|
||||
{
|
||||
|
||||
TaskManager::TaskManager(size_t threadCount) {
|
||||
workGuard = std::make_unique<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>>(ioContext.get_executor());
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
workGuard = std::make_unique<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>>(ioContext.get_executor());
|
||||
|
||||
for (size_t i = 0; i < threadCount; ++i) {
|
||||
workers.emplace_back([this]() {
|
||||
ioContext.run();
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void TaskManager::EnqueueBackgroundTask(std::function<void()> task) {
|
||||
#ifdef EMSCRIPTEN
|
||||
task();
|
||||
#else
|
||||
boost::asio::post(ioContext, task);
|
||||
#endif
|
||||
}
|
||||
|
||||
TaskManager::~TaskManager() {
|
||||
#ifndef EMSCRIPTEN
|
||||
workGuard.reset(); // Ðàçðåøàåì ioContext.run() çàâåðøèòüñÿ, êîãäà çàäà÷ íå îñòàíåòñÿ
|
||||
ioContext.stop(); // Îïöèîíàëüíî: íåìåäëåííàÿ îñòàíîâêà
|
||||
for (auto& t : workers) {
|
||||
if (t.joinable()) t.join();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainThreadHandler::EnqueueMainThreadTask(std::function<void()> task) {
|
||||
#ifndef EMSCRIPTEN
|
||||
std::lock_guard<std::mutex> lock(mainThreadMutex);
|
||||
#endif
|
||||
mainThreadTasks.push(task);
|
||||
}
|
||||
|
||||
void MainThreadHandler::processMainThreadTasks() {
|
||||
std::function<void()> task;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
if (!mainThreadTasks.empty()) {
|
||||
task = std::move(mainThreadTasks.front());
|
||||
mainThreadTasks.pop();
|
||||
}
|
||||
#else
|
||||
// Èçâëåêàåì òîëüêî îäíó çàäà÷ó, ÷òîáû íå áëîêèðîâàòü update íàäîëãî
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mainThreadMutex);
|
||||
@@ -42,6 +59,7 @@ namespace ZL
|
||||
mainThreadTasks.pop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (task) {
|
||||
task(); // Çäåñü âûïîëíÿåòñÿ RefreshVBO èëè çàãðóçêà òåêñòóðû
|
||||
|
||||
Reference in new issue
Block a user