Support proper actuator animation

This commit is contained in:
2025-09-27 01:23:16 +03:00
parent 7e06da700a
commit 25280a9cbe
16 changed files with 528 additions and 103 deletions

View File

@@ -63,7 +63,8 @@ int LuaData::call_handler(const Ogre::String &event)
lua_rawgeti(L, LUA_REGISTRYINDEX, setup_handlers[i]);
lua_pushstring(L, event.c_str());
lua_pushinteger(L, -1);
if (lua_pcall(L, 2, 0, 0)) {
lua_pushinteger(L, -1);
if (lua_pcall(L, 3, 0, 0)) {
Ogre::LogManager::getSingleton().stream()
<< lua_tostring(L, -1);
OgreAssert(false, "Lua error");
@@ -72,14 +73,16 @@ int LuaData::call_handler(const Ogre::String &event)
return 0;
}
int LuaData::call_handler(const Ogre::String &event, flecs::entity e)
int LuaData::call_handler(const Ogre::String &event, flecs::entity e,
flecs::entity o)
{
int i;
for (i = 0; i < setup_handlers.size(); i++) {
lua_rawgeti(L, LUA_REGISTRYINDEX, setup_handlers[i]);
lua_pushstring(L, event.c_str());
lua_pushinteger(L, idmap.add_entity(e));
if (lua_pcall(L, 2, 0, 0)) {
lua_pushinteger(L, idmap.add_entity(o));
if (lua_pcall(L, 3, 0, 0)) {
Ogre::LogManager::getSingleton().stream()
<< lua_tostring(L, -1);
OgreAssert(false, "Lua error");
@@ -373,6 +376,31 @@ LuaData::LuaData()
return 1;
});
lua_setglobal(L, "ecs_child_character_trigger");
lua_pushcfunction(L, [](lua_State *L) -> int {
luaL_checktype(L, 1, LUA_TNUMBER); // trigger
luaL_checktype(L, 2, LUA_TNUMBER); // object
int trigger = lua_tointeger(L, 1);
int object = lua_tointeger(L, 2);
flecs::entity trigger_e = idmap.get_entity(trigger);
flecs::entity object_e = idmap.get_entity(object);
Ogre::SceneNode *target_node = nullptr;
Ogre::Any targetAny = trigger_e.get<EventTrigger>()
.node->getUserObjectBindings()
.getUserAny("target");
OgreAssert(targetAny.has_value(), "need target");
target_node = Ogre::any_cast<Ogre::SceneNode *>(targetAny);
Ogre::Vector3 position = target_node->_getDerivedPosition();
Ogre::Quaternion orientation =
target_node->_getDerivedOrientation();
if (object_e.has<CharacterBase>()) {
object_e.get_mut<CharacterBase>()
.mBodyNode->_setDerivedPosition(position);
object_e.get_mut<CharacterBase>()
.mBodyNode->_setDerivedOrientation(orientation);
}
return 0;
});
lua_setglobal(L, "ecs_trigger_set_position");
lua_pushcfunction(L, [](lua_State *L) -> int {
OgreAssert(lua_gettop(L) == 5, "Invalid parameters");
luaL_checktype(L, 1, LUA_TSTRING); // type
@@ -444,6 +472,20 @@ LuaData::LuaData()
return 0;
});
lua_setglobal(L, "ecs_character_physics_control");
lua_pushcfunction(L, [](lua_State *L) -> int {
luaL_checktype(L, 1, LUA_TNUMBER); // object
luaL_checktype(L, 2, LUA_TSTRING); // animation
Ogre::String animation = lua_tostring(L, 2);
int object = lua_tointeger(L, 1);
flecs::entity object_e = idmap.get_entity(object);
if (animation.length())
object_e.set<CharacterInActuator>({ animation });
else
object_e.remove<CharacterInActuator>();
return 0;
});
lua_setglobal(L, "ecs_character_set_actuator");
lua_pushcfunction(L, [](lua_State *L) -> int {
OgreAssert(lua_gettop(L) == 3, "Bad parameters");
luaL_checktype(L, 1, LUA_TNUMBER); // parent
@@ -454,7 +496,7 @@ LuaData::LuaData()
Ogre::String slot = lua_tostring(L, 3);
flecs::entity parent_e = idmap.get_entity(parent);
flecs::entity object_e = idmap.get_entity(object);
object_e.set<CharacterSlot>({ parent_e, slot, false });
object_e.set<ParentSlot>({ parent_e, slot, false });
return 0;
});
lua_setglobal(L, "ecs_set_slot");