Better boat handling

This commit is contained in:
2025-11-30 18:28:26 +03:00
parent cd82fb0eed
commit 5b014dcb65
21 changed files with 938 additions and 230 deletions

View File

@@ -4,6 +4,7 @@
#include "CharacterModule.h"
#include "PhysicsModule.h"
#include "CharacterAnimationModule.h"
#include "EventModule.h"
#include "world-build.h"
namespace ECS
{
@@ -11,12 +12,14 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
{
ecs.module<CharacterAnimationModule>();
ecs.component<AnimationControl>();
ecs.import <EventModule>();
ecs.system<const CharacterBase, AnimationControl>("HandleAnimations")
.kind(flecs::OnUpdate)
.each([this](flecs::entity e, const CharacterBase &ch,
AnimationControl &anim) {
if (!anim.configured && ch.mSkeleton) {
int i, j;
e.set<EventData>({});
ch.mSkeleton->setBlendMode(
Ogre::ANIMBLEND_CUMULATIVE);
Ogre::String animNames[] = {
@@ -504,26 +507,29 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
if (Ogre::Math::Abs(input.motion.z -
act.prevMotion.z) >
0.001f) {
if (input.motion.z < 0)
ECS::get<LuaBase>()
.mLua
->call_handler(
"actuator_forward",
trig,
e);
if (input.motion.z > 0)
ECS::get_mut<LuaBase>()
.mLua
->call_handler(
"actuator_backward",
trig,
e);
if (input.motion.z < 0) {
trig.get_mut<EventData>()
.add(e,
"actuator_forward",
trig, e);
trig.modified<
EventData>();
}
if (input.motion.z > 0) {
trig.get_mut<EventData>()
.add(e,
"actuator_backward",
trig, e);
trig.modified<
EventData>();
}
}
if (input.act_pressed) {
trig.get_mut<EventData>().add(
e, "actuator_action",
trig, e);
trig.modified<EventData>();
}
if (input.act_pressed)
ECS::get_mut<LuaBase>()
.mLua->call_handler(
"actuator_action",
trig, e);
// ECS::get_mut<LuaData>().call_handler(
// "actuator_update", trig, e);
trigger_event = true;
@@ -532,26 +538,25 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
if (Ogre::Math::Abs(input.motion.z -
act.prevMotion.z) >
0.001f) {
if (input.motion.z < 0)
ECS::get<LuaBase>()
.mLua
->call_handler(
"_in_actuator_forward",
e, e);
if (input.motion.z > 0)
ECS::get_mut<LuaBase>()
.mLua
->call_handler(
"_in_actuator_backward",
e, e);
}
if (input.act_pressed)
ECS::get_mut<LuaBase>()
.mLua->call_handler(
"_in_actuator_action",
if (input.motion.z < 0) {
e.get_mut<EventData>().add(
e,
"_in_actuator_forward",
e, e);
// ECS::get_mut<LuaData>().call_handler(
// "actuator_update", trig, e);
}
if (input.motion.z > 0) {
e.get_mut<EventData>().add(
e,
"_in_actuator_backward",
e, e);
}
}
if (input.act_pressed) {
e.get_mut<EventData>().add(
e,
"_in_actuator_action",
e, e);
}
}
act.prevMotion.x = input.motion.x;
act.prevMotion.y = input.motion.y;
@@ -569,6 +574,25 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
#endif
act.prevMotion = input.motion;
});
ecs.system<EventData>("UpdateEvents")
.kind(flecs::OnUpdate)
.with<Character>()
.each([](flecs::entity e, EventData &evt) {
for (auto ev : evt.events) {
std::cout << "character event: " << ev.event
<< std::endl;
/* parse character events */
e.each<InTrigger>([&](flecs::entity trig) {
/* if triggered, dispatch events to trigger */
trig.get_mut<EventData>().add(
ev.sender, ev.event,
trig, // it is easier this way to identify trigger entity
ev.e2);
});
}
evt.events.clear();
});
#ifdef VDEBUG
ecs.system<const CharacterBase>("CharacterGravityStatus")
.kind(flecs::OnUpdate)