2021-01-10 00:39:54 -08:00
|
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* This file is part of 0 A.D.
|
2009-06-20 09:13:29 -07:00
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-06-20 09:13:29 -07:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-06-20 09:13:29 -07:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-20 09:13:29 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "GameLoop.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "MessagePasserImpl.h"
|
|
|
|
|
|
#include "Messages.h"
|
|
|
|
|
|
#include "SharedMemory.h"
|
|
|
|
|
|
#include "Handlers/MessageHandler.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 10:36:42 -07:00
|
|
|
|
#include "ActorViewer.h"
|
|
|
|
|
|
#include "View.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
|
|
#include "InputProcessor.h"
|
|
|
|
|
|
|
2010-09-10 14:02:10 -07:00
|
|
|
|
#include "graphics/TextureManager.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 10:36:42 -07:00
|
|
|
|
#include "lib/app_hooks.h"
|
2012-01-12 15:32:27 -08:00
|
|
|
|
#include "lib/external_libraries/libsdl.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
|
#include "lib/timer.h"
|
|
|
|
|
|
#include "ps/CLogger.h"
|
2006-12-19 19:09:21 -08:00
|
|
|
|
#include "ps/DllLoader.h"
|
2010-01-09 11:20:14 -08:00
|
|
|
|
#include "ps/Filesystem.h"
|
2007-02-09 19:09:52 -08:00
|
|
|
|
#include "ps/Profile.h"
|
2019-08-12 01:16:28 -07:00
|
|
|
|
#include "ps/ThreadUtil.h"
|
2010-03-29 03:24:17 -07:00
|
|
|
|
#include "ps/GameSetup/Paths.h"
|
2010-09-10 14:02:10 -07:00
|
|
|
|
#include "renderer/Renderer.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
|
|
using namespace AtlasMessage;
|
|
|
|
|
|
|
2019-08-12 05:56:32 -07:00
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
|
|
namespace AtlasMessage
|
|
|
|
|
|
{
|
2006-06-02 22:08:32 -07:00
|
|
|
|
extern void RegisterHandlers();
|
2006-04-23 16:14:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Loaded from DLL:
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 10:36:42 -07:00
|
|
|
|
void (*Atlas_StartWindow)(const wchar_t* type);
|
2010-03-29 03:24:17 -07:00
|
|
|
|
void (*Atlas_SetDataDirectory)(const wchar_t* path);
|
2012-03-19 15:40:06 -07:00
|
|
|
|
void (*Atlas_SetConfigDirectory)(const wchar_t* path);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
void (*Atlas_SetMessagePasser)(MessagePasser*);
|
2007-01-02 10:11:00 -08:00
|
|
|
|
void (*Atlas_GLSetCurrent)(void* cavas);
|
|
|
|
|
|
void (*Atlas_GLSwapBuffers)(void* canvas);
|
2008-09-18 04:31:12 -07:00
|
|
|
|
void (*Atlas_DisplayError)(const wchar_t* text, size_t flags);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
namespace AtlasMessage
|
|
|
|
|
|
{
|
|
|
|
|
|
void* (*ShareableMallocFptr)(size_t);
|
|
|
|
|
|
void (*ShareableFreeFptr)(void*);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-24 04:56:21 -07:00
|
|
|
|
MessagePasser* AtlasMessage::g_MessagePasser = NULL;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GameLoopState state;
|
2012-03-03 15:48:04 -08:00
|
|
|
|
GameLoopState* g_AtlasGameLoop = &state;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
|
void RendererIncrementalLoad()
|
2010-09-10 14:02:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
// TODO: shouldn't duplicate this code from main.cpp
|
|
|
|
|
|
|
|
|
|
|
|
if (!CRenderer::IsInitialised())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
const double maxTime = 0.1f;
|
|
|
|
|
|
|
|
|
|
|
|
double startTime = timer_Time();
|
|
|
|
|
|
bool more;
|
|
|
|
|
|
do {
|
|
|
|
|
|
more = g_Renderer.GetTextureManager().MakeProgress();
|
|
|
|
|
|
}
|
|
|
|
|
|
while (more && timer_Time() - startTime < maxTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-23 05:02:58 -08:00
|
|
|
|
bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
|
2011-09-20 15:49:02 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Load required symbols from the DLL
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dll.LoadSymbol("Atlas_StartWindow", Atlas_StartWindow);
|
|
|
|
|
|
dll.LoadSymbol("Atlas_SetMessagePasser", Atlas_SetMessagePasser);
|
|
|
|
|
|
dll.LoadSymbol("Atlas_SetDataDirectory", Atlas_SetDataDirectory);
|
2012-03-19 15:40:06 -07:00
|
|
|
|
dll.LoadSymbol("Atlas_SetConfigDirectory", Atlas_SetConfigDirectory);
|
2011-09-20 15:49:02 -07:00
|
|
|
|
dll.LoadSymbol("Atlas_GLSetCurrent", Atlas_GLSetCurrent);
|
|
|
|
|
|
dll.LoadSymbol("Atlas_GLSwapBuffers", Atlas_GLSwapBuffers);
|
|
|
|
|
|
dll.LoadSymbol("Atlas_DisplayError", Atlas_DisplayError);
|
|
|
|
|
|
dll.LoadSymbol("ShareableMalloc", ShareableMallocFptr);
|
|
|
|
|
|
dll.LoadSymbol("ShareableFree", ShareableFreeFptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (PSERROR_DllLoader&)
|
|
|
|
|
|
{
|
|
|
|
|
|
debug_warn(L"Failed to initialise DLL");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Construct a message passer for communicating with Atlas
|
2011-11-12 14:08:59 -08:00
|
|
|
|
// (here so that its scope lasts beyond the game thread)
|
2011-09-20 15:49:02 -07:00
|
|
|
|
MessagePasserImpl msgPasser;
|
|
|
|
|
|
AtlasMessage::g_MessagePasser = &msgPasser;
|
|
|
|
|
|
|
|
|
|
|
|
// Pass our message handler to Atlas
|
|
|
|
|
|
Atlas_SetMessagePasser(&msgPasser);
|
|
|
|
|
|
|
|
|
|
|
|
// Tell Atlas the location of the data directory
|
|
|
|
|
|
const Paths paths(args);
|
|
|
|
|
|
Atlas_SetDataDirectory(paths.RData().string().c_str());
|
|
|
|
|
|
|
2012-03-19 15:40:06 -07:00
|
|
|
|
// Tell Atlas the location of the user config directory
|
|
|
|
|
|
Atlas_SetConfigDirectory(paths.Config().string().c_str());
|
|
|
|
|
|
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
|
RegisterHandlers();
|
|
|
|
|
|
|
|
|
|
|
|
state.args = args;
|
|
|
|
|
|
state.running = true;
|
|
|
|
|
|
state.view = AtlasView::GetView_None();
|
|
|
|
|
|
state.glCanvas = NULL;
|
2011-09-20 15:49:02 -07:00
|
|
|
|
|
2011-11-12 14:08:59 -08:00
|
|
|
|
// Start Atlas UI on main thread
|
|
|
|
|
|
// (required for wxOSX/Cocoa compatibility - see http://trac.wildfiregames.com/ticket/500)
|
2011-09-20 15:49:02 -07:00
|
|
|
|
Atlas_StartWindow(L"ScenarioEditor");
|
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
|
// TODO: delete all remaining messages, to avoid memory leak warnings
|
|
|
|
|
|
|
2011-09-20 15:49:02 -07:00
|
|
|
|
// Restore main thread
|
2021-01-10 00:39:54 -08:00
|
|
|
|
Threading::SetMainThread();
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 10:36:42 -07:00
|
|
|
|
|
|
|
|
|
|
// Clean up
|
2012-03-03 15:48:04 -08:00
|
|
|
|
AtlasView::DestroyViews();
|
2013-01-21 12:33:25 -08:00
|
|
|
|
AtlasMessage::g_MessagePasser = NULL;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
2006-12-09 06:39:52 -08:00
|
|
|
|
return true;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
}
|