2013-08-20 14:07:42 -07:00
|
|
|
/* Copyright (C) 2013 Wildfire Games.
|
2009-06-20 09:13:29 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* 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
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
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"
|
2010-06-01 17:36:21 -07:00
|
|
|
#include "gui/GUIManager.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"
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2006-04-23 16:14:18 -07:00
|
|
|
void (*Atlas_NotifyEndOfFrame)();
|
2008-09-18 04:31:12 -07:00
|
|
|
void (*Atlas_DisplayError)(const wchar_t* text, size_t flags);
|
2007-05-11 06:11:25 -07:00
|
|
|
void (*Atlas_ReportError)();
|
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 InputProcessor g_Input;
|
|
|
|
|
|
|
|
|
|
static GameLoopState state;
|
2012-03-03 15:48:04 -08:00
|
|
|
GameLoopState* g_AtlasGameLoop = &state;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
# 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
|
|
|
|
2010-12-09 03:16:21 -08:00
|
|
|
static ErrorReactionInternal AtlasDisplayError(const wchar_t* text, size_t flags)
|
# 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
|
|
|
{
|
|
|
|
|
// TODO: after Atlas has been unloaded, don't do this
|
|
|
|
|
Atlas_DisplayError(text, flags);
|
|
|
|
|
|
2010-12-09 03:16:21 -08:00
|
|
|
return ERI_CONTINUE;
|
# 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
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2010-09-10 14:02:10 -07:00
|
|
|
static void RendererIncrementalLoad()
|
|
|
|
|
{
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 16:09:31 -07:00
|
|
|
static void* RunEngine(void* data)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
2011-09-20 15:49:02 -07:00
|
|
|
debug_SetThreadName("engine_thread");
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2011-09-20 15:49:02 -07:00
|
|
|
// Set new main thread so that all the thread-safety checks pass
|
|
|
|
|
ThreadUtil::SetMainThread();
|
2010-07-24 04:56:21 -07:00
|
|
|
|
2011-11-05 16:09:31 -07:00
|
|
|
g_Profiler2.RegisterCurrentThread("atlasmain");
|
|
|
|
|
|
2011-09-20 15:49:02 -07:00
|
|
|
const CmdLineArgs args = *reinterpret_cast<const CmdLineArgs*>(data);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2011-09-20 15:49:02 -07:00
|
|
|
MessagePasserImpl* msgPasser = (MessagePasserImpl*)AtlasMessage::g_MessagePasser;
|
2010-03-29 03:24:17 -07:00
|
|
|
|
2006-06-02 22:08:32 -07:00
|
|
|
// Register all the handlers for message which might be passed back
|
|
|
|
|
RegisterHandlers();
|
2011-09-20 15:49:02 -07:00
|
|
|
|
# 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
|
|
|
// Override ah_display_error to pass all errors to the Atlas UI
|
2013-08-20 14:07:42 -07:00
|
|
|
// 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
|
|
|
|
|
// (use INIT_HAVE_DISPLAY_ERROR init flag to test this)
|
# 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
|
|
|
AppHooks hooks = {0};
|
|
|
|
|
hooks.display_error = AtlasDisplayError;
|
2013-08-20 22:37:28 -07:00
|
|
|
app_hooks_update(&hooks);
|
2007-06-10 16:15:14 -07:00
|
|
|
|
|
|
|
|
// Disable the game's cursor rendering
|
2009-11-03 13:46:35 -08:00
|
|
|
extern CStrW g_CursorName;
|
|
|
|
|
g_CursorName = L"";
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2006-12-09 06:39:52 -08:00
|
|
|
state.args = args;
|
2006-04-23 16:14:18 -07:00
|
|
|
state.running = true;
|
2012-03-03 15:48:04 -08:00
|
|
|
state.view = AtlasView::GetView_None();
|
2007-01-02 10:11:00 -08:00
|
|
|
state.glCanvas = NULL;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2008-01-07 12:03:19 -08:00
|
|
|
double last_activity = timer_Time();
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
while (state.running)
|
|
|
|
|
{
|
|
|
|
|
bool recent_activity = false;
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// (TODO: Work out why these things have to be in this order (to avoid
|
# 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
|
|
|
// jumps when starting to move, etc))
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
// Calculate frame length
|
|
|
|
|
{
|
2012-12-03 05:24:12 -08:00
|
|
|
const double time = timer_Time();
|
2006-04-23 16:14:18 -07:00
|
|
|
static double last_time = time;
|
2012-12-03 05:24:12 -08:00
|
|
|
const double realFrameLength = time-last_time;
|
2006-04-23 16:14:18 -07:00
|
|
|
last_time = time;
|
2012-12-03 05:24:12 -08:00
|
|
|
ENSURE(realFrameLength >= 0.0);
|
2006-04-23 16:14:18 -07:00
|
|
|
// TODO: filter out big jumps, e.g. when having done a lot of slow
|
|
|
|
|
// processing in the last frame
|
2012-06-06 12:37:03 -07:00
|
|
|
state.realFrameLength = realFrameLength;
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process the input that was received in the past
|
|
|
|
|
if (g_Input.ProcessInput(&state))
|
|
|
|
|
recent_activity = true;
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
IMessage* msg;
|
2011-09-20 15:49:02 -07:00
|
|
|
while ((msg = msgPasser->Retrieve()) != NULL)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
recent_activity = true;
|
|
|
|
|
|
|
|
|
|
std::string name (msg->GetName());
|
|
|
|
|
|
|
|
|
|
msgHandlers::const_iterator it = GetMsgHandlers().find(name);
|
|
|
|
|
if (it != GetMsgHandlers().end())
|
|
|
|
|
{
|
|
|
|
|
it->second(msg);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-11-03 13:46:35 -08:00
|
|
|
debug_warn(L"Unrecognised message");
|
2007-05-31 17:34:36 -07:00
|
|
|
// CLogger might not be initialised, but this error will be sent
|
|
|
|
|
// to the debug output window anyway so people can still see it
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGERROR("Unrecognised message (%s)", name.c_str());
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg->GetType() == IMessage::Query)
|
|
|
|
|
{
|
|
|
|
|
// For queries, we need to notify MessagePasserImpl::Query
|
|
|
|
|
// that the query has now been processed.
|
|
|
|
|
sem_post((sem_t*) static_cast<QueryMessage*>(msg)->m_Semaphore);
|
|
|
|
|
// (msg may have been destructed at this point, so don't use it again)
|
|
|
|
|
|
|
|
|
|
// It's quite possible that the querier is going to do a tiny
|
|
|
|
|
// bit of processing on the query results and then issue another
|
|
|
|
|
// query, and repeat lots of times in a loop. To avoid slowing
|
|
|
|
|
// that down by rendering between every query, make this
|
|
|
|
|
// thread yield now.
|
|
|
|
|
SDL_Delay(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// For non-queries, we need to delete the object, since we
|
|
|
|
|
// took ownership of it.
|
|
|
|
|
AtlasMessage::ShareableDelete(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exit, if desired
|
|
|
|
|
if (! state.running)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// Do per-frame processing:
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
ReloadChangedFiles();
|
2007-01-16 19:25:20 -08:00
|
|
|
|
2010-09-10 14:02:10 -07:00
|
|
|
RendererIncrementalLoad();
|
|
|
|
|
|
2010-06-01 17:36:21 -07:00
|
|
|
// Pump SDL events (e.g. hotkeys)
|
|
|
|
|
SDL_Event_ ev;
|
Improve correctness of hotkeys at low framerates.
SDL queues up all the input events received in a frame. When the hotkey
system saw a key up/down event, it immediately updated its
HotkeyIsPressed state and then pushed a hotkey event onto the end of the
queue.
If the initial queue was e.g. [key-down shift, key-press Z, key-up
shift], the hotkey event triggered by Z would be processed after the
key-up shift had updated the HotkeyIsPressed state, so the handler of
the Z hotkey would not think the shift hotkey was pressed.
If the initial queue was e.g. [key-press Z, mouse-click], the hotkey
triggered by Z would be processed after the mouse-click event, so it
could apply to the wrong building selection.
Fix by pushing the hotkey events onto a special queue that gets
processed before any subsequent SDL input events.
Also update the HotkeyIsPressed status when the HOTKEYDOWN/HOTKEYUP
events are processed, not when they are generated, to guarantee they are
consistent with the DOWN/UP events.
Fixes #1869.
This was SVN commit r14057.
2013-10-29 18:38:32 -07:00
|
|
|
while (in_poll_event(&ev))
|
2010-06-01 17:36:21 -07:00
|
|
|
in_dispatch_event(&ev);
|
|
|
|
|
|
|
|
|
|
if (g_GUI)
|
|
|
|
|
g_GUI->TickObjects();
|
|
|
|
|
|
2012-06-06 12:37:03 -07:00
|
|
|
state.view->Update(state.realFrameLength);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
# 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
|
|
|
state.view->Render();
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2007-02-09 19:09:52 -08:00
|
|
|
if (CProfileManager::IsInitialised())
|
|
|
|
|
g_Profiler.Frame();
|
|
|
|
|
|
|
|
|
|
|
2008-01-07 12:03:19 -08:00
|
|
|
double time = timer_Time();
|
2006-04-23 16:14:18 -07:00
|
|
|
if (recent_activity)
|
|
|
|
|
last_activity = time;
|
|
|
|
|
|
|
|
|
|
// Be nice to the processor (by sleeping lots) if we're not doing anything
|
|
|
|
|
// useful, and nice to the user (by just yielding to other threads) if we are
|
# 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
|
|
|
bool yield = (time - last_activity > 0.5);
|
|
|
|
|
|
|
|
|
|
// But make sure we aren't doing anything interesting right now, where
|
|
|
|
|
// the user wants to see the screen updating even though they're not
|
|
|
|
|
// interacting with it
|
|
|
|
|
if (state.view->WantsHighFramerate())
|
2006-08-21 19:24:44 -07:00
|
|
|
yield = false;
|
# 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
|
|
|
|
2006-08-21 19:24:44 -07:00
|
|
|
if (yield) // if there was no recent activity...
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
double sleepUntil = time + 0.5; // only redraw at 2fps
|
|
|
|
|
while (time < sleepUntil)
|
|
|
|
|
{
|
|
|
|
|
// To minimise latency when the user starts doing stuff, only
|
|
|
|
|
// sleep for a short while, then check if anything's happened,
|
|
|
|
|
// then go back to sleep
|
|
|
|
|
// (TODO: This should probably be done with something like semaphores)
|
|
|
|
|
Atlas_NotifyEndOfFrame(); // (TODO: rename to NotifyEndOfQuiteShortProcessingPeriodSoPleaseSendMeNewMessages or something)
|
|
|
|
|
SDL_Delay(50);
|
2011-09-20 15:49:02 -07:00
|
|
|
if (!msgPasser->IsEmpty())
|
2006-04-23 16:14:18 -07:00
|
|
|
break;
|
2008-01-07 12:03:19 -08:00
|
|
|
time = timer_Time();
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Atlas_NotifyEndOfFrame();
|
|
|
|
|
SDL_Delay(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-20 15:49:02 -07:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
|
|
|
|
|
{
|
|
|
|
|
// 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_NotifyEndOfFrame", Atlas_NotifyEndOfFrame);
|
|
|
|
|
dll.LoadSymbol("Atlas_DisplayError", Atlas_DisplayError);
|
|
|
|
|
dll.LoadSymbol("Atlas_ReportError", Atlas_ReportError);
|
|
|
|
|
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());
|
|
|
|
|
|
2011-11-12 14:08:59 -08:00
|
|
|
// Run the engine loop in a new thread
|
2011-09-20 15:49:02 -07:00
|
|
|
pthread_t engineThread;
|
|
|
|
|
pthread_create(&engineThread, NULL, RunEngine, reinterpret_cast<void*>(const_cast<CmdLineArgs*>(&args)));
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
// Wait for the engine to exit
|
|
|
|
|
pthread_join(engineThread, NULL);
|
|
|
|
|
|
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
|
|
|
|
|
ThreadUtil::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
|
|
|
}
|