summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-03-12 17:59:10 +0100
committerTycho <work.tycho+git@gmail.com>2014-03-12 17:59:10 +0100
commit3caa4a38b9a60afdda0e76cfb267c49ffac1063c (patch)
tree89bd29d89d6892a94137ebf4829dfe6a4ae3c450 /src
parentFixed comments an assert (diff)
parentFixed missing comment terminator. (diff)
downloadcuberite-3caa4a38b9a60afdda0e76cfb267c49ffac1063c.tar
cuberite-3caa4a38b9a60afdda0e76cfb267c49ffac1063c.tar.gz
cuberite-3caa4a38b9a60afdda0e76cfb267c49ffac1063c.tar.bz2
cuberite-3caa4a38b9a60afdda0e76cfb267c49ffac1063c.tar.lz
cuberite-3caa4a38b9a60afdda0e76cfb267c49ffac1063c.tar.xz
cuberite-3caa4a38b9a60afdda0e76cfb267c49ffac1063c.tar.zst
cuberite-3caa4a38b9a60afdda0e76cfb267c49ffac1063c.zip
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/AllToLua.pkg11
-rw-r--r--src/Bindings/LuaState.cpp14
-rw-r--r--src/Bindings/LuaState.h10
-rw-r--r--src/Bindings/PluginLua.cpp1
-rw-r--r--src/BlockArea.cpp19
-rw-r--r--src/BlockArea.h9
-rw-r--r--src/BoundingBox.h2
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/ChunkDef.h2
-rw-r--r--src/ClientHandle.cpp3
-rw-r--r--src/ClientHandle.h2
-rw-r--r--src/Cuboid.h3
-rw-r--r--src/Entities/Entity.cpp2
-rw-r--r--src/Entities/Entity.h4
-rw-r--r--src/Entities/Player.cpp1
-rw-r--r--src/Entities/ProjectileEntity.cpp26
-rw-r--r--src/Entities/ProjectileEntity.h1
-rw-r--r--src/Generating/PieceGenerator.cpp4
-rw-r--r--src/Globals.h8
-rw-r--r--src/LineBlockTracer.cpp2
-rw-r--r--src/Matrix4.h224
-rw-r--r--src/Matrix4f.cpp4
-rw-r--r--src/Matrix4f.h225
-rw-r--r--src/Mobs/Bat.cpp2
-rw-r--r--src/Mobs/Squid.cpp2
-rw-r--r--src/Scoreboard.h2
-rw-r--r--src/Server.cpp2
-rw-r--r--src/Simulator/Simulator.cpp1
-rw-r--r--src/Simulator/Simulator.h2
-rw-r--r--src/Tracer.cpp4
-rw-r--r--src/Tracer.h3
-rw-r--r--src/Vector3.h286
-rw-r--r--src/Vector3d.cpp77
-rw-r--r--src/Vector3d.h81
-rw-r--r--src/Vector3f.cpp34
-rw-r--r--src/Vector3f.h47
-rw-r--r--src/Vector3i.cpp58
-rw-r--r--src/Vector3i.h68
-rw-r--r--src/WebAdmin.cpp1
-rw-r--r--src/World.cpp1
-rw-r--r--src/World.h3
-rw-r--r--src/WorldStorage/SchematicFileSerializer.cpp23
-rw-r--r--src/WorldStorage/WSSCompact.h2
43 files changed, 639 insertions, 642 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 2676281f9..1cd7c74f8 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -11,6 +11,7 @@ typedef unsigned int UInt32;
typedef unsigned short UInt16;
+$cfile "../Vector3.h"
$cfile "../ChunkDef.h"
$cfile "../BiomeDef.h"
@@ -62,10 +63,6 @@ $cfile "../BlockEntities/MobHeadEntity.h"
$cfile "../BlockEntities/FlowerPotEntity.h"
$cfile "../WebAdmin.h"
$cfile "../Root.h"
-$cfile "../Vector3f.h"
-$cfile "../Vector3d.h"
-$cfile "../Vector3i.h"
-$cfile "../Matrix4f.h"
$cfile "../Cuboid.h"
$cfile "../BoundingBox.h"
$cfile "../Tracer.h"
@@ -97,4 +94,10 @@ typedef unsigned char Byte;
+// Aliases
+$renaming Vector3<double> @ Vector3d
+$renaming Vector3<float> @ Vector3f
+$renaming Vector3<int> @ Vector3i
+
+
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index aa6ee05b3..dfc428bbc 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -94,12 +94,20 @@ void cLuaState::Create(void)
}
m_LuaState = lua_open();
luaL_openlibs(m_LuaState);
+ m_IsOwned = true;
+}
+
+
+
+
+
+void cLuaState::RegisterAPILibs(void)
+{
tolua_AllToLua_open(m_LuaState);
ManualBindings::Bind(m_LuaState);
DeprecatedBindings::Bind(m_LuaState);
luaopen_lsqlite3(m_LuaState);
luaopen_lxp(m_LuaState);
- m_IsOwned = true;
}
@@ -734,10 +742,6 @@ void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
{
a_Value.assign(data, len);
}
- else
- {
- a_Value.clear();
- }
}
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 4a7a6fadb..73f9629cb 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -29,6 +29,8 @@ extern "C"
#include "lua/src/lauxlib.h"
}
+#include "../Vector3.h"
+
@@ -52,7 +54,6 @@ class cWebAdmin;
struct HTTPTemplateRequest;
class cTNTEntity;
class cCreeper;
-class Vector3i;
class cHopperEntity;
class cBlockEntity;
@@ -139,9 +140,14 @@ public:
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
operator lua_State * (void) { return m_LuaState; }
- /** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor */
+ /** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor.
+ The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as
+ lite-config as well), use RegisterAPILibs() to do that. */
void Create(void);
+ /** Registers all the API libraries that MCS provides into m_LuaState. */
+ void RegisterAPILibs(void);
+
/** Closes the m_LuaState, if not closed already */
void Close(void);
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 45c8216be..cccbc3c93 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -75,6 +75,7 @@ bool cPluginLua::Initialize(void)
if (!m_LuaState.IsValid())
{
m_LuaState.Create();
+ m_LuaState.RegisterAPILibs();
// Inject the identification global variables into the state:
lua_pushlightuserdata(m_LuaState, this);
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index d07ef747a..406e18a3b 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -168,6 +168,7 @@ cBlockArea::cBlockArea(void) :
m_SizeX(0),
m_SizeY(0),
m_SizeZ(0),
+ m_WEOffset(0, 0, 0),
m_BlockTypes(NULL),
m_BlockMetas(NULL),
m_BlockLight(NULL),
@@ -254,6 +255,24 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
+void cBlockArea::SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ)
+{
+ m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ);
+}
+
+
+
+
+
+void cBlockArea::SetWEOffset(const Vector3i & a_Offset)
+{
+ m_WEOffset.Set(a_Offset.x, a_Offset.y, a_Offset.z);
+}
+
+
+
+
+
void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
{
m_OriginX = a_OriginX;
diff --git a/src/BlockArea.h b/src/BlockArea.h
index 0703f195e..e0e8fe972 100644
--- a/src/BlockArea.h
+++ b/src/BlockArea.h
@@ -13,13 +13,13 @@
#pragma once
#include "ForEachChunkProvider.h"
+#include "Vector3.h"
// fwd:
class cCuboid;
-class Vector3i;
@@ -209,6 +209,8 @@ public:
void SetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight);
void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight);
void SetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight);
+ void SetWEOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ);
+ void SetWEOffset (const Vector3i & a_Offset);
// Getters:
BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const;
@@ -219,6 +221,7 @@ public:
NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const;
NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
+ const Vector3i & GetWEOffset (void) const {return m_WEOffset;}
void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
@@ -299,6 +302,10 @@ protected:
int m_SizeY;
int m_SizeZ;
+ /** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin.
+ cBlockArea doesn't use this value in any way. */
+ Vector3i m_WEOffset;
+
BLOCKTYPE * m_BlockTypes;
NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access
NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access
diff --git a/src/BoundingBox.h b/src/BoundingBox.h
index 9ac5f11b8..a7c6c3eea 100644
--- a/src/BoundingBox.h
+++ b/src/BoundingBox.h
@@ -8,7 +8,7 @@
#pragma once
-#include "Vector3d.h"
+#include "Vector3.h"
#include "Defines.h"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c2de26664..0f8700692 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -62,7 +62,6 @@ if (NOT MSVC)
Inventory.h
Item.h
ItemGrid.h
- Matrix4f.h
Mobs/Monster.h
OSSupport/File.h
Root.h
@@ -70,9 +69,7 @@ if (NOT MSVC)
StringUtils.h
Tracer.h
UI/Window.h
- Vector3d.h
- Vector3f.h
- Vector3i.h
+ Vector3.h
WebAdmin.h
World.h
)
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index 61ad49ad0..9c7753820 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -9,7 +9,7 @@
#pragma once
-#include "Vector3i.h"
+#include "Vector3.h"
#include "BiomeDef.h"
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index df728e83b..7ab637926 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -22,9 +22,6 @@
#include "Blocks/BlockSlab.h"
#include "Blocks/ChunkInterface.h"
-#include "Vector3f.h"
-#include "Vector3d.h"
-
#include "Root.h"
#include "Authenticator.h"
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 72b1c7d09..8366caa16 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -12,7 +12,7 @@
#define CCLIENTHANDLE_H_INCLUDED
#include "Defines.h"
-#include "Vector3d.h"
+#include "Vector3.h"
#include "OSSupport/SocketThreads.h"
#include "ChunkDef.h"
#include "ByteBuffer.h"
diff --git a/src/Cuboid.h b/src/Cuboid.h
index b95517f69..b90a09e05 100644
--- a/src/Cuboid.h
+++ b/src/Cuboid.h
@@ -1,8 +1,7 @@
#pragma once
-#include "Vector3i.h"
-#include "Vector3d.h"
+#include "Vector3.h"
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 96e8c15a5..0750ae05e 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -4,7 +4,7 @@
#include "../World.h"
#include "../Server.h"
#include "../Root.h"
-#include "../Matrix4f.h"
+#include "../Matrix4.h"
#include "../ClientHandle.h"
#include "../Chunk.h"
#include "../Simulator/FluidSimulator.h"
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index b3b1cef83..a73565de7 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -2,9 +2,7 @@
#pragma once
#include "../Item.h"
-#include "../Vector3d.h"
-#include "../Vector3f.h"
-#include "../Vector3i.h"
+#include "../Vector3.h"
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index ccdd151f3..440d30595 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -14,6 +14,7 @@
#include "../OSSupport/Timer.h"
#include "../Chunk.h"
#include "../Items/ItemHandler.h"
+#include "../Vector3.h"
#include "inifile/iniFile.h"
#include "json/json.h"
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index 12d2025ec..f4ab825f2 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -663,8 +663,6 @@ cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, do
void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace)
{
- // TODO: Apply damage to certain mobs (blaze etc.) and anger all mobs
-
Destroy();
}
@@ -672,6 +670,30 @@ void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFac
+void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
+{
+ int TotalDamage = 0;
+ if (a_EntityHit.IsMob())
+ {
+ cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType();
+ if (MobType == cMonster::mtBlaze)
+ {
+ TotalDamage = 3;
+ }
+ else if (MobType == cMonster::mtEnderDragon)
+ {
+ TotalDamage = 1;
+ }
+ }
+ a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1);
+
+ Destroy(true);
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cBottleOEnchantingEntity :
diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h
index fac592d16..efb7ae783 100644
--- a/src/Entities/ProjectileEntity.h
+++ b/src/Entities/ProjectileEntity.h
@@ -259,6 +259,7 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
+ virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
// tolua_begin
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
index 8fcc14389..50bfe65fe 100644
--- a/src/Generating/PieceGenerator.cpp
+++ b/src/Generating/PieceGenerator.cpp
@@ -376,8 +376,8 @@ bool cPieceGenerator::TryPlacePieceAtConnector(
// You need DirectionRotationTable[rot1][rot2] CCW turns to connect rot1 to rot2 (they are opposite)
static const int DirectionRotationTable[6][6] =
{
- /* YM, YP, ZM, ZP, XM, XP
- YM */ { 0, 0, 0, 0, 0, 0},
+ /* YM, YP, ZM, ZP, XM, XP */
+ /* YM */ { 0, 0, 0, 0, 0, 0},
/* YP */ { 0, 0, 0, 0, 0, 0},
/* ZM */ { 0, 0, 2, 0, 1, 3},
/* ZP */ { 0, 0, 0, 2, 3, 1},
diff --git a/src/Globals.h b/src/Globals.h
index 6661aa476..5ced0cc39 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -261,6 +261,14 @@ T Clamp(T a_Value, T a_Min, T a_Max)
+#ifndef TOLUA_TEMPLATE_BIND
+#define TOLUA_TEMPLATE_BIND(x)
+#endif
+
+
+
+
+
// Common headers (part 2, with macros):
#include "ChunkDef.h"
#include "BiomeDef.h"
diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp
index da1c7f2fd..f4f29e833 100644
--- a/src/LineBlockTracer.cpp
+++ b/src/LineBlockTracer.cpp
@@ -5,7 +5,7 @@
#include "Globals.h"
#include "LineBlockTracer.h"
-#include "Vector3d.h"
+#include "Vector3.h"
#include "World.h"
#include "Chunk.h"
diff --git a/src/Matrix4.h b/src/Matrix4.h
new file mode 100644
index 000000000..456677f0f
--- /dev/null
+++ b/src/Matrix4.h
@@ -0,0 +1,224 @@
+
+#pragma once
+
+
+
+#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC)
+#include <math.h>
+
+
+
+
+
+template <typename T>
+// tolua_begin
+class Matrix4
+{
+
+ TOLUA_TEMPLATE_BIND((T, float, double))
+
+ // tolua_end
+
+public:
+
+ T cell[16];
+
+ // tolua_begin
+
+ inline Matrix4(void)
+ {
+ Identity();
+ }
+
+ inline Matrix4(const Matrix4 & a_Rhs)
+ {
+ *this = a_Rhs;
+ }
+
+ inline Matrix4 & operator = (const Matrix4 & a_Rhs)
+ {
+ for (unsigned int i = 0; i < 16; ++i)
+ {
+ cell[i] = a_Rhs.cell[i];
+ }
+ return *this;
+ }
+
+ inline T & operator [] (int a_N)
+ {
+ ASSERT(a_N < 16);
+ return cell[a_N];
+ }
+
+ inline void Identity()
+ {
+ cell[1] = cell[2] = cell[3] = cell[4] = 0;
+ cell[6] = cell[7] = cell[8] = cell[9] = 0;
+ cell[11] = cell[12] = cell[13] = cell[14] = 0;
+
+ cell[0] = cell[5] = cell[10] = cell[15] = 1;
+ }
+
+ inline void Init(const Vector3<T> & a_Pos, T a_RX, T a_RY, T a_RZ)
+ {
+ Matrix4<T> t;
+ t.RotateX(a_RZ);
+ RotateY(a_RY);
+ Concatenate(t);
+ t.RotateZ(a_RX);
+ Concatenate(t);
+ Translate(a_Pos);
+ }
+
+ inline void RotateX(T a_RX)
+ {
+ T sx = (T) sin(a_RX * M_PI / 180);
+ T cx = (T) cos(a_RX * M_PI / 180);
+
+ Identity();
+
+ cell[5] = cx; cell[6] = sx;
+ cell[9] = -sx; cell[10] = cx;
+ }
+
+ inline void RotateY(T a_RY)
+ {
+ T sy = (T) sin(a_RY * M_PI / 180);
+ T cy = (T) cos(a_RY * M_PI / 180);
+
+ Identity();
+
+ cell[0] = cy; cell[2] = -sy;
+ cell[8] = sy; cell[10] = cy;
+ }
+
+ inline void RotateZ(T a_RZ)
+ {
+ T sz = (T) sin(a_RZ * M_PI / 180);
+ T cz = (T) cos(a_RZ * M_PI / 180);
+
+ Identity();
+
+ cell[0] = cz; cell[1] = sz;
+ cell[4] = -sz; cell[5] = cz;
+ }
+
+ inline void Translate(const Vector3<T> & a_Pos)
+ {
+ cell[3] += a_Pos.x;
+ cell[7] += a_Pos.y;
+ cell[11] += a_Pos.z;
+ }
+
+ inline void SetTranslation(const Vector3<T> & a_Pos)
+ {
+ cell[3] = a_Pos.x;
+ cell[7] = a_Pos.y;
+ cell[11] = a_Pos.z;
+ }
+
+ inline void Concatenate(const Matrix4 & m2)
+ {
+ Matrix4 res;
+
+ for (unsigned int c = 0; c < 4; ++c)
+ {
+ for (unsigned int r = 0; r < 4; ++r)
+ {
+ res.cell[r * 4 + c] = (
+ cell[r * 4 + 0] * m2.cell[c + 0] +
+ cell[r * 4 + 1] * m2.cell[c + 4] +
+ cell[r * 4 + 2] * m2.cell[c + 8] +
+ cell[r * 4 + 3] * m2.cell[c + 12]
+ );
+ }
+ }
+
+ *this = res;
+ }
+
+ inline Vector3<T> Transform(const Vector3<T> & v) const
+ {
+ T x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3];
+ T y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7];
+ T z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11];
+
+ return Vector3<T>(x, y, z);
+ }
+
+ inline void Invert(void)
+ {
+ Matrix4 t;
+
+ T tx = -cell[3];
+ T ty = -cell[7];
+ T tz = -cell[11];
+
+ for (unsigned int h = 0; h < 3; ++h)
+ {
+ for (unsigned int v = 0; v < 3; ++v)
+ {
+ t.cell[h + v * 4] = cell[v + h * 4];
+ }
+ }
+
+ for (unsigned int i = 0; i < 11; ++i)
+ {
+ cell[i] = t.cell[i];
+ }
+
+ cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2];
+ cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6];
+ cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10];
+ }
+
+ inline Vector3<T> GetXColumn(void) const
+ {
+ return Vector3<T>(cell[0], cell[1], cell[2]);
+ }
+
+ inline Vector3<T> GetYColumn(void) const
+ {
+ return Vector3<T>(cell[4], cell[5], cell[6]);
+ }
+
+ inline Vector3<T> GetZColumn(void) const
+ {
+ return Vector3<T>(cell[8], cell[9], cell[10]);
+ }
+
+ inline void SetXColumn(const Vector3<T> & a_X)
+ {
+ cell[0] = a_X.x;
+ cell[1] = a_X.y;
+ cell[2] = a_X.z;
+ }
+
+ inline void SetYColumn(const Vector3<T> & a_Y)
+ {
+ cell[4] = a_Y.x;
+ cell[5] = a_Y.y;
+ cell[6] = a_Y.z;
+ }
+
+ inline void SetZColumn(const Vector3<T> & a_Z)
+ {
+ cell[8] = a_Z.x;
+ cell[9] = a_Z.y;
+ cell[10] = a_Z.z;
+ }
+};
+// tolua_end
+
+
+
+
+// tolua_begin
+typedef Matrix4<double> Matrix4d;
+typedef Matrix4<float> Matrix4f;
+// tolua_end
+
+
+
+
+
diff --git a/src/Matrix4f.cpp b/src/Matrix4f.cpp
deleted file mode 100644
index d0a407a99..000000000
--- a/src/Matrix4f.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-// _X: empty file??
diff --git a/src/Matrix4f.h b/src/Matrix4f.h
deleted file mode 100644
index 249c92f5f..000000000
--- a/src/Matrix4f.h
+++ /dev/null
@@ -1,225 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-#include "Vector3f.h"
-
-class Matrix4f
-{
-public:
- enum
- {
- TX=3,
- TY=7,
- TZ=11,
- D0=0, D1=5, D2=10, D3=15,
- SX=D0, SY=D1, SZ=D2,
- W=D3
- };
- Matrix4f() { Identity(); }
- float& operator [] ( int a_N ) { return cell[a_N]; }
- void Identity()
- {
- cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] =
- cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0;
- cell[D0] = cell[D1] = cell[D2] = cell[W] = 1;
- }
- void Init( Vector3f a_Pos, float a_RX, float a_RY, float a_RZ )
- {
- Matrix4f t;
- t.RotateX( a_RZ );
- RotateY( a_RY );
- Concatenate( t );
- t.RotateZ( a_RX );
- Concatenate( t );
- Translate( a_Pos );
- }
- void RotateX( float a_RX )
- {
- float sx = (float)sin( a_RX * M_PI / 180 );
- float cx = (float)cos( a_RX * M_PI / 180 );
- Identity();
- cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx;
- }
- void RotateY( float a_RY )
- {
- float sy = (float)sin( a_RY * M_PI / 180 );
- float cy = (float)cos( a_RY * M_PI / 180 );
- Identity ();
- cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy;
- }
- void RotateZ( float a_RZ )
- {
- float sz = (float)sin( a_RZ * M_PI / 180 );
- float cz = (float)cos( a_RZ * M_PI / 180 );
- Identity ();
- cell[0] = cz, cell[1] = sz, cell[4] = -sz, cell[5] = cz;
- }
- void Translate( Vector3f a_Pos ) { cell[TX] += a_Pos.x; cell[TY] += a_Pos.y; cell[TZ] += a_Pos.z; }
- void SetTranslation( Vector3f a_Pos ) { cell[TX] = a_Pos.x; cell[TY] = a_Pos.y; cell[TZ] = a_Pos.z; }
- void Concatenate( const Matrix4f& m2 )
- {
- Matrix4f res;
- int c;
- for ( c = 0; c < 4; c++ ) for ( int r = 0; r < 4; r++ )
- res.cell[r * 4 + c] = cell[r * 4] * m2.cell[c] +
- cell[r * 4 + 1] * m2.cell[c + 4] +
- cell[r * 4 + 2] * m2.cell[c + 8] +
- cell[r * 4 + 3] * m2.cell[c + 12];
- for ( c = 0; c < 16; c++ ) cell[c] = res.cell[c];
- }
- Vector3f Transform( const Vector3f& v ) const
- {
- float x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3];
- float y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7];
- float z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11];
- return Vector3f( x, y, z );
- }
- void Invert()
- {
- Matrix4f t;
- int h, i;
- float tx = -cell[3], ty = -cell[7], tz = -cell[11];
- for ( h = 0; h < 3; h++ ) for ( int v = 0; v < 3; v++ ) t.cell[h + v * 4] = cell[v + h * 4];
- for ( i = 0; i < 11; i++ ) cell[i] = t.cell[i];
- cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2];
- cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6];
- cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10];
- }
- Vector3f GetXColumn() { return Vector3f( cell[0], cell[1], cell[2] ); }
- Vector3f GetYColumn() { return Vector3f( cell[4], cell[5], cell[6] ); }
- Vector3f GetZColumn() { return Vector3f( cell[8], cell[9], cell[10] ); }
- void SetXColumn( const Vector3f & a_X )
- {
- cell[0] = a_X.x;
- cell[1] = a_X.y;
- cell[2] = a_X.z;
- }
- void SetYColumn( const Vector3f & a_Y )
- {
- cell[4] = a_Y.x;
- cell[5] = a_Y.y;
- cell[6] = a_Y.z;
- }
- void SetZColumn( const Vector3f & a_Z )
- {
- cell[8] = a_Z.x;
- cell[9] = a_Z.y;
- cell[10] = a_Z.z;
- }
- float cell[16];
-};
-
-
-
-
-
-class Matrix4d
-{
-public:
- enum
- {
- TX=3,
- TY=7,
- TZ=11,
- D0=0, D1=5, D2=10, D3=15,
- SX=D0, SY=D1, SZ=D2,
- W=D3
- };
- Matrix4d() { Identity(); }
- double& operator [] ( int a_N ) { return cell[a_N]; }
- void Identity()
- {
- cell[1] = cell[2] = cell[TX] = cell[4] = cell[6] = cell[TY] =
- cell[8] = cell[9] = cell[TZ] = cell[12] = cell[13] = cell[14] = 0;
- cell[D0] = cell[D1] = cell[D2] = cell[W] = 1;
- }
- void Init( Vector3f a_Pos, double a_RX, double a_RY, double a_RZ )
- {
- Matrix4d t;
- t.RotateX( a_RZ );
- RotateY( a_RY );
- Concatenate( t );
- t.RotateZ( a_RX );
- Concatenate( t );
- Translate( a_Pos );
- }
- void RotateX( double a_RX )
- {
- double sx = (double)sin( a_RX * M_PI / 180 );
- double cx = (double)cos( a_RX * M_PI / 180 );
- Identity();
- cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx;
- }
- void RotateY( double a_RY )
- {
- double sy = (double)sin( a_RY * M_PI / 180 );
- double cy = (double)cos( a_RY * M_PI / 180 );
- Identity ();
- cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy;
- }
- void RotateZ( double a_RZ )
- {
- double sz = (double)sin( a_RZ * M_PI / 180 );
- double cz = (double)cos( a_RZ * M_PI / 180 );
- Identity ();
- cell[0] = cz, cell[1] = sz, cell[4] = -sz, cell[5] = cz;
- }
- void Translate( Vector3d a_Pos ) { cell[TX] += a_Pos.x; cell[TY] += a_Pos.y; cell[TZ] += a_Pos.z; }
- void SetTranslation( Vector3d a_Pos ) { cell[TX] = a_Pos.x; cell[TY] = a_Pos.y; cell[TZ] = a_Pos.z; }
- void Concatenate( const Matrix4d & m2 )
- {
- Matrix4d res;
- int c;
- for ( c = 0; c < 4; c++ ) for ( int r = 0; r < 4; r++ )
- res.cell[r * 4 + c] = cell[r * 4] * m2.cell[c] +
- cell[r * 4 + 1] * m2.cell[c + 4] +
- cell[r * 4 + 2] * m2.cell[c + 8] +
- cell[r * 4 + 3] * m2.cell[c + 12];
- for ( c = 0; c < 16; c++ ) cell[c] = res.cell[c];
- }
- Vector3d Transform( const Vector3d & v ) const
- {
- double x = cell[0] * v.x + cell[1] * v.y + cell[2] * v.z + cell[3];
- double y = cell[4] * v.x + cell[5] * v.y + cell[6] * v.z + cell[7];
- double z = cell[8] * v.x + cell[9] * v.y + cell[10] * v.z + cell[11];
- return Vector3d( x, y, z );
- }
- void Invert()
- {
- Matrix4d t;
- int h, i;
- double tx = -cell[3], ty = -cell[7], tz = -cell[11];
- for ( h = 0; h < 3; h++ ) for ( int v = 0; v < 3; v++ ) t.cell[h + v * 4] = cell[v + h * 4];
- for ( i = 0; i < 11; i++ ) cell[i] = t.cell[i];
- cell[3] = tx * cell[0] + ty * cell[1] + tz * cell[2];
- cell[7] = tx * cell[4] + ty * cell[5] + tz * cell[6];
- cell[11] = tx * cell[8] + ty * cell[9] + tz * cell[10];
- }
- Vector3d GetXColumn() { return Vector3d( cell[0], cell[1], cell[2] ); }
- Vector3d GetYColumn() { return Vector3d( cell[4], cell[5], cell[6] ); }
- Vector3d GetZColumn() { return Vector3d( cell[8], cell[9], cell[10] ); }
- void SetXColumn( const Vector3d & a_X )
- {
- cell[0] = a_X.x;
- cell[1] = a_X.y;
- cell[2] = a_X.z;
- }
- void SetYColumn( const Vector3d & a_Y )
- {
- cell[4] = a_Y.x;
- cell[5] = a_Y.y;
- cell[6] = a_Y.z;
- }
- void SetZColumn( const Vector3d & a_Z )
- {
- cell[8] = a_Z.x;
- cell[9] = a_Z.y;
- cell[10] = a_Z.z;
- }
- double cell[16];
-} ;
-
-
-
-
diff --git a/src/Mobs/Bat.cpp b/src/Mobs/Bat.cpp
index b9c82996b..1417ddd9e 100644
--- a/src/Mobs/Bat.cpp
+++ b/src/Mobs/Bat.cpp
@@ -2,7 +2,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Bat.h"
-#include "../Vector3d.h"
+#include "../Vector3.h"
#include "../Chunk.h"
diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp
index ba9171b39..bd0e141a0 100644
--- a/src/Mobs/Squid.cpp
+++ b/src/Mobs/Squid.cpp
@@ -2,7 +2,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Squid.h"
-#include "../Vector3d.h"
+#include "../Vector3.h"
#include "../Chunk.h"
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index e22ecaeb1..2fae5e499 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -150,6 +150,8 @@ public:
/** Removes all registered players */
void Reset(void);
+ // tolua_begin
+
/** Returns the number of registered players */
unsigned int GetNumPlayers(void) const;
diff --git a/src/Server.cpp b/src/Server.cpp
index fcbcaa919..1b168ff20 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -24,7 +24,7 @@
#include "MersenneTwister.h"
#include "inifile/iniFile.h"
-#include "Vector3f.h"
+#include "Vector3.h"
#include <fstream>
#include <sstream>
diff --git a/src/Simulator/Simulator.cpp b/src/Simulator/Simulator.cpp
index 06fd0f858..0739f0187 100644
--- a/src/Simulator/Simulator.cpp
+++ b/src/Simulator/Simulator.cpp
@@ -3,7 +3,6 @@
#include "Simulator.h"
#include "../World.h"
-#include "../Vector3i.h"
#include "../BlockID.h"
#include "../Defines.h"
#include "../Chunk.h"
diff --git a/src/Simulator/Simulator.h b/src/Simulator/Simulator.h
index a25b7f1b6..a2e2a5742 100644
--- a/src/Simulator/Simulator.h
+++ b/src/Simulator/Simulator.h
@@ -1,7 +1,7 @@
#pragma once
-#include "../Vector3i.h"
+#include "../Vector3.h"
#include "inifile/iniFile.h"
diff --git a/src/Tracer.cpp b/src/Tracer.cpp
index 968a64439..6da6b2ad7 100644
--- a/src/Tracer.cpp
+++ b/src/Tracer.cpp
@@ -4,10 +4,6 @@
#include "Tracer.h"
#include "World.h"
-#include "Vector3f.h"
-#include "Vector3i.h"
-#include "Vector3d.h"
-
#include "Entities/Entity.h"
#ifndef _WIN32
diff --git a/src/Tracer.h b/src/Tracer.h
index 6c2ab6792..bdb080f0d 100644
--- a/src/Tracer.h
+++ b/src/Tracer.h
@@ -1,8 +1,7 @@
#pragma once
-#include "Vector3i.h"
-#include "Vector3f.h"
+#include "Vector3.h"
diff --git a/src/Vector3.h b/src/Vector3.h
new file mode 100644
index 000000000..b7a810fc5
--- /dev/null
+++ b/src/Vector3.h
@@ -0,0 +1,286 @@
+
+#pragma once
+
+
+
+#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC)
+#include <math.h>
+
+
+
+
+
+template <typename T>
+// tolua_begin
+class Vector3
+{
+
+ TOLUA_TEMPLATE_BIND((T, int, float, double))
+
+public:
+
+ T x, y, z;
+
+
+ inline Vector3(void) : x(0), y(0), z(0) {}
+ inline Vector3(T a_x, T a_y, T a_z) : x(a_x), y(a_y), z(a_z) {}
+
+
+ // Hardcoded copy constructors (tolua++ does not support function templates .. yet)
+ Vector3(const Vector3<float> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
+ Vector3(const Vector3<double> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
+ Vector3(const Vector3<int> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
+
+
+ // tolua_end
+ template <typename _T>
+ Vector3(const Vector3<_T> & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {}
+
+ template <typename _T>
+ Vector3(const Vector3<_T> * a_Rhs) : x(a_Rhs->x), y(a_Rhs->y), z(a_Rhs->z) {}
+ // tolua_begin
+
+
+ inline void Set(T a_x, T a_y, T a_z)
+ {
+ x = a_x;
+ y = a_y;
+ z = a_z;
+ }
+
+ inline void Normalize(void)
+ {
+ double Len = 1.0 / Length();
+
+ x *= Len;
+ y *= Len;
+ z *= Len;
+ }
+
+ inline Vector3<T> NormalizeCopy(void) const
+ {
+ double Len = 1.0 / Length();
+
+ return Vector3<T>(
+ x * Len,
+ y * Len,
+ z * Len
+ );
+ }
+
+ inline void NormalizeCopy(Vector3<T> & a_Rhs) const
+ {
+ double Len = 1.0 / Length();
+
+ a_Rhs.Set(
+ x * Len,
+ y * Len,
+ z * Len
+ );
+ }
+
+ inline double Length(void) const
+ {
+ return sqrt((double)(x * x + y * y + z * z));
+ }
+
+ inline double SqrLength(void) const
+ {
+ return x * x + y * y + z * z;
+ }
+
+ inline T Dot(const Vector3<T> & a_Rhs) const
+ {
+ return x * a_Rhs.x + y * a_Rhs.y + z * a_Rhs.z;
+ }
+
+ inline Vector3<T> Cross(const Vector3<T> & a_Rhs) const
+ {
+ return Vector3<T>(
+ y * a_Rhs.z - z * a_Rhs.y,
+ z * a_Rhs.x - x * a_Rhs.z,
+ x * a_Rhs.y - y * a_Rhs.x
+ );
+ }
+
+ inline bool Equals(const Vector3<T> & a_Rhs) const
+ {
+ return x == a_Rhs.x && y == a_Rhs.y && z == a_Rhs.z;
+ }
+
+ inline bool operator < (const Vector3<T> & a_Rhs)
+ {
+ // return (x < a_Rhs.x) && (y < a_Rhs.y) && (z < a_Rhs.z); ?
+ return (x < a_Rhs.x) || (x == a_Rhs.x && y < a_Rhs.y) || (x == a_Rhs.x && y == a_Rhs.y && z < a_Rhs.z);
+ }
+
+ inline void Move(T a_X, T a_Y, T a_Z)
+ {
+ x += a_X;
+ y += a_Y;
+ z += a_Z;
+ }
+
+ // tolua_end
+
+ inline void operator += (const Vector3<T> & a_Rhs)
+ {
+ x += a_Rhs.x;
+ y += a_Rhs.y;
+ z += a_Rhs.z;
+ }
+
+ inline void operator -= (const Vector3<T> & a_Rhs)
+ {
+ x -= a_Rhs.x;
+ y -= a_Rhs.y;
+ z -= a_Rhs.z;
+ }
+
+ inline void operator *= (const Vector3<T> & a_Rhs)
+ {
+ x *= a_Rhs.x;
+ y *= a_Rhs.y;
+ z *= a_Rhs.z;
+ }
+
+ inline void operator *= (T a_v)
+ {
+ x *= a_v;
+ y *= a_v;
+ z *= a_v;
+ }
+
+ // tolua_begin
+
+ inline Vector3<T> operator + (const Vector3<T>& a_Rhs) const
+ {
+ return Vector3<T>(
+ x + a_Rhs.x,
+ y + a_Rhs.y,
+ z + a_Rhs.z
+ );
+ }
+
+ inline Vector3<T> operator - (const Vector3<T>& a_Rhs) const
+ {
+ return Vector3<T>(
+ x - a_Rhs.x,
+ y - a_Rhs.y,
+ z - a_Rhs.z
+ );
+ }
+
+ inline Vector3<T> operator * (const Vector3<T>& a_Rhs) const
+ {
+ return Vector3<T>(
+ x * a_Rhs.x,
+ y * a_Rhs.y,
+ z * a_Rhs.z
+ );
+ }
+
+ inline Vector3<T> operator * (T a_v) const
+ {
+ return Vector3<T>(
+ x * a_v,
+ y * a_v,
+ z * a_v
+ );
+ }
+
+ inline Vector3<T> operator / (T a_v) const
+ {
+ return Vector3<T>(
+ x / a_v,
+ y / a_v,
+ z / a_v
+ );
+ }
+
+ /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord.
+ The result satisfies the following equation:
+ (*this + Result * (a_OtherEnd - *this)).z = a_Z
+ If the line is too close to being parallel, this function returns NO_INTERSECTION
+ */
+ inline double LineCoeffToXYPlane(const Vector3<T> & a_OtherEnd, T a_Z) const
+ {
+ if (abs(z - a_OtherEnd.z) < EPS)
+ {
+ return NO_INTERSECTION;
+ }
+
+ return (a_Z - z) / (a_OtherEnd.z - z);
+ }
+
+ /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord.
+ The result satisfies the following equation:
+ (*this + Result * (a_OtherEnd - *this)).y = a_Y
+ If the line is too close to being parallel, this function returns NO_INTERSECTION
+ */
+ inline double LineCoeffToXZPlane(const Vector3<T> & a_OtherEnd, T a_Y) const
+ {
+ if (abs(y - a_OtherEnd.y) < EPS)
+ {
+ return NO_INTERSECTION;
+ }
+
+ return (a_Y - y) / (a_OtherEnd.y - y);
+ }
+
+ /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord.
+ The result satisfies the following equation:
+ (*this + Result * (a_OtherEnd - *this)).x = a_X
+ If the line is too close to being parallel, this function returns NO_INTERSECTION
+ */
+ inline double LineCoeffToYZPlane(const Vector3<T> & a_OtherEnd, T a_X) const
+ {
+ if (abs(x - a_OtherEnd.x) < EPS)
+ {
+ return NO_INTERSECTION;
+ }
+
+ return (a_X - x) / (a_OtherEnd.x - x);
+ }
+
+ /** The max difference between two coords for which the coords are assumed equal. */
+ static const double EPS;
+
+ /** Return value of LineCoeffToPlane() if the line is parallel to the plane. */
+ static const double NO_INTERSECTION;
+
+};
+// tolua_end
+
+
+
+
+
+template <typename T>
+const double Vector3<T>::EPS = 0.000001;
+
+template <typename T>
+const double Vector3<T>::NO_INTERSECTION = 1e70;
+
+
+
+
+
+// tolua_begin
+typedef Vector3<double> Vector3d;
+typedef Vector3<float> Vector3f;
+typedef Vector3<int> Vector3i;
+// tolua_end
+
+
+
+
+
+typedef std::list<Vector3i> cVector3iList;
+typedef std::vector<Vector3i> cVector3iArray;
+
+
+
+
+
+
diff --git a/src/Vector3d.cpp b/src/Vector3d.cpp
deleted file mode 100644
index 96ebebab5..000000000
--- a/src/Vector3d.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "Vector3d.h"
-#include "Vector3f.h"
-
-
-
-
-
-const double Vector3d::EPS = 0.000001; ///< The max difference between two coords for which the coords are assumed equal
-const double Vector3d::NO_INTERSECTION = 1e70; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane
-
-
-
-
-
-Vector3d::Vector3d(const Vector3f & v) :
- x(v.x),
- y(v.y),
- z(v.z)
-{
-}
-
-
-
-
-
-Vector3d::Vector3d(const Vector3f * v) :
- x(v->x),
- y(v->y),
- z(v->z)
-{
-}
-
-
-
-
-
-double Vector3d::LineCoeffToXYPlane(const Vector3d & a_OtherEnd, double a_Z) const
-{
- if (abs(z - a_OtherEnd.z) < EPS)
- {
- return NO_INTERSECTION;
- }
- return (a_Z - z) / (a_OtherEnd.z - z);
-}
-
-
-
-
-
-double Vector3d::LineCoeffToXZPlane(const Vector3d & a_OtherEnd, double a_Y) const
-{
- if (abs(y - a_OtherEnd.y) < EPS)
- {
- return NO_INTERSECTION;
- }
- return (a_Y - y) / (a_OtherEnd.y - y);
-}
-
-
-
-
-
-double Vector3d::LineCoeffToYZPlane(const Vector3d & a_OtherEnd, double a_X) const
-{
- if (abs(x - a_OtherEnd.x) < EPS)
- {
- return NO_INTERSECTION;
- }
- return (a_X - x) / (a_OtherEnd.x - x);
-}
-
-
-
-
diff --git a/src/Vector3d.h b/src/Vector3d.h
deleted file mode 100644
index a06a17c09..000000000
--- a/src/Vector3d.h
+++ /dev/null
@@ -1,81 +0,0 @@
-#pragma once
-
-#include <math.h>
-
-class Vector3f;
-
-
-
-// tolua_begin
-
-class Vector3d
-{
-public:
- // convert from float
- Vector3d(const Vector3f & v);
- Vector3d(const Vector3f * v);
-
- Vector3d() : x(0), y(0), z(0) {}
- Vector3d(double a_x, double a_y, double a_z) : x(a_x), y(a_y), z(a_z) {}
-
- inline void Set(double a_x, double a_y, double a_z) { x = a_x, y = a_y, z = a_z; }
- inline void Normalize() { double l = 1.0f / Length(); x *= l; y *= l; z *= l; }
- inline Vector3d NormalizeCopy() { double l = 1.0f / Length(); return Vector3d( x * l, y * l, z * l ); }
- inline void NormalizeCopy(Vector3d & a_V) { double l = 1.0f / Length(); a_V.Set(x*l, y*l, z*l ); }
- inline double Length() const { return (double)sqrt( x * x + y * y + z * z ); }
- inline double SqrLength() const { return x * x + y * y + z * z; }
- inline double Dot( const Vector3d & a_V ) const { return x * a_V.x + y * a_V.y + z * a_V.z; }
- inline Vector3d Cross( const Vector3d & v ) const { return Vector3d( y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
-
- /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord
- The result satisfies the following equation:
- (*this + Result * (a_OtherEnd - *this)).z = a_Z
- If the line is too close to being parallel, this function returns NO_INTERSECTION
- */
- double LineCoeffToXYPlane(const Vector3d & a_OtherEnd, double a_Z) const;
-
- /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord
- The result satisfies the following equation:
- (*this + Result * (a_OtherEnd - *this)).y = a_Y
- If the line is too close to being parallel, this function returns NO_INTERSECTION
- */
- double LineCoeffToXZPlane(const Vector3d & a_OtherEnd, double a_Y) const;
-
- /** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord
- The result satisfies the following equation:
- (*this + Result * (a_OtherEnd - *this)).x = a_X
- If the line is too close to being parallel, this function returns NO_INTERSECTION
- */
- double LineCoeffToYZPlane(const Vector3d & a_OtherEnd, double a_X) const;
-
- inline bool Equals(const Vector3d & v) const { return ((x == v.x) && (y == v.y) && (z == v.z)); }
-
- // tolua_end
-
- void operator += ( const Vector3d& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; }
- void operator += ( Vector3d* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; }
- void operator -= ( const Vector3d& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; }
- void operator -= ( Vector3d* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; }
- void operator *= ( double a_f ) { x *= a_f; y *= a_f; z *= a_f; }
-
- // tolua_begin
-
- Vector3d operator + (const Vector3d & v2) const { return Vector3d(x + v2.x, y + v2.y, z + v2.z ); }
- Vector3d operator + (const Vector3d * v2) const { return Vector3d(x + v2->x, y + v2->y, z + v2->z ); }
- Vector3d operator - (const Vector3d & v2) const { return Vector3d(x - v2.x, y - v2.y, z - v2.z ); }
- Vector3d operator - (const Vector3d * v2) const { return Vector3d(x - v2->x, y - v2->y, z - v2->z ); }
- Vector3d operator * (const double f) const { return Vector3d(x * f, y * f, z * f ); }
- Vector3d operator * (const Vector3d & v2) const { return Vector3d(x * v2.x, y * v2.y, z * v2.z ); }
- Vector3d operator / (const double f) const { return Vector3d(x / f, y / f, z / f ); }
-
- double x, y, z;
-
- static const double EPS; ///< The max difference between two coords for which the coords are assumed equal
- static const double NO_INTERSECTION; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane
-} ;
-
-// tolua_end
-
-
-
-
diff --git a/src/Vector3f.cpp b/src/Vector3f.cpp
deleted file mode 100644
index 59d71d371..000000000
--- a/src/Vector3f.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "Vector3f.h"
-#include "Vector3d.h"
-#include "Vector3i.h"
-
-Vector3f::Vector3f( const Vector3d & v )
- : x( (float)v.x )
- , y( (float)v.y )
- , z( (float)v.z )
-{
-}
-
-Vector3f::Vector3f( const Vector3d * v )
- : x( (float)v->x )
- , y( (float)v->y )
- , z( (float)v->z )
-{
-}
-
-Vector3f::Vector3f( const Vector3i & v )
- : x( (float)v.x )
- , y( (float)v.y )
- , z( (float)v.z )
-{
-}
-
-Vector3f::Vector3f( const Vector3i * v )
- : x( (float)v->x )
- , y( (float)v->y )
- , z( (float)v->z )
-{
-} \ No newline at end of file
diff --git a/src/Vector3f.h b/src/Vector3f.h
deleted file mode 100644
index adb154ad7..000000000
--- a/src/Vector3f.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#pragma once
-
-#include <math.h>
-
-class Vector3i;
-class Vector3d;
-class Vector3f // tolua_export
-{ // tolua_export
-public: // tolua_export
- Vector3f( const Vector3d & v ); // tolua_export
- Vector3f( const Vector3d * v ); // tolua_export
- Vector3f( const Vector3i & v ); // tolua_export
- Vector3f( const Vector3i * v ); // tolua_export
-
-
- Vector3f() : x(0), y(0), z(0) {} // tolua_export
- Vector3f(float a_x, float a_y, float a_z) : x(a_x), y(a_y), z(a_z) {} // tolua_export
-
- inline void Set(float a_x, float a_y, float a_z) { x = a_x, y = a_y, z = a_z; } // tolua_export
- inline void Normalize() { float l = 1.0f / Length(); x *= l; y *= l; z *= l; } // tolua_export
- inline Vector3f NormalizeCopy() const { float l = 1.0f / Length(); return Vector3f( x * l, y * l, z * l ); }// tolua_export
- inline void NormalizeCopy(Vector3f & a_V) const { float l = 1.0f / Length(); a_V.Set(x*l, y*l, z*l ); } // tolua_export
- inline float Length() const { return (float)sqrtf( x * x + y * y + z * z ); } // tolua_export
- inline float SqrLength() const { return x * x + y * y + z * z; } // tolua_export
- inline float Dot( const Vector3f & a_V ) const { return x * a_V.x + y * a_V.y + z * a_V.z; } // tolua_export
- inline Vector3f Cross( const Vector3f & v ) const { return Vector3f( y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); } // tolua_export
-
- inline bool Equals( const Vector3f & v ) const { return (x == v.x && y == v.y && z == v.z ); } // tolua_export
-
- void operator += ( const Vector3f& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; }
- void operator += ( Vector3f* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; }
- void operator -= ( const Vector3f& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; }
- void operator -= ( Vector3f* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; }
- void operator *= ( float a_f ) { x *= a_f; y *= a_f; z *= a_f; }
- void operator *= ( Vector3f* a_V ) { x *= a_V->x; y *= a_V->y; z *= a_V->z; }
- void operator *= ( const Vector3f& a_V ) { x *= a_V.x; y *= a_V.y; z *= a_V.z; }
-
- Vector3f operator + ( const Vector3f& v2 ) const { return Vector3f( x + v2.x, y + v2.y, z + v2.z ); } // tolua_export
- Vector3f operator + ( const Vector3f* v2 ) const { return Vector3f( x + v2->x, y + v2->y, z + v2->z ); } // tolua_export
- Vector3f operator - ( const Vector3f& v2 ) const { return Vector3f( x - v2.x, y - v2.y, z - v2.z ); } // tolua_export
- Vector3f operator - ( const Vector3f* v2 ) const { return Vector3f( x - v2->x, y - v2->y, z - v2->z ); } // tolua_export
- Vector3f operator * ( const float f ) const { return Vector3f( x * f, y * f, z * f ); } // tolua_export
- Vector3f operator * ( const Vector3f& v2 ) const { return Vector3f( x * v2.x, y * v2.y, z * v2.z ); } // tolua_export
-
- float x, y, z; // tolua_export
-
-};// tolua_export
diff --git a/src/Vector3i.cpp b/src/Vector3i.cpp
deleted file mode 100644
index 2106aea6d..000000000
--- a/src/Vector3i.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-
-// Vector3i.cpp
-
-// Implements the Vector3i class representing an int-based 3D vector
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "math.h"
-#include "Vector3i.h"
-#include "Vector3d.h"
-
-
-
-
-
-Vector3i::Vector3i(const Vector3d & v) :
- x((int)v.x),
- y((int)v.y),
- z((int)v.z)
-{
-}
-
-
-
-
-
-Vector3i::Vector3i(void) :
- x(0),
- y(0),
- z(0)
-{
-}
-
-
-
-
-
-Vector3i::Vector3i(int a_x, int a_y, int a_z) :
- x(a_x),
- y(a_y),
- z(a_z)
-{
-}
-
-
-
-
-
-void Vector3i::Move(int a_MoveX, int a_MoveY, int a_MoveZ)
-{
- x += a_MoveX;
- y += a_MoveY;
- z += a_MoveZ;
-}
-
-
-
-
diff --git a/src/Vector3i.h b/src/Vector3i.h
deleted file mode 100644
index 39e138683..000000000
--- a/src/Vector3i.h
+++ /dev/null
@@ -1,68 +0,0 @@
-
-// Vector3i.h
-
-// Declares the Vector3i class representing an int-based 3D vector
-
-
-
-
-
-#pragma once
-
-
-
-
-
-// fwd:
-class Vector3d;
-
-
-
-
-
-// tolua_begin
-class Vector3i
-{
-public:
- /** Creates an int vector based on the floor()-ed coords of a double vector. */
- Vector3i(const Vector3d & v);
-
- Vector3i(void);
- Vector3i(int a_x, int a_y, int a_z);
-
- inline void Set(int a_x, int a_y, int a_z) { x = a_x, y = a_y, z = a_z; }
- inline float Length() const { return sqrtf( (float)( x * x + y * y + z * z) ); }
- inline int SqrLength() const { return x * x + y * y + z * z; }
-
- inline bool Equals( const Vector3i & v ) const { return (x == v.x && y == v.y && z == v.z ); }
- inline bool Equals( const Vector3i * v ) const { return (x == v->x && y == v->y && z == v->z ); }
-
- void Move(int a_MoveX, int a_MoveY, int a_MoveZ);
-
- // tolua_end
-
- void operator += ( const Vector3i& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; }
- void operator += ( Vector3i* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; }
- void operator -= ( const Vector3i& a_V ) { x -= a_V.x; y -= a_V.y; z -= a_V.z; }
- void operator -= ( Vector3i* a_V ) { x -= a_V->x; y -= a_V->y; z -= a_V->z; }
- void operator *= ( int a_f ) { x *= a_f; y *= a_f; z *= a_f; }
-
- friend Vector3i operator + ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z ); }
- friend Vector3i operator + ( const Vector3i& v1, Vector3i* v2 ) { return Vector3i( v1.x + v2->x, v1.y + v2->y, v1.z + v2->z ); }
- friend Vector3i operator - ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z ); }
- friend Vector3i operator - ( const Vector3i& v1, Vector3i* v2 ) { return Vector3i( v1.x - v2->x, v1.y - v2->y, v1.z - v2->z ); }
- friend Vector3i operator - ( const Vector3i* v1, Vector3i& v2 ) { return Vector3i( v1->x - v2.x, v1->y - v2.y, v1->z - v2.z ); }
- friend Vector3i operator * ( const Vector3i& v, const int f ) { return Vector3i( v.x * f, v.y * f, v.z * f ); }
- friend Vector3i operator * ( const Vector3i& v1, const Vector3i& v2 ) { return Vector3i( v1.x * v2.x, v1.y * v2.y, v1.z * v2.z ); }
- friend Vector3i operator * ( const int f, const Vector3i& v ) { return Vector3i( v.x * f, v.y * f, v.z * f ); }
- friend bool operator < ( const Vector3i& v1, const Vector3i& v2 ) { return (v1.x<v2.x)||(v1.x==v2.x && v1.y<v2.y)||(v1.x==v2.x && v1.y == v2.y && v1.z<v2.z); }
-
- int x, y, z; // tolua_export
-}; // tolua_export
-
-typedef std::list<Vector3i> cVector3iList;
-typedef std::vector<Vector3i> cVector3iArray;
-
-
-
-
diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp
index e88de5947..402cd3035 100644
--- a/src/WebAdmin.cpp
+++ b/src/WebAdmin.cpp
@@ -127,6 +127,7 @@ bool cWebAdmin::Start(void)
// Initialize the WebAdmin template script and load the file
m_TemplateScript.Create();
+ m_TemplateScript.RegisterAPILibs();
if (!m_TemplateScript.LoadFile(FILE_IO_PREFIX "webadmin/template.lua"))
{
LOGWARN("Could not load WebAdmin template \"%s\", using default template.", FILE_IO_PREFIX "webadmin/template.lua");
diff --git a/src/World.cpp b/src/World.cpp
index a9db6bf00..3d01dc40f 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -46,7 +46,6 @@
#include "Generating/Trees.h"
#include "Bindings/PluginManager.h"
#include "Blocks/BlockHandler.h"
-#include "Vector3d.h"
#include "Tracer.h"
diff --git a/src/World.h b/src/World.h
index d48db5911..a772710ab 100644
--- a/src/World.h
+++ b/src/World.h
@@ -14,8 +14,7 @@
#include "ChunkMap.h"
#include "WorldStorage/WorldStorage.h"
#include "Generating/ChunkGenerator.h"
-#include "Vector3i.h"
-#include "Vector3f.h"
+#include "Vector3.h"
#include "ChunkSender.h"
#include "Defines.h"
#include "LightingThread.h"
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp
index b021aeb0c..ef67fdb13 100644
--- a/src/WorldStorage/SchematicFileSerializer.cpp
+++ b/src/WorldStorage/SchematicFileSerializer.cpp
@@ -177,6 +177,25 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
a_BlockArea.Clear();
a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes);
+ int TOffsetX = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetX");
+ int TOffsetY = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetY");
+ int TOffsetZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetZ");
+
+ if (
+ (TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) ||
+ (a_NBT.GetType(TOffsetX) != TAG_Int) ||
+ (a_NBT.GetType(TOffsetY) != TAG_Int) ||
+ (a_NBT.GetType(TOffsetZ) != TAG_Int)
+ )
+ {
+ // Not every schematic file has an offset, so we shoudn't give a warn message.
+ a_BlockArea.SetWEOffset(0, 0, 0);
+ }
+ else
+ {
+ a_BlockArea.SetWEOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ));
+ }
+
// Copy the block types and metas:
int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ;
if (a_NBT.GetDataLength(TBlockTypes) < NumBytes)
@@ -234,6 +253,10 @@ AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockA
Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
}
+ Writer.AddInt("WEOffsetX", a_BlockArea.m_WEOffset.x);
+ Writer.AddInt("WEOffsetY", a_BlockArea.m_WEOffset.y);
+ Writer.AddInt("WEOffsetZ", a_BlockArea.m_WEOffset.z);
+
// TODO: Save entities and block entities
Writer.BeginList("Entities", TAG_Compound);
Writer.EndList();
diff --git a/src/WorldStorage/WSSCompact.h b/src/WorldStorage/WSSCompact.h
index 64b8d7f31..4df146ec3 100644
--- a/src/WorldStorage/WSSCompact.h
+++ b/src/WorldStorage/WSSCompact.h
@@ -12,7 +12,7 @@
#define WSSCOMPACT_H_INCLUDED
#include "WorldStorage.h"
-#include "../Vector3i.h"
+#include "../Vector3.h"
#include "json/json.h"