summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-06-12 07:57:47 +0200
committerGitHub <noreply@github.com>2016-06-12 07:57:47 +0200
commitb403ad4d68eb1e730d5b514d3bfceea0de932bfa (patch)
tree2c332eef23ae5eb816d08786fb2f87535b289ca5 /src
parentMerge pull request #3225 from cuberite/FixAutoAPI (diff)
parentNormalized Vector3 API to use the same capitalization as all else. (diff)
downloadcuberite-b403ad4d68eb1e730d5b514d3bfceea0de932bfa.tar
cuberite-b403ad4d68eb1e730d5b514d3bfceea0de932bfa.tar.gz
cuberite-b403ad4d68eb1e730d5b514d3bfceea0de932bfa.tar.bz2
cuberite-b403ad4d68eb1e730d5b514d3bfceea0de932bfa.tar.lz
cuberite-b403ad4d68eb1e730d5b514d3bfceea0de932bfa.tar.xz
cuberite-b403ad4d68eb1e730d5b514d3bfceea0de932bfa.tar.zst
cuberite-b403ad4d68eb1e730d5b514d3bfceea0de932bfa.zip
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/DeprecatedBindings.cpp58
-rw-r--r--src/Generating/Trees.cpp4
-rw-r--r--src/Vector3.h13
3 files changed, 67 insertions, 8 deletions
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp
index 25fba5d9d..0ffc58cbb 100644
--- a/src/Bindings/DeprecatedBindings.cpp
+++ b/src/Bindings/DeprecatedBindings.cpp
@@ -340,6 +340,49 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
+template <typename T>
+int tolua_Vector3_Abs(lua_State * a_LuaState)
+{
+ // Retrieve the params, including self:
+ cLuaState L(a_LuaState);
+ Vector3<T> * self;
+ if (!L.GetStackValues(1, self))
+ {
+ tolua_error(a_LuaState, "invalid 'self' in function 'Vector3<T>:Abs'", nullptr);
+ return 0;
+ }
+
+ // Absolutize the vector:
+ self->Abs();
+ return 0;
+}
+
+
+
+
+
+template <typename T>
+int tolua_Vector3_Clamp(lua_State * a_LuaState)
+{
+ // Retrieve the params, including self:
+ cLuaState L(a_LuaState);
+ Vector3<T> * self;
+ T min, max;
+ if (!L.GetStackValues(1, self, min, max))
+ {
+ tolua_error(a_LuaState, "invalid parameters for function 'Vector3<T>:Clamp', expected a Vector3 and two numbers", nullptr);
+ return 0;
+ }
+
+ // Clamp the vector:
+ self->Clamp(min, max);
+ return 0;
+}
+
+
+
+
+
void DeprecatedBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, nullptr);
@@ -359,6 +402,21 @@ void DeprecatedBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "Vector3i");
+ tolua_function(tolua_S,"abs", tolua_Vector3_Abs<int>);
+ tolua_function(tolua_S,"clamp", tolua_Vector3_Clamp<int>);
+ tolua_endmodule(tolua_S);
+
+ tolua_beginmodule(tolua_S, "Vector3f");
+ tolua_function(tolua_S,"abs", tolua_Vector3_Abs<float>);
+ tolua_function(tolua_S,"clamp", tolua_Vector3_Clamp<float>);
+ tolua_endmodule(tolua_S);
+
+ tolua_beginmodule(tolua_S, "Vector3d");
+ tolua_function(tolua_S,"abs", tolua_Vector3_Abs<double>);
+ tolua_function(tolua_S,"clamp", tolua_Vector3_Clamp<double>);
+ tolua_endmodule(tolua_S);
+
tolua_endmodule(tolua_S);
}
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index 9cde11877..c185f54d9 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -445,7 +445,7 @@ void GetLargeAppleTreeBranch(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Bra
return;
}
Direction -= a_Direction;
- Direction.clamp(-1.0, 1.0);
+ Direction.Clamp(-1.0, 1.0);
a_LogBlocks.push_back(sSetBlock(FloorC(CurrentPos.x), FloorC(CurrentPos.y), FloorC(CurrentPos.z), E_BLOCK_LOG, GetLogMetaFromDirection(E_META_LOG_APPLE, Direction)));
}
}
@@ -456,7 +456,7 @@ void GetLargeAppleTreeBranch(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Bra
NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction)
{
- a_Direction.abs();
+ a_Direction.Abs();
if ((a_Direction.y > a_Direction.x) && (a_Direction.y > a_Direction.z))
{
diff --git a/src/Vector3.h b/src/Vector3.h
index 19ab0b021..4fa9ff46c 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -107,19 +107,20 @@ public:
return x * a_Rhs.x + y * a_Rhs.y + z * a_Rhs.z;
}
- inline void abs()
+ /** Updates each coord to its absolute value */
+ inline void Abs()
{
x = (x < 0) ? -x : x;
y = (y < 0) ? -y : y;
z = (z < 0) ? -z : z;
}
- // We can't use a capital letter, because we wouldn't be able to call the normal Clamp function.
- inline void clamp(T a_Min, T a_Max)
+ /** Clamps each coord into the specified range. */
+ inline void Clamp(T a_Min, T a_Max)
{
- x = Clamp(x, a_Min, a_Max);
- y = Clamp(y, a_Min, a_Max);
- z = Clamp(z, a_Min, a_Max);
+ x = ::Clamp(x, a_Min, a_Max);
+ y = ::Clamp(y, a_Min, a_Max);
+ z = ::Clamp(z, a_Min, a_Max);
}
inline Vector3<T> Cross(const Vector3<T> & a_Rhs) const