LCOV - code coverage report
Current view: top level - source/tools/atlas/GameInterface/Handlers - MiscHandlers.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 73 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 28 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2022 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 "MessageHandler.h"
      21             : #include "../MessagePasserImpl.h"
      22             : 
      23             : #include "../GameLoop.h"
      24             : #include "../View.h"
      25             : #include "graphics/GameView.h"
      26             : #include "gui/GUIManager.h"
      27             : #include "gui/CGUI.h"
      28             : #include "lib/external_libraries/libsdl.h"
      29             : #include "maths/MathUtil.h"
      30             : #include "ps/Game.h"
      31             : #include "ps/GameSetup/Config.h"
      32             : #include "ps/GameSetup/GameSetup.h"
      33             : #include "renderer/Renderer.h"
      34             : #include "scriptinterface/ScriptInterface.h"
      35             : #include "simulation2/Simulation2.h"
      36             : #include "simulation2/components/ICmpSoundManager.h"
      37             : 
      38             : extern void (*Atlas_GLSwapBuffers)(void* context);
      39             : 
      40             : namespace AtlasMessage
      41             : {
      42             : 
      43           0 : MESSAGEHANDLER(MessageTrace)
      44             : {
      45           0 :     ((MessagePasserImpl*)g_MessagePasser)->SetTrace(msg->enable);
      46           0 : }
      47             : 
      48           0 : MESSAGEHANDLER(Screenshot)
      49             : {
      50           0 :     if (msg->big)
      51           0 :         g_Renderer.MakeScreenShotOnNextFrame(CRenderer::ScreenShotType::BIG);
      52             :     else
      53           0 :         g_Renderer.MakeScreenShotOnNextFrame(CRenderer::ScreenShotType::DEFAULT);
      54           0 : }
      55             : 
      56           0 : QUERYHANDLER(Ping)
      57             : {
      58             :     UNUSED2(msg);
      59           0 : }
      60             : 
      61           0 : MESSAGEHANDLER(SimStopMusic)
      62             : {
      63             :     UNUSED2(msg);
      64             : 
      65           0 :     CmpPtr<ICmpSoundManager> cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
      66           0 :     if (cmpSoundManager)
      67           0 :         cmpSoundManager->StopMusic();
      68           0 : }
      69             : 
      70           0 : MESSAGEHANDLER(SimStateSave)
      71             : {
      72           0 :     AtlasView::GetView_Game()->SaveState(*msg->label);
      73           0 : }
      74             : 
      75           0 : MESSAGEHANDLER(SimStateRestore)
      76             : {
      77           0 :     AtlasView::GetView_Game()->RestoreState(*msg->label);
      78           0 : }
      79             : 
      80           0 : QUERYHANDLER(SimStateDebugDump)
      81             : {
      82           0 :     msg->dump = AtlasView::GetView_Game()->DumpState(msg->binary);
      83           0 : }
      84             : 
      85           0 : MESSAGEHANDLER(SimPlay)
      86             : {
      87           0 :     AtlasView::GetView_Game()->SetSpeedMultiplier(msg->speed);
      88           0 :     AtlasView::GetView_Game()->SetTesting(msg->simTest);
      89           0 : }
      90             : 
      91           0 : MESSAGEHANDLER(JavaScript)
      92             : {
      93           0 :     g_GUI->GetActiveGUI()->GetScriptInterface()->LoadGlobalScript(L"Atlas", *msg->command);
      94           0 : }
      95             : 
      96           0 : MESSAGEHANDLER(GuiSwitchPage)
      97             : {
      98           0 :     g_GUI->SwitchPage(*msg->page, NULL, JS::UndefinedHandleValue);
      99           0 : }
     100             : 
     101           0 : MESSAGEHANDLER(GuiMouseButtonEvent)
     102             : {
     103           0 :     SDL_Event_ ev = { { 0 } };
     104           0 :     ev.ev.type = msg->pressed ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
     105           0 :     ev.ev.button.button = msg->button;
     106           0 :     ev.ev.button.state = msg->pressed ? SDL_PRESSED : SDL_RELEASED;
     107           0 :     ev.ev.button.clicks = msg->clicks;
     108             :     float x, y;
     109           0 :     msg->pos->GetScreenSpace(x, y);
     110           0 :     ev.ev.button.x = static_cast<u16>(Clamp<int>(x, 0, g_xres));
     111           0 :     ev.ev.button.y = static_cast<u16>(Clamp<int>(y, 0, g_yres));
     112           0 :     in_dispatch_event(&ev);
     113           0 : }
     114             : 
     115           0 : MESSAGEHANDLER(GuiMouseMotionEvent)
     116             : {
     117           0 :     SDL_Event_ ev = { { 0 } };
     118           0 :     ev.ev.type = SDL_MOUSEMOTION;
     119             :     float x, y;
     120           0 :     msg->pos->GetScreenSpace(x, y);
     121           0 :     ev.ev.motion.x = static_cast<u16>(Clamp<int>(x, 0, g_xres));
     122           0 :     ev.ev.motion.y = static_cast<u16>(Clamp<int>(y, 0, g_yres));
     123           0 :     in_dispatch_event(&ev);
     124           0 : }
     125             : 
     126           0 : MESSAGEHANDLER(GuiKeyEvent)
     127             : {
     128           0 :     SDL_Event_ ev = { { 0 } };
     129           0 :     ev.ev.type = msg->pressed ? SDL_KEYDOWN : SDL_KEYUP;
     130           0 :     ev.ev.key.keysym.sym = (SDL_Keycode)(int)msg->sdlkey;
     131           0 :     ev.ev.key.keysym.scancode = SDL_GetScancodeFromKey((SDL_Keycode)(int)msg->sdlkey);
     132           0 :     in_dispatch_event(&ev);
     133           0 : }
     134             : 
     135           0 : MESSAGEHANDLER(GuiCharEvent)
     136             : {
     137             :     // Simulate special 'text input' events in the SDL
     138             :     // This isn't quite compatible with WXWidget's handling,
     139             :     // so to avoid trouble we only send 'letter-like' ASCII input.
     140           0 :     SDL_Event_ ev = { { 0 } };
     141           0 :     ev.ev.type = SDL_TEXTEDITING;
     142           0 :     ev.ev.text.type = SDL_TEXTEDITING;
     143           0 :     ev.ev.text.text[0] = (char)msg->sdlkey;
     144           0 :     ev.ev.text.text[1] = (char)0;
     145           0 :     in_dispatch_event(&ev);
     146             : 
     147           0 :     ev.ev.type = SDL_TEXTINPUT;
     148           0 :     ev.ev.text.type = SDL_TEXTINPUT;
     149           0 :     ev.ev.text.text[0] = (char)msg->sdlkey;
     150           0 :     ev.ev.text.text[1] = (char)0;
     151           0 :     in_dispatch_event(&ev);
     152           0 : }
     153             : 
     154             : } // namespace AtlasMessage

Generated by: LCOV version 1.13