converted to Jolt physics
This commit is contained in:
@@ -2,15 +2,67 @@
|
||||
#include "GameData.h"
|
||||
#include "Components.h"
|
||||
#include "GUIModule.h"
|
||||
#include "PhysicsModule.h"
|
||||
#include "CharacterModule.h"
|
||||
#include "CharacterAnimationModule.h"
|
||||
#include "BoatModule.h"
|
||||
#include "EventTriggerModule.h"
|
||||
#include "SlotsModule.h"
|
||||
#include "world-build.h"
|
||||
#include "LuaData.h"
|
||||
|
||||
#include "luaaa.hpp"
|
||||
extern "C" {
|
||||
int luaopen_lpeg(lua_State *L);
|
||||
}
|
||||
struct FooPosition {
|
||||
Ogre::Vector3 value;
|
||||
Ogre::Vector3 &get()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
namespace luaaa
|
||||
{
|
||||
template <> struct LuaStack<FooPosition> {
|
||||
inline static FooPosition get(lua_State *L, int idx)
|
||||
{
|
||||
FooPosition result;
|
||||
if (lua_istable(L, idx)) {
|
||||
lua_pushnil(L);
|
||||
while (0 != lua_next(L, idx)) {
|
||||
const int top = lua_gettop(L);
|
||||
const char *name =
|
||||
LuaStack<const char *>::get(L, top - 1);
|
||||
if (strncmp(name, "x", 1) == 0)
|
||||
result.value.x =
|
||||
LuaStack<float>::get(L, top);
|
||||
else if (strncmp(name, "y", 1) == 0)
|
||||
result.value.y =
|
||||
LuaStack<float>::get(L, top);
|
||||
else if (strncmp(name, "z", 1) == 0)
|
||||
result.value.z =
|
||||
LuaStack<float>::get(L, top);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
inline static void put(lua_State *L, const FooPosition &v)
|
||||
{
|
||||
lua_newtable(L);
|
||||
LuaStack<const char *>::put(L, "x");
|
||||
LuaStack<float>::put(L, v.value.x);
|
||||
lua_rawset(L, -3);
|
||||
LuaStack<const char *>::put(L, "y");
|
||||
LuaStack<float>::put(L, v.value.y);
|
||||
lua_rawset(L, -3);
|
||||
LuaStack<const char *>::put(L, "z");
|
||||
LuaStack<float>::put(L, v.value.z);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
namespace ECS
|
||||
{
|
||||
@@ -194,6 +246,46 @@ LuaData::LuaData()
|
||||
#endif
|
||||
installLibraryLoader(L);
|
||||
lua_pop(L, 1);
|
||||
|
||||
#if 0
|
||||
luaaa::LuaClass<Ogre::Vector3> luaVector3(L, "Vector3");
|
||||
luaVector3.ctor<float, float, float>();
|
||||
luaVector3.get("x", [](Ogre::Vector3 &v) -> float { return v.x; });
|
||||
luaVector3.set("x", [](Ogre::Vector3 &v, float value) -> void {
|
||||
v.x = value;
|
||||
});
|
||||
luaVector3.get("y", [](Ogre::Vector3 &v) -> float { return v.y; });
|
||||
luaVector3.set("y", [](Ogre::Vector3 &v, float value) -> void {
|
||||
v.y = value;
|
||||
});
|
||||
luaVector3.get("z", [](Ogre::Vector3 &v) -> float { return v.z; });
|
||||
luaVector3.set("z", [](Ogre::Vector3 &v, float value) -> void {
|
||||
v.z = value;
|
||||
});
|
||||
luaVector3.fun("squaredLength", &Ogre::Vector3::squaredLength);
|
||||
luaVector3.fun("length", &Ogre::Vector3::length);
|
||||
luaVector3.fun("squaredDistance", &Ogre::Vector3::squaredDistance);
|
||||
luaVector3.fun("distance", &Ogre::Vector3::distance);
|
||||
#endif
|
||||
luaaa::LuaModule luaECS(L, "_ecs");
|
||||
luaECS.fun("position", [](int id) -> FooPosition {
|
||||
#if 0
|
||||
flecs::entity e = idmap.get_entity(id);
|
||||
if (e.has<CharacterBase>()) {
|
||||
const CharacterBase &cb = e.get<CharacterBase>();
|
||||
return cb.mBodyNode->_getDerivedPosition();
|
||||
} else if (e.has<BoatBase>()) {
|
||||
const BoatBase &boat = e.get<BoatBase>();
|
||||
return boat.mNode->_getDerivedPosition();
|
||||
} else if (e.has<EventTrigger>()) {
|
||||
const EventTrigger &trigger = e.get<EventTrigger>();
|
||||
return trigger.position;
|
||||
} else
|
||||
return Ogre::Vector3(0, 0, 0);
|
||||
#endif
|
||||
return FooPosition();
|
||||
});
|
||||
|
||||
lua_pushcfunction(L, [](lua_State *L) -> int {
|
||||
OgreAssert(false, "Crash function called");
|
||||
return 0;
|
||||
@@ -567,7 +659,9 @@ 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<ParentSlot>({ parent_e, slot, false });
|
||||
if (!object_e.has<CharacterDisablePhysics>())
|
||||
object_e.add<CharacterDisablePhysics>();
|
||||
object_e.set<ParentSlot>({ parent_e, slot });
|
||||
return 0;
|
||||
});
|
||||
lua_setglobal(L, "ecs_set_slot");
|
||||
@@ -737,6 +831,7 @@ void LuaData::lateSetup()
|
||||
LuaModule::LuaModule(flecs::world &ecs)
|
||||
{
|
||||
ecs.module<LuaModule>();
|
||||
ecs.import <SlotsModule>();
|
||||
ecs.component<LuaChildEventTrigger>();
|
||||
ecs.component<LuaBase>()
|
||||
.on_add([](LuaBase &lua) {
|
||||
|
||||
Reference in New Issue
Block a user