Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/GameLoop.cpp
Show All 11 Lines | |||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include <thread> | |||||
#include "GameLoop.h" | #include "GameLoop.h" | ||||
#include "MessagePasserImpl.h" | #include "MessagePasserImpl.h" | ||||
#include "Messages.h" | #include "Messages.h" | ||||
#include "SharedMemory.h" | #include "SharedMemory.h" | ||||
#include "Handlers/MessageHandler.h" | #include "Handlers/MessageHandler.h" | ||||
#include "ActorViewer.h" | #include "ActorViewer.h" | ||||
#include "View.h" | #include "View.h" | ||||
#include "InputProcessor.h" | #include "InputProcessor.h" | ||||
#include "graphics/TextureManager.h" | #include "graphics/TextureManager.h" | ||||
#include "gui/GUIManager.h" | #include "gui/GUIManager.h" | ||||
#include "lib/app_hooks.h" | #include "lib/app_hooks.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/DllLoader.h" | #include "ps/DllLoader.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/ThreadUtil.h" | |||||
#include "ps/GameSetup/Paths.h" | #include "ps/GameSetup/Paths.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
using namespace AtlasMessage; | using namespace AtlasMessage; | ||||
namespace AtlasMessage | namespace AtlasMessage | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | static void RendererIncrementalLoad() | ||||
double startTime = timer_Time(); | double startTime = timer_Time(); | ||||
bool more; | bool more; | ||||
do { | do { | ||||
more = g_Renderer.GetTextureManager().MakeProgress(); | more = g_Renderer.GetTextureManager().MakeProgress(); | ||||
} | } | ||||
while (more && timer_Time() - startTime < maxTime); | while (more && timer_Time() - startTime < maxTime); | ||||
} | } | ||||
static void* RunEngine(void* data) | static void RunEngine(const CmdLineArgs& args) | ||||
{ | { | ||||
debug_SetThreadName("engine_thread"); | debug_SetThreadName("engine_thread"); | ||||
// Set new main thread so that all the thread-safety checks pass | // Set new main thread so that all the thread-safety checks pass | ||||
ThreadUtil::SetMainThread(); | ThreadUtil::SetMainThread(); | ||||
g_Profiler2.RegisterCurrentThread("atlasmain"); | g_Profiler2.RegisterCurrentThread("atlasmain"); | ||||
const CmdLineArgs args = *reinterpret_cast<const CmdLineArgs*>(data); | |||||
MessagePasserImpl* msgPasser = (MessagePasserImpl*)AtlasMessage::g_MessagePasser; | MessagePasserImpl* msgPasser = (MessagePasserImpl*)AtlasMessage::g_MessagePasser; | ||||
// Register all the handlers for message which might be passed back | // Register all the handlers for message which might be passed back | ||||
RegisterHandlers(); | RegisterHandlers(); | ||||
// Override ah_display_error to pass all errors to the Atlas UI | // Override ah_display_error to pass all errors to the Atlas UI | ||||
// TODO: this doesn't work well because it doesn't pause the game thread | // TODO: this doesn't work well because it doesn't pause the game thread | ||||
// and the error box is ugly, so only use it if we fix those issues | // and the error box is ugly, so only use it if we fix those issues | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if (yield) // if there was no recent activity... | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
Atlas_NotifyEndOfFrame(); | Atlas_NotifyEndOfFrame(); | ||||
SDL_Delay(0); | SDL_Delay(0); | ||||
} | } | ||||
} | } | ||||
return NULL; | |||||
} | } | ||||
bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll) | bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll) | ||||
{ | { | ||||
// Load required symbols from the DLL | // Load required symbols from the DLL | ||||
try | try | ||||
{ | { | ||||
dll.LoadSymbol("Atlas_StartWindow", Atlas_StartWindow); | dll.LoadSymbol("Atlas_StartWindow", Atlas_StartWindow); | ||||
Show All 24 Lines | bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll) | ||||
// Tell Atlas the location of the data directory | // Tell Atlas the location of the data directory | ||||
const Paths paths(args); | const Paths paths(args); | ||||
Atlas_SetDataDirectory(paths.RData().string().c_str()); | Atlas_SetDataDirectory(paths.RData().string().c_str()); | ||||
// Tell Atlas the location of the user config directory | // Tell Atlas the location of the user config directory | ||||
Atlas_SetConfigDirectory(paths.Config().string().c_str()); | Atlas_SetConfigDirectory(paths.Config().string().c_str()); | ||||
// Run the engine loop in a new thread | // Run the engine loop in a new thread | ||||
pthread_t engineThread; | std::thread engineThread = std::thread(RunEngine, std::ref(args)); | ||||
pthread_create(&engineThread, NULL, RunEngine, reinterpret_cast<void*>(const_cast<CmdLineArgs*>(&args))); | |||||
// Start Atlas UI on main thread | // Start Atlas UI on main thread | ||||
// (required for wxOSX/Cocoa compatibility - see http://trac.wildfiregames.com/ticket/500) | // (required for wxOSX/Cocoa compatibility - see http://trac.wildfiregames.com/ticket/500) | ||||
Atlas_StartWindow(L"ScenarioEditor"); | Atlas_StartWindow(L"ScenarioEditor"); | ||||
// Wait for the engine to exit | // Wait for the engine to exit | ||||
pthread_join(engineThread, NULL); | engineThread.join(); | ||||
// TODO: delete all remaining messages, to avoid memory leak warnings | // TODO: delete all remaining messages, to avoid memory leak warnings | ||||
// Restore main thread | // Restore main thread | ||||
ThreadUtil::SetMainThread(); | ThreadUtil::SetMainThread(); | ||||
// Clean up | // Clean up | ||||
AtlasView::DestroyViews(); | AtlasView::DestroyViews(); | ||||
AtlasMessage::g_MessagePasser = NULL; | AtlasMessage::g_MessagePasser = NULL; | ||||
return true; | return true; | ||||
} | } |
Wildfire Games · Phabricator