From 0f1fd3312332da2a6104c9eb98625610a4a08eff Mon Sep 17 00:00:00 2001 From: Hownaer Date: Thu, 28 Aug 2014 01:21:54 +0200 Subject: Enchanting table improvements. --- src/Item.cpp | 32 ++++----- src/UI/SlotArea.cpp | 192 +++++++++++++++++++++------------------------------- src/UI/SlotArea.h | 7 +- src/UI/Window.cpp | 33 +++++---- src/UI/Window.h | 3 - 5 files changed, 113 insertions(+), 154 deletions(-) diff --git a/src/Item.cpp b/src/Item.cpp index 2c5deaddf..a5117c271 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -190,31 +190,23 @@ void cItem::FromJson(const Json::Value & a_Value) -bool cItem::IsEnchantable(short item) +bool cItem::IsEnchantable(short a_ItemType) { - if ((item >= 256) && (item <= 259)) + if (ItemCategory::IsTool(a_ItemType) || ItemCategory::IsArmor(a_ItemType)) { return true; } - if ((item >= 267) && (item <= 279)) - { - return true; - } - if ((item >= 283) && (item <= 286)) - { - return true; - } - if ((item >= 290) && (item <= 294)) - { - return true; - } - if ((item >= 298) && (item <= 317)) - { - return true; - } - if ((item == 346) || (item == 359) || (item == 261)) + + switch (a_ItemType) { - return true; + case E_ITEM_BOOK: + case E_ITEM_BOW: + case E_ITEM_CARROT_ON_STICK: + case E_ITEM_FISHING_ROD: + case E_ITEM_SHEARS: + { + return true; + } } return false; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 4199bbf56..74173d087 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -207,7 +207,7 @@ void cSlotArea::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ m_ParentWindow.DistributeStack(Slot, a_Player, this, true); if (Slot.IsEmpty()) { - // Empty the slot completely, the cilent doesn't like left-over ItemType with zero count + // Empty the slot completely, the client doesn't like left-over ItemType with zero count Slot.Empty(); } SetSlot(a_SlotNum, a_Player, Slot); @@ -1389,8 +1389,11 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) //////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnchanting: -cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) : - cSlotAreaTemporary(1, a_ParentWindow) +cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) : + cSlotAreaTemporary(1, a_ParentWindow), + m_BlockX(a_BlockX), + m_BlockY(a_BlockY), + m_BlockZ(a_BlockZ) { a_ParentWindow.m_SlotArea = this; } @@ -1409,7 +1412,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); return; } - + switch (a_ClickAction) { case caShiftLeftClick: @@ -1420,7 +1423,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio } case caDblClick: { - DblClicked(a_Player, a_SlotNum); + // DblClicked(a_Player, a_SlotNum); return; } case caMiddleClick: @@ -1428,6 +1431,25 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio MiddleClicked(a_Player, a_SlotNum); return; } + case caDropKey: + case caCtrlDropKey: + { + DropClicked(a_Player, a_SlotNum, false); + return; + } + case caNumber1: + case caNumber2: + case caNumber3: + case caNumber4: + case caNumber5: + case caNumber6: + case caNumber7: + case caNumber8: + case caNumber9: + { + NumberClicked(a_Player, a_SlotNum, a_ClickAction); + return; + } default: { break; @@ -1443,106 +1465,37 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio bAsync = true; } cItem & DraggingItem = a_Player.GetDraggingItem(); - switch (a_ClickAction) + + if (DraggingItem.IsEmpty()) { - case caRightClick: - { - // Right-clicked - if (DraggingItem.IsEmpty()) - { - DraggingItem = Slot.CopyOne(); - Slot.Empty(); - break; - } - - if (Slot.IsEmpty()) - { - Slot = DraggingItem.CopyOne(); - DraggingItem.m_ItemCount -= 1; - if (DraggingItem.m_ItemCount <= 0) - { - DraggingItem.Empty(); - } - } - else if ((!DraggingItem.IsEqual(Slot)) && (DraggingItem.m_ItemCount == 1)) - { - // Swap contents - cItem tmp(DraggingItem); - DraggingItem = Slot; - Slot = tmp; - } - break; - } - - case caLeftClick: + if (!Slot.IsEmpty()) { - // Left-clicked - if (DraggingItem.IsEmpty()) - { - DraggingItem = Slot.CopyOne(); - Slot.Empty(); - break; - } - - if (DraggingItem.IsEqual(Slot)) - { - // Do nothing - break; - } - - if (!Slot.IsEmpty()) - { - if (DraggingItem.m_ItemCount == 1) - { - // Swap contents - cItem tmp(DraggingItem); - DraggingItem = Slot; - Slot = tmp; - } - } - else - { - Slot = DraggingItem.CopyOne(); - DraggingItem.m_ItemCount -= 1; - if (DraggingItem.m_ItemCount <= 0) - { - DraggingItem.Empty(); - } - } - break; + DraggingItem = Slot; + Slot.Empty(); } - default: + } + else if (Slot.IsEmpty()) + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + + if (DraggingItem.m_ItemCount <= 0) { - LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction)); - m_ParentWindow.BroadcastWholeWindow(); - return; + DraggingItem.Empty(); } - } // switch (a_ClickAction - - SetSlot(a_SlotNum, a_Player, Slot); - if (bAsync) - { - m_ParentWindow.BroadcastWholeWindow(); } - UpdateResult(a_Player); -} - - - - - -void cSlotAreaEnchanting::DblClicked(cPlayer & a_Player, int a_SlotNum) -{ - cItem & Dragging = a_Player.GetDraggingItem(); - if ((!Dragging.IsEmpty()) || (a_SlotNum != 0)) + else if ((DraggingItem.m_ItemCount == 1) && !DraggingItem.IsEqual(Slot)) { - return; + // Switch contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; } - - cItem Item = *GetSlot(0, a_Player); - if (!m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, false)) + + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) { - m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, true); + m_ParentWindow.BroadcastWholeWindow(); } } @@ -1567,7 +1520,15 @@ void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Playe { a_ItemStack.Empty(); } +} + + + + +void cSlotAreaEnchanting::OnPlayerAdded(cPlayer & a_Player) +{ + super::OnPlayerAdded(a_Player); UpdateResult(a_Player); } @@ -1587,29 +1548,33 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +void cSlotAreaEnchanting::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) +{ + super::SetSlot(a_SlotNum, a_Player, a_Item); + UpdateResult(a_Player); +} + + + + + void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); - if (Item.IsEmpty() || !Item.m_Enchantments.IsEmpty()) - { - m_ParentWindow.SetProperty(0, 0, a_Player); - m_ParentWindow.SetProperty(1, 0, a_Player); - m_ParentWindow.SetProperty(2, 0, a_Player); - } - else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) + if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) { int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15); cFastRandom Random; - int base = (Random.GenerateRandomInteger(1, 8) + (int)floor((float)Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); - int topSlot = std::max(base / 3, 1); - int middleSlot = (base * 2) / 3 + 1; - int bottomSlot = std::max(base, Bookshelves * 2); + int Base = (Random.GenerateRandomInteger(1, 8) + (int)floor((float)Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); + int TopSlot = std::max(Base / 3, 1); + int MiddleSlot = (Base * 2) / 3 + 1; + int BottomSlot = std::max(Base, Bookshelves * 2); - m_ParentWindow.SetProperty(0, topSlot, a_Player); - m_ParentWindow.SetProperty(1, middleSlot, a_Player); - m_ParentWindow.SetProperty(2, bottomSlot, a_Player); + m_ParentWindow.SetProperty(0, TopSlot, a_Player); + m_ParentWindow.SetProperty(1, MiddleSlot, a_Player); + m_ParentWindow.SetProperty(2, BottomSlot, a_Player); } else { @@ -1625,12 +1590,9 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) { - int PosX, PosY, PosZ; - ((cEnchantingWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); - int Bookshelves = 0; cBlockArea Area; - Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); + Area.Read(a_World, m_BlockX - 2, m_BlockX + 2, m_BlockY, m_BlockY + 1, m_BlockZ - 2, m_BlockZ + 2); static const struct { @@ -1678,7 +1640,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) if ( (Area.GetRelBlockType(CheckCoords[i].m_AirX, CheckCoords[i].m_AirY, CheckCoords[i].m_AirZ) == E_BLOCK_AIR) && // There's air in the checkspot (Area.GetRelBlockType(CheckCoords[i].m_BookX, CheckCoords[i].m_BookY, CheckCoords[i].m_BookZ) == E_BLOCK_BOOKCASE) // There's bookcase in the wanted place - ) + ) { Bookshelves++; } diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 9a96f2f3c..6bbc87b76 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -349,14 +349,15 @@ class cSlotAreaEnchanting : typedef cSlotAreaTemporary super; public: - cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow); + cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ); // cSlotArea overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; - virtual void DblClicked(cPlayer & a_Player, int a_SlotNum) override; virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; + virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; // cSlotAreaTemporary overrides: + virtual void OnPlayerAdded (cPlayer & a_Player) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; /* Get the count of bookshelves who stand in the near of the enchanting table */ @@ -365,6 +366,8 @@ public: protected: /** Handles a click in the item slot. */ void UpdateResult(cPlayer & a_Player); + + int m_BlockX, m_BlockY, m_BlockZ; }; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 8f4913030..66900269f 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -881,7 +881,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : m_BlockY(a_BlockY), m_BlockZ(a_BlockZ) { - m_SlotAreas.push_back(new cSlotAreaEnchanting(*this)); + m_SlotAreas.push_back(new cSlotAreaEnchanting(*this, m_BlockX, m_BlockY, m_BlockZ)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); } @@ -892,8 +892,13 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : void cEnchantingWindow::SetProperty(int a_Property, int a_Value) { - m_PropertyValue[a_Property] = a_Value; + if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) + { + ASSERT(!"a_Property is invalid"); + return; + } + m_PropertyValue[a_Property] = a_Value; super::SetProperty(a_Property, a_Value); } @@ -903,8 +908,13 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value) void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) { - m_PropertyValue[a_Property] = a_Value; + if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) + { + ASSERT(!"a_Property is invalid"); + return; + } + m_PropertyValue[a_Property] = a_Value; super::SetProperty(a_Property, a_Value, a_Player); } @@ -914,18 +924,13 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla int cEnchantingWindow::GetPropertyValue(int a_Property) { - return m_PropertyValue[a_Property]; -} - - - - + if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) + { + ASSERT(!"a_Property is invalid"); + return 0; + } -void cEnchantingWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ) -{ - a_PosX = m_BlockX; - a_PosY = m_BlockY; - a_PosZ = m_BlockZ; + return m_PropertyValue[a_Property]; } diff --git a/src/UI/Window.h b/src/UI/Window.h index 9fb0e3b38..3d860407f 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -291,9 +291,6 @@ public: /** Return the Value of a Property */ int GetPropertyValue(int a_Property); - /** Get the Position from the Enchantment Table */ - void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); - cSlotArea * m_SlotArea; protected: -- cgit v1.2.3 From 3c1c073714e2b0542c9a79db962b6fc9e6ddd352 Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Thu, 28 Aug 2014 11:36:35 +0200 Subject: remove y-coord from chunks --- src/Bindings/LuaChunkStay.cpp | 2 +- src/Chunk.cpp | 7 +- src/Chunk.h | 2 +- src/ChunkDef.h | 6 +- src/ChunkMap.cpp | 258 +++++++++++++++++++------------------- src/ChunkMap.h | 14 +-- src/ChunkSender.cpp | 14 +-- src/ChunkSender.h | 7 +- src/ChunkStay.cpp | 2 +- src/ClientHandle.cpp | 20 +-- src/ClientHandle.h | 2 +- src/Generating/ChunkGenerator.cpp | 14 +-- src/Generating/ChunkGenerator.h | 4 +- src/World.cpp | 21 ++-- src/World.h | 6 +- src/WorldStorage/WSSCompact.cpp | 6 +- src/WorldStorage/WorldStorage.cpp | 28 ++--- src/WorldStorage/WorldStorage.h | 12 +- 18 files changed, 208 insertions(+), 217 deletions(-) diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index 59b02d8f7..154bcb200 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -107,7 +107,7 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index) } } // for itr - m_Chunks[] - m_Chunks.push_back(cChunkCoords(ChunkX, ZERO_CHUNK_Y, ChunkZ)); + m_Chunks.push_back(cChunkCoords(ChunkX, ChunkZ)); } diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 116c0f3a0..5fd6cb352 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -65,7 +65,7 @@ sSetBlock::sSetBlock( int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_Bloc // cChunk: cChunk::cChunk( - int a_ChunkX, int a_ChunkY, int a_ChunkZ, + int a_ChunkX, int a_ChunkZ, cChunkMap * a_ChunkMap, cWorld * a_World, cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, cAllocationPool & a_Pool @@ -77,7 +77,6 @@ cChunk::cChunk( m_HasLoadFailed(false), m_StayCount(0), m_PosX(a_ChunkX), - m_PosY(a_ChunkY), m_PosZ(a_ChunkZ), m_World(a_World), m_ChunkMap(a_ChunkMap), @@ -643,7 +642,7 @@ void cChunk::MoveEntityToNewChunk(cEntity * a_Entity) cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width); if (Neighbor == NULL) { - Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); + Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); if (Neighbor == NULL) { // TODO: What to do with this? @@ -2593,7 +2592,7 @@ cChunk * cChunk::GetRelNeighborChunk(int a_RelX, int a_RelZ) int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ; int ChunkX, ChunkZ; BlockToChunk(BlockX, BlockZ, ChunkX, ChunkZ); - return m_ChunkMap->GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + return m_ChunkMap->GetChunkNoLoad(ChunkX, ChunkZ); } // Walk the neighbors: diff --git a/src/Chunk.h b/src/Chunk.h index 72a1f6c95..67b208fe5 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -67,7 +67,7 @@ class cChunk : { public: cChunk( - int a_ChunkX, int a_ChunkY, int a_ChunkZ, // Chunk coords + int a_ChunkX, int a_ChunkZ, // Chunk coords cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks cAllocationPool & a_Pool diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 51075ab4a..b7122efe2 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -19,7 +19,6 @@ /** This is really only a placeholder to be used in places where we need to "make up" a chunk's Y coord. It will help us when the new chunk format comes out and we need to patch everything up for compatibility. */ -#define ZERO_CHUNK_Y 0 // Used to smoothly convert to new axis ordering. One will be removed when deemed stable. #define AXIS_ORDER_YZX 1 // Original (1.1-) @@ -377,14 +376,13 @@ class cChunkCoords { public: int m_ChunkX; - int m_ChunkY; int m_ChunkZ; - cChunkCoords(int a_ChunkX, int a_ChunkY, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ) {} + cChunkCoords(int a_ChunkX, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ) {} bool operator == (const cChunkCoords & a_Other) const { - return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkY == a_Other.m_ChunkY) && (m_ChunkZ == a_Other.m_ChunkZ)); + return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ)); } } ; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index dd8be0631..e4ce6cbf5 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -143,7 +143,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayerForChunk(int a_ChunkX, int a_ChunkZ) -cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkZ) { // No need to lock m_CSLayers, since it's already locked by the operation that called us ASSERT(m_CSLayers.IsLockedByCurrentThread()); @@ -155,14 +155,14 @@ cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) return NULL; } - cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return NULL; } if (!(Chunk->IsValid())) { - m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ, true); + m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ, true); } return Chunk; } @@ -171,7 +171,7 @@ cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) -cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ) +cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkZ) { // No need to lock m_CSLayers, since it's already locked by the operation that called us cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ); @@ -181,14 +181,14 @@ cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ) return NULL; } - cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return NULL; } if (!(Chunk->IsValid())) { - m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ, false); + m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ, false); } return Chunk; @@ -198,7 +198,7 @@ cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ) -cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkY, int a_ChunkZ) +cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkZ) { // No need to lock m_CSLayers, since it's already locked by the operation that called us cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ); @@ -208,7 +208,7 @@ cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkY, int a_ChunkZ) return NULL; } - return Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + return Layer->GetChunk(a_ChunkX, a_ChunkZ); } @@ -222,7 +222,7 @@ bool cChunkMap::LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk == NULL) { return false; @@ -244,7 +244,7 @@ bool cChunkMap::LockedGetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLO int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk == NULL) { return false; @@ -265,7 +265,7 @@ bool cChunkMap::LockedGetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIB int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk == NULL) { return false; @@ -284,7 +284,7 @@ bool cChunkMap::LockedSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY // We already have m_CSLayers locked since this can be called only from within the tick thread int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk == NULL) { return false; @@ -303,7 +303,7 @@ bool cChunkMap::LockedFastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLO // We already have m_CSLayers locked since this can be called only from within the tick thread int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk == NULL) { return false; @@ -336,7 +336,7 @@ cChunk * cChunkMap::FindChunk(int a_ChunkX, int a_ChunkZ) void cChunkMap::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -356,7 +356,7 @@ void cChunkMap::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, c x = a_BlockX; z = a_BlockZ; cChunkDef::BlockToChunk(x, z, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -375,7 +375,7 @@ void cChunkMap::BroadcastBlockBreakAnimation(int a_entityID, int a_blockX, int a int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_blockX, a_blockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -393,7 +393,7 @@ void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -408,7 +408,7 @@ void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, 0, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return; @@ -424,7 +424,7 @@ void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSeriali void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -440,7 +440,7 @@ void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -456,7 +456,7 @@ void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHa void cChunkMap::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -472,7 +472,7 @@ void cChunkMap::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -488,7 +488,7 @@ void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotN void cChunkMap::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -504,7 +504,7 @@ void cChunkMap::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientH void cChunkMap::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -520,7 +520,7 @@ void cChunkMap::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandl void cChunkMap::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -536,7 +536,7 @@ void cChunkMap::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientH void cChunkMap::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -552,7 +552,7 @@ void cChunkMap::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, ch void cChunkMap::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -568,7 +568,7 @@ void cChunkMap::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -584,7 +584,7 @@ void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, c void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -600,7 +600,7 @@ void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientH void cChunkMap::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -619,7 +619,7 @@ void cChunkMap::BroadcastParticleEffect(const AString & a_ParticleName, float a_ int ChunkX, ChunkZ; cChunkDef::BlockToChunk((int) a_SrcX, (int) a_SrcZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -636,7 +636,7 @@ void cChunkMap::BroadcastRemoveEntityEffect(const cEntity & a_Entity, int a_Effe { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -655,7 +655,7 @@ void cChunkMap::BroadcastSoundEffect(const AString & a_SoundName, double a_X, do int ChunkX, ChunkZ; cChunkDef::BlockToChunk((int)std::floor(a_X), (int)std::floor(a_Z), ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -674,7 +674,7 @@ void cChunkMap::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_S int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_SrcX, a_SrcZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -690,7 +690,7 @@ void cChunkMap::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_S void cChunkMap::BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ()); if (Chunk == NULL) { return; @@ -708,7 +708,7 @@ void cChunkMap::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, c cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -727,7 +727,7 @@ void cChunkMap::BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bl int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -745,7 +745,7 @@ void cChunkMap::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClien cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -763,7 +763,7 @@ void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -778,7 +778,7 @@ void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return false; @@ -795,7 +795,7 @@ void cChunkMap::WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -824,7 +824,7 @@ void cChunkMap::WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_M int MaxZ = std::min(a_MaxBlockZ, z * cChunkDef::Width + cChunkDef::Width - 1); for (int x = MinChunkX; x <= MaxChunkX; x++) { - cChunkPtr Chunk = GetChunkNoGen(x, 0, z); + cChunkPtr Chunk = GetChunkNoGen(x, z); if ((Chunk == NULL) || !Chunk->IsValid()) { continue; @@ -852,7 +852,7 @@ void cChunkMap::WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_M void cChunkMap::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -867,7 +867,7 @@ void cChunkMap::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDirty) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -886,7 +886,7 @@ void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDi void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -901,7 +901,7 @@ void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -919,7 +919,7 @@ void cChunkMap::SetChunkData(cSetChunkData & a_SetChunkData) int ChunkZ = a_SetChunkData.GetChunkZ(); { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk == NULL) { return; @@ -964,7 +964,7 @@ void cChunkMap::ChunkLighted( ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return; @@ -980,7 +980,7 @@ void cChunkMap::ChunkLighted( bool cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -996,7 +996,7 @@ bool cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_ bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -1012,7 +1012,7 @@ bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blo bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); return (Chunk != NULL) && Chunk->IsValid(); } @@ -1023,7 +1023,7 @@ bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ) bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); return (Chunk != NULL) && Chunk->HasAnyClients(); } @@ -1038,7 +1038,7 @@ int cChunkMap::GetHeight(int a_BlockX, int a_BlockZ) cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ, BlockY = 0; cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); if (Chunk == NULL) { return 0; @@ -1065,7 +1065,7 @@ bool cChunkMap::TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height) cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ, BlockY = 0; cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -1088,7 +1088,7 @@ void cChunkMap::FastSetBlocks(sSetBlockList & a_BlockList) int ChunkX = a_BlockList.front().ChunkX; int ChunkZ = a_BlockList.front().ChunkZ; cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { for (sSetBlockList::iterator itr = a_BlockList.begin(); itr != a_BlockList.end();) @@ -1135,7 +1135,7 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player) int BlockX = (int)(a_Player->GetPosX()); // Truncating doesn't matter much; we're scanning entire chunks anyway int BlockY = (int)(a_Player->GetPosY()); int BlockZ = (int)(a_Player->GetPosZ()); - int ChunkX, ChunkZ, ChunkY = ZERO_CHUNK_Y; + int ChunkX = 0, ChunkZ = 0; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); int OtherChunkX = ChunkX + ((BlockX > 8) ? 1 : -1); int OtherChunkZ = ChunkZ + ((BlockZ > 8) ? 1 : -1); @@ -1144,13 +1144,13 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player) // The only time the chunks are not valid is when the player is downloading the initial world and they should not call this at that moment cCSLock Lock(m_CSLayers); - GetChunkNoLoad(ChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer(a_Player); + GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer(a_Player); // Check the neighboring chunks as well: - GetChunkNoLoad(OtherChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer (a_Player); - GetChunkNoLoad(OtherChunkX, ChunkY, OtherChunkZ)->CollectPickupsByPlayer(a_Player); - GetChunkNoLoad(ChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer (a_Player); - GetChunkNoLoad(ChunkX, ChunkY, OtherChunkZ)->CollectPickupsByPlayer(a_Player); + GetChunkNoLoad(OtherChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player); + GetChunkNoLoad(OtherChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player); + GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player); + GetChunkNoLoad(ChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player); } @@ -1177,7 +1177,7 @@ BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { return Chunk->GetBlock(a_BlockX, a_BlockY, a_BlockZ); @@ -1206,7 +1206,7 @@ NIBBLETYPE cChunkMap::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { return Chunk->GetMeta(a_BlockX, a_BlockY, a_BlockZ); @@ -1224,7 +1224,7 @@ NIBBLETYPE cChunkMap::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ) cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { return Chunk->GetSkyLight(a_BlockX, a_BlockY, a_BlockZ); @@ -1242,7 +1242,7 @@ NIBBLETYPE cChunkMap::GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_Block cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { return Chunk->GetBlockLight(a_BlockX, a_BlockY, a_BlockZ); @@ -1261,7 +1261,7 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP // a_BlockXYZ now contains relative coords! cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->SetMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); @@ -1284,7 +1284,7 @@ void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_SendToClients); @@ -1303,7 +1303,7 @@ void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYP cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->QueueSetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_Tick, a_PreviousBlockType); @@ -1320,7 +1320,7 @@ bool cChunkMap::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCK cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->GetBlockTypeMeta(X, Y, Z, a_BlockType, a_BlockMeta); @@ -1339,7 +1339,7 @@ bool cChunkMap::GetBlockInfo(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->GetBlockInfo(X, Y, Z, a_BlockType, a_Meta, a_SkyLight, a_BlockLight); @@ -1357,7 +1357,7 @@ void cChunkMap::ReplaceBlocks(const sSetBlockVector & a_Blocks, BLOCKTYPE a_Filt cCSLock Lock(m_CSLayers); for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) { - cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ); + cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { continue; @@ -1378,7 +1378,7 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) cCSLock Lock(m_CSLayers); for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) { - cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ); + cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { continue; @@ -1413,7 +1413,7 @@ EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ) cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { return Chunk->GetBiomeAt(X, Z); @@ -1434,7 +1434,7 @@ bool cChunkMap::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome) cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->SetBiomeAt(X, Z, a_Biome); @@ -1467,7 +1467,7 @@ bool cChunkMap::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMC { int MinRelZ = (z == MinChunkZ) ? MinZ : 0; int MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1; - cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z); + cChunkPtr Chunk = GetChunkNoLoad(x, z); if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome); @@ -1491,7 +1491,7 @@ bool cChunkMap::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure) cCSLock Lock(m_CSLayers); for (sSetBlockVector::iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) { - cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ); + cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { if (!a_ContinueOnFailure) @@ -1519,7 +1519,7 @@ bool cChunkMap::DigBlock(int a_X, int a_Y, int a_Z) { cCSLock Lock(m_CSLayers); - cChunkPtr DestChunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr DestChunk = GetChunk( ChunkX, ChunkZ); if ((DestChunk == NULL) || !DestChunk->IsValid()) { return false; @@ -1542,7 +1542,7 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player) cChunkDef::AbsoluteToRelative(a_X, a_Y, a_Z, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); if ((Chunk != NULL) && (Chunk->IsValid())) { Chunk->SendBlockTo(a_X, a_Y, a_Z, a_Player->GetClientHandle()); @@ -1556,12 +1556,12 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player) void cChunkMap::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, ZERO_CHUNK_Y, a_ChunkZ1); + cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, a_ChunkZ1); if (Chunk1 == NULL) { return; } - cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, ZERO_CHUNK_Y, a_ChunkZ2); + cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, a_ChunkZ2); if (Chunk2 == NULL) { return; @@ -1623,7 +1623,7 @@ void cChunkMap::CompareChunkClients(cChunk * a_Chunk1, cChunk * a_Chunk2, cClien bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunk(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return false; @@ -1638,7 +1638,7 @@ bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Cli void cChunkMap::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return; @@ -1667,7 +1667,7 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client) void cChunkMap::AddEntity(cEntity * a_Entity) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); if ( (Chunk == NULL) || // Chunk not present at all (!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953) @@ -1688,7 +1688,7 @@ void cChunkMap::AddEntity(cEntity * a_Entity) void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); if ( (Chunk == NULL) || // Chunk not present at all (!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953) @@ -1729,7 +1729,7 @@ bool cChunkMap::HasEntity(int a_UniqueID) void cChunkMap::RemoveEntity(cEntity * a_Entity) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); // Even if a chunk is not valid, it may still contain entities such as players; make sure to remove them (#1190) if (Chunk == NULL) @@ -1763,7 +1763,7 @@ bool cChunkMap::ForEachEntity(cEntityCallback & a_Callback) bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2011,7 +2011,7 @@ bool cChunkMap::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback) bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2026,7 +2026,7 @@ bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEnti bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2041,7 +2041,7 @@ bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2056,7 +2056,7 @@ bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCa bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2071,7 +2071,7 @@ bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallba bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2086,7 +2086,7 @@ bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpens bool cChunkMap::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2104,7 +2104,7 @@ bool cChunkMap::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cB int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2122,7 +2122,7 @@ bool cChunkMap::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeacon int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2140,7 +2140,7 @@ bool cChunkMap::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCa int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2158,7 +2158,7 @@ bool cChunkMap::DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDis int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2176,7 +2176,7 @@ bool cChunkMap::DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropp int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2194,7 +2194,7 @@ bool cChunkMap::DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cD int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2212,7 +2212,7 @@ bool cChunkMap::DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurna int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2229,7 +2229,7 @@ bool cChunkMap::DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNot int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2246,7 +2246,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2264,7 +2264,7 @@ bool cChunkMap::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHe int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2282,7 +2282,7 @@ bool cChunkMap::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlo int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2300,7 +2300,7 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2312,10 +2312,10 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & -void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + GetChunk(a_ChunkX, a_ChunkZ); } @@ -2323,11 +2323,11 @@ void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) /// Loads the chunk synchronously, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) -bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkZ) { { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { // Internal error @@ -2344,7 +2344,7 @@ bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) return false; } } - return m_World->GetStorage().LoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + return m_World->GetStorage().LoadChunk(a_ChunkX, a_ChunkZ); } @@ -2356,7 +2356,7 @@ void cChunkMap::LoadChunks(const cChunkCoordsList & a_Chunks) { for (cChunkCoordsList::const_iterator itr = a_Chunks.begin(); itr != a_Chunks.end(); ++itr) { - LoadChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); + LoadChunk(itr->m_ChunkX, itr->m_ChunkZ); } // for itr - a_Chunks[] } @@ -2364,10 +2364,10 @@ void cChunkMap::LoadChunks(const cChunkCoordsList & a_Chunks) -void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkY, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { return; @@ -2384,7 +2384,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return false; @@ -2399,7 +2399,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { // Not present @@ -2415,7 +2415,7 @@ void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ) bool cChunkMap::IsChunkLighted(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); if (Chunk == NULL) { // Not present @@ -2436,7 +2436,7 @@ bool cChunkMap::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinCh { for (int x = a_MinChunkX; x <= a_MaxChunkX; x++) { - cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z); + cChunkPtr Chunk = GetChunkNoLoad(x, z); if ((Chunk == NULL) || (!Chunk->IsValid())) { // Not present / not valid @@ -2478,7 +2478,7 @@ bool cChunkMap::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBl { for (int x = MinChunkX; x <= MaxChunkX; x++) { - cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z); + cChunkPtr Chunk = GetChunkNoLoad(x, z); if ((Chunk == NULL) || (!Chunk->IsValid())) { // Not present / not valid @@ -2519,7 +2519,7 @@ void cChunkMap::GrowMelonPumpkin(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCK cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk != NULL) { Chunk->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_Rand); @@ -2536,7 +2536,7 @@ void cChunkMap::GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Nu cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk != NULL) { Chunk->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow); @@ -2553,7 +2553,7 @@ void cChunkMap::GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBl cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk != NULL) { Chunk->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow); @@ -2570,7 +2570,7 @@ void cChunkMap::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ) cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk != NULL) { Chunk->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ); @@ -2625,7 +2625,7 @@ void cChunkMap::TickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if ((Chunk == NULL) || !Chunk->IsValid()) { return; @@ -2694,7 +2694,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) // a_BlockXYZ now contains relative coords! cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); if (Chunk != NULL) { Chunk->QueueTickBlock(a_BlockX, a_BlockY, a_BlockZ); @@ -2708,7 +2708,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) void cChunkMap::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); if (Chunk != NULL) { Chunk->SetAlwaysTicked(a_AlwaysTicked); @@ -2753,7 +2753,7 @@ cChunkMap::cChunkLayer::~cChunkLayer() -cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ) +cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkZ) { // Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check @@ -2773,7 +2773,7 @@ cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_Ch cChunk * neixp = (LocalX < LAYER_SIZE - 1) ? m_Chunks[Index + 1] : m_Parent->FindChunk(a_ChunkX + 1, a_ChunkZ); cChunk * neizm = (LocalZ > 0) ? m_Chunks[Index - LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ - 1); cChunk * neizp = (LocalZ < LAYER_SIZE - 1) ? m_Chunks[Index + LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ + 1); - m_Chunks[Index] = new cChunk(a_ChunkX, 0, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool); + m_Chunks[Index] = new cChunk(a_ChunkX, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool); } return m_Chunks[Index]; } @@ -2973,7 +2973,7 @@ void cChunkMap::cChunkLayer::Save(void) { if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid() && m_Chunks[i]->IsDirty()) { - World->GetStorage().QueueSaveChunk(m_Chunks[i]->GetPosX(), m_Chunks[i]->GetPosY(), m_Chunks[i]->GetPosZ()); + World->GetStorage().QueueSaveChunk(m_Chunks[i]->GetPosX(), m_Chunks[i]->GetPosZ()); } } // for i - m_Chunks[] } @@ -3046,7 +3046,7 @@ void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay) const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks(); for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr) { - cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); + cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ); if (Chunk == NULL) { continue; @@ -3095,7 +3095,7 @@ void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay) const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks(); for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr) { - cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); + cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkZ); if (Chunk == NULL) { continue; diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 1e9a0f982..6a379e51d 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -270,16 +270,16 @@ public: bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible /** Touches the chunk, causing it to be loaded or generated */ - void TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void TouchChunk(int a_ChunkX, int a_ChunkZ); /** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */ - bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + bool LoadChunk(int a_ChunkX, int a_ChunkZ); /** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */ void LoadChunks(const cChunkCoordsList & a_Chunks); /** Marks the chunk as failed-to-load */ - void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ); /** Sets the sign text. Returns true if sign text changed. */ bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); @@ -363,7 +363,7 @@ private: ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ - cChunkPtr GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ); + cChunkPtr GetChunk( int a_ChunkX, int a_ChunkZ); /** Returns the specified chunk, or NULL if not created yet */ cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); @@ -456,9 +456,9 @@ private: std::auto_ptr > m_Pool; - cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid - cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate - cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Doesn't load, doesn't generate + cChunkPtr GetChunk (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid + cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate + cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkZ); // Doesn't load, doesn't generate /** Gets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */ bool LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index ebcf0e272..95c4d03d2 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -81,7 +81,7 @@ void cChunkSender::ChunkReady(int a_ChunkX, int a_ChunkZ) // This is probably never gonna be called twice for the same chunk, and if it is, we don't mind, so we don't check { cCSLock Lock(m_CS); - m_ChunksReady.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); + m_ChunksReady.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); } m_evtQueue.Set(); } @@ -95,12 +95,12 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle * ASSERT(a_Client != NULL); { cCSLock Lock(m_CS); - if (std::find(m_SendChunks.begin(), m_SendChunks.end(), sSendChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ, a_Client)) != m_SendChunks.end()) + if (std::find(m_SendChunks.begin(), m_SendChunks.end(), sSendChunk(a_ChunkX, a_ChunkZ, a_Client)) != m_SendChunks.end()) { // Already queued, bail out return; } - m_SendChunks.push_back(sSendChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ, a_Client)); + m_SendChunks.push_back(sSendChunk(a_ChunkX, a_ChunkZ, a_Client)); } m_evtQueue.Set(); } @@ -160,7 +160,7 @@ void cChunkSender::Execute(void) m_ChunksReady.pop_front(); Lock.Unlock(); - SendChunk(Coords.m_ChunkX, Coords.m_ChunkY, Coords.m_ChunkZ, NULL); + SendChunk(Coords.m_ChunkX, Coords.m_ChunkZ, NULL); } else { @@ -169,7 +169,7 @@ void cChunkSender::Execute(void) m_SendChunks.pop_front(); Lock.Unlock(); - SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkY, Chunk.m_ChunkZ, Chunk.m_Client); + SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, Chunk.m_Client); } Lock.Lock(); int RemoveCount = m_RemoveCount; @@ -186,14 +186,14 @@ void cChunkSender::Execute(void) -void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client) +void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) { ASSERT(m_World != NULL); // Ask the client if it still wants the chunk: if (a_Client != NULL) { - if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkY, a_ChunkZ)) + if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkZ)) { return; } diff --git a/src/ChunkSender.h b/src/ChunkSender.h index 624a3a0bd..a0e9087a9 100644 --- a/src/ChunkSender.h +++ b/src/ChunkSender.h @@ -95,13 +95,11 @@ protected: struct sSendChunk { int m_ChunkX; - int m_ChunkY; int m_ChunkZ; cClientHandle * m_Client; - sSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client) : + sSendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) : m_ChunkX(a_ChunkX), - m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Client(a_Client) { @@ -111,7 +109,6 @@ protected: { return ( (a_Other.m_ChunkX == m_ChunkX) && - (a_Other.m_ChunkY == m_ChunkY) && (a_Other.m_ChunkZ == m_ChunkZ) && (a_Other.m_Client == m_Client) ); @@ -162,7 +159,7 @@ protected: virtual void BlockEntity (cBlockEntity * a_Entity) override; /// Sends the specified chunk to a_Client, or to all chunk clients if a_Client == NULL - void SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client); + void SendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client); } ; diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp index b5002a63d..38aa89a37 100644 --- a/src/ChunkStay.cpp +++ b/src/ChunkStay.cpp @@ -51,7 +51,7 @@ void cChunkStay::Add(int a_ChunkX, int a_ChunkZ) return; } } // for itr - Chunks[] - m_Chunks.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); + m_Chunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8aa883144..18c1a32ef 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -472,13 +472,13 @@ void cClientHandle::StreamChunks(void) // For each distance touch chunks in a hollow square centered around current position: for (int i = -d; i <= d; ++i) { - World->TouchChunk(ChunkPosX + d, ZERO_CHUNK_Y, ChunkPosZ + i); - World->TouchChunk(ChunkPosX - d, ZERO_CHUNK_Y, ChunkPosZ + i); + World->TouchChunk(ChunkPosX + d, ChunkPosZ + i); + World->TouchChunk(ChunkPosX - d, ChunkPosZ + i); } // for i for (int i = -d + 1; i < d; ++i) { - World->TouchChunk(ChunkPosX + i, ZERO_CHUNK_Y, ChunkPosZ + d); - World->TouchChunk(ChunkPosX + i, ZERO_CHUNK_Y, ChunkPosZ - d); + World->TouchChunk(ChunkPosX + i, ChunkPosZ + d); + World->TouchChunk(ChunkPosX + i, ChunkPosZ - d); } // for i } // for d } @@ -501,8 +501,8 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) { { cCSLock Lock(m_CSChunkLists); - m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); - m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); + m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); + m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); } World->SendChunkTo(a_ChunkX, a_ChunkZ, this); } @@ -2733,7 +2733,7 @@ bool cClientHandle::HasPluginChannel(const AString & a_PluginChannel) -bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkZ) { if (m_State >= csDestroying) { @@ -2741,7 +2741,7 @@ bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) } cCSLock Lock(m_CSChunkLists); - return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)) != m_ChunksToSend.end()); + return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) != m_ChunksToSend.end()); } @@ -2757,9 +2757,9 @@ void cClientHandle::AddWantedChunk(int a_ChunkX, int a_ChunkZ) LOGD("Adding chunk [%d, %d] to wanted chunks for client %p", a_ChunkX, a_ChunkZ, this); cCSLock Lock(m_CSChunkLists); - if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)) == m_ChunksToSend.end()) + if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) == m_ChunksToSend.end()) { - m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); + m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); } } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 7ae70a07f..e98d7be99 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -209,7 +209,7 @@ public: // tolua_end /** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */ - bool WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + bool WantsSendChunk(int a_ChunkX, int a_ChunkZ); /** Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) */ void AddWantedChunk(int a_ChunkX, int a_ChunkZ); diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index a1188f984..4d0cf3192 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -99,7 +99,7 @@ void cChunkGenerator::Stop(void) -void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ) { { cCSLock Lock(m_CS); @@ -107,7 +107,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk // Check if it is already in the queue: for (cChunkCoordsList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr) { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ)) + if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) { // Already in the queue, bail out return; @@ -119,7 +119,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk { LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size()); } - m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); + m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); } m_Event.Set(); @@ -246,7 +246,7 @@ void cChunkGenerator::Execute(void) } // Hack for regenerating chunks: if Y != 0, the chunk is considered invalid, even if it has its data set - if ((coords.m_ChunkY == 0) && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ)) + if (m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ)) { LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ); // Already generated, ignore request @@ -259,8 +259,8 @@ void cChunkGenerator::Execute(void) continue; } - LOGD("Generating chunk [%d, %d, %d]", coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); - DoGenerate(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); + LOGD("Generating chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ); + DoGenerate(coords.m_ChunkX, coords.m_ChunkZ); NumChunksGenerated++; } // while (!bStop) @@ -269,7 +269,7 @@ void cChunkGenerator::Execute(void) -void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ) { ASSERT(m_PluginInterface != NULL); ASSERT(m_ChunkSink != NULL); diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h index 88d71f3f9..17ca8adce 100644 --- a/src/Generating/ChunkGenerator.h +++ b/src/Generating/ChunkGenerator.h @@ -116,7 +116,7 @@ public: void Stop(void); /// Queues the chunk for generation; removes duplicate requests - void QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void QueueGenerateChunk(int a_ChunkX, int a_ChunkZ); /// Generates the biomes for the specified chunk (directly, not in a separate thread). Used by the world loader if biomes failed loading. void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap); @@ -154,7 +154,7 @@ private: // cIsThread override: virtual void Execute(void) override; - void DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void DoGenerate(int a_ChunkX, int a_ChunkZ); }; diff --git a/src/World.cpp b/src/World.cpp index 69d1217f1..eba3a8357 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -442,7 +442,7 @@ void cWorld::InitializeSpawn(void) { for (int z = 0; z < ViewDist; z++) { - m_ChunkMap->TouchChunk(x + ChunkX-(ViewDist - 1) / 2, ZERO_CHUNK_Y, z + ChunkZ-(ViewDist - 1) / 2); // Queue the chunk in the generator / loader + m_ChunkMap->TouchChunk(x + ChunkX-(ViewDist - 1) / 2, z + ChunkZ-(ViewDist - 1) / 2); // Queue the chunk in the generator / loader } } @@ -2421,7 +2421,7 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData) // Save the chunk right after generating, so that we don't have to generate it again on next run if (a_SetChunkData.ShouldMarkDirty()) { - m_Storage.QueueSaveChunk(ChunkX, 0, ChunkZ); + m_Storage.QueueSaveChunk(ChunkX, ChunkZ); } } @@ -2766,18 +2766,18 @@ void cWorld::RemoveClientFromChunkSender(cClientHandle * a_Client) -void cWorld::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cWorld::TouchChunk(int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->TouchChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + m_ChunkMap->TouchChunk(a_ChunkX, a_ChunkZ); } -bool cWorld::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +bool cWorld::LoadChunk(int a_ChunkX, int a_ChunkZ) { - return m_ChunkMap->LoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + return m_ChunkMap->LoadChunk(a_ChunkX, a_ChunkZ); } @@ -2793,9 +2793,9 @@ void cWorld::LoadChunks(const cChunkCoordsList & a_Chunks) -void cWorld::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cWorld::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ); + m_ChunkMap->ChunkLoadFailed(a_ChunkX, a_ChunkZ); } @@ -2900,8 +2900,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) { m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); - // Trick: use Y=1 to force the chunk generation even though the chunk data is already present - m_Generator.QueueGenerateChunk(a_ChunkX, 1, a_ChunkZ); + m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ); } @@ -2910,7 +2909,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ) { - m_Generator.QueueGenerateChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); + m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ); } diff --git a/src/World.h b/src/World.h index 578c9682b..50b157312 100644 --- a/src/World.h +++ b/src/World.h @@ -351,16 +351,16 @@ public: void RemoveClientFromChunkSender(cClientHandle * a_Client); /** Touches the chunk, causing it to be loaded or generated */ - void TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void TouchChunk(int a_ChunkX, int a_ChunkZ); /** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */ - bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + bool LoadChunk(int a_ChunkX, int a_ChunkZ); /** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */ void LoadChunks(const cChunkCoordsList & a_Chunks); /** Marks the chunk as failed-to-load: */ - void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ); /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as UpdateSign() */ bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 58f9e3cab..6760186b2 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -980,7 +980,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld if (!a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer)) { // Chunk not valid - LOG("cWSSCompact: Trying to save chunk [%d, %d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ); + LOG("cWSSCompact: Trying to save chunk [%d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } @@ -999,7 +999,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld int errorcode = CompressString(Data.data(), Data.size(), CompressedData, m_CompressionFactor); if (errorcode != Z_OK) { - LOGERROR("Error %i compressing data for chunk [%d, %d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ); + LOGERROR("Error %i compressing data for chunk [%d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } @@ -1010,7 +1010,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld sChunkHeader * Header = new sChunkHeader; if (Header == NULL) { - LOGWARNING("Cannot create a new chunk header to save chunk [%d, %d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ); + LOGWARNING("Cannot create a new chunk header to save chunk [%d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } Header->m_CompressedSize = (int)CompressedData.size(); diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index 707e8f929..c4df8c379 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -141,9 +141,9 @@ size_t cWorldStorage::GetSaveQueueLength(void) -void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) +void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, bool a_Generate) { - m_LoadQueue.EnqueueItem(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); + m_LoadQueue.EnqueueItem(sChunkLoad(a_ChunkX, a_ChunkZ, a_Generate)); m_Event.Set(); } @@ -151,9 +151,9 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo -void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ) { - m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); + m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkZ)); m_Event.Set(); } @@ -161,9 +161,9 @@ void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) -void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkZ) { - m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, true)); + m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkZ, true)); } @@ -242,19 +242,19 @@ void cWorldStorage::Execute(void) bool cWorldStorage::LoadOneChunk(void) { - sChunkLoad ToLoad(0, 0, 0, false); + sChunkLoad ToLoad(0, 0, false); bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad); - if (ShouldLoad && !LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ)) + if (ShouldLoad && !LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ)) { if (ToLoad.m_Generate) { // The chunk couldn't be loaded, generate it: - m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ); + m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ); } else { // TODO: Notify the world that the load has failed: - // m_World->ChunkLoadFailed(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ); + // m_World->ChunkLoadFailed(ToLoad.m_ChunkX, ToLoad.m_ChunkZ); } } return ShouldLoad; @@ -266,7 +266,7 @@ bool cWorldStorage::LoadOneChunk(void) bool cWorldStorage::SaveOneChunk(void) { - cChunkCoords ToSave(0, 0, 0); + cChunkCoords ToSave(0, 0); bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave); if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ)) { @@ -283,7 +283,7 @@ bool cWorldStorage::SaveOneChunk(void) -bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkZ) { if (m_World->IsChunkValid(a_ChunkX, a_ChunkZ)) { @@ -291,7 +291,7 @@ bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) return true; } - cChunkCoords Coords(a_ChunkX, a_ChunkY, a_ChunkZ); + cChunkCoords Coords(a_ChunkX, a_ChunkZ); // First try the schema that is used for saving if (m_SaveSchema->LoadChunk(Coords)) @@ -309,7 +309,7 @@ bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) } // Notify the chunk owner that the chunk failed to load (sets cChunk::m_HasLoadFailed to true): - m_World->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ); + m_World->ChunkLoadFailed(a_ChunkX, a_ChunkZ); return false; } diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index dd07ecb64..5f89ead53 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -64,13 +64,13 @@ public: cWorldStorage(void); ~cWorldStorage(); - void QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true - void QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void QueueLoadChunk(int a_ChunkX, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true + void QueueSaveChunk(int a_ChunkX, int a_ChunkZ); /// Loads the chunk specified; returns true on success, false on failure - bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + bool LoadChunk(int a_ChunkX, int a_ChunkZ); - void UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + void UnqueueLoad(int a_ChunkX, int a_ChunkZ); void UnqueueSave(const cChunkCoords & a_Chunk); bool Start(cWorld * a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor); // Hide the cIsThread's Start() method, we need to provide args @@ -87,17 +87,15 @@ protected: struct sChunkLoad { int m_ChunkX; - int m_ChunkY; int m_ChunkZ; bool m_Generate; // If true, the chunk will be generated if it cannot be loaded - sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {} + sChunkLoad(int a_ChunkX, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {} bool operator ==(const sChunkLoad other) const { return ( (this->m_ChunkX == other.m_ChunkX) && - (this->m_ChunkY == other.m_ChunkY) && (this->m_ChunkZ == other.m_ChunkZ) ); } -- cgit v1.2.3 From 6c3b80f04c7c2cca26efb57cc9827a7a1d20fcda Mon Sep 17 00:00:00 2001 From: Hownaer Date: Thu, 28 Aug 2014 14:58:03 +0200 Subject: Fixed crashes and use std::swap. --- src/ClientHandle.cpp | 22 +++++++++++++++++++--- src/ClientHandle.h | 2 +- src/Item.cpp | 36 ++++++++++++++++++++---------------- src/UI/SlotArea.cpp | 9 +++------ 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8aa883144..1dd8ff31c 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2857,11 +2857,27 @@ void cClientHandle::SocketClosed(void) -void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) +void cClientHandle::HandleEnchantItem(Byte & a_WindowID, Byte & a_Enchantment) { - cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); + if (a_Enchantment > 2) + { + LOGWARNING("%s attempt to crash the server with invalid enchanting selection!", GetUsername().c_str()); + Kick("Invalid enchanting!"); + return; + } + + if ( + (m_Player->GetWindow() == NULL) || + (m_Player->GetWindow()->GetWindowID() != a_WindowID) || + (m_Player->GetWindow()->GetWindowType() != cWindow::wtEnchantment) + ) + { + return; + } + + cEnchantingWindow * Window = (cEnchantingWindow*) m_Player->GetWindow(); cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); - int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); + int BaseEnchantmentLevel = Window->GetPropertyValue(a_Enchantment); if (Item.EnchantByXPLevels(BaseEnchantmentLevel)) { diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 7ae70a07f..24031119d 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -269,7 +269,7 @@ public: void RemoveFromWorld(void); /** Called when the player will enchant a Item */ - void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); + void HandleEnchantItem(Byte & a_WindowID, Byte & a_Enchantment); private: diff --git a/src/Item.cpp b/src/Item.cpp index a5117c271..4d29318e6 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -291,73 +291,77 @@ int cItem::GetEnchantability() bool cItem::EnchantByXPLevels(int a_NumXPLevels) { - if (!cItem::IsEnchantable(m_ItemType) && (m_ItemType != E_ITEM_BOOK)) + if (!cItem::IsEnchantable(m_ItemType)) { return false; } int Enchantability = GetEnchantability(); + if (Enchantability == 0) + { + return false; + } cFastRandom Random; int ModifiedEnchantmentLevel = a_NumXPLevels + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1; float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); - cWeightedEnchantments enchantments; - cEnchantments::AddItemEnchantmentWeights(enchantments, m_ItemType, FinalEnchantmentLevel); + cWeightedEnchantments Enchantments; + cEnchantments::AddItemEnchantmentWeights(Enchantments, m_ItemType, FinalEnchantmentLevel); if (m_ItemType == E_ITEM_BOOK) { m_ItemType = E_ITEM_ENCHANTED_BOOK; } - cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments); m_Enchantments.AddFromString(Enchantment1.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment1); + cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment1); // Checking for conflicting enchantments - cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1); + cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment1); float NewEnchantmentLevel = (float)a_NumXPLevels; // Next Enchantment (Second) NewEnchantmentLevel = NewEnchantmentLevel / 2; float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (enchantments.empty() || (Random.NextFloat(100) > SecondEnchantmentChance)) + if (Enchantments.empty() || (Random.NextFloat(100) > SecondEnchantmentChance)) { return true; } - cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments); m_Enchantments.AddFromString(Enchantment2.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment2); + cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment2); // Checking for conflicting enchantments - cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); + cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment2); // Next Enchantment (Third) NewEnchantmentLevel = NewEnchantmentLevel / 2; float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (enchantments.empty() || (Random.NextFloat(100) > ThirdEnchantmentChance)) + if (Enchantments.empty() || (Random.NextFloat(100) > ThirdEnchantmentChance)) { return true; } - cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments); m_Enchantments.AddFromString(Enchantment3.ToString()); - cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment3); + cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment3); // Checking for conflicting enchantments - cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); + cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment3); // Next Enchantment (Fourth) NewEnchantmentLevel = NewEnchantmentLevel / 2; float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (enchantments.empty() || (Random.NextFloat(100) > FourthEnchantmentChance)) + if (Enchantments.empty() || (Random.NextFloat(100) > FourthEnchantmentChance)) { return true; } - cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments); m_Enchantments.AddFromString(Enchantment4.ToString()); return true; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 74173d087..88af257a0 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1423,7 +1423,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio } case caDblClick: { - // DblClicked(a_Player, a_SlotNum); + DblClicked(a_Player, a_SlotNum); return; } case caMiddleClick: @@ -1470,8 +1470,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio { if (!Slot.IsEmpty()) { - DraggingItem = Slot; - Slot.Empty(); + std::swap(DraggingItem, Slot); } } else if (Slot.IsEmpty()) @@ -1487,9 +1486,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio else if ((DraggingItem.m_ItemCount == 1) && !DraggingItem.IsEqual(Slot)) { // Switch contents - cItem tmp(DraggingItem); - DraggingItem = Slot; - Slot = tmp; + std::swap(DraggingItem, Slot); } SetSlot(a_SlotNum, a_Player, Slot); -- cgit v1.2.3 From f1470fcf9f1dc907241a645614cdcd5547dc1dbd Mon Sep 17 00:00:00 2001 From: Hownaer Date: Thu, 28 Aug 2014 15:21:38 +0200 Subject: Fixed bad values in the IsEnchantable() method. --- src/Item.cpp | 20 ++++++++++++++++---- src/Item.h | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Item.cpp b/src/Item.cpp index 4d29318e6..ebdf99ca5 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -190,9 +190,16 @@ void cItem::FromJson(const Json::Value & a_Value) -bool cItem::IsEnchantable(short a_ItemType) +bool cItem::IsEnchantable(short a_ItemType, bool a_WithBook) { - if (ItemCategory::IsTool(a_ItemType) || ItemCategory::IsArmor(a_ItemType)) + if ( + ItemCategory::IsAxe(a_ItemType) || + ItemCategory::IsSword(a_ItemType) || + ItemCategory::IsShovel(a_ItemType) || + ItemCategory::IsPickaxe(a_ItemType) || + (a_WithBook && ItemCategory::IsHoe(a_ItemType)) || + ItemCategory::IsArmor(a_ItemType) + ) { return true; } @@ -201,12 +208,17 @@ bool cItem::IsEnchantable(short a_ItemType) { case E_ITEM_BOOK: case E_ITEM_BOW: - case E_ITEM_CARROT_ON_STICK: case E_ITEM_FISHING_ROD: - case E_ITEM_SHEARS: { return true; } + + case E_ITEM_CARROT_ON_STICK: + case E_ITEM_SHEARS: + case E_ITEM_FLINT_AND_STEEL: + { + return a_WithBook; + } } return false; diff --git a/src/Item.h b/src/Item.h index d8b9e78a0..61011d861 100644 --- a/src/Item.h +++ b/src/Item.h @@ -184,7 +184,7 @@ public: void FromJson(const Json::Value & a_Value); /** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */ - static bool IsEnchantable(short a_ItemType); // tolua_export + static bool IsEnchantable(short a_ItemType, bool a_WithBook = false); // tolua_export /** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */ int GetEnchantability(); // tolua_export -- cgit v1.2.3 From c0c4ac5236779af648fd64d32eb7075553e4a88a Mon Sep 17 00:00:00 2001 From: Hownaer Date: Thu, 28 Aug 2014 15:21:50 +0200 Subject: Added comments. --- src/UI/SlotArea.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 88af257a0..b4facb2d3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1468,6 +1468,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio if (DraggingItem.IsEmpty()) { + // DraggingItem is empty -> Switch draggingitem and slot if (!Slot.IsEmpty()) { std::swap(DraggingItem, Slot); @@ -1475,6 +1476,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio } else if (Slot.IsEmpty()) { + // DraggingItem isn't empty and slot is empty -> Set one dragging item in the slot Slot = DraggingItem.CopyOne(); DraggingItem.m_ItemCount -= 1; @@ -1485,7 +1487,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio } else if ((DraggingItem.m_ItemCount == 1) && !DraggingItem.IsEqual(Slot)) { - // Switch contents + // DraggingItem and slot aren't empty -> Switch items std::swap(DraggingItem, Slot); } -- cgit v1.2.3 From 4ff34b9f10368587b7d7ade58977fb8ec7692d73 Mon Sep 17 00:00:00 2001 From: Hownaer Date: Thu, 28 Aug 2014 18:18:21 +0200 Subject: APIDump: Added missing cItem things. --- MCServer/Plugins/APIDump/APIDesc.lua | 11 ++++++++--- src/Item.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 3e1a6e3bb..d75911666 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1188,7 +1188,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins, constructor = { { Params = "", Return = "cItem", Notes = "Creates a new empty cItem object" }, - { Params = "ItemType, Count, Damage, EnchantmentString", Return = "cItem", Notes = "Creates a new cItem object of the specified type, count (1 by default), damage (0 by default) and enchantments (non-enchanted by default)" }, + { Params = "ItemType, Count, Damage, EnchantmentString, CustomName, Lore", Return = "cItem", Notes = "Creates a new cItem object of the specified type, count (1 by default), damage (0 by default), enchantments (non-enchanted by default), CustomName (empty by default) and Lore (string, empty by default)" }, { Params = "cItem", Return = "cItem", Notes = "Creates an exact copy of the cItem object in the parameter" }, } , AddCount = { Params = "AmountToAdd", Return = "cItem", Notes = "Adds the specified amount to the item count. Returns self (useful for chaining)." }, @@ -1207,6 +1207,9 @@ These ItemGrids are available in the API and can be manipulated by the plugins, 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." }, + GetEnchantability = { Params = "", Return = "number", Notes = "Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0" }, + EnchantByXPLevels = { Params = "NumXPLevels", Return = "bool", Notes = "Enchants the item using the specified number of XP levels. Returns true if item enchanted, false if not." }, + IsEnchantable = { Params = "ItemType, WithBook", Return = "bool", Notes = "(STATIC) Returns true if the specified item type is enchantable." }, }, Variables = { @@ -1214,8 +1217,10 @@ These ItemGrids are available in the API and can be manipulated by the plugins, m_ItemCount = { Type = "number", Notes = "Number of items in this stack" }, m_ItemDamage = { Type = "number", Notes = "The damage of the item. Zero means no damage. Maximum damage can be queried with GetMaxDamage()" }, m_ItemType = { Type = "number", Notes = "The item type. One of E_ITEM_ or E_BLOCK_ constants" }, - m_CustomName = { Type = "string", Notes = "The custom name for an item." }, - m_Lore = { Type = "string", Notes = "The lore for an item. Line breaks are represented by the ` character." }, + m_CustomName = { Type = "string", Notes = "The custom name for an item." }, + m_Lore = { Type = "string", Notes = "The lore for an item. Line breaks are represented by the ` character." }, + m_RepairCost = { Type = "number", Notes = "The repair cost of the item. The anvil need this value" }, + m_Enchantments = { Type = "{{cEnchantments|cEnchantments}}}", Notes = "The enchantments of the item." }, }, AdditionalInfo = { diff --git a/src/Item.h b/src/Item.h index 61011d861..316928b9e 100644 --- a/src/Item.h +++ b/src/Item.h @@ -183,7 +183,7 @@ public: /** Loads the item data from JSON representation */ void FromJson(const Json::Value & a_Value); - /** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */ + /** Returns true if the specified item type is enchantable. */ static bool IsEnchantable(short a_ItemType, bool a_WithBook = false); // tolua_export /** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */ -- cgit v1.2.3 From 75e131638616c68d126eb64abdf903a93dd7322f Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Fri, 29 Aug 2014 20:19:45 +0200 Subject: fix chunk regenerating --- src/Generating/ChunkGenerator.cpp | 8 -------- src/World.cpp | 8 ++++++++ src/World.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index 4d0cf3192..a1c3d50cc 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -245,14 +245,6 @@ void cChunkGenerator::Execute(void) LastReportTick = clock(); } - // Hack for regenerating chunks: if Y != 0, the chunk is considered invalid, even if it has its data set - if (m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ)) - { - LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ); - // Already generated, ignore request - continue; - } - if (SkipEnabled && !m_ChunkSink->HasChunkAnyClients(coords.m_ChunkX, coords.m_ChunkZ)) { LOGWARNING("Chunk generator overloaded, skipping chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ); diff --git a/src/World.cpp b/src/World.cpp index eba3a8357..aba5bd859 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2909,7 +2909,15 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ) { + if (!(m_ChunkMap->IsChunkValid(a_ChunkX, a_ChunkZ))) + { + LOGD("Chunk [%d, %d] already generated, skipping generation", a_ChunkX, a_ChunkZ); + // Already generated, ignore reques + } + else + { m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ); + } } diff --git a/src/World.h b/src/World.h index 50b157312..49e30694e 100644 --- a/src/World.h +++ b/src/World.h @@ -380,7 +380,7 @@ public: /** Regenerate the given chunk: */ void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export - /** Generates the given chunk, if not already generated */ + /** Generates the given chunk */ void GenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export /** Queues a chunk for lighting; a_Callback is called after the chunk is lighted */ -- cgit v1.2.3 From e45a27add934dcdad8eadcea16ce647fb87fbf9d Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Fri, 29 Aug 2014 20:26:19 +0200 Subject: add comments --- src/World.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/World.cpp b/src/World.cpp index aba5bd859..7c6a1af2f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2909,10 +2909,11 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ) { + /** Add a chunk to the generation queue, if it's not already present. */ if (!(m_ChunkMap->IsChunkValid(a_ChunkX, a_ChunkZ))) { LOGD("Chunk [%d, %d] already generated, skipping generation", a_ChunkX, a_ChunkZ); - // Already generated, ignore reques + /** Already generated, ignore reques */ } else { -- cgit v1.2.3 From 5a6ef8b8e5887a13b252623a584ac05f0b2bd070 Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Fri, 29 Aug 2014 20:27:58 +0200 Subject: me being stupid --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/World.cpp b/src/World.cpp index 7c6a1af2f..f6fed53ee 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2913,7 +2913,7 @@ void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ) if (!(m_ChunkMap->IsChunkValid(a_ChunkX, a_ChunkZ))) { LOGD("Chunk [%d, %d] already generated, skipping generation", a_ChunkX, a_ChunkZ); - /** Already generated, ignore reques */ + /** Already generated, ignore request */ } else { -- cgit v1.2.3 From ac95173e81028856e7dac7e751c9526d0c9d4c8a Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Sat, 30 Aug 2014 00:45:05 +0200 Subject: remove orphaned comment. --- src/ChunkDef.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index b7122efe2..111e081db 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -16,10 +16,6 @@ -/** This is really only a placeholder to be used in places where we need to "make up" a chunk's Y coord. -It will help us when the new chunk format comes out and we need to patch everything up for compatibility. -*/ - // Used to smoothly convert to new axis ordering. One will be removed when deemed stable. #define AXIS_ORDER_YZX 1 // Original (1.1-) #define AXIS_ORDER_XZY 2 // New (1.2+) -- cgit v1.2.3 From 3ee3a59e75ac1e6eb9284983a05a459aab5be1fd Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 30 Aug 2014 15:06:43 +0200 Subject: Changed the IsEnchantable() comment. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- src/Item.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index d75911666..da8f9cd74 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1209,7 +1209,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins, IsLoreEmpty = { Params = "", Return = "", Notes = "Returns if the lore of the cItem is empty." }, GetEnchantability = { Params = "", Return = "number", Notes = "Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0" }, EnchantByXPLevels = { Params = "NumXPLevels", Return = "bool", Notes = "Enchants the item using the specified number of XP levels. Returns true if item enchanted, false if not." }, - IsEnchantable = { Params = "ItemType, WithBook", Return = "bool", Notes = "(STATIC) Returns true if the specified item type is enchantable." }, + IsEnchantable = { Params = "ItemType, WithBook", Return = "bool", Notes = "(STATIC) Returns true if the specified item type is enchantable. If WithBook is true, the function checks the enchantments with a book too." }, }, Variables = { diff --git a/src/Item.h b/src/Item.h index 316928b9e..e7fd67b9a 100644 --- a/src/Item.h +++ b/src/Item.h @@ -183,7 +183,8 @@ public: /** Loads the item data from JSON representation */ void FromJson(const Json::Value & a_Value); - /** Returns true if the specified item type is enchantable. */ + /** Returns true if the specified item type is enchantable. + If WithBook is true, the function checks the enchantments with a book too. */ static bool IsEnchantable(short a_ItemType, bool a_WithBook = false); // tolua_export /** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */ -- cgit v1.2.3 From 4c9abab2d12fa3900a8339ef125fe0808e182eaf Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Mon, 1 Sep 2014 15:01:56 +0200 Subject: fix possibility of a twice generated chunk --- src/Generating/ChunkGenerator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index a1c3d50cc..845202358 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -230,7 +230,6 @@ void cChunkGenerator::Execute(void) } cChunkCoords coords = m_Queue.front(); // Get next coord from queue - m_Queue.erase( m_Queue.begin()); // Remove coordinate from queue bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT); Lock.Unlock(); // Unlock ASAP m_evtRemoved.Set(); @@ -254,6 +253,8 @@ void cChunkGenerator::Execute(void) LOGD("Generating chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ); DoGenerate(coords.m_ChunkX, coords.m_ChunkZ); + m_Queue.erase(m_Queue.begin()); // Remove coordinate from queue + NumChunksGenerated++; } // while (!bStop) } -- cgit v1.2.3 From 7695471ff9423c14d9e7188a85a270b368760402 Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Mon, 1 Sep 2014 21:37:36 +0200 Subject: added multicache class definition --- src/Generating/BioGen.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index 227ec97d7..a53d8bca2 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -77,7 +77,42 @@ protected: } ; +class cBioGenMulticache : + public cBiomeGen +{ + + typedef cBiomeGen super; + +public: + cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSize, int a_CacheLength); // Doesn't take ownership of a_BioGenToCache + ~cBioGenMulticache(); + +protected: + + cBiomeGen * m_BioGenToCache; + struct sCacheData + { + int m_ChunkX; + int m_ChunkZ; + cChunkDef::BiomeMap m_BiomeMap; + }; + + // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data + int m_CacheSize; + int m_CacheLength; + + int **m_CachesOrder; // MRU-ized order, indices into the multiple m_CachesData array + sCacheData ** m_CachesData; + + // Cache statistics + int m_NumHits; + int m_NumMisses; + int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) + + virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; + virtual void InitializeBiomeGen(cIniFile & a_IniFile) override; +}; /// Base class for generators that use a list of available biomes. This class takes care of the list. -- cgit v1.2.3 From 77409d47eb98eb691f852728cd8e013d0fc14185 Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Mon, 1 Sep 2014 22:33:58 +0200 Subject: adding the multicache behavior --- src/Generating/BioGen.cpp | 115 +++++++++++++++++++++++++++++++++ src/Generating/BioGen.h | 6 +- src/Generating/ComposableGenerator.cpp | 2 +- 3 files changed, 119 insertions(+), 4 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 8fad9f5c9..c9aeffa54 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -208,6 +208,121 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile) +//////////////////////////////////////////////////////////////////////////////// +// cBioGenMulticache: + +cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSize, int a_CachesLength) : +m_BioGenToCache(a_BioGenToCache), +m_CacheSize(a_CacheSize), +m_CachesLength(a_CachesLength), +m_CachesOrder(new int*[a_CachesLength * a_CachesLength]), +m_CachesData(new sCacheData*[a_CachesLength * a_CachesLength]), +m_NumHits(0), +m_NumMisses(0), +m_TotalChain(0) +{ + for (int i = 0; i < m_CachesLength * m_CachesLength; i++) { + sCacheData * cacheData = m_CachesData[i] = new sCacheData[m_CacheSize]; + int * cacheOrder = m_CachesOrder[i] = new int[m_CacheSize]; + + for (int j = 0; j < m_CacheSize; j++) + { + cacheOrder[j] = j; + cacheData[j].m_ChunkX = 0x7fffffff; + cacheData[j].m_ChunkZ = 0x7fffffff; + } + } + +} + + + + + +cBioGenMulticache::~cBioGenMulticache() +{ + for (int i = 0; i < m_CachesLength * m_CachesLength; i++) { + delete[] m_CachesData[i]; + delete[] m_CachesOrder[i]; + } + delete[] m_CachesData; + m_CachesData = NULL; + delete[] m_CachesOrder; + m_CachesOrder = NULL; +} + + + + + +void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +{ + if (((m_NumHits + m_NumMisses) % 1024) == 10) + { + LOGD("BioGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses)); + LOGD("BioGenCache: Avg cache chain length: %.2f", (float)m_TotalChain / m_NumHits); + } + + int cacheIdx = ((unsigned int)a_ChunkX % m_CachesLength) * m_CachesLength + ((unsigned int)a_ChunkZ % m_CachesLength); + sCacheData * cacheData = m_CachesData[cacheIdx]; + int * cacheOrder = m_CachesOrder[cacheIdx]; + + for (int i = 0; i < m_CacheSize; i++) + { + if ( + (cacheData[cacheOrder[i]].m_ChunkX != a_ChunkX) || + (cacheData[cacheOrder[i]].m_ChunkZ != a_ChunkZ) + ) + { + continue; + } + // Found it in the cache + int Idx = cacheOrder[i]; + + // Move to front: + for (int j = i; j > 0; j--) + { + cacheOrder[j] = cacheOrder[j - 1]; + } + cacheOrder[0] = Idx; + + // Use the cached data: + memcpy(a_BiomeMap, cacheData[Idx].m_BiomeMap, sizeof(a_BiomeMap)); + + m_NumHits++; + m_TotalChain += i; + return; + } // for i - cache + + // Not in the cache: + m_NumMisses++; + m_BioGenToCache->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); + + // Insert it as the first item in the MRU order: + int Idx = cacheOrder[m_CacheSize - 1]; + for (int i = m_CacheSize - 1; i > 0; i--) + { + cacheOrder[i] = cacheOrder[i - 1]; + } // for i - m_CacheOrder[] + cacheOrder[0] = Idx; + memcpy(cacheData[Idx].m_BiomeMap, a_BiomeMap, sizeof(a_BiomeMap)); + cacheData[Idx].m_ChunkX = a_ChunkX; + cacheData[Idx].m_ChunkZ = a_ChunkZ; +} + + + + + +void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile) +{ + super::InitializeBiomeGen(a_IniFile); + m_BioGenToCache->InitializeBiomeGen(a_IniFile); +} + + + + //////////////////////////////////////////////////////////////////////////////// // cBiomeGenList: diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index a53d8bca2..f9564ed24 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -84,7 +84,7 @@ class cBioGenMulticache : typedef cBiomeGen super; public: - cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSize, int a_CacheLength); // Doesn't take ownership of a_BioGenToCache + cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSize, int a_CachesLength); // Doesn't take ownership of a_BioGenToCache ~cBioGenMulticache(); protected: @@ -100,9 +100,9 @@ protected: // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data int m_CacheSize; - int m_CacheLength; + int m_CachesLength; - int **m_CachesOrder; // MRU-ized order, indices into the multiple m_CachesData array + int ** m_CachesOrder; // MRU-ized order, indices into the multiple m_CachesData array sCacheData ** m_CachesData; // Cache statistics diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 6f4007d24..057d7accf 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -241,7 +241,7 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) } LOGD("Using a cache for biomegen of size %d.", CacheSize); m_UnderlyingBiomeGen = m_BiomeGen; - m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize); + m_BiomeGen = new cBioGenMulticache(m_UnderlyingBiomeGen, CacheSize, 4); } } -- cgit v1.2.3 From d9afe6dd657363f4a6e42790ba4705a9b9b89e60 Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Tue, 2 Sep 2014 01:13:54 +0200 Subject: adding config file entry #381 --- src/Generating/ComposableGenerator.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 057d7accf..0535e89f3 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -230,6 +230,8 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) // Add a cache, if requested: int CacheSize = a_IniFile.GetValueSetI("Generator", "BiomeGenCacheSize", CacheOffByDefault ? 0 : 64); + int MultiCacheLength = a_IniFile.GetValueSetI("Generator", "BiomeGenMultiCacheLength", 4); + if (CacheSize > 0) { if (CacheSize < 4) @@ -241,7 +243,14 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) } LOGD("Using a cache for biomegen of size %d.", CacheSize); m_UnderlyingBiomeGen = m_BiomeGen; - m_BiomeGen = new cBioGenMulticache(m_UnderlyingBiomeGen, CacheSize, 4); + if (MultiCacheLength > 0) { + LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength); + m_BiomeGen = new cBioGenMulticache(m_UnderlyingBiomeGen, CacheSize, MultiCacheLength); + } + else { + m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize); + } + } } -- cgit v1.2.3 From ac4ec5117dbe0ae12e73968b6a6d6cbc1640933a Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Tue, 2 Sep 2014 10:49:46 +0200 Subject: changing implem, using vectors --- src/Generating/BioGen.cpp | 93 ++++++++--------------------------------------- src/Generating/BioGen.h | 28 ++++---------- 2 files changed, 23 insertions(+), 98 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index c9aeffa54..4936fc251 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -212,27 +212,14 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile) // cBioGenMulticache: cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSize, int a_CachesLength) : -m_BioGenToCache(a_BioGenToCache), -m_CacheSize(a_CacheSize), m_CachesLength(a_CachesLength), -m_CachesOrder(new int*[a_CachesLength * a_CachesLength]), -m_CachesData(new sCacheData*[a_CachesLength * a_CachesLength]), -m_NumHits(0), -m_NumMisses(0), -m_TotalChain(0) +m_InternalCacheLength(a_CachesLength * a_CacheSize) { - for (int i = 0; i < m_CachesLength * m_CachesLength; i++) { - sCacheData * cacheData = m_CachesData[i] = new sCacheData[m_CacheSize]; - int * cacheOrder = m_CachesOrder[i] = new int[m_CacheSize]; - - for (int j = 0; j < m_CacheSize; j++) - { - cacheOrder[j] = j; - cacheData[j].m_ChunkX = 0x7fffffff; - cacheData[j].m_ChunkZ = 0x7fffffff; - } + //m_Caches = new std::vector; + m_Caches.reserve(m_InternalCacheLength); + for (int i = 0; i < m_InternalCacheLength; i++) { + m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize)); } - } @@ -241,14 +228,7 @@ m_TotalChain(0) cBioGenMulticache::~cBioGenMulticache() { - for (int i = 0; i < m_CachesLength * m_CachesLength; i++) { - delete[] m_CachesData[i]; - delete[] m_CachesOrder[i]; - } - delete[] m_CachesData; - m_CachesData = NULL; - delete[] m_CachesOrder; - m_CachesOrder = NULL; + m_Caches.erase(m_Caches.cbegin(), m_Caches.cend()); } @@ -257,57 +237,10 @@ cBioGenMulticache::~cBioGenMulticache() void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) { - if (((m_NumHits + m_NumMisses) % 1024) == 10) - { - LOGD("BioGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses)); - LOGD("BioGenCache: Avg cache chain length: %.2f", (float)m_TotalChain / m_NumHits); - } - - int cacheIdx = ((unsigned int)a_ChunkX % m_CachesLength) * m_CachesLength + ((unsigned int)a_ChunkZ % m_CachesLength); - sCacheData * cacheData = m_CachesData[cacheIdx]; - int * cacheOrder = m_CachesOrder[cacheIdx]; + int cacheIdx = ((unsigned int)a_ChunkX % m_CachesLength) * m_CachesLength + + ((unsigned int)a_ChunkZ % m_CachesLength); - for (int i = 0; i < m_CacheSize; i++) - { - if ( - (cacheData[cacheOrder[i]].m_ChunkX != a_ChunkX) || - (cacheData[cacheOrder[i]].m_ChunkZ != a_ChunkZ) - ) - { - continue; - } - // Found it in the cache - int Idx = cacheOrder[i]; - - // Move to front: - for (int j = i; j > 0; j--) - { - cacheOrder[j] = cacheOrder[j - 1]; - } - cacheOrder[0] = Idx; - - // Use the cached data: - memcpy(a_BiomeMap, cacheData[Idx].m_BiomeMap, sizeof(a_BiomeMap)); - - m_NumHits++; - m_TotalChain += i; - return; - } // for i - cache - - // Not in the cache: - m_NumMisses++; - m_BioGenToCache->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); - - // Insert it as the first item in the MRU order: - int Idx = cacheOrder[m_CacheSize - 1]; - for (int i = m_CacheSize - 1; i > 0; i--) - { - cacheOrder[i] = cacheOrder[i - 1]; - } // for i - m_CacheOrder[] - cacheOrder[0] = Idx; - memcpy(cacheData[Idx].m_BiomeMap, a_BiomeMap, sizeof(a_BiomeMap)); - cacheData[Idx].m_ChunkX = a_ChunkX; - cacheData[Idx].m_ChunkZ = a_ChunkZ; + m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); } @@ -316,8 +249,12 @@ void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMa void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile) { - super::InitializeBiomeGen(a_IniFile); - m_BioGenToCache->InitializeBiomeGen(a_IniFile); + //super::InitializeBiomeGen(a_IniFile); + for (auto it = m_Caches.begin(); it != m_Caches.end(); it++) + { + cBiomeGen * tmp = *it; + tmp->InitializeBiomeGen(a_IniFile); + } } diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index f9564ed24..feb449c06 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -77,6 +77,9 @@ protected: } ; + + + class cBioGenMulticache : public cBiomeGen { @@ -88,33 +91,18 @@ public: ~cBioGenMulticache(); protected: - - cBiomeGen * m_BioGenToCache; - - struct sCacheData - { - int m_ChunkX; - int m_ChunkZ; - cChunkDef::BiomeMap m_BiomeMap; - }; - - // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data - int m_CacheSize; int m_CachesLength; - - int ** m_CachesOrder; // MRU-ized order, indices into the multiple m_CachesData array - sCacheData ** m_CachesData; - - // Cache statistics - int m_NumHits; - int m_NumMisses; - int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) + int m_InternalCacheLength; + std::vector m_Caches; virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void InitializeBiomeGen(cIniFile & a_IniFile) override; }; + + + /// Base class for generators that use a list of available biomes. This class takes care of the list. class cBiomeGenList : public cBiomeGen -- cgit v1.2.3 From 29811c4f2155bb3dd03b81803b58df45e15b84f4 Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Tue, 2 Sep 2014 18:05:53 +0200 Subject: fixing memory leak --- src/Generating/BioGen.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 4936fc251..698b9463b 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -215,7 +215,6 @@ cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSiz m_CachesLength(a_CachesLength), m_InternalCacheLength(a_CachesLength * a_CacheSize) { - //m_Caches = new std::vector; m_Caches.reserve(m_InternalCacheLength); for (int i = 0; i < m_InternalCacheLength; i++) { m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize)); @@ -228,7 +227,10 @@ m_InternalCacheLength(a_CachesLength * a_CacheSize) cBioGenMulticache::~cBioGenMulticache() { - m_Caches.erase(m_Caches.cbegin(), m_Caches.cend()); + for (std::vector::iterator it = m_Caches.begin(); it != m_Caches.end(); it++) + { + delete *it; + } } @@ -249,8 +251,7 @@ void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMa void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile) { - //super::InitializeBiomeGen(a_IniFile); - for (auto it = m_Caches.begin(); it != m_Caches.end(); it++) + for (std::vector::iterator it = m_Caches.begin(); it != m_Caches.end(); it++) { cBiomeGen * tmp = *it; tmp->InitializeBiomeGen(a_IniFile); -- cgit v1.2.3 From 82911f36629e77f3ec5a7a318de7151b4341ded2 Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Tue, 2 Sep 2014 18:13:24 +0200 Subject: opting for size_t --- src/Generating/BioGen.cpp | 6 +++--- src/Generating/BioGen.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 698b9463b..de6869e12 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -216,7 +216,7 @@ m_CachesLength(a_CachesLength), m_InternalCacheLength(a_CachesLength * a_CacheSize) { m_Caches.reserve(m_InternalCacheLength); - for (int i = 0; i < m_InternalCacheLength; i++) { + for (size_t i = 0; i < m_InternalCacheLength; i++) { m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize)); } } @@ -239,8 +239,8 @@ cBioGenMulticache::~cBioGenMulticache() void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) { - int cacheIdx = ((unsigned int)a_ChunkX % m_CachesLength) * m_CachesLength - + ((unsigned int)a_ChunkZ % m_CachesLength); + size_t cacheIdx = ((size_t)a_ChunkX % m_CachesLength) * m_CachesLength + + ((size_t)a_ChunkZ % m_CachesLength); m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); } diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index feb449c06..bf79d242d 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -91,8 +91,8 @@ public: ~cBioGenMulticache(); protected: - int m_CachesLength; - int m_InternalCacheLength; + size_t m_CachesLength; + size_t m_InternalCacheLength; std::vector m_Caches; virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; -- cgit v1.2.3 From b8636ee53abf8f497aae5c8765618fad63d0552a Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Tue, 2 Sep 2014 18:18:43 +0200 Subject: forgot this one --- src/Generating/BioGen.cpp | 2 +- src/Generating/BioGen.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index de6869e12..69af5c79a 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -211,7 +211,7 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cBioGenMulticache: -cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSize, int a_CachesLength) : +cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength) : m_CachesLength(a_CachesLength), m_InternalCacheLength(a_CachesLength * a_CacheSize) { diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index bf79d242d..cfa748ec7 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -87,7 +87,7 @@ class cBioGenMulticache : typedef cBiomeGen super; public: - cBioGenMulticache(cBiomeGen * a_BioGenToCache, int a_CacheSize, int a_CachesLength); // Doesn't take ownership of a_BioGenToCache + cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength); // Doesn't take ownership of a_BioGenToCache ~cBioGenMulticache(); protected: -- cgit v1.2.3 From c19b2befa88bfe5549a3630c997070d5e1d37941 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 2 Sep 2014 20:17:31 +0200 Subject: Changed the IsEnchantable() comment again. --- MCServer/Plugins/APIDump/APIDesc.lua | 3 +-- src/Item.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index eec731c34..ffd228d1a 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1201,7 +1201,6 @@ These ItemGrids are available in the API and can be manipulated by the plugins, IsDamageable = { Params = "", Return = "bool", Notes = "Returns true if this item does account for its damage" }, IsEmpty = { Params = "", Return = "bool", Notes = "Returns true if this object represents an empty item (zero count or invalid ID)" }, IsEqual = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is the same as the one stored in the object (type, damage, lore, name and enchantments)" }, - 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" }, IsBothNameAndLoreEmpty = { Params = "", Return = "bool", Notes = "Returns if both the custom name and lore are not set." }, @@ -1209,7 +1208,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins, IsLoreEmpty = { Params = "", Return = "", Notes = "Returns if the lore of the cItem is empty." }, GetEnchantability = { Params = "", Return = "number", Notes = "Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0" }, EnchantByXPLevels = { Params = "NumXPLevels", Return = "bool", Notes = "Enchants the item using the specified number of XP levels. Returns true if item enchanted, false if not." }, - IsEnchantable = { Params = "ItemType, WithBook", Return = "bool", Notes = "(STATIC) Returns true if the specified item type is enchantable. If WithBook is true, the function checks the enchantments with a book too." }, + IsEnchantable = { Params = "ItemType, WithBook", Return = "bool", Notes = "(STATIC) Returns true if the specified item type is enchantable. If WithBook is true, the function is used in the anvil inventory with book enchantments. So it checks the \"only book enchantments\" too. Example: You can only enchant a hoe with a book." }, }, Variables = { diff --git a/src/Item.h b/src/Item.h index e7fd67b9a..056b5eb8a 100644 --- a/src/Item.h +++ b/src/Item.h @@ -184,7 +184,8 @@ public: void FromJson(const Json::Value & a_Value); /** Returns true if the specified item type is enchantable. - If WithBook is true, the function checks the enchantments with a book too. */ + If WithBook is true, the function is used in the anvil inventory with book enchantments. + So it checks the "only book enchantments" too. Example: You can only enchant a hoe with a book. */ static bool IsEnchantable(short a_ItemType, bool a_WithBook = false); // tolua_export /** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */ -- cgit v1.2.3 From 92a60bf4d5b0fe4705d9aa83e318f02d5ed2c0a0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 2 Sep 2014 22:40:24 +0200 Subject: Added strict error reporting to chunk loading. This should help with #1307. --- src/WorldStorage/WSSAnvil.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e79cc291d..0c31d8b02 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -69,6 +69,18 @@ Since only the header is actually in the memory, this number can be high, but st /// The maximum size of an inflated chunk; raw chunk data is 192 KiB, allow 64 KiB more of entities #define CHUNK_INFLATE_MAX 256 KiB +#define LOAD_FAILED(CHX, CHZ) \ + { \ + const int RegionX = FAST_FLOOR_DIV(CHX, 32); \ + const int RegionZ = FAST_FLOOR_DIV(CHZ, 32); \ + LOGERROR("%s (%d): Loading chunk [%d, %d] from file r.%d.%d.mca failed. " \ + "The server will now abort in order to avoid further data loss. " \ + "Please add the reported file and this message to the issue report.", \ + __FUNCTION__, __LINE__, CHX, CHZ, RegionX, RegionZ \ + ); \ + *((int *)0) = 0; /* Crash intentionally */ \ + } + @@ -263,6 +275,7 @@ bool cWSSAnvil::LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & inflateEnd(&strm); if (res != Z_STREAM_END) { + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } @@ -271,6 +284,7 @@ bool cWSSAnvil::LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & if (!NBT.IsValid()) { // NBT Parsing failed + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } @@ -317,11 +331,13 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT int Level = a_NBT.FindChildByName(0, "Level"); if (Level < 0) { + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } int Sections = a_NBT.FindChildByName(Level, "Sections"); if ((Sections < 0) || (a_NBT.GetType(Sections) != TAG_List) || (a_NBT.GetChildrenType(Sections) != TAG_Compound)) { + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } for (int Child = a_NBT.GetFirstChild(Sections); Child >= 0; Child = a_NBT.GetNextSibling(Child)) @@ -2811,30 +2827,42 @@ bool cWSSAnvil::cMCAFile::GetChunkData(const cChunkCoords & a_Chunk, AString & a } unsigned ChunkLocation = ntohl(m_Header[LocalX + 32 * LocalZ]); unsigned ChunkOffset = ChunkLocation >> 8; + if (ChunkOffset <= 2) + { + return false; + } m_File.Seek((int)ChunkOffset * 4096); int ChunkSize = 0; if (m_File.Read(&ChunkSize, 4) != 4) { + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } ChunkSize = ntohl((u_long)ChunkSize); char CompressionType = 0; if (m_File.Read(&CompressionType, 1) != 1) { + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } if (CompressionType != 2) { // Chunk is in an unknown compression + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } ChunkSize--; // HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly a_Data.assign(ChunkSize, '\0'); - return (m_File.Read((void *)a_Data.data(), ChunkSize) == ChunkSize); + if (m_File.Read((void *)a_Data.data(), ChunkSize) == ChunkSize) + { + return true; + } + LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); + return false; } -- cgit v1.2.3 From a0687b42e44df65cf4774b40af59ad763c48fa1a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 2 Sep 2014 23:05:24 +0200 Subject: Clang wants volatile... --- src/WorldStorage/WSSAnvil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 0c31d8b02..815b6544f 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -78,7 +78,7 @@ Since only the header is actually in the memory, this number can be high, but st "Please add the reported file and this message to the issue report.", \ __FUNCTION__, __LINE__, CHX, CHZ, RegionX, RegionZ \ ); \ - *((int *)0) = 0; /* Crash intentionally */ \ + *((volatile int *)0) = 0; /* Crash intentionally */ \ } -- cgit v1.2.3 From a600e3bdfef5514d28475b6574f1c78ee74ed214 Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Wed, 3 Sep 2014 00:14:51 +0200 Subject: hopefully the last commit for removing y-coord from chunks. :) --- src/ChunkDef.h | 21 +++++++++++++++++++++ src/Generating/ChunkGenerator.cpp | 18 ++++++++++++------ src/Generating/ChunkGenerator.h | 10 +++++----- src/World.cpp | 13 ++----------- src/WorldStorage/WorldStorage.cpp | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 111e081db..ded0bdf4c 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -389,6 +389,27 @@ typedef std::vector cChunkCoordsVector; +class cChunkCoordsWithBool +{ +public: + int m_ChunkX; + int m_ChunkZ; + bool m_ForceGenerate; + + cChunkCoordsWithBool(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_ForceGenerate(a_ForceGenerate){} + + bool operator == (const cChunkCoordsWithBool & a_Other) const + { + return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ) && (m_ForceGenerate == a_Other.m_ForceGenerate)); + } +}; + +typedef std::list cChunkCoordWithBoolList; + + + + + /// Interface class used as a callback for operations that involve chunk coords class cChunkCoordCallback { diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index 845202358..6216958d2 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -99,13 +99,13 @@ void cChunkGenerator::Stop(void) -void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ) +void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate) { { cCSLock Lock(m_CS); // Check if it is already in the queue: - for (cChunkCoordsList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr) + for (cChunkCoordWithBoolList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr) { if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) { @@ -119,7 +119,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ) { LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size()); } - m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); + m_Queue.push_back(cChunkCoordsWithBool(a_ChunkX, a_ChunkZ, a_ForceGenerate)); } m_Event.Set(); @@ -229,8 +229,9 @@ void cChunkGenerator::Execute(void) continue; } - cChunkCoords coords = m_Queue.front(); // Get next coord from queue + cChunkCoordsWithBool coords = m_Queue.front(); // Get next coord from queue bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT); + m_Queue.erase(m_Queue.begin()); // Remove coordinate from queue Lock.Unlock(); // Unlock ASAP m_evtRemoved.Set(); @@ -244,6 +245,13 @@ void cChunkGenerator::Execute(void) LastReportTick = clock(); } + if (!coords.m_ForceGenerate && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ)) + { + LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ); + // Already generated, ignore request + continue; + } + if (SkipEnabled && !m_ChunkSink->HasChunkAnyClients(coords.m_ChunkX, coords.m_ChunkZ)) { LOGWARNING("Chunk generator overloaded, skipping chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ); @@ -253,8 +261,6 @@ void cChunkGenerator::Execute(void) LOGD("Generating chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ); DoGenerate(coords.m_ChunkX, coords.m_ChunkZ); - m_Queue.erase(m_Queue.begin()); // Remove coordinate from queue - NumChunksGenerated++; } // while (!bStop) } diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h index 17ca8adce..0737834c9 100644 --- a/src/Generating/ChunkGenerator.h +++ b/src/Generating/ChunkGenerator.h @@ -116,7 +116,7 @@ public: void Stop(void); /// Queues the chunk for generation; removes duplicate requests - void QueueGenerateChunk(int a_ChunkX, int a_ChunkZ); + void QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate); /// Generates the biomes for the specified chunk (directly, not in a separate thread). Used by the world loader if biomes failed loading. void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap); @@ -137,10 +137,10 @@ private: int m_Seed; - cCriticalSection m_CS; - cChunkCoordsList m_Queue; - cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate - cEvent m_evtRemoved; ///< Set when an item is removed from the queue + cCriticalSection m_CS; + cChunkCoordWithBoolList m_Queue; + cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate + cEvent m_evtRemoved; ///< Set when an item is removed from the queue cGenerator * m_Generator; ///< The actual generator engine used to generate chunks diff --git a/src/World.cpp b/src/World.cpp index f6fed53ee..2301cd8c6 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2900,7 +2900,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) { m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); - m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ); + m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ, true); } @@ -2909,16 +2909,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ) { - /** Add a chunk to the generation queue, if it's not already present. */ - if (!(m_ChunkMap->IsChunkValid(a_ChunkX, a_ChunkZ))) - { - LOGD("Chunk [%d, %d] already generated, skipping generation", a_ChunkX, a_ChunkZ); - /** Already generated, ignore request */ - } - else - { - m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ); - } + m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ, false); } diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index c4df8c379..0d7698b3d 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -249,7 +249,7 @@ bool cWorldStorage::LoadOneChunk(void) if (ToLoad.m_Generate) { // The chunk couldn't be loaded, generate it: - m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ); + m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ, true); } else { -- cgit v1.2.3 From 554f58501733f00f54e88190bc8ad85bfb11b84f Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Wed, 3 Sep 2014 00:28:08 +0200 Subject: re-add the missing "s" too cChunkCoordsWithBoolList --- src/ChunkDef.h | 2 +- src/Generating/ChunkGenerator.cpp | 2 +- src/Generating/ChunkGenerator.h | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index ded0bdf4c..7247cf5e4 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -404,7 +404,7 @@ public: } }; -typedef std::list cChunkCoordWithBoolList; +typedef std::list cChunkCoordsWithBoolList; diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index 6216958d2..d39b44733 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -105,7 +105,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_Forc cCSLock Lock(m_CS); // Check if it is already in the queue: - for (cChunkCoordWithBoolList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr) + for (cChunkCoordsWithBoolList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr) { if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) { diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h index 0737834c9..e880a6766 100644 --- a/src/Generating/ChunkGenerator.h +++ b/src/Generating/ChunkGenerator.h @@ -137,10 +137,10 @@ private: int m_Seed; - cCriticalSection m_CS; - cChunkCoordWithBoolList m_Queue; - cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate - cEvent m_evtRemoved; ///< Set when an item is removed from the queue + cCriticalSection m_CS; + cChunkCoordsWithBoolList m_Queue; + cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate + cEvent m_evtRemoved; ///< Set when an item is removed from the queue cGenerator * m_Generator; ///< The actual generator engine used to generate chunks -- cgit v1.2.3 From 5a608dc2794aa83ab687db5ae692c2d702729668 Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Wed, 3 Sep 2014 02:53:21 +0200 Subject: adapting format --- src/Generating/BioGen.cpp | 7 ++++--- src/Generating/BioGen.h | 8 ++++++-- src/Generating/ComposableGenerator.cpp | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 69af5c79a..46516b327 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -212,11 +212,12 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile) // cBioGenMulticache: cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength) : -m_CachesLength(a_CachesLength), -m_InternalCacheLength(a_CachesLength * a_CacheSize) + m_CachesLength(a_CachesLength), + m_InternalCacheLength(a_CachesLength * a_CacheSize) { m_Caches.reserve(m_InternalCacheLength); - for (size_t i = 0; i < m_InternalCacheLength; i++) { + for (size_t i = 0; i < m_InternalCacheLength; i++) + { m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize)); } } diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index cfa748ec7..47383633f 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -87,12 +87,16 @@ class cBioGenMulticache : typedef cBiomeGen super; public: + /* + a_CacheSize defines the size of each singular cache + a_CachesLength defines how many caches are used for the multicache + */ cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength); // Doesn't take ownership of a_BioGenToCache ~cBioGenMulticache(); protected: - size_t m_CachesLength; - size_t m_InternalCacheLength; + size_t m_CachesLength; + size_t m_InternalCacheLength; // used internally only std::vector m_Caches; virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 0535e89f3..d70438bf3 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -243,11 +243,13 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) } LOGD("Using a cache for biomegen of size %d.", CacheSize); m_UnderlyingBiomeGen = m_BiomeGen; - if (MultiCacheLength > 0) { + if (MultiCacheLength > 0) + { LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength); m_BiomeGen = new cBioGenMulticache(m_UnderlyingBiomeGen, CacheSize, MultiCacheLength); } - else { + else + { m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize); } -- cgit v1.2.3 From b414e918833999ae0c2b11cefd864ad3c07fc18f Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 2 Sep 2014 22:56:39 -0700 Subject: EntityEffect.cpp: Enable 1.8's leaping potion --- src/Entities/EntityEffect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 3e28392f4..a33955a6a 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -34,6 +34,7 @@ cEntityEffect::eType cEntityEffect::GetPotionEffectType(short a_ItemDamage) case 0x08: return cEntityEffect::effWeakness; case 0x09: return cEntityEffect::effStrength; case 0x0a: return cEntityEffect::effSlowness; + case 0x0b: return cEntityEffect::effJumpBoost; case 0x0c: return cEntityEffect::effInstantDamage; case 0x0d: return cEntityEffect::effWaterBreathing; case 0x0e: return cEntityEffect::effInvisibility; @@ -41,7 +42,6 @@ cEntityEffect::eType cEntityEffect::GetPotionEffectType(short a_ItemDamage) // No effect potions case 0x00: case 0x07: - case 0x0b: // Will be potion of leaping in 1.8 case 0x0f: { break; -- cgit v1.2.3 From 34d6f0713e94b5cb3424be6ed3374afaeca5526b Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 2 Sep 2014 23:21:08 -0700 Subject: Added mutton, which sheep now drop when killed --- src/BlockID.h | 2 ++ src/Items/ItemFood.h | 2 ++ src/Items/ItemHandler.cpp | 2 ++ src/Mobs/Sheep.cpp | 7 +++++++ 4 files changed, 13 insertions(+) diff --git a/src/BlockID.h b/src/BlockID.h index 08c576886..1565fee49 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -362,6 +362,8 @@ enum ENUM_ITEM_ID E_ITEM_LEAD = 420, E_ITEM_NAME_TAG = 421, E_ITEM_MINECART_WITH_COMMAND_BLOCK = 422, + E_ITEM_RAW_MUTTON = 423, + E_ITEM_MUTTON = 424, // Keep these two as the last values of the consecutive list, without a number - they will get their correct number assigned automagically by C++ // IsValidItem() depends on this! diff --git a/src/Items/ItemFood.h b/src/Items/ItemFood.h index 98050cad8..c7e7ef2ca 100644 --- a/src/Items/ItemFood.h +++ b/src/Items/ItemFood.h @@ -47,10 +47,12 @@ public: case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2); case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2); case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8); + case E_ITEM_RAW_MUTTON: return FoodInfo(2, 1.2); case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4); case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8); case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2); case E_ITEM_STEAK: return FoodInfo(8, 12.8); + case E_ITEM_MUTTON: return FoodInfo(6, 9.6); } LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType); return FoodInfo(0, 0.f); diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index bceedaf69..45a779ade 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -223,10 +223,12 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_RAW_CHICKEN: case E_ITEM_RAW_FISH: case E_ITEM_RAW_PORKCHOP: + case E_ITEM_RAW_MUTTON: case E_ITEM_RED_APPLE: case E_ITEM_ROTTEN_FLESH: case E_ITEM_SPIDER_EYE: case E_ITEM_STEAK: + case E_ITEM_MUTTON: { return new cItemFoodHandler(a_ItemType); } diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 9fb47201d..3be688b43 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -39,6 +39,13 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer) { a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor)); } + + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_MUTTON : E_ITEM_RAW_MUTTON); } -- cgit v1.2.3 From 62d5ab15a5b43bb57d7b93898ab21e496893c8a7 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 2 Sep 2014 23:21:34 -0700 Subject: Quick fix for a preprocessor error with clang on OS X --- lib/tolua++/include/tolua++.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tolua++/include/tolua++.h b/lib/tolua++/include/tolua++.h index 8da427fe3..c8b654ae6 100644 --- a/lib/tolua++/include/tolua++.h +++ b/lib/tolua++/include/tolua++.h @@ -36,7 +36,9 @@ extern "C" { #define TEMPLATE_BIND(p) #endif -#define TOLUA_TEMPLATE_BIND(p) +#ifndef TOLUA_TEMPLATE_BIND + #define TOLUA_TEMPLATE_BIND(p) +#endif #define TOLUA_PROTECTED_DESTRUCTOR #define TOLUA_PROPERTY_TYPE(p) -- cgit v1.2.3 From 1cc65b626462ca3e5aff1619e51450b5d33ff717 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 10:29:10 +0200 Subject: Fixed style and alpha-sorting. --- src/BlockID.h | 4 ++-- src/Entities/Entity.cpp | 4 ++-- src/Entities/EntityEffect.cpp | 4 ++-- src/Items/ItemFood.h | 6 +++--- src/Items/ItemHandler.cpp | 8 ++++---- src/Mobs/Sheep.cpp | 14 +++++++------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index 1565fee49..d835f9518 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -362,8 +362,8 @@ enum ENUM_ITEM_ID E_ITEM_LEAD = 420, E_ITEM_NAME_TAG = 421, E_ITEM_MINECART_WITH_COMMAND_BLOCK = 422, - E_ITEM_RAW_MUTTON = 423, - E_ITEM_MUTTON = 424, + E_ITEM_RAW_MUTTON = 423, + E_ITEM_MUTTON = 424, // Keep these two as the last values of the consecutive list, without a number - they will get their correct number assigned automagically by C++ // IsValidItem() depends on this! diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 89d1cffa1..9bcdcffeb 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -387,7 +387,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) case cMonster::mtGhast: case cMonster::mtZombiePigman: case cMonster::mtMagmaCube: - { + { break; }; default: StartBurning(BurnTicks * 20); @@ -417,7 +417,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) } if (!Player->IsOnGround()) - { + { if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack)) { a_TDI.FinalDamage += 2; diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index a33955a6a..f08755674 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -34,11 +34,11 @@ cEntityEffect::eType cEntityEffect::GetPotionEffectType(short a_ItemDamage) case 0x08: return cEntityEffect::effWeakness; case 0x09: return cEntityEffect::effStrength; case 0x0a: return cEntityEffect::effSlowness; - case 0x0b: return cEntityEffect::effJumpBoost; + case 0x0b: return cEntityEffect::effJumpBoost; case 0x0c: return cEntityEffect::effInstantDamage; case 0x0d: return cEntityEffect::effWaterBreathing; case 0x0e: return cEntityEffect::effInvisibility; - + // No effect potions case 0x00: case 0x07: diff --git a/src/Items/ItemFood.h b/src/Items/ItemFood.h index c7e7ef2ca..8bea19fba 100644 --- a/src/Items/ItemFood.h +++ b/src/Items/ItemFood.h @@ -43,16 +43,16 @@ public: case E_ITEM_POISONOUS_POTATO: return FoodInfo(2, 1.2); // Potatoes handled in ItemSeeds case E_ITEM_PUMPKIN_PIE: return FoodInfo(8, 4.8); + case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4); case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8); case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2); case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2); + case E_ITEM_RAW_MUTTON: return FoodInfo(2, 1.2); case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8); - case E_ITEM_RAW_MUTTON: return FoodInfo(2, 1.2); - case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4); case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8); case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2); case E_ITEM_STEAK: return FoodInfo(8, 12.8); - case E_ITEM_MUTTON: return FoodInfo(6, 9.6); + case E_ITEM_MUTTON: return FoodInfo(6, 9.6); } LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType); return FoodInfo(0, 0.f); diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 45a779ade..67c945ce4 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -207,7 +207,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) } // Food (please keep alpha-sorted): - // (carrots and potatoes handled in SeedHandler as both seed and food + // (carrots and potatoes handled separately in SeedHandler as they're both seed and food) case E_ITEM_BAKED_POTATO: case E_ITEM_BREAD: case E_ITEM_COOKED_CHICKEN: @@ -217,18 +217,18 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_GOLDEN_CARROT: case E_ITEM_MELON_SLICE: case E_ITEM_MUSHROOM_SOUP: + case E_ITEM_MUTTON: case E_ITEM_POISONOUS_POTATO: case E_ITEM_PUMPKIN_PIE: + case E_ITEM_RED_APPLE: case E_ITEM_RAW_BEEF: case E_ITEM_RAW_CHICKEN: case E_ITEM_RAW_FISH: + case E_ITEM_RAW_MUTTON: case E_ITEM_RAW_PORKCHOP: - case E_ITEM_RAW_MUTTON: - case E_ITEM_RED_APPLE: case E_ITEM_ROTTEN_FLESH: case E_ITEM_SPIDER_EYE: case E_ITEM_STEAK: - case E_ITEM_MUTTON: { return new cItemFoodHandler(a_ItemType); } diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 3be688b43..1a82115d2 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -39,13 +39,13 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer) { a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor)); } - - int LootingLevel = 0; - if (a_Killer != NULL) - { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); - } - AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_MUTTON : E_ITEM_RAW_MUTTON); + + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_MUTTON : E_ITEM_RAW_MUTTON); } -- cgit v1.2.3 From 42fb71f261519dbb6c417aefea626d01eadf8abb Mon Sep 17 00:00:00 2001 From: LO1ZB Date: Wed, 3 Sep 2014 13:52:32 +0200 Subject: commit --- src/WorldStorage/WorldStorage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index 0d7698b3d..667a28470 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -249,7 +249,7 @@ bool cWorldStorage::LoadOneChunk(void) if (ToLoad.m_Generate) { // The chunk couldn't be loaded, generate it: - m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ, true); + m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ, false); } else { -- cgit v1.2.3 From 9eb07f483a237f3fba21a761e7a19053032d2282 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 16:56:59 +0200 Subject: cBoundingBox: Added accessors. --- src/BoundingBox.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/BoundingBox.h b/src/BoundingBox.h index 793466302..928e62afa 100644 --- a/src/BoundingBox.h +++ b/src/BoundingBox.h @@ -80,6 +80,17 @@ public: /// Calculates the intersection of the two bounding boxes; returns true if nonempty bool Intersect(const cBoundingBox & a_Other, cBoundingBox & a_Intersection); + double GetMinX(void) const { return m_Min.x; } + double GetMinY(void) const { return m_Min.y; } + double GetMinZ(void) const { return m_Min.z; } + + double GetMaxX(void) const { return m_Max.x; } + double GetMaxY(void) const { return m_Max.y; } + double GetMaxZ(void) const { return m_Max.z; } + + const Vector3d & GetMin(void) const { return m_Min; } + const Vector3d & GetMax(void) const { return m_Max; } + protected: Vector3d m_Min; Vector3d m_Max; -- cgit v1.2.3 From a51c1e0b73a83cddcce865671ca30240393e458f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 17:00:26 +0200 Subject: Added cWorld::ForEachEntityInBox() --- src/Bindings/LuaState.cpp | 26 ++++++++++++++++++++++++++ src/Bindings/LuaState.h | 10 ++++++++++ src/Chunk.cpp | 25 +++++++++++++++++++++++++ src/Chunk.h | 4 ++++ src/ChunkMap.cpp | 32 ++++++++++++++++++++++++++++++++ src/ChunkMap.h | 6 ++++++ src/World.cpp | 9 +++++++++ src/World.h | 5 +++++ 8 files changed, 117 insertions(+) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 9fe93ccc2..4ebb1e92f 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -859,6 +859,32 @@ void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal) +void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal) +{ + tolua_Error err; + if (tolua_isusertable(m_LuaState, a_StackPos, "cBoundingBox", false, &err)) + { + a_ReturnedVal = (cBoundingBox *)lua_touserdata(m_LuaState, a_StackPos); + } +} + + + + + +void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal) +{ + tolua_Error err; + if (tolua_isusertable(m_LuaState, a_StackPos, "cWorld", false, &err)) + { + a_ReturnedVal = (cWorld *)lua_touserdata(m_LuaState, a_StackPos); + } +} + + + + + bool cLuaState::CallFunction(int a_NumResults) { ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index eeb93fd4d..fd506b10e 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -59,6 +59,10 @@ class cTNTEntity; class cCreeper; class cHopperEntity; class cBlockEntity; +class cBoundingBox; + +typedef cBoundingBox * pBoundingBox; +typedef cWorld * pWorld; @@ -230,6 +234,12 @@ public: /** Retrieve value at a_StackPos, if it is a valid number, converting and clamping it to eWeather. If not, a_Value is unchanged. */ void GetStackValue(int a_StackPos, eWeather & a_Value); + + /** Retrieve value at a_StackPos, if it is a valid cBoundingBox class. If not, a_Value is unchanged */ + void GetStackValue(int a_StackPos, pBoundingBox & a_Value); + + /** Retrieve value at a_StackPos, if it is a valid cWorld class. If not, a_Value is unchanged */ + void GetStackValue(int a_StackPos, pWorld & a_Value); // Include the cLuaState::Call() overload implementation that is generated by the gen_LuaState_Call.lua script: diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 40ffff834..20e943d9a 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -37,6 +37,7 @@ #include "MobSpawner.h" #include "BlockInServerPluginInterface.h" #include "SetChunkData.h" +#include "BoundingBox.h" #include "json/json.h" @@ -1960,6 +1961,30 @@ bool cChunk::ForEachEntity(cEntityCallback & a_Callback) +bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback) +{ + // The entity list is locked by the parent chunkmap's CS + for (cEntityList::iterator itr = m_Entities.begin(), itr2 = itr; itr != m_Entities.end(); itr = itr2) + { + ++itr2; + cBoundingBox EntBox((*itr)->GetPosition(), (*itr)->GetWidth() / 2, (*itr)->GetHeight()); + if (!EntBox.DoesIntersect(a_Box)) + { + // The entity is not in the specified box + continue; + } + if (a_Callback.Item(*itr)) + { + return false; + } + } // for itr - m_Entitites[] + return true; +} + + + + + bool cChunk::DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult) { // The entity list is locked by the parent chunkmap's CS diff --git a/src/Chunk.h b/src/Chunk.h index e5de22e3b..008a351db 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -216,6 +216,10 @@ public: /** Calls the callback for each entity; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible + /** Calls the callback for each entity that has a nonempty intersection with the specified boundingbox. + Returns true if all entities processed, false if the callback aborted by returning true. */ + bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Lua-accessible + /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. */ bool DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index a3692ef11..ffc5e3d3f 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1775,6 +1775,38 @@ bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback +bool cChunkMap::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback) +{ + // Calculate the chunk range for the box: + int MinChunkX = (int)floor(a_Box.GetMinX() / cChunkDef::Width); + int MinChunkZ = (int)floor(a_Box.GetMinZ() / cChunkDef::Width); + int MaxChunkX = (int)floor((a_Box.GetMaxX() + cChunkDef::Width) / cChunkDef::Width); + int MaxChunkZ = (int)floor((a_Box.GetMaxZ() + cChunkDef::Width) / cChunkDef::Width); + + // Iterate over each chunk in the range: + cCSLock Lock(m_CSLayers); + for (int z = MinChunkZ; z <= MaxChunkZ; z++) + { + for (int x = MinChunkX; x <= MaxChunkX; x++) + { + cChunkPtr Chunk = GetChunkNoGen(x, ZERO_CHUNK_Y, z); + if ((Chunk == NULL) || !Chunk->IsValid()) + { + continue; + } + if (!Chunk->ForEachEntityInBox(a_Box, a_Callback)) + { + return false; + } + } // for x + } // for z + return true; +} + + + + + void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, cVector3iArray & a_BlocksAffected) { // Don't explode if outside of Y range (prevents the following test running into unallocated memory): diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 1e9a0f982..24a91dcd1 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -36,6 +36,7 @@ class cBlockArea; class cMobCensus; class cMobSpawner; class cSetChunkData; +class cBoundingBox; typedef std::list cClientHandleList; typedef cChunk * cChunkPtr; @@ -209,6 +210,11 @@ public: /** Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback); // Lua-accessible + /** Calls the callback for each entity that has a nonempty intersection with the specified boundingbox. + Returns true if all entities processed, false if the callback aborted by returning true. + If any chunk in the box is missing, ignores the entities in that chunk silently. */ + bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Lua-accessible + /** Destroys and returns a list of blocks destroyed in the explosion at the specified coordinates */ void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, cVector3iArray & a_BlockAffected); diff --git a/src/World.cpp b/src/World.cpp index 99e09c658..d3751364f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2696,6 +2696,15 @@ bool cWorld::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & +bool cWorld::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback) +{ + return m_ChunkMap->ForEachEntityInBox(a_Box, a_Callback); +} + + + + + bool cWorld::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback) { return m_ChunkMap->DoWithEntityByID(a_UniqueID, a_Callback); diff --git a/src/World.h b/src/World.h index 578c9682b..d4acb52d4 100644 --- a/src/World.h +++ b/src/World.h @@ -324,6 +324,11 @@ public: /** Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true */ bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback for each entity that has a nonempty intersection with the specified boundingbox. + Returns true if all entities processed, false if the callback aborted by returning true. + If any chunk in the box is missing, ignores the entities in that chunk silently. */ + bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found and callback returned false. */ bool DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp -- cgit v1.2.3 From a9ed5baba35b012f577ca6c6cca970042fc4edf0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 17:01:23 +0200 Subject: Exported ForEachEntityInBox() to Lua API. --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + src/Bindings/ManualBindings.cpp | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index ffd228d1a..718cb4e98 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2344,6 +2344,7 @@ end ForEachBlockEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each block entity in the chunk. Returns true if all block entities in the chunk have been processed (including when there are zero block entities), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])
The callback should return false or no value to continue with the next block entity, or true to abort the enumeration. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." }, ForEachChestInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each chest in the chunk. Returns true if all chests in the chunk have been processed (including when there are zero chests), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cChestEntity|ChestEntity}}, [CallbackData])
The callback should return false or no value to continue with the next chest, or true to abort the enumeration." }, ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, + ForEachEntityInBox = { Params = "{{cBoundingBox|Box}}, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each entity in the specified bounding box. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. If any chunk within the bounding box is not valid, it is silently skipped without any notification. The callback function has the following signature:
function Callback({{cEntity|Entity}})
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}}, [CallbackData])
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." }, ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cPlayer|Player}}, [CallbackData])
The callback should return false or no value to continue with the next player, or true to abort the enumeration." }, diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index adf10a72f..b7ea65759 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -676,6 +676,75 @@ static int tolua_ForEachInChunk(lua_State * tolua_S) +template < + class Ty1, + class Ty2, + bool (Ty1::*Func1)(const cBoundingBox &, cItemCallback &) +> +static int tolua_ForEachInBox(lua_State * tolua_S) +{ + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cWorld") || + !L.CheckParamUserType(2, "cBoundingBox") || + !L.CheckParamFunction(3) || + !L.CheckParamEnd(4) + ) + { + return 0; + } + + // Get the params: + Ty1 * Self = NULL; + cBoundingBox * Box = NULL; + L.GetStackValues(1, Self, Box); + ASSERT(Self != NULL); // We have verified the type at the top, so we should get valid objects here + ASSERT(Box != NULL); + + // Create a reference for the function: + cLuaState::cRef FnRef(L, 3); + + // Callback wrapper for the Lua function: + class cLuaCallback : public cItemCallback + { + public: + cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FuncRef) : + m_LuaState(a_LuaState), + m_FnRef(a_FuncRef) + {} + + private: + // cItemCallback overrides: + virtual bool Item(Ty2 * a_Item) override + { + bool res = false; + if (!m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, res)) + { + LOGWARNING("Failed to call Lua callback"); + m_LuaState.LogStackTrace(); + return true; // Abort enumeration + } + + return res; + } + cLuaState & m_LuaState; + cLuaState::cRef & m_FnRef; + } Callback(L, FnRef); + + bool bRetVal = (Self->*Func1)(*Box, Callback); + + FnRef.UnRef(); + + /* Push return value on stack */ + tolua_pushboolean(tolua_S, bRetVal); + return 1; +} + + + + + template < class Ty1, class Ty2, @@ -3327,6 +3396,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); tolua_function(tolua_S, "ForEachChestInChunk", tolua_ForEachInChunk); tolua_function(tolua_S, "ForEachEntity", tolua_ForEach< cWorld, cEntity, &cWorld::ForEachEntity>); + tolua_function(tolua_S, "ForEachEntityInBox", tolua_ForEachInBox< cWorld, cEntity, &cWorld::ForEachEntityInBox>); tolua_function(tolua_S, "ForEachEntityInChunk", tolua_ForEachInChunk); tolua_function(tolua_S, "ForEachFurnaceInChunk", tolua_ForEachInChunk); tolua_function(tolua_S, "ForEachPlayer", tolua_ForEach< cWorld, cPlayer, &cWorld::ForEachPlayer>); -- cgit v1.2.3 From 5fa1a7fa223324a891c14c8b91544d859ee6fef4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 17:02:16 +0200 Subject: Debuggers: Added a test code for ForEachEntityInBox(). Currently untested, may not run, may crash. --- MCServer/Plugins/Debuggers/Debuggers.lua | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 179935c08..ca764c959 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -65,6 +65,8 @@ function Initialize(Plugin) PM:BindCommand("/sb", "debuggers", HandleSetBiome, "- Sets the biome around you to the specified one"); PM:BindCommand("/wesel", "debuggers", HandleWESel, "- Expands the current WE selection by 1 block in X/Z"); PM:BindCommand("/rmitem", "debuggers", HandleRMItem, "- Remove the specified item from the inventory."); + PM:BindCommand("/pickups", "debuggers", HandlePickups, "- Spawns random pickups around you"); + PM:BindCommand("/poof", "debuggers", HandlePoof, "- Nudges pickups close to you away from you"); Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers) Plugin:AddWebTab("StressTest", HandleRequest_StressTest) @@ -1558,3 +1560,50 @@ end + +local PossibleItems = +{ + cItem(E_ITEM_DIAMOND), + cItem(E_ITEM_GOLD), + cItem(E_ITEM_IRON), + cItem(E_ITEM_DYE, E_META_DYE_BLUE), -- Lapis lazuli + cItem(E_ITEM_COAL), +} + + + + + +function HandlePickups(a_Split, a_Player) + local PlayerX = a_Player:GetPosX() + local PlayerY = a_Player:GetPosY() + local PlayerZ = a_Player:GetPosZ() + local World = a_Player:GetWorld() + local Range = 15 + for x = 0, Range do for z = 0, Range do + local x = PlayerX + x - Range / 2 + local z = PlayerZ + z - Range / 2 + local Items = cItems() + Items:Add(PossibleItems[math.random(#PossibleItems)]) + World:SpawnItemPickups(Items, x, PlayerY, z, 0) + end end -- for z, for x +end + + + + +function HandlePoof(a_Split, a_Player) + local PlayerPos = a_Player:GetPos() + local Box = cBoundingBox(PlayerPos, a_Player:GetWidth() / 2, a_Player:GetHeight()) + a_Player:GetWorld():ForEachEntityInBox(Box, + function (a_Entity) + local AddSpeed = PlayerPos - a_Entity:GetPosition() -- Speed away from the player + a_Entity:AddSpeed(AddSpeed / AddSpeed:SqrLength()) -- The further away, the less speed to add + end + ) + a_Player:SendMessage("Poof!") +end + + + + -- cgit v1.2.3 From d2bacc34f6b4e9b0d7a6db9ba81d76c51b1fd60f Mon Sep 17 00:00:00 2001 From: DayBr3ak Date: Wed, 3 Sep 2014 18:48:47 +0200 Subject: change to linear calculation --- src/Generating/BioGen.cpp | 13 ++++++------- src/Generating/BioGen.h | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 46516b327..175e4ef33 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -151,7 +151,7 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a LOGD("BioGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses)); LOGD("BioGenCache: Avg cache chain length: %.2f", (float)m_TotalChain / m_NumHits); } - + for (int i = 0; i < m_CacheSize; i++) { if ( @@ -212,11 +212,10 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile) // cBioGenMulticache: cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength) : - m_CachesLength(a_CachesLength), - m_InternalCacheLength(a_CachesLength * a_CacheSize) + m_CachesLength(a_CachesLength) { - m_Caches.reserve(m_InternalCacheLength); - for (size_t i = 0; i < m_InternalCacheLength; i++) + m_Caches.reserve(a_CachesLength); + for (size_t i = 0; i < a_CachesLength; i++) { m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize)); } @@ -240,8 +239,8 @@ cBioGenMulticache::~cBioGenMulticache() void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) { - size_t cacheIdx = ((size_t)a_ChunkX % m_CachesLength) * m_CachesLength - + ((size_t)a_ChunkZ % m_CachesLength); + const size_t coefficient = 3; + const size_t cacheIdx = ((size_t)a_ChunkX + coefficient * (size_t)a_ChunkZ) % m_CachesLength; m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); } diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index 47383633f..a4cf95a72 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -95,8 +95,7 @@ public: ~cBioGenMulticache(); protected: - size_t m_CachesLength; - size_t m_InternalCacheLength; // used internally only + size_t m_CachesLength; std::vector m_Caches; virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; -- cgit v1.2.3 From 44c1d9c2480fe6ea37dbed6199b51acf035de0c2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 19:36:53 +0200 Subject: Anvil: switched inflate to stream mode. This removes the fixed-size buffer which could have caused #1307 and #1366. --- src/StringCompression.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ src/StringCompression.h | 2 ++ src/WorldStorage/WSSAnvil.cpp | 24 +++++------------ 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/src/StringCompression.cpp b/src/StringCompression.cpp index 71d64e71e..af9f1687f 100644 --- a/src/StringCompression.cpp +++ b/src/StringCompression.cpp @@ -180,3 +180,65 @@ extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString & + +extern int InflateString(const char * a_Data, size_t a_Length, AString & a_Uncompressed) +{ + a_Uncompressed.reserve(a_Length); + + char Buffer[64 KiB]; + z_stream strm; + memset(&strm, 0, sizeof(strm)); + strm.next_in = (Bytef *)a_Data; + strm.avail_in = (uInt)a_Length; + strm.next_out = (Bytef *)Buffer; + strm.avail_out = sizeof(Buffer); + + int res = inflateInit(&strm); // Force GZIP decoding + if (res != Z_OK) + { + LOG("%s: inflation initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg); + return res; + } + + for (;;) + { + res = inflate(&strm, Z_NO_FLUSH); + switch (res) + { + case Z_OK: + { + // Some data has been uncompressed. Consume the buffer and continue uncompressing + a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out); + strm.next_out = (Bytef *)Buffer; + strm.avail_out = sizeof(Buffer); + if (strm.avail_in == 0) + { + // All data has been uncompressed + inflateEnd(&strm); + return Z_OK; + } + break; + } + + case Z_STREAM_END: + { + // Finished uncompressing. Consume the rest of the buffer and return + a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out); + inflateEnd(&strm); + return Z_OK; + } + + default: + { + // An error has occurred, log it and return the error value + LOG("%s: inflation failed: %d (\"%s\").", __FUNCTION__, res, strm.msg); + inflateEnd(&strm); + return res; + } + } // switch (res) + } // while (true) +} + + + + diff --git a/src/StringCompression.h b/src/StringCompression.h index 038240797..dde17ce30 100644 --- a/src/StringCompression.h +++ b/src/StringCompression.h @@ -21,5 +21,7 @@ extern int CompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_ /// Uncompresses a_Data into a_Uncompressed using GZIP; returns Z_OK for success or Z_XXX error constants same as zlib extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Uncompressed); +/** Uncompresses a_Data into a_Uncompressed using Inflate; returns Z_OK for success or Z_XXX error constants same as zlib */ +extern int InflateString(const char * a_Data, size_t a_Length, AString & a_Uncompressed); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 815b6544f..239f4a155 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -66,9 +66,6 @@ Since only the header is actually in the memory, this number can be high, but st */ #define MAX_MCA_FILES 32 -/// The maximum size of an inflated chunk; raw chunk data is 192 KiB, allow 64 KiB more of entities -#define CHUNK_INFLATE_MAX 256 KiB - #define LOAD_FAILED(CHX, CHZ) \ { \ const int RegionX = FAST_FLOOR_DIV(CHX, 32); \ @@ -260,27 +257,18 @@ cWSSAnvil::cMCAFile * cWSSAnvil::LoadMCAFile(const cChunkCoords & a_Chunk) bool cWSSAnvil::LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & a_Data) { - // Decompress the data: - char Uncompressed[CHUNK_INFLATE_MAX]; - z_stream strm; - strm.zalloc = (alloc_func)NULL; - strm.zfree = (free_func)NULL; - strm.opaque = NULL; - inflateInit(&strm); - strm.next_out = (Bytef *)Uncompressed; - strm.avail_out = sizeof(Uncompressed); - strm.next_in = (Bytef *)a_Data.data(); - strm.avail_in = (uInt)a_Data.size(); - int res = inflate(&strm, Z_FINISH); - inflateEnd(&strm); - if (res != Z_STREAM_END) + // Uncompress the data: + AString Uncompressed; + int res = InflateString(a_Data.data(), a_Data.size(), Uncompressed); + if (res != Z_OK) { + LOGWARNING("Uncompressing chunk [%d, %d] failed: %d", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, res); LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } // Parse the NBT data: - cParsedNBT NBT(Uncompressed, strm.total_out); + cParsedNBT NBT(Uncompressed.data(), Uncompressed.size()); if (!NBT.IsValid()) { // NBT Parsing failed -- cgit v1.2.3 From b4c6ad0036bf6cf83e2d5e56defcefdcf6f2d4a4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 22:37:31 +0200 Subject: Updated SQLiteCpp. This should fix #1374. --- lib/SQLiteCpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SQLiteCpp b/lib/SQLiteCpp index 27b9d1118..203c2fb68 160000 --- a/lib/SQLiteCpp +++ b/lib/SQLiteCpp @@ -1 +1 @@ -Subproject commit 27b9d111818af3b05bcf4153bb6e380fe1dd6816 +Subproject commit 203c2fb68bbf871eaf4ca98756a113d74d620dea -- cgit v1.2.3 From fac89d0c437c822e41fe12529a875279f48fd2d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 23:00:16 +0200 Subject: Added cIniFile::HasValue() function. --- lib/inifile/iniFile.cpp | 18 ++++++++++++++++++ lib/inifile/iniFile.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index 2bf6c91ed..7cfe7661f 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -668,6 +668,24 @@ void cIniFile::Clear(void) +bool cIniFile::HasValue(const AString & a_KeyName, const AString & a_ValueName) +{ + // Find the key: + int keyID = FindKey(a_KeyName); + if (keyID == noID) + { + return false; + } + + // Find the value: + int valueID = FindValue(keyID, a_ValueName); + return (valueID != noID); +} + + + + + void cIniFile::AddHeaderComment(const AString & comment) { comments.push_back(comment); diff --git a/lib/inifile/iniFile.h b/lib/inifile/iniFile.h index 58fecd0cf..33229bff0 100644 --- a/lib/inifile/iniFile.h +++ b/lib/inifile/iniFile.h @@ -53,7 +53,9 @@ private: /// Removes the UTF-8 BOMs (Byte order makers), if present. void RemoveBom(AString & a_line) const; + public: + enum errors { noID = -1, @@ -79,6 +81,9 @@ public: /// Deletes all stored ini data (but doesn't touch the file) void Clear(void); + + /** Returns true iff the specified value exists. */ + bool HasValue(const AString & a_KeyName, const AString & a_ValueName); /// Returns index of specified key, or noID if not found int FindKey(const AString & keyname) const; -- cgit v1.2.3 From bae928fd27cb26ec55db04f64d8de888443d65a0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 23:02:00 +0200 Subject: ChunkGenerator: Log world seed when creating a new one. --- src/Generating/ChunkGenerator.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index d39b44733..4fa9729ec 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -52,10 +52,21 @@ bool cChunkGenerator::Start(cPluginInterface & a_PluginInterface, cChunkSink & a m_PluginInterface = &a_PluginInterface; m_ChunkSink = &a_ChunkSink; - MTRand rnd; - m_Seed = a_IniFile.GetValueSetI("Seed", "Seed", (int)rnd.randInt()); + // Get the seed; create a new one and log it if not found in the INI file: + if (a_IniFile.HasValue("Seed", "Seed")) + { + m_Seed = a_IniFile.GetValueI("Seed", "Seed"); + } + else + { + MTRand rnd; + m_Seed = rnd.randInt(); + LOGINFO("Chosen a new random seed for world: %d", m_Seed); + a_IniFile.SetValueI("Seed", "Seed", m_Seed); + } + + // Get the generator engine based on the INI file settings: AString GeneratorName = a_IniFile.GetValueSet("Generator", "Generator", "Composable"); - if (NoCaseCompare(GeneratorName, "Noise3D") == 0) { m_Generator = new cNoise3DGenerator(*this); -- cgit v1.2.3 From 06c66a08cdbfbbac56d79a175bcc6142d690cc94 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 23:05:03 +0200 Subject: LuaState: Fixed referenced function pushing. The references are no longer destroyed by the call. --- src/Bindings/LuaState.h | 8 ++++++++ src/Bindings/gen_LuaState_Call.lua | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index fd506b10e..44f187701 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -338,6 +338,14 @@ protected: */ bool PushFunction(int a_FnRef); + /** Pushes a function that has been saved as a reference. + Returns true if successful. Logs a warning on failure + */ + bool PushFunction(const cRef & a_FnRef) + { + return PushFunction((int)a_FnRef); + } + /** Pushes a function that is stored in a referenced table by name Returns true if successful. Logs a warning on failure */ diff --git a/src/Bindings/gen_LuaState_Call.lua b/src/Bindings/gen_LuaState_Call.lua index 2d8630d12..7f62573c7 100644 --- a/src/Bindings/gen_LuaState_Call.lua +++ b/src/Bindings/gen_LuaState_Call.lua @@ -109,7 +109,7 @@ local function WriteOverload(f, a_NumParams, a_NumReturns) -- Write the function signature: f:write("bool Call(") - f:write("FnT a_Function") + f:write("const FnT & a_Function") for i = 1, a_NumParams do f:write(", ParamT", i, " a_Param", i) end -- cgit v1.2.3 From 014a55a15ac77d274538236228ec990be9269080 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 23:05:22 +0200 Subject: LuaState: Fixed class value-getting off the stack. --- src/Bindings/LuaState.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 4ebb1e92f..ba2f3c5e0 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -862,9 +862,9 @@ void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal) void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal) { tolua_Error err; - if (tolua_isusertable(m_LuaState, a_StackPos, "cBoundingBox", false, &err)) + if (tolua_isusertype(m_LuaState, a_StackPos, "cBoundingBox", false, &err)) { - a_ReturnedVal = (cBoundingBox *)lua_touserdata(m_LuaState, a_StackPos); + a_ReturnedVal = *((cBoundingBox **)lua_touserdata(m_LuaState, a_StackPos)); } } @@ -875,9 +875,9 @@ void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal) void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal) { tolua_Error err; - if (tolua_isusertable(m_LuaState, a_StackPos, "cWorld", false, &err)) + if (tolua_isusertype(m_LuaState, a_StackPos, "cWorld", false, &err)) { - a_ReturnedVal = (cWorld *)lua_touserdata(m_LuaState, a_StackPos); + a_ReturnedVal = *((cWorld **)lua_touserdata(m_LuaState, a_StackPos)); } } -- cgit v1.2.3 From 1b9edb0279b008cf549d75fa3135c166503bf9bc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 3 Sep 2014 23:05:49 +0200 Subject: Debuggers: Reviewed and fixed the Pickups and Poof commands. Now they're confirmed working. --- MCServer/Plugins/Debuggers/Debuggers.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index ca764c959..0e7e647d5 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -1566,7 +1566,7 @@ local PossibleItems = cItem(E_ITEM_DIAMOND), cItem(E_ITEM_GOLD), cItem(E_ITEM_IRON), - cItem(E_ITEM_DYE, E_META_DYE_BLUE), -- Lapis lazuli + cItem(E_ITEM_DYE, 1, E_META_DYE_BLUE), -- Lapis lazuli cItem(E_ITEM_COAL), } @@ -1579,29 +1579,36 @@ function HandlePickups(a_Split, a_Player) local PlayerY = a_Player:GetPosY() local PlayerZ = a_Player:GetPosZ() local World = a_Player:GetWorld() - local Range = 15 + local Range = 12 for x = 0, Range do for z = 0, Range do - local x = PlayerX + x - Range / 2 - local z = PlayerZ + z - Range / 2 + local px = PlayerX + x - Range / 2 + local pz = PlayerZ + z - Range / 2 local Items = cItems() Items:Add(PossibleItems[math.random(#PossibleItems)]) - World:SpawnItemPickups(Items, x, PlayerY, z, 0) + World:SpawnItemPickups(Items, px, PlayerY, pz, 0) end end -- for z, for x + return true end function HandlePoof(a_Split, a_Player) - local PlayerPos = a_Player:GetPos() - local Box = cBoundingBox(PlayerPos, a_Player:GetWidth() / 2, a_Player:GetHeight()) + local PlayerPos = Vector3d(a_Player:GetPosition()) -- Create a copy of the position + PlayerPos.y = PlayerPos.y - 1 + local Box = cBoundingBox(PlayerPos, 4, 2) + local NumEntities = 0 a_Player:GetWorld():ForEachEntityInBox(Box, function (a_Entity) - local AddSpeed = PlayerPos - a_Entity:GetPosition() -- Speed away from the player - a_Entity:AddSpeed(AddSpeed / AddSpeed:SqrLength()) -- The further away, the less speed to add + if not(a_Entity:IsPlayer()) then + local AddSpeed = a_Entity:GetPosition() - PlayerPos -- Speed away from the player + a_Entity:AddSpeed(AddSpeed * 32 / (AddSpeed:SqrLength() + 1)) -- The further away, the less speed to add + NumEntities = NumEntities + 1 + end end ) - a_Player:SendMessage("Poof!") + a_Player:SendMessage("Poof! (" .. NumEntities .. " entities)") + return true end -- cgit v1.2.3 From 472efa8174626a00ffdf5b39e1a44ac419cd3698 Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 3 Sep 2014 16:12:43 -0700 Subject: Globals.h: Added Floor and Ciel casting, C++ cast cleanups, etc Snow Golems must also be above 64Y to spawn snow (as of 1.8). --- src/Entities/Entity.h | 6 +++--- src/Globals.h | 40 ++++++++++++++++++++++++++++++++++++---- src/Mobs/SnowGolem.cpp | 12 +++++++----- src/Vector3.h | 33 ++++++++++++++++----------------- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b9c280b6b..73e8a0d8b 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -27,9 +27,9 @@ return super::GetClass(); \ } -#define POSX_TOINT (int)floor(GetPosX()) -#define POSY_TOINT (int)floor(GetPosY()) -#define POSZ_TOINT (int)floor(GetPosZ()) +#define POSX_TOINT FloorD(GetPosX()) +#define POSY_TOINT FloorD(GetPosY()) +#define POSZ_TOINT FloorD(GetPosZ()) #define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT) #define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == NULL) || !ChunkVarName->IsValid()) { return; } diff --git a/src/Globals.h b/src/Globals.h index de1024010..a782de325 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -217,10 +217,10 @@ template class SizeChecker; // CRT stuff: #include -#include -#include -#include -#include +#include +#include +#include +#include @@ -370,6 +370,38 @@ T Clamp(T a_Value, T a_Min, T a_Max) +/** Floors a_Value, then casts it to C (an int by default) */ +template +C FloorD(double a_Value) +{ + return static_cast(std::floor(a_Value)); +} + +/** Floors a_Value, then casts it to C (an int by default) */ +template +C FloorF(double a_Value) +{ + return static_cast(std::floorf(a_Value)); +} + +/** Ciels a_Value, then casts it to C (an int by default) */ +template +C CeilD(double a_Value) +{ + return static_cast(std::ceil(a_Value)); +} + +/** Ciels a_Value, then casts it to C (an int by default) */ +template +C CeilF(double a_Value) +{ + return static_cast(std::ceilf(a_Value)); +} + + + + + #ifndef TOLUA_TEMPLATE_BIND #define TOLUA_TEMPLATE_BIND(x) #endif diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 76334d970..43ce16ee4 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -30,17 +30,19 @@ void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (IsBiomeNoDownfall(m_World->GetBiomeAt((int) floor(GetPosX()), (int) floor(GetPosZ())))) + if (IsBiomeNoDownfall(m_World->GetBiomeAt(POSX_TOINT, POSZ_TOINT))) { TakeDamage(*this); } else { - BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ())); - BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ())); - if (Block == E_BLOCK_AIR && cBlockInfo::IsSolid(BlockBelow)) + BLOCKTYPE BlockBelow = m_World->GetBlock(POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT); + if (Block == E_BLOCK_AIR + && cBlockInfo::IsSolid(BlockBelow) + && GetPosY() >= 64) // Must be at at least 64Y for snow to form { - m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0); + m_World->SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_SNOW, 0); } } } diff --git a/src/Vector3.h b/src/Vector3.h index 1dcb38f64..782b0d1c9 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -4,7 +4,6 @@ #define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC) -#include #include #include @@ -29,9 +28,9 @@ public: // Hardcoded copy constructors (tolua++ does not support function templates .. yet) - 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) {} + Vector3(const Vector3 & a_Rhs) : x(static_cast(a_Rhs.x)), y(static_cast(a_Rhs.y)), z(static_cast(a_Rhs.z)) {} + Vector3(const Vector3 & a_Rhs) : x(static_cast(a_Rhs.x)), y(static_cast(a_Rhs.y)), z(static_cast(a_Rhs.z)) {} + Vector3(const Vector3 & a_Rhs) : x(static_cast(a_Rhs.x)), y(static_cast(a_Rhs.y)), z(static_cast(a_Rhs.z)) {} // tolua_end @@ -53,9 +52,9 @@ public: { double Len = 1.0 / Length(); - x = (T)(x * Len); - y = (T)(y * Len); - z = (T)(z * Len); + x = static_cast(x * Len); + y = static_cast(y * Len); + z = static_cast(z * Len); } inline Vector3 NormalizeCopy(void) const @@ -63,9 +62,9 @@ public: double Len = 1.0 / Length(); return Vector3( - (T)(x * Len), - (T)(y * Len), - (T)(z * Len) + static_cast(x * Len), + static_cast(y * Len), + static_cast(z * Len) ); } @@ -74,15 +73,15 @@ public: double Len = 1.0 / Length(); a_Rhs.Set( - (T)(x * Len), - (T)(y * Len), - (T)(z * Len) + static_cast(x * Len), + static_cast(y * Len), + static_cast(z * Len) ); } inline double Length(void) const { - return sqrt((double)(x * x + y * y + z * z)); + return sqrt(static_cast(x * x + y * y + z * z)); } inline double SqrLength(void) const @@ -138,9 +137,9 @@ public: inline Vector3 Floor(void) const { return Vector3( - (int)floor(x), - (int)floor(y), - (int)floor(z) + static_cast(floor(x)), + static_cast(floor(y)), + static_cast(floor(z)) ); } -- cgit v1.2.3 From 19067b27de62574c338eed45ddabdfee2ad89d9c Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 3 Sep 2014 16:18:58 -0700 Subject: In 1.8, carrots and potatoes yield one less hunger point. --- src/Items/ItemFood.h | 2 +- src/Items/ItemSeeds.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Items/ItemFood.h b/src/Items/ItemFood.h index 8bea19fba..9035344df 100644 --- a/src/Items/ItemFood.h +++ b/src/Items/ItemFood.h @@ -29,7 +29,7 @@ public: switch (m_ItemType) { // Please keep alpha-sorted. - case E_ITEM_BAKED_POTATO: return FoodInfo(6, 7.2); + case E_ITEM_BAKED_POTATO: return FoodInfo(5, 7.2); case E_ITEM_BREAD: return FoodInfo(5, 6); // Carrots handled in ItemSeeds case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2); diff --git a/src/Items/ItemSeeds.h b/src/Items/ItemSeeds.h index 54a1183d7..e1db7c5f4 100644 --- a/src/Items/ItemSeeds.h +++ b/src/Items/ItemSeeds.h @@ -37,7 +37,7 @@ public: { switch (m_ItemType) { - case E_ITEM_CARROT: return FoodInfo(4, 4.8); + case E_ITEM_CARROT: return FoodInfo(3, 4.8); case E_ITEM_POTATO: return FoodInfo(1, 0.6); default: return FoodInfo(0, 0); } -- cgit v1.2.3 From e1206568ec71c0e7017c1f764fdc146ba86ce30a Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 3 Sep 2014 16:22:04 -0700 Subject: Revert "Globals.h: Added Floor and Ciel casting, C++ cast cleanups, etc" This reverts commit 472efa8174626a00ffdf5b39e1a44ac419cd3698. Apparently we don't support some of these features quite yet (darn you C++98!) --- src/Entities/Entity.h | 6 +++--- src/Globals.h | 40 ++++------------------------------------ src/Mobs/SnowGolem.cpp | 12 +++++------- src/Vector3.h | 33 +++++++++++++++++---------------- 4 files changed, 29 insertions(+), 62 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 73e8a0d8b..b9c280b6b 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -27,9 +27,9 @@ return super::GetClass(); \ } -#define POSX_TOINT FloorD(GetPosX()) -#define POSY_TOINT FloorD(GetPosY()) -#define POSZ_TOINT FloorD(GetPosZ()) +#define POSX_TOINT (int)floor(GetPosX()) +#define POSY_TOINT (int)floor(GetPosY()) +#define POSZ_TOINT (int)floor(GetPosZ()) #define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT) #define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == NULL) || !ChunkVarName->IsValid()) { return; } diff --git a/src/Globals.h b/src/Globals.h index a782de325..de1024010 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -217,10 +217,10 @@ template class SizeChecker; // CRT stuff: #include -#include -#include -#include -#include +#include +#include +#include +#include @@ -370,38 +370,6 @@ T Clamp(T a_Value, T a_Min, T a_Max) -/** Floors a_Value, then casts it to C (an int by default) */ -template -C FloorD(double a_Value) -{ - return static_cast(std::floor(a_Value)); -} - -/** Floors a_Value, then casts it to C (an int by default) */ -template -C FloorF(double a_Value) -{ - return static_cast(std::floorf(a_Value)); -} - -/** Ciels a_Value, then casts it to C (an int by default) */ -template -C CeilD(double a_Value) -{ - return static_cast(std::ceil(a_Value)); -} - -/** Ciels a_Value, then casts it to C (an int by default) */ -template -C CeilF(double a_Value) -{ - return static_cast(std::ceilf(a_Value)); -} - - - - - #ifndef TOLUA_TEMPLATE_BIND #define TOLUA_TEMPLATE_BIND(x) #endif diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 43ce16ee4..76334d970 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -30,19 +30,17 @@ void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (IsBiomeNoDownfall(m_World->GetBiomeAt(POSX_TOINT, POSZ_TOINT))) + if (IsBiomeNoDownfall(m_World->GetBiomeAt((int) floor(GetPosX()), (int) floor(GetPosZ())))) { TakeDamage(*this); } else { - BLOCKTYPE BlockBelow = m_World->GetBlock(POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT); - BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT); - if (Block == E_BLOCK_AIR - && cBlockInfo::IsSolid(BlockBelow) - && GetPosY() >= 64) // Must be at at least 64Y for snow to form + BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ())); + if (Block == E_BLOCK_AIR && cBlockInfo::IsSolid(BlockBelow)) { - m_World->SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_SNOW, 0); + m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0); } } } diff --git a/src/Vector3.h b/src/Vector3.h index 782b0d1c9..1dcb38f64 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -4,6 +4,7 @@ #define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC) +#include #include #include @@ -28,9 +29,9 @@ public: // Hardcoded copy constructors (tolua++ does not support function templates .. yet) - Vector3(const Vector3 & a_Rhs) : x(static_cast(a_Rhs.x)), y(static_cast(a_Rhs.y)), z(static_cast(a_Rhs.z)) {} - Vector3(const Vector3 & a_Rhs) : x(static_cast(a_Rhs.x)), y(static_cast(a_Rhs.y)), z(static_cast(a_Rhs.z)) {} - Vector3(const Vector3 & a_Rhs) : x(static_cast(a_Rhs.x)), y(static_cast(a_Rhs.y)), z(static_cast(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 @@ -52,9 +53,9 @@ public: { double Len = 1.0 / Length(); - x = static_cast(x * Len); - y = static_cast(y * Len); - z = static_cast(z * Len); + x = (T)(x * Len); + y = (T)(y * Len); + z = (T)(z * Len); } inline Vector3 NormalizeCopy(void) const @@ -62,9 +63,9 @@ public: double Len = 1.0 / Length(); return Vector3( - static_cast(x * Len), - static_cast(y * Len), - static_cast(z * Len) + (T)(x * Len), + (T)(y * Len), + (T)(z * Len) ); } @@ -73,15 +74,15 @@ public: double Len = 1.0 / Length(); a_Rhs.Set( - static_cast(x * Len), - static_cast(y * Len), - static_cast(z * Len) + (T)(x * Len), + (T)(y * Len), + (T)(z * Len) ); } inline double Length(void) const { - return sqrt(static_cast(x * x + y * y + z * z)); + return sqrt((double)(x * x + y * y + z * z)); } inline double SqrLength(void) const @@ -137,9 +138,9 @@ public: inline Vector3 Floor(void) const { return Vector3( - static_cast(floor(x)), - static_cast(floor(y)), - static_cast(floor(z)) + (int)floor(x), + (int)floor(y), + (int)floor(z) ); } -- cgit v1.2.3 From d77221c7157a7a371cdbc7b00abe287199be3c86 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 4 Sep 2014 14:00:54 +0200 Subject: Anvil: Cleanly refuse to store data that is too large. Each chunk in MCA needs to be less than 1 MiB compressed; chunks that are larger will be refused with a log message. --- src/WorldStorage/WSSAnvil.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 239f4a155..4d2f92173 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2905,7 +2905,13 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri // Store the header: ChunkSize = ((u_long)a_Data.size() + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size *up* to nearest 4KB sector, make it a sector number - ASSERT(ChunkSize < 256); + if (ChunkSize > 255) + { + LOGWARNING("Cannot save chunk [%d, %d], the data is too large (%u KiB, maximum is 1024 KiB). Remove some entities and retry.", + a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, (unsigned)(ChunkSize * 4) + ); + return false; + } m_Header[LocalX + 32 * LocalZ] = htonl((ChunkSector << 8) | ChunkSize); if (m_File.Seek(0) < 0) { -- cgit v1.2.3 From 7ab4c078b873433a9b353b742a9a39540dd5219b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 4 Sep 2014 14:05:42 +0200 Subject: Fixed compilation after chunk Y removal. --- src/ChunkMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 557434fbb..8c765c8c9 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1789,7 +1789,7 @@ bool cChunkMap::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & { for (int x = MinChunkX; x <= MaxChunkX; x++) { - cChunkPtr Chunk = GetChunkNoGen(x, ZERO_CHUNK_Y, z); + cChunkPtr Chunk = GetChunkNoGen(x, z); if ((Chunk == NULL) || !Chunk->IsValid()) { continue; -- cgit v1.2.3