mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
iwyu 0.26 now want's full declaration of TYPE in case of std::vector<TYPE>, which is good as it allows the header to be self standing. There are some other changes suggested in part of the headers not being updated when they should have been and some due to changes in iwyu itself. Ref: #8086 Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
163 lines
4.4 KiB
C++
163 lines
4.4 KiB
C++
/* Copyright (C) 2026 Wildfire Games.
|
|
* This file is part of 0 A.D.
|
|
*
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
* 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.
|
|
*
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
* 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
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "precompiled.h"
|
|
|
|
#include "MessageHandler.h"
|
|
#include "gui/CGUI.h"
|
|
#include "gui/GUIManager.h"
|
|
#include "lib/input.h"
|
|
#include "lib/path.h"
|
|
#include "lib/types.h"
|
|
#include "maths/MathUtil.h"
|
|
#include "ps/Game.h"
|
|
#include "ps/GameSetup/Config.h"
|
|
#include "renderer/Renderer.h"
|
|
#include "scriptinterface/ScriptInterface.h"
|
|
#include "simulation2/components/ICmpSoundManager.h"
|
|
#include "simulation2/system/Component.h"
|
|
#include "simulation2/system/Entity.h"
|
|
#include "tools/atlas/GameInterface/MessagePasser.h"
|
|
#include "tools/atlas/GameInterface/MessagePasserImpl.h"
|
|
#include "tools/atlas/GameInterface/Messages.h"
|
|
#include "tools/atlas/GameInterface/Shareable.h"
|
|
#include "tools/atlas/GameInterface/SharedTypes.h"
|
|
#include "tools/atlas/GameInterface/View.h"
|
|
|
|
#include <SDL_events.h>
|
|
#include <SDL_keyboard.h>
|
|
#include <SDL_keycode.h>
|
|
#include <cstddef>
|
|
#include <js/CallArgs.h>
|
|
#include <js/RootingAPI.h>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
extern void (*Atlas_GLSwapBuffers)(void* context);
|
|
|
|
namespace AtlasMessage
|
|
{
|
|
|
|
MESSAGEHANDLER(MessageTrace)
|
|
{
|
|
((MessagePasserImpl*)g_MessagePasser)->SetTrace(msg->enable);
|
|
}
|
|
|
|
MESSAGEHANDLER(Screenshot)
|
|
{
|
|
if (msg->big)
|
|
g_Renderer.MakeScreenShotOnNextFrame(CRenderer::ScreenShotType::BIG);
|
|
else
|
|
g_Renderer.MakeScreenShotOnNextFrame(CRenderer::ScreenShotType::DEFAULT);
|
|
}
|
|
|
|
QUERYHANDLER(Ping)
|
|
{
|
|
}
|
|
|
|
MESSAGEHANDLER(SimStopMusic)
|
|
{
|
|
CmpPtr<ICmpSoundManager> cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
|
if (cmpSoundManager)
|
|
cmpSoundManager->StopMusic();
|
|
}
|
|
|
|
MESSAGEHANDLER(SimStateSave)
|
|
{
|
|
AtlasView::GetView_Game()->SaveState(*msg->label);
|
|
}
|
|
|
|
MESSAGEHANDLER(SimStateRestore)
|
|
{
|
|
AtlasView::GetView_Game()->RestoreState(*msg->label);
|
|
}
|
|
|
|
QUERYHANDLER(SimStateDebugDump)
|
|
{
|
|
msg->dump = AtlasView::GetView_Game()->DumpState(msg->binary);
|
|
}
|
|
|
|
MESSAGEHANDLER(SimPlay)
|
|
{
|
|
AtlasView::GetView_Game()->SetSpeedMultiplier(msg->speed);
|
|
AtlasView::GetView_Game()->SetTesting(msg->simTest);
|
|
}
|
|
|
|
MESSAGEHANDLER(JavaScript)
|
|
{
|
|
g_GUI->GetActiveGUI()->GetScriptInterface()->LoadGlobalScript(L"Atlas", *msg->command);
|
|
}
|
|
|
|
MESSAGEHANDLER(GuiSwitchPage)
|
|
{
|
|
g_GUI->SwitchPage(*msg->page, NULL, JS::UndefinedHandleValue);
|
|
}
|
|
|
|
MESSAGEHANDLER(GuiMouseButtonEvent)
|
|
{
|
|
SDL_Event ev{};
|
|
ev.type = msg->pressed ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
|
|
ev.button.button = msg->button;
|
|
ev.button.state = msg->pressed ? SDL_PRESSED : SDL_RELEASED;
|
|
ev.button.clicks = msg->clicks;
|
|
float x, y;
|
|
msg->pos->GetScreenSpace(x, y);
|
|
ev.button.x = static_cast<u16>(Clamp<int>(x, 0, g_xres));
|
|
ev.button.y = static_cast<u16>(Clamp<int>(y, 0, g_yres));
|
|
in_dispatch_event(ev);
|
|
}
|
|
|
|
MESSAGEHANDLER(GuiMouseMotionEvent)
|
|
{
|
|
SDL_Event ev{};
|
|
ev.type = SDL_MOUSEMOTION;
|
|
float x, y;
|
|
msg->pos->GetScreenSpace(x, y);
|
|
ev.motion.x = static_cast<u16>(Clamp<int>(x, 0, g_xres));
|
|
ev.motion.y = static_cast<u16>(Clamp<int>(y, 0, g_yres));
|
|
in_dispatch_event(ev);
|
|
}
|
|
|
|
MESSAGEHANDLER(GuiKeyEvent)
|
|
{
|
|
SDL_Event ev{};
|
|
ev.type = msg->pressed ? SDL_KEYDOWN : SDL_KEYUP;
|
|
ev.key.keysym.sym = static_cast<SDL_Keycode>(static_cast<int>(msg->sdlkey));
|
|
ev.key.keysym.scancode = SDL_GetScancodeFromKey(static_cast<SDL_Keycode>(static_cast<int>(msg->sdlkey)));
|
|
in_dispatch_event(ev);
|
|
}
|
|
|
|
MESSAGEHANDLER(GuiCharEvent)
|
|
{
|
|
// Simulate special 'text input' events in the SDL
|
|
// This isn't quite compatible with WXWidget's handling,
|
|
// so to avoid trouble we only send 'letter-like' ASCII input.
|
|
SDL_Event ev{};
|
|
ev.type = SDL_TEXTEDITING;
|
|
ev.text.type = SDL_TEXTEDITING;
|
|
ev.text.text[0] = static_cast<char>(msg->sdlkey);
|
|
ev.text.text[1] = '\0';
|
|
in_dispatch_event(ev);
|
|
|
|
ev.type = SDL_TEXTINPUT;
|
|
ev.text.type = SDL_TEXTINPUT;
|
|
ev.text.text[0] = static_cast<char>(msg->sdlkey);
|
|
ev.text.text[1] = '\0';
|
|
in_dispatch_event(ev);
|
|
}
|
|
|
|
} // namespace AtlasMessage
|