From 485752de82e6058473dfe8dccdf64ac04e983ae9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 20:59:04 +0100 Subject: Implemented Allocation Pool --- src/AllocationPool.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/AllocationPool.h diff --git a/src/AllocationPool.h b/src/AllocationPool.h new file mode 100644 index 000000000..f03897f98 --- /dev/null +++ b/src/AllocationPool.h @@ -0,0 +1,50 @@ + +#pragma once + +template +class AllocationPool { + public: + + ~AllocationPool() + { + while (!m_FreeList.empty()) + { + delete m_FreeList.front(); + m_FreeList.pop_front(); + } + } + + T* Allocate() + { + if (m_FreeList.Size() <= BufferSize) + { + try + { + return new T; + } + catch (std::bad_alloc& ex) + { + if (m_FreeList.size() == BufferSize) + { + StarvationCallbacks.OnStartingUsingBuffer(); + } + else if (m_FreeList.empty()) + { + StarvationCallbacks.OnBufferEmpty(); + // Try again until the memory is avalable + return Allocate(); + } + } + } + T* ret = m_FreeList.front(); + m_FreeList.pop_front(); + return ret; + } + void Free(T* ptr) + { + m_FreeList.push_front(ptr); + } + + private: + std::list m_FreeList; +} -- cgit v1.2.3 From 4124eac15d6b545b685e58f9f5f3a0266c1d8df0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 21:30:08 +0100 Subject: Added callback for stopping starvation mode --- src/AllocationPool.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index f03897f98..f1e324953 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -43,6 +43,10 @@ class AllocationPool { void Free(T* ptr) { m_FreeList.push_front(ptr); + if (m_FreeList.size() == BufferSize) + { + StarvationCallbacks.OnStopUsingBuffer(); + } } private: -- cgit v1.2.3 From 5ef6c8fe72f96dec20e2305ba190759c17512861 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 22 May 2014 10:54:07 +0200 Subject: Both SetSpeed functions are now overridden by cPlayer --- src/Entities/Entity.h | 13 ++++++++----- src/Entities/Player.cpp | 20 ++++++++++++++++++++ src/Entities/Player.h | 5 ++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 0c393c0f5..0ea27ef10 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -214,8 +214,14 @@ public: void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180) void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180) void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180) - void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); - void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } + // tolua_end + + /** Measured in meter/second (m/s) */ + Vector3d m_Speed; + + // tolua_begin + virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); + virtual void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } void SetSpeedX (double a_SpeedX); void SetSpeedY (double a_SpeedY); void SetSpeedZ (double a_SpeedZ); @@ -504,9 +510,6 @@ private: /** Measured in degrees, [-180, +180) */ double m_HeadYaw; - /** Measured in meter/second (m/s) */ - Vector3d m_Speed; - /** Measured in degrees, [-180, +180) */ Vector3d m_Rot; diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c3b763278..48320b6c9 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1252,6 +1252,26 @@ void cPlayer::ForceSetSpeed(const Vector3d & a_Speed) +void cPlayer::SetSpeed(const Vector3d & a_Speed) +{ + m_Speed.Set(a_Speed.x, a_Speed.y, a_Speed.z); + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + +void cPlayer::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) +{ + m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ); + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + void cPlayer::MoveTo( const Vector3d & a_NewPos ) { if ((a_NewPos.y < -990) && (GetPosY() > -100)) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 78b534d83..43f27e045 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -191,9 +191,12 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /** Forces the player to move in the given direction. */ + /** Forces the player to move in the given direction. DEPRECATED! Use SetSpeed instead */ void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export + virtual void SetSpeed(const Vector3d & a_Speed) override; + virtual void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override + /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From 73455d293861c492388f3a28af3380318eaa0bae Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 22 May 2014 11:08:44 +0200 Subject: cPlayer overrides the SetSpeedXX functions Fixed compile error --- src/Entities/Entity.h | 6 +++--- src/Entities/Player.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/Entities/Player.h | 6 +++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 0ea27ef10..fc72462c3 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -222,9 +222,9 @@ public: // tolua_begin virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); virtual void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } - void SetSpeedX (double a_SpeedX); - void SetSpeedY (double a_SpeedY); - void SetSpeedZ (double a_SpeedZ); + virtual void SetSpeedX (double a_SpeedX); + virtual void SetSpeedY (double a_SpeedY); + virtual void SetSpeedZ (double a_SpeedZ); void SetWidth (double a_Width); void AddPosX (double a_AddPosX); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 48320b6c9..0d79ff533 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1255,6 +1255,9 @@ void cPlayer::ForceSetSpeed(const Vector3d & a_Speed) void cPlayer::SetSpeed(const Vector3d & a_Speed) { m_Speed.Set(a_Speed.x, a_Speed.y, a_Speed.z); + WrapSpeed(); + + // Send the speed to the client so he actualy moves m_ClientHandle->SendEntityVelocity(*this); } @@ -1265,6 +1268,48 @@ void cPlayer::SetSpeed(const Vector3d & a_Speed) void cPlayer::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) { m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ); + WrapSpeed(); + + // Send the speed to the client so he actualy moves + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + +void cPlayer::SetSpeedX(double a_SpeedX) +{ + m_Speed.x = a_SpeedX; + WrapSpeed(); + + // Send the speed to the client so he actualy moves + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + +void cPlayer::SetSpeedY(double a_SpeedY) +{ + m_Speed.y = a_SpeedY; + WrapSpeed(); + + // Send the speed to the client so he actualy moves + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + +void cPlayer::SetSpeedZ(double a_SpeedZ) +{ + m_Speed.z = a_SpeedZ; + WrapSpeed(); + + // Send the speed to the client so he actualy moves m_ClientHandle->SendEntityVelocity(*this); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 43f27e045..fb6bdc3ee 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -195,7 +195,11 @@ public: void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export virtual void SetSpeed(const Vector3d & a_Speed) override; - virtual void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override + virtual void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; + + virtual void SetSpeedX(double a_SpeedX) override; + virtual void SetSpeedY(double a_SpeedY) override; + virtual void SetSpeedZ(double a_SpeedZ) override; /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From 592a0b6147f359fd9d12a28c9c43c208d84b5b3f Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 22 May 2014 11:46:38 +0200 Subject: cEntity::SetSpeed(a_Vector3d) isn't virtualized anymore --- src/Entities/Entity.h | 2 +- src/Entities/Player.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index fc72462c3..ed67465a3 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -221,7 +221,7 @@ public: // tolua_begin virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); - virtual void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } + void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } virtual void SetSpeedX (double a_SpeedX); virtual void SetSpeedY (double a_SpeedY); virtual void SetSpeedZ (double a_SpeedZ); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index fb6bdc3ee..ee91beb4b 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -194,7 +194,7 @@ public: /** Forces the player to move in the given direction. DEPRECATED! Use SetSpeed instead */ void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export - virtual void SetSpeed(const Vector3d & a_Speed) override; + void SetSpeed(const Vector3d & a_Speed); virtual void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; virtual void SetSpeedX(double a_SpeedX) override; -- cgit v1.2.3 From 5e90976cd972e044248f71238d3e6b0672701870 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 22 May 2014 17:10:35 +0200 Subject: Added doxy-comments --- src/Entities/Player.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index ee91beb4b..0f4773893 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -194,12 +194,14 @@ public: /** Forces the player to move in the given direction. DEPRECATED! Use SetSpeed instead */ void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export - void SetSpeed(const Vector3d & a_Speed); - virtual void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; - - virtual void SetSpeedX(double a_SpeedX) override; - virtual void SetSpeedY(double a_SpeedY) override; - virtual void SetSpeedZ(double a_SpeedZ) override; + /** Sets the speed of the player and moves them in the given speed. */ + void SetSpeed (const Vector3d & a_Speed); + virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; + + /** Sets the speed for the X, Y or Z axis */ + virtual void SetSpeedX (double a_SpeedX) override; + virtual void SetSpeedY (double a_SpeedY) override; + virtual void SetSpeedZ (double a_SpeedZ) override; /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From 6991c2dd84060f8e7375966d4e488a359b42d43a Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 23 May 2014 15:48:09 +0100 Subject: Use placement new to initalise objects --- src/AllocationPool.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index f1e324953..d14d56f7a 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -36,12 +36,15 @@ class AllocationPool { } } } - T* ret = m_FreeList.front(); + // placement new, used to initalize the object + T* ret = new (m_FreeList.front()) T; m_FreeList.pop_front(); return ret; } void Free(T* ptr) { + // placement destruct. + ptr->~T(); m_FreeList.push_front(ptr); if (m_FreeList.size() == BufferSize) { @@ -50,5 +53,5 @@ class AllocationPool { } private: - std::list m_FreeList; + std::list m_FreeList; } -- cgit v1.2.3 From 8be3a8f7dc10dbc49dfcdeca572677ef1e00f714 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 23 May 2014 17:18:11 +0100 Subject: Implemented Allocation Pool use by cChunkData --- src/AllocationPool.h | 39 ++++++++++++++++++++++++++++----------- src/Chunk.cpp | 4 +++- src/Chunk.h | 3 ++- src/ChunkData.cpp | 6 +++--- src/ChunkData.h | 33 ++++++++++++++++++++++----------- src/ChunkMap.cpp | 11 +++++++---- src/ChunkMap.h | 15 ++++++++++++++- tests/ChunkData/ArraytoCoord.cpp | 15 ++++++++++++--- tests/ChunkData/Coordinates.cpp | 16 ++++++++++++---- tests/ChunkData/Copies.cpp | 18 +++++++++++++----- tests/ChunkData/creatable.cpp | 10 +++++++++- 11 files changed, 125 insertions(+), 45 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index d14d56f7a..b3818e8b1 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -1,36 +1,52 @@ #pragma once -template -class AllocationPool { +#include + +template +class cAllocationPool { public: + + class cStarvationCallbacks + { + public: + virtual ~cStarvationCallbacks() {} + virtual void OnStartingUsingBuffer() = 0; + virtual void OnStopUsingBuffer() = 0; + virtual void OnBufferEmpty() = 0; + }; + + cAllocationPool(std::auto_ptr a_Callbacks) : + m_Callbacks(a_Callbacks) + { + } - ~AllocationPool() + ~cAllocationPool() { while (!m_FreeList.empty()) { - delete m_FreeList.front(); + free (m_FreeList.front()); m_FreeList.pop_front(); } } T* Allocate() { - if (m_FreeList.Size() <= BufferSize) + if (m_FreeList.size() <= BufferSize) { try { - return new T; + return new(malloc(sizeof(T))) T; } - catch (std::bad_alloc& ex) + catch (std::bad_alloc&) { if (m_FreeList.size() == BufferSize) { - StarvationCallbacks.OnStartingUsingBuffer(); + m_Callbacks->OnStartingUsingBuffer(); } else if (m_FreeList.empty()) { - StarvationCallbacks.OnBufferEmpty(); + m_Callbacks->OnBufferEmpty(); // Try again until the memory is avalable return Allocate(); } @@ -48,10 +64,11 @@ class AllocationPool { m_FreeList.push_front(ptr); if (m_FreeList.size() == BufferSize) { - StarvationCallbacks.OnStopUsingBuffer(); + m_Callbacks->OnStopUsingBuffer(); } } private: std::list m_FreeList; -} + std::auto_ptr m_Callbacks; +}; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index d85b44607..cdec0774f 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -64,7 +64,8 @@ sSetBlock::sSetBlock( int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_Bloc cChunk::cChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkMap * a_ChunkMap, cWorld * a_World, - cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP + cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, + cAllocationPool& a_Pool ) : m_IsValid(false), m_IsLightValid(false), @@ -77,6 +78,7 @@ cChunk::cChunk( m_PosZ(a_ChunkZ), m_World(a_World), m_ChunkMap(a_ChunkMap), + m_ChunkData(a_Pool), m_BlockTickX(0), m_BlockTickY(0), m_BlockTickZ(0), diff --git a/src/Chunk.h b/src/Chunk.h index 2de45919e..e5b55ed2a 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -65,7 +65,8 @@ public: cChunk( int a_ChunkX, int a_ChunkY, 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 + cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks + cAllocationPool& a_Pool ); cChunk(cChunk& other); ~cChunk(); diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 86b0c431c..31de364b9 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -4,7 +4,7 @@ cChunkData cChunkData::Copy() const { - cChunkData copy; + cChunkData copy(m_Pool); for (int i = 0; i < CHUNK_SECTION_NUM; i++) { if (m_Sections[i] != NULL) @@ -360,14 +360,14 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) cChunkData::sChunkSection * cChunkData::Allocate() const { // TODO: use a allocation pool - return new cChunkData::sChunkSection; + return m_Pool.Allocate(); } void cChunkData::Free(cChunkData::sChunkSection * ptr) const { - delete ptr; + m_Pool.Free(ptr); } diff --git a/src/ChunkData.h b/src/ChunkData.h index 9c852ee24..527c5b2ae 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -7,6 +7,8 @@ #include "ChunkDef.h" +#include "AllocationPool.h" + #define CHUNK_SECTION_HEIGHT 16 #define CHUNK_SECTION_NUM (256 / CHUNK_SECTION_HEIGHT) @@ -21,11 +23,14 @@ class cChunkData { public: - cChunkData() + struct sChunkSection; + + cChunkData(cAllocationPool& a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management - : IsOwner(true) + IsOwner(true), #endif + m_Pool(a_Pool) { memset(m_Sections, 0, sizeof(m_Sections)); } @@ -44,7 +49,8 @@ public: #if __cplusplus < 201103L // auto_ptr style interface for memory management cChunkData(const cChunkData& other) : - IsOwner(true) + IsOwner(true), + m_Pool(other.m_Pool) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { @@ -70,13 +76,15 @@ public: m_Sections[i] = other.m_Sections[i]; } other.IsOwner = false; + ASSERT(&m_Pool == &other.m_Pool); } return *this; } #else // unique_ptr style interface for memory management - cChunkData(cChunkData&& other) + cChunkData(cChunkData&& other) : + m_Pool(other.m_Pool) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { @@ -95,6 +103,7 @@ public: m_Sections[i] = other.m_Sections[i]; other.m_Sections[i] = 0; } + ASSERT(&m_Pool == &other.m_Pool); } return *this; } @@ -252,13 +261,6 @@ public: void SetLight (const NIBBLETYPE * a_src); void SetSkyLight (const NIBBLETYPE * a_src); -private: - - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - mutable bool IsOwner; - #endif - struct sChunkSection { BLOCKTYPE m_BlockTypes [CHUNK_SECTION_HEIGHT * 16 * 16] ; NIBBLETYPE m_BlockMeta [CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; @@ -266,12 +268,21 @@ private: NIBBLETYPE m_BlockSkyLight[CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; }; +private: + + #if __cplusplus < 201103L + // auto_ptr style interface for memory management + mutable bool IsOwner; + #endif + sChunkSection *m_Sections[CHUNK_SECTION_NUM]; sChunkSection * Allocate() const; void Free(sChunkSection * ptr) const; void ZeroSection(sChunkSection * ptr) const; + + cAllocationPool& m_Pool; }; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index d3f44bef8..bf2b09342 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -34,7 +34,8 @@ // cChunkMap: cChunkMap::cChunkMap(cWorld * a_World ) - : m_World( a_World ) + : m_World( a_World ), + m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) { } @@ -78,7 +79,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayer(int a_LayerX, int a_LayerZ) } // Not found, create new: - cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this); + cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this, m_Pool); if (Layer == NULL) { LOGERROR("cChunkMap: Cannot create new layer, server out of memory?"); @@ -2646,11 +2647,13 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) //////////////////////////////////////////////////////////////////////////////// // cChunkMap::cChunkLayer: -cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent) +cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, + cAllocationPool& a_Pool) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) , m_NumChunksLoaded( 0 ) + , m_Pool(a_Pool) { memset(m_Chunks, 0, sizeof(m_Chunks)); } @@ -2692,7 +2695,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_Chunks[Index] = new cChunk(a_ChunkX, 0, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool); } return m_Chunks[Index]; } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index c3deda088..1744c09d0 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -347,7 +347,8 @@ private: class cChunkLayer { public: - cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent); + cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, + cAllocationPool& a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ @@ -391,6 +392,16 @@ private: int m_LayerZ; cChunkMap * m_Parent; int m_NumChunksLoaded; + + cAllocationPool & m_Pool; + }; + + class cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks + { + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} }; typedef std::list cChunkLayerList; @@ -423,6 +434,8 @@ private: /** The cChunkStay descendants that are currently enabled in this chunkmap */ cChunkStays m_ChunkStays; + cAllocationPool 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 diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index fe82a3a7b..04e6fbc5a 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -6,9 +6,18 @@ int main(int argc, char** argv) { + class cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} + }; + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + { + // Test first segment - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); @@ -45,7 +54,7 @@ int main(int argc, char** argv) { // test following segment - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); @@ -82,7 +91,7 @@ int main(int argc, char** argv) { // test zeros - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index c0c46000e..0a7d5e3f1 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -6,8 +6,16 @@ int main(int argc, char** argv) { + class cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { - cChunkData buffer; + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} + }; + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + { + cChunkData buffer(Pool); // Empty chunks buffer.SetBlock(0,0,0, 0xAB); @@ -105,7 +113,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); // Zero's buffer.SetBlock(0,0,0, 0x0); @@ -122,9 +130,9 @@ int main(int argc, char** argv) { // Operator = - cChunkData buffer; + cChunkData buffer(Pool); buffer.SetBlock(0,0,0,0x42); - cChunkData copy; + cChunkData copy(Pool); #if __cplusplus < 201103L copy = buffer; #else diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index 145ffd8e0..1ccda9d9c 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -6,8 +6,16 @@ int main(int argc, char** argv) { + class cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { - cChunkData buffer; + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} + }; + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + { + cChunkData buffer(Pool); buffer.SetBlock(3,1,4,0xDE); buffer.SetMeta(3,1,4,0xA); @@ -47,7 +55,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) @@ -80,7 +88,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) @@ -114,7 +122,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) @@ -148,7 +156,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp index 74025cb14..78b1a82d1 100644 --- a/tests/ChunkData/creatable.cpp +++ b/tests/ChunkData/creatable.cpp @@ -4,6 +4,14 @@ int main(int argc, char** argv) { - cChunkData buffer; + class cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks + { + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} + }; + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + cChunkData buffer(Pool); return 0; } -- cgit v1.2.3 From 25910873852252fb388059e78d88a293ccd9d797 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 25 May 2014 17:48:40 +0100 Subject: Fixed bug in freeing NULL pointers --- src/AllocationPool.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index b3818e8b1..643b44a6d 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -34,22 +34,20 @@ class cAllocationPool { { if (m_FreeList.size() <= BufferSize) { - try + void * space = malloc(sizeof(T)); + if (space != NULL) { - return new(malloc(sizeof(T))) T; + return new(space) T; } - catch (std::bad_alloc&) + else if (m_FreeList.size() == BufferSize) { - if (m_FreeList.size() == BufferSize) - { - m_Callbacks->OnStartingUsingBuffer(); - } - else if (m_FreeList.empty()) - { - m_Callbacks->OnBufferEmpty(); - // Try again until the memory is avalable - return Allocate(); - } + m_Callbacks->OnStartingUsingBuffer(); + } + else if (m_FreeList.empty()) + { + m_Callbacks->OnBufferEmpty(); + // Try again until the memory is avalable + return Allocate(); } } // placement new, used to initalize the object @@ -59,6 +57,10 @@ class cAllocationPool { } void Free(T* ptr) { + if (ptr == NULL) + { + return; + } // placement destruct. ptr->~T(); m_FreeList.push_front(ptr); -- cgit v1.2.3 From 2a7d199df68d11f6fd1fa2b4186faa00d0e81676 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 25 May 2014 18:26:10 +0100 Subject: Fixed bad merge --- src/ChunkData.cpp | 10 +++++----- src/ChunkData.h | 9 +++++---- tests/ChunkData/Coordinates.cpp | 8 +++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 1bc3072c2..99421bc33 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -242,7 +242,7 @@ NIBBLETYPE cChunkData::GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const cChunkData cChunkData::Copy() const { cChunkData copy(m_Pool); - for (int i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { if (m_Sections[i] != NULL) { @@ -432,7 +432,7 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src) void cChunkData::SetMeta(const NIBBLETYPE * a_src) { - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] != NULL) @@ -484,10 +484,10 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src) -void cChunkData::SetLight(const NIBBLETYPE * a_src) +void cChunkData::SetBlockLight(const NIBBLETYPE * a_src) { if (!a_src) return; - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] != NULL) @@ -542,7 +542,7 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src) void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) { if (!a_src) return; - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] != NULL) diff --git a/src/ChunkData.h b/src/ChunkData.h index 08f1603bb..637771741 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -19,6 +19,11 @@ class cChunkData { +private: + + static const size_t CHUNK_SECTION_HEIGHT = 16; + static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT); + public: struct sChunkSection; @@ -65,10 +70,6 @@ public: }; private: - - static const size_t CHUNK_SECTION_HEIGHT = 16; - static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT); - #if __cplusplus < 201103L // auto_ptr style interface for memory management mutable bool IsOwner; diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index f94532183..3a4477fd6 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -8,8 +8,14 @@ int main(int argc, char** argv) { class cStarvationCallbacks : public cAllocationPool::cStarvationCallbacks + { + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} + }; + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); { - cChunkData buffer; + cChunkData buffer(Pool); // Empty chunks buffer.SetBlock(0, 0, 0, 0xAB); -- cgit v1.2.3 From aa7c82580f2493052d119b1f27d5255c1609aa19 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 10 Jun 2014 23:16:38 -0700 Subject: Player.h: Moved doxy-comments to Entity.h Moved doxy-comments to the defining function in Entity.h rather than the overloaded functions in Player.h Comment for each function (instead of assumed encapsulating comments) @deprecated tag for ForceSetSpeed() --- src/Entities/Entity.h | 7 +++++++ src/Entities/Player.h | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index ed67465a3..ecd26b194 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -220,11 +220,18 @@ public: Vector3d m_Speed; // tolua_begin + /** Sets the speed of the entity and moves them in the given speed. */ virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); + /** Sets the speed of the entity and moves them in the given speed. */ void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } + + /** Sets the speed for the X axis */ virtual void SetSpeedX (double a_SpeedX); + /** Sets the speed for the Y axis */ virtual void SetSpeedY (double a_SpeedY); + /** Sets the speed for the Z axis */ virtual void SetSpeedZ (double a_SpeedZ); + void SetWidth (double a_Width); void AddPosX (double a_AddPosX); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 0f4773893..0fcf767e9 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -191,14 +191,14 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /** Forces the player to move in the given direction. DEPRECATED! Use SetSpeed instead */ + /** Forces the player to move in the given direction. + * @deprecated Use SetSpeed instead. + */ void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export /** Sets the speed of the player and moves them in the given speed. */ void SetSpeed (const Vector3d & a_Speed); virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; - - /** Sets the speed for the X, Y or Z axis */ virtual void SetSpeedX (double a_SpeedX) override; virtual void SetSpeedY (double a_SpeedY) override; virtual void SetSpeedZ (double a_SpeedZ) override; -- cgit v1.2.3 From 3f009a7c9e35a08d5685cd4276e17fc8f3443f9e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 14 Jun 2014 17:10:53 +0200 Subject: Refactored speed-setting to use a common function for all cases. --- src/Entities/Entity.cpp | 27 +++++++++++++---------- src/Entities/Entity.h | 39 +++++++++++++++++++-------------- src/Entities/Player.cpp | 58 ++----------------------------------------------- src/Entities/Player.h | 13 ++++------- 4 files changed, 44 insertions(+), 93 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8f736a269..76bd11406 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1076,6 +1076,17 @@ void cEntity::SetSwimState(cChunk & a_Chunk) +void cEntity::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) +{ + m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ); + + WrapSpeed(); +} + + + + + void cEntity::HandleAir(void) { // Ref.: http://www.minecraftwiki.net/wiki/Chunk_format @@ -1428,9 +1439,7 @@ void cEntity::SetRoll(double a_Roll) void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) { - m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ); - - WrapSpeed(); + DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ); } @@ -1438,9 +1447,7 @@ void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) void cEntity::SetSpeedX(double a_SpeedX) { - m_Speed.x = a_SpeedX; - - WrapSpeed(); + SetSpeed(a_SpeedX, m_Speed.y, m_Speed.z); } @@ -1448,9 +1455,7 @@ void cEntity::SetSpeedX(double a_SpeedX) void cEntity::SetSpeedY(double a_SpeedY) { - m_Speed.y = a_SpeedY; - - WrapSpeed(); + SetSpeed(m_Speed.x, a_SpeedY, m_Speed.z); } @@ -1458,9 +1463,7 @@ void cEntity::SetSpeedY(double a_SpeedY) void cEntity::SetSpeedZ(double a_SpeedZ) { - m_Speed.z = a_SpeedZ; - - WrapSpeed(); + SetSpeed(m_Speed.x, m_Speed.y, a_SpeedZ); } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index fed856b30..cb35db43b 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -217,21 +217,21 @@ public: void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180) // tolua_end - /** Measured in meter/second (m/s) */ - Vector3d m_Speed; - // tolua_begin - /** Sets the speed of the entity and moves them in the given speed. */ - virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); - /** Sets the speed of the entity and moves them in the given speed. */ - void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } - - /** Sets the speed for the X axis */ - virtual void SetSpeedX (double a_SpeedX); - /** Sets the speed for the Y axis */ - virtual void SetSpeedY (double a_SpeedY); - /** Sets the speed for the Z axis */ - virtual void SetSpeedZ (double a_SpeedZ); + /** Sets the speed of the entity, measured in m / sec */ + void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); + + /** Sets the speed of the entity, measured in m / sec */ + void SetSpeed(const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } + + /** Sets the speed in the X axis, leaving the other speed components intact. Measured in m / sec. */ + void SetSpeedX(double a_SpeedX); + + /** Sets the speed in the Y axis, leaving the other speed components intact. Measured in m / sec. */ + void SetSpeedY(double a_SpeedY); + + /** Sets the speed in the Z axis, leaving the other speed components intact. Measured in m / sec. */ + void SetSpeedZ(double a_SpeedZ); void SetWidth (double a_Width); @@ -442,6 +442,9 @@ protected: static cCriticalSection m_CSCount; static int m_EntityCount; + /** Measured in meter/second (m/s) */ + Vector3d m_Speed; + int m_UniqueID; int m_Health; @@ -499,11 +502,15 @@ protected: /// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void. int m_TicksSinceLastVoidDamage; - + + /** Does the actual speed-setting. The default implementation just sets the member variable value; + overrides can provide further processing, such as forcing players to move at the given speed. */ + virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); + virtual void Destroyed(void) {} // Called after the entity has been destroyed /** Called in each tick to handle air-related processing i.e. drowning */ - virtual void HandleAir(); + virtual void HandleAir(void); /** Called once per tick to set IsSwimming and IsSubmerged */ virtual void SetSwimState(cChunk & a_Chunk); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 33b339f8e..f1e0aad7e 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1257,30 +1257,15 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const void cPlayer::ForceSetSpeed(const Vector3d & a_Speed) { SetSpeed(a_Speed); - m_ClientHandle->SendEntityVelocity(*this); -} - - - - - -void cPlayer::SetSpeed(const Vector3d & a_Speed) -{ - m_Speed.Set(a_Speed.x, a_Speed.y, a_Speed.z); - WrapSpeed(); - - // Send the speed to the client so he actualy moves - m_ClientHandle->SendEntityVelocity(*this); } -void cPlayer::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) +void cPlayer::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) { - m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ); - WrapSpeed(); + super::DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ); // Send the speed to the client so he actualy moves m_ClientHandle->SendEntityVelocity(*this); @@ -1290,45 +1275,6 @@ void cPlayer::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) -void cPlayer::SetSpeedX(double a_SpeedX) -{ - m_Speed.x = a_SpeedX; - WrapSpeed(); - - // Send the speed to the client so he actualy moves - m_ClientHandle->SendEntityVelocity(*this); -} - - - - - -void cPlayer::SetSpeedY(double a_SpeedY) -{ - m_Speed.y = a_SpeedY; - WrapSpeed(); - - // Send the speed to the client so he actualy moves - m_ClientHandle->SendEntityVelocity(*this); -} - - - - - -void cPlayer::SetSpeedZ(double a_SpeedZ) -{ - m_Speed.z = a_SpeedZ; - WrapSpeed(); - - // Send the speed to the client so he actualy moves - m_ClientHandle->SendEntityVelocity(*this); -} - - - - - void cPlayer::MoveTo( const Vector3d & a_NewPos ) { if ((a_NewPos.y < -990) && (GetPosY() > -100)) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 165963e6e..325ff9005 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -195,17 +195,9 @@ public: void LoginSetGameMode(eGameMode a_GameMode); /** Forces the player to move in the given direction. - * @deprecated Use SetSpeed instead. - */ + @deprecated Use SetSpeed instead. */ void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export - /** Sets the speed of the player and moves them in the given speed. */ - void SetSpeed (const Vector3d & a_Speed); - virtual void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; - virtual void SetSpeedX (double a_SpeedX) override; - virtual void SetSpeedY (double a_SpeedY) override; - virtual void SetSpeedZ (double a_SpeedZ) override; - /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export @@ -521,6 +513,9 @@ protected: + /** Sets the speed and sends it to the client, so that they are forced to move so. */ + virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; + void ResolvePermissions(void); void ResolveGroups(void); -- cgit v1.2.3 From a89422ea4c5859464a9d955675ca666b67453190 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 14 Jun 2014 18:16:10 +0200 Subject: Simplified speed clamping. --- src/Entities/Entity.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 76bd11406..ee7ce06ac 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -179,14 +179,9 @@ void cEntity::WrapRotation(void) void cEntity::WrapSpeed(void) { - // There shoudn't be a need for flipping the flag on because this function is called - // after any update, so the flag is already turned on - if (m_Speed.x > 78.0f) m_Speed.x = 78.0f; - else if (m_Speed.x < -78.0f) m_Speed.x = -78.0f; - if (m_Speed.y > 78.0f) m_Speed.y = 78.0f; - else if (m_Speed.y < -78.0f) m_Speed.y = -78.0f; - if (m_Speed.z > 78.0f) m_Speed.z = 78.0f; - else if (m_Speed.z < -78.0f) m_Speed.z = -78.0f; + m_Speed.x = Clamp(m_Speed.x, -78.0, 78.0); + m_Speed.y = Clamp(m_Speed.y, -78.0, 78.0); + m_Speed.z = Clamp(m_Speed.z, -78.0, 78.0); } -- cgit v1.2.3 From 493d36433108735553ec073ccfbb563a4468a3fd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 14 Jun 2014 18:23:27 +0200 Subject: Removed an unused tolua_end and tolua_begin pair. --- src/Entities/Entity.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index cb35db43b..2df66e353 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -215,9 +215,7 @@ public: void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180) void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180) void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180) - // tolua_end - // tolua_begin /** Sets the speed of the entity, measured in m / sec */ void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); -- cgit v1.2.3 From 061102c77860e7a31b7504ca52bb99e419393fb2 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 17:23:57 +0100 Subject: Added logging --- src/ChunkMap.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 1a3258f15..efe489854 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -403,9 +403,18 @@ private: class cStarvationCallbacks : public cAllocationPool::cStarvationCallbacks { - virtual void OnStartingUsingBuffer() {} - virtual void OnStopUsingBuffer() {} - virtual void OnBufferEmpty() {} + virtual void OnStartingUsingBuffer() + { + LOG("Using backup memory buffer"); + } + virtual void OnStopUsingBuffer() + { + LOG("Stoped using backup memory buffer"); + } + virtual void OnBufferEmpty() + { + LOG("Out of Memory"); + } }; typedef std::list cChunkLayerList; -- cgit v1.2.3 From 8bf37f3dd7ff017eedaac427b9291a9335d61efc Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 17:57:21 +0100 Subject: Fixed comments --- src/AllocationPool.h | 8 ++++---- src/ChunkData.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 643b44a6d..b8862e7df 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -3,7 +3,7 @@ #include -template +template class cAllocationPool { public: @@ -32,14 +32,14 @@ class cAllocationPool { T* Allocate() { - if (m_FreeList.size() <= BufferSize) + if (m_FreeList.size() <= NumElementsInReserve) { void * space = malloc(sizeof(T)); if (space != NULL) { return new(space) T; } - else if (m_FreeList.size() == BufferSize) + else if (m_FreeList.size() == NumElementsInReserve) { m_Callbacks->OnStartingUsingBuffer(); } @@ -64,7 +64,7 @@ class cAllocationPool { // placement destruct. ptr->~T(); m_FreeList.push_front(ptr); - if (m_FreeList.size() == BufferSize) + if (m_FreeList.size() == NumElementsInReserve) { m_Callbacks->OnStopUsingBuffer(); } diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 24a2c3e14..a80b1de0f 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -30,9 +30,9 @@ template inline bool IsAllValue(const T * a_Array, size_t a_NumElem cChunkData::cChunkData(cAllocationPool& a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management - m_IsOwner(true) + m_IsOwner(true), #endif -m_Pool(a_Pool) + m_Pool(a_Pool) { for (size_t i = 0; i < NumSections; i++) { -- cgit v1.2.3 From bff76f201ffec0cc4c4df2be6ac125efa985dce7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 17:59:47 +0100 Subject: Fill with buffer on startup --- src/AllocationPool.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index b8862e7df..e4f1427f6 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,6 +19,16 @@ class cAllocationPool { cAllocationPool(std::auto_ptr a_Callbacks) : m_Callbacks(a_Callbacks) { + for(int i = 0; i < NumElementsInReserve; i++) + { + void * space = malloc(sizeof(T)); + if (space == NULL) + { + m_Callbacks->OnStartingUsingBuffer(); + break; + } + m_FreeList.push_front(space); + } } ~cAllocationPool() -- cgit v1.2.3 From f6af584efa60d23c06abdc86dbfdfc85da23a3dc Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 18:11:43 +0100 Subject: fixed const issue --- src/ChunkData.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index a80b1de0f..d2903cff1 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -68,7 +68,7 @@ cChunkData::~cChunkData() // auto_ptr style interface for memory management cChunkData::cChunkData(const cChunkData & a_Other) : m_IsOwner(true), - m_Pool(other.m_Pool) + m_Pool(a_Other.m_Pool) { // Move contents and ownership from a_Other to this, pointer-wise: for (size_t i = 0; i < NumSections; i++) @@ -107,7 +107,7 @@ cChunkData::~cChunkData() m_Sections[i] = a_Other.m_Sections[i]; } a_Other.m_IsOwner = false; - ASSERT(&m_Pool == &other.m_Pool); + ASSERT(&m_Pool == &a_Other.m_Pool); return *this; } @@ -327,7 +327,7 @@ cChunkData cChunkData::Copy(void) const { if (m_Sections[i] != NULL) { - copy.m_Sections[i] = Allocate(); + copy.m_Sections[i] = copy.Allocate(); *copy.m_Sections[i] = *m_Sections[i]; } } -- cgit v1.2.3 From a2df68b80b3ccb4395922c4351d4bd2f366003db Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 18:19:34 +0100 Subject: fixed compile --- src/AllocationPool.h | 2 +- tests/ChunkData/CopyBlocks.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index e4f1427f6..f73b32601 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,7 +19,7 @@ class cAllocationPool { cAllocationPool(std::auto_ptr a_Callbacks) : m_Callbacks(a_Callbacks) { - for(int i = 0; i < NumElementsInReserve; i++) + for(size_t i = 0; i < NumElementsInReserve; i++) { void * space = malloc(sizeof(T)); if (space == NULL) diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index be8cab234..7f8f66c4d 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -17,7 +17,15 @@ int main(int argc, char ** argv) { // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02: - cChunkData Data; + class cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks + { + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} + }; + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + cChunkData Data(Pool); cChunkDef::BlockTypes BlockTypes; cChunkDef::BlockNibbles BlockMetas; memset(BlockTypes, 0x01, sizeof(BlockTypes)); -- cgit v1.2.3 From 0310a50192fcbd4a9e5ec03c98a0d7f33457df54 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 18:43:36 +0100 Subject: fixed spaces --- src/AllocationPool.h | 2 +- src/ChunkMap.cpp | 2 +- src/ChunkMap.h | 8 ++++---- tests/ChunkData/ArraytoCoord.cpp | 4 ++-- tests/ChunkData/Coordinates.cpp | 4 ++-- tests/ChunkData/Copies.cpp | 4 ++-- tests/ChunkData/CopyBlocks.cpp | 4 ++-- tests/ChunkData/creatable.cpp | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index f73b32601..9144c2eac 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,7 +19,7 @@ class cAllocationPool { cAllocationPool(std::auto_ptr a_Callbacks) : m_Callbacks(a_Callbacks) { - for(size_t i = 0; i < NumElementsInReserve; i++) + for (size_t i = 0; i < NumElementsInReserve; i++) { void * space = malloc(sizeof(T)); if (space == NULL) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 586d7a65e..862d0b7ec 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -35,7 +35,7 @@ cChunkMap::cChunkMap(cWorld * a_World ) : m_World( a_World ), - m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) + m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) { } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index efe489854..071921f92 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -352,7 +352,7 @@ private: { public: cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool& a_Pool); + cAllocationPool& a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ @@ -397,11 +397,11 @@ private: cChunkMap * m_Parent; int m_NumChunksLoaded; - cAllocationPool & m_Pool; + cAllocationPool & m_Pool; }; class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() { @@ -447,7 +447,7 @@ private: /** The cChunkStay descendants that are currently enabled in this chunkmap */ cChunkStays m_ChunkStays; - cAllocationPool m_Pool; + cAllocationPool 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 diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index 80bcc5283..3f22d239a 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -7,13 +7,13 @@ int main(int argc, char** argv) { class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() {} virtual void OnStopUsingBuffer() {} virtual void OnBufferEmpty() {} }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); { // Test first segment diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index d5abbb143..66fab46ab 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -7,13 +7,13 @@ int main(int argc, char** argv) { class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() {} virtual void OnStopUsingBuffer() {} virtual void OnBufferEmpty() {} }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); { cChunkData buffer(Pool); diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index 6f5d40792..4a672380f 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -7,13 +7,13 @@ int main(int argc, char** argv) { class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() {} virtual void OnStopUsingBuffer() {} virtual void OnBufferEmpty() {} }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); { cChunkData buffer(Pool); diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index 7f8f66c4d..db3d391c3 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -18,13 +18,13 @@ int main(int argc, char ** argv) { // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02: class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() {} virtual void OnStopUsingBuffer() {} virtual void OnBufferEmpty() {} }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); cChunkData Data(Pool); cChunkDef::BlockTypes BlockTypes; cChunkDef::BlockNibbles BlockMetas; diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp index 0dde8cf3b..2bb61b7ce 100644 --- a/tests/ChunkData/creatable.cpp +++ b/tests/ChunkData/creatable.cpp @@ -5,13 +5,13 @@ int main(int argc, char** argv) { class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() {} virtual void OnStopUsingBuffer() {} virtual void OnBufferEmpty() {} }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); cChunkData buffer(Pool); return 0; } -- cgit v1.2.3 From 6b99e556462fdbdf6a265c014fb03f070b0f1b25 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:05:02 +0100 Subject: fixed spaces --- src/AllocationPool.h | 11 ++++++----- src/Chunk.cpp | 2 +- src/Chunk.h | 2 +- src/ChunkData.cpp | 2 +- src/ChunkData.h | 7 ++++--- src/ChunkMap.cpp | 2 +- src/ChunkMap.h | 2 +- tests/ChunkData/Coordinates.cpp | 2 +- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 9144c2eac..9bb44ff1f 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -4,7 +4,8 @@ #include template -class cAllocationPool { +class cAllocationPool +{ public: class cStarvationCallbacks @@ -17,7 +18,7 @@ class cAllocationPool { }; cAllocationPool(std::auto_ptr a_Callbacks) : - m_Callbacks(a_Callbacks) + m_Callbacks(a_Callbacks) { for (size_t i = 0; i < NumElementsInReserve; i++) { @@ -40,7 +41,7 @@ class cAllocationPool { } } - T* Allocate() + T * Allocate() { if (m_FreeList.size() <= NumElementsInReserve) { @@ -61,11 +62,11 @@ class cAllocationPool { } } // placement new, used to initalize the object - T* ret = new (m_FreeList.front()) T; + T * ret = new (m_FreeList.front()) T; m_FreeList.pop_front(); return ret; } - void Free(T* ptr) + void Free(T * ptr) { if (ptr == NULL) { diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 64a5660d8..a0a397a08 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -65,7 +65,7 @@ cChunk::cChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkMap * a_ChunkMap, cWorld * a_World, cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, - cAllocationPool& a_Pool + cAllocationPool & a_Pool ) : m_IsValid(false), m_IsLightValid(false), diff --git a/src/Chunk.h b/src/Chunk.h index 7309fd022..07f597d59 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -66,7 +66,7 @@ public: int a_ChunkX, int a_ChunkY, 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 + cAllocationPool & a_Pool ); cChunk(cChunk & other); ~cChunk(); diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index d2903cff1..f9c263d88 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -27,7 +27,7 @@ template inline bool IsAllValue(const T * a_Array, size_t a_NumElem -cChunkData::cChunkData(cAllocationPool& a_Pool) : +cChunkData::cChunkData(cAllocationPool & a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management m_IsOwner(true), diff --git a/src/ChunkData.h b/src/ChunkData.h index aaefc4575..9dee78ad0 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -37,7 +37,7 @@ public: struct sChunkSection; - cChunkData(cAllocationPool& a_Pool); + cChunkData(cAllocationPool & a_Pool); ~cChunkData(); #if __cplusplus < 201103L @@ -96,7 +96,8 @@ public: Allows a_Src to be NULL, in which case it doesn't do anything. */ void SetSkyLight(const NIBBLETYPE * a_Src); - struct sChunkSection { + struct sChunkSection + { BLOCKTYPE m_BlockTypes [SectionHeight * 16 * 16] ; NIBBLETYPE m_BlockMetas [SectionHeight * 16 * 16 / 2]; NIBBLETYPE m_BlockLight [SectionHeight * 16 * 16 / 2]; @@ -121,7 +122,7 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool& m_Pool; + cAllocationPool & m_Pool; }; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 862d0b7ec..704c4f823 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2672,7 +2672,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) // cChunkMap::cChunkLayer: cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool& a_Pool) + cAllocationPool & a_Pool) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 071921f92..08156e7e6 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -352,7 +352,7 @@ private: { public: cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool& a_Pool); + cAllocationPool & a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index 66fab46ab..1ac600f82 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -144,7 +144,7 @@ int main(int argc, char** argv) #else copy = std::move(copy); #endif - testassert(copy.GetBlock(0,0,0) == 0x42); + testassert(copy.GetBlock(0, 0, 0) == 0x42); } return 0; -- cgit v1.2.3 From a1520c7a406b74d20da674426444d538fff56fac Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:06:54 +0100 Subject: reverted accedental android changes --- Android/.classpath | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Android/.classpath b/Android/.classpath index 7bc01d9a9..a4763d1ee 100644 --- a/Android/.classpath +++ b/Android/.classpath @@ -3,7 +3,6 @@ - - + -- cgit v1.2.3 From 94c48febd2f596648fc2616a8a577316a219b581 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:46:34 +0100 Subject: Added generic Allocation Pool Interface --- src/AllocationPool.h | 46 ++++++++++++++++++++++++---------------- src/Chunk.cpp | 2 +- src/Chunk.h | 2 +- src/ChunkData.cpp | 2 +- src/ChunkData.h | 4 ++-- src/ChunkMap.cpp | 12 ++++++++--- src/ChunkMap.h | 8 +++---- tests/ChunkData/ArraytoCoord.cpp | 21 +++++++++++------- tests/ChunkData/Coordinates.cpp | 19 +++++++++++------ tests/ChunkData/Copies.cpp | 21 +++++++++++------- tests/ChunkData/CopyBlocks.cpp | 21 +++++++++++------- tests/ChunkData/creatable.cpp | 21 +++++++++++------- 12 files changed, 110 insertions(+), 69 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 9bb44ff1f..88bc132e9 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -3,21 +3,31 @@ #include +template +class cAllocationPool +{ +public: + class cStarvationCallbacks + { + public: + virtual ~cStarvationCallbacks() {} + virtual void OnStartingUsingBuffer() = 0; + virtual void OnStopUsingBuffer() = 0; + virtual void OnBufferEmpty() = 0; + }; + + virtual ~cAllocationPool() {} + + virtual T * Allocate() = 0; + virtual void Free(T * a_ptr) = 0; +}; + template -class cAllocationPool +class cListAllocationPool : public cAllocationPool { public: - - class cStarvationCallbacks - { - public: - virtual ~cStarvationCallbacks() {} - virtual void OnStartingUsingBuffer() = 0; - virtual void OnStopUsingBuffer() = 0; - virtual void OnBufferEmpty() = 0; - }; - cAllocationPool(std::auto_ptr a_Callbacks) : + cListAllocationPool(std::auto_ptr::cStarvationCallbacks> a_Callbacks) : m_Callbacks(a_Callbacks) { for (size_t i = 0; i < NumElementsInReserve; i++) @@ -32,7 +42,7 @@ class cAllocationPool } } - ~cAllocationPool() + virtual ~cListAllocationPool() { while (!m_FreeList.empty()) { @@ -41,7 +51,7 @@ class cAllocationPool } } - T * Allocate() + virtual T * Allocate() override { if (m_FreeList.size() <= NumElementsInReserve) { @@ -66,15 +76,15 @@ class cAllocationPool m_FreeList.pop_front(); return ret; } - void Free(T * ptr) + virtual void Free(T * a_ptr) override { - if (ptr == NULL) + if (a_ptr == NULL) { return; } // placement destruct. - ptr->~T(); - m_FreeList.push_front(ptr); + a_ptr->~T(); + m_FreeList.push_front(a_ptr); if (m_FreeList.size() == NumElementsInReserve) { m_Callbacks->OnStopUsingBuffer(); @@ -83,5 +93,5 @@ class cAllocationPool private: std::list m_FreeList; - std::auto_ptr m_Callbacks; + std::auto_ptr::cStarvationCallbacks> m_Callbacks; }; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a0a397a08..4703e4536 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -65,7 +65,7 @@ cChunk::cChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkMap * a_ChunkMap, cWorld * a_World, cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, - cAllocationPool & a_Pool + cAllocationPool & a_Pool ) : m_IsValid(false), m_IsLightValid(false), diff --git a/src/Chunk.h b/src/Chunk.h index 07f597d59..7664a7afd 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -66,7 +66,7 @@ public: int a_ChunkX, int a_ChunkY, 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 + cAllocationPool & a_Pool ); cChunk(cChunk & other); ~cChunk(); diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index f9c263d88..03b0224a6 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -27,7 +27,7 @@ template inline bool IsAllValue(const T * a_Array, size_t a_NumElem -cChunkData::cChunkData(cAllocationPool & a_Pool) : +cChunkData::cChunkData(cAllocationPool & a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management m_IsOwner(true), diff --git a/src/ChunkData.h b/src/ChunkData.h index 9dee78ad0..e3b36c581 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -37,7 +37,7 @@ public: struct sChunkSection; - cChunkData(cAllocationPool & a_Pool); + cChunkData(cAllocationPool & a_Pool); ~cChunkData(); #if __cplusplus < 201103L @@ -122,7 +122,7 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool & m_Pool; + cAllocationPool & m_Pool; }; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 704c4f823..3b946f9ec 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -35,8 +35,14 @@ cChunkMap::cChunkMap(cWorld * a_World ) : m_World( a_World ), - m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) + m_Pool( + new cListAllocationPool( + std::auto_ptr::cStarvationCallbacks>( + new cStarvationCallbacks()) + ) + ) { + } @@ -79,7 +85,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayer(int a_LayerX, int a_LayerZ) } // Not found, create new: - cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this, m_Pool); + cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this, *m_Pool); if (Layer == NULL) { LOGERROR("cChunkMap: Cannot create new layer, server out of memory?"); @@ -2672,7 +2678,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) // cChunkMap::cChunkLayer: cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool) + cAllocationPool & a_Pool) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 08156e7e6..c1dc743e5 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -352,7 +352,7 @@ private: { public: cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool); + cAllocationPool & a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ @@ -397,11 +397,11 @@ private: cChunkMap * m_Parent; int m_NumChunksLoaded; - cAllocationPool & m_Pool; + cAllocationPool & m_Pool; }; class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() { @@ -447,7 +447,7 @@ private: /** The cChunkStay descendants that are currently enabled in this chunkmap */ cChunkStays m_ChunkStays; - cAllocationPool m_Pool; + 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 diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index 3f22d239a..9d0ca6c8c 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -6,14 +6,19 @@ int main(int argc, char** argv) { - class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks - { - virtual void OnStartingUsingBuffer() {} - virtual void OnStopUsingBuffer() {} - virtual void OnBufferEmpty() {} - }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; { // Test first segment diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index 1ac600f82..b3c66dde5 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -6,14 +6,19 @@ int main(int argc, char** argv) { - class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + class cMockAllocationPool + : public cAllocationPool { - virtual void OnStartingUsingBuffer() {} - virtual void OnStopUsingBuffer() {} - virtual void OnBufferEmpty() {} - }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; { cChunkData buffer(Pool); diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index 4a672380f..440819e91 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -6,14 +6,19 @@ int main(int argc, char** argv) { - class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks - { - virtual void OnStartingUsingBuffer() {} - virtual void OnStopUsingBuffer() {} - virtual void OnBufferEmpty() {} - }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; { cChunkData buffer(Pool); diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index db3d391c3..ec9451099 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -17,14 +17,19 @@ int main(int argc, char ** argv) { // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02: - class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks - { - virtual void OnStartingUsingBuffer() {} - virtual void OnStopUsingBuffer() {} - virtual void OnBufferEmpty() {} - }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; cChunkData Data(Pool); cChunkDef::BlockTypes BlockTypes; cChunkDef::BlockNibbles BlockMetas; diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp index 2bb61b7ce..fc786f688 100644 --- a/tests/ChunkData/creatable.cpp +++ b/tests/ChunkData/creatable.cpp @@ -4,14 +4,19 @@ int main(int argc, char** argv) { - class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks - { - virtual void OnStartingUsingBuffer() {} - virtual void OnStopUsingBuffer() {} - virtual void OnBufferEmpty() {} - }; - cAllocationPool Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())); + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; cChunkData buffer(Pool); return 0; } -- cgit v1.2.3 From 3efbdb1c9b8f83ecb28992282c08aa065e21e1f8 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:54:09 +0100 Subject: Moved m_Sections --- src/ChunkData.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ChunkData.h b/src/ChunkData.h index e3b36c581..fe8b068a2 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -111,6 +111,8 @@ private: #endif sChunkSection * m_Sections[NumSections]; + + cAllocationPool & m_Pool; /** Allocates a new section. Entry-point to custom allocators. */ sChunkSection * Allocate(void); @@ -122,7 +124,6 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool & m_Pool; }; -- cgit v1.2.3 From f97116141f464d4e27515197eec7d42f9d2ba772 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:56:01 +0100 Subject: Reformated ChunkMap.h --- src/ChunkMap.cpp | 7 +++++-- src/ChunkMap.h | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 3b946f9ec..d2ccca94e 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2677,8 +2677,11 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) //////////////////////////////////////////////////////////////////////////////// // cChunkMap::cChunkLayer: -cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool) +cChunkMap::cChunkLayer::cChunkLayer( + int a_LayerX, int a_LayerZ, + cChunkMap * a_Parent, + cAllocationPool & a_Pool +) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index c1dc743e5..0d6f1f80a 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -351,8 +351,11 @@ private: class cChunkLayer { public: - cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool); + cChunkLayer( + int a_LayerX, int a_LayerZ, + cChunkMap * a_Parent, + cAllocationPool & a_Pool + ); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ -- cgit v1.2.3 From 2643a46c69d7d1354ec324a274dba4ccca315f3c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:04:35 +0100 Subject: Documented cAllocationPool --- src/AllocationPool.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 88bc132e9..cac5689b9 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -18,10 +18,15 @@ public: virtual ~cAllocationPool() {} + /** Allocates a pointer to T **/ virtual T * Allocate() = 0; + + /** Frees the pointer passed in a_ptr, invalidating it **/ virtual void Free(T * a_ptr) = 0; }; +/** Allocates memory storing unused elements in a linked list. Keeps at least NumElementsInReserve + elements in the list unless malloc fails so that the program has a reserve to handle OOM.**/ template class cListAllocationPool : public cAllocationPool { -- cgit v1.2.3 From 41e5a64ff8f268f2cb0278e691f300e3a1790388 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:07:17 +0100 Subject: Documented starvation callbacks --- src/AllocationPool.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index cac5689b9..b7d0bb506 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -11,8 +11,15 @@ public: { public: virtual ~cStarvationCallbacks() {} + + /** Is called when the reserve buffer starts to be used **/ virtual void OnStartingUsingBuffer() = 0; + + /** Is called once the reserve buffer has returned to normal size **/ virtual void OnStopUsingBuffer() = 0; + + /** Is called when the allocation pool is unable to allocate memory. Will be repeatedly + called if it does not free sufficient memory **/ virtual void OnBufferEmpty() = 0; }; -- cgit v1.2.3 From 6ddcf42409b0460091abf0bb94b01043dd1b112b Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:10:49 +0100 Subject: Removed spaces --- src/AllocationPool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index b7d0bb506..9c833302f 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,7 +19,7 @@ public: virtual void OnStopUsingBuffer() = 0; /** Is called when the allocation pool is unable to allocate memory. Will be repeatedly - called if it does not free sufficient memory **/ + called if it does not free sufficient memory **/ virtual void OnBufferEmpty() = 0; }; @@ -33,7 +33,7 @@ public: }; /** Allocates memory storing unused elements in a linked list. Keeps at least NumElementsInReserve - elements in the list unless malloc fails so that the program has a reserve to handle OOM.**/ +elements in the list unless malloc fails so that the program has a reserve to handle OOM.**/ template class cListAllocationPool : public cAllocationPool { -- cgit v1.2.3 From 8a2aa6cb169563c7df752821e032b1cab1bac5d1 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:24:52 +0100 Subject: Changed names of callbacks --- src/AllocationPool.h | 14 +++++++------- src/ChunkMap.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 9c833302f..5d749a79e 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -13,14 +13,14 @@ public: virtual ~cStarvationCallbacks() {} /** Is called when the reserve buffer starts to be used **/ - virtual void OnStartingUsingBuffer() = 0; + virtual void OnStartUsingReserve() = 0; /** Is called once the reserve buffer has returned to normal size **/ - virtual void OnStopUsingBuffer() = 0; + virtual void OnEndUsingReserve() = 0; /** Is called when the allocation pool is unable to allocate memory. Will be repeatedly called if it does not free sufficient memory **/ - virtual void OnBufferEmpty() = 0; + virtual void OnOutOfReserve() = 0; }; virtual ~cAllocationPool() {} @@ -47,7 +47,7 @@ class cListAllocationPool : public cAllocationPool void * space = malloc(sizeof(T)); if (space == NULL) { - m_Callbacks->OnStartingUsingBuffer(); + m_Callbacks->OnStartUsingReserve(); break; } m_FreeList.push_front(space); @@ -74,11 +74,11 @@ class cListAllocationPool : public cAllocationPool } else if (m_FreeList.size() == NumElementsInReserve) { - m_Callbacks->OnStartingUsingBuffer(); + m_Callbacks->OnStartUsingReserve(); } else if (m_FreeList.empty()) { - m_Callbacks->OnBufferEmpty(); + m_Callbacks->OnOutOfReserve(); // Try again until the memory is avalable return Allocate(); } @@ -99,7 +99,7 @@ class cListAllocationPool : public cAllocationPool m_FreeList.push_front(a_ptr); if (m_FreeList.size() == NumElementsInReserve) { - m_Callbacks->OnStopUsingBuffer(); + m_Callbacks->OnEndUsingReserve(); } } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 0d6f1f80a..fd319fbc9 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -406,15 +406,15 @@ private: class cStarvationCallbacks : public cAllocationPool::cStarvationCallbacks { - virtual void OnStartingUsingBuffer() + virtual void OnStartUsingReserve() { LOG("Using backup memory buffer"); } - virtual void OnStopUsingBuffer() + virtual void OnEndUsingReserve() { LOG("Stoped using backup memory buffer"); } - virtual void OnBufferEmpty() + virtual void OnOutOfReserve() { LOG("Out of Memory"); } -- cgit v1.2.3 From 2a6ca71a0b8839a299335f5f02872128db325b59 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 15 Jun 2014 16:27:20 +0100 Subject: Fixed daylight sensor unpowering * Fixes #1094 --- src/Simulator/IncrementalRedstoneSimulator.cpp | 34 +++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index f20f396f2..3d8229e16 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -59,19 +59,21 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, int RelZ = 0; BLOCKTYPE Block; NIBBLETYPE Meta; + cChunk * Chunk; if (a_OtherChunk != NULL) { RelX = a_BlockX - a_OtherChunk->GetPosX() * cChunkDef::Width; RelZ = a_BlockZ - a_OtherChunk->GetPosZ() * cChunkDef::Width; a_OtherChunk->GetBlockTypeMeta(RelX, a_BlockY, RelZ, Block, Meta); - a_OtherChunk->SetIsRedstoneDirty(true); + Chunk = a_OtherChunk; } else { RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width; RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width; a_Chunk->GetBlockTypeMeta(RelX, a_BlockY, RelZ, Block, Meta); + Chunk = a_Chunk; } // Every time a block is changed (AddBlock called), we want to go through all lists and check to see if the coordiantes stored within are still valid @@ -90,7 +92,7 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list as it no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); itr = PoweredBlocks->erase(itr); - a_Chunk->SetIsRedstoneDirty(true); + Chunk->SetIsRedstoneDirty(true); continue; } else if ( @@ -105,9 +107,25 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); itr = PoweredBlocks->erase(itr); - a_Chunk->SetIsRedstoneDirty(true); + Chunk->SetIsRedstoneDirty(true); continue; } + else if (Block == E_BLOCK_DAYLIGHT_SENSOR) + { + if (!m_World.IsChunkLighted(Chunk->GetPosX(), Chunk->GetPosZ())) + { + m_World.QueueLightChunk(Chunk->GetPosX(), Chunk->GetPosZ()); + } + else + { + if (Chunk->GetTimeAlteredLight(Chunk->GetSkyLight(RelX, a_BlockY + 1, RelZ)) <= 7) + { + itr = PoweredBlocks->erase(itr); + Chunk->SetIsRedstoneDirty(true); + continue; + } + } + } ++itr; } @@ -121,7 +139,7 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); itr = LinkedPoweredBlocks->erase(itr); - a_Chunk->SetIsRedstoneDirty(true); + Chunk->SetIsRedstoneDirty(true); continue; } else if ( @@ -135,7 +153,7 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); itr = LinkedPoweredBlocks->erase(itr); - a_Chunk->SetIsRedstoneDirty(true); + Chunk->SetIsRedstoneDirty(true); continue; } } @@ -145,7 +163,7 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list as it is no longer powered through a valid middle block", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); itr = LinkedPoweredBlocks->erase(itr); - a_Chunk->SetIsRedstoneDirty(true); + Chunk->SetIsRedstoneDirty(true); continue; } } @@ -1145,6 +1163,10 @@ void cIncrementalRedstoneSimulator::HandleDaylightSensor(int a_RelBlockX, int a_ { SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); } + else + { + WakeUp(BlockX, a_RelBlockY, BlockZ, m_Chunk); + } } } -- cgit v1.2.3 From f822a46bdb24a9c693e897d3619ece15a1cc1a5a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 15 Jun 2014 19:42:14 +0100 Subject: Fixed bad comparison crash * Fixes #1095 --- src/Simulator/IncrementalRedstoneSimulator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 3d8229e16..69c8b9f56 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -806,12 +806,12 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_RelBlockX, int { WereItrsChanged = QueueRepeaterPowerChange(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_Meta, false); } - else if (a_Itr != m_RepeatersDelayList->end()) + else if (a_Itr == m_RepeatersDelayList->end()) { return; } } - else if (a_Itr != m_RepeatersDelayList->end()) + else if (a_Itr == m_RepeatersDelayList->end()) { return; } -- cgit v1.2.3 From abbd11be6da261293f2086135e05e9a0659220f2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 15 Jun 2014 20:28:08 +0100 Subject: Players are saved regularly * Fixes #1076 --- src/Entities/Player.cpp | 19 ++++++++++++++++++- src/Entities/Player.h | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index feb09b5d2..cffdd71b1 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -22,6 +22,12 @@ #include "inifile/iniFile.h" #include "json/json.h" +// 6000 ticks or 5 minutes +#define PLAYER_INVENTORY_SAVE_INTERVAL 6000 + +// 1000 = once per second +#define PLAYER_LIST_TIME_MS 1000 + @@ -64,6 +70,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_BowCharge(0) , m_FloaterID(-1) , m_Team(NULL) + , m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", a_PlayerName.c_str(), a_Client->GetIPString().c_str(), @@ -250,7 +257,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) // Send Player List (Once per m_LastPlayerListTime/1000 ms) cTimer t1; - if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime()) + if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime()) { m_World->SendPlayerList(this); m_LastPlayerListTime = t1.GetNowTime(); @@ -260,6 +267,16 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) { m_LastGroundHeight = (float)GetPosY(); } + + if (m_TicksUntilNextSave == 0) + { + SaveToDisk(); + m_TicksUntilNextSave = PLAYER_INVENTORY_SAVE_INTERVAL; + } + else + { + m_TicksUntilNextSave--; + } } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 83b9ad593..a9acf6efc 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -461,7 +461,6 @@ protected: cItem m_DraggingItem; long long m_LastPlayerListTime; - static const unsigned short PLAYER_LIST_TIME_MS = 1000; // 1000 = once per second cClientHandle * m_ClientHandle; @@ -539,6 +538,10 @@ protected: Set by a right click on unoccupied bed, unset by a time fast forward or teleport */ bool m_bIsInBed; + /** How long till the player's inventory will be saved + Default save interval is #defined in PLAYER_INVENTORY_SAVE_INTERVAL */ + unsigned int m_TicksUntilNextSave; + } ; // tolua_export -- cgit v1.2.3 From d9719e696ce11df0557acbbc56545cb0d0f95075 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 15 Jun 2014 23:30:43 +0200 Subject: Added random offsets to cGridStructGen. Fixes #740. --- src/Generating/Caves.cpp | 10 +++++----- src/Generating/Caves.h | 4 ++-- src/Generating/ComposableGenerator.cpp | 36 +++++++++++++++++++++------------- src/Generating/GridStructGen.cpp | 31 +++++++++++++++++------------ src/Generating/GridStructGen.h | 33 +++++++++++++++++++++++++------ src/Generating/MineShafts.cpp | 16 ++++++++------- src/Generating/MineShafts.h | 4 ++-- src/Generating/NetherFortGen.cpp | 15 ++++++++------ src/Generating/NetherFortGen.h | 4 ++-- src/Generating/RainbowRoadsGen.cpp | 11 ++++++----- src/Generating/RainbowRoadsGen.h | 4 ++-- src/Generating/Ravines.cpp | 12 ++++++------ src/Generating/Ravines.h | 2 +- src/Generating/UnderwaterBaseGen.cpp | 11 ++++++----- src/Generating/UnderwaterBaseGen.h | 4 ++-- src/Generating/VillageGen.cpp | 11 ++++++----- src/Generating/VillageGen.h | 4 ++-- 17 files changed, 127 insertions(+), 85 deletions(-) diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index 872e3341d..6aa7fd4cb 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -125,7 +125,7 @@ public: int m_BlockX; int m_BlockZ; - cCaveSystem(int a_OriginX, int a_OriginZ, int a_MaxOffset, int a_Size, cNoise & a_Noise); + cCaveSystem(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxOffset, int a_Size, cNoise & a_Noise); ~cCaveSystem(); protected: @@ -574,8 +574,8 @@ AString cCaveTunnel::ExportAsSVG(int a_Color, int a_OffsetX, int a_OffsetZ) cons /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenWormNestCaves::cCaveSystem: -cStructGenWormNestCaves::cCaveSystem::cCaveSystem(int a_OriginX, int a_OriginZ, int a_MaxOffset, int a_Size, cNoise & a_Noise) : - super(a_OriginX, a_OriginZ), +cStructGenWormNestCaves::cCaveSystem::cCaveSystem(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxOffset, int a_Size, cNoise & a_Noise) : + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Size(a_Size) { int Num = 1 + a_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) % 3; @@ -690,9 +690,9 @@ int cStructGenWormNestCaves::cCaveSystem::GetRadius(cNoise & a_Noise, int a_Orig /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenWormNestCaves: -cGridStructGen::cStructurePtr cStructGenWormNestCaves::CreateStructure(int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cStructGenWormNestCaves::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { - return cStructurePtr(new cCaveSystem(a_OriginX, a_OriginZ, m_MaxOffset, m_Size, m_Noise)); + return cStructurePtr(new cCaveSystem(a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxOffset, m_Size, m_Noise)); } diff --git a/src/Generating/Caves.h b/src/Generating/Caves.h index 254dcddbd..0e17acf9e 100644 --- a/src/Generating/Caves.h +++ b/src/Generating/Caves.h @@ -69,7 +69,7 @@ class cStructGenWormNestCaves : typedef cGridStructGen super; public: cStructGenWormNestCaves(int a_Seed, int a_Size = 64, int a_Grid = 96, int a_MaxOffset = 128) : - super(a_Seed, a_Grid, a_Grid, a_Size + a_MaxOffset, a_Size + a_MaxOffset, 100), + super(a_Seed, a_Grid, a_Grid, a_MaxOffset, a_MaxOffset, a_Size, a_Size, 100), m_Noise(a_Seed), m_Size(a_Size), m_MaxOffset(a_MaxOffset), @@ -86,7 +86,7 @@ protected: int m_Grid; // average spacing of the nests // cGridStructGen override: - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 1801b7375..f332b4d78 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -357,12 +357,13 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) else if (NoCaseCompare(*itr, "MineShafts") == 0) { int GridSize = a_IniFile.GetValueSetI("Generator", "MineShaftsGridSize", 512); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "MineShaftsMaxOffset", 256); int MaxSystemSize = a_IniFile.GetValueSetI("Generator", "MineShaftsMaxSystemSize", 160); int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600); int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200); m_FinishGens.push_back(new cStructGenMineShafts( - Seed, GridSize, MaxSystemSize, + Seed, GridSize, MaxOffset, MaxSystemSize, ChanceCorridor, ChanceCrossing, ChanceStaircase )); } @@ -376,9 +377,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "NetherForts") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "NetherFortsGridSize", 512); - int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 12); - m_FinishGens.push_back(new cNetherFortGen(Seed, GridSize, MaxDepth)); + int GridSize = a_IniFile.GetValueSetI("Generator", "NetherFortsGridSize", 512); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "NetherFortMaxOffset", 128); + int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 12); + m_FinishGens.push_back(new cNetherFortGen(Seed, GridSize, MaxOffset, MaxDepth)); } else if (NoCaseCompare(*itr, "OreNests") == 0) { @@ -394,10 +396,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "RainbowRoads") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsGridSize", 512); - int MaxDepth = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxDepth", 30); - int MaxSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxSize", 260); - m_FinishGens.push_back(new cRainbowRoadsGen(Seed, GridSize, MaxDepth, MaxSize)); + int GridSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsGridSize", 512); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxOffset", 128); + int MaxDepth = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxDepth", 30); + int MaxSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxSize", 260); + m_FinishGens.push_back(new cRainbowRoadsGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize)); } else if (NoCaseCompare(*itr, "Ravines") == 0) { @@ -417,19 +420,21 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "UnderwaterBases") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseGridSize", 1024); - int MaxDepth = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxDepth", 7); - int MaxSize = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxSize", 128); - m_FinishGens.push_back(new cUnderwaterBaseGen(Seed, GridSize, MaxDepth, MaxSize, *m_BiomeGen)); + int GridSize = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseGridSize", 1024); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxOffset", 128); + int MaxDepth = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxDepth", 7); + int MaxSize = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxSize", 128); + m_FinishGens.push_back(new cUnderwaterBaseGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize, *m_BiomeGen)); } else if (NoCaseCompare(*itr, "Villages") == 0) { int GridSize = a_IniFile.GetValueSetI("Generator", "VillageGridSize", 384); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "VillageMaxOffset", 128); int MaxDepth = a_IniFile.GetValueSetI("Generator", "VillageMaxDepth", 2); int MaxSize = a_IniFile.GetValueSetI("Generator", "VillageMaxSize", 128); int MinDensity = a_IniFile.GetValueSetI("Generator", "VillageMinDensity", 50); int MaxDensity = a_IniFile.GetValueSetI("Generator", "VillageMaxDensity", 80); - m_FinishGens.push_back(new cVillageGen(Seed, GridSize, MaxDepth, MaxSize, MinDensity, MaxDensity, *m_BiomeGen, *m_HeightGen)); + m_FinishGens.push_back(new cVillageGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize, MinDensity, MaxDensity, *m_BiomeGen, *m_HeightGen)); } else if (NoCaseCompare(*itr, "WaterLakes") == 0) { @@ -442,7 +447,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "WormNestCaves") == 0) { - m_FinishGens.push_back(new cStructGenWormNestCaves(Seed)); + int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64); + int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "NetherFortMaxOffset", 32); + m_FinishGens.push_back(new cStructGenWormNestCaves(Seed, Size, Grid, MaxOffset)); } else { diff --git a/src/Generating/GridStructGen.cpp b/src/Generating/GridStructGen.cpp index 474242557..2931df3eb 100644 --- a/src/Generating/GridStructGen.cpp +++ b/src/Generating/GridStructGen.cpp @@ -21,8 +21,8 @@ class cEmptyStructure : typedef cGridStructGen::cStructure super; public: - cEmptyStructure(int a_OriginX, int a_OriginZ) : - super(a_OriginX, a_OriginZ) + cEmptyStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ) { } @@ -40,17 +40,20 @@ protected: cGridStructGen::cGridStructGen( int a_Seed, int a_GridSizeX, int a_GridSizeZ, + int a_MaxOffsetX, int a_MaxOffsetZ, int a_MaxStructureSizeX, int a_MaxStructureSizeZ, size_t a_MaxCacheSize ) : - m_Seed(a_Seed), + m_Noise(a_Seed), m_GridSizeX(a_GridSizeX), m_GridSizeZ(a_GridSizeZ), + m_MaxOffsetX(a_MaxOffsetX), + m_MaxOffsetZ(a_MaxOffsetZ), m_MaxStructureSizeX(a_MaxStructureSizeX), m_MaxStructureSizeZ(a_MaxStructureSizeZ), m_MaxCacheSize(a_MaxCacheSize) { - size_t NumStructuresPerQuery = (size_t)((m_MaxStructureSizeX / m_GridSizeX + 1) * (m_MaxStructureSizeZ / m_GridSizeZ + 1)); + size_t NumStructuresPerQuery = (size_t)(((m_MaxStructureSizeX + m_MaxOffsetX) / m_GridSizeX + 1) * ((m_MaxStructureSizeZ + m_MaxOffsetZ) / m_GridSizeZ + 1)); if (NumStructuresPerQuery > m_MaxCacheSize) { m_MaxCacheSize = NumStructuresPerQuery * 4; @@ -68,10 +71,10 @@ cGridStructGen::cGridStructGen( void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructurePtrs & a_Structures) { // Calculate the min and max grid coords of the structures to be returned: - int MinBlockX = a_ChunkX * cChunkDef::Width - m_MaxStructureSizeX; - int MinBlockZ = a_ChunkZ * cChunkDef::Width - m_MaxStructureSizeZ; - int MaxBlockX = a_ChunkX * cChunkDef::Width + m_MaxStructureSizeX + cChunkDef::Width - 1; - int MaxBlockZ = a_ChunkZ * cChunkDef::Width + m_MaxStructureSizeZ + cChunkDef::Width - 1; + int MinBlockX = a_ChunkX * cChunkDef::Width - m_MaxStructureSizeX - m_MaxOffsetX; + int MinBlockZ = a_ChunkZ * cChunkDef::Width - m_MaxStructureSizeZ - m_MaxOffsetZ; + int MaxBlockX = a_ChunkX * cChunkDef::Width + m_MaxStructureSizeX + m_MaxOffsetX + cChunkDef::Width - 1; + int MaxBlockZ = a_ChunkZ * cChunkDef::Width + m_MaxStructureSizeZ + m_MaxOffsetZ + cChunkDef::Width - 1; int MinGridX = MinBlockX / m_GridSizeX; int MinGridZ = MinBlockZ / m_GridSizeZ; int MaxGridX = (MaxBlockX + m_GridSizeX - 1) / m_GridSizeX; @@ -103,14 +106,14 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur // Create those structures that haven't been in the cache: for (int x = MinGridX; x < MaxGridX; x++) { - int OriginX = x * m_GridSizeX; + int GridX = x * m_GridSizeX; for (int z = MinGridZ; z < MaxGridZ; z++) { - int OriginZ = z * m_GridSizeZ; + int GridZ = z * m_GridSizeZ; bool Found = false; for (cStructurePtrs::const_iterator itr = a_Structures.begin(), end = a_Structures.end(); itr != end; ++itr) { - if (((*itr)->m_OriginX == OriginX) && ((*itr)->m_OriginZ == OriginZ)) + if (((*itr)->m_GridX == GridX) && ((*itr)->m_GridZ == GridZ)) { Found = true; break; @@ -118,10 +121,12 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur } // for itr - a_Structures[] if (!Found) { - cStructurePtr Structure = CreateStructure(OriginX, OriginZ); + int OriginX = GridX + ((m_Noise.IntNoise2DInt(GridX + 3, GridZ + 5) / 7) % (m_MaxOffsetX * 2)) - m_MaxOffsetX; + int OriginZ = GridZ + ((m_Noise.IntNoise2DInt(GridX + 5, GridZ + 3) / 7) % (m_MaxOffsetZ * 2)) - m_MaxOffsetZ; + cStructurePtr Structure = CreateStructure(GridX, GridZ, OriginX, OriginZ); if (Structure.get() == NULL) { - Structure.reset(new cEmptyStructure(OriginX, OriginZ)); + Structure.reset(new cEmptyStructure(GridX, GridZ, OriginX, OriginZ)); } a_Structures.push_back(Structure); } diff --git a/src/Generating/GridStructGen.h b/src/Generating/GridStructGen.h index 630a5e44e..03131fce9 100644 --- a/src/Generating/GridStructGen.h +++ b/src/Generating/GridStructGen.h @@ -10,6 +10,7 @@ #pragma once #include "ComposableGenerator.h" +#include "../Noise.h" @@ -19,7 +20,12 @@ Defines a grid in the XZ space with predefined cell size in each direction. Each cell then receives exactly one structure (provided by the descendant class). The structure is placed within the cell, but doesn't need to be bounded by the cell, it can be well outside the cell; the generator uses the MaxStructureSize parameter -to determine how far away from the cell the structure can be at most. +to determine how far away from the cell the structure can be at most. Each structure has an offset from the +grid's center point, the offset is generated randomly from a range given to this class as a parameter. + +Each structure thus contains the coords of its grid center (m_GridX, m_GridZ) and the actual origin from +which it's built (m_OriginX, m_OriginZ). + This class provides a cache for the structures generated for successive chunks and manages that cache. It also provides the cFinishGen override that uses the cache to actually generate the structure into chunk data. @@ -43,12 +49,17 @@ public: class cStructure { public: - /** The origin (the coords of the gridpoint for which the structure is generated) */ + /** The grid point for which the structure is generated. */ + int m_GridX, m_GridZ; + + /** The origin (the coords for which the structure is generated) */ int m_OriginX, m_OriginZ; - /** Creates a structure that has its originset at the specified coords. */ - cStructure (int a_OriginX, int a_OriginZ) : + /** Creates a structure that has its origin set at the specified coords. */ + cStructure (int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : + m_GridX(a_GridX), + m_GridZ(a_GridZ), m_OriginX(a_OriginX), m_OriginZ(a_OriginZ) { @@ -70,20 +81,30 @@ public: cGridStructGen( int a_Seed, int a_GridSizeX, int a_GridSizeZ, + int a_MaxOffsetX, int a_MaxOffsetZ, int a_MaxStructureSizeX, int a_MaxStructureSizeZ, size_t a_MaxCacheSize ); protected: - /** Seed for generating the semi-random grid. */ + /** Seed for generating grid offsets and also available for descendants. */ int m_Seed; + /** The noise used for generating grid offsets. */ + cNoise m_Noise; + /** The size of each grid's cell in the X axis */ int m_GridSizeX; /** The size of each grid's cell in the Z axis */ int m_GridSizeZ; + /** The maximum offset of the structure's origin from the grid midpoint, in X coord. */ + int m_MaxOffsetX; + + /** The maximum offset of the structure's origin from the grid midpoint, in Z coord. */ + int m_MaxOffsetZ; + /** Maximum theoretical size of the structure in the X axis. This limits the structures considered for a single chunk, so the lesser the number, the better performance. Structures large than this may get cropped. */ @@ -115,7 +136,7 @@ protected: // Functions for the descendants to override: /** Create a new structure at the specified gridpoint */ - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) = 0; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) = 0; } ; diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 81ae6481d..ab9b1aa29 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -248,7 +248,8 @@ public: /** Creates and generates the entire system */ cMineShaftSystem( - int a_OriginX, int a_OriginZ, int a_GridSize, int a_MaxSystemSize, cNoise & a_Noise, + int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, + int a_GridSize, int a_MaxSystemSize, cNoise & a_Noise, int a_ProbLevelCorridor, int a_ProbLevelCrossing, int a_ProbLevelStaircase ); @@ -278,10 +279,11 @@ public: // cStructGenMineShafts::cMineShaftSystem: cStructGenMineShafts::cMineShaftSystem::cMineShaftSystem( - int a_OriginX, int a_OriginZ, int a_GridSize, int a_MaxSystemSize, cNoise & a_Noise, + int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, + int a_GridSize, int a_MaxSystemSize, cNoise & a_Noise, int a_ProbLevelCorridor, int a_ProbLevelCrossing, int a_ProbLevelStaircase ) : - super(a_OriginX, a_OriginZ), + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_GridSize(a_GridSize), m_MaxRecursion(8), // TODO: settable m_ProbLevelCorridor(a_ProbLevelCorridor), @@ -1280,10 +1282,10 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) // cStructGenMineShafts: cStructGenMineShafts::cStructGenMineShafts( - int a_Seed, int a_GridSize, int a_MaxSystemSize, + int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxSystemSize, int a_ChanceCorridor, int a_ChanceCrossing, int a_ChanceStaircase ) : - super(a_Seed, a_GridSize, a_GridSize, a_MaxSystemSize, a_MaxSystemSize, 100), + super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSystemSize, a_MaxSystemSize, 100), m_Noise(a_Seed), m_GridSize(a_GridSize), m_MaxSystemSize(a_MaxSystemSize), @@ -1297,9 +1299,9 @@ cStructGenMineShafts::cStructGenMineShafts( -cGridStructGen::cStructurePtr cStructGenMineShafts::CreateStructure(int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cStructGenMineShafts::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { - return cStructurePtr(new cMineShaftSystem(a_OriginX, a_OriginZ, m_GridSize, m_MaxSystemSize, m_Noise, m_ProbLevelCorridor, m_ProbLevelCrossing, m_ProbLevelStaircase)); + return cStructurePtr(new cMineShaftSystem(a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_GridSize, m_MaxSystemSize, m_Noise, m_ProbLevelCorridor, m_ProbLevelCrossing, m_ProbLevelStaircase)); } diff --git a/src/Generating/MineShafts.h b/src/Generating/MineShafts.h index c29b6cdac..2850db571 100644 --- a/src/Generating/MineShafts.h +++ b/src/Generating/MineShafts.h @@ -23,7 +23,7 @@ class cStructGenMineShafts : public: cStructGenMineShafts( - int a_Seed, int a_GridSize, int a_MaxSystemSize, + int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxSystemSize, int a_ChanceCorridor, int a_ChanceCrossing, int a_ChanceStaircase ); @@ -43,7 +43,7 @@ protected: int m_ProbLevelStaircase; ///< Probability level of a branch object being the staircase, minus Crossing // cGridStructGen overrides: - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; diff --git a/src/Generating/NetherFortGen.cpp b/src/Generating/NetherFortGen.cpp index 3867ec80c..23fa56048 100644 --- a/src/Generating/NetherFortGen.cpp +++ b/src/Generating/NetherFortGen.cpp @@ -26,8 +26,8 @@ public: cPlacedPieces m_Pieces; - cNetherFort(cNetherFortGen & a_ParentGen, int a_OriginX, int a_OriginZ, int a_GridSize, int a_MaxDepth, int a_Seed) : - super(a_OriginX, a_OriginZ), + cNetherFort(cNetherFortGen & a_ParentGen, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_GridSize, int a_MaxDepth, int a_Seed) : + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_ParentGen(a_ParentGen), m_GridSize(a_GridSize), m_Seed(a_Seed) @@ -108,8 +108,8 @@ cPrefabPiecePool cNetherFortGen::m_PiecePool(g_NetherFortPrefabs, g_NetherFortPr -cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth) : - super(a_Seed, a_GridSize, a_GridSize, a_MaxDepth * 10, a_MaxDepth * 10, 200), +cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth) : + super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxDepth * 10, a_MaxDepth * 10, 200), m_MaxDepth(a_MaxDepth) { /* @@ -124,8 +124,11 @@ cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth) : -cGridStructGen::cStructurePtr cNetherFortGen::CreateStructure(int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cNetherFortGen::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { - return cStructurePtr(new cNetherFort(*this, a_OriginX, a_OriginZ, m_GridSizeX, m_MaxDepth, m_Seed)); + return cStructurePtr(new cNetherFort(*this, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_GridSizeX, m_MaxDepth, m_Seed)); } + + + diff --git a/src/Generating/NetherFortGen.h b/src/Generating/NetherFortGen.h index f35801a3c..9b31aa0e2 100644 --- a/src/Generating/NetherFortGen.h +++ b/src/Generating/NetherFortGen.h @@ -23,7 +23,7 @@ class cNetherFortGen : typedef cGridStructGen super; public: - cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth); + cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth); protected: friend class cNetherFortPerfTest; // fwd: NetherFortGen.cpp @@ -37,7 +37,7 @@ protected: // cGridStructGen overrides: - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; diff --git a/src/Generating/RainbowRoadsGen.cpp b/src/Generating/RainbowRoadsGen.cpp index d1e1f4bda..3b0ff7df8 100644 --- a/src/Generating/RainbowRoadsGen.cpp +++ b/src/Generating/RainbowRoadsGen.cpp @@ -29,11 +29,12 @@ class cRainbowRoadsGen::cRainbowRoads : public: cRainbowRoads( int a_Seed, + int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxDepth, int a_MaxSize ) : - super(a_OriginX, a_OriginZ), + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Seed(a_Seed), m_Noise(a_Seed), m_MaxSize(a_MaxSize), @@ -92,8 +93,8 @@ protected: -cRainbowRoadsGen::cRainbowRoadsGen(int a_Seed, int a_GridSize, int a_MaxDepth, int a_MaxSize) : - super(a_Seed, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 100), +cRainbowRoadsGen::cRainbowRoadsGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize) : + super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100), m_Noise(a_Seed + 9000), m_MaxDepth(a_MaxDepth), m_MaxSize(a_MaxSize) @@ -104,10 +105,10 @@ cRainbowRoadsGen::cRainbowRoadsGen(int a_Seed, int a_GridSize, int a_MaxDepth, i -cGridStructGen::cStructurePtr cRainbowRoadsGen::CreateStructure(int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cRainbowRoadsGen::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { // Create a base based on the chosen prefabs: - return cStructurePtr(new cRainbowRoads(m_Seed, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize)); + return cStructurePtr(new cRainbowRoads(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize)); } diff --git a/src/Generating/RainbowRoadsGen.h b/src/Generating/RainbowRoadsGen.h index acbd5abf9..5813e1d14 100644 --- a/src/Generating/RainbowRoadsGen.h +++ b/src/Generating/RainbowRoadsGen.h @@ -22,7 +22,7 @@ class cRainbowRoadsGen : typedef cGridStructGen super; public: - cRainbowRoadsGen(int a_Seed, int a_GridSize, int a_MaxDepth, int a_MaxSize); + cRainbowRoadsGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize); protected: class cRainbowRoads; // fwd: RainbowRoadsGen.cpp @@ -39,7 +39,7 @@ protected: // cGridStructGen overrides: - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index 2722e4ca3..24f2cc3ab 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -61,7 +61,7 @@ class cStructGenRavines::cRavine : public: - cRavine(int a_BlockX, int a_BlockZ, int a_Size, cNoise & a_Noise); + cRavine(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_Size, cNoise & a_Noise); #ifdef _DEBUG /// Exports itself as a SVG line definition @@ -81,7 +81,7 @@ protected: // cStructGenRavines: cStructGenRavines::cStructGenRavines(int a_Seed, int a_Size) : - super(a_Seed, a_Size, a_Size, a_Size * 2, a_Size * 2, 100), + super(a_Seed, a_Size, a_Size, a_Size, a_Size, a_Size * 2, a_Size * 2, 100), m_Noise(a_Seed), m_Size(a_Size) { @@ -91,9 +91,9 @@ cStructGenRavines::cStructGenRavines(int a_Seed, int a_Size) : -cGridStructGen::cStructurePtr cStructGenRavines::CreateStructure(int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cStructGenRavines::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { - return cStructurePtr(new cRavine(a_OriginX, a_OriginZ, m_Size, m_Noise)); + return cStructurePtr(new cRavine(a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_Size, m_Noise)); } @@ -104,8 +104,8 @@ cGridStructGen::cStructurePtr cStructGenRavines::CreateStructure(int a_OriginX, /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cStructGenRavines::cRavine -cStructGenRavines::cRavine::cRavine(int a_OriginX, int a_OriginZ, int a_Size, cNoise & a_Noise) : - super(a_OriginX, a_OriginZ) +cStructGenRavines::cRavine::cRavine(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_Size, cNoise & a_Noise) : + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ) { // Calculate the ravine shape-defining points: GenerateBaseDefPoints(a_OriginX, a_OriginZ, a_Size, a_Noise); diff --git a/src/Generating/Ravines.h b/src/Generating/Ravines.h index 30b47e9ec..3e41c5ce6 100644 --- a/src/Generating/Ravines.h +++ b/src/Generating/Ravines.h @@ -32,7 +32,7 @@ protected: // cGridStructGen overrides: - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; diff --git a/src/Generating/UnderwaterBaseGen.cpp b/src/Generating/UnderwaterBaseGen.cpp index ff6f17dde..d3abae9b7 100644 --- a/src/Generating/UnderwaterBaseGen.cpp +++ b/src/Generating/UnderwaterBaseGen.cpp @@ -29,11 +29,12 @@ class cUnderwaterBaseGen::cUnderwaterBase : public: cUnderwaterBase( int a_Seed, + int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxDepth, int a_MaxSize ) : - super(a_OriginX, a_OriginZ), + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Seed(a_Seed), m_Noise(a_Seed), m_MaxSize(a_MaxSize), @@ -92,8 +93,8 @@ protected: -cUnderwaterBaseGen::cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxDepth, int a_MaxSize, cBiomeGen & a_BiomeGen) : - super(a_Seed, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 100), +cUnderwaterBaseGen::cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, cBiomeGen & a_BiomeGen) : + super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100), m_Noise(a_Seed + 1000), m_MaxDepth(a_MaxDepth), m_MaxSize(a_MaxSize), @@ -105,7 +106,7 @@ cUnderwaterBaseGen::cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxDept -cGridStructGen::cStructurePtr cUnderwaterBaseGen::CreateStructure(int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cUnderwaterBaseGen::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { // Generate the biomes for the chunk surrounding the origin: int ChunkX, ChunkZ; @@ -134,7 +135,7 @@ cGridStructGen::cStructurePtr cUnderwaterBaseGen::CreateStructure(int a_OriginX, } // for i - Biomes[] // Create a base based on the chosen prefabs: - return cStructurePtr(new cUnderwaterBase(m_Seed, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize)); + return cStructurePtr(new cUnderwaterBase(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize)); } diff --git a/src/Generating/UnderwaterBaseGen.h b/src/Generating/UnderwaterBaseGen.h index 0aefbb4c7..d6267b602 100644 --- a/src/Generating/UnderwaterBaseGen.h +++ b/src/Generating/UnderwaterBaseGen.h @@ -22,7 +22,7 @@ class cUnderwaterBaseGen : typedef cGridStructGen super; public: - cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxDepth, int a_MaxSize, cBiomeGen & a_BiomeGen); + cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, cBiomeGen & a_BiomeGen); protected: class cUnderwaterBase; // fwd: UnderwaterBaseGen.cpp @@ -42,7 +42,7 @@ protected: // cGridStructGen overrides: - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index 9917141ed..2b7ecc837 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -110,6 +110,7 @@ class cVillageGen::cVillage : public: cVillage( int a_Seed, + int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxRoadDepth, int a_MaxSize, @@ -119,7 +120,7 @@ public: BLOCKTYPE a_RoadBlock, BLOCKTYPE a_WaterRoadBlock ) : - super(a_OriginX, a_OriginZ), + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Seed(a_Seed), m_Noise(a_Seed), m_MaxSize(a_MaxSize), @@ -358,8 +359,8 @@ static cVillagePiecePool * g_PlainsVillagePools[] = -cVillageGen::cVillageGen(int a_Seed, int a_GridSize, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen) : - super(a_Seed, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 100), +cVillageGen::cVillageGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen) : + super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100), m_Noise(a_Seed + 1000), m_MaxDepth(a_MaxDepth), m_MaxSize(a_MaxSize), @@ -374,7 +375,7 @@ cVillageGen::cVillageGen(int a_Seed, int a_GridSize, int a_MaxDepth, int a_MaxSi -cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { // Generate the biomes for the chunk surrounding the origin: int ChunkX, ChunkZ; @@ -435,7 +436,7 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_OriginX, int a_ { return cStructurePtr(); } - return cStructurePtr(new cVillage(m_Seed, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize, Density, *VillagePrefabs, m_HeightGen, RoadBlock, WaterRoadBlock)); + return cStructurePtr(new cVillage(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize, Density, *VillagePrefabs, m_HeightGen, RoadBlock, WaterRoadBlock)); } diff --git a/src/Generating/VillageGen.h b/src/Generating/VillageGen.h index 5faaae8a6..694ea2358 100644 --- a/src/Generating/VillageGen.h +++ b/src/Generating/VillageGen.h @@ -21,7 +21,7 @@ class cVillageGen : { typedef cGridStructGen super; public: - cVillageGen(int a_Seed, int a_GridSize, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen); + cVillageGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen); protected: class cVillage; // fwd: VillageGen.cpp @@ -49,7 +49,7 @@ protected: // cGridStructGen overrides: - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; -- cgit v1.2.3 From c41299b4d486116b80056a898b0685f83419cbed Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 16 Jun 2014 10:18:23 +0200 Subject: Updated the SandFlatRoofVillage prefabs. --- .../Prefabs/SandFlatRoofVillagePrefabs.cpp | 669 ++++++++++++--------- 1 file changed, 381 insertions(+), 288 deletions(-) diff --git a/src/Generating/Prefabs/SandFlatRoofVillagePrefabs.cpp b/src/Generating/Prefabs/SandFlatRoofVillagePrefabs.cpp index 4f0efdcc6..eb01cf59e 100644 --- a/src/Generating/Prefabs/SandFlatRoofVillagePrefabs.cpp +++ b/src/Generating/Prefabs/SandFlatRoofVillagePrefabs.cpp @@ -20,18 +20,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 32, ID 173, created by Aloe_vera { // Size: - 12, 5, 10, // SizeX = 12, SizeY = 5, SizeZ = 10 + 12, 6, 10, // SizeX = 12, SizeY = 6, SizeZ = 10 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 11, 4, 9, // MaxX, MaxY, MaxZ + 11, 5, 9, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 2\n" /* sandstonestairs */ - "b:128: 1\n" /* sandstonestairs */ - "c:128: 0\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e:128: 3\n" /* sandstonestairs */ "f:171:15\n" /* carpet */ "g: 64: 6\n" /* wooddoorblock */ @@ -54,35 +54,49 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Level 0 /* z\x* 11 */ /* * 012345678901 */ - /* 0 */ "aaaaaab....." - /* 1 */ "cdddddddddd." - /* 2 */ "cdddddddddd." - /* 3 */ "cdddddddddd." - /* 4 */ "cdddddddddd." - /* 5 */ "edddddddddd." - /* 6 */ ".dddddddddd." - /* 7 */ ".dddddddddd." - /* 8 */ ".dddddddddd." - /* 9 */ "............" + /* 0 */ "aaaaaaammmmm" + /* 1 */ "aaaaaaaaaaam" + /* 2 */ "aaaaaaaaaaam" + /* 3 */ "aaaaaaaaaaam" + /* 4 */ "aaaaaaaaaaam" + /* 5 */ "aaaaaaaaaaam" + /* 6 */ "maaaaaaaaaam" + /* 7 */ "maaaaaaaaaam" + /* 8 */ "maaaaaaaaaam" + /* 9 */ "mmmmmmmmmmmm" // Level 1 /* z\x* 11 */ /* * 012345678901 */ - /* 0 */ "............" - /* 1 */ ".d....ddddd." - /* 2 */ "......dfffd." - /* 3 */ "......ghfhd." - /* 4 */ "......diiid." - /* 5 */ ".d....dhfhd." - /* 6 */ ".djddjdfffd." - /* 7 */ ".ddkkddl..d." - /* 8 */ ".dddddddddd." + /* 0 */ "bcccccd....." + /* 1 */ "baaaaaaaaaa." + /* 2 */ "baaaaaaaaaa." + /* 3 */ "baaaaaaaaaa." + /* 4 */ "baaaaaaaaaa." + /* 5 */ "eaaaaaaaaaa." + /* 6 */ ".aaaaaaaaaa." + /* 7 */ ".aaaaaaaaaa." + /* 8 */ ".aaaaaaaaaa." /* 9 */ "............" // Level 2 /* z\x* 11 */ /* * 012345678901 */ /* 0 */ "............" + /* 1 */ ".a....aaaaa." + /* 2 */ "......afffa." + /* 3 */ "......ghfha." + /* 4 */ "......aiiia." + /* 5 */ ".a....ahfha." + /* 6 */ ".ajaajafffa." + /* 7 */ ".aakkaal..a." + /* 8 */ ".aaaaaaaaaa." + /* 9 */ "............" + + // Level 3 + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "............" /* 1 */ ".n....nn.nn." /* 2 */ "......n...n." /* 3 */ "......o...n." @@ -93,36 +107,36 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = /* 8 */ ".nnn.nnn.nn." /* 9 */ "............" - // Level 3 + // Level 4 /* z\x* 11 */ /* * 012345678901 */ /* 0 */ "............" - /* 1 */ ".d....ddddd." - /* 2 */ "......d...d." - /* 3 */ "......d...d." - /* 4 */ "......dp..d." - /* 5 */ ".d....d...d." - /* 6 */ ".dqqqqd...d." - /* 7 */ ".d....d...d." - /* 8 */ ".dddddddddd." + /* 1 */ ".a....aaaaa." + /* 2 */ "......a...a." + /* 3 */ "......a...a." + /* 4 */ "......ap..a." + /* 5 */ ".a....a...a." + /* 6 */ ".aqqqqa...a." + /* 7 */ ".a....a...a." + /* 8 */ ".aaaaaaaaaa." /* 9 */ "............" - // Level 4 + // Level 5 /* z\x* 11 */ /* * 012345678901 */ /* 0 */ "rsssssssssss" - /* 1 */ "rddddddddddt" - /* 2 */ "rddddddddddt" - /* 3 */ "rddddddddddt" - /* 4 */ "rddddddddddt" - /* 5 */ "rddddddddddt" - /* 6 */ "rddddddddddt" - /* 7 */ "rddddddddddt" - /* 8 */ "rddddddddddt" + /* 1 */ "raaaaaaaaaat" + /* 2 */ "raaaaaaaaaat" + /* 3 */ "raaaaaaaaaat" + /* 4 */ "raaaaaaaaaat" + /* 5 */ "raaaaaaaaaat" + /* 6 */ "raaaaaaaaaat" + /* 7 */ "raaaaaaaaaat" + /* 8 */ "raaaaaaaaaat" /* 9 */ "uuuuuuuuuuut", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -153,18 +167,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 31, ID 172, created by Aloe_vera { // Size: - 13, 5, 9, // SizeX = 13, SizeY = 5, SizeZ = 9 + 13, 6, 9, // SizeX = 13, SizeY = 6, SizeZ = 9 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 12, 4, 8, // MaxX, MaxY, MaxZ + 12, 5, 8, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 0\n" /* sandstonestairs */ - "b:128: 2\n" /* sandstonestairs */ - "c:128: 1\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e: 64: 7\n" /* wooddoorblock */ "f:171: 0\n" /* carpet */ "g:171:15\n" /* carpet */ @@ -185,33 +199,46 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Level 0 /* z\x* 111 */ /* * 0123456789012 */ - /* 0 */ "..abc........" - /* 1 */ ".ddddddddddd." - /* 2 */ ".ddddddddddd." - /* 3 */ ".ddddddddddd." - /* 4 */ ".ddddddddddd." - /* 5 */ ".ddddddddddd." - /* 6 */ ".ddddddddddd." - /* 7 */ ".ddddddddddd." - /* 8 */ "............." + /* 0 */ "mmaaammmmmmmm" + /* 1 */ "maaaaaaaaaaam" + /* 2 */ "maaaaaaaaaaam" + /* 3 */ "maaaaaaaaaaam" + /* 4 */ "maaaaaaaaaaam" + /* 5 */ "maaaaaaaaaaam" + /* 6 */ "maaaaaaaaaaam" + /* 7 */ "maaaaaaaaaaam" + /* 8 */ "mmmmmmmmmmmmm" // Level 1 /* z\x* 111 */ /* * 0123456789012 */ - /* 0 */ "............." - /* 1 */ ".ddedddddddd." - /* 2 */ ".dffgggggffd." - /* 3 */ ".dfghhhhhgfd." - /* 4 */ ".dfghfffhgfd." - /* 5 */ ".dfghhhhhgfd." - /* 6 */ ".dffgggggffd." - /* 7 */ ".ddddddddddd." + /* 0 */ "..bcd........" + /* 1 */ ".aaaaaaaaaaa." + /* 2 */ ".aaaaaaaaaaa." + /* 3 */ ".aaaaaaaaaaa." + /* 4 */ ".aaaaaaaaaaa." + /* 5 */ ".aaaaaaaaaaa." + /* 6 */ ".aaaaaaaaaaa." + /* 7 */ ".aaaaaaaaaaa." /* 8 */ "............." // Level 2 /* z\x* 111 */ /* * 0123456789012 */ /* 0 */ "............." + /* 1 */ ".aaeaaaaaaaa." + /* 2 */ ".affgggggffa." + /* 3 */ ".afghhhhhgfa." + /* 4 */ ".afghfffhgfa." + /* 5 */ ".afghhhhhgfa." + /* 6 */ ".affgggggffa." + /* 7 */ ".aaaaaaaaaaa." + /* 8 */ "............." + + // Level 3 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "............." /* 1 */ ".iiji.iii.ii." /* 2 */ ".i.........i." /* 3 */ ".i.........i." @@ -221,34 +248,34 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = /* 7 */ ".ii.ii.ii.ii." /* 8 */ "............." - // Level 3 + // Level 4 /* z\x* 111 */ /* * 0123456789012 */ /* 0 */ "............." - /* 1 */ ".ddddddddddd." - /* 2 */ ".d..k..k...d." - /* 3 */ ".d.........d." - /* 4 */ ".dl.......nd." - /* 5 */ ".d.........d." - /* 6 */ ".d....o....d." - /* 7 */ ".ddddddddddd." + /* 1 */ ".aaaaaaaaaaa." + /* 2 */ ".a..k..k...a." + /* 3 */ ".a.........a." + /* 4 */ ".al.......na." + /* 5 */ ".a.........a." + /* 6 */ ".a....o....a." + /* 7 */ ".aaaaaaaaaaa." /* 8 */ "............." - // Level 4 + // Level 5 /* z\x* 111 */ /* * 0123456789012 */ /* 0 */ "pqqqqqqqqqqqq" - /* 1 */ "pdddddddddddr" - /* 2 */ "pdddddddddddr" - /* 3 */ "pdddddddddddr" - /* 4 */ "pdddddddddddr" - /* 5 */ "pdddddddddddr" - /* 6 */ "pdddddddddddr" - /* 7 */ "pdddddddddddr" + /* 1 */ "paaaaaaaaaaar" + /* 2 */ "paaaaaaaaaaar" + /* 3 */ "paaaaaaaaaaar" + /* 4 */ "paaaaaaaaaaar" + /* 5 */ "paaaaaaaaaaar" + /* 6 */ "paaaaaaaaaaar" + /* 7 */ "paaaaaaaaaaar" /* 8 */ "ssssssssssssr", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -279,18 +306,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 25, ID 166, created by Aloe_vera { // Size: - 7, 5, 6, // SizeX = 7, SizeY = 5, SizeZ = 6 + 7, 6, 6, // SizeX = 7, SizeY = 6, SizeZ = 6 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 6, 4, 5, // MaxX, MaxY, MaxZ + 6, 5, 5, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 0\n" /* sandstonestairs */ - "b:128: 2\n" /* sandstonestairs */ - "c:128: 1\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e: 64: 7\n" /* wooddoorblock */ "f:171: 0\n" /* carpet */ "g:171:14\n" /* carpet */ @@ -306,51 +333,60 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Block data: // Level 0 /* z\x* 0123456 */ - /* 0 */ "..abc.." - /* 1 */ ".ddddd." - /* 2 */ ".ddddd." - /* 3 */ ".ddddd." - /* 4 */ ".ddddd." - /* 5 */ "......." + /* 0 */ "mmaaamm" + /* 1 */ "maaaaam" + /* 2 */ "maaaaam" + /* 3 */ "maaaaam" + /* 4 */ "maaaaam" + /* 5 */ "mmmmmmm" // Level 1 /* z\x* 0123456 */ - /* 0 */ "......." - /* 1 */ ".ddedd." - /* 2 */ ".dfgfd." - /* 3 */ ".dfgfd." - /* 4 */ ".ddddd." + /* 0 */ "..bcd.." + /* 1 */ ".aaaaa." + /* 2 */ ".aaaaa." + /* 3 */ ".aaaaa." + /* 4 */ ".aaaaa." /* 5 */ "......." // Level 2 /* z\x* 0123456 */ /* 0 */ "......." + /* 1 */ ".aaeaa." + /* 2 */ ".afgfa." + /* 3 */ ".afgfa." + /* 4 */ ".aaaaa." + /* 5 */ "......." + + // Level 3 + /* z\x* 0123456 */ + /* 0 */ "......." /* 1 */ ".hhihh." /* 2 */ ".h...h." /* 3 */ ".h...h." /* 4 */ ".hh.hh." /* 5 */ "......." - // Level 3 + // Level 4 /* z\x* 0123456 */ /* 0 */ "......." - /* 1 */ ".ddddd." - /* 2 */ ".dj.jd." - /* 3 */ ".d...d." - /* 4 */ ".ddddd." + /* 1 */ ".aaaaa." + /* 2 */ ".aj.ja." + /* 3 */ ".a...a." + /* 4 */ ".aaaaa." /* 5 */ "......." - // Level 4 + // Level 5 /* z\x* 0123456 */ /* 0 */ "kllllln" - /* 1 */ "kdddddn" - /* 2 */ "kdddddn" - /* 3 */ "kdddddn" - /* 4 */ "kdddddn" + /* 1 */ "kaaaaan" + /* 2 */ "kaaaaan" + /* 3 */ "kaaaaan" + /* 4 */ "kaaaaan" /* 5 */ "oooooon", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -381,18 +417,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 26, ID 167, created by Aloe_vera { // Size: - 7, 5, 7, // SizeX = 7, SizeY = 5, SizeZ = 7 + 7, 6, 7, // SizeX = 7, SizeY = 6, SizeZ = 7 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 6, 4, 6, // MaxX, MaxY, MaxZ + 6, 5, 6, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 0\n" /* sandstonestairs */ - "b:128: 2\n" /* sandstonestairs */ - "c:128: 1\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e: 64: 7\n" /* wooddoorblock */ "f:171: 0\n" /* carpet */ "g:171:15\n" /* carpet */ @@ -409,27 +445,37 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Block data: // Level 0 /* z\x* 0123456 */ - /* 0 */ "..abc.." - /* 1 */ ".ddddd." - /* 2 */ ".ddddd." - /* 3 */ ".ddddd." - /* 4 */ ".ddddd." - /* 5 */ ".ddddd." - /* 6 */ "......." + /* 0 */ "mmaaamm" + /* 1 */ "maaaaam" + /* 2 */ "maaaaam" + /* 3 */ "maaaaam" + /* 4 */ "maaaaam" + /* 5 */ "maaaaam" + /* 6 */ "mmmmmmm" // Level 1 /* z\x* 0123456 */ - /* 0 */ "......." - /* 1 */ ".ddedd." - /* 2 */ ".dfffd." - /* 3 */ ".dghgd." - /* 4 */ ".dfffd." - /* 5 */ ".ddddd." + /* 0 */ "..bcd.." + /* 1 */ ".aaaaa." + /* 2 */ ".aaaaa." + /* 3 */ ".aaaaa." + /* 4 */ ".aaaaa." + /* 5 */ ".aaaaa." /* 6 */ "......." // Level 2 /* z\x* 0123456 */ /* 0 */ "......." + /* 1 */ ".aaeaa." + /* 2 */ ".afffa." + /* 3 */ ".aghga." + /* 4 */ ".afffa." + /* 5 */ ".aaaaa." + /* 6 */ "......." + + // Level 3 + /* z\x* 0123456 */ + /* 0 */ "......." /* 1 */ ".iijii." /* 2 */ ".i...i." /* 3 */ "......." @@ -437,28 +483,28 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = /* 5 */ ".ii.ii." /* 6 */ "......." - // Level 3 + // Level 4 /* z\x* 0123456 */ /* 0 */ "......." - /* 1 */ ".ddddd." - /* 2 */ ".dk.kd." - /* 3 */ ".d...d." - /* 4 */ ".d...d." - /* 5 */ ".ddddd." + /* 1 */ ".aaaaa." + /* 2 */ ".ak.ka." + /* 3 */ ".a...a." + /* 4 */ ".a...a." + /* 5 */ ".aaaaa." /* 6 */ "......." - // Level 4 + // Level 5 /* z\x* 0123456 */ /* 0 */ "lnnnnno" - /* 1 */ "ldddddo" - /* 2 */ "ldddddo" - /* 3 */ "ldddddo" - /* 4 */ "ldddddo" - /* 5 */ "ldddddo" + /* 1 */ "laaaaao" + /* 2 */ "laaaaao" + /* 3 */ "laaaaao" + /* 4 */ "laaaaao" + /* 5 */ "laaaaao" /* 6 */ "ppppppo", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -489,18 +535,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 27, ID 168, created by Aloe_vera { // Size: - 9, 5, 7, // SizeX = 9, SizeY = 5, SizeZ = 7 + 9, 6, 7, // SizeX = 9, SizeY = 6, SizeZ = 7 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 8, 4, 6, // MaxX, MaxY, MaxZ + 8, 5, 6, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 0\n" /* sandstonestairs */ - "b:128: 2\n" /* sandstonestairs */ - "c:128: 1\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e: 64: 7\n" /* wooddoorblock */ "f:171:14\n" /* carpet */ "g:171: 0\n" /* carpet */ @@ -517,27 +563,37 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Block data: // Level 0 /* z\x* 012345678 */ - /* 0 */ "..abc...." - /* 1 */ ".ddddddd." - /* 2 */ ".ddddddd." - /* 3 */ ".ddddddd." - /* 4 */ ".ddddddd." - /* 5 */ ".ddddddd." - /* 6 */ "........." + /* 0 */ "mmaaammmm" + /* 1 */ "maaaaaaam" + /* 2 */ "maaaaaaam" + /* 3 */ "maaaaaaam" + /* 4 */ "maaaaaaam" + /* 5 */ "maaaaaaam" + /* 6 */ "mmmmmmmmm" // Level 1 /* z\x* 012345678 */ - /* 0 */ "........." - /* 1 */ ".ddedddd." - /* 2 */ ".dfffffd." - /* 3 */ ".dghhhgd." - /* 4 */ ".dfffffd." - /* 5 */ ".ddddddd." + /* 0 */ "..bcd...." + /* 1 */ ".aaaaaaa." + /* 2 */ ".aaaaaaa." + /* 3 */ ".aaaaaaa." + /* 4 */ ".aaaaaaa." + /* 5 */ ".aaaaaaa." /* 6 */ "........." // Level 2 /* z\x* 012345678 */ /* 0 */ "........." + /* 1 */ ".aaeaaaa." + /* 2 */ ".afffffa." + /* 3 */ ".aghhhga." + /* 4 */ ".afffffa." + /* 5 */ ".aaaaaaa." + /* 6 */ "........." + + // Level 3 + /* z\x* 012345678 */ + /* 0 */ "........." /* 1 */ ".iiji.ii." /* 2 */ ".i.....i." /* 3 */ "........." @@ -545,28 +601,28 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = /* 5 */ ".iii.iii." /* 6 */ "........." - // Level 3 + // Level 4 /* z\x* 012345678 */ /* 0 */ "........." - /* 1 */ ".ddddddd." - /* 2 */ ".dk.k..d." - /* 3 */ ".d.....d." - /* 4 */ ".d.....d." - /* 5 */ ".ddddddd." + /* 1 */ ".aaaaaaa." + /* 2 */ ".ak.k..a." + /* 3 */ ".a.....a." + /* 4 */ ".a.....a." + /* 5 */ ".aaaaaaa." /* 6 */ "........." - // Level 4 + // Level 5 /* z\x* 012345678 */ /* 0 */ "lnnnnnnnn" - /* 1 */ "ldddddddo" - /* 2 */ "ldddddddo" - /* 3 */ "ldddddddo" - /* 4 */ "ldddddddo" - /* 5 */ "ldddddddo" + /* 1 */ "laaaaaaao" + /* 2 */ "laaaaaaao" + /* 3 */ "laaaaaaao" + /* 4 */ "laaaaaaao" + /* 5 */ "laaaaaaao" /* 6 */ "ppppppppo", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -597,18 +653,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 28, ID 169, created by Aloe_vera { // Size: - 10, 5, 7, // SizeX = 10, SizeY = 5, SizeZ = 7 + 10, 6, 7, // SizeX = 10, SizeY = 6, SizeZ = 7 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 9, 4, 6, // MaxX, MaxY, MaxZ + 9, 5, 6, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 0\n" /* sandstonestairs */ - "b:128: 2\n" /* sandstonestairs */ - "c:128: 1\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e: 64: 7\n" /* wooddoorblock */ "f:171: 0\n" /* carpet */ "g:171:14\n" /* carpet */ @@ -626,29 +682,40 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Level 0 /* z\x* */ /* * 0123456789 */ - /* 0 */ "..abc....." - /* 1 */ ".dddddddd." - /* 2 */ ".dddddddd." - /* 3 */ ".dddddddd." - /* 4 */ ".dddddddd." - /* 5 */ ".dddddddd." - /* 6 */ ".........." + /* 0 */ "mmaaammmmm" + /* 1 */ "maaaaaaaam" + /* 2 */ "maaaaaaaam" + /* 3 */ "maaaaaaaam" + /* 4 */ "maaaaaaaam" + /* 5 */ "maaaaaaaam" + /* 6 */ "mmmmmmmmmm" // Level 1 /* z\x* */ /* * 0123456789 */ - /* 0 */ ".........." - /* 1 */ ".ddeddddd." - /* 2 */ ".dfghhgfd." - /* 3 */ ".dfhffhfd." - /* 4 */ ".dfghhgfd." - /* 5 */ ".dddddddd." + /* 0 */ "..bcd....." + /* 1 */ ".aaaaaaaa." + /* 2 */ ".aaaaaaaa." + /* 3 */ ".aaaaaaaa." + /* 4 */ ".aaaaaaaa." + /* 5 */ ".aaaaaaaa." /* 6 */ ".........." // Level 2 /* z\x* */ /* * 0123456789 */ /* 0 */ ".........." + /* 1 */ ".aaeaaaaa." + /* 2 */ ".afghhgfa." + /* 3 */ ".afhffhfa." + /* 4 */ ".afghhgfa." + /* 5 */ ".aaaaaaaa." + /* 6 */ ".........." + + // Level 3 + /* z\x* */ + /* * 0123456789 */ + /* 0 */ ".........." /* 1 */ ".iijii.ii." /* 2 */ ".i......i." /* 3 */ ".........." @@ -656,30 +723,30 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = /* 5 */ ".ii.ii.ii." /* 6 */ ".........." - // Level 3 + // Level 4 /* z\x* */ /* * 0123456789 */ /* 0 */ ".........." - /* 1 */ ".dddddddd." - /* 2 */ ".dk.k...d." - /* 3 */ ".d......d." - /* 4 */ ".d......d." - /* 5 */ ".dddddddd." + /* 1 */ ".aaaaaaaa." + /* 2 */ ".ak.k...a." + /* 3 */ ".a......a." + /* 4 */ ".a......a." + /* 5 */ ".aaaaaaaa." /* 6 */ ".........." - // Level 4 + // Level 5 /* z\x* */ /* * 0123456789 */ /* 0 */ "lnnnnnnnnn" - /* 1 */ "lddddddddo" - /* 2 */ "lddddddddo" - /* 3 */ "lddddddddo" - /* 4 */ "lddddddddo" - /* 5 */ "lddddddddo" + /* 1 */ "laaaaaaaao" + /* 2 */ "laaaaaaaao" + /* 3 */ "laaaaaaaao" + /* 4 */ "laaaaaaaao" + /* 5 */ "laaaaaaaao" /* 6 */ "pppppppppo", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -710,18 +777,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 29, ID 170, created by Aloe_vera { // Size: - 10, 5, 9, // SizeX = 10, SizeY = 5, SizeZ = 9 + 10, 6, 9, // SizeX = 10, SizeY = 6, SizeZ = 9 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 9, 4, 8, // MaxX, MaxY, MaxZ + 9, 5, 8, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 0\n" /* sandstonestairs */ - "b:128: 2\n" /* sandstonestairs */ - "c:128: 1\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e: 64: 7\n" /* wooddoorblock */ "f:171: 0\n" /* carpet */ "g:171:14\n" /* carpet */ @@ -741,33 +808,46 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Level 0 /* z\x* */ /* * 0123456789 */ - /* 0 */ "..abc....." - /* 1 */ ".dddddddd." - /* 2 */ ".dddddddd." - /* 3 */ ".dddddddd." - /* 4 */ ".dddddddd." - /* 5 */ ".dddddddd." - /* 6 */ ".dddddddd." - /* 7 */ ".dddddddd." - /* 8 */ ".........." + /* 0 */ "mmaaammmmm" + /* 1 */ "maaaaaaaam" + /* 2 */ "maaaaaaaam" + /* 3 */ "maaaaaaaam" + /* 4 */ "maaaaaaaam" + /* 5 */ "maaaaaaaam" + /* 6 */ "maaaaaaaam" + /* 7 */ "maaaaaaaam" + /* 8 */ "mmmmmmmmmm" // Level 1 /* z\x* */ /* * 0123456789 */ - /* 0 */ ".........." - /* 1 */ ".ddeddddd." - /* 2 */ ".dfghhgfd." - /* 3 */ ".dfhffhfd." - /* 4 */ ".dfhgghfd." - /* 5 */ ".dfhffhfd." - /* 6 */ ".dfghhgfd." - /* 7 */ ".dddddddd." + /* 0 */ "..bcd....." + /* 1 */ ".aaaaaaaa." + /* 2 */ ".aaaaaaaa." + /* 3 */ ".aaaaaaaa." + /* 4 */ ".aaaaaaaa." + /* 5 */ ".aaaaaaaa." + /* 6 */ ".aaaaaaaa." + /* 7 */ ".aaaaaaaa." /* 8 */ ".........." // Level 2 /* z\x* */ /* * 0123456789 */ /* 0 */ ".........." + /* 1 */ ".aaeaaaaa." + /* 2 */ ".afghhgfa." + /* 3 */ ".afhffhfa." + /* 4 */ ".afhgghfa." + /* 5 */ ".afhffhfa." + /* 6 */ ".afghhgfa." + /* 7 */ ".aaaaaaaa." + /* 8 */ ".........." + + // Level 3 + /* z\x* */ + /* * 0123456789 */ + /* 0 */ ".........." /* 1 */ ".iijii.ii." /* 2 */ ".i......i." /* 3 */ ".i......i." @@ -777,34 +857,34 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = /* 7 */ ".ii.ii.ii." /* 8 */ ".........." - // Level 3 + // Level 4 /* z\x* */ /* * 0123456789 */ /* 0 */ ".........." - /* 1 */ ".dddddddd." - /* 2 */ ".d..k...d." - /* 3 */ ".d......d." - /* 4 */ ".dl....nd." - /* 5 */ ".d......d." - /* 6 */ ".d......d." - /* 7 */ ".dddddddd." + /* 1 */ ".aaaaaaaa." + /* 2 */ ".a..k...a." + /* 3 */ ".a......a." + /* 4 */ ".al....na." + /* 5 */ ".a......a." + /* 6 */ ".a......a." + /* 7 */ ".aaaaaaaa." /* 8 */ ".........." - // Level 4 + // Level 5 /* z\x* */ /* * 0123456789 */ /* 0 */ "oppppppppp" - /* 1 */ "oddddddddq" - /* 2 */ "oddddddddq" - /* 3 */ "oddddddddq" - /* 4 */ "oddddddddq" - /* 5 */ "oddddddddq" - /* 6 */ "oddddddddq" - /* 7 */ "oddddddddq" + /* 1 */ "oaaaaaaaaq" + /* 2 */ "oaaaaaaaaq" + /* 3 */ "oaaaaaaaaq" + /* 4 */ "oaaaaaaaaq" + /* 5 */ "oaaaaaaaaq" + /* 6 */ "oaaaaaaaaq" + /* 7 */ "oaaaaaaaaq" /* 8 */ "rrrrrrrrrq", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -835,18 +915,18 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // The data has been exported from the gallery Desert, area index 30, ID 171, created by Aloe_vera { // Size: - 11, 5, 9, // SizeX = 11, SizeY = 5, SizeZ = 9 + 11, 6, 9, // SizeX = 11, SizeY = 6, SizeZ = 9 // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 10, 4, 8, // MaxX, MaxY, MaxZ + 10, 5, 8, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ - "a:128: 0\n" /* sandstonestairs */ - "b:128: 2\n" /* sandstonestairs */ - "c:128: 1\n" /* sandstonestairs */ - "d: 24: 0\n" /* sandstone */ + "a: 24: 0\n" /* sandstone */ + "b:128: 0\n" /* sandstonestairs */ + "c:128: 2\n" /* sandstonestairs */ + "d:128: 1\n" /* sandstonestairs */ "e: 64: 7\n" /* wooddoorblock */ "f:171: 0\n" /* carpet */ "g:171:15\n" /* carpet */ @@ -867,33 +947,46 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = // Level 0 /* z\x* 1 */ /* * 01234567890 */ - /* 0 */ "..abc......" - /* 1 */ ".ddddddddd." - /* 2 */ ".ddddddddd." - /* 3 */ ".ddddddddd." - /* 4 */ ".ddddddddd." - /* 5 */ ".ddddddddd." - /* 6 */ ".ddddddddd." - /* 7 */ ".ddddddddd." - /* 8 */ "..........." + /* 0 */ "mmaaammmmmm" + /* 1 */ "maaaaaaaaam" + /* 2 */ "maaaaaaaaam" + /* 3 */ "maaaaaaaaam" + /* 4 */ "maaaaaaaaam" + /* 5 */ "maaaaaaaaam" + /* 6 */ "maaaaaaaaam" + /* 7 */ "maaaaaaaaam" + /* 8 */ "mmmmmmmmmmm" // Level 1 /* z\x* 1 */ /* * 01234567890 */ - /* 0 */ "..........." - /* 1 */ ".ddedddddd." - /* 2 */ ".dffgggffd." - /* 3 */ ".dfghhhgfd." - /* 4 */ ".dfghfhgfd." - /* 5 */ ".dfghhhgfd." - /* 6 */ ".dffgggffd." - /* 7 */ ".ddddddddd." + /* 0 */ "..bcd......" + /* 1 */ ".aaaaaaaaa." + /* 2 */ ".aaaaaaaaa." + /* 3 */ ".aaaaaaaaa." + /* 4 */ ".aaaaaaaaa." + /* 5 */ ".aaaaaaaaa." + /* 6 */ ".aaaaaaaaa." + /* 7 */ ".aaaaaaaaa." /* 8 */ "..........." // Level 2 /* z\x* 1 */ /* * 01234567890 */ /* 0 */ "..........." + /* 1 */ ".aaeaaaaaa." + /* 2 */ ".affgggffa." + /* 3 */ ".afghhhgfa." + /* 4 */ ".afghfhgfa." + /* 5 */ ".afghhhgfa." + /* 6 */ ".affgggffa." + /* 7 */ ".aaaaaaaaa." + /* 8 */ "..........." + + // Level 3 + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "..........." /* 1 */ ".iijii.iii." /* 2 */ ".i.......i." /* 3 */ ".i.......i." @@ -903,34 +996,34 @@ const cPrefab::sDef g_SandFlatRoofVillagePrefabs[] = /* 7 */ ".ii.iii.ii." /* 8 */ "..........." - // Level 3 + // Level 4 /* z\x* 1 */ /* * 01234567890 */ /* 0 */ "..........." - /* 1 */ ".ddddddddd." - /* 2 */ ".d..k....d." - /* 3 */ ".d.......d." - /* 4 */ ".dl.....nd." - /* 5 */ ".d.......d." - /* 6 */ ".d...o...d." - /* 7 */ ".ddddddddd." + /* 1 */ ".aaaaaaaaa." + /* 2 */ ".a..k....a." + /* 3 */ ".a.......a." + /* 4 */ ".al.....na." + /* 5 */ ".a.......a." + /* 6 */ ".a...o...a." + /* 7 */ ".aaaaaaaaa." /* 8 */ "..........." - // Level 4 + // Level 5 /* z\x* 1 */ /* * 01234567890 */ /* 0 */ "pqqqqqqqqqq" - /* 1 */ "pdddddddddr" - /* 2 */ "pdddddddddr" - /* 3 */ "pdddddddddr" - /* 4 */ "pdddddddddr" - /* 5 */ "pdddddddddr" - /* 6 */ "pdddddddddr" - /* 7 */ "pdddddddddr" + /* 1 */ "paaaaaaaaar" + /* 2 */ "paaaaaaaaar" + /* 3 */ "paaaaaaaaar" + /* 4 */ "paaaaaaaaar" + /* 5 */ "paaaaaaaaar" + /* 6 */ "paaaaaaaaar" + /* 7 */ "paaaaaaaaar" /* 8 */ "ssssssssssr", // Connectors: - "-1: 3, 0, 0: 2\n" /* Type -1, direction Z- */, + "-1: 3, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ -- cgit v1.2.3 From 6b503b45a06429513cca2bf69d2835853b906337 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 16 Jun 2014 14:53:33 +0200 Subject: Fixed a copypasta error in WormNestCaves generator settings. --- src/Generating/ComposableGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index f332b4d78..22941dcbe 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -449,7 +449,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64); int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96); - int MaxOffset = a_IniFile.GetValueSetI("Generator", "NetherFortMaxOffset", 32); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "WormNestMaxOffset", 32); m_FinishGens.push_back(new cStructGenWormNestCaves(Seed, Size, Grid, MaxOffset)); } else -- cgit v1.2.3 From 1e57161ecc09ca9aa009b5c4795113aae95d89ea Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 16 Jun 2014 14:12:10 +0100 Subject: Added override --- src/ChunkMap.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index fd319fbc9..5aad0dd2a 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -406,15 +406,15 @@ private: class cStarvationCallbacks : public cAllocationPool::cStarvationCallbacks { - virtual void OnStartUsingReserve() + virtual void OnStartUsingReserve() override { LOG("Using backup memory buffer"); } - virtual void OnEndUsingReserve() + virtual void OnEndUsingReserve() override { LOG("Stoped using backup memory buffer"); } - virtual void OnOutOfReserve() + virtual void OnOutOfReserve() override { LOG("Out of Memory"); } -- cgit v1.2.3