diff --git a/data/scripts/lumix.d.lua b/data/scripts/lumix.d.lua index dfc611fe6..53db87846 100644 --- a/data/scripts/lumix.d.lua +++ b/data/scripts/lumix.d.lua @@ -98,6 +98,7 @@ declare class SweepHit position : Vec3 normal : Vec3 entity : Entity + distance : number end declare class GUISystem diff --git a/src/engine/lua_api.cpp b/src/engine/lua_api.cpp index b7e7efe8e..05b815649 100644 --- a/src/engine/lua_api.cpp +++ b/src/engine/lua_api.cpp @@ -7,6 +7,7 @@ #include "lua_wrapper.h" #include "plugin.h" #include "prefab.h" +#include "profiler.h" #include "reflection.h" #include "string.h" #include "world.h" @@ -1005,6 +1006,10 @@ void registerEngineAPI(lua_State* L, Engine* engine) LuaWrapper::createSystemFunction(L, "LumixReflection", "getStructMemberName", &LuaWrapper::wrap); LuaWrapper::createSystemFunction(L, "LumixReflection", "getStructMemberType", &LuaWrapper::wrap); + LuaWrapper::createSystemFunction(L, "LumixAPI", "beginProfilerBlock", LuaWrapper::wrap<&profiler::endBlock>); + LuaWrapper::createSystemFunction(L, "LumixAPI", "endProfilerBlock", LuaWrapper::wrap<&profiler::beginBlock>); + LuaWrapper::createSystemFunction(L, "LumixAPI", "createProfilerCounter", LuaWrapper::wrap<&profiler::createCounter>); + LuaWrapper::createSystemFunction(L, "LumixAPI", "pushProfilerCounter", LuaWrapper::wrap<&profiler::pushCounter>); LuaWrapper::createSystemFunction(L, "LumixAPI", "networkRead", &LUA_networkRead); LuaWrapper::createSystemFunction(L, "LumixAPI", "packU32", &LUA_packU32); LuaWrapper::createSystemFunction(L, "LumixAPI", "unpackU32", &LUA_unpackU32); @@ -1158,6 +1163,11 @@ void registerEngineAPI(lua_State* L, Engine* engine) end end end + + Lumix.Entity.__eq = function(a, b) + return a._entity == b._entity and a._world == b._world + end + Lumix.Entity.__newindex = function(table, key, value) if key == "position" then LumixAPI.setEntityPosition(table._world, table._entity, value) diff --git a/src/physics/physics_module.cpp b/src/physics/physics_module.cpp index 729b66942..38c628d62 100644 --- a/src/physics/physics_module.cpp +++ b/src/physics/physics_module.cpp @@ -2407,6 +2407,7 @@ struct PhysicsModuleImpl final : PhysicsModule result.entity = EntityPtr{(int)(intptr_t)hit.block.actor->userData}; result.position = fromPhysx(hit.block.position); result.normal = fromPhysx(hit.block.normal); + result.distance = hit.block.distance; return true; } @@ -3972,6 +3973,7 @@ void PhysicsModule::reflect() { reflection::structure("SweepHit") .member<&SweepHit::position>("position") .member<&SweepHit::normal>("normal") + .member<&SweepHit::distance>("distance") .member<&SweepHit::entity>("entity"); LUMIX_MODULE(PhysicsModuleImpl, "physics") diff --git a/src/physics/physics_module.h b/src/physics/physics_module.h index b101f0ca7..405f9a28f 100644 --- a/src/physics/physics_module.h +++ b/src/physics/physics_module.h @@ -50,6 +50,7 @@ struct SweepHit { Vec3 position; Vec3 normal; EntityPtr entity; + float distance; }; struct LUMIX_PHYSICS_API PhysicsModule : IModule diff --git a/src/renderer/render_module.cpp b/src/renderer/render_module.cpp index 619b6d09d..7550c203c 100644 --- a/src/renderer/render_module.cpp +++ b/src/renderer/render_module.cpp @@ -2027,8 +2027,9 @@ struct RenderModuleImpl final : RenderModule { RayCastModelHit hit = module->castRay(origin, dir, INVALID_ENTITY); LuaWrapper::push(L, hit.is_hit); LuaWrapper::push(L, hit.is_hit ? hit.origin + hit.dir * hit.t : DVec3(0)); + LuaWrapper::pushEntity(L, hit.is_hit ? hit.entity : INVALID_ENTITY, &module->getWorld()); - return 2; + return 3; }