From ce873108aa91d19104f46c5acd3350385e7a4541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Fri, 30 Mar 2018 18:32:52 +0200 Subject: Client eventmanager refactor (#7179) * Drop EventManager from GameDef & do some client cleanups * EventManager is only used by Client. Don't expose it on Server & GameDef for nothing * Drop Client::event() in favor of direct calls to getEventManager * Cleanup some event put from new + put to put(new) * MtEvent: add Type(u8) enum * This will enhance event performance & ensure stricter type * Drop MtEvent::checkIs (unused) * clang-tidy reported fixes * Code style * Move event_manager.h to the client directory as it's only used by client Add EventManager unittests + switch to unordered_map as order is not important here Drop a unused function --- src/game.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 3103d1f2d..9a7f4e6d7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "clouds.h" #include "config.h" #include "content_cao.h" -#include "event_manager.h" +#include "client/event_manager.h" #include "fontengine.h" #include "itemdef.h" #include "log.h" @@ -246,9 +246,9 @@ public: p(p), n(n) {} - const char *getType() const + MtEvent::Type getType() const { - return "NodeDug"; + return MtEvent::NODE_DUG; } }; @@ -331,14 +331,14 @@ public: void registerReceiver(MtEventManager *mgr) { - mgr->reg("ViewBobbingStep", SoundMaker::viewBobbingStep, this); - mgr->reg("PlayerRegainGround", SoundMaker::playerRegainGround, this); - mgr->reg("PlayerJump", SoundMaker::playerJump, this); - mgr->reg("CameraPunchLeft", SoundMaker::cameraPunchLeft, this); - mgr->reg("CameraPunchRight", SoundMaker::cameraPunchRight, this); - mgr->reg("NodeDug", SoundMaker::nodeDug, this); - mgr->reg("PlayerDamage", SoundMaker::playerDamage, this); - mgr->reg("PlayerFallingDamage", SoundMaker::playerFallingDamage, this); + mgr->reg(MtEvent::VIEW_BOBBING_STEP, SoundMaker::viewBobbingStep, this); + mgr->reg(MtEvent::PLAYER_REGAIN_GROUND, SoundMaker::playerRegainGround, this); + mgr->reg(MtEvent::PLAYER_JUMP, SoundMaker::playerJump, this); + mgr->reg(MtEvent::CAMERA_PUNCH_LEFT, SoundMaker::cameraPunchLeft, this); + mgr->reg(MtEvent::CAMERA_PUNCH_RIGHT, SoundMaker::cameraPunchRight, this); + mgr->reg(MtEvent::NODE_DUG, SoundMaker::nodeDug, this); + mgr->reg(MtEvent::PLAYER_DAMAGE, SoundMaker::playerDamage, this); + mgr->reg(MtEvent::PLAYER_FALLING_DAMAGE, SoundMaker::playerFallingDamage, this); } void step(float dtime) @@ -2491,15 +2491,15 @@ void Game::handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation } runData.damage_flash += 95.0 + 3.2 * event->player_damage.amount; - runData.damage_flash = MYMIN(runData.damage_flash, 127.0); + runData.damage_flash = MYMIN(runData.damage_flash, 127.0f); LocalPlayer *player = client->getEnv().getLocalPlayer(); player->hurt_tilt_timer = 1.5; player->hurt_tilt_strength = - rangelim(event->player_damage.amount / 4, 1.0, 4.0); + rangelim(event->player_damage.amount / 4, 1.0f, 4.0f); - client->event()->put(new SimpleTriggerEvent("PlayerDamage")); + client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::PLAYER_DAMAGE)); } void Game::handleClientEvent_PlayerForceMove(ClientEvent *event, CameraOrientation *cam) @@ -3586,8 +3586,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, // Send event to trigger sound - MtEvent *e = new NodeDugEvent(nodepos, wasnode); - client->event()->put(e); + client->getEventManager()->put(new NodeDugEvent(nodepos, wasnode)); } if (runData.dig_time_complete < 100000.0) { -- cgit v1.2.3