From 0cce0478d846114f49c4b8fe201aee7a1bb06b22 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 10 Mar 2014 17:07:46 +0100 Subject: [PATCH 01/19] This allows a blockarea to have an Offset. --- src/BlockArea.cpp | 19 ++++++++++++++++ src/BlockArea.h | 5 +++++ src/WorldStorage/SchematicFileSerializer.cpp | 23 ++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index d07ef747a..986b2ee25 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_Offset(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::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) +{ + m_Offset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); +} + + + + + +void cBlockArea::SetOffset(Vector3i a_Offset) +{ + m_Offset.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..d89c9b372 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -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 SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ); + void SetOffset (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; + Vector3i GetOffset (void) const {return m_Offset;} 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,8 @@ protected: int m_SizeY; int m_SizeZ; + Vector3i m_Offset; + 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/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index b021aeb0c..0aea931eb 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.SetOffset(0, 0, 0); + } + else + { + a_BlockArea.SetOffset(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_Offset.x); + Writer.AddInt("WEOffsetY", a_BlockArea.m_Offset.y); + Writer.AddInt("WEOffsetZ", a_BlockArea.m_Offset.z); + // TODO: Save entities and block entities Writer.BeginList("Entities", TAG_Compound); Writer.EndList(); From e213e5f9fcb3681a5f383546e17b9800d4a4804a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 18:23:21 +0100 Subject: [PATCH 02/19] Renamed m_Offset to m_WEOffset --- src/BlockArea.cpp | 6 +++--- src/BlockArea.h | 5 +++-- src/WorldStorage/SchematicFileSerializer.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index dfdf998df..983dbe46b 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -168,7 +168,7 @@ cBlockArea::cBlockArea(void) : m_SizeX(0), m_SizeY(0), m_SizeZ(0), - m_Offset(0,0,0), + m_WEOffset(0, 0, 0), m_BlockTypes(NULL), m_BlockMetas(NULL), m_BlockLight(NULL), @@ -257,7 +257,7 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) { - m_Offset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); + m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); } @@ -266,7 +266,7 @@ void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) void cBlockArea::SetOffset(const Vector3i & a_Offset) { - m_Offset.Set(a_Offset.x, a_Offset.y, a_Offset.z); + m_WEOffset.Set(a_Offset.x, a_Offset.y, a_Offset.z); } diff --git a/src/BlockArea.h b/src/BlockArea.h index 75b8db3a6..76424d02f 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -221,7 +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 & GetOffset (void) const {return m_Offset;} + const Vector3i & GetOffset (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); @@ -302,7 +302,8 @@ protected: int m_SizeY; int m_SizeZ; - Vector3i m_Offset; + // Used for schematics that are created by the WorldEdit plugin. The offset is used for player-relative pasting. + Vector3i m_WEOffset; BLOCKTYPE * m_BlockTypes; NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index 0aea931eb..b899540df 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -253,9 +253,9 @@ AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockA Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); } - Writer.AddInt("WEOffsetX", a_BlockArea.m_Offset.x); - Writer.AddInt("WEOffsetY", a_BlockArea.m_Offset.y); - Writer.AddInt("WEOffsetZ", a_BlockArea.m_Offset.z); + 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); From fa4ff28bc04f73a2af98a0f00e536e2b5293cbf1 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 19:38:56 +0100 Subject: [PATCH 03/19] Documented the functions. --- MCServer/Plugins/APIDump/APIDesc.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 1e572492b..54b2372f8 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -115,6 +115,7 @@ g_APIDesc = GetBlockType = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified absolute coords" }, GetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified absolute coords" }, GetDataTypes = { Params = "", Return = "number", Notes = "Returns the mask of datatypes that the objectis currently holding" }, + GetOffset = { Params = "", Returns = "Vector3i", Notes = "Returns the offset wich are sometimes saved in schematic files if created by WorldEdit (Bukkit) for player-relative pasting. The default is 0, 0, 0"}, GetOrigin = { Params = "", Return = "OriginX, OriginY, OriginZ", Notes = "Returns the origin coords of where the area was read from." }, GetOriginX = { Params = "", Return = "number", Notes = "Returns the origin x-coord" }, GetOriginY = { Params = "", Return = "number", Notes = "Returns the origin y-coord" }, @@ -168,6 +169,11 @@ g_APIDesc = SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" }, SetBlockType = { Params = "BlockX, BlockY, BlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified absolute coords" }, SetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified absolute coords" }, + SetOffset = + { + { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, + { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, + } SetOrigin = { { Params = "{{Vector3i|Origin}}", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, From 7d1e32a28b167faa6b17235283822da0cc7b2c13 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 19:45:16 +0100 Subject: [PATCH 04/19] Fixed APIDump --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 54b2372f8..5d4b89425 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -173,7 +173,7 @@ g_APIDesc = { { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, - } + }, SetOrigin = { { Params = "{{Vector3i|Origin}}", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, From 950614da7e700b8847f0dcc0bac9d76367801a3f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 07:46:14 +0100 Subject: [PATCH 05/19] Renamed cBlockArea Offset to WEOffset. Even in getters / setters. --- src/BlockArea.cpp | 4 ++-- src/BlockArea.h | 9 +++++---- src/WorldStorage/SchematicFileSerializer.cpp | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 983dbe46b..406e18a3b 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -255,7 +255,7 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) -void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) +void cBlockArea::SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) { m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); } @@ -264,7 +264,7 @@ void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) -void cBlockArea::SetOffset(const Vector3i & a_Offset) +void cBlockArea::SetWEOffset(const Vector3i & a_Offset) { m_WEOffset.Set(a_Offset.x, a_Offset.y, a_Offset.z); } diff --git a/src/BlockArea.h b/src/BlockArea.h index 76424d02f..31918ce8c 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -209,8 +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 SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ); - void SetOffset (const Vector3i & a_Offset); + 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; @@ -221,7 +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 & GetOffset (void) const {return m_WEOffset;} + 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); @@ -302,7 +302,8 @@ protected: int m_SizeY; int m_SizeZ; - // Used for schematics that are created by the WorldEdit plugin. The offset is used for player-relative pasting. + /** 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; diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index b899540df..ef67fdb13 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -189,11 +189,11 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP ) { // Not every schematic file has an offset, so we shoudn't give a warn message. - a_BlockArea.SetOffset(0, 0, 0); + a_BlockArea.SetWEOffset(0, 0, 0); } else { - a_BlockArea.SetOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ)); + a_BlockArea.SetWEOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ)); } // Copy the block types and metas: From 15c70a1f68ac176993b647cb0860cd190b7631d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 07:53:25 +0100 Subject: [PATCH 06/19] APIDump: Updated WEOffset-related docs. --- MCServer/Plugins/APIDump/APIDesc.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 086791006..18b90adbf 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -114,8 +114,7 @@ g_APIDesc = GetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ", Return = "NIBBLETYPE", Notes = "Returns the skylight at the specified absolute coords" }, GetBlockType = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified absolute coords" }, GetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified absolute coords" }, - GetDataTypes = { Params = "", Return = "number", Notes = "Returns the mask of datatypes that the objectis currently holding" }, - GetOffset = { Params = "", Returns = "Vector3i", Notes = "Returns the offset wich are sometimes saved in schematic files if created by WorldEdit (Bukkit) for player-relative pasting. The default is 0, 0, 0"}, + GetDataTypes = { Params = "", Return = "number", Notes = "Returns the mask of datatypes that the object is currently holding" }, GetOrigin = { Params = "", Return = "OriginX, OriginY, OriginZ", Notes = "Returns the origin coords of where the area was read from." }, GetOriginX = { Params = "", Return = "number", Notes = "Returns the origin x-coord" }, GetOriginY = { Params = "", Return = "number", Notes = "Returns the origin y-coord" }, @@ -130,6 +129,7 @@ g_APIDesc = GetSizeY = { Params = "", Return = "number", Notes = "Returns the size of the held data in the y-axis" }, GetSizeZ = { Params = "", Return = "number", Notes = "Returns the size of the held data in the z-axis" }, GetVolume = { Params = "", Return = "number", Notes = "Returns the volume of the area - the total number of blocks stored within." }, + GetWEOffset = { Params = "", Return = "{{Vector3i}}", Notes = "Returns the WE offset, a data value sometimes stored in the schematic files. MCServer doesn't use this value, but provides access to it using this method. The default is {0, 0, 0}."}, HasBlockLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include blocklight" }, HasBlockMetas = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include block metas" }, HasBlockSkyLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include skylight" }, @@ -169,11 +169,6 @@ g_APIDesc = SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" }, SetBlockType = { Params = "BlockX, BlockY, BlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified absolute coords" }, SetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified absolute coords" }, - SetOffset = - { - { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, - { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the offset of the cBlockArea. Mostly used for WorldEdit." }, - }, SetOrigin = { { Params = "{{Vector3i|Origin}}", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." }, @@ -184,6 +179,11 @@ g_APIDesc = SetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified relative coords" }, SetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified relative coords" }, SetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified relative coords" }, + SetWEOffset = + { + { Params = "{{Vector3i|Offset}}", Return = "", Notes = "Sets the WE offset, a data value sometimes stored in the schematic files. Mostly used for WorldEdit. MCServer doesn't use this value, but provides access to it using this method." }, + { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Sets the WE offset, a data value sometimes stored in the schematic files. Mostly used for WorldEdit. MCServer doesn't use this value, but provides access to it using this method." }, + }, Write = { { Params = "World, {{Vector3i|MinPoint}}, DataTypes", Return = "bool", Notes = "Writes the area into World at the specified coords, returns true if successful" }, From 04dcd850d6c5609bd5ecea2c60b0be0148571d61 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Mar 2014 08:30:01 +0100 Subject: [PATCH 07/19] APIDump: Removed old documentation, documented some new functions. --- MCServer/Plugins/APIDump/APIDesc.lua | 21 +++++++++++++------ MCServer/Plugins/APIDump/Classes/Geometry.lua | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 18b90adbf..3c99b82de 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -423,6 +423,7 @@ g_APIDesc = SetUseDefaultFinish = { Params = "bool", Return = "", Notes = "Sets the chunk to use default finishers or not" }, SetUseDefaultHeight = { Params = "bool", Return = "", Notes = "Sets the chunk to use default height generator or not" }, SetUseDefaultStructures = { Params = "bool", Return = "", Notes = "Sets the chunk to use default structures or not" }, + UpdateHeightmap = { Params = "", Return = "", Notes = "Updates the heightmap to match current contents. The plugins should do that if they modify the contents and don't modify the heightmap accordingly; MCServer expects (and checks in Debug mode) that the heightmap matches the contents when the cChunkDesc is returned from a plugin." }, WriteBlockArea = { Params = "{{cBlockArea|BlockArea}}, MinRelX, MinRelY, MinRelZ", Return = "", Notes = "Writes data from the block area into the chunk" }, }, AdditionalInfo = @@ -472,6 +473,7 @@ end Functions = { + GetLocale = { Params = "", Return = "Locale", Notes = "Returns the locale string that the client sends as part of the protocol handshake. Can be used to provide localized strings." }, GetPing = { Params = "", Return = "number", Notes = "Returns the ping time, in ms" }, GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." }, GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" }, @@ -480,6 +482,7 @@ end HasPluginChannel = { Params = "ChannelName", Return = "bool", Notes = "Returns true if the client has registered to receive messages on the specified plugin channel." }, Kick = { Params = "Reason", Return = "", Notes = "Kicks the user with the specified reason" }, SendPluginMessage = { Params = "Channel, Message", Return = "", Notes = "Sends the plugin message on the specified channel." }, + SetLocale = { Params = "Locale", Return = "", Notes = "Sets the locale that MCServer keeps on record. Initially the locale is initialized in protocol handshake, this function allows plugins to override the stored value (but only server-side and only until the user disconnects)." }, SetUsername = { Params = "Name", Return = "", Notes = "Sets the username" }, SetViewDistance = { Params = "ViewDistance", Return = "", Notes = "Sets the viewdistance (number of chunks loaded for the player in each direction)" }, SendBlockChange = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sends a BlockChange packet to the client. This can be used to create fake blocks only for that player." }, @@ -883,7 +886,6 @@ cFile:Delete("/usr/bin/virus.exe"); SetColor = { Return = "" }, GetColor = { Return = "string" }, AddCommand = { Return = "" }, - HasCommand = { Return = "bool" }, AddPermission = { Return = "" }, InheritFrom = { Return = "" }, }, @@ -1150,7 +1152,6 @@ These ItemGrids are available in the API and can be manipulated by the plugins, IsEnchantable = { Params = "", Return = "bool", Notes = "Returns true if the item is enchantable" }, IsFullStack = { Params = "", Return = "bool", Notes = "Returns true if the item is stacked up to its maximum stacking" }, IsSameType = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is of the same ItemType as the one stored in the object. This is true even if the two items have different enchantments" }, - IsStackableWith = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is stackable with the one stored in the object. Two items with different enchantments cannot be stacked" }, IsBothNameAndLoreEmpty = { Params = "", Return = "bool", Notes = "Returns if both the custom name and lore are not set." }, IsCustomNameEmpty = { Params = "", Return = "bool", Notes = "Returns if the custom name of the cItem is empty." }, IsLoreEmpty = { Params = "", Return = "", Notes = "Returns if the lore of the cItem is empty." }, @@ -1656,7 +1657,6 @@ a_Player:OpenWindow(Window); AddToGroup = { Params = "GroupName", Return = "", Notes = "Temporarily adds the player to the specified group. The assignment is lost when the player disconnects." }, CalcLevelFromXp = { Params = "XPAmount", Return = "number", Notes = "(STATIC) Returns the level which is reached with the specified amount of XP. Inverse of XpForLevel()." }, CanFly = { Return = "bool", Notes = "Returns if the player is able to fly." }, - CanUseCommand = { Params = "Command", Return = "bool", Notes = "Returns true if the player is allowed to use the specified command." }, CloseWindow = { Params = "[CanRefuse]", Return = "", Notes = "Closes the currently open UI window. If CanRefuse is true (default), the window may refuse the closing." }, CloseWindowIfID = { Params = "WindowID, [CanRefuse]", Return = "", Notes = "Closes the currently open UI window if its ID matches the given ID. If CanRefuse is true (default), the window may refuse the closing." }, DeltaExperience = { Params = "DeltaXP", Return = "", Notes = "Adds or removes XP from the current XP amount. Won't allow XP to go negative. Returns the new experience, -1 on error (XP overflow)." }, @@ -1733,7 +1733,6 @@ a_Player:OpenWindow(Window); SetSprint = { Params = "IsSprinting", Return = "", Notes = "Sets whether the player is sprinting or not." }, SetSprintingMaxSpeed = { Params = "SprintingMaxSpeed", Return = "", Notes = "Sets the sprinting maximum speed (as reported by the 1.6.1+ protocols)" }, SetVisible = { Params = "IsVisible", Return = "", Notes = "Sets the player visibility to other players" }, - TossItem = { Params = "DraggedItem, [Amount], [CreateType], [CreateDamage]", Return = "", Notes = "FIXME: This function will be rewritten, avoid it. It tosses an item, either from the inventory, dragged in hand (while in UI window) or a newly created one." }, XpForLevel = { Params = "XPLevel", Return = "number", Notes = "(STATIC) Returns the total amount of XP needed for the specified XP level. Inverse of CalcLevelFromXp()." }, }, Constants = @@ -2630,7 +2629,8 @@ end ]], Functions = { - AddFaceDirection = {Params = "BlockX, BlockY, BlockZ, BlockFace, [IsInverse]", Return = "BlockX, BlockY, BlockZ", Notes = "Returns the coords of a block adjacent to the specified block through the specified {{Globals#BlockFace|face}}"}, + AddFaceDirection = {Params = "BlockX, BlockY, BlockZ, BlockFace, [IsInverse]", Return = "BlockX, BlockY, BlockZ", Notes = "Returns the coords of a block adjacent to the specified block through the specified {{Globals#BlockFaces|face}}"}, + BlockFaceToString = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "string", Notes = "Returns the string representation of the {{Globals#BlockFaces|eBlockFace}} constant. Uses the axis-direction-based names, such as BLOCK_FACE_XP." }, BlockStringToType = {Params = "BlockTypeString", Return = "BLOCKTYPE", Notes = "Returns the block type parsed from the given string"}, ClickActionToString = {Params = "{{Globals#ClickAction|ClickAction}}", Return = "string", Notes = "Returns a string description of the ClickAction enumerated value"}, DamageTypeToString = {Params = "{{Globals#DamageType|DamageType}}", Return = "string", Notes = "Converts the {{Globals#DamageType|DamageType}} enumerated value to a string representation "}, @@ -2649,9 +2649,12 @@ end LOGINFO = {Params = "string", Notes = "Logs a text into the server console using 'info' severity (yellow text)"}, LOGWARN = {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text); OBSOLETE, use LOGWARNING() instead"}, LOGWARNING = {Params = "string", Notes = "Logs a text into the server console using 'warning' severity (red text)"}, + MirrorBlockFaceY = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after mirroring it around the Y axis (or rotating 180 degrees around it)." }, NoCaseCompare = {Params = "string, string", Return = "number", Notes = "Case-insensitive string comparison; returns 0 if the strings are the same"}, NormalizeAngleDegrees = { Params = "AngleDegrees", Return = "AngleDegrees", Notes = "Returns the angle, wrapped into the [-180, +180) range." }, ReplaceString = {Params = "full-string, to-be-replaced-string, to-replace-string", Notes = "Replaces *each* occurence of to-be-replaced-string in full-string with to-replace-string"}, + RotateBlockFaceCCW = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees counter-clockwise." }, + RotateBlockFaceCW = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees clockwise." }, StringSplit = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered."}, StringSplitAndTrim = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered. Each of the separate strings is trimmed (whitespace removed from the beginning and end of the string)"}, StringToBiome = {Params = "string", Return = "{{Globals#BiomeTypes|BiomeType}}", Notes = "Converts a string representation to a {{Globals#BiomeTypes|BiomeType}} enumerated value"}, @@ -2698,7 +2701,13 @@ end Include = "^BLOCK_FACE_.*", TextBefore = [[ These constants are used to describe individual faces of the block. They are used when the - client is interacting with a block, or when the {{cLineBlockTracer}} hits a block, etc. + client is interacting with a block in the {{OnPlayerBreakingBlock|HOOK_PLAYER_BREAKING_BLOCK}}, + {{OnPlayerBrokenBlock|HOOK_PLAYER_BROKEN_BLOCK}}, {{OnPlayerLeftClick|HOOK_PLAYER_LEFT_CLICK}}, + {{OnPlayerPlacedBlock|HOOK_PLAYER_PLACED_BLOCK}}, {{OnPlayerPlacingBlock|HOOK_PLAYER_PLACING_BLOCK}}, + {{OnPlayerRightClick|HOOK_PLAYER_RIGHT_CLICK}}, {{OnPlayerUsedBlock|HOOK_PLAYER_USED_BLOCK}}, + {{OnPlayerUsedItem|HOOK_PLAYER_USED_ITEM}}, {{OnPlayerUsingBlock|HOOK_PLAYER_USING_BLOCK}}, + and {{OnPlayerUsingItem|HOOK_PLAYER_USING_ITEM}} hooks, or when the {{cLineBlockTracer}} hits a + block, etc. ]], }, ClickAction = diff --git a/MCServer/Plugins/APIDump/Classes/Geometry.lua b/MCServer/Plugins/APIDump/Classes/Geometry.lua index e83d6e4b1..6f95c4cbf 100644 --- a/MCServer/Plugins/APIDump/Classes/Geometry.lua +++ b/MCServer/Plugins/APIDump/Classes/Geometry.lua @@ -76,6 +76,7 @@ return DifY = { Params = "", Return = "number", Notes = "Returns the difference between the two Y coords (Y-size minus 1). Assumes sorted." }, DifZ = { Params = "", Return = "number", Notes = "Returns the difference between the two Z coords (Z-size minus 1). Assumes sorted." }, DoesIntersect = { Params = "OtherCuboid", Return = "bool", Notes = "Returns true if this cuboid has at least one voxel in common with OtherCuboid. Note that edges are considered inclusive. Assumes both sorted." }, + Engulf = { Params = "{{Vector3i|Point}}", Return = "", Notes = "If needed, expands the cuboid to include the specified point. Doesn't shrink. Assumes sorted. " }, Expand = { Params = "SubMinX, AddMaxX, SubMinY, AddMaxY, SubMinZ, AddMaxZ", Return = "", Notes = "Expands the cuboid by the specified amount in each direction. Works on unsorted cuboids as well. NOTE: this function doesn't check for underflows." }, GetVolume = { Params = "", Return = "number", Notes = "Returns the volume of the cuboid, in blocks. Note that the volume considers both coords inclusive. Works on unsorted cuboids, too." }, IsCompletelyInside = { Params = "OuterCuboid", Return = "bool", Notes = "Returns true if this cuboid is completely inside (in all directions) in OuterCuboid. Assumes both sorted." }, @@ -308,6 +309,7 @@ end }, Equals = { Params = "Vector3i", Return = "bool", Notes = "Returns true if this vector is exactly the same as the specified vector." }, Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector." }, + Move = { Params = "X, Y, Z", Return = "", Notes = "Moves the vector by the specified amount in each axis direction." }, Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once" }, SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." }, }, From 541175d8a08515568d75a8d6b57bc4841e273c4a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 14:44:21 +0100 Subject: [PATCH 08/19] Using ```const Vector3i &``` --- src/BlockArea.cpp | 2 +- src/BlockArea.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 986b2ee25..dfdf998df 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -264,7 +264,7 @@ void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) -void cBlockArea::SetOffset(Vector3i a_Offset) +void cBlockArea::SetOffset(const Vector3i & a_Offset) { m_Offset.Set(a_Offset.x, a_Offset.y, a_Offset.z); } diff --git a/src/BlockArea.h b/src/BlockArea.h index d89c9b372..75b8db3a6 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -210,7 +210,7 @@ public: 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 SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ); - void SetOffset (Vector3i a_Offset); + void SetOffset (const Vector3i & a_Offset); // Getters: BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const; @@ -221,7 +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; - Vector3i GetOffset (void) const {return m_Offset;} + const Vector3i & GetOffset (void) const {return m_Offset;} 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); From b4bf13aa4f004a7819e262679a295d8ca886557b Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 16:01:17 +0200 Subject: [PATCH 09/19] Unified Vector classes --- src/Bindings/AllToLua.pkg | 10 +- src/Bindings/LuaState.h | 3 +- src/BlockArea.h | 2 +- src/BoundingBox.h | 2 +- src/CMakeLists.txt | 4 +- src/ChunkDef.h | 2 +- src/ClientHandle.cpp | 3 - src/ClientHandle.h | 2 +- src/Cuboid.h | 3 +- src/Entities/Entity.h | 4 +- src/Entities/Player.cpp | 1 + src/Globals.h | 8 ++ src/LineBlockTracer.cpp | 2 +- src/Matrix4f.h | 2 +- src/Mobs/Bat.cpp | 2 +- src/Mobs/Squid.cpp | 2 +- src/Scoreboard.h | 2 + src/Server.cpp | 2 +- src/Simulator/Simulator.cpp | 1 - src/Simulator/Simulator.h | 2 +- src/Tracer.cpp | 4 - src/Tracer.h | 3 +- src/Vector3.h | 264 ++++++++++++++++++++++++++++++++++ src/Vector3d.cpp | 77 ---------- src/Vector3d.h | 81 ----------- src/Vector3f.cpp | 34 ----- src/Vector3f.h | 47 ------ src/Vector3i.cpp | 58 -------- src/Vector3i.h | 68 --------- src/World.cpp | 1 - src/World.h | 3 +- src/WorldStorage/WSSCompact.h | 2 +- 32 files changed, 300 insertions(+), 401 deletions(-) create mode 100644 src/Vector3.h delete mode 100644 src/Vector3d.cpp delete mode 100644 src/Vector3d.h delete mode 100644 src/Vector3f.cpp delete mode 100644 src/Vector3f.h delete mode 100644 src/Vector3i.cpp delete mode 100644 src/Vector3i.h diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 2676281f9..302714318 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,9 +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" @@ -97,4 +95,10 @@ typedef unsigned char Byte; +// Aliases +$renaming Vector3 @ Vector3d +$renaming Vector3 @ Vector3f +$renaming Vector3 @ Vector3i + + diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 4a7a6fadb..1156f5363 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; diff --git a/src/BlockArea.h b/src/BlockArea.h index 0703f195e..0e52a5de0 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; 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..04736c2d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,9 +70,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 7876c58e7..04a7f5af2 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 94c9f5f71..9083d7ae0 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.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/Globals.h b/src/Globals.h index 28805a83f..b8acfca64 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -246,6 +246,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/Matrix4f.h b/src/Matrix4f.h index 249c92f5f..0e36974ad 100644 --- a/src/Matrix4f.h +++ b/src/Matrix4f.h @@ -2,7 +2,7 @@ #define _USE_MATH_DEFINES #include -#include "Vector3f.h" +#include "Vector3.h" class Matrix4f { 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 #include 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..0be52248d --- /dev/null +++ b/src/Vector3.h @@ -0,0 +1,264 @@ + +#pragma once + + + + +#include + + + + + + + + + +template +// tolua_begin +class Vector3 +{ + + TOLUA_TEMPLATE_BIND((T, int, float, double)) + +public: + + T x, y, z; + + + inline Vector3() : 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) {} + + + // tolua_end + template + Vector3(const Vector3<_T> & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + + template + 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) + { + T Len = 1.0 / Length(); + + x *= Len; + y *= Len; + z *= Len; + } + + inline Vector3 NormalizeCopy(void) const + { + T Len = 1.0 / Length(); + + return Vector3( + x * Len, + y * Len, + z * Len + ); + } + + inline void NormalizeCopy(Vector3 & a_Rhs) const + { + T Len = 1.0 / Length(); + + a_Rhs.Set( + x * Len, + y * Len, + z * Len + ); + } + + inline T Length(void) const + { + return sqrt(x * x + y * y + z * z); + } + + inline T SqrLength(void) const + { + return x * x + y * y + z * z; + } + + inline T Dot(const Vector3 & a_Rhs) const + { + return x * a_Rhs.x + y * a_Rhs.y + z * a_Rhs.z; + } + + inline Vector3 Cross(const Vector3 & a_Rhs) const + { + return Vector3( + 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 & a_Rhs) const + { + return x == a_Rhs.x && y == a_Rhs.y && z == a_Rhs.z; + } + + inline bool operator < (const Vector3 & 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 & a_Rhs) + { + x += a_Rhs.x; + y += a_Rhs.y; + z += a_Rhs.z; + } + + inline void operator -= (const Vector3 & a_Rhs) + { + x -= a_Rhs.x; + y -= a_Rhs.y; + z -= a_Rhs.z; + } + + inline void operator *= (const Vector3 & 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 operator + (const Vector3& a_Rhs) const + { + return Vector3( + x + a_Rhs.x, + y + a_Rhs.y, + z + a_Rhs.z + ); + } + + inline Vector3 operator - (const Vector3& a_Rhs) const + { + return Vector3( + x - a_Rhs.x, + y - a_Rhs.y, + z - a_Rhs.z + ); + } + + inline Vector3 operator * (const Vector3& a_Rhs) const + { + return Vector3( + x * a_Rhs.x, + y * a_Rhs.y, + z * a_Rhs.z + ); + } + + inline Vector3 operator * (T a_v) const + { + return Vector3( + x * a_v, + y * a_v, + z * a_v + ); + } + + inline Vector3 operator / (T a_v) const + { + return Vector3( + x / a_v, + y / a_v, + z / a_v + ); + } + + inline double LineCoeffToXYPlane(const Vector3 & a_OtherEnd, T a_Z) const + { + if (abs(z - a_OtherEnd.z) < EPS) + { + return NO_INTERSECTION; + } + + return (a_Z - z) / (a_OtherEnd.z - z); + } + + inline double LineCoeffToXZPlane(const Vector3 & a_OtherEnd, T a_Y) const + { + if (abs(y - a_OtherEnd.y) < EPS) + { + return NO_INTERSECTION; + } + + return (a_Y - y) / (a_OtherEnd.y - y); + } + + inline double LineCoeffToYZPlane(const Vector3 & 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 +const double Vector3::EPS = 0.000001; + +template +const double Vector3::NO_INTERSECTION = 1e70; + + + + + +// tolua_begin +typedef Vector3 Vector3d; +typedef Vector3 Vector3f; +typedef Vector3 Vector3i; +// tolua_end + + + + + +typedef std::list cVector3iList; +typedef std::vector 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 - -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 - -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 cVector3iList; -typedef std::vector cVector3iArray; - - - - 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/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" From deafec874d87b5b1ef0dd7fb094fd7b38634a0db Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 15:14:47 +0100 Subject: [PATCH 10/19] Snowballs now actualy hurt other entities. 3 damage for blazes and 1 for the ender dragon. Otherwise 0 --- src/Entities/ProjectileEntity.cpp | 26 ++++++++++++++++++++++++-- src/Entities/ProjectileEntity.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 03bc0c99d..92890919c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -655,8 +655,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(); } @@ -664,6 +662,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, m_Creator, TotalDamage, 1); + + Destroy(true); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBottleOEnchantingEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index e80592999..840dac871 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 From ef3c5a97a46212a0f8cd1a05125f4b75e3f32b74 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 11 Mar 2014 16:24:05 +0100 Subject: [PATCH 11/19] TakeDamage now has the cThrownSnowballEntity instead of the creator's object. --- src/Entities/ProjectileEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 92890919c..37238a0c0 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -677,7 +677,7 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & TotalDamage = 1; } } - a_EntityHit.TakeDamage(dtRangedAttack, m_Creator, TotalDamage, 1); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); } From d64db443c2d0f094c4ee098fa1ffacb2c92e5d88 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 18:10:15 +0200 Subject: [PATCH 12/19] LineCoeff Doc --- src/Vector3.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index 0be52248d..8ee7a87b0 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -10,10 +10,6 @@ - - - - template // tolua_begin class Vector3 @@ -196,6 +192,11 @@ public: ); } + /** 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 & a_OtherEnd, T a_Z) const { if (abs(z - a_OtherEnd.z) < EPS) @@ -206,6 +207,11 @@ public: 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 & a_OtherEnd, T a_Y) const { if (abs(y - a_OtherEnd.y) < EPS) @@ -216,6 +222,11 @@ public: 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 & a_OtherEnd, T a_X) const { if (abs(x - a_OtherEnd.x) < EPS) @@ -231,9 +242,14 @@ public: /** Return value of LineCoeffToPlane() if the line is parallel to the plane. */ static const double NO_INTERSECTION; + }; // tolua_end + + + + template const double Vector3::EPS = 0.000001; From 9810d57a394b2bb56fbcfddb05d34dcd504a7b35 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 18:32:33 +0200 Subject: [PATCH 13/19] Unified Matrix4 code --- src/Bindings/AllToLua.pkg | 1 - src/CMakeLists.txt | 1 - src/Entities/Entity.cpp | 2 +- src/Matrix4.h | 228 ++++++++++++++++++++++++++++++++++++++ src/Matrix4f.cpp | 4 - src/Matrix4f.h | 225 ------------------------------------- src/Vector3.h | 2 +- 7 files changed, 230 insertions(+), 233 deletions(-) create mode 100644 src/Matrix4.h delete mode 100644 src/Matrix4f.cpp delete mode 100644 src/Matrix4f.h diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 302714318..1cd7c74f8 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -63,7 +63,6 @@ $cfile "../BlockEntities/MobHeadEntity.h" $cfile "../BlockEntities/FlowerPotEntity.h" $cfile "../WebAdmin.h" $cfile "../Root.h" -$cfile "../Matrix4f.h" $cfile "../Cuboid.h" $cfile "../BoundingBox.h" $cfile "../Tracer.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04736c2d7..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 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/Matrix4.h b/src/Matrix4.h new file mode 100644 index 000000000..14ccb94fd --- /dev/null +++ b/src/Matrix4.h @@ -0,0 +1,228 @@ + +#pragma once + + + + +#include + + + + + +template +// tolua_begin +class Matrix4 +{ + + TOLUA_TEMPLATE_BIND((T, float, double)) + + // tolua_end + +public: + + T cell[16]; + + enum + { + TX=3, TY=7, TZ=11, + D0=0, D1=5, D2=10, D3=15, + SX=D0, SY=D1, SZ=D2, + W=D3 + }; + + // 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[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; + } + + inline void Init(const Vector3 & a_Pos, T a_RX, T a_RY, T a_RZ) + { + Matrix4 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 & a_Pos) + { + cell[TX] += a_Pos.x; + cell[TY] += a_Pos.y; + cell[TZ] += a_Pos.z; + } + + inline void SetTranslation(const Vector3 & a_Pos) + { + cell[TX] = a_Pos.x; + cell[TY] = a_Pos.y; + cell[TZ] = 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] * 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] + ); + } + } + + *this = res; + } + + inline Vector3 Transform(const Vector3 & 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(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 GetXColumn(void) const + { + return Vector3(cell[0], cell[1], cell[2]); + } + + inline Vector3 GetYColumn(void) const + { + return Vector3(cell[4], cell[5], cell[6]); + } + + inline Vector3 GetZColumn(void) const + { + return Vector3(cell[8], cell[9], cell[10]); + } + + inline void SetXColumn(const Vector3 & a_X) + { + cell[0] = a_X.x; + cell[1] = a_X.y; + cell[2] = a_X.z; + } + + inline void SetYColumn(const Vector3 & a_Y) + { + cell[4] = a_Y.x; + cell[5] = a_Y.y; + cell[6] = a_Y.z; + } + + inline void SetZColumn(const Vector3 & a_Z) + { + cell[8] = a_Z.x; + cell[9] = a_Z.y; + cell[10] = a_Z.z; + } +}; +// tolua_end + + + + +// tolua_begin +typedef Matrix4 Matrix4d; +typedef Matrix4 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 0e36974ad..000000000 --- a/src/Matrix4f.h +++ /dev/null @@ -1,225 +0,0 @@ -#pragma once - -#define _USE_MATH_DEFINES -#include -#include "Vector3.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/Vector3.h b/src/Vector3.h index 8ee7a87b0..841c3e7d1 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -22,7 +22,7 @@ public: T x, y, z; - inline Vector3() : x(0), y(0), z(0) {} + 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) {} From abf4effaaf0eff1a98e005512f805211c2fad9a7 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 21:58:50 +0200 Subject: [PATCH 14/19] Matrix4: Removed enum --- src/Matrix4.h | 40 ++++++++++++++++++---------------------- src/Vector3.h | 6 ++++++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Matrix4.h b/src/Matrix4.h index 14ccb94fd..a20c019e9 100644 --- a/src/Matrix4.h +++ b/src/Matrix4.h @@ -23,14 +23,6 @@ public: T cell[16]; - enum - { - TX=3, TY=7, TZ=11, - D0=0, D1=5, D2=10, D3=15, - SX=D0, SY=D1, SZ=D2, - W=D3 - }; - // tolua_begin inline Matrix4(void) @@ -60,9 +52,11 @@ public: inline 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; + 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 & a_Pos, T a_RX, T a_RY, T a_RZ) @@ -83,7 +77,8 @@ public: Identity(); - cell[5] = cx, cell[6] = sx, cell[9] = -sx, cell[10] = cx; + cell[5] = cx; cell[6] = sx; + cell[9] = -sx; cell[10] = cx; } inline void RotateY(T a_RY) @@ -93,7 +88,8 @@ public: Identity(); - cell[0] = cy, cell[2] = -sy, cell[8] = sy, cell[10] = cy; + cell[0] = cy; cell[2] = -sy; + cell[8] = sy; cell[10] = cy; } inline void RotateZ(T a_RZ) @@ -109,16 +105,16 @@ public: inline void Translate(const Vector3 & a_Pos) { - cell[TX] += a_Pos.x; - cell[TY] += a_Pos.y; - cell[TZ] += a_Pos.z; + cell[3] += a_Pos.x; + cell[7] += a_Pos.y; + cell[11] += a_Pos.z; } inline void SetTranslation(const Vector3 & a_Pos) { - cell[TX] = a_Pos.x; - cell[TY] = a_Pos.y; - cell[TZ] = a_Pos.z; + cell[3] = a_Pos.x; + cell[7] = a_Pos.y; + cell[11] = a_Pos.z; } inline void Concatenate(const Matrix4 & m2) @@ -130,7 +126,7 @@ public: for (unsigned int r = 0; r < 4; ++r) { res.cell[r * 4 + c] = ( - cell[r * 4] * m2.cell[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] @@ -207,8 +203,8 @@ public: inline void SetZColumn(const Vector3 & a_Z) { - cell[8] = a_Z.x; - cell[9] = a_Z.y; + cell[8] = a_Z.x; + cell[9] = a_Z.y; cell[10] = a_Z.z; } }; diff --git a/src/Vector3.h b/src/Vector3.h index 841c3e7d1..79c47ae77 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -26,6 +26,12 @@ public: 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 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + + // tolua_end template Vector3(const Vector3<_T> & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} From 0c15fdf7b05ee6ad0705b2a789f6b709bbde2733 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 13:05:28 +0100 Subject: [PATCH 15/19] Moved Lua API registering into a separate function. This will allow us to use Lua as lite-config files as well, should we want to. --- src/Bindings/LuaState.cpp | 10 +++++++++- src/Bindings/LuaState.h | 7 ++++++- src/Bindings/PluginLua.cpp | 1 + src/WebAdmin.cpp | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index aa6ee05b3..1f0549a59 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; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 4a7a6fadb..1495c72f0 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -139,9 +139,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/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"); From 5d7df54e35e99d41f69a44c5ea9c78a98fb557d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 14:11:28 +0100 Subject: [PATCH 16/19] Fixed Lua string return values. Fixes #773. --- src/Bindings/LuaState.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 1f0549a59..dfc428bbc 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -742,10 +742,6 @@ void cLuaState::GetStackValue(int a_StackPos, AString & a_Value) { a_Value.assign(data, len); } - else - { - a_Value.clear(); - } } From a3a94436dcc1cc95c1476c8a88400b16ac279e71 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 12 Mar 2014 15:13:19 +0200 Subject: [PATCH 17/19] Vector3: Length() should always return a float --- src/Vector3.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index 79c47ae77..80583879a 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -27,9 +27,9 @@ public: // Hardcoded copy constructors (tolua++ does not support function templates .. yet) - Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} - Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} - Vector3(const Vector3 & a_Rhs) : x(a_Rhs.x), y(a_Rhs.y), z(a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {} + Vector3(const Vector3 & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {} // tolua_end @@ -50,7 +50,7 @@ public: inline void Normalize(void) { - T Len = 1.0 / Length(); + double Len = 1.0 / Length(); x *= Len; y *= Len; @@ -59,7 +59,7 @@ public: inline Vector3 NormalizeCopy(void) const { - T Len = 1.0 / Length(); + double Len = 1.0 / Length(); return Vector3( x * Len, @@ -70,7 +70,7 @@ public: inline void NormalizeCopy(Vector3 & a_Rhs) const { - T Len = 1.0 / Length(); + double Len = 1.0 / Length(); a_Rhs.Set( x * Len, @@ -79,12 +79,12 @@ public: ); } - inline T Length(void) const + inline double Length(void) const { - return sqrt(x * x + y * y + z * z); + return sqrt((double)(x * x + y * y + z * z)); } - inline T SqrLength(void) const + inline double SqrLength(void) const { return x * x + y * y + z * z; } From 6f2bb0ad44592ac42334dc627afd3ad734b7a4ab Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 12 Mar 2014 16:13:03 +0200 Subject: [PATCH 18/19] M_PI MSVC Fix --- src/Matrix4.h | 2 +- src/Vector3.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Matrix4.h b/src/Matrix4.h index a20c019e9..456677f0f 100644 --- a/src/Matrix4.h +++ b/src/Matrix4.h @@ -3,7 +3,7 @@ - +#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC) #include diff --git a/src/Vector3.h b/src/Vector3.h index 80583879a..b7a810fc5 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -3,7 +3,7 @@ - +#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC) #include From d545be9614e9d6717d19794ea8a49b6d4a0da52f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 15:33:28 +0100 Subject: [PATCH 19/19] Fixed missing comment terminator. --- src/Generating/PieceGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index e3de5b951..cf5ab6226 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -377,7 +377,7 @@ 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, 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},