2025-08-09 03:01:01 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2009-06-20 09:13:29 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-06-20 09:13:29 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-06-20 09:13:29 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-20 09:13:29 -07:00
|
|
|
*/
|
|
|
|
|
|
2007-06-05 11:35:05 -07:00
|
|
|
#include "precompiled.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
#include "DLLInterface.h"
|
|
|
|
|
|
2025-08-09 03:01:01 -07:00
|
|
|
#include "tools/atlas/AtlasUI/ActorEditor/ActorEditor.h"
|
|
|
|
|
#include "tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h"
|
|
|
|
|
#include "tools/atlas/AtlasUI/General/Datafile.h"
|
|
|
|
|
#include "tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/MessagePasser.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/SharedMemory.h"
|
2006-05-30 22:27:02 -07:00
|
|
|
|
2025-08-09 03:01:01 -07:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <libxml/xmlversion.h>
|
|
|
|
|
#include <wx/app.h>
|
|
|
|
|
#include <wx/chartype.h>
|
|
|
|
|
#include <wx/cmdargs.h>
|
|
|
|
|
#include <wx/config.h>
|
|
|
|
|
#include <wx/debug.h>
|
|
|
|
|
#include <wx/defs.h>
|
|
|
|
|
#include <wx/file.h>
|
|
|
|
|
#include <wx/fileconf.h>
|
|
|
|
|
#include <wx/filename.h>
|
|
|
|
|
#include <wx/frame.h>
|
|
|
|
|
#include <wx/init.h>
|
|
|
|
|
#include <wx/log.h>
|
|
|
|
|
#include <wx/object.h>
|
|
|
|
|
#include <wx/setup.h>
|
|
|
|
|
#include <wx/string.h>
|
|
|
|
|
#include <wx/translation.h>
|
|
|
|
|
#include <wx/unichar.h>
|
|
|
|
|
#include <wx/utils.h>
|
|
|
|
|
#include <wx/wxcrt.h>
|
2009-03-22 13:51:35 -07:00
|
|
|
|
|
|
|
|
#ifndef LIBXML_THREAD_ENABLED
|
|
|
|
|
#error libxml2 must have threading support enabled
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-03-19 18:06:34 -07:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-04-21 07:12:37 -07:00
|
|
|
// If enabled, we'll try to use wxDebugReport to report fatal exceptions.
|
|
|
|
|
// But this is broken on Linux and can cause the UI to deadlock (see comment
|
|
|
|
|
// in OnFatalException), and it's never especially useful, so don't use it.
|
|
|
|
|
#define USE_WX_FATAL_EXCEPTION_REPORT 0
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
// Shared memory allocation functions
|
|
|
|
|
ATLASDLLIMPEXP void* ShareableMalloc(size_t n)
|
|
|
|
|
{
|
|
|
|
|
// TODO: make sure this is thread-safe everywhere. (It is in MSVC with the
|
|
|
|
|
// multithreaded CRT.)
|
|
|
|
|
return malloc(n);
|
|
|
|
|
}
|
|
|
|
|
ATLASDLLIMPEXP void ShareableFree(void* p)
|
|
|
|
|
{
|
# 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
|
|
|
free(p);
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
// Define the function pointers that we'll use when calling those functions.
|
|
|
|
|
// (The game loads the addresses of the above functions, then does the same.)
|
|
|
|
|
namespace AtlasMessage
|
|
|
|
|
{
|
|
|
|
|
void* (*ShareableMallocFptr) (size_t) = &ShareableMalloc;
|
|
|
|
|
void (*ShareableFreeFptr) (void*) = &ShareableFree;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Global variables, to remember state between DllMain and StartWindow and OnInit
|
|
|
|
|
wxString g_InitialWindowType;
|
|
|
|
|
bool g_IsLoaded = false;
|
2006-12-01 12:34:28 -08:00
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
2006-11-11 20:02:36 -08:00
|
|
|
HINSTANCE g_Module;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
|
|
|
|
|
{
|
|
|
|
|
switch (fdwReason)
|
|
|
|
|
{
|
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
|
g_Module = hModule;
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
|
if (g_IsLoaded)
|
|
|
|
|
{
|
|
|
|
|
wxEntryCleanup();
|
|
|
|
|
g_IsLoaded = false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2006-12-01 12:34:28 -08:00
|
|
|
#endif // __WXMSW__
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
using namespace AtlasMessage;
|
|
|
|
|
|
|
|
|
|
MessagePasser* AtlasMessage::g_MessagePasser = NULL;
|
|
|
|
|
|
|
|
|
|
ATLASDLLIMPEXP void Atlas_SetMessagePasser(MessagePasser* passer)
|
|
|
|
|
{
|
|
|
|
|
g_MessagePasser = passer;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-29 03:24:17 -07:00
|
|
|
bool g_HasSetDataDirectory = false;
|
|
|
|
|
ATLASDLLIMPEXP void Atlas_SetDataDirectory(const wchar_t* path)
|
|
|
|
|
{
|
|
|
|
|
Datafile::SetDataDirectory(path);
|
|
|
|
|
g_HasSetDataDirectory = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 15:40:06 -07:00
|
|
|
wxString g_ConfigDir;
|
|
|
|
|
ATLASDLLIMPEXP void Atlas_SetConfigDirectory(const wchar_t* path)
|
|
|
|
|
{
|
|
|
|
|
wxFileName config (path);
|
|
|
|
|
g_ConfigDir = config.GetPath(wxPATH_GET_SEPARATOR);
|
|
|
|
|
}
|
|
|
|
|
|
# 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
|
|
|
ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
2009-03-22 13:51:35 -07:00
|
|
|
// Initialise libxml2
|
|
|
|
|
// (If we're executed from the game instead, it has the responsibility to initialise libxml2)
|
2009-03-22 18:07:08 -07:00
|
|
|
LIBXML_TEST_VERSION
|
2016-11-23 06:09:58 -08:00
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
g_InitialWindowType = type;
|
2006-12-01 12:34:28 -08:00
|
|
|
#ifdef __WXMSW__
|
2006-04-23 16:14:18 -07:00
|
|
|
wxEntry(g_Module);
|
2006-11-11 20:02:36 -08:00
|
|
|
#else
|
2007-09-02 09:50:20 -07:00
|
|
|
#ifdef __WXGTK__
|
2007-03-19 18:06:34 -07:00
|
|
|
// Because we do GL calls from a secondary thread, Xlib needs to
|
|
|
|
|
// be told to support multiple threads safely
|
|
|
|
|
int status = XInitThreads();
|
|
|
|
|
if (status == 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Error enabling thread-safety via XInitThreads\n");
|
|
|
|
|
}
|
2024-10-05 23:28:39 -07:00
|
|
|
#if defined(wxUSE_GLCANVAS_EGL) && wxUSE_GLCANVAS_EGL == 0
|
|
|
|
|
// The glcanvas is currently either built with support for GLX or EGL, if
|
|
|
|
|
// built with GLX support on Wayland we need to use XWayland.
|
|
|
|
|
// https://github.com/wxWidgets/wxWidgets/issues/22325
|
|
|
|
|
const wxString xdgSessionType{wxGetenv("XDG_SESSION_TYPE")};
|
|
|
|
|
const wxString waylandDisplay{wxGetenv("WAYLAND_DISPLAY")};
|
|
|
|
|
if (xdgSessionType == "wayland" || waylandDisplay.Contains("wayland"))
|
|
|
|
|
{
|
|
|
|
|
// GTK has an API to set allowed backends but would require to add it
|
|
|
|
|
// as a direct dependency, so just force it using an envvar.
|
|
|
|
|
wxSetEnv("GDK_BACKEND", "x11");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2007-09-02 09:50:20 -07:00
|
|
|
#endif
|
2006-12-01 12:34:28 -08:00
|
|
|
int argc = 1;
|
2009-03-22 13:51:35 -07:00
|
|
|
char atlas[] = "atlas";
|
|
|
|
|
char *argv[] = {atlas, NULL};
|
2014-09-28 00:03:51 -07:00
|
|
|
#ifndef __WXOSX__
|
2006-11-11 20:02:36 -08:00
|
|
|
wxEntry(argc, argv);
|
2014-09-28 00:03:51 -07:00
|
|
|
#else
|
2024-12-10 02:29:34 -08:00
|
|
|
// Fix for OS X init (see https://gitea.wildfiregames.com/0ad/0ad/issues/2427 )
|
2014-09-28 00:03:51 -07:00
|
|
|
// If we launched from in-game, SDL started NSApplication which will
|
|
|
|
|
// break some things in wxWidgets
|
|
|
|
|
wxEntryStart(argc, argv);
|
|
|
|
|
wxTheApp->OnInit();
|
|
|
|
|
wxTheApp->OnRun();
|
|
|
|
|
wxTheApp->OnExit();
|
|
|
|
|
wxEntryCleanup();
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-11-11 20:02:36 -08:00
|
|
|
#endif
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
2008-09-18 04:31:12 -07:00
|
|
|
ATLASDLLIMPEXP void Atlas_DisplayError(const wchar_t* text, size_t WXUNUSED(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
|
|
|
{
|
|
|
|
|
// This is called from the game thread.
|
|
|
|
|
// wxLog appears to be thread-safe, so that's okay.
|
|
|
|
|
wxLogError(L"%s", text);
|
|
|
|
|
|
|
|
|
|
// TODO: wait for user response (if possible) before returning,
|
|
|
|
|
// and return their status (break/continue/debug/etc), but only in
|
|
|
|
|
// cases where we're certain it won't deadlock (i.e. the UI event loop
|
|
|
|
|
// is still running and won't block before showing the dialog to the user)
|
|
|
|
|
// and where it matters (i.e. errors, not warnings (unless they're going to
|
|
|
|
|
// turn into errors after continuing))
|
2006-09-22 10:43:00 -07:00
|
|
|
|
|
|
|
|
// TODO: 'text' (or at least some copy of it) appears to get leaked when
|
|
|
|
|
// this function is called
|
# 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
|
|
|
|
# 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
|
|
|
class AtlasDLLApp : public wxApp
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
public:
|
# 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
|
|
|
virtual bool OnInit()
|
|
|
|
|
{
|
2006-09-22 10:43:00 -07:00
|
|
|
// _CrtSetBreakAlloc(5632);
|
|
|
|
|
|
2012-04-21 07:12:37 -07:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION && USE_WX_FATAL_EXCEPTION_REPORT
|
2006-04-23 16:14:18 -07:00
|
|
|
if (! wxIsDebuggerRunning())
|
|
|
|
|
wxHandleFatalExceptions();
|
2010-08-29 05:51:52 -07:00
|
|
|
#endif
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2012-03-19 15:40:06 -07:00
|
|
|
#ifndef __WXMSW__ // On Windows we use the registry so don't attempt to set the path.
|
|
|
|
|
// When launching a standalone executable g_ConfigDir may not be
|
|
|
|
|
// set. In this case we default to the XDG base dir spec and use
|
|
|
|
|
// 0ad/config/ as the config directory.
|
|
|
|
|
wxString configPath;
|
|
|
|
|
if (!g_ConfigDir.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
configPath = g_ConfigDir;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wxString xdgConfigHome;
|
|
|
|
|
if (wxGetEnv(_T("XDG_CONFIG_HOME"), &xdgConfigHome) && !xdgConfigHome.IsEmpty())
|
|
|
|
|
configPath = xdgConfigHome + _T("/0ad/config/");
|
|
|
|
|
else
|
|
|
|
|
configPath = wxFileName::GetHomeDir() + _T("/.config/0ad/config/");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
// Initialise the global config file
|
2012-03-19 15:40:06 -07:00
|
|
|
wxConfigBase::Set(new wxConfig(_T("Atlas Editor"), _T("Wildfire Games")
|
|
|
|
|
#ifndef __WXMSW__ // On Windows we use wxRegConfig and setting this changes the Registry key
|
|
|
|
|
, configPath + _T("atlas.ini")
|
|
|
|
|
#endif
|
|
|
|
|
));
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2010-03-29 03:24:17 -07:00
|
|
|
if (! g_HasSetDataDirectory)
|
|
|
|
|
{
|
|
|
|
|
// Assume that the .exe is located in .../binaries/system. (We can't
|
|
|
|
|
// just use the cwd, since that isn't correct when being executed by
|
|
|
|
|
// dragging-and-dropping onto the program in Explorer.)
|
|
|
|
|
Datafile::SetSystemDirectory(argv[0]);
|
|
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
// Display the appropriate window
|
|
|
|
|
wxFrame* frame;
|
2012-01-14 11:12:18 -08:00
|
|
|
if (g_InitialWindowType == _T("ActorEditor"))
|
|
|
|
|
{
|
|
|
|
|
frame = new ActorEditor(NULL);
|
|
|
|
|
}
|
|
|
|
|
else if (g_InitialWindowType == _T("ScenarioEditor"))
|
2007-06-08 15:56:01 -07:00
|
|
|
{
|
2014-02-24 12:22:02 -08:00
|
|
|
frame = new ScenarioEditor(NULL);
|
2007-06-08 15:56:01 -07:00
|
|
|
}
|
|
|
|
|
else
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
wxFAIL_MSG(_("Internal error: invalid window type"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frame->Show();
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
|
|
|
|
|
AtlasWindow* win = wxDynamicCast(frame, AtlasWindow);
|
|
|
|
|
if (win)
|
|
|
|
|
{
|
|
|
|
|
// One argument => argv[1] is probably a filename to open
|
|
|
|
|
if (argc > 1)
|
|
|
|
|
{
|
2011-08-18 16:38:11 -07:00
|
|
|
wxString filename = argv[1];
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
if (filename[0] != _T('-')) // ignore -options
|
|
|
|
|
{
|
|
|
|
|
if (wxFile::Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
win->OpenFile(filename);
|
|
|
|
|
}
|
|
|
|
|
else
|
2011-08-18 16:38:11 -07:00
|
|
|
wxLogError(_("Cannot find file '%s'"), filename.c_str());
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 07:12:37 -07:00
|
|
|
#if wxUSE_DEBUGREPORT && USE_WX_FATAL_EXCEPTION_REPORT
|
2006-12-01 12:34:28 -08:00
|
|
|
virtual void OnFatalException()
|
|
|
|
|
{
|
2012-04-21 07:12:37 -07:00
|
|
|
// NOTE: At least on Linux, this might be called from a thread other
|
|
|
|
|
// than the UI thread, so it's not safe to use any wx objects here
|
|
|
|
|
|
2006-12-01 12:34:28 -08:00
|
|
|
wxDebugReport report;
|
|
|
|
|
wxDebugReportPreviewStd preview;
|
|
|
|
|
|
|
|
|
|
report.AddAll();
|
|
|
|
|
|
|
|
|
|
if (preview.Show(report))
|
|
|
|
|
{
|
|
|
|
|
wxString dir = report.GetDirectory(); // save the string, since it gets cleared by Process
|
|
|
|
|
report.Process();
|
|
|
|
|
OpenDirectory(dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-07 16:09:36 -07:00
|
|
|
#endif // wxUSE_DEBUGREPORT
|
2006-12-01 12:34:28 -08:00
|
|
|
|
|
|
|
|
/* Disabled (and should be removed if it turns out to be unnecessary)
|
|
|
|
|
- see MessagePasserImpl.cpp for information
|
|
|
|
|
virtual int MainLoop()
|
|
|
|
|
{
|
|
|
|
|
// Override the default MainLoop so that we can provide our own event loop
|
|
|
|
|
|
|
|
|
|
wxEventLoop* old = m_mainLoop;
|
|
|
|
|
m_mainLoop = new AtlasEventLoop;
|
|
|
|
|
|
|
|
|
|
int ret = m_mainLoop->Run();
|
|
|
|
|
|
|
|
|
|
delete m_mainLoop;
|
|
|
|
|
m_mainLoop = old;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private:
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
bool OpenDirectory(const wxString& dir)
|
|
|
|
|
{
|
2006-12-01 12:34:28 -08:00
|
|
|
// Open a directory on the filesystem - used so people can find the
|
|
|
|
|
// debug report files generated in OnFatalException easily
|
|
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
2006-04-23 16:14:18 -07:00
|
|
|
// Code largely copied from wxLaunchDefaultBrowser:
|
|
|
|
|
|
|
|
|
|
typedef HINSTANCE (WINAPI *LPShellExecute)(HWND hwnd, const wxChar* lpOperation,
|
|
|
|
|
const wxChar* lpFile,
|
|
|
|
|
const wxChar* lpParameters,
|
|
|
|
|
const wxChar* lpDirectory,
|
|
|
|
|
INT nShowCmd);
|
|
|
|
|
|
|
|
|
|
HINSTANCE hShellDll = ::LoadLibrary(_T("shell32.dll"));
|
|
|
|
|
if (hShellDll == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
LPShellExecute lpShellExecute =
|
|
|
|
|
(LPShellExecute) ::GetProcAddress(hShellDll,
|
|
|
|
|
wxString(_T("ShellExecute")
|
2006-12-01 12:34:28 -08:00
|
|
|
# ifdef _UNICODE
|
|
|
|
|
_T("W")
|
|
|
|
|
# else
|
|
|
|
|
_T("A")
|
|
|
|
|
# endif
|
2006-04-23 16:14:18 -07:00
|
|
|
).mb_str(wxConvLocal));
|
|
|
|
|
|
|
|
|
|
if (lpShellExecute == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/*HINSTANCE nResult =*/ (*lpShellExecute)(NULL, _T("explore"), dir.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
2006-12-01 12:34:28 -08:00
|
|
|
// ignore return value, since we're not going to do anything if this fails
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
::FreeLibrary(hShellDll);
|
|
|
|
|
|
|
|
|
|
return true;
|
2006-11-11 20:02:36 -08:00
|
|
|
#else
|
|
|
|
|
// Figure out what goes for "default browser" on unix/linux/whatever
|
|
|
|
|
// open an xterm perhaps? :)
|
2009-03-22 13:51:35 -07:00
|
|
|
(void)dir;
|
2006-11-11 20:02:36 -08:00
|
|
|
return false;
|
|
|
|
|
#endif
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2011-08-18 16:38:11 -07:00
|
|
|
IMPLEMENT_APP_NO_MAIN(AtlasDLLApp);
|