LCOV - code coverage report
Current view: top level - source/tools/atlas/GameInterface - GameLoop.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 2 39 5.1 %
Date: 2023-01-19 00:18:29 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 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 "GameLoop.h"
      21             : 
      22             : #include "MessagePasserImpl.h"
      23             : #include "Messages.h"
      24             : #include "SharedMemory.h"
      25             : #include "Handlers/MessageHandler.h"
      26             : #include "ActorViewer.h"
      27             : #include "View.h"
      28             : 
      29             : #include "InputProcessor.h"
      30             : 
      31             : #include "graphics/TextureManager.h"
      32             : #include "lib/app_hooks.h"
      33             : #include "lib/external_libraries/libsdl.h"
      34             : #include "lib/timer.h"
      35             : #include "ps/CLogger.h"
      36             : #include "ps/DllLoader.h"
      37             : #include "ps/Filesystem.h"
      38             : #include "ps/Profile.h"
      39             : #include "ps/ThreadUtil.h"
      40             : #include "ps/GameSetup/Paths.h"
      41             : #include "renderer/Renderer.h"
      42             : 
      43             : using namespace AtlasMessage;
      44             : 
      45             : #include <thread>
      46             : 
      47             : 
      48             : namespace AtlasMessage
      49             : {
      50             :     extern void RegisterHandlers();
      51             : }
      52             : 
      53             : // Loaded from DLL:
      54             : void (*Atlas_StartWindow)(const wchar_t* type);
      55             : void (*Atlas_SetDataDirectory)(const wchar_t* path);
      56             : void (*Atlas_SetConfigDirectory)(const wchar_t* path);
      57             : void (*Atlas_SetMessagePasser)(MessagePasser*);
      58             : void (*Atlas_GLSetCurrent)(void* cavas);
      59             : void (*Atlas_GLSwapBuffers)(void* canvas);
      60             : void (*Atlas_DisplayError)(const wchar_t* text, size_t flags);
      61             : namespace AtlasMessage
      62             : {
      63             :     void* (*ShareableMallocFptr)(size_t);
      64             :     void (*ShareableFreeFptr)(void*);
      65             : }
      66             : 
      67             : 
      68             : MessagePasser* AtlasMessage::g_MessagePasser = NULL;
      69             : 
      70             : 
      71           1 : static GameLoopState state;
      72             : GameLoopState* g_AtlasGameLoop = &state;
      73             : 
      74           0 : void RendererIncrementalLoad()
      75             : {
      76             :     // TODO: shouldn't duplicate this code from main.cpp
      77             : 
      78           0 :     if (!CRenderer::IsInitialised())
      79           0 :         return;
      80             : 
      81           0 :     const double maxTime = 0.1f;
      82             : 
      83           0 :     double startTime = timer_Time();
      84             :     bool more;
      85           0 :     do {
      86           0 :         more = g_Renderer.GetTextureManager().MakeProgress();
      87             :     }
      88           0 :     while (more && timer_Time() - startTime < maxTime);
      89             : }
      90             : 
      91           0 : bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
      92             : {
      93             :     // Load required symbols from the DLL
      94             :     try
      95             :     {
      96           0 :         dll.LoadSymbol("Atlas_StartWindow", Atlas_StartWindow);
      97           0 :         dll.LoadSymbol("Atlas_SetMessagePasser", Atlas_SetMessagePasser);
      98           0 :         dll.LoadSymbol("Atlas_SetDataDirectory", Atlas_SetDataDirectory);
      99           0 :         dll.LoadSymbol("Atlas_SetConfigDirectory", Atlas_SetConfigDirectory);
     100           0 :         dll.LoadSymbol("Atlas_GLSetCurrent", Atlas_GLSetCurrent);
     101           0 :         dll.LoadSymbol("Atlas_GLSwapBuffers", Atlas_GLSwapBuffers);
     102           0 :         dll.LoadSymbol("Atlas_DisplayError", Atlas_DisplayError);
     103           0 :         dll.LoadSymbol("ShareableMalloc", ShareableMallocFptr);
     104           0 :         dll.LoadSymbol("ShareableFree", ShareableFreeFptr);
     105             :     }
     106           0 :     catch (PSERROR_DllLoader&)
     107             :     {
     108           0 :         debug_warn(L"Failed to initialise DLL");
     109           0 :         return false;
     110             :     }
     111             : 
     112             :     // Construct a message passer for communicating with Atlas
     113             :     // (here so that its scope lasts beyond the game thread)
     114           0 :     MessagePasserImpl msgPasser;
     115           0 :     AtlasMessage::g_MessagePasser = &msgPasser;
     116             : 
     117             :     // Pass our message handler to Atlas
     118           0 :     Atlas_SetMessagePasser(&msgPasser);
     119             : 
     120             :     // Tell Atlas the location of the data directory
     121           0 :     const Paths paths(args);
     122           0 :     Atlas_SetDataDirectory(paths.RData().string().c_str());
     123             : 
     124             :     // Tell Atlas the location of the user config directory
     125           0 :     Atlas_SetConfigDirectory(paths.Config().string().c_str());
     126             : 
     127           0 :     RegisterHandlers();
     128             : 
     129           0 :     state.args = args;
     130           0 :     state.running = true;
     131           0 :     state.view = AtlasView::GetView_None();
     132           0 :     state.glCanvas = NULL;
     133             : 
     134             :     // Start Atlas UI on main thread
     135             :     // (required for wxOSX/Cocoa compatibility - see http://trac.wildfiregames.com/ticket/500)
     136           0 :     Atlas_StartWindow(L"ScenarioEditor");
     137             : 
     138             :     // TODO: delete all remaining messages, to avoid memory leak warnings
     139             : 
     140             :     // Restore main thread
     141           0 :     Threading::SetMainThread();
     142             : 
     143             :     // Clean up
     144           0 :     AtlasView::DestroyViews();
     145           0 :     AtlasMessage::g_MessagePasser = NULL;
     146             : 
     147           0 :     return true;
     148           3 : }

Generated by: LCOV version 1.13