diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-03-29 20:45:42 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-03-29 20:45:42 +0100 |
commit | a633c45e8e714b91783b3625c1ec98c62302292d (patch) | |
tree | fbf60bef53bb2f7fa35de13eb7f3f5d7ba350ff1 | |
parent | ListenThread now reports the protocol used (IPv4 - IPv6) in its error messages (diff) | |
download | cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.gz cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.bz2 cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.lz cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.xz cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.zst cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.zip |
-rw-r--r-- | source/Bindings.cpp | 247 | ||||
-rw-r--r-- | source/Bindings.h | 2 | ||||
-rw-r--r-- | source/Cuboid.cpp | 48 | ||||
-rw-r--r-- | source/Cuboid.h | 17 |
4 files changed, 310 insertions, 4 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp index f21cccee9..1c6147594 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 03/29/13 17:37:21. +** Generated automatically by tolua++-1.0.92 on 03/29/13 20:28:23. */ #ifndef __cplusplus @@ -17408,6 +17408,136 @@ tolua_lerror: } #endif //#ifndef TOLUA_DISABLE +/* method: new of class cCuboid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_new03 +static int tolua_AllToLua_cCuboid_new03(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cCuboid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + int a_X1 = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y1 = ((int) tolua_tonumber(tolua_S,3,0)); + int a_Z1 = ((int) tolua_tonumber(tolua_S,4,0)); + { + cCuboid* tolua_ret = (cCuboid*) Mtolua_new((cCuboid)(a_X1,a_Y1,a_Z1)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cCuboid"); + } + } + return 1; +tolua_lerror: + return tolua_AllToLua_cCuboid_new02(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: new_local of class cCuboid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_new03_local +static int tolua_AllToLua_cCuboid_new03_local(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cCuboid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + int a_X1 = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y1 = ((int) tolua_tonumber(tolua_S,3,0)); + int a_Z1 = ((int) tolua_tonumber(tolua_S,4,0)); + { + cCuboid* tolua_ret = (cCuboid*) Mtolua_new((cCuboid)(a_X1,a_Y1,a_Z1)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cCuboid"); + tolua_register_gc(tolua_S,lua_gettop(tolua_S)); + } + } + return 1; +tolua_lerror: + return tolua_AllToLua_cCuboid_new02_local(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: new of class cCuboid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_new04 +static int tolua_AllToLua_cCuboid_new04(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cCuboid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnumber(tolua_S,6,0,&tolua_err) || + !tolua_isnumber(tolua_S,7,0,&tolua_err) || + !tolua_isnoobj(tolua_S,8,&tolua_err) + ) + goto tolua_lerror; + else + { + int a_X1 = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y1 = ((int) tolua_tonumber(tolua_S,3,0)); + int a_Z1 = ((int) tolua_tonumber(tolua_S,4,0)); + int a_X2 = ((int) tolua_tonumber(tolua_S,5,0)); + int a_Y2 = ((int) tolua_tonumber(tolua_S,6,0)); + int a_Z2 = ((int) tolua_tonumber(tolua_S,7,0)); + { + cCuboid* tolua_ret = (cCuboid*) Mtolua_new((cCuboid)(a_X1,a_Y1,a_Z1,a_X2,a_Y2,a_Z2)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cCuboid"); + } + } + return 1; +tolua_lerror: + return tolua_AllToLua_cCuboid_new03(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: new_local of class cCuboid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_new04_local +static int tolua_AllToLua_cCuboid_new04_local(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cCuboid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnumber(tolua_S,6,0,&tolua_err) || + !tolua_isnumber(tolua_S,7,0,&tolua_err) || + !tolua_isnoobj(tolua_S,8,&tolua_err) + ) + goto tolua_lerror; + else + { + int a_X1 = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y1 = ((int) tolua_tonumber(tolua_S,3,0)); + int a_Z1 = ((int) tolua_tonumber(tolua_S,4,0)); + int a_X2 = ((int) tolua_tonumber(tolua_S,5,0)); + int a_Y2 = ((int) tolua_tonumber(tolua_S,6,0)); + int a_Z2 = ((int) tolua_tonumber(tolua_S,7,0)); + { + cCuboid* tolua_ret = (cCuboid*) Mtolua_new((cCuboid)(a_X1,a_Y1,a_Z1,a_X2,a_Y2,a_Z2)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cCuboid"); + tolua_register_gc(tolua_S,lua_gettop(tolua_S)); + } + } + return 1; +tolua_lerror: + return tolua_AllToLua_cCuboid_new03_local(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + /* method: Sort of class cCuboid */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_Sort00 static int tolua_AllToLua_cCuboid_Sort00(lua_State* tolua_S) @@ -17535,6 +17665,40 @@ static int tolua_AllToLua_cCuboid_DifZ00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: DoesIntersect of class cCuboid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_DoesIntersect00 +static int tolua_AllToLua_cCuboid_DoesIntersect00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCuboid",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cCuboid",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cCuboid* self = (const cCuboid*) tolua_tousertype(tolua_S,1,0); + const cCuboid* a_Other = ((const cCuboid*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DoesIntersect'", NULL); +#endif + { + bool tolua_ret = (bool) self->DoesIntersect(*a_Other); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'DoesIntersect'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: IsInside of class cCuboid */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_IsInside00 static int tolua_AllToLua_cCuboid_IsInside00(lua_State* tolua_S) @@ -17576,6 +17740,39 @@ static int tolua_AllToLua_cCuboid_IsInside01(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"const cCuboid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + const cCuboid* self = (const cCuboid*) tolua_tousertype(tolua_S,1,0); + int a_X = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y = ((int) tolua_tonumber(tolua_S,3,0)); + int a_Z = ((int) tolua_tonumber(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsInside'", NULL); +#endif + { + bool tolua_ret = (bool) self->IsInside(a_X,a_Y,a_Z); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +tolua_lerror: + return tolua_AllToLua_cCuboid_IsInside00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: IsInside of class cCuboid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_IsInside02 +static int tolua_AllToLua_cCuboid_IsInside02(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cCuboid",0,&tolua_err) || (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const Vector3d",0,&tolua_err)) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -17594,7 +17791,44 @@ static int tolua_AllToLua_cCuboid_IsInside01(lua_State* tolua_S) } return 1; tolua_lerror: - return tolua_AllToLua_cCuboid_IsInside00(tolua_S); + return tolua_AllToLua_cCuboid_IsInside01(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: Move of class cCuboid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cCuboid_Move00 +static int tolua_AllToLua_cCuboid_Move00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cCuboid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cCuboid* self = (cCuboid*) tolua_tousertype(tolua_S,1,0); + int a_OfsX = ((int) tolua_tonumber(tolua_S,2,0)); + int a_OfsY = ((int) tolua_tonumber(tolua_S,3,0)); + int a_OfsZ = ((int) tolua_tonumber(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Move'", NULL); +#endif + { + self->Move(a_OfsX,a_OfsY,a_OfsZ); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'Move'.",&tolua_err); + return 0; +#endif } #endif //#ifndef TOLUA_DISABLE @@ -23349,12 +23583,21 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"new",tolua_AllToLua_cCuboid_new02); tolua_function(tolua_S,"new_local",tolua_AllToLua_cCuboid_new02_local); tolua_function(tolua_S,".call",tolua_AllToLua_cCuboid_new02_local); + tolua_function(tolua_S,"new",tolua_AllToLua_cCuboid_new03); + tolua_function(tolua_S,"new_local",tolua_AllToLua_cCuboid_new03_local); + tolua_function(tolua_S,".call",tolua_AllToLua_cCuboid_new03_local); + tolua_function(tolua_S,"new",tolua_AllToLua_cCuboid_new04); + tolua_function(tolua_S,"new_local",tolua_AllToLua_cCuboid_new04_local); + tolua_function(tolua_S,".call",tolua_AllToLua_cCuboid_new04_local); tolua_function(tolua_S,"Sort",tolua_AllToLua_cCuboid_Sort00); tolua_function(tolua_S,"DifX",tolua_AllToLua_cCuboid_DifX00); tolua_function(tolua_S,"DifY",tolua_AllToLua_cCuboid_DifY00); tolua_function(tolua_S,"DifZ",tolua_AllToLua_cCuboid_DifZ00); + tolua_function(tolua_S,"DoesIntersect",tolua_AllToLua_cCuboid_DoesIntersect00); tolua_function(tolua_S,"IsInside",tolua_AllToLua_cCuboid_IsInside00); tolua_function(tolua_S,"IsInside",tolua_AllToLua_cCuboid_IsInside01); + tolua_function(tolua_S,"IsInside",tolua_AllToLua_cCuboid_IsInside02); + tolua_function(tolua_S,"Move",tolua_AllToLua_cCuboid_Move00); tolua_endmodule(tolua_S); #ifdef __cplusplus tolua_cclass(tolua_S,"cTracer","cTracer","",tolua_collect_cTracer); diff --git a/source/Bindings.h b/source/Bindings.h index 0dfcea988..803b2b8ce 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 03/29/13 17:37:21. +** Generated automatically by tolua++-1.0.92 on 03/29/13 20:28:24. */ /* Exported function */ diff --git a/source/Cuboid.cpp b/source/Cuboid.cpp index e50ea1faf..54dd1f1a4 100644 --- a/source/Cuboid.cpp +++ b/source/Cuboid.cpp @@ -7,7 +7,24 @@ -void cCuboid::Sort() +/// Returns true if the two specified intervals have a non-empty union +static bool DoIntervalsIntersect(int a_Min1, int a_Max1, int a_Min2, int a_Max2) +{ + return ( + ((a_Min1 >= a_Min2) && (a_Min1 <= a_Max2)) || // Start of first interval is within the second interval + ((a_Max1 >= a_Min2) && (a_Max1 <= a_Max2)) || // End of first interval is within the second interval + ((a_Min2 >= a_Min2) && (a_Min2 <= a_Max2)) // Start of second interval is within the first interval + ); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cCuboid: + +void cCuboid::Sort(void) { if (p1.x > p2.x) { @@ -26,3 +43,32 @@ void cCuboid::Sort() + +bool cCuboid::DoesIntersect(const cCuboid & a_Other) const +{ + // In order for cuboids to intersect, each of their coord intervals need to intersect + return ( + DoIntervalsIntersect(p1.x, p2.x, a_Other.p1.x, a_Other.p2.x) && + DoIntervalsIntersect(p1.y, p2.y, a_Other.p1.y, a_Other.p2.y) && + DoIntervalsIntersect(p1.z, p2.z, a_Other.p1.z, a_Other.p2.z) + ); +} + + + + + +void cCuboid::Move(int a_OfsX, int a_OfsY, int a_OfsZ) +{ + p1.x += a_OfsX; + p1.y += a_OfsY; + p1.z += a_OfsZ; + p2.x += a_OfsX; + p2.y += a_OfsY; + p2.z += a_OfsZ; +} + + + + + diff --git a/source/Cuboid.h b/source/Cuboid.h index 4032b66fb..4b0a76a34 100644 --- a/source/Cuboid.h +++ b/source/Cuboid.h @@ -18,12 +18,17 @@ public: cCuboid(void) {} cCuboid(const cCuboid & a_Cuboid ) : p1(a_Cuboid.p1), p2(a_Cuboid.p2) {} cCuboid(const Vector3i & a_p1, const 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) {} + 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) {} void Sort(void); int DifX(void) const { return p2.x - p1.x; } int DifY(void) const { return p2.y - p1.y; } int DifZ(void) const { return p2.z - p1.z; } + + /// Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. + bool DoesIntersect(const cCuboid & a_Other) const; bool IsInside(const Vector3i & v) const { @@ -34,6 +39,15 @@ 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( const Vector3d & v ) const { return ( @@ -42,6 +56,9 @@ public: (v.z >= p1.z) && (v.z <= p2.z) ); } + + /// Moves the cuboid by the specified offsets in each direction + void Move(int a_OfsX, int a_OfsY, int a_OfsZ); } ; // tolua_end |