1
0

Removed coord-based API from cCuboid. (#4362)

This commit is contained in:
Mattes D 2019-08-09 03:13:15 +02:00 committed by GitHub
parent a2547bf1fe
commit e7016b1525
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 185 additions and 142 deletions

View File

@ -570,28 +570,12 @@ return
Params =
{
{
Name = "X1",
Type = "number",
Name = "Point1",
Type = "Vector3i",
},
{
Name = "Y1",
Type = "number",
},
{
Name = "Z1",
Type = "number",
},
{
Name = "X2",
Type = "number",
},
{
Name = "Y2",
Type = "number",
},
{
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 =
{
@ -868,30 +816,6 @@ return
},
IsInside =
{
{
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 =
{
@ -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.",

View File

@ -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);

View File

@ -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);
}

View File

@ -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 */

View File

@ -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;
}