aboutsummaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-03-30 18:32:52 +0200
committerGitHub <noreply@github.com>2018-03-30 18:32:52 +0200
commitce873108aa91d19104f46c5acd3350385e7a4541 (patch)
tree58672a3c803469de71c9ae270beb9a052ba5559a /src/game.cpp
parent2c490dddc037d7d1cf211bbf28309e31b0abdadd (diff)
downloadminetest-ce873108aa91d19104f46c5acd3350385e7a4541.tar.gz
minetest-ce873108aa91d19104f46c5acd3350385e7a4541.tar.bz2
minetest-ce873108aa91d19104f46c5acd3350385e7a4541.zip
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
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp31
1 files changed, 15 insertions, 16 deletions
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) {