diff options
author | Mattes D <github@xoft.cz> | 2017-05-11 14:34:36 +0200 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2017-05-11 14:34:36 +0200 |
commit | 2c3c1f15273835923d9bd4950a19ee88a95ee0f4 (patch) | |
tree | cda390aa07a202497271439c2b330643074239df /src/Bindings | |
parent | Exported cFallingBlock and cExpOrb (#3700) (diff) | |
download | cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.gz cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.bz2 cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.lz cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.xz cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.zst cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/DeprecatedBindings.cpp | 46 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 206 |
2 files changed, 250 insertions, 2 deletions
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 0ffc58cbb..029d4edb7 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -10,6 +10,7 @@ #include "../World.h" #include "../Entities/Player.h" #include "LuaState.h" +#include "../Tracer.h" @@ -291,6 +292,47 @@ tolua_lerror: +/* method: Trace of class cTracer */ +static int tolua_cTracer_Trace(lua_State * a_LuaState) +{ + // Log a deprecation warning with stacktrace: + cLuaState S(a_LuaState); + LOGWARNING("The function cTracer:Trace is obsolete, use the cLineBlockTracer instead"); + S.LogStackTrace(); + + // Check params: + if ( + !S.CheckParamUserType(1, "cTracer") || + !S.CheckParamUserType(2, "const Vector3<float>", 3) || + !S.CheckParamNumber (4) + ) + { + return 0; + } + + // Read params: + cTracer * self; + Vector3d * start; + Vector3d * direction; + int distance; + bool lineOfSight = false; + if (!S.GetStackValues(1, self, start, direction, distance)) + { + LOGWARNING("Cannot retrieve parameters for cTracer::Trace. Expected a cTracer (self), Vector3d, Vector3d, number and optional boolean."); + S.LogStackValues(); + return 0; + } + S.GetStackValue(5, lineOfSight); + + // Call and push the result: + S.Push(self->Trace(*start, *direction, distance, lineOfSight)); + return 1; +} + + + + + /** function: cWorld:SetSignLines */ static int tolua_cWorld_SetSignLines(lua_State * tolua_S) { @@ -398,6 +440,10 @@ void DeprecatedBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "StringToMobType", tolua_AllToLua_StringToMobType00); + tolua_beginmodule(tolua_S, "cTracer"); + tolua_function(tolua_S, "Trace", tolua_cTracer_Trace); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cWorld"); tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines); tolua_endmodule(tolua_S); diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index c2392063a..1ad427331 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2605,7 +2605,7 @@ public: { } - virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) override { bool res = false; if (!m_Callbacks->CallTableFn( @@ -2683,6 +2683,202 @@ protected: +static int tolua_cLineBlockTracer_FirstSolidHitTrace(lua_State * tolua_S) +{ + /* Supported function signatures: + cLineBlockTracer:FirstSolidHitTrace(World, StartX, StartY, StartZ, EndX, EndY, EndZ) -> bool, [Vector3d, Vector3i, eBlockFace] // Canonical + cLineBlockTracer:FirstSolidHitTrace(World, Start, End) -> bool, [Vector3d, Vector3i, eBlockFace] // Canonical + cLineBlockTracer.FirstSolidHitTrace(World, StartX, StartY, StartZ, EndX, EndY, EndZ) -> bool, [Vector3d, Vector3i, eBlockFace] + cLineBlockTracer.FirstSolidHitTrace(World, Start, End) -> bool, [Vector3d, Vector3i, eBlockFace] + */ + + // If the first param is the cLineBlockTracer class, shift param index by one: + int idx = 1; + tolua_Error err; + if (tolua_isusertable(tolua_S, 1, "cLineBlockTracer", 0, &err)) + { + idx = 2; + } + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(idx, "cWorld") + ) + { + return 0; + } + + if (L.IsParamNumber(idx + 1)) + { + // This is the number variant of the call: + if ( + !L.CheckParamNumber(idx + 1, idx + 6) || + !L.CheckParamEnd(idx + 7) + ) + { + return 0; + } + // Get the params: + cWorld * world; + double startX, startY, startZ; + double endX, endY, endZ; + if (!L.GetStackValues(idx, world, startX, startY, startZ, endX, endY, endZ)) + { + LOGWARNING("cLineBlockTracer:FirstSolidHitTrace(): Cannot read parameters, aborting the trace."); + L.LogStackTrace(); + L.LogStackValues("Values on the stack"); + return 0; + } + Vector3d hitCoords; + Vector3i hitBlockCoords; + eBlockFace hitBlockFace; + auto isHit = cLineBlockTracer::FirstSolidHitTrace(*world, Vector3d(startX, startY, startZ), Vector3d(endX, endY, endZ), hitCoords, hitBlockCoords, hitBlockFace); + L.Push(isHit); + if (!isHit) + { + return 1; + } + L.Push(hitCoords); + L.Push(hitBlockCoords); + L.Push(hitBlockFace); + return 4; + } + + if (L.IsParamUserType(idx + 1, "Vector3<double>")) + { + // This is the Vector3d-based variant of the call: + if ( + !L.CheckParamUserType(idx + 1, "Vector3<double>", idx + 2) || + !L.CheckParamEnd(idx + 3) + ) + { + return 0; + } + // Get the params: + cWorld * world; + Vector3d * start; + Vector3d * end; + if (!L.GetStackValues(idx, world, start, end)) + { + LOGWARNING("cLineBlockTracer:FirstSolidHitTrace(): Cannot read parameters, aborting the trace."); + L.LogStackTrace(); + L.LogStackValues("Values on the stack"); + return 0; + } + Vector3d hitCoords; + Vector3i hitBlockCoords; + eBlockFace hitBlockFace; + auto isHit = cLineBlockTracer::FirstSolidHitTrace(*world, start, end, hitCoords, hitBlockCoords, hitBlockFace); + L.Push(isHit); + if (!isHit) + { + return 1; + } + L.Push(hitCoords); + L.Push(hitBlockCoords); + L.Push(hitBlockFace); + return 4; + } + + tolua_error(L, "cLineBlockTracer:FirstSolidHitTrace(): Invalid parameters, expected either a set of coords, or two Vector3d's", nullptr); + return 0; +} + + + + + +static int tolua_cLineBlockTracer_LineOfSightTrace(lua_State * tolua_S) +{ + /* Supported function signatures: + cLineBlockTracer:LineOfSightTrace(World, StartX, StartY, StartZ, EndX, EndY, EndZ, Sight) -> bool // Canonical + cLineBlockTracer:LineOfSightTrace(World, Start, End, Sight) -> bool // Canonical + cLineBlockTracer.LineOfSightTrace(World, StartX, StartY, StartZ, EndX, EndY, EndZ, Sight) -> bool + cLineBlockTracer.LineOfSightTrace(World, Start, End, Sight) -> bool + */ + + // If the first param is the cLineBlockTracer class, shift param index by one: + int idx = 1; + tolua_Error err; + if (tolua_isusertable(tolua_S, 1, "cLineBlockTracer", 0, &err)) + { + idx = 2; + } + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(idx, "cWorld") + ) + { + return 0; + } + + if (L.IsParamNumber(idx + 1)) + { + // This is the number variant of the call: + if ( + !L.CheckParamNumber(idx + 1, idx + 6) || + // Optional param lineOfSight is not checked + !L.CheckParamEnd(idx + 8) + ) + { + return 0; + } + // Get the params: + cWorld * world; + double startX, startY, startZ; + double endX, endY, endZ; + if (!L.GetStackValues(idx, world, startX, startY, startZ, endX, endY, endZ)) + { + LOGWARNING("cLineBlockTracer:LineOfSightTrace(): Cannot read parameters, aborting the trace."); + L.LogStackTrace(); + L.LogStackValues("Values on the stack"); + return 0; + } + int lineOfSight = cLineBlockTracer::losAir | cLineBlockTracer::losWater; + L.GetStackValue(idx + 7, lineOfSight); + L.Push(cLineBlockTracer::LineOfSightTrace(*world, Vector3d(startX, startY, startZ), Vector3d(endX, endY, endZ), lineOfSight)); + return 1; + } + + if (L.IsParamUserType(idx + 1, "Vector3<double>")) + { + // This is the Vector3d-based variant of the call: + if ( + !L.CheckParamUserType(idx + 1, "Vector3<double>", idx + 2) || + // Optional param lineOfSight is not checked + !L.CheckParamEnd(idx + 4) + ) + { + return 0; + } + // Get the params: + cWorld * world; + Vector3d * start; + Vector3d * end; + if (!L.GetStackValues(idx, world, start, end)) + { + LOGWARNING("cLineBlockTracer:LineOfSightTrace(): Cannot read parameters, aborting the trace."); + L.LogStackTrace(); + L.LogStackValues("Values on the stack"); + return 0; + } + int lineOfSight = cLineBlockTracer::losAirWater; + L.GetStackValue(idx + 7, lineOfSight); + L.Push(cLineBlockTracer::LineOfSightTrace(*world, start, end, lineOfSight)); + return 1; + } + + tolua_error(L, "cLineBlockTracer:LineOfSightTrace(): Invalid parameters, expected either a set of coords, or two Vector3d's", nullptr); + return 0; +} + + + + + static int tolua_cLineBlockTracer_Trace(lua_State * tolua_S) { /* Supported function signatures: @@ -3917,7 +4113,13 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cLineBlockTracer"); - tolua_function(tolua_S, "Trace", tolua_cLineBlockTracer_Trace); + tolua_function(tolua_S, "FirstSolidHitTrace", tolua_cLineBlockTracer_FirstSolidHitTrace); + tolua_function(tolua_S, "LineOfSightTrace", tolua_cLineBlockTracer_LineOfSightTrace); + tolua_function(tolua_S, "Trace", tolua_cLineBlockTracer_Trace); + + tolua_constant(tolua_S, "losAir", cLineBlockTracer::losAir); + tolua_constant(tolua_S, "losWater", cLineBlockTracer::losWater); + tolua_constant(tolua_S, "losLava", cLineBlockTracer::losLava); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cLuaWindow"); |