1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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
This commit is contained in:
Loïc Blot 2018-03-30 18:32:52 +02:00 committed by GitHub
parent 2c490dddc0
commit ce873108aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 249 additions and 185 deletions

View file

@ -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) {