2023-01-19 23:34:46 +01:00
|
|
|
/* Copyright (C) 2023 Wildfire Games.
|
2023-07-27 22:54:46 +02:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2023-07-27 22:54:46 +02:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 19:00:33 +02: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 22:54:46 +02:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 19:00:33 +02: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 22:54:46 +02:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2021-12-27 11:11:26 +01:00
|
|
|
#include "ps/GameSetup/GameSetup.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
#include "graphics/GameView.h"
|
|
|
|
#include "graphics/MapReader.h"
|
|
|
|
#include "graphics/TerrainTextureManager.h"
|
2019-09-18 22:51:45 +02:00
|
|
|
#include "gui/CGUI.h"
|
2012-08-15 02:10:44 +02:00
|
|
|
#include "gui/GUIManager.h"
|
2022-05-15 08:34:17 +02:00
|
|
|
#include "gui/Scripting/JSInterface_GUIManager.h"
|
2014-10-15 18:04:37 +02:00
|
|
|
#include "i18n/L10n.h"
|
2021-12-27 11:11:26 +01:00
|
|
|
#include "lib/app_hooks.h"
|
|
|
|
#include "lib/config2.h"
|
|
|
|
#include "lib/external_libraries/libsdl.h"
|
|
|
|
#include "lib/file/common/file_stats.h"
|
|
|
|
#include "lib/input.h"
|
|
|
|
#include "lib/timer.h"
|
|
|
|
#include "lobby/IXmppClient.h"
|
2012-08-15 02:10:44 +02:00
|
|
|
#include "network/NetServer.h"
|
|
|
|
#include "network/NetClient.h"
|
2016-06-13 18:56:14 +02:00
|
|
|
#include "network/NetMessage.h"
|
|
|
|
#include "network/NetMessages.h"
|
2022-05-15 08:34:17 +02:00
|
|
|
#include "network/scripting/JSInterface_Network.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/CConsole.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 19:36:42 +02:00
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "ps/ConfigDB.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "ps/Filesystem.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/Game.h"
|
2012-08-15 02:10:44 +02:00
|
|
|
#include "ps/GameSetup/Atlas.h"
|
|
|
|
#include "ps/GameSetup/Paths.h"
|
|
|
|
#include "ps/GameSetup/Config.h"
|
|
|
|
#include "ps/GameSetup/CmdLineArgs.h"
|
|
|
|
#include "ps/GameSetup/HWDetect.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 19:36:42 +02:00
|
|
|
#include "ps/Globals.h"
|
2021-02-27 18:44:59 +01:00
|
|
|
#include "ps/GUID.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/Hotkey.h"
|
2010-12-30 20:45:13 +01:00
|
|
|
#include "ps/Joystick.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 19:36:42 +02:00
|
|
|
#include "ps/Loader.h"
|
2014-08-25 18:02:40 +02:00
|
|
|
#include "ps/Mod.h"
|
2018-04-22 20:14:45 +02:00
|
|
|
#include "ps/ModIo.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 19:36:42 +02:00
|
|
|
#include "ps/Profile.h"
|
|
|
|
#include "ps/ProfileViewer.h"
|
2011-11-04 02:35:50 +01:00
|
|
|
#include "ps/Profiler2.h"
|
2012-08-15 02:10:44 +02:00
|
|
|
#include "ps/Pyrogenesis.h" // psSetLogDir
|
|
|
|
#include "ps/scripting/JSInterface_Console.h"
|
2022-05-15 08:34:17 +02:00
|
|
|
#include "ps/scripting/JSInterface_Game.h"
|
|
|
|
#include "ps/scripting/JSInterface_Main.h"
|
|
|
|
#include "ps/scripting/JSInterface_VFS.h"
|
2012-02-25 18:29:27 +01:00
|
|
|
#include "ps/TouchInput.h"
|
2011-02-16 21:40:15 +01:00
|
|
|
#include "ps/UserReport.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/Util.h"
|
2010-06-03 21:07:59 +02:00
|
|
|
#include "ps/VideoMode.h"
|
2016-08-17 17:17:43 +02:00
|
|
|
#include "ps/VisualReplay.h"
|
2010-05-20 20:09:23 +02:00
|
|
|
#include "ps/World.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "renderer/Renderer.h"
|
2022-01-04 14:29:01 +01:00
|
|
|
#include "renderer/SceneRenderer.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "renderer/VertexBufferManager.h"
|
2021-05-01 16:04:53 +02:00
|
|
|
#include "scriptinterface/FunctionWrapper.h"
|
2021-12-27 11:11:26 +01:00
|
|
|
#include "scriptinterface/JSON.h"
|
2010-06-30 23:41:04 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2010-08-02 21:23:58 +02:00
|
|
|
#include "scriptinterface/ScriptStats.h"
|
2020-11-14 11:57:50 +01:00
|
|
|
#include "scriptinterface/ScriptContext.h"
|
2017-05-23 21:26:33 +02:00
|
|
|
#include "scriptinterface/ScriptConversions.h"
|
2012-08-15 02:10:44 +02:00
|
|
|
#include "simulation2/Simulation2.h"
|
2022-05-15 08:34:17 +02:00
|
|
|
#include "simulation2/scripting/JSInterface_Simulation.h"
|
2013-06-06 13:13:57 +02:00
|
|
|
#include "soundmanager/scripting/JSInterface_Sound.h"
|
|
|
|
#include "soundmanager/ISoundManager.h"
|
2012-02-27 06:32:35 +01:00
|
|
|
#include "tools/atlas/GameInterface/GameLoop.h"
|
|
|
|
|
2012-02-14 00:53:09 +01:00
|
|
|
#if !(OS_WIN || OS_MACOSX || OS_ANDROID) // assume all other platforms use X11 for wxWidgets
|
2010-07-07 23:47:31 +02:00
|
|
|
#define MUST_INIT_X11 1
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#else
|
|
|
|
#define MUST_INIT_X11 0
|
|
|
|
#endif
|
|
|
|
|
2018-05-08 11:45:54 +02:00
|
|
|
extern void RestartEngine();
|
2014-08-25 18:02:40 +02:00
|
|
|
|
2021-03-03 23:38:59 +01:00
|
|
|
#include <fstream>
|
2010-05-11 15:24:25 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2014-08-25 18:02:40 +02:00
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
2021-05-09 15:53:25 +02:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2014-08-25 18:02:40 +02:00
|
|
|
#include <boost/algorithm/string/split.hpp>
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
ERROR_GROUP(System);
|
|
|
|
ERROR_TYPE(System, SDLInitFailed);
|
|
|
|
ERROR_TYPE(System, VmodeFailed);
|
|
|
|
ERROR_TYPE(System, RequiredExtensionsMissing);
|
|
|
|
|
2021-05-22 21:28:40 +02:00
|
|
|
thread_local std::shared_ptr<ScriptContext> g_ScriptContext;
|
2014-01-04 11:14:53 +01:00
|
|
|
|
2014-04-20 22:03:57 +02:00
|
|
|
bool g_InDevelopmentCopy;
|
|
|
|
bool g_CheckedIfInDevelopmentCopy = false;
|
|
|
|
|
2010-12-09 12:16:21 +01:00
|
|
|
ErrorReactionInternal psDisplayError(const wchar_t* UNUSED(text), size_t UNUSED(flags))
|
2010-11-20 18:14:45 +01:00
|
|
|
{
|
|
|
|
// If we're fullscreen, then sometimes (at least on some particular drivers on Linux)
|
|
|
|
// displaying the error dialog hangs the desktop since the dialog box is behind the
|
|
|
|
// fullscreen window. So we just force the game to windowed mode before displaying the dialog.
|
|
|
|
// (But only if we're in the main thread, and not if we're being reentrant.)
|
2021-01-10 09:39:54 +01:00
|
|
|
if (Threading::IsMainThread())
|
2010-11-20 18:14:45 +01:00
|
|
|
{
|
|
|
|
static bool reentering = false;
|
|
|
|
if (!reentering)
|
|
|
|
{
|
|
|
|
reentering = true;
|
|
|
|
g_VideoMode.SetFullscreen(false);
|
|
|
|
reentering = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't actually implement the error display here, so return appropriately
|
2010-12-09 12:16:21 +01:00
|
|
|
return ERI_NOT_IMPLEMENTED;
|
2010-11-20 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 18:02:40 +02:00
|
|
|
void MountMods(const Paths& paths, const std::vector<CStr>& mods)
|
|
|
|
{
|
|
|
|
OsPath modPath = paths.RData()/"mods";
|
|
|
|
OsPath modUserPath = paths.UserData()/"mods";
|
2021-03-23 13:46:59 +01:00
|
|
|
|
|
|
|
size_t userFlags = VFS_MOUNT_WATCH|VFS_MOUNT_ARCHIVABLE;
|
|
|
|
size_t baseFlags = userFlags|VFS_MOUNT_MUST_EXIST;
|
2021-03-28 09:01:34 +02:00
|
|
|
size_t priority = 0;
|
2014-08-25 18:02:40 +02:00
|
|
|
for (size_t i = 0; i < mods.size(); ++i)
|
|
|
|
{
|
2021-03-23 13:46:59 +01:00
|
|
|
priority = i + 1; // Mods are higher priority than regular mountings, which default to priority 0
|
2014-08-25 18:02:40 +02:00
|
|
|
|
|
|
|
OsPath modName(mods[i]);
|
2021-03-23 13:46:59 +01:00
|
|
|
// Only mount mods from the user path if they don't exist in the 'rdata' path.
|
|
|
|
if (DirectoryExists(modPath / modName / ""))
|
|
|
|
g_VFS->Mount(L"", modPath / modName / "", baseFlags, priority);
|
2021-03-22 19:49:42 +01:00
|
|
|
else
|
2021-03-23 13:46:59 +01:00
|
|
|
g_VFS->Mount(L"", modUserPath / modName / "", userFlags, priority);
|
2014-08-25 18:02:40 +02:00
|
|
|
}
|
2021-03-23 13:46:59 +01:00
|
|
|
|
|
|
|
// Mount the user mod last. In dev copy, mount it with a low priority. Otherwise, make it writable.
|
|
|
|
g_VFS->Mount(L"", modUserPath / "user" / "", userFlags, InDevelopmentCopy() ? 0 : priority + 1);
|
2013-06-11 22:50:09 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 23:07:42 +02:00
|
|
|
static void InitVfs(const CmdLineArgs& args, int flags)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER(L"InitVfs");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2013-08-20 23:07:42 +02:00
|
|
|
const bool setup_error = (flags & INIT_HAVE_DISPLAY_ERROR) == 0;
|
|
|
|
|
2009-08-08 13:11:26 +02:00
|
|
|
const Paths paths(args);
|
2009-08-02 13:07:42 +02:00
|
|
|
|
2011-03-23 14:36:20 +01:00
|
|
|
OsPath logs(paths.Logs());
|
2009-08-04 21:57:53 +02:00
|
|
|
CreateDirectories(logs, 0700);
|
2010-03-20 18:20:23 +01:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
psSetLogDir(logs);
|
2010-03-20 18:20:23 +01:00
|
|
|
// desired location for crashlog is now known. update AppHooks ASAP
|
|
|
|
// (particularly before the following error-prone operations):
|
|
|
|
AppHooks hooks = {0};
|
|
|
|
hooks.bundle_logs = psBundleLogs;
|
|
|
|
hooks.get_log_dir = psLogDir;
|
2013-08-20 23:07:42 +02:00
|
|
|
if (setup_error)
|
|
|
|
hooks.display_error = psDisplayError;
|
2010-03-20 18:20:23 +01:00
|
|
|
app_hooks_update(&hooks);
|
2009-08-02 13:07:42 +02:00
|
|
|
|
2017-12-10 18:33:03 +01:00
|
|
|
g_VFS = CreateVfs();
|
2016-11-23 14:02:58 +01:00
|
|
|
|
2013-06-11 22:50:09 +02:00
|
|
|
const OsPath readonlyConfig = paths.RData()/"config"/"";
|
2006-06-30 00:52:50 +02:00
|
|
|
|
2021-03-23 13:46:59 +01:00
|
|
|
// Mount these dirs with highest priority so that mods can't overwrite them.
|
|
|
|
g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE, VFS_MAX_PRIORITY); // (adding XMBs to archive speeds up subsequent reads)
|
|
|
|
if (readonlyConfig != paths.Config())
|
|
|
|
g_VFS->Mount(L"config/", readonlyConfig, 0, VFS_MAX_PRIORITY-1);
|
|
|
|
g_VFS->Mount(L"config/", paths.Config(), 0, VFS_MAX_PRIORITY);
|
|
|
|
g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/"", 0, VFS_MAX_PRIORITY);
|
|
|
|
g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH, VFS_MAX_PRIORITY);
|
|
|
|
|
|
|
|
// Engine localization files (regular priority, these can be overwritten).
|
2014-04-20 22:03:57 +02:00
|
|
|
g_VFS->Mount(L"l10n/", paths.RData()/"l10n"/"");
|
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
// Mods will be mounted later.
|
2006-12-09 16:47:12 +01:00
|
|
|
|
2009-11-04 18:26:54 +01:00
|
|
|
// note: don't bother with g_VFS->TextRepresentation - directories
|
|
|
|
// haven't yet been populated and are empty.
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-04 22:14:17 +02:00
|
|
|
static void InitPs(bool setup_gui, const CStrW& gui_page, ScriptInterface* srcScriptInterface, JS::HandleValue initData)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
|
|
|
// console
|
|
|
|
TIMER(L"ps_console");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2021-05-22 01:10:43 +02:00
|
|
|
g_Console->Init();
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-11-03 18:52:07 +01:00
|
|
|
// hotkeys
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
|
|
|
TIMER(L"ps_lang_hotkeys");
|
2021-01-18 11:58:16 +01:00
|
|
|
LoadHotkeys(g_ConfigDB);
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
|
|
|
|
2010-06-02 02:36:21 +02:00
|
|
|
if (!setup_gui)
|
|
|
|
{
|
|
|
|
// We do actually need *some* kind of GUI loaded, so use the
|
|
|
|
// (currently empty) Atlas one
|
2014-01-04 11:14:53 +01:00
|
|
|
g_GUI->SwitchPage(L"page_atlas.xml", srcScriptInterface, initData);
|
2010-06-02 02:36:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
// GUI uses VFS, so this must come after VFS init.
|
2014-01-04 11:14:53 +01:00
|
|
|
g_GUI->SwitchPage(gui_page, srcScriptInterface, initData);
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2019-09-15 14:16:28 +02:00
|
|
|
void InitInput()
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2010-12-30 20:45:13 +01:00
|
|
|
g_Joystick.Initialise();
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// register input handlers
|
|
|
|
// This stack is constructed so the first added, will be the last
|
|
|
|
// one called. This is important, because each of the handlers
|
|
|
|
// has the potential to block events to go further down
|
|
|
|
// in the chain. I.e. the last one in the list added, is the
|
|
|
|
// only handler that can block all messages before they are
|
|
|
|
// processed.
|
|
|
|
in_add_handler(game_view_handler);
|
|
|
|
|
|
|
|
in_add_handler(CProfileViewer::InputThunk);
|
|
|
|
|
2021-04-02 16:18:20 +02:00
|
|
|
in_add_handler(HotkeyInputActualHandler);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-02 02:36:21 +02:00
|
|
|
// gui_handler needs to be registered after (i.e. called before!) the
|
|
|
|
// hotkey handler so that input boxes can be typed in without
|
|
|
|
// setting off hotkeys.
|
|
|
|
in_add_handler(gui_handler);
|
2021-03-31 17:50:25 +02:00
|
|
|
// Likewise for the console.
|
|
|
|
in_add_handler(conInputHandler);
|
2010-06-30 23:41:04 +02:00
|
|
|
|
2012-02-25 18:29:27 +01:00
|
|
|
in_add_handler(touch_input_handler);
|
2016-11-23 14:02:58 +01:00
|
|
|
|
2021-04-02 16:18:20 +02:00
|
|
|
// Should be called after scancode map update (i.e. after the global input, but before UI).
|
|
|
|
// This never blocks the event, but it does some processing necessary for hotkeys,
|
|
|
|
// which are triggered later down the input chain.
|
|
|
|
// (by calling this before the UI, we can use 'EventWouldTriggerHotkey' in the UI).
|
|
|
|
in_add_handler(HotkeyInputPrepHandler);
|
2019-09-15 14:16:28 +02:00
|
|
|
|
2021-04-02 16:18:20 +02:00
|
|
|
// These two must be called first (i.e. pushed last)
|
|
|
|
// GlobalsInputHandler deals with some important global state,
|
|
|
|
// such as which scancodes are being pressed, mouse buttons pressed, etc.
|
|
|
|
// while HotkeyStateChange updates the map of active hotkeys.
|
|
|
|
in_add_handler(GlobalsInputHandler);
|
2019-09-15 14:16:28 +02:00
|
|
|
in_add_handler(HotkeyStateChange);
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ShutdownPs()
|
|
|
|
{
|
2009-12-03 21:17:22 +01:00
|
|
|
SAFE_DELETE(g_GUI);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2014-09-15 03:27:06 +02:00
|
|
|
UnloadHotkeys();
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void InitSDL()
|
|
|
|
{
|
2011-07-13 19:40:12 +02:00
|
|
|
#if OS_LINUX
|
|
|
|
// In fullscreen mode when SDL is compiled with DGA support, the mouse
|
|
|
|
// sensitivity often appears to be unusably wrong (typically too low).
|
|
|
|
// (This seems to be reported almost exclusively on Ubuntu, but can be
|
|
|
|
// reproduced on Gentoo after explicitly enabling DGA.)
|
|
|
|
// Disabling the DGA mouse appears to fix that problem, and doesn't
|
|
|
|
// have any obvious negative effects.
|
|
|
|
setenv("SDL_VIDEO_X11_DGAMOUSE", "0", 0);
|
|
|
|
#endif
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) < 0)
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("SDL library initialization failed: %s", SDL_GetError());
|
2006-04-24 01:14:18 +02:00
|
|
|
throw PSERROR_System_SDLInitFailed();
|
|
|
|
}
|
|
|
|
atexit(SDL_Quit);
|
2012-02-06 23:47:35 +01:00
|
|
|
|
2016-11-23 14:29:47 +01:00
|
|
|
// Text input is active by default, disable it until it is actually needed.
|
|
|
|
SDL_StopTextInput();
|
|
|
|
|
2021-01-19 14:13:00 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
|
|
|
// SDL2 >= 2.0.9 defaults to 32 pixels (to support touch screens) but that can break our double-clicking.
|
|
|
|
SDL_SetHint(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS, "1");
|
|
|
|
#endif
|
|
|
|
|
2021-12-12 17:01:30 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 14) && OS_WIN
|
|
|
|
// SDL2 >= 2.0.14 Before SDL 2.0.14, this defaulted to true. In 2.0.14 they switched to false
|
|
|
|
// breaking the behavior on Windows.
|
|
|
|
// https://github.com/libsdl-org/SDL/commit/1947ca7028ab165cc3e6cbdb0b4b7c4db68d1710
|
|
|
|
// https://github.com/libsdl-org/SDL/issues/5033
|
|
|
|
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "1");
|
|
|
|
#endif
|
|
|
|
|
2015-12-14 11:52:21 +01:00
|
|
|
#if OS_MACOSX
|
2015-02-22 22:24:27 +01:00
|
|
|
// Some Mac mice only have one button, so they can't right-click
|
|
|
|
// but SDL2 can emulate that with Ctrl+Click
|
|
|
|
bool macMouse = false;
|
|
|
|
CFG_GET_VAL("macmouse", macMouse);
|
|
|
|
SDL_SetHint(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, macMouse ? "1" : "0");
|
|
|
|
#endif
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2010-07-07 23:47:31 +02:00
|
|
|
static void ShutdownSDL()
|
|
|
|
{
|
2010-07-08 00:23:18 +02:00
|
|
|
SDL_Quit();
|
2010-07-07 23:47:31 +02:00
|
|
|
}
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
void EndGame()
|
|
|
|
{
|
2010-05-20 02:59:01 +02:00
|
|
|
SAFE_DELETE(g_NetClient);
|
2014-02-05 03:44:25 +01:00
|
|
|
SAFE_DELETE(g_NetServer);
|
2010-05-20 02:59:01 +02:00
|
|
|
SAFE_DELETE(g_Game);
|
2013-08-29 15:20:55 +02:00
|
|
|
|
2019-08-25 13:02:55 +02:00
|
|
|
if (CRenderer::IsInitialised())
|
2017-05-23 21:26:33 +02:00
|
|
|
{
|
|
|
|
ISoundManager::CloseGame();
|
2022-01-04 14:29:01 +01:00
|
|
|
g_Renderer.GetSceneRenderer().ResetState();
|
2017-05-23 21:26:33 +02:00
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2014-08-25 18:02:40 +02:00
|
|
|
void Shutdown(int flags)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2019-08-25 13:02:55 +02:00
|
|
|
const bool hasRenderer = CRenderer::IsInitialised();
|
2017-05-23 21:26:33 +02:00
|
|
|
|
2014-08-25 18:02:40 +02:00
|
|
|
if ((flags & SHUTDOWN_FROM_CONFIG))
|
|
|
|
goto from_config;
|
|
|
|
|
2010-07-02 23:28:48 +02:00
|
|
|
EndGame();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2013-11-08 16:28:44 +01:00
|
|
|
SAFE_DELETE(g_XmppClient);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2018-04-22 20:14:45 +02:00
|
|
|
SAFE_DELETE(g_ModIo);
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
ShutdownPs();
|
2006-10-08 06:56:30 +02:00
|
|
|
|
2019-08-25 13:02:55 +02:00
|
|
|
if (hasRenderer)
|
2017-05-23 21:26:33 +02:00
|
|
|
{
|
|
|
|
TIMER_BEGIN(L"shutdown Renderer");
|
2019-08-25 13:02:55 +02:00
|
|
|
g_Renderer.~CRenderer();
|
2017-05-23 21:26:33 +02:00
|
|
|
TIMER_END(L"shutdown Renderer");
|
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2020-11-22 12:09:13 +01:00
|
|
|
g_RenderingOptions.ClearHooks();
|
|
|
|
|
2011-11-09 14:09:01 +01:00
|
|
|
g_Profiler2.ShutdownGPU();
|
|
|
|
|
2022-12-04 15:54:24 +01:00
|
|
|
if (hasRenderer)
|
|
|
|
g_VideoMode.Shutdown();
|
|
|
|
|
2010-07-07 23:47:31 +02:00
|
|
|
TIMER_BEGIN(L"shutdown SDL");
|
|
|
|
ShutdownSDL();
|
|
|
|
TIMER_END(L"shutdown SDL");
|
|
|
|
|
2011-02-16 21:40:15 +01:00
|
|
|
TIMER_BEGIN(L"shutdown UserReporter");
|
|
|
|
g_UserReporter.Deinitialize();
|
|
|
|
TIMER_END(L"shutdown UserReporter");
|
|
|
|
|
2018-04-22 20:14:45 +02:00
|
|
|
// Cleanup curl now that g_ModIo and g_UserReporter have been shutdown.
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
2014-10-15 18:04:37 +02:00
|
|
|
delete &g_L10n;
|
|
|
|
|
2014-08-25 18:02:40 +02:00
|
|
|
from_config:
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown ConfigDB");
|
2021-04-27 09:45:40 +02:00
|
|
|
CConfigDB::Shutdown();
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown ConfigDB");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2014-09-28 02:13:55 +02:00
|
|
|
SAFE_DELETE(g_Console);
|
|
|
|
|
2014-08-25 18:02:40 +02:00
|
|
|
// This is needed to ensure that no callbacks from the JSAPI try to use
|
|
|
|
// the profiler when it's already destructed
|
2020-11-14 11:57:50 +01:00
|
|
|
g_ScriptContext.reset();
|
2014-08-25 18:02:40 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// resource
|
|
|
|
// first shut down all resource owners, and then the handle manager.
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"resource modules");
|
2013-06-13 14:12:44 +02:00
|
|
|
|
|
|
|
ISoundManager::SetEnabled(false);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
g_VFS.reset();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-10-10 12:22:11 +02:00
|
|
|
file_stats_dump();
|
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"resource modules");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown misc");
|
2008-01-07 21:03:19 +01:00
|
|
|
timer_DisplayClientTotals();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-07-03 21:31:14 +02:00
|
|
|
CNetHost::Deinitialize();
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// should be last, since the above use them
|
2006-09-28 22:41:12 +02:00
|
|
|
SAFE_DELETE(g_Logger);
|
2006-04-24 01:14:18 +02:00
|
|
|
delete &g_Profiler;
|
|
|
|
delete &g_ProfileViewer;
|
2015-05-06 00:34:41 +02:00
|
|
|
|
|
|
|
SAFE_DELETE(g_ScriptStatsTable);
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown misc");
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2011-02-12 01:19:59 +01:00
|
|
|
#if OS_UNIX
|
2011-07-06 23:19:59 +02:00
|
|
|
static void FixLocales()
|
2011-02-12 01:19:59 +01:00
|
|
|
{
|
2012-01-30 07:21:11 +01:00
|
|
|
#if OS_MACOSX || OS_BSD
|
2011-07-06 23:19:59 +02:00
|
|
|
// OS X requires a UTF-8 locale in LC_CTYPE so that *wprintf can handle
|
|
|
|
// wide characters. Peculiarly the string "UTF-8" seems to be acceptable
|
|
|
|
// despite not being a real locale, and it's conveniently language-agnostic,
|
|
|
|
// so use that.
|
|
|
|
setlocale(LC_CTYPE, "UTF-8");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-02-12 01:19:59 +01:00
|
|
|
// On misconfigured systems with incorrect locale settings, we'll die
|
2011-07-06 23:19:59 +02:00
|
|
|
// with a C++ exception when some code (e.g. Boost) tries to use locales.
|
2011-02-12 01:19:59 +01:00
|
|
|
// To avoid death, we'll detect the problem here and warn the user and
|
|
|
|
// reset to the default C locale.
|
|
|
|
|
|
|
|
|
|
|
|
// For informing the user of the problem, use the list of env vars that
|
|
|
|
// glibc setlocale looks at. (LC_ALL is checked first, and LANG last.)
|
|
|
|
const char* const LocaleEnvVars[] = {
|
|
|
|
"LC_ALL",
|
|
|
|
"LC_COLLATE",
|
|
|
|
"LC_CTYPE",
|
|
|
|
"LC_MONETARY",
|
|
|
|
"LC_NUMERIC",
|
|
|
|
"LC_TIME",
|
|
|
|
"LC_MESSAGES",
|
|
|
|
"LANG"
|
|
|
|
};
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// this constructor is similar to setlocale(LC_ALL, ""),
|
|
|
|
// but instead of returning NULL, it throws runtime_error
|
|
|
|
// when the first locale env variable found contains an invalid value
|
2011-02-13 19:38:22 +01:00
|
|
|
std::locale("");
|
2011-02-12 01:19:59 +01:00
|
|
|
}
|
|
|
|
catch (std::runtime_error&)
|
|
|
|
{
|
2015-01-22 21:31:30 +01:00
|
|
|
LOGWARNING("Invalid locale settings");
|
2011-02-12 01:19:59 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(LocaleEnvVars); i++)
|
|
|
|
{
|
|
|
|
if (char* envval = getenv(LocaleEnvVars[i]))
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING(" %s=\"%s\"", LocaleEnvVars[i], envval);
|
2011-02-12 01:19:59 +01:00
|
|
|
else
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING(" %s=\"(unset)\"", LocaleEnvVars[i]);
|
2011-02-12 01:19:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// We should set LC_ALL since it overrides LANG
|
|
|
|
if (setenv("LC_ALL", std::locale::classic().name().c_str(), 1))
|
|
|
|
debug_warn(L"Invalid locale settings, and unable to set LC_ALL env variable.");
|
|
|
|
else
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Setting LC_ALL env variable to: %s", getenv("LC_ALL"));
|
2011-02-12 01:19:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2011-07-06 23:19:59 +02:00
|
|
|
static void FixLocales()
|
2011-02-12 01:19:59 +01:00
|
|
|
{
|
|
|
|
// Do nothing on Windows
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-27 01:29:20 +02:00
|
|
|
void EarlyInit()
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2007-05-27 01:29:20 +02:00
|
|
|
// If you ever want to catch a particular allocation:
|
2009-11-03 22:46:35 +01:00
|
|
|
//_CrtSetBreakAlloc(232647);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2021-01-10 09:39:54 +01:00
|
|
|
Threading::SetMainThread();
|
2010-10-31 23:00:28 +01:00
|
|
|
|
2008-09-27 12:05:11 +02:00
|
|
|
debug_SetThreadName("main");
|
2006-04-24 01:14:18 +02:00
|
|
|
// add all debug_printf "tags" that we are interested in:
|
2015-02-14 02:45:13 +01:00
|
|
|
debug_filter_add("TIMER");
|
2022-03-05 18:28:00 +01:00
|
|
|
debug_filter_add("FILES");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2020-12-12 09:18:24 +01:00
|
|
|
timer_Init();
|
2007-09-03 01:38:58 +02:00
|
|
|
|
2011-11-09 01:09:19 +01:00
|
|
|
// initialise profiler early so it can profile startup,
|
|
|
|
// but only after LatchStartTime
|
2011-11-04 02:35:50 +01:00
|
|
|
g_Profiler2.Initialise();
|
|
|
|
|
2011-07-06 23:19:59 +02:00
|
|
|
FixLocales();
|
2011-02-23 10:19:41 +01:00
|
|
|
|
2010-07-07 23:47:31 +02:00
|
|
|
// Because we do GL calls from a secondary thread, Xlib needs to
|
|
|
|
// be told to support multiple threads safely.
|
|
|
|
// This is needed for Atlas, but we have to call it before any other
|
|
|
|
// Xlib functions (e.g. the ones used when drawing the main menu
|
|
|
|
// before launching Atlas)
|
|
|
|
#if MUST_INIT_X11
|
|
|
|
int status = XInitThreads();
|
|
|
|
if (status == 0)
|
2015-02-14 02:45:13 +01:00
|
|
|
debug_printf("Error enabling thread-safety via XInitThreads\n");
|
2010-07-07 23:47:31 +02:00
|
|
|
#endif
|
|
|
|
|
2007-09-03 01:38:58 +02:00
|
|
|
// Initialise the low-quality rand function
|
2007-11-18 10:09:06 +01:00
|
|
|
srand(time(NULL)); // NOTE: this rand should *not* be used for simulation!
|
2007-05-27 01:29:20 +02:00
|
|
|
}
|
|
|
|
|
2011-04-07 04:32:16 +02:00
|
|
|
bool Autostart(const CmdLineArgs& args);
|
2010-05-20 02:59:01 +02:00
|
|
|
|
2015-09-20 14:29:59 +02:00
|
|
|
/**
|
|
|
|
* Returns true if the user has intended to start a visual replay from command line.
|
|
|
|
*/
|
2015-09-30 22:28:23 +02:00
|
|
|
bool AutostartVisualReplay(const std::string& replayFile);
|
2015-06-06 10:45:49 +02:00
|
|
|
|
2014-08-25 18:02:40 +02:00
|
|
|
bool Init(const CmdLineArgs& args, int flags)
|
2007-05-27 01:29:20 +02:00
|
|
|
{
|
2006-04-24 01:14:18 +02:00
|
|
|
// Do this as soon as possible, because it chdirs
|
|
|
|
// and will mess up the error reporting if anything
|
|
|
|
// crashes before the working directory is set.
|
2013-08-20 23:07:42 +02:00
|
|
|
InitVfs(args, flags);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// This must come after VFS init, which sets the current directory
|
|
|
|
// (required for finding our output log files).
|
2006-09-28 22:41:12 +02:00
|
|
|
g_Logger = new CLogger;
|
2015-01-24 15:46:52 +01:00
|
|
|
|
|
|
|
new CProfileViewer;
|
|
|
|
new CProfileManager; // before any script code
|
|
|
|
|
|
|
|
g_ScriptStatsTable = new CScriptStatsTable;
|
|
|
|
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
|
|
|
|
|
|
|
|
// Set up the console early, so that debugging
|
|
|
|
// messages can be logged to it. (The console's size
|
|
|
|
// and fonts are set later in InitPs())
|
|
|
|
g_Console = new CConsole();
|
|
|
|
|
|
|
|
// g_ConfigDB, command line args, globals
|
|
|
|
CONFIG_Init(args);
|
2016-11-23 14:02:58 +01:00
|
|
|
|
2020-11-14 11:57:50 +01:00
|
|
|
// Using a global object for the context is a workaround until Simulation and AI use
|
|
|
|
// their own threads and also their own contexts.
|
|
|
|
const int contextSize = 384 * 1024 * 1024;
|
2014-09-22 22:13:04 +02:00
|
|
|
const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024;
|
2020-11-14 11:57:50 +01:00
|
|
|
g_ScriptContext = ScriptContext::CreateContext(contextSize, heapGrowthBytesGCTrigger);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
// On the first Init (INIT_MODS), check for command-line arguments
|
|
|
|
// or use the default mods from the config and enable those.
|
|
|
|
// On later engine restarts (e.g. the mod selector), we will skip this path,
|
|
|
|
// to avoid overwriting the newly selected mods.
|
|
|
|
if (flags & INIT_MODS)
|
|
|
|
{
|
|
|
|
ScriptInterface modInterface("Engine", "Mod", g_ScriptContext);
|
2021-08-17 19:32:10 +02:00
|
|
|
g_Mods.UpdateAvailableMods(modInterface);
|
2021-05-20 16:36:42 +02:00
|
|
|
std::vector<CStr> mods;
|
|
|
|
if (args.Has("mod"))
|
|
|
|
mods = args.GetMultiple("mod");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CStr modsStr;
|
|
|
|
CFG_GET_VAL("mod.enabledmods", modsStr);
|
|
|
|
boost::split(mods, modsStr, boost::algorithm::is_space(), boost::token_compress_on);
|
|
|
|
}
|
|
|
|
|
2021-08-22 11:54:16 +02:00
|
|
|
if (!g_Mods.EnableMods(mods, flags & INIT_MODS_PUBLIC))
|
2021-05-20 16:36:42 +02:00
|
|
|
{
|
|
|
|
// In non-visual mode, fail entirely.
|
|
|
|
if (args.Has("autostart-nonvisual"))
|
|
|
|
{
|
|
|
|
LOGERROR("Trying to start with incompatible mods: %s.", boost::algorithm::join(g_Mods.GetIncompatibleMods(), ", "));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-22 09:33:49 +02:00
|
|
|
// If there are incompatible mods, switch to the mod selector so players can resolve the problem.
|
|
|
|
if (g_Mods.GetIncompatibleMods().empty())
|
|
|
|
MountMods(Paths(args), g_Mods.GetEnabledMods());
|
|
|
|
else
|
|
|
|
MountMods(Paths(args), { "mod" });
|
2018-05-24 20:08:56 +02:00
|
|
|
|
2010-04-09 21:02:39 +02:00
|
|
|
// Special command-line mode to dump the entity schemas instead of running the game.
|
|
|
|
// (This must be done after loading VFS etc, but should be done before wasting time
|
|
|
|
// on anything else.)
|
|
|
|
if (args.Has("dumpSchema"))
|
|
|
|
{
|
2020-11-14 11:57:50 +01:00
|
|
|
CSimulation2 sim(NULL, g_ScriptContext, NULL);
|
2010-04-09 21:02:39 +02:00
|
|
|
sim.LoadDefaultScripts();
|
|
|
|
std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc);
|
|
|
|
f << sim.GenerateSchema();
|
2023-01-19 23:34:46 +01:00
|
|
|
debug_printf("Generated entity.rng\n");
|
|
|
|
return false;
|
2010-04-09 21:02:39 +02:00
|
|
|
}
|
|
|
|
|
2010-07-03 21:31:14 +02:00
|
|
|
CNetHost::Initialize();
|
|
|
|
|
2012-08-31 21:08:41 +02:00
|
|
|
#if CONFIG2_AUDIO
|
2021-01-11 19:56:33 +01:00
|
|
|
if (!args.Has("autostart-nonvisual") && !g_DisableAudio)
|
2017-05-23 21:26:33 +02:00
|
|
|
ISoundManager::CreateSoundManager();
|
2012-08-31 21:08:41 +02:00
|
|
|
#endif
|
2012-08-15 02:10:44 +02:00
|
|
|
|
2014-10-15 18:04:37 +02:00
|
|
|
new L10n;
|
|
|
|
|
2011-11-09 14:09:01 +01:00
|
|
|
// Optionally start profiler HTTP output automatically
|
|
|
|
// (By default it's only enabled by a hotkey, for security/performance)
|
|
|
|
bool profilerHTTPEnable = false;
|
2014-11-18 01:24:29 +01:00
|
|
|
CFG_GET_VAL("profiler2.autoenable", profilerHTTPEnable);
|
2011-11-09 14:09:01 +01:00
|
|
|
if (profilerHTTPEnable)
|
|
|
|
g_Profiler2.EnableHTTP();
|
|
|
|
|
2018-04-22 20:14:45 +02:00
|
|
|
// Initialise everything except Win32 sockets (because our networking
|
|
|
|
// system already inits those)
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL & ~CURL_GLOBAL_WIN32);
|
|
|
|
|
2011-02-16 21:40:15 +01:00
|
|
|
if (!g_Quickstart)
|
|
|
|
g_UserReporter.Initialize(); // after config
|
2011-11-04 02:35:50 +01:00
|
|
|
|
|
|
|
PROFILE2_EVENT("Init finished");
|
2014-08-25 18:02:40 +02:00
|
|
|
return true;
|
2010-10-22 01:44:54 +02:00
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2018-04-15 03:46:28 +02:00
|
|
|
void InitGraphics(const CmdLineArgs& args, int flags, const std::vector<CStr>& installedMods)
|
2010-10-22 01:44:54 +02:00
|
|
|
{
|
|
|
|
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
|
|
|
|
|
|
|
|
if(setup_vmode)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2010-10-22 01:44:54 +02:00
|
|
|
InitSDL();
|
|
|
|
|
2010-06-03 21:07:59 +02:00
|
|
|
if (!g_VideoMode.InitSDL())
|
|
|
|
throw PSERROR_System_VmodeFailed(); // abort startup
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2023-07-18 22:32:21 +02:00
|
|
|
RunHardwareDetection(!g_Quickstart, g_VideoMode.GetBackendDevice());
|
2010-11-20 20:46:49 +01:00
|
|
|
|
2011-11-09 14:09:01 +01:00
|
|
|
// Optionally start profiler GPU timings automatically
|
|
|
|
// (By default it's only enabled by a hotkey, for performance/compatibility)
|
|
|
|
bool profilerGPUEnable = false;
|
2014-11-18 01:24:29 +01:00
|
|
|
CFG_GET_VAL("profiler2.autoenable", profilerGPUEnable);
|
2011-11-09 14:09:01 +01:00
|
|
|
if (profilerGPUEnable)
|
|
|
|
g_Profiler2.EnableGPU();
|
|
|
|
|
2010-06-05 02:49:14 +02:00
|
|
|
if(g_DisableAudio)
|
2013-06-06 13:13:57 +02:00
|
|
|
ISoundManager::SetEnabled(false);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
g_GUI = new CGUIManager();
|
2010-06-03 21:07:59 +02:00
|
|
|
|
2020-10-25 22:00:52 +01:00
|
|
|
CStr8 renderPath = "default";
|
|
|
|
CFG_GET_VAL("renderpath", renderPath);
|
2021-12-15 07:43:41 +01:00
|
|
|
if (RenderPathEnum::FromString(renderPath) == FIXED)
|
2013-02-09 23:55:42 +01:00
|
|
|
{
|
2020-10-25 22:00:52 +01:00
|
|
|
// It doesn't make sense to continue working here, because we're not
|
|
|
|
// able to display anything.
|
|
|
|
DEBUG_DISPLAY_FATAL_ERROR(
|
2013-02-09 23:55:42 +01:00
|
|
|
L"Your graphics card doesn't appear to be fully compatible with OpenGL shaders."
|
2020-10-25 22:00:52 +01:00
|
|
|
L" The game does not support pre-shader graphics cards."
|
2013-02-09 23:55:42 +01:00
|
|
|
L" You are advised to try installing newer drivers and/or upgrade your graphics card."
|
|
|
|
L" For more information, please see http://www.wildfiregames.com/forum/index.php?showtopic=16734"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-03 13:19:44 +01:00
|
|
|
g_RenderingOptions.ReadConfigAndSetupHooks();
|
|
|
|
|
2022-01-04 19:13:45 +01:00
|
|
|
// create renderer
|
2023-06-14 09:06:22 +02:00
|
|
|
new CRenderer(g_VideoMode.GetBackendDevice());
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
InitInput();
|
|
|
|
|
2015-06-07 23:56:52 +02:00
|
|
|
// TODO: Is this the best place for this?
|
2015-06-15 18:00:26 +02:00
|
|
|
if (VfsDirectoryExists(L"maps/"))
|
|
|
|
CXeromyces::AddValidator(g_VFS, "map", "maps/scenario.rng");
|
2015-06-07 23:56:52 +02:00
|
|
|
|
2011-04-07 04:32:16 +02:00
|
|
|
try
|
|
|
|
{
|
2015-09-20 14:29:59 +02:00
|
|
|
if (!AutostartVisualReplay(args.Get("replay-visual")) && !Autostart(args))
|
2011-04-07 04:32:16 +02:00
|
|
|
{
|
|
|
|
const bool setup_gui = ((flags & INIT_NO_GUI) == 0);
|
2012-10-17 22:33:50 +02:00
|
|
|
// We only want to display the splash screen at startup
|
2021-05-22 21:28:40 +02:00
|
|
|
std::shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetScriptInterface();
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 19:29:17 +01:00
|
|
|
ScriptRequest rq(scriptInterface);
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue data(rq.cx);
|
2012-10-17 22:33:50 +02:00
|
|
|
if (g_GUI)
|
|
|
|
{
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(rq, &data, "isStartup", true);
|
2018-04-15 03:46:28 +02:00
|
|
|
if (!installedMods.empty())
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, data, "installedMods", installedMods);
|
2012-10-17 22:33:50 +02:00
|
|
|
}
|
2018-04-15 03:46:28 +02:00
|
|
|
InitPs(setup_gui, installedMods.empty() ? L"page_pregame.xml" : L"page_modmod.xml", g_GUI->GetScriptInterface().get(), data);
|
2011-04-07 04:32:16 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-23 00:27:53 +02:00
|
|
|
catch (PSERROR_Game_World_MapLoadFailed& e)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2011-04-07 04:32:16 +02:00
|
|
|
// Map Loading failed
|
|
|
|
|
|
|
|
// Start the engine so we have a GUI
|
2014-08-04 22:14:17 +02:00
|
|
|
InitPs(true, L"page_pregame.xml", NULL, JS::UndefinedHandleValue);
|
2011-04-07 04:32:16 +02:00
|
|
|
|
|
|
|
// Call script function to do the actual work
|
|
|
|
// (delete game data, switch GUI page, show error, etc.)
|
|
|
|
CancelLoad(CStr(e.what()).FromUTF8());
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-15 08:34:17 +02:00
|
|
|
bool InitNonVisual(const CmdLineArgs& args)
|
2017-05-23 21:26:33 +02:00
|
|
|
{
|
2022-05-15 08:34:17 +02:00
|
|
|
return Autostart(args);
|
2017-05-23 21:26:33 +02:00
|
|
|
}
|
|
|
|
|
2014-06-01 10:18:46 +02:00
|
|
|
/**
|
|
|
|
* Temporarily loads a scenario map and retrieves the "ScriptSettings" JSON
|
|
|
|
* data from it.
|
|
|
|
* The scenario map format is used for scenario and skirmish map types (random
|
|
|
|
* games do not use a "map" (format) but a small JavaScript program which
|
|
|
|
* creates a map on the fly). It contains a section to initialize the game
|
|
|
|
* setup screen.
|
2014-08-25 18:02:40 +02:00
|
|
|
* @param mapPath Absolute path (from VFS root) to the map file to peek in.
|
2014-06-01 10:18:46 +02:00
|
|
|
* @return ScriptSettings in JSON format extracted from the map.
|
|
|
|
*/
|
|
|
|
CStr8 LoadSettingsOfScenarioMap(const VfsPath &mapPath)
|
|
|
|
{
|
|
|
|
CXeromyces mapFile;
|
|
|
|
const char *pathToSettings[] =
|
|
|
|
{
|
|
|
|
"Scenario", "ScriptSettings", "" // Path to JSON data in map
|
|
|
|
};
|
|
|
|
|
|
|
|
Status loadResult = mapFile.Load(g_VFS, mapPath);
|
|
|
|
|
|
|
|
if (INFO::OK != loadResult)
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("LoadSettingsOfScenarioMap: Unable to load map file '%s'", mapPath.string8());
|
2014-09-17 03:15:03 +02:00
|
|
|
throw PSERROR_Game_World_MapLoadFailed("Unable to load map file, check the path for typos.");
|
2014-06-01 10:18:46 +02:00
|
|
|
}
|
|
|
|
XMBElement mapElement = mapFile.GetRoot();
|
|
|
|
|
|
|
|
// Select the ScriptSettings node in the map file...
|
2015-06-01 02:29:35 +02:00
|
|
|
for (int i = 0; pathToSettings[i][0]; ++i)
|
2014-06-01 10:18:46 +02:00
|
|
|
{
|
|
|
|
int childId = mapFile.GetElementID(pathToSettings[i]);
|
|
|
|
|
2015-06-01 02:29:35 +02:00
|
|
|
XMBElementList nodes = mapElement.GetChildNodes();
|
|
|
|
auto it = std::find_if(nodes.begin(), nodes.end(), [&childId](const XMBElement& child) {
|
|
|
|
return child.GetNodeName() == childId;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (it != nodes.end())
|
|
|
|
mapElement = *it;
|
2014-06-01 10:18:46 +02:00
|
|
|
}
|
|
|
|
// ... they contain a JSON document to initialize the game setup
|
|
|
|
// screen
|
|
|
|
return mapElement.GetText();
|
|
|
|
}
|
|
|
|
|
2022-05-15 08:34:17 +02:00
|
|
|
// TODO: this essentially duplicates the CGUI logic to load directory or scripts.
|
|
|
|
// NB: this won't make sure to not double-load scripts, unlike the GUI.
|
|
|
|
void AutostartLoadScript(const ScriptInterface& scriptInterface, const VfsPath& path)
|
|
|
|
{
|
|
|
|
if (path.IsDirectory())
|
|
|
|
{
|
|
|
|
VfsPaths pathnames;
|
|
|
|
vfs::GetPathnames(g_VFS, path, L"*.js", pathnames);
|
|
|
|
for (const VfsPath& file : pathnames)
|
|
|
|
scriptInterface.LoadGlobalScriptFile(file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
scriptInterface.LoadGlobalScriptFile(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this essentially duplicates the CGUI function
|
|
|
|
CParamNode GetTemplate(const std::string& templateName)
|
|
|
|
{
|
|
|
|
// This is very cheap to create so let's just do it every time.
|
|
|
|
CTemplateLoader templateLoader;
|
|
|
|
|
2022-12-30 08:34:23 +01:00
|
|
|
const CParamNode& templateRoot = templateLoader.GetTemplateFileData(templateName).GetOnlyChild();
|
2022-05-15 08:34:17 +02:00
|
|
|
if (!templateRoot.IsOk())
|
|
|
|
LOGERROR("Invalid template found for '%s'", templateName.c_str());
|
|
|
|
|
|
|
|
return templateRoot;
|
|
|
|
}
|
|
|
|
|
2014-09-17 03:15:03 +02:00
|
|
|
/*
|
2016-05-04 08:51:34 +02:00
|
|
|
* Command line options for autostart
|
|
|
|
* (keep synchronized with binaries/system/readme.txt):
|
|
|
|
*
|
|
|
|
* -autostart="TYPEDIR/MAPNAME" enables autostart and sets MAPNAME;
|
|
|
|
* TYPEDIR is skirmishes, scenarios, or random
|
2023-06-14 08:35:27 +02:00
|
|
|
* -autostart-biome=BIOME sets BIOME for a random map
|
2017-06-08 16:47:55 +02:00
|
|
|
* -autostart-seed=SEED sets randomization seed value (default 0, use -1 for random)
|
2016-05-04 08:51:34 +02:00
|
|
|
* -autostart-ai=PLAYER:AI sets the AI for PLAYER (e.g. 2:petra)
|
|
|
|
* -autostart-aidiff=PLAYER:DIFF sets the DIFFiculty of PLAYER's AI
|
2023-05-10 17:34:38 +02:00
|
|
|
* (default 3, 0: sandbox, 5: very hard)
|
2016-05-04 08:51:34 +02:00
|
|
|
* -autostart-aiseed=AISEED sets the seed used for the AI random
|
|
|
|
* generator (default 0, use -1 for random)
|
2018-04-04 20:46:36 +02:00
|
|
|
* -autostart-player=NUMBER sets the playerID in non-networked games (default 1, use -1 for observer)
|
2022-03-06 22:12:16 +01:00
|
|
|
* -autostart-civ=PLAYER:CIV sets PLAYER's civilisation to CIV (skirmish and random maps only).
|
|
|
|
* Use random for a random civ.
|
2016-05-04 08:51:34 +02:00
|
|
|
* -autostart-team=PLAYER:TEAM sets the team for PLAYER (e.g. 2:2).
|
2018-03-16 01:12:58 +01:00
|
|
|
* -autostart-ceasefire=NUM sets a ceasefire duration NUM
|
|
|
|
* (default 0 minutes)
|
2017-05-23 21:26:33 +02:00
|
|
|
* -autostart-nonvisual disable any graphics and sounds
|
|
|
|
* -autostart-victory=SCRIPTNAME sets the victory conditions with SCRIPTNAME
|
|
|
|
* located in simulation/data/settings/victory_conditions/
|
2020-10-25 22:00:52 +01:00
|
|
|
* (default conquest). When the first given SCRIPTNAME is
|
2019-03-16 15:20:28 +01:00
|
|
|
* "endless", no victory conditions will apply.
|
2018-03-16 00:46:29 +01:00
|
|
|
* -autostart-wonderduration=NUM sets the victory duration NUM for wonder victory condition
|
2018-02-06 20:44:05 +01:00
|
|
|
* (default 10 minutes)
|
2018-03-16 00:46:29 +01:00
|
|
|
* -autostart-relicduration=NUM sets the victory duration NUM for relic victory condition
|
2018-02-06 20:44:05 +01:00
|
|
|
* (default 10 minutes)
|
2018-03-16 00:46:29 +01:00
|
|
|
* -autostart-reliccount=NUM sets the number of relics for relic victory condition
|
|
|
|
* (default 2 relics)
|
2019-07-03 23:36:40 +02:00
|
|
|
* -autostart-disable-replay disable saving of replays
|
2014-09-17 03:15:03 +02:00
|
|
|
*
|
|
|
|
* Multiplayer:
|
2016-05-04 08:51:34 +02:00
|
|
|
* -autostart-playername=NAME sets local player NAME (default 'anonymous')
|
|
|
|
* -autostart-host sets multiplayer host mode
|
|
|
|
* -autostart-host-players=NUMBER sets NUMBER of human players for multiplayer
|
|
|
|
* game (default 2)
|
|
|
|
* -autostart-client=IP sets multiplayer client to join host at
|
|
|
|
* given IP address
|
2014-09-17 03:15:03 +02:00
|
|
|
* Random maps only:
|
2016-05-04 08:51:34 +02:00
|
|
|
* -autostart-size=TILES sets random map size in TILES (default 192)
|
|
|
|
* -autostart-players=NUMBER sets NUMBER of players on random map
|
|
|
|
* (default 2)
|
2014-09-17 03:15:03 +02:00
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* 1) "Bob" will host a 2 player game on the Arcadia map:
|
2022-03-06 22:12:16 +01:00
|
|
|
* -autostart="scenarios/arcadia" -autostart-host -autostart-host-players=2 -autostart-playername="Bob"
|
2018-04-04 20:46:36 +02:00
|
|
|
* "Alice" joins the match as player 2:
|
2022-03-06 22:12:16 +01:00
|
|
|
* -autostart-client=127.0.0.1 -autostart-playername="Alice"
|
2018-04-04 20:46:36 +02:00
|
|
|
* The players use the developer overlay to control players.
|
2023-05-10 18:02:53 +02:00
|
|
|
*
|
2014-09-17 03:15:03 +02:00
|
|
|
* 2) Load Alpine Lakes random map with random seed, 2 players (Athens and Britons), and player 2 is PetraBot:
|
|
|
|
* -autostart="random/alpine_lakes" -autostart-seed=-1 -autostart-players=2 -autostart-civ=1:athen -autostart-civ=2:brit -autostart-ai=2:petra
|
2023-05-10 18:02:53 +02:00
|
|
|
*
|
|
|
|
* 3) Observe the PetraBot on a triggerscript map:
|
|
|
|
* -autostart="random/jebel_barkal" -autostart-seed=-1 -autostart-players=2 -autostart-civ=1:athen -autostart-civ=2:brit -autostart-ai=1:petra -autostart-ai=2:petra -autostart-player=-1
|
2018-04-04 20:46:36 +02:00
|
|
|
*/
|
2011-04-07 04:32:16 +02:00
|
|
|
bool Autostart(const CmdLineArgs& args)
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
2022-05-15 08:34:17 +02:00
|
|
|
if (!args.Has("autostart-client") && !args.Has("autostart"))
|
|
|
|
return false;
|
|
|
|
|
2022-03-06 22:12:16 +01:00
|
|
|
// Get optional playername.
|
|
|
|
CStrW userName = L"anonymous";
|
|
|
|
if (args.Has("autostart-playername"))
|
|
|
|
userName = args.Get("autostart-playername").FromUTF8();
|
|
|
|
|
|
|
|
// Create some scriptinterface to store the js values for the settings.
|
|
|
|
ScriptInterface scriptInterface("Engine", "Game Setup", g_ScriptContext);
|
|
|
|
|
|
|
|
ScriptRequest rq(scriptInterface);
|
2022-05-15 08:34:17 +02:00
|
|
|
|
|
|
|
// We use the javascript gameSettings to handle options, but that requires running JS.
|
|
|
|
// Since we don't want to use the full Gui manager, we load an entrypoint script
|
|
|
|
// that can run the priviledged "LoadScript" function, and then call the appropriate function.
|
|
|
|
ScriptFunction::Register<&AutostartLoadScript>(rq, "LoadScript");
|
|
|
|
// Load the entire folder to allow mods to extend the entrypoint without copying the whole file.
|
|
|
|
AutostartLoadScript(scriptInterface, VfsPath(L"autostart/"));
|
|
|
|
|
|
|
|
// Provide some required functions to the script.
|
|
|
|
if (args.Has("autostart-nonvisual"))
|
|
|
|
ScriptFunction::Register<&GetTemplate>(rq, "GetTemplate");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
JSI_GUIManager::RegisterScriptFunctions(rq);
|
|
|
|
// TODO: this loads pregame, which is hardcoded to exist by various code paths. That ought be changed.
|
|
|
|
InitPs(false, L"page_pregame.xml", g_GUI->GetScriptInterface().get(), JS::UndefinedHandleValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSI_Game::RegisterScriptFunctions(rq);
|
|
|
|
JSI_Main::RegisterScriptFunctions(rq);
|
|
|
|
JSI_Simulation::RegisterScriptFunctions(rq);
|
|
|
|
JSI_VFS::RegisterScriptFunctions_ReadWriteAnywhere(rq);
|
|
|
|
JSI_Network::RegisterScriptFunctions(rq);
|
|
|
|
|
2022-03-06 22:12:16 +01:00
|
|
|
JS::RootedValue sessionInitData(rq.cx);
|
|
|
|
|
|
|
|
if (args.Has("autostart-client"))
|
|
|
|
{
|
|
|
|
CStr ip = args.Get("autostart-client");
|
|
|
|
if (ip.empty())
|
|
|
|
ip = "127.0.0.1";
|
|
|
|
|
|
|
|
Script::CreateObject(
|
|
|
|
rq,
|
|
|
|
&sessionInitData,
|
|
|
|
"playerName", userName,
|
|
|
|
"ip", ip,
|
|
|
|
"port", PS_DEFAULT_PORT,
|
|
|
|
"storeReplay", !args.Has("autostart-disable-replay"));
|
|
|
|
|
2022-05-15 08:34:17 +02:00
|
|
|
JS::RootedValue global(rq.cx, rq.globalValue());
|
|
|
|
if (!ScriptFunction::CallVoid(rq, global, "autostartClient", sessionInitData, true))
|
|
|
|
return false;
|
2022-03-06 22:12:16 +01:00
|
|
|
|
2022-05-15 08:34:17 +02:00
|
|
|
bool shouldQuit = false;
|
|
|
|
while (!shouldQuit)
|
|
|
|
{
|
|
|
|
g_NetClient->Poll();
|
|
|
|
ScriptFunction::Call(rq, global, "onTick", shouldQuit);
|
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(200));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.Has("autostart-nonvisual"))
|
|
|
|
{
|
|
|
|
LDR_NonprogressiveLoad();
|
|
|
|
g_Game->ReallyStartGame();
|
|
|
|
}
|
2022-03-06 22:12:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-22 02:34:45 +01:00
|
|
|
CStr autoStartName = args.Get("autostart");
|
2012-02-25 18:29:27 +01:00
|
|
|
|
2011-03-22 02:34:45 +01:00
|
|
|
if (autoStartName.empty())
|
2010-05-20 02:59:01 +02:00
|
|
|
return false;
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue attrs(rq.cx);
|
|
|
|
JS::RootedValue settings(rq.cx);
|
|
|
|
JS::RootedValue playerData(rq.cx);
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(rq, &attrs);
|
|
|
|
Script::CreateObject(rq, &settings);
|
|
|
|
Script::CreateArray(rq, &playerData);
|
2011-03-22 02:34:45 +01:00
|
|
|
|
2014-06-01 10:18:46 +02:00
|
|
|
// The directory in front of the actual map name indicates which type
|
|
|
|
// of map is being loaded. Drawback of this approach is the association
|
|
|
|
// of map types and folders is hard-coded, but benefits are:
|
2014-09-17 03:15:03 +02:00
|
|
|
// - No need to pass the map type via command line separately
|
2014-06-01 10:18:46 +02:00
|
|
|
// - Prevents mixing up of scenarios and skirmish maps to some degree
|
|
|
|
Path mapPath = Path(autoStartName);
|
|
|
|
std::wstring mapDirectory = mapPath.Parent().Filename().string();
|
|
|
|
std::string mapType;
|
|
|
|
|
|
|
|
if (mapDirectory == L"random")
|
2011-03-22 02:34:45 +01:00
|
|
|
{
|
2011-04-16 06:04:06 +02:00
|
|
|
// Get optional map size argument (default 192)
|
|
|
|
uint mapSize = 192;
|
2011-04-07 04:32:16 +02:00
|
|
|
if (args.Has("autostart-size"))
|
|
|
|
{
|
|
|
|
CStr size = args.Get("autostart-size");
|
|
|
|
mapSize = size.ToUInt();
|
|
|
|
}
|
2011-03-22 02:34:45 +01:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "Size", mapSize); // Random map size (in patches)
|
2011-03-22 02:34:45 +01:00
|
|
|
|
2023-06-14 08:35:27 +02:00
|
|
|
if (args.Has("autostart-biome"))
|
|
|
|
{
|
|
|
|
CStr biome = args.Get("autostart-biome");
|
|
|
|
Script::SetProperty(rq, settings, "Biome", biome);
|
|
|
|
}
|
|
|
|
|
2011-04-07 04:32:16 +02:00
|
|
|
// Get optional number of players (default 2)
|
2011-03-22 02:34:45 +01:00
|
|
|
size_t numPlayers = 2;
|
2011-04-07 04:32:16 +02:00
|
|
|
if (args.Has("autostart-players"))
|
|
|
|
{
|
|
|
|
CStr num = args.Get("autostart-players");
|
|
|
|
numPlayers = num.ToUInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up player data
|
2011-03-22 02:34:45 +01:00
|
|
|
for (size_t i = 0; i < numPlayers; ++i)
|
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue player(rq.cx);
|
2011-03-22 02:34:45 +01:00
|
|
|
|
2012-05-10 01:06:03 +02:00
|
|
|
// We could load player_defaults.json here, but that would complicate the logic
|
2014-09-17 03:15:03 +02:00
|
|
|
// even more and autostart is only intended for developers anyway
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(rq, &player, "Civ", "athen");
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetPropertyInt(rq, playerData, i, player);
|
2011-03-22 02:34:45 +01:00
|
|
|
}
|
2014-06-01 10:18:46 +02:00
|
|
|
mapType = "random";
|
|
|
|
}
|
2022-03-06 22:12:16 +01:00
|
|
|
else if (mapDirectory == L"scenarios")
|
|
|
|
mapType = "scenario";
|
|
|
|
else if (mapDirectory == L"skirmishes")
|
|
|
|
mapType = "skirmish";
|
2014-09-17 03:15:03 +02:00
|
|
|
else
|
2014-06-01 10:18:46 +02:00
|
|
|
{
|
2015-01-22 21:37:38 +01:00
|
|
|
LOGERROR("Autostart: Unrecognized map type '%s'", utf8_from_wstring(mapDirectory));
|
2014-09-17 03:15:03 +02:00
|
|
|
throw PSERROR_Game_World_MapLoadFailed("Unrecognized map type.\nConsult readme.txt for the currently supported types.");
|
2014-06-01 10:18:46 +02:00
|
|
|
}
|
2017-06-08 16:47:55 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, attrs, "mapType", mapType);
|
|
|
|
Script::SetProperty(rq, attrs, "map", "maps/" + autoStartName);
|
|
|
|
Script::SetProperty(rq, settings, "mapType", mapType);
|
|
|
|
Script::SetProperty(rq, settings, "CheatsEnabled", true);
|
2010-10-31 23:00:28 +01:00
|
|
|
|
2017-06-08 16:47:55 +02:00
|
|
|
// The seed is used for both random map generation and simulation
|
|
|
|
u32 seed = 0;
|
|
|
|
if (args.Has("autostart-seed"))
|
|
|
|
{
|
|
|
|
CStr seedArg = args.Get("autostart-seed");
|
|
|
|
if (seedArg == "-1")
|
|
|
|
seed = rand();
|
|
|
|
else
|
|
|
|
seed = seedArg.ToULong();
|
|
|
|
}
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "Seed", seed);
|
2017-06-08 16:47:55 +02:00
|
|
|
|
2014-11-16 20:53:29 +01:00
|
|
|
// Set seed for AIs
|
|
|
|
u32 aiseed = 0;
|
|
|
|
if (args.Has("autostart-aiseed"))
|
|
|
|
{
|
|
|
|
CStr seedArg = args.Get("autostart-aiseed");
|
|
|
|
if (seedArg == "-1")
|
|
|
|
aiseed = rand();
|
|
|
|
else
|
|
|
|
aiseed = seedArg.ToULong();
|
|
|
|
}
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "AISeed", aiseed);
|
2014-11-16 20:53:29 +01:00
|
|
|
|
2011-03-22 02:34:45 +01:00
|
|
|
// Set player data for AIs
|
2016-04-05 20:21:10 +02:00
|
|
|
// attrs.settings = { PlayerData: [ { AI: ... }, ... ] }
|
|
|
|
// or = { PlayerData: [ null, { AI: ... }, ... ] } when gaia set
|
|
|
|
int offset = 1;
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue player(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
if (Script::GetPropertyInt(rq, playerData, 0, &player) && player.isNull())
|
2016-04-05 20:21:10 +02:00
|
|
|
offset = 0;
|
|
|
|
|
2016-05-04 08:51:34 +02:00
|
|
|
// Set teams
|
|
|
|
if (args.Has("autostart-team"))
|
|
|
|
{
|
|
|
|
std::vector<CStr> civArgs = args.GetMultiple("autostart-team");
|
|
|
|
for (size_t i = 0; i < civArgs.size(); ++i)
|
|
|
|
{
|
2016-11-23 14:02:58 +01:00
|
|
|
int playerID = civArgs[i].BeforeFirst(":").ToInt();
|
2016-05-04 08:51:34 +02:00
|
|
|
|
|
|
|
// Instead of overwriting existing player data, modify the array
|
2020-11-26 23:28:50 +01:00
|
|
|
JS::RootedValue currentPlayer(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
if (!Script::GetPropertyInt(rq, playerData, playerID-offset, ¤tPlayer) || currentPlayer.isUndefined())
|
|
|
|
Script::CreateObject(rq, ¤tPlayer);
|
2016-05-04 08:51:34 +02:00
|
|
|
|
|
|
|
int teamID = civArgs[i].AfterFirst(":").ToInt() - 1;
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, currentPlayer, "Team", teamID);
|
|
|
|
Script::SetPropertyInt(rq, playerData, playerID-offset, currentPlayer);
|
2016-05-04 08:51:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 01:12:58 +01:00
|
|
|
int ceasefire = 0;
|
|
|
|
if (args.Has("autostart-ceasefire"))
|
|
|
|
ceasefire = args.Get("autostart-ceasefire").ToInt();
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "Ceasefire", ceasefire);
|
2018-03-16 01:12:58 +01:00
|
|
|
|
2011-01-12 13:29:00 +01:00
|
|
|
if (args.Has("autostart-ai"))
|
|
|
|
{
|
|
|
|
std::vector<CStr> aiArgs = args.GetMultiple("autostart-ai");
|
|
|
|
for (size_t i = 0; i < aiArgs.size(); ++i)
|
|
|
|
{
|
2014-09-17 03:15:03 +02:00
|
|
|
int playerID = aiArgs[i].BeforeFirst(":").ToInt();
|
|
|
|
|
2011-06-28 01:27:25 +02:00
|
|
|
// Instead of overwriting existing player data, modify the array
|
2020-11-26 23:28:50 +01:00
|
|
|
JS::RootedValue currentPlayer(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
if (!Script::GetPropertyInt(rq, playerData, playerID-offset, ¤tPlayer) || currentPlayer.isUndefined())
|
|
|
|
Script::CreateObject(rq, ¤tPlayer);
|
2011-02-27 20:20:36 +01:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, currentPlayer, "AI", aiArgs[i].AfterFirst(":"));
|
|
|
|
Script::SetProperty(rq, currentPlayer, "AIDiff", 3);
|
|
|
|
Script::SetProperty(rq, currentPlayer, "AIBehavior", "balanced");
|
|
|
|
Script::SetPropertyInt(rq, playerData, playerID-offset, currentPlayer);
|
2011-01-12 13:29:00 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 21:44:48 +01:00
|
|
|
// Set AI difficulty
|
|
|
|
if (args.Has("autostart-aidiff"))
|
|
|
|
{
|
|
|
|
std::vector<CStr> civArgs = args.GetMultiple("autostart-aidiff");
|
|
|
|
for (size_t i = 0; i < civArgs.size(); ++i)
|
|
|
|
{
|
2014-09-17 03:15:03 +02:00
|
|
|
int playerID = civArgs[i].BeforeFirst(":").ToInt();
|
|
|
|
|
2013-03-13 21:44:48 +01:00
|
|
|
// Instead of overwriting existing player data, modify the array
|
2020-11-26 23:28:50 +01:00
|
|
|
JS::RootedValue currentPlayer(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
if (!Script::GetPropertyInt(rq, playerData, playerID-offset, ¤tPlayer) || currentPlayer.isUndefined())
|
|
|
|
Script::CreateObject(rq, ¤tPlayer);
|
2014-09-17 03:15:03 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, currentPlayer, "AIDiff", civArgs[i].AfterFirst(":").ToInt());
|
|
|
|
Script::SetPropertyInt(rq, playerData, playerID-offset, currentPlayer);
|
2013-03-13 21:44:48 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-09 15:09:06 +01:00
|
|
|
// Set player data for Civs
|
|
|
|
if (args.Has("autostart-civ"))
|
|
|
|
{
|
2014-09-17 03:15:03 +02:00
|
|
|
if (mapDirectory != L"scenarios")
|
2013-03-09 15:09:06 +01:00
|
|
|
{
|
2014-09-17 03:15:03 +02:00
|
|
|
std::vector<CStr> civArgs = args.GetMultiple("autostart-civ");
|
|
|
|
for (size_t i = 0; i < civArgs.size(); ++i)
|
2013-03-09 15:09:06 +01:00
|
|
|
{
|
2014-09-17 03:15:03 +02:00
|
|
|
int playerID = civArgs[i].BeforeFirst(":").ToInt();
|
|
|
|
|
|
|
|
// Instead of overwriting existing player data, modify the array
|
2020-11-26 23:28:50 +01:00
|
|
|
JS::RootedValue currentPlayer(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
if (!Script::GetPropertyInt(rq, playerData, playerID-offset, ¤tPlayer) || currentPlayer.isUndefined())
|
|
|
|
Script::CreateObject(rq, ¤tPlayer);
|
2016-11-23 14:02:58 +01:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, currentPlayer, "Civ", civArgs[i].AfterFirst(":"));
|
|
|
|
Script::SetPropertyInt(rq, playerData, playerID-offset, currentPlayer);
|
2014-09-17 03:15:03 +02:00
|
|
|
}
|
2013-03-09 15:09:06 +01:00
|
|
|
}
|
2014-09-17 03:15:03 +02:00
|
|
|
else
|
2015-01-22 21:31:30 +01:00
|
|
|
LOGWARNING("Autostart: Option 'autostart-civ' is invalid for scenarios");
|
2013-03-09 15:09:06 +01:00
|
|
|
}
|
2011-01-12 13:29:00 +01:00
|
|
|
|
2017-05-23 21:26:33 +02:00
|
|
|
// Add additional scripts to the TriggerScripts property
|
|
|
|
std::vector<CStrW> triggerScriptsVector;
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue triggerScripts(rq.cx);
|
2017-05-23 21:26:33 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
if (Script::HasProperty(rq, settings, "TriggerScripts"))
|
2017-05-23 21:26:33 +02:00
|
|
|
{
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::GetProperty(rq, settings, "TriggerScripts", &triggerScripts);
|
2021-05-13 11:43:33 +02:00
|
|
|
Script::FromJSVal(rq, triggerScripts, triggerScriptsVector);
|
2017-05-23 21:26:33 +02:00
|
|
|
}
|
|
|
|
|
2019-08-25 13:02:55 +02:00
|
|
|
if (!CRenderer::IsInitialised())
|
2017-05-23 21:26:33 +02:00
|
|
|
{
|
|
|
|
CStr nonVisualScript = "scripts/NonVisualTrigger.js";
|
|
|
|
triggerScriptsVector.push_back(nonVisualScript.FromUTF8());
|
|
|
|
}
|
|
|
|
|
2022-03-06 22:12:16 +01:00
|
|
|
Script::ToJSVal(rq, &triggerScripts, triggerScriptsVector);
|
|
|
|
Script::SetProperty(rq, settings, "TriggerScripts", triggerScripts);
|
|
|
|
|
2018-03-09 22:51:18 +01:00
|
|
|
std::vector<CStr> victoryConditions(1, "conquest");
|
2017-05-23 21:26:33 +02:00
|
|
|
if (args.Has("autostart-victory"))
|
2018-03-09 22:51:18 +01:00
|
|
|
victoryConditions = args.GetMultiple("autostart-victory");
|
2017-05-23 21:26:33 +02:00
|
|
|
|
2018-03-09 22:51:18 +01:00
|
|
|
if (victoryConditions.size() == 1 && victoryConditions[0] == "endless")
|
|
|
|
victoryConditions.clear();
|
2017-05-23 21:26:33 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "VictoryConditions", victoryConditions);
|
2018-03-09 22:51:18 +01:00
|
|
|
|
2018-02-06 20:44:05 +01:00
|
|
|
int wonderDuration = 10;
|
|
|
|
if (args.Has("autostart-wonderduration"))
|
|
|
|
wonderDuration = args.Get("autostart-wonderduration").ToInt();
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "WonderDuration", wonderDuration);
|
2018-02-06 20:44:05 +01:00
|
|
|
|
|
|
|
int relicDuration = 10;
|
|
|
|
if (args.Has("autostart-relicduration"))
|
|
|
|
relicDuration = args.Get("autostart-relicduration").ToInt();
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "RelicDuration", relicDuration);
|
2017-05-23 21:26:33 +02:00
|
|
|
|
2018-03-16 00:46:29 +01:00
|
|
|
int relicCount = 2;
|
|
|
|
if (args.Has("autostart-reliccount"))
|
|
|
|
relicCount = args.Get("autostart-reliccount").ToInt();
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, settings, "RelicCount", relicCount);
|
2018-03-16 00:46:29 +01:00
|
|
|
|
2022-03-06 22:12:16 +01:00
|
|
|
// Add player data to map settings.
|
|
|
|
Script::SetProperty(rq, settings, "PlayerData", playerData);
|
|
|
|
|
|
|
|
// Add map settings to game attributes.
|
|
|
|
Script::SetProperty(rq, attrs, "settings", settings);
|
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
if (args.Has("autostart-host"))
|
|
|
|
{
|
2022-03-06 22:12:16 +01:00
|
|
|
int maxPlayers = 2;
|
2014-09-17 03:15:03 +02:00
|
|
|
if (args.Has("autostart-host-players"))
|
|
|
|
maxPlayers = args.Get("autostart-host-players").ToUInt();
|
2010-05-20 02:59:01 +02:00
|
|
|
|
2022-03-06 22:12:16 +01:00
|
|
|
Script::CreateObject(
|
|
|
|
rq,
|
|
|
|
&sessionInitData,
|
|
|
|
"attribs", attrs,
|
|
|
|
"playerName", userName,
|
|
|
|
"port", PS_DEFAULT_PORT,
|
|
|
|
"maxPlayers", maxPlayers,
|
|
|
|
"storeReplay", !args.Has("autostart-disable-replay"));
|
2010-10-31 23:00:28 +01:00
|
|
|
|
2022-05-15 08:34:17 +02:00
|
|
|
JS::RootedValue global(rq.cx, rq.globalValue());
|
|
|
|
if (!ScriptFunction::CallVoid(rq, global, "autostartHost", sessionInitData, true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// In MP host mode, we need to wait until clients have loaded.
|
|
|
|
bool shouldQuit = false;
|
|
|
|
while (!shouldQuit)
|
|
|
|
{
|
|
|
|
g_NetClient->Poll();
|
|
|
|
ScriptFunction::Call(rq, global, "onTick", shouldQuit);
|
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(200));
|
|
|
|
}
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-06 22:12:16 +01:00
|
|
|
JS::RootedValue localPlayer(rq.cx);
|
|
|
|
Script::CreateObject(
|
|
|
|
rq,
|
|
|
|
&localPlayer,
|
|
|
|
"player", args.Has("autostart-player") ? args.Get("autostart-player").ToInt() : 1,
|
|
|
|
"name", userName);
|
|
|
|
|
|
|
|
JS::RootedValue playerAssignments(rq.cx);
|
|
|
|
Script::CreateObject(rq, &playerAssignments);
|
|
|
|
Script::SetProperty(rq, playerAssignments, "local", localPlayer);
|
2011-04-07 04:32:16 +02:00
|
|
|
|
2022-03-06 22:12:16 +01:00
|
|
|
Script::CreateObject(
|
|
|
|
rq,
|
|
|
|
&sessionInitData,
|
|
|
|
"attribs", attrs,
|
|
|
|
"playerAssignments", playerAssignments,
|
|
|
|
"storeReplay", !args.Has("autostart-disable-replay"));
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2022-05-15 08:34:17 +02:00
|
|
|
JS::RootedValue global(rq.cx, rq.globalValue());
|
|
|
|
if (!ScriptFunction::CallVoid(rq, global, "autostartHost", sessionInitData, false))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.Has("autostart-nonvisual"))
|
|
|
|
{
|
|
|
|
LDR_NonprogressiveLoad();
|
|
|
|
g_Game->ReallyStartGame();
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
2009-04-18 17:27:38 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
return true;
|
2009-11-06 19:35:32 +01:00
|
|
|
}
|
2011-04-07 04:32:16 +02:00
|
|
|
|
2015-09-30 22:28:23 +02:00
|
|
|
bool AutostartVisualReplay(const std::string& replayFile)
|
2015-06-06 10:45:49 +02:00
|
|
|
{
|
|
|
|
if (!FileExists(OsPath(replayFile)))
|
|
|
|
return false;
|
|
|
|
|
2019-08-25 13:02:55 +02:00
|
|
|
g_Game = new CGame(false);
|
2015-06-06 10:45:49 +02:00
|
|
|
g_Game->SetPlayerID(-1);
|
2015-09-13 21:03:33 +02:00
|
|
|
g_Game->StartVisualReplay(replayFile);
|
2015-06-06 10:45:49 +02:00
|
|
|
|
|
|
|
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 19:29:17 +01:00
|
|
|
ScriptRequest rq(scriptInterface);
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue attrs(rq.cx, g_Game->GetSimulation2()->GetInitAttributes());
|
2018-04-04 20:46:36 +02:00
|
|
|
|
2022-03-06 22:12:16 +01:00
|
|
|
JS::RootedValue playerAssignments(rq.cx);
|
|
|
|
Script::CreateObject(rq, &playerAssignments);
|
|
|
|
JS::RootedValue localPlayer(rq.cx);
|
|
|
|
Script::CreateObject(rq, &localPlayer, "player", g_Game->GetPlayerID());
|
|
|
|
Script::SetProperty(rq, playerAssignments, "local", localPlayer);
|
|
|
|
|
|
|
|
JS::RootedValue sessionInitData(rq.cx);
|
|
|
|
|
|
|
|
Script::CreateObject(
|
|
|
|
rq,
|
|
|
|
&sessionInitData,
|
|
|
|
"attribs", attrs,
|
|
|
|
"playerAssignments", playerAssignments);
|
|
|
|
|
|
|
|
InitPs(true, L"page_loading.xml", &scriptInterface, sessionInitData);
|
2015-06-06 10:45:49 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-07 04:32:16 +02:00
|
|
|
void CancelLoad(const CStrW& message)
|
|
|
|
{
|
2021-05-22 21:28:40 +02:00
|
|
|
std::shared_ptr<ScriptInterface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 19:29:17 +01:00
|
|
|
ScriptRequest rq(pScriptInterface);
|
2016-11-23 14:02:58 +01:00
|
|
|
|
2020-11-14 09:46:32 +01:00
|
|
|
JS::RootedValue global(rq.cx, rq.globalValue());
|
2017-06-16 00:44:24 +02:00
|
|
|
|
2011-04-07 04:32:16 +02:00
|
|
|
LDR_Cancel();
|
|
|
|
|
2017-06-16 00:44:24 +02:00
|
|
|
if (g_GUI &&
|
2019-09-04 17:45:48 +02:00
|
|
|
g_GUI->GetPageCount() &&
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::HasProperty(rq, global, "cancelOnLoadGameError"))
|
2021-05-01 16:04:53 +02:00
|
|
|
ScriptFunction::CallVoid(rq, global, "cancelOnLoadGameError", message);
|
2011-04-07 04:32:16 +02:00
|
|
|
}
|
2014-04-20 22:03:57 +02:00
|
|
|
|
|
|
|
bool InDevelopmentCopy()
|
|
|
|
{
|
|
|
|
if (!g_CheckedIfInDevelopmentCopy)
|
|
|
|
{
|
|
|
|
g_InDevelopmentCopy = (g_VFS->GetFileInfo(L"config/dev.cfg", NULL) == INFO::OK);
|
|
|
|
g_CheckedIfInDevelopmentCopy = true;
|
|
|
|
}
|
|
|
|
return g_InDevelopmentCopy;
|
|
|
|
}
|