Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include "precompiled.h" 19 : 20 : #include "Atlas.h" 21 : 22 : #include "lib/debug.h" 23 : #include "ps/CLogger.h" 24 : #include "ps/CStr.h" 25 : #include "ps/DllLoader.h" 26 : #include "ps/GameSetup/CmdLineArgs.h" 27 : 28 : //---------------------------------------------------------------------------- 29 : // Atlas (map editor) integration 30 : //---------------------------------------------------------------------------- 31 : 32 : DllLoader atlas_dll("AtlasUI", CLogger::Normal); 33 : 34 : enum AtlasRunFlags 35 : { 36 : // used by ATLAS_RunIfOnCmdLine; makes any error output go through 37 : // DEBUG_DISPLAY_ERROR rather than a GUI dialog box (because GUI init was 38 : // skipped to reduce load time). 39 : ATLAS_NO_GUI = 1 40 : }; 41 : 42 : // starts the Atlas UI. 43 0 : static void ATLAS_Run(const CmdLineArgs& args, int flags = 0) 44 : { 45 : // first check if we can run at all 46 0 : if(!atlas_dll.LoadDLL()) 47 : { 48 0 : if(flags & ATLAS_NO_GUI) 49 0 : DEBUG_DISPLAY_ERROR(L"The Atlas UI was not successfully loaded and therefore cannot be started as requested."); 50 : else 51 0 : DEBUG_DISPLAY_ERROR(L"The Atlas UI was not successfully loaded and therefore cannot be started as requested.");// TODO: implement GUI error message 52 0 : return; 53 : } 54 : 55 : // TODO (make nicer) 56 0 : extern bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll); 57 0 : if (!BeginAtlas(args, atlas_dll)) 58 : { 59 0 : debug_warn(L"Atlas loading failed"); 60 0 : return; 61 : } 62 : } 63 : 64 0 : bool ATLAS_IsAvailable() 65 : { 66 0 : return atlas_dll.LoadDLL(); 67 : } 68 : 69 : // starts the Atlas UI if an "-editor" switch is found on the command line. 70 : // this is the alternative to starting the main menu and clicking on 71 : // the editor button; it is much faster because it's called during early 72 : // init and therefore skips GUI setup. 73 : // notes: 74 : // - GUI init still runs, but some GUI setup will be skipped since 75 : // ATLAS_IsRunning() will return true. 76 0 : bool ATLAS_RunIfOnCmdLine(const CmdLineArgs& args, bool force) 77 : { 78 0 : if (force || args.Has("editor")) 79 : { 80 0 : if (args.Has("dumpSchema")) 81 : { 82 0 : LOGERROR("-dumpSchema and -editor arguments are incompatible: Atlas will not be started."); 83 0 : return false; 84 : } 85 : 86 0 : ATLAS_Run(args, ATLAS_NO_GUI); 87 0 : return true; 88 : } 89 : 90 : return false; 91 : }