diff options
author | Mattes D <github@xoft.cz> | 2019-08-09 03:13:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-09 03:13:15 +0200 |
commit | e7016b15259f8432e0a333a948498fb280d4d7a9 (patch) | |
tree | c762898c05633066e37ec568f0e0146dcd3ab6f5 | |
parent | cBoundingBox: Fix tolua warning (#4361) (diff) | |
download | cuberite-e7016b15259f8432e0a333a948498fb280d4d7a9.tar cuberite-e7016b15259f8432e0a333a948498fb280d4d7a9.tar.gz cuberite-e7016b15259f8432e0a333a948498fb280d4d7a9.tar.bz2 cuberite-e7016b15259f8432e0a333a948498fb280d4d7a9.tar.lz cuberite-e7016b15259f8432e0a333a948498fb280d4d7a9.tar.xz cuberite-e7016b15259f8432e0a333a948498fb280d4d7a9.tar.zst cuberite-e7016b15259f8432e0a333a948498fb280d4d7a9.zip |
Diffstat (limited to '')
-rw-r--r-- | Server/Plugins/APIDump/Classes/Geometry.lua | 96 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 134 | ||||
-rw-r--r-- | src/Cuboid.cpp | 20 | ||||
-rw-r--r-- | src/Cuboid.h | 39 | ||||
-rw-r--r-- | src/Generating/MineShafts.cpp | 38 |
5 files changed, 185 insertions, 142 deletions
diff --git a/Server/Plugins/APIDump/Classes/Geometry.lua b/Server/Plugins/APIDump/Classes/Geometry.lua index e9280b359..e086d23fa 100644 --- a/Server/Plugins/APIDump/Classes/Geometry.lua +++ b/Server/Plugins/APIDump/Classes/Geometry.lua @@ -570,28 +570,12 @@ return Params = { { - Name = "X1", - Type = "number", - }, - { - Name = "Y1", - Type = "number", - }, - { - Name = "Z1", - Type = "number", - }, - { - Name = "X2", - Type = "number", - }, - { - Name = "Y2", - Type = "number", + Name = "Point1", + Type = "Vector3i", }, { - Name = "Z2", - Type = "number", + Name = "Point2", + Type = "Vector3i", }, }, Notes = "Assigns all the coords to the specified values. Sort-state is ignored.", @@ -713,42 +697,6 @@ return }, Notes = "Creates a new Cuboid object with the specified point as both its corners (the cuboid has a size of 1 in each direction).", }, - { - Params = - { - { - Name = "X1", - Type = "number", - }, - { - Name = "Y1", - Type = "number", - }, - { - Name = "Z1", - Type = "number", - }, - { - Name = "X2", - Type = "number", - }, - { - Name = "Y2", - Type = "number", - }, - { - Name = "Z2", - Type = "number", - }, - }, - Returns = - { - { - Type = "cCuboid", - }, - }, - Notes = "Creates a new Cuboid object with the specified points as its corners.", - }, }, DifX = { @@ -872,30 +820,6 @@ return Params = { { - Name = "X", - Type = "number", - }, - { - Name = "Y", - Type = "number", - }, - { - Name = "Z", - Type = "number", - }, - }, - Returns = - { - { - Type = "boolean", - }, - }, - Notes = "Returns true if the specified point (integral coords) is inside this cuboid. Assumes sorted.", - }, - { - Params = - { - { Name = "Point", Type = "Vector3i", }, @@ -940,16 +864,8 @@ return Params = { { - Name = "OffsetX", - Type = "number", - }, - { - Name = "OffsetY", - Type = "number", - }, - { - Name = "OffsetZ", - Type = "number", + Name = "Offset", + Type = "Vector3i", }, }, Notes = "Adds the specified offsets to each respective coord, effectively moving the Cuboid. Sort-state is ignored and preserved.", diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 90251a4b2..af4a301a0 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3954,6 +3954,134 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S) +static int tolua_cCuboid_Assign(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + + if (!L.CheckParamSelf("cCuboid")) + { + return 0; + } + + cCuboid * self = nullptr; + L.GetStackValue(1, self); + + // Check the old coord-based signature: + int x1, y1, z1, x2, y2, z2; + if (L.GetStackValues(2, x1, y1, z1, x2, y2, z2)) + { + LOGWARNING("cCuboid:Assign(x1, y1, z1, x2, y2, z2) is deprecated, use cCuboid:Assign(Vector3i, Vector3i) instead."); + L.LogStackTrace(); + self->Assign({x1, y1, z1}, {x2, y2, z2}); + return 0; + } + + // Try the (cCuboid) param version: + cCuboid * other = nullptr; + if (L.GetStackValue(2, other) && (other != nullptr)) + { + self->Assign(*other); + return 0; + } + + // Try the (Vector3i, Vector3i) param version: + Vector3i * pt1 = nullptr; + Vector3i * pt2 = nullptr; + if (L.GetStackValues(2, pt1, pt2) && (pt1 != nullptr) && (pt2 != nullptr)) + { + self->Assign(*pt1, *pt2); + return 0; + } + return L.ApiParamError("Invalid parameter, expected either a cCuboid or two Vector3i-s."); +} + + + + + +static int tolua_cCuboid_IsInside(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + + if (!L.CheckParamSelf("cCuboid")) + { + return 0; + } + + cCuboid * self = nullptr; + L.GetStackValue(1, self); + + // Check the old coord-based signature: + int x, y, z; + if (L.GetStackValues(2, x, y, z)) + { + LOGWARNING("cCuboid:IsInside(x, y, z) is deprecated, use cCuboid:IsInside(Vector3d) instead."); + L.LogStackTrace(); + self->Move({x, y, z}); + return 0; + } + + // Try the (Vector3i) param version: + { + Vector3i * pt = nullptr; + if (L.GetStackValue(2, pt) && (pt != nullptr)) + { + L.Push(self->IsInside(*pt)); + return 1; + } + } + + // Try the (Vector3d) param version: + { + Vector3d * pt = nullptr; + if (L.GetStackValue(2, pt) && (pt != nullptr)) + { + L.Push(self->IsInside(*pt)); + return 1; + } + } + return L.ApiParamError("Invalid parameter #2, expected a Vector3i or a Vector3d."); +} + + + + + +static int tolua_cCuboid_Move(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + + if (!L.CheckParamSelf("cCuboid")) + { + return 0; + } + + cCuboid * self = nullptr; + L.GetStackValue(1, self); + + // Check the old coord-based signature: + int x, y, z; + if (L.GetStackValues(2, x, y, z)) + { + LOGWARNING("cCuboid:Move(x, y, z) is deprecated, use cCuboid:Move(Vector3i) instead."); + L.LogStackTrace(); + self->Move({x, y, z}); + return 0; + } + + Vector3i * offset = nullptr; + if (!L.GetStackValue(2, offset) || (offset == nullptr)) + { + return L.ApiParamError("Invalid parameter #2, expected a Vector3i."); + } + self->Move(*offset); + return 0; +} + + + + + static int tolua_cEntity_IsSubmerged(lua_State * tolua_S) { // Check the params: @@ -4121,6 +4249,12 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "sha1HexString", tolua_sha1HexString); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cCuboid"); + tolua_function(tolua_S, "Assign", tolua_cCuboid_Assign); + tolua_function(tolua_S, "IsInside", tolua_cCuboid_IsInside); + tolua_function(tolua_S, "Move", tolua_cCuboid_Move); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cEntity"); tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID); tolua_function(tolua_S, "IsSubmerged", tolua_cEntity_IsSubmerged); diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index 930ee6c0e..93749491e 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -10,14 +10,10 @@ //////////////////////////////////////////////////////////////////////////////// // cCuboid: -void cCuboid::Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) +void cCuboid::Assign(Vector3i a_Point1, Vector3i a_Point2) { - p1.x = a_X1; - p1.y = a_Y1; - p1.z = a_Z1; - p2.x = a_X2; - p2.y = a_Y2; - p2.z = a_Z2; + p1 = a_Point1; + p2 = a_Point2; } @@ -75,14 +71,10 @@ bool cCuboid::IsCompletelyInside(const cCuboid & a_Outer) const -void cCuboid::Move(int a_OfsX, int a_OfsY, int a_OfsZ) +void cCuboid::Move(Vector3i a_Offset) { - p1.x += a_OfsX; - p1.y += a_OfsY; - p1.z += a_OfsZ; - p2.x += a_OfsX; - p2.y += a_OfsY; - p2.z += a_OfsZ; + p1.Move(a_Offset); + p2.Move(a_Offset); } diff --git a/src/Cuboid.h b/src/Cuboid.h index acb19d46b..864bea7a2 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -13,22 +13,21 @@ public: Vector3i p1, p2; cCuboid(void) {} - cCuboid(const Vector3i & a_p1, const Vector3i & a_p2) : p1(a_p1), p2(a_p2) {} + cCuboid(Vector3i a_p1, Vector3i a_p2) : p1(a_p1), p2(a_p2) {} cCuboid(int a_X1, int a_Y1, int a_Z1) : p1(a_X1, a_Y1, a_Z1), p2(a_X1, a_Y1, a_Z1) {} #ifdef TOLUA_EXPOSITION // tolua isn't aware of implicitly generated copy constructors cCuboid(const cCuboid & a_Cuboid); #endif - // DEPRECATED, use cCuboid(Vector3i, Vector3i) instead - cCuboid(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) : p1(a_X1, a_Y1, a_Z1), p2(a_X2, a_Y2, a_Z2) - { - LOGWARNING("cCuboid(int, int, int, int, int, int) constructor is deprecated, use cCuboid(Vector3i, Vector3i) constructor instead."); - } + // tolua_end + // Exported in ManualBindings.cpp to support the old deprecated coord-based overload. - void Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2); + void Assign(Vector3i a_Point1, Vector3i a_Point2); void Assign(const cCuboid & a_SrcCuboid) { *this = a_SrcCuboid; } + // tolua_begin + void Sort(void); int DifX(void) const { return p2.x - p1.x; } @@ -55,6 +54,9 @@ public: ); } + // tolua_end + // Exported in ManualBindings.cpp to support the old deprecated coord-based overload. + bool IsInside(Vector3i v) const { return ( @@ -64,15 +66,6 @@ public: ); } - bool IsInside(int a_X, int a_Y, int a_Z) const - { - return ( - (a_X >= p1.x) && (a_X <= p2.x) && - (a_Y >= p1.y) && (a_Y <= p2.y) && - (a_Z >= p1.z) && (a_Z <= p2.z) - ); - } - bool IsInside(Vector3d v) const { return ( @@ -82,12 +75,19 @@ public: ); } - /** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords). + // tolua_begin + + /** Returns true if this cuboid is completely inside the specified cuboid (in all 6 coords). Assumes both cuboids are sorted. */ bool IsCompletelyInside(const cCuboid & a_Outer) const; - /** Moves the cuboid by the specified offsets in each direction */ - void Move(int a_OfsX, int a_OfsY, int a_OfsZ); + // tolua_end + + /** Moves the cuboid by the specified offset. + Exported in ManualBindings to support the old deprecated coord-based overload. */ + void Move(Vector3i a_Offset); + + // tolua_begin /** Expands the cuboid by the specified amount in each direction. Works on unsorted cuboids as well. @@ -109,6 +109,7 @@ public: /** If needed, expands the cuboid so that it contains the specified point. Assumes sorted. Doesn't contract. */ void Engulf(Vector3i a_Point); + private: /** Returns true if the two specified intervals have a non-empty union */ diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 5a9fd6368..80ba3f5b5 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -299,8 +299,8 @@ cStructGenMineShafts::cMineShaftSystem::cMineShaftSystem( m_MineShafts.push_back(Start); m_BoundingBox.Assign( - Start->m_BoundingBox.p1.x - a_MaxSystemSize / 2, 2, Start->m_BoundingBox.p1.z - a_MaxSystemSize / 2, - Start->m_BoundingBox.p2.x + a_MaxSystemSize / 2, 50, Start->m_BoundingBox.p2.z + a_MaxSystemSize / 2 + {Start->m_BoundingBox.p1.x - a_MaxSystemSize / 2, 2, Start->m_BoundingBox.p1.z - a_MaxSystemSize / 2}, + {Start->m_BoundingBox.p2.x + a_MaxSystemSize / 2, 50, Start->m_BoundingBox.p2.z + a_MaxSystemSize / 2} ); Start->AppendBranches(0, a_Noise); @@ -639,7 +639,7 @@ void cMineShaftCorridor::ProcessChunk(cChunkDesc & a_ChunkDesc) int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; cCuboid RelBoundingBox(m_BoundingBox); - RelBoundingBox.Move(-BlockX, 0, -BlockZ); + RelBoundingBox.Move({-BlockX, 0, -BlockZ}); RelBoundingBox.p1.y += 1; RelBoundingBox.p2.y -= 1; cCuboid Top(RelBoundingBox); @@ -818,7 +818,7 @@ void cMineShaftCorridor::PlaceTracks(cChunkDesc & a_ChunkDesc) return; } cCuboid Box(m_BoundingBox); - Box.Move(-a_ChunkDesc.GetChunkX() * cChunkDef::Width, 1, -a_ChunkDesc.GetChunkZ() * cChunkDef::Width); + Box.Move({-a_ChunkDesc.GetChunkX() * cChunkDef::Width, 1, -a_ChunkDesc.GetChunkZ() * cChunkDef::Width}); Box.p2.y = Box.p1.y; Box.p1.x += 1; Box.p2.x -= 1; @@ -1061,7 +1061,7 @@ void cMineShaftCrossing::ProcessChunk(cChunkDesc & a_ChunkDesc) int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; cCuboid box(m_BoundingBox); - box.Move(-BlockX, 0, -BlockZ); + box.Move({-BlockX, 0, -BlockZ}); if ((box.p2.x < 0) || (box.p2.z < 0) || (box.p1.x >= cChunkDef::Width) || (box.p1.z > cChunkDef::Width)) { // Does not intersect this chunk @@ -1135,22 +1135,22 @@ cMineShaft * cMineShaftStaircase::CreateAndFit( { case dirXM: { - Box.Assign(a_PivotX - 7, a_PivotY - 1, a_PivotZ - 1, a_PivotX, a_PivotY + 6, a_PivotZ + 1); + Box.Assign({a_PivotX - 7, a_PivotY - 1, a_PivotZ - 1}, {a_PivotX, a_PivotY + 6, a_PivotZ + 1}); break; } case dirXP: { - Box.Assign(a_PivotX, a_PivotY - 1, a_PivotZ - 1, a_PivotX + 7, a_PivotY + 6, a_PivotZ + 1); + Box.Assign({a_PivotX, a_PivotY - 1, a_PivotZ - 1}, {a_PivotX + 7, a_PivotY + 6, a_PivotZ + 1}); break; } case dirZM: { - Box.Assign(a_PivotX - 1, a_PivotY - 1, a_PivotZ - 7, a_PivotX + 1, a_PivotY + 6, a_PivotZ); + Box.Assign({a_PivotX - 1, a_PivotY - 1, a_PivotZ - 7}, {a_PivotX + 1, a_PivotY + 6, a_PivotZ}); break; } case dirZP: { - Box.Assign(a_PivotX - 1, a_PivotY - 1, a_PivotZ, a_PivotX + 1, a_PivotY + 6, a_PivotZ + 7); + Box.Assign({a_PivotX - 1, a_PivotY - 1, a_PivotZ}, {a_PivotX + 1, a_PivotY + 6, a_PivotZ + 7}); break; } } @@ -1158,7 +1158,7 @@ cMineShaft * cMineShaftStaircase::CreateAndFit( if ((rnd % 4) < 2) // 50 % { Slope = sDown; - Box.Move(0, -4, 0); + Box.Move({0, -4, 0}); } if (!a_ParentSystem.CanAppend(Box)) { @@ -1192,7 +1192,7 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; cCuboid RelB(m_BoundingBox); - RelB.Move(-BlockX, 0, -BlockZ); + RelB.Move({-BlockX, 0, -BlockZ}); if ( (RelB.p1.x >= cChunkDef::Width) || (RelB.p1.z >= cChunkDef::Width) || @@ -1217,12 +1217,12 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p1.x + 1, DFloor, DFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(RelB.p2.x - 1, RelB.p2.x, SFloor - 1, SFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p1.x + 1, DFloor - 1, DFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); - Box.Assign(RelB.p2.x - 2, SFloor + InitAdd, RelB.p1.z, RelB.p2.x - 2, SFloor + 3 + InitAdd, RelB.p2.z); + Box.Assign({RelB.p2.x - 2, SFloor + InitAdd, RelB.p1.z}, {RelB.p2.x - 2, SFloor + 3 + InitAdd, RelB.p2.z}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); - Box.Move(-1, Add, 0); + Box.Move({-1, Add, 0}); } break; } @@ -1233,12 +1233,12 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) a_ChunkDesc.FillRelCuboid (RelB.p2.x - 1, RelB.p2.x, DFloor, DFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p1.x + 1, SFloor - 1, SFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); a_ChunkDesc.FloorRelCuboid(RelB.p2.x - 1, RelB.p2.x, DFloor - 1, DFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); - Box.Assign(RelB.p1.x + 2, SFloor + InitAdd, RelB.p1.z, RelB.p1.x + 2, SFloor + 3 + InitAdd, RelB.p2.z); + Box.Assign({RelB.p1.x + 2, SFloor + InitAdd, RelB.p1.z}, {RelB.p1.x + 2, SFloor + 3 + InitAdd, RelB.p2.z}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); - Box.Move(1, Add, 0); + Box.Move({1, Add, 0}); } break; } @@ -1249,12 +1249,12 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p2.x, DFloor, DFloor + 2, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, SFloor - 1, SFloor - 1, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_PLANKS, 0); a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, DFloor - 1, DFloor - 1, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_PLANKS, 0); - Box.Assign(RelB.p1.x, SFloor + InitAdd, RelB.p2.z - 2, RelB.p2.x, SFloor + 3 + InitAdd, RelB.p2.z - 2); + Box.Assign({RelB.p1.x, SFloor + InitAdd, RelB.p2.z - 2}, {RelB.p2.x, SFloor + 3 + InitAdd, RelB.p2.z - 2}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); - Box.Move(0, Add, -1); + Box.Move({0, Add, -1}); } break; } @@ -1265,12 +1265,12 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p2.x, DFloor, DFloor + 2, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, SFloor - 1, SFloor - 1, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_PLANKS, 0); a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, DFloor - 1, DFloor - 1, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_PLANKS, 0); - Box.Assign(RelB.p1.x, SFloor + InitAdd, RelB.p1.z + 2, RelB.p2.x, SFloor + 3 + InitAdd, RelB.p1.z + 2); + Box.Assign({RelB.p1.x, SFloor + InitAdd, RelB.p1.z + 2}, {RelB.p2.x, SFloor + 3 + InitAdd, RelB.p1.z + 2}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); - Box.Move(0, Add, 1); + Box.Move({0, Add, 1}); } break; } |