From 14d2085e35bbc3e5c73c018e5c70e8093003820f Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sat, 21 Dec 2013 14:43:32 +0000 Subject: basic threadsafe queue interface --- src/OSSupport/Queue.h | 30 ++++++++++++++++++++++++++++++ src/OSSupport/Queue.inc | 4 ++++ 2 files changed, 34 insertions(+) create mode 100644 src/OSSupport/Queue.h create mode 100644 src/OSSupport/Queue.inc (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h new file mode 100644 index 000000000..838a101e0 --- /dev/null +++ b/src/OSSupport/Queue.h @@ -0,0 +1,30 @@ +#pragma once + +template +class cDeleter +{ + public: + static void Delete(T) {}; +} + +template +class cQueue +{ +public: + cQueue(int warnsize); + cQueue(cQueue& queue); + ~cQueue(); + + void EnqueueItem(T item); + bool TryDequeueItem(T& item); + T DequeueItem(); + void BlockTillEmpty(cEvent CancelationEvent); + void Clear(); + int Size(); + +private: + int warnsize; +} + +//template classes must be implemented in the header +#include "Queue.inc" diff --git a/src/OSSupport/Queue.inc b/src/OSSupport/Queue.inc new file mode 100644 index 000000000..f172e9794 --- /dev/null +++ b/src/OSSupport/Queue.inc @@ -0,0 +1,4 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + + -- cgit v1.2.3 From 38f808ac3d09cbb5bf437243f4b050e196fa582c Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sat, 21 Dec 2013 15:00:31 +0000 Subject: ChunkSender is now warnings clean --- src/BlockEntities/BlockEntity.h | 2 +- src/ChunkDef.h | 2 +- src/ChunkSender.cpp | 2 +- src/Entities/Entity.h | 8 ++++---- src/Entities/ProjectileEntity.h | 2 +- src/Simulator/Simulator.h | 3 ++- 6 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 0d358b556..4a2939b32 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -87,7 +87,7 @@ public: virtual void SendTo(cClientHandle & a_Client) = 0; /// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. - virtual bool Tick(float a_Dt, cChunk & a_Chunk) { return false; } + virtual bool Tick(float /*a_Dt*/, cChunk & /*a_Chunk*/) { return false; } protected: /// Position in absolute block coordinates diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 8c37e7907..c6f6c50b3 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -180,7 +180,7 @@ public: /// Converts absolute block coords into relative (chunk + block) coords: - inline static void AbsoluteToRelative(/* in-out */ int & a_X, int & a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) + inline static void AbsoluteToRelative(/* in-out */ int & a_X, int& /* a_Y */, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) { BlockToChunk(a_X, a_Z, a_ChunkX, a_ChunkZ); diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index fe3ee9b42..2425adf18 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -264,7 +264,7 @@ void cChunkSender::BlockEntity(cBlockEntity * a_Entity) -void cChunkSender::Entity(cEntity * a_Entity) +void cChunkSender::Entity(cEntity *) { // Nothing needed yet, perhaps in the future when we save entities into chunks we'd like to send them upon load, too ;) } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 9cb36eb14..0d7634f73 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -351,10 +351,10 @@ public: // tolua_end /// Called when the specified player right-clicks this entity - virtual void OnRightClicked(cPlayer & a_Player) {}; + virtual void OnRightClicked(cPlayer &) {}; /// Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of looting etc.). Called from KilledBy(). - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) {} + virtual void GetDrops(cItems & /*a_Drops*/, cEntity * /*a_Killer*/ = NULL) {} protected: static cCriticalSection m_CSCount; @@ -420,11 +420,11 @@ protected: void Dereference( cEntity*& a_EntityPtr ); private: - // Measured in degrees (MAX 360°) + // Measured in degrees (MAX 360°) double m_HeadYaw; // Measured in meter/second (m/s) Vector3d m_Speed; - // Measured in degrees (MAX 360°) + // Measured in degrees (MAX 360°) Vector3d m_Rot; /// Position of the entity's XZ center and Y bottom diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 959e81ae5..e9e377fe0 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -52,7 +52,7 @@ public: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace); /// Called by the physics blocktracer when the entity hits another entity - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) {} + virtual void OnHitEntity(cEntity & /*a_EntityHit*/, const Vector3d & /*a_HitPos*/) {} /// Called by Chunk when the projectile is eligible for player collection virtual void CollectedBy(cPlayer * a_Dest); diff --git a/src/Simulator/Simulator.h b/src/Simulator/Simulator.h index 5cd0e8657..3a6252024 100644 --- a/src/Simulator/Simulator.h +++ b/src/Simulator/Simulator.h @@ -25,7 +25,8 @@ public: virtual void Simulate(float a_Dt) = 0; /// Called in each tick for each chunk, a_Dt is the time passed since the last tick, in msec; direct access to chunk data available - virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) {}; + virtual void SimulateChunk(float /*a_Dt*/, int /*a_ChunkX*/, + int /*a_ChunkZ*/, cChunk * /*a_Chunk*/) {}; /// Called when a block changes virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk); -- cgit v1.2.3 From 5034ae29b889b37c10524678e4b92d8ca700bde7 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sat, 21 Dec 2013 15:08:01 +0000 Subject: Piston is now warnings clean --- src/Blocks/BlockHandler.h | 2 +- src/Piston.cpp | 2 +- src/Simulator/FireSimulator.h | 2 +- src/Simulator/RedstoneSimulator.h | 4 ++-- src/Simulator/SandSimulator.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 107d36476..1dc0e2a2a 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -99,7 +99,7 @@ public: virtual bool DoesIgnoreBuildCollision(void); /// Similar to DoesIgnoreBuildCollision(void), but is used for cases where block meta/player item-in-hand is needed to determine collision (thin snow) - virtual bool DoesIgnoreBuildCollision(cPlayer * a_Player, NIBBLETYPE a_Meta) { return DoesIgnoreBuildCollision(); } + virtual bool DoesIgnoreBuildCollision(cPlayer *, NIBBLETYPE /*a_Meta*/) { return DoesIgnoreBuildCollision(); } /// Returns if this block drops if it gets destroyed by an unsuitable situation. Default: true virtual bool DoesDropOnUnsuitable(void); diff --git a/src/Piston.cpp b/src/Piston.cpp index b15e7d95e..17729a352 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -236,7 +236,7 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) -bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE /*a_BlockMeta*/) { return g_BlockPistonBreakable[a_BlockType]; } diff --git a/src/Simulator/FireSimulator.h b/src/Simulator/FireSimulator.h index 66c31b440..f509c66e2 100644 --- a/src/Simulator/FireSimulator.h +++ b/src/Simulator/FireSimulator.h @@ -22,7 +22,7 @@ public: cFireSimulator(cWorld & a_World, cIniFile & a_IniFile); ~cFireSimulator(); - virtual void Simulate(float a_Dt) override {} // not used + virtual void Simulate(float /*a_Dt*/) override {} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override; diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index 309135497..903ac8775 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -19,7 +19,7 @@ public: cRedstoneSimulator(cWorld & a_World); ~cRedstoneSimulator(); - virtual void Simulate(float a_Dt) override {}; // Not used in this simulator + virtual void Simulate(float /*a_Dt*/) override {}; // Not used in this simulator virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return IsRedstone(a_BlockType); } @@ -269,4 +269,4 @@ private: default: return false; } } -}; \ No newline at end of file +}; diff --git a/src/Simulator/SandSimulator.h b/src/Simulator/SandSimulator.h index 6e9ea15ac..90447c915 100644 --- a/src/Simulator/SandSimulator.h +++ b/src/Simulator/SandSimulator.h @@ -15,7 +15,7 @@ public: cSandSimulator(cWorld & a_World, cIniFile & a_IniFile); // cSimulator overrides: - virtual void Simulate(float a_Dt) override {} // Unused in this simulator + virtual void Simulate(float /*a_Dt*/) override {} // Unused in this simulator virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override; -- cgit v1.2.3 From 9f41761e8ea1eff8980af4dceb7137471538298b Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sat, 21 Dec 2013 15:38:37 +0000 Subject: Root is now warnings clean --- src/Bindings/LuaState.h | 40 ++++++++++++++++++++-------------------- src/Bindings/PluginManager.h | 2 +- src/CommandOutput.h | 2 +- src/Entities/Player.h | 4 ++-- src/Items/ItemHandler.h | 2 +- src/Root.cpp | 2 +- src/Server.h | 2 ++ src/WebAdmin.h | 8 ++++---- 8 files changed, 32 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 15b0cdeff..cca0df049 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -244,7 +244,7 @@ public: template< typename FnT, typename ArgT1, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -264,7 +264,7 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -285,7 +285,7 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -307,7 +307,7 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -330,7 +330,7 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -355,7 +355,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -381,7 +381,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -408,7 +408,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -436,7 +436,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -465,7 +465,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename ArgT10, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & a_Mark, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & /*a_Mark*/, RetT1 & a_Ret1) { if (!PushFunction(a_FnName)) { @@ -494,7 +494,7 @@ public: template< typename FnT, typename ArgT1, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) { if (!PushFunction(a_FnName)) { @@ -515,7 +515,7 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) { if (!PushFunction(a_FnName)) { @@ -538,7 +538,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) { if (!PushFunction(a_FnName)) { @@ -562,7 +562,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) { if (!PushFunction(a_FnName)) { @@ -587,7 +587,7 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) { if (!PushFunction(a_FnName)) { @@ -614,7 +614,7 @@ public: typename ArgT6, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) { if (!PushFunction(a_FnName)) { @@ -642,7 +642,7 @@ public: typename ArgT6, typename ArgT7, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) { if (!PushFunction(a_FnName)) { @@ -671,7 +671,7 @@ public: typename ArgT6, typename ArgT7, typename RetT1, typename RetT2, typename RetT3 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) { if (!PushFunction(a_FnName)) { @@ -701,7 +701,7 @@ public: typename ArgT6, typename ArgT7, typename ArgT8, typename RetT1, typename RetT2, typename RetT3 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) { if (!PushFunction(a_FnName)) { @@ -732,7 +732,7 @@ public: typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1, typename RetT2, typename RetT3, typename RetT4, typename RetT5 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5) { if (!PushFunction(a_FnName)) { diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 04d6470c7..e5edd70e0 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -271,7 +271,7 @@ private: bool m_bReloadPlugins; cPluginManager(); - ~cPluginManager(); + virtual ~cPluginManager(); /// Reloads all plugins, defaulting to settings.ini for settings location void ReloadPluginsNow(void); diff --git a/src/CommandOutput.h b/src/CommandOutput.h index bdf675238..80339b405 100644 --- a/src/CommandOutput.h +++ b/src/CommandOutput.h @@ -35,7 +35,7 @@ class cNullCommandOutputCallback : public cCommandOutputCallback { // cCommandOutputCallback overrides: - virtual void Out(const AString & a_Text) override + virtual void Out(const AString & /*a_Text*/) override { // Do nothing } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index c0ad9eeac..241eb3050 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -45,7 +45,7 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override { }; + virtual void HandlePhysics(float /*a_Dt*/, cChunk &) override { }; /// Returns the curently equipped weapon; empty item if none virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } @@ -114,7 +114,7 @@ public: double GetEyeHeight(void) const; // tolua_export Vector3d GetEyePosition(void) const; // tolua_export inline bool IsOnGround(void) const {return m_bTouchGround; } // tolua_export - inline const double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. + inline double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export inline const cInventory & GetInventory(void) const { return m_Inventory; } diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index e39bb054b..cee3fb73b 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -25,7 +25,7 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); /// Called when the client sends the SHOOT status in the lclk packet - virtual void OnItemShoot(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) {} + virtual void OnItemShoot(cPlayer *, int /*a_BlockX*/, int /*a_BlockY*/, int /*a_BlockZ*/, char /*a_BlockFace*/) {} /// Called while the player diggs a block using this item virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace); diff --git a/src/Root.cpp b/src/Root.cpp index fffd8fb47..6b1785abb 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -580,10 +580,10 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac public: cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback) : - m_Callback(a_Callback), m_BestRating(0), m_NameLength(a_PlayerName.length()), m_PlayerName(a_PlayerName), + m_Callback(a_Callback), m_BestMatch(NULL), m_NumMatches(0) {} diff --git a/src/Server.h b/src/Server.h index 0d93469a5..1f94bb3da 100644 --- a/src/Server.h +++ b/src/Server.h @@ -35,6 +35,8 @@ class cServer // tolua_export : public cListenThread::cCallback { // tolua_export public: // tolua_export + + virtual ~cServer() {} bool InitServer(cIniFile & a_SettingsIni); // tolua_begin diff --git a/src/WebAdmin.h b/src/WebAdmin.h index c629d44ff..0f61d7e38 100644 --- a/src/WebAdmin.h +++ b/src/WebAdmin.h @@ -105,7 +105,7 @@ public: cWebAdmin(void); - ~cWebAdmin(); + virtual ~cWebAdmin(); /// Initializes the object. Returns true if successfully initialized and ready to start bool Init(void); @@ -166,9 +166,9 @@ protected: virtual void OnBody(const char * a_Data, int a_Size) override; // cHTTPFormParser::cCallbacks overrides. Files are ignored: - virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) override {} - virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, int a_Size) override {} - virtual void OnFileEnd(cHTTPFormParser & a_Parser) override {} + virtual void OnFileStart(cHTTPFormParser &, const AString & /*a_FileName*/) override {} + virtual void OnFileData(cHTTPFormParser &, const char * /*a_Data*/, int /*a_Size*/) override {} + virtual void OnFileEnd(cHTTPFormParser &) override {} } ; -- cgit v1.2.3 From 3289abde739cdca666763ee762424257e8db2ef5 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sat, 21 Dec 2013 15:49:59 +0000 Subject: fixed hidden bug with furnaces ignoring time burnt this patch fixes an issue with furnaces where they would ignore the time burnt in setBurnTimes this did not cause a problem as this function was only called with the same value as the one it was using for time burnt --- src/BlockEntities/FurnaceEntity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index 8b695d61a..b08187300 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -95,7 +95,7 @@ public: // tolua_end - void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned) {m_FuelBurnTime = a_FuelBurnTime; m_TimeBurned = 0; } + void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned) {m_FuelBurnTime = a_FuelBurnTime; m_TimeBurned = a_TimeBurned; } void SetCookTimes(int a_NeedCookTime, int a_TimeCooked) {m_NeedCookTime = a_NeedCookTime; m_TimeCooked = a_TimeCooked; } protected: -- cgit v1.2.3 From b3046a09e5dfaa8e675c6309dc77ea517616f101 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sat, 21 Dec 2013 15:58:21 +0000 Subject: Chunk is now warnings clean --- src/BlockEntities/BlockEntityWithItems.h | 2 +- src/BlockEntities/JukeboxEntity.h | 2 +- src/BlockEntities/NoteEntity.h | 2 +- src/Chunk.cpp | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h index f35412e03..f2c51fd9e 100644 --- a/src/BlockEntities/BlockEntityWithItems.h +++ b/src/BlockEntities/BlockEntityWithItems.h @@ -71,7 +71,7 @@ protected: cItemGrid m_Contents; // cItemGrid::cListener overrides: - virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) + virtual void OnSlotChanged(cItemGrid * a_Grid, int /*a_SlotNum*/) { ASSERT(a_Grid == &m_Contents); if (m_World != NULL) diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index fcafdc479..996de965b 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -45,7 +45,7 @@ public: // tolua_end virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle & a_Client) override { }; + virtual void SendTo(cClientHandle &) override { }; private: int m_Record; diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index e2d088f44..cf78aeac6 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -52,7 +52,7 @@ public: // tolua_end virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle & a_Client) override { }; + virtual void SendTo(cClientHandle &) override { }; private: char m_Pitch; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 3c44b91d0..adeec37f5 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -527,9 +527,9 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner) // MG TODO : check that "Level" really means Y - NIBBLETYPE SkyLight = 0; + /*NIBBLETYPE SkyLight = 0; - NIBBLETYPE BlockLight = 0; + NIBBLETYPE BlockLight = 0;*/ if (IsLightValid()) { @@ -2323,7 +2323,6 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { - int Idx = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); a_BlockType = cChunkDef::GetBlock (m_BlockTypes, a_RelX, a_RelY, a_RelZ); a_BlockMeta = cChunkDef::GetNibble(m_BlockMeta, a_RelX, a_RelY, a_RelZ); } -- cgit v1.2.3 From d7242414070aa823f879f225b0cf734f4a880759 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 13:46:55 +0000 Subject: converted commneted paramater names to the unused macro --- src/Bindings/LuaState.h | 61 +++++++++++++++++++++----------- src/BlockEntities/BlockEntity.h | 7 +++- src/BlockEntities/BlockEntityWithItems.h | 3 +- src/Blocks/BlockHandler.h | 6 +++- src/ChunkDef.h | 3 +- src/CommandOutput.h | 3 +- src/Entities/Entity.h | 10 ++++-- src/Entities/Player.h | 2 +- src/Entities/ProjectileEntity.h | 6 +++- src/Items/ItemHandler.h | 8 ++++- src/Piston.cpp | 3 +- src/Simulator/FireSimulator.h | 2 +- src/Simulator/RedstoneSimulator.h | 2 +- src/Simulator/SandSimulator.h | 2 +- src/Simulator/Simulator.h | 10 ++++-- src/WebAdmin.h | 11 ++++-- 16 files changed, 100 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 475dec42a..a6c31b6d3 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -246,6 +246,7 @@ public: > bool Call(FnT a_FnName, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -263,8 +264,9 @@ public: template< typename FnT, typename ArgT1, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -283,8 +285,9 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -304,8 +307,9 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -326,8 +330,9 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -349,8 +354,9 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -374,8 +380,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -400,8 +407,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -427,8 +435,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -455,8 +464,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -484,8 +494,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename ArgT10, typename RetT1 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & /*a_Mark*/, RetT1 & a_Ret1) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -513,8 +524,9 @@ public: template< typename FnT, typename ArgT1, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -534,8 +546,9 @@ public: template< typename FnT, typename ArgT1, typename ArgT2, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -557,8 +570,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -581,8 +595,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -606,8 +621,9 @@ public: typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -633,8 +649,9 @@ public: typename ArgT6, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -661,8 +678,9 @@ public: typename ArgT6, typename ArgT7, typename RetT1, typename RetT2 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -690,8 +708,9 @@ public: typename ArgT6, typename ArgT7, typename RetT1, typename RetT2, typename RetT3 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -720,8 +739,9 @@ public: typename ArgT6, typename ArgT7, typename ArgT8, typename RetT1, typename RetT2, typename RetT3 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -751,8 +771,9 @@ public: typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1, typename RetT2, typename RetT3, typename RetT4, typename RetT5 > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & /*a_Mark*/, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5) + bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 4a2939b32..c3b8d41c0 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -87,7 +87,12 @@ public: virtual void SendTo(cClientHandle & a_Client) = 0; /// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. - virtual bool Tick(float /*a_Dt*/, cChunk & /*a_Chunk*/) { return false; } + virtual bool Tick(float a_Dt, cChunk & a_Chunk) + { + UNUSED(a_Dt); + UNUSED(a_Chunk); + return false; + } protected: /// Position in absolute block coordinates diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h index f2c51fd9e..bf6289a2f 100644 --- a/src/BlockEntities/BlockEntityWithItems.h +++ b/src/BlockEntities/BlockEntityWithItems.h @@ -71,8 +71,9 @@ protected: cItemGrid m_Contents; // cItemGrid::cListener overrides: - virtual void OnSlotChanged(cItemGrid * a_Grid, int /*a_SlotNum*/) + virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) { + UNUSED(a_SlotNum); ASSERT(a_Grid == &m_Contents); if (m_World != NULL) { diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 1dc0e2a2a..a732aa797 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -99,7 +99,11 @@ public: virtual bool DoesIgnoreBuildCollision(void); /// Similar to DoesIgnoreBuildCollision(void), but is used for cases where block meta/player item-in-hand is needed to determine collision (thin snow) - virtual bool DoesIgnoreBuildCollision(cPlayer *, NIBBLETYPE /*a_Meta*/) { return DoesIgnoreBuildCollision(); } + virtual bool DoesIgnoreBuildCollision(cPlayer *, NIBBLETYPE a_Meta) + { + UNUSED(a_Meta); + return DoesIgnoreBuildCollision(); + } /// Returns if this block drops if it gets destroyed by an unsuitable situation. Default: true virtual bool DoesDropOnUnsuitable(void); diff --git a/src/ChunkDef.h b/src/ChunkDef.h index c6f6c50b3..bf41aa625 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -180,8 +180,9 @@ public: /// Converts absolute block coords into relative (chunk + block) coords: - inline static void AbsoluteToRelative(/* in-out */ int & a_X, int& /* a_Y */, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) + inline static void AbsoluteToRelative(/* in-out */ int & a_X, int& a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) { + UNUSED(a_Y); BlockToChunk(a_X, a_Z, a_ChunkX, a_ChunkZ); a_X = a_X - a_ChunkX * Width; diff --git a/src/CommandOutput.h b/src/CommandOutput.h index 80339b405..3763d625f 100644 --- a/src/CommandOutput.h +++ b/src/CommandOutput.h @@ -35,9 +35,10 @@ class cNullCommandOutputCallback : public cCommandOutputCallback { // cCommandOutputCallback overrides: - virtual void Out(const AString & /*a_Text*/) override + virtual void Out(const AString & a_Text) override { // Do nothing + UNUSED(a_Text); } } ; diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 0d7634f73..3634f087c 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -354,7 +354,11 @@ public: virtual void OnRightClicked(cPlayer &) {}; /// Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of looting etc.). Called from KilledBy(). - virtual void GetDrops(cItems & /*a_Drops*/, cEntity * /*a_Killer*/ = NULL) {} + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) + { + UNUSED(a_Drops); + UNUSED(a_Killer); + } protected: static cCriticalSection m_CSCount; @@ -420,11 +424,11 @@ protected: void Dereference( cEntity*& a_EntityPtr ); private: - // Measured in degrees (MAX 360°) + // Measured in degrees (MAX 360 degrees) double m_HeadYaw; // Measured in meter/second (m/s) Vector3d m_Speed; - // Measured in degrees (MAX 360°) + // Measured in degrees (MAX 360 degrees) Vector3d m_Rot; /// Position of the entity's XZ center and Y bottom diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 0a3f50d19..f9ce950ba 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -45,7 +45,7 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void HandlePhysics(float /*a_Dt*/, cChunk &) override { }; + virtual void HandlePhysics(float a_Dt, cChunk &) override { UNUSED(a_Dt); }; /// Returns the curently equipped weapon; empty item if none virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index e9e377fe0..4721409ee 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -52,7 +52,11 @@ public: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace); /// Called by the physics blocktracer when the entity hits another entity - virtual void OnHitEntity(cEntity & /*a_EntityHit*/, const Vector3d & /*a_HitPos*/) {} + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) + { + UNUSED(a_EntityHit); + UNUSED(a_HitPos); + } /// Called by Chunk when the projectile is eligible for player collection virtual void CollectedBy(cPlayer * a_Dest); diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index cee3fb73b..db0ffc9db 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -25,7 +25,13 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); /// Called when the client sends the SHOOT status in the lclk packet - virtual void OnItemShoot(cPlayer *, int /*a_BlockX*/, int /*a_BlockY*/, int /*a_BlockZ*/, char /*a_BlockFace*/) {} + virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) + { + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_BlockFace); + } /// Called while the player diggs a block using this item virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace); diff --git a/src/Piston.cpp b/src/Piston.cpp index 17729a352..75eeb5e98 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -236,8 +236,9 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) -bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE /*a_BlockMeta*/) +bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { + UNUSED(a_BlockMeta); return g_BlockPistonBreakable[a_BlockType]; } diff --git a/src/Simulator/FireSimulator.h b/src/Simulator/FireSimulator.h index f509c66e2..9ccc3ef4f 100644 --- a/src/Simulator/FireSimulator.h +++ b/src/Simulator/FireSimulator.h @@ -22,7 +22,7 @@ public: cFireSimulator(cWorld & a_World, cIniFile & a_IniFile); ~cFireSimulator(); - virtual void Simulate(float /*a_Dt*/) override {} // not used + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override; diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index cfeb2b1f2..1080c3f81 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -19,7 +19,7 @@ public: cRedstoneSimulator(cWorld & a_World); ~cRedstoneSimulator(); - virtual void Simulate(float /*a_Dt*/) override {}; // Not used in this simulator + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return IsRedstone(a_BlockType); } diff --git a/src/Simulator/SandSimulator.h b/src/Simulator/SandSimulator.h index 90447c915..6e64aa425 100644 --- a/src/Simulator/SandSimulator.h +++ b/src/Simulator/SandSimulator.h @@ -15,7 +15,7 @@ public: cSandSimulator(cWorld & a_World, cIniFile & a_IniFile); // cSimulator overrides: - virtual void Simulate(float /*a_Dt*/) override {} // Unused in this simulator + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override; diff --git a/src/Simulator/Simulator.h b/src/Simulator/Simulator.h index 3a6252024..a25b7f1b6 100644 --- a/src/Simulator/Simulator.h +++ b/src/Simulator/Simulator.h @@ -25,8 +25,14 @@ public: virtual void Simulate(float a_Dt) = 0; /// Called in each tick for each chunk, a_Dt is the time passed since the last tick, in msec; direct access to chunk data available - virtual void SimulateChunk(float /*a_Dt*/, int /*a_ChunkX*/, - int /*a_ChunkZ*/, cChunk * /*a_Chunk*/) {}; + virtual void SimulateChunk(float a_Dt, int a_ChunkX, + int a_ChunkZ, cChunk * a_Chunk) + { + UNUSED(a_Dt); + UNUSED(a_ChunkX); + UNUSED(a_ChunkZ); + UNUSED(a_Chunk); + }; /// Called when a block changes virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk); diff --git a/src/WebAdmin.h b/src/WebAdmin.h index 1a27eabfe..3eb807640 100644 --- a/src/WebAdmin.h +++ b/src/WebAdmin.h @@ -169,8 +169,15 @@ protected: virtual void OnBody(const char * a_Data, int a_Size) override; // cHTTPFormParser::cCallbacks overrides. Files are ignored: - virtual void OnFileStart(cHTTPFormParser &, const AString & /*a_FileName*/) override {} - virtual void OnFileData(cHTTPFormParser &, const char * /*a_Data*/, int /*a_Size*/) override {} + virtual void OnFileStart(cHTTPFormParser &, const AString & a_FileName) override + { + UNUSED(a_FileName); + } + virtual void OnFileData(cHTTPFormParser &, const char * a_Data, int a_Size) override + { + UNUSED(a_Data); + UNUSED(a_Size); + } virtual void OnFileEnd(cHTTPFormParser &) override {} } ; -- cgit v1.2.3 From 725b997a2817bd999079e5e6678f5497373cbbac Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 28 Dec 2013 21:59:50 +0100 Subject: Fixed a (valid) warning in RCONServer. --- src/OSSupport/SocketThreads.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/OSSupport/SocketThreads.h b/src/OSSupport/SocketThreads.h index ecbac3aeb..858729c49 100644 --- a/src/OSSupport/SocketThreads.h +++ b/src/OSSupport/SocketThreads.h @@ -61,6 +61,9 @@ public: class cCallback { public: + // Force a virtual destructor in all subclasses: + virtual ~cCallback() {} + /// Called when data is received from the remote party virtual void DataReceived(const char * a_Data, int a_Size) = 0; -- cgit v1.2.3 From b93b4c4825503e3c03c44091b415cc7186b24455 Mon Sep 17 00:00:00 2001 From: Mike Hunsinger Date: Sat, 28 Dec 2013 23:49:51 -0700 Subject: Added function to create Tall Birch tree in BirchTreeForest biomes --- src/Generating/Trees.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++--- src/Generating/Trees.h | 3 +++ 2 files changed, 49 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index fbed57cb6..7e8a3c75f 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -216,7 +216,14 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No GetBirchTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks); break; } - + + case biBirchForestM: + case biBirchForestHillsM: + { + GetTallBirchTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks); + break; + } + case biRoofedForest: case biColdTaiga: case biColdTaigaHills: @@ -237,8 +244,6 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No case biIcePlainsSpikes: case biJungleM: case biJungleEdgeM: - case biBirchForestM: - case biBirchForestHillsM: case biRoofedForestM: case biColdTaigaM: case biMegaSpruceTaiga: @@ -377,6 +382,44 @@ void GetBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Nois +void GetTallBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +{ + int Height = 9 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3); + + // Prealloc, so that we don't realloc too often later: + a_LogBlocks.reserve(Height); + a_OtherBlocks.reserve(80); + + // The entire trunk, out of logs: + for (int i = Height - 1; i >= 0; --i) + { + a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ, E_BLOCK_LOG, E_META_LOG_BIRCH)); + } + int h = a_BlockY + Height; + + // Top layer - just the Plus: + PushCoordBlocks(a_BlockX, h, a_BlockZ, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + a_OtherBlocks.push_back(sSetBlock(a_BlockX, h, a_BlockZ, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH)); // There's no log at this layer + h--; + + // Second layer - log, Plus and maybe Corners: + PushCoordBlocks (a_BlockX, h, a_BlockZ, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + PushCornerBlocks(a_BlockX, h, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 1, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + h--; + + // Third and fourth layers - BigO2 and maybe 2*Corners: + for (int Row = 0; Row < 2; Row++) + { + PushCoordBlocks (a_BlockX, h, a_BlockZ, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + PushCornerBlocks(a_BlockX, h, a_BlockZ, a_Seq, a_Noise, 0x3fffffff + Row * 0x10000000, a_OtherBlocks, 2, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + h--; + } // for Row - 2* +} + + + + + void GetConiferTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) { // Half chance for a spruce, half for a pine: diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h index f5148ad6f..514158eb7 100644 --- a/src/Generating/Trees.h +++ b/src/Generating/Trees.h @@ -63,6 +63,9 @@ void GetLargeAppleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a /// Generates an image of a random birch tree void GetBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +/// Generates an image of a random large birch tree +void GetTallBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks,sSetBlockVector & a_OtherBlocks); + /// Generates an image of a random conifer tree void GetConiferTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); -- cgit v1.2.3 From 248ba1ea9f6826234535c2a777b3834fbe264e0d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 29 Dec 2013 12:51:58 +0100 Subject: Added HOOK_PLUGINS_LOADED. This fixes #482. --- src/Bindings/LuaState.h | 19 +++++++++++++++++++ src/Bindings/Plugin.h | 1 + src/Bindings/PluginLua.cpp | 18 ++++++++++++++++++ src/Bindings/PluginLua.h | 1 + src/Bindings/PluginManager.cpp | 26 +++++++++++++++++++++++--- src/Bindings/PluginManager.h | 2 ++ 6 files changed, 64 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 15b0cdeff..40bb67e69 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -240,6 +240,25 @@ public: return CallFunction(0); } + /// Call any 0-param 1-return Lua function in a single line: + template< + typename FnT, typename RetT1 + > + bool Call(FnT a_FnName, const cRet & a_Mark, RetT1 & a_Ret1) + { + if (!PushFunction(a_FnName)) + { + return false; + } + if (!CallFunction(1)) + { + return false; + } + GetReturn(-1, a_Ret1); + lua_pop(m_LuaState, 1); + return true; + } + /// Call any 1-param 1-return Lua function in a single line: template< typename FnT, typename ArgT1, typename RetT1 diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 9a3c2383e..ee0f8a062 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -82,6 +82,7 @@ public: virtual bool OnPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0; virtual bool OnPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0; + virtual bool OnPluginsLoaded (void) = 0; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 0e5a66cd6..69e83fb0a 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -910,6 +910,24 @@ bool cPluginLua::OnPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_Block +bool cPluginLua::OnPluginsLoaded(void) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLUGINS_LOADED]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + bool ret = false; + m_LuaState.Call((int)(**itr), cLuaState::Return, ret); + res = res || ret; + } + return res; +} + + + + + bool cPluginLua::OnPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index e1e274c72..1b257285e 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -79,6 +79,7 @@ public: virtual bool OnPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual bool OnPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual bool OnPluginsLoaded (void) override; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 832dc4249..ffffe1a23 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -118,7 +118,7 @@ void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni) int KeyNum = a_SettingsIni.FindKey("Plugins"); // If it does, how many plugins are there? - unsigned int NumPlugins = ((KeyNum != -1) ? (a_SettingsIni.GetNumValues(KeyNum)) : 0); + int NumPlugins = ((KeyNum != -1) ? (a_SettingsIni.GetNumValues(KeyNum)) : 0); if (KeyNum == -1) { @@ -126,7 +126,7 @@ void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni) } else if (NumPlugins > 0) { - for(unsigned int i = 0; i < NumPlugins; i++) + for (int i = 0; i < NumPlugins; i++) { AString ValueName = a_SettingsIni.GetValueName(KeyNum, i); if (ValueName.compare("Plugin") == 0) @@ -136,7 +136,7 @@ void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni) { if (m_Plugins.find(PluginFile) != m_Plugins.end()) { - LoadPlugin( PluginFile ); + LoadPlugin(PluginFile); } } } @@ -155,6 +155,7 @@ void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni) { LOG("-- Loaded 1 Plugin --"); } + CallHookPluginsLoaded(); } @@ -987,6 +988,25 @@ bool cPluginManager::CallHookPlayerUsingItem(cPlayer & a_Player, int a_BlockX, i +bool cPluginManager::CallHookPluginsLoaded(void) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PLUGINS_LOADED); + if (Plugins == m_Hooks.end()) + { + return false; + } + bool res = false; + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + res = !(*itr)->OnPluginsLoaded() || res; + } + return res; +} + + + + + bool cPluginManager::CallHookPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) { HookMap::iterator Plugins = m_Hooks.find(HOOK_POST_CRAFTING); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 04d6470c7..5abb8be84 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -94,6 +94,7 @@ public: // tolua_export HOOK_PLAYER_USED_ITEM, HOOK_PLAYER_USING_BLOCK, HOOK_PLAYER_USING_ITEM, + HOOK_PLUGINS_LOADED, HOOK_POST_CRAFTING, HOOK_PRE_CRAFTING, HOOK_SPAWNED_ENTITY, @@ -181,6 +182,7 @@ public: // tolua_export bool CallHookPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); bool CallHookPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); + bool CallHookPluginsLoaded (void); bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity); -- cgit v1.2.3 From a71299c46b7b53a5f9f11ea2851f8e5b66d2d912 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 15:41:01 +0000 Subject: fixed rdynamic as its not acctually needed a cmake handles it, looks like the problem was caused by the linux linker accepting the option twice and the os x linker not --- src/OSSupport/Queue.h | 31 +++++++++++++++++++++++++++++++ src/WorldStorage/WorldStorage.h | 3 ++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/OSSupport/Queue.h (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h new file mode 100644 index 000000000..4571272b3 --- /dev/null +++ b/src/OSSupport/Queue.h @@ -0,0 +1,31 @@ +#pragma once + +template +class cDeleter +{ + public: + static void Delete(T) {}; +}; + +template> +class cQueue +{ +public: + cQueue(int warnsize); + cQueue(cQueue& queue); + ~cQueue(); + + void EnqueueItem(T item); + bool TryDequeueItem(T& item); + T DequeueItem(); + void BlockTillEmpty(cEvent CancelationEvent); + void Clear(); + int Size(); + +private: + int warnsize; + std::list contents; +}; + +//template classes must be implemented in the header +#include "Queue.inc" diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index 007d37571..106842a22 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,6 +16,7 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" +#include "../OSSupport/Queue.h" @@ -93,7 +94,7 @@ protected: sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {} } ; - typedef std::list sChunkLoadQueue; + typedef cQueue sChunkLoadQueue; cWorld * m_World; AString m_StorageSchemaName; -- cgit v1.2.3 From a7a4b2886d98eb0c015421fb82c60531a8e66aaa Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 15:55:57 +0000 Subject: fixed accedental commit --- src/WorldStorage/WorldStorage.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index 106842a22..007d37571 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,7 +16,6 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" -#include "../OSSupport/Queue.h" @@ -94,7 +93,7 @@ protected: sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {} } ; - typedef cQueue sChunkLoadQueue; + typedef std::list sChunkLoadQueue; cWorld * m_World; AString m_StorageSchemaName; -- cgit v1.2.3 From 15a980a6169ff975628bf1d4ecd16168fe609bf4 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 16:11:34 +0000 Subject: merged in warnings changes --- src/Bindings/LuaState.h | 21 ++++++++++++++++++++ src/Bindings/PluginManager.h | 2 +- src/BlockEntities/BlockEntity.h | 6 +++++- src/BlockEntities/BlockEntityWithItems.h | 1 + src/BlockEntities/FurnaceEntity.h | 2 +- src/BlockEntities/JukeboxEntity.h | 2 +- src/BlockEntities/NoteEntity.h | 2 +- src/Blocks/BlockHandler.h | 6 +++++- src/Chunk.cpp | 15 ++++---------- src/Chunk.h | 23 --------------------- src/Chunk.inl.h | 34 -------------------------------- src/ChunkDef.h | 1 + src/ChunkSender.cpp | 2 +- src/CommandOutput.h | 1 + src/Entities/Entity.h | 14 +++++++++---- src/Entities/Player.h | 4 ++-- src/Entities/ProjectileEntity.h | 6 +++++- src/Items/ItemHandler.h | 8 +++++++- src/Piston.cpp | 1 + src/Root.cpp | 2 +- src/Server.h | 2 ++ src/Simulator/FireSimulator.h | 2 +- src/Simulator/RedstoneSimulator.h | 4 ++-- src/Simulator/SandSimulator.h | 2 +- src/Simulator/Simulator.h | 9 ++++++++- src/WebAdmin.h | 15 ++++++++++---- 26 files changed, 94 insertions(+), 93 deletions(-) delete mode 100644 src/Chunk.inl.h (limited to 'src') diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 40bb67e69..a6c31b6d3 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -246,6 +246,7 @@ public: > bool Call(FnT a_FnName, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -265,6 +266,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -285,6 +287,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -306,6 +309,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -328,6 +332,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -351,6 +356,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -376,6 +382,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -402,6 +409,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -429,6 +437,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -457,6 +466,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -486,6 +496,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & a_Mark, RetT1 & a_Ret1) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -515,6 +526,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -536,6 +548,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -559,6 +572,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -583,6 +597,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -608,6 +623,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -635,6 +651,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -663,6 +680,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -692,6 +710,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -722,6 +741,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; @@ -753,6 +773,7 @@ public: > bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5) { + UNUSED(a_Mark); if (!PushFunction(a_FnName)) { return false; diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 5abb8be84..e94421057 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -273,7 +273,7 @@ private: bool m_bReloadPlugins; cPluginManager(); - ~cPluginManager(); + virtual ~cPluginManager(); /// Reloads all plugins, defaulting to settings.ini for settings location void ReloadPluginsNow(void); diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 0d358b556..7c6688f8d 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -87,7 +87,11 @@ public: virtual void SendTo(cClientHandle & a_Client) = 0; /// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. - virtual bool Tick(float a_Dt, cChunk & a_Chunk) { return false; } + virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) + { + UNUSED(a_Dt); + return false; + } protected: /// Position in absolute block coordinates diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h index f35412e03..bf6289a2f 100644 --- a/src/BlockEntities/BlockEntityWithItems.h +++ b/src/BlockEntities/BlockEntityWithItems.h @@ -73,6 +73,7 @@ protected: // cItemGrid::cListener overrides: virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) { + UNUSED(a_SlotNum); ASSERT(a_Grid == &m_Contents); if (m_World != NULL) { diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index 8b695d61a..b08187300 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -95,7 +95,7 @@ public: // tolua_end - void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned) {m_FuelBurnTime = a_FuelBurnTime; m_TimeBurned = 0; } + void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned) {m_FuelBurnTime = a_FuelBurnTime; m_TimeBurned = a_TimeBurned; } void SetCookTimes(int a_NeedCookTime, int a_TimeCooked) {m_NeedCookTime = a_NeedCookTime; m_TimeCooked = a_TimeCooked; } protected: diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index fcafdc479..996de965b 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -45,7 +45,7 @@ public: // tolua_end virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle & a_Client) override { }; + virtual void SendTo(cClientHandle &) override { }; private: int m_Record; diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index e2d088f44..cf78aeac6 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -52,7 +52,7 @@ public: // tolua_end virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle & a_Client) override { }; + virtual void SendTo(cClientHandle &) override { }; private: char m_Pitch; diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 107d36476..a732aa797 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -99,7 +99,11 @@ public: virtual bool DoesIgnoreBuildCollision(void); /// Similar to DoesIgnoreBuildCollision(void), but is used for cases where block meta/player item-in-hand is needed to determine collision (thin snow) - virtual bool DoesIgnoreBuildCollision(cPlayer * a_Player, NIBBLETYPE a_Meta) { return DoesIgnoreBuildCollision(); } + virtual bool DoesIgnoreBuildCollision(cPlayer *, NIBBLETYPE a_Meta) + { + UNUSED(a_Meta); + return DoesIgnoreBuildCollision(); + } /// Returns if this block drops if it gets destroyed by an unsuitable situation. Default: true virtual bool DoesDropOnUnsuitable(void); diff --git a/src/Chunk.cpp b/src/Chunk.cpp index c446db9a6..b229a4aff 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -527,9 +527,10 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner) // MG TODO : check that "Level" really means Y + /* NIBBLETYPE SkyLight = 0; - NIBBLETYPE BlockLight = 0; + */ if (IsLightValid()) { @@ -2324,8 +2325,8 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { int Idx = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - a_BlockType = cChunkDef::GetBlock (m_BlockTypes, a_RelX, a_RelY, a_RelZ); - a_BlockMeta = cChunkDef::GetNibble(m_BlockMeta, a_RelX, a_RelY, a_RelZ); + a_BlockType = cChunkDef::GetBlock (m_BlockTypes, Idx); + a_BlockMeta = cChunkDef::GetNibble(m_BlockMeta, Idx); } @@ -2897,11 +2898,3 @@ NIBBLETYPE cChunk::GetTimeAlteredLight(NIBBLETYPE a_Skylight) const - -#if !C_CHUNK_USE_INLINE -# include "cChunk.inl.h" -#endif - - - - diff --git a/src/Chunk.h b/src/Chunk.h index 05a96d419..f0a50c3c4 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -12,19 +12,6 @@ -#define C_CHUNK_USE_INLINE 1 - -// Do not touch -#if C_CHUNK_USE_INLINE - #define __C_CHUNK_INLINE__ inline -#else - #define __C_CHUNK_INLINE__ -#endif - - - - - namespace Json { class Value; @@ -436,8 +423,6 @@ private: void RemoveBlockEntity(cBlockEntity * a_BlockEntity); void AddBlockEntity (cBlockEntity * a_BlockEntity); - void SpreadLightOfBlock(NIBBLETYPE * a_LightBuffer, int a_X, int a_Y, int a_Z, char a_Falloff); - /// Creates a block entity for each block that needs a block entity and doesn't have one in the list void CreateBlockEntities(void); @@ -482,11 +467,3 @@ typedef std::list cChunkPtrList; - -#if C_CHUNK_USE_INLINE - #include "Chunk.inl.h" -#endif - - - - diff --git a/src/Chunk.inl.h b/src/Chunk.inl.h deleted file mode 100644 index fb9c4dad1..000000000 --- a/src/Chunk.inl.h +++ /dev/null @@ -1,34 +0,0 @@ - -#ifndef __C_CHUNK_INL_H__ -#define __C_CHUNK_INL_H__ - -#ifndef MAX -# define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - - - - - -__C_CHUNK_INLINE__ -void cChunk::SpreadLightOfBlock(NIBBLETYPE * a_LightBuffer, int a_X, int a_Y, int a_Z, char a_Falloff) -{ - unsigned char CurrentLight = cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y, a_Z ); - cChunkDef::SetNibble( a_LightBuffer, a_X-1, a_Y, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X-1, a_Y, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X+1, a_Y, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X+1, a_Y, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y-1, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y-1, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y+1, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y+1, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y, a_Z-1, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y, a_Z-1 ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y, a_Z+1, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y, a_Z+1 ), MAX(0,CurrentLight-a_Falloff) ) ); - MarkDirty(); -} - - - - - -#endif - - - - diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 8c37e7907..7d727a4d4 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -182,6 +182,7 @@ public: /// Converts absolute block coords into relative (chunk + block) coords: inline static void AbsoluteToRelative(/* in-out */ int & a_X, int & a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) { + UNUSED(a_Y); BlockToChunk(a_X, a_Z, a_ChunkX, a_ChunkZ); a_X = a_X - a_ChunkX * Width; diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index fe3ee9b42..2425adf18 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -264,7 +264,7 @@ void cChunkSender::BlockEntity(cBlockEntity * a_Entity) -void cChunkSender::Entity(cEntity * a_Entity) +void cChunkSender::Entity(cEntity *) { // Nothing needed yet, perhaps in the future when we save entities into chunks we'd like to send them upon load, too ;) } diff --git a/src/CommandOutput.h b/src/CommandOutput.h index bdf675238..3763d625f 100644 --- a/src/CommandOutput.h +++ b/src/CommandOutput.h @@ -38,6 +38,7 @@ class cNullCommandOutputCallback : virtual void Out(const AString & a_Text) override { // Do nothing + UNUSED(a_Text); } } ; diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 9cb36eb14..2ba1b303d 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -351,10 +351,14 @@ public: // tolua_end /// Called when the specified player right-clicks this entity - virtual void OnRightClicked(cPlayer & a_Player) {}; + virtual void OnRightClicked(cPlayer &) {}; /// Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of looting etc.). Called from KilledBy(). - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) {} + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) + { + UNUSED(a_Drops); + UNUSED(a_Killer); + } protected: static cCriticalSection m_CSCount; @@ -420,11 +424,13 @@ protected: void Dereference( cEntity*& a_EntityPtr ); private: - // Measured in degrees (MAX 360°) + // Measured in degrees, [-180, +180) double m_HeadYaw; + // Measured in meter/second (m/s) Vector3d m_Speed; - // Measured in degrees (MAX 360°) + + // Measured in degrees, [-180, +180) Vector3d m_Rot; /// Position of the entity's XZ center and Y bottom diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 66f1c07a7..f9ce950ba 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -45,7 +45,7 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override { }; + virtual void HandlePhysics(float a_Dt, cChunk &) override { UNUSED(a_Dt); }; /// Returns the curently equipped weapon; empty item if none virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } @@ -114,7 +114,7 @@ public: double GetEyeHeight(void) const; // tolua_export Vector3d GetEyePosition(void) const; // tolua_export inline bool IsOnGround(void) const {return m_bTouchGround; } // tolua_export - inline const double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. + inline double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export inline const cInventory & GetInventory(void) const { return m_Inventory; } diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 959e81ae5..4721409ee 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -52,7 +52,11 @@ public: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace); /// Called by the physics blocktracer when the entity hits another entity - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) {} + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) + { + UNUSED(a_EntityHit); + UNUSED(a_HitPos); + } /// Called by Chunk when the projectile is eligible for player collection virtual void CollectedBy(cPlayer * a_Dest); diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index e39bb054b..db0ffc9db 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -25,7 +25,13 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); /// Called when the client sends the SHOOT status in the lclk packet - virtual void OnItemShoot(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) {} + virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) + { + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_BlockFace); + } /// Called while the player diggs a block using this item virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace); diff --git a/src/Piston.cpp b/src/Piston.cpp index b15e7d95e..75eeb5e98 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -238,6 +238,7 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { + UNUSED(a_BlockMeta); return g_BlockPistonBreakable[a_BlockType]; } diff --git a/src/Root.cpp b/src/Root.cpp index 798f965be..16a521698 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -596,10 +596,10 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac public: cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback) : - m_Callback(a_Callback), m_BestRating(0), m_NameLength(a_PlayerName.length()), m_PlayerName(a_PlayerName), + m_Callback(a_Callback), m_BestMatch(NULL), m_NumMatches(0) {} diff --git a/src/Server.h b/src/Server.h index 0d93469a5..1f94bb3da 100644 --- a/src/Server.h +++ b/src/Server.h @@ -35,6 +35,8 @@ class cServer // tolua_export : public cListenThread::cCallback { // tolua_export public: // tolua_export + + virtual ~cServer() {} bool InitServer(cIniFile & a_SettingsIni); // tolua_begin diff --git a/src/Simulator/FireSimulator.h b/src/Simulator/FireSimulator.h index 66c31b440..9ccc3ef4f 100644 --- a/src/Simulator/FireSimulator.h +++ b/src/Simulator/FireSimulator.h @@ -22,7 +22,7 @@ public: cFireSimulator(cWorld & a_World, cIniFile & a_IniFile); ~cFireSimulator(); - virtual void Simulate(float a_Dt) override {} // not used + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override; diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index 60c86a3c5..1080c3f81 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -19,7 +19,7 @@ public: cRedstoneSimulator(cWorld & a_World); ~cRedstoneSimulator(); - virtual void Simulate(float a_Dt) override {}; // Not used in this simulator + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return IsRedstone(a_BlockType); } @@ -271,4 +271,4 @@ private: default: return false; } } -}; \ No newline at end of file +}; diff --git a/src/Simulator/SandSimulator.h b/src/Simulator/SandSimulator.h index 6e9ea15ac..6e64aa425 100644 --- a/src/Simulator/SandSimulator.h +++ b/src/Simulator/SandSimulator.h @@ -15,7 +15,7 @@ public: cSandSimulator(cWorld & a_World, cIniFile & a_IniFile); // cSimulator overrides: - virtual void Simulate(float a_Dt) override {} // Unused in this simulator + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override; virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override; diff --git a/src/Simulator/Simulator.h b/src/Simulator/Simulator.h index 5cd0e8657..a25b7f1b6 100644 --- a/src/Simulator/Simulator.h +++ b/src/Simulator/Simulator.h @@ -25,7 +25,14 @@ public: virtual void Simulate(float a_Dt) = 0; /// Called in each tick for each chunk, a_Dt is the time passed since the last tick, in msec; direct access to chunk data available - virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) {}; + virtual void SimulateChunk(float a_Dt, int a_ChunkX, + int a_ChunkZ, cChunk * a_Chunk) + { + UNUSED(a_Dt); + UNUSED(a_ChunkX); + UNUSED(a_ChunkZ); + UNUSED(a_Chunk); + }; /// Called when a block changes virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk); diff --git a/src/WebAdmin.h b/src/WebAdmin.h index 0907e7bc3..3eb807640 100644 --- a/src/WebAdmin.h +++ b/src/WebAdmin.h @@ -105,7 +105,7 @@ public: cWebAdmin(void); - ~cWebAdmin(); + virtual ~cWebAdmin(); /// Initializes the object. Returns true if successfully initialized and ready to start bool Init(void); @@ -169,9 +169,16 @@ protected: virtual void OnBody(const char * a_Data, int a_Size) override; // cHTTPFormParser::cCallbacks overrides. Files are ignored: - virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) override {} - virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, int a_Size) override {} - virtual void OnFileEnd(cHTTPFormParser & a_Parser) override {} + virtual void OnFileStart(cHTTPFormParser &, const AString & a_FileName) override + { + UNUSED(a_FileName); + } + virtual void OnFileData(cHTTPFormParser &, const char * a_Data, int a_Size) override + { + UNUSED(a_Data); + UNUSED(a_Size); + } + virtual void OnFileEnd(cHTTPFormParser &) override {} } ; -- cgit v1.2.3 From 75abce905d28192ec1ad049945b160f2b64fee4a Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 16:33:40 +0000 Subject: fixed bad merge --- src/Chunk.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 34cb6a534..fb26e983d 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -2900,10 +2900,6 @@ NIBBLETYPE cChunk::GetTimeAlteredLight(NIBBLETYPE a_Skylight) const -#if !C_CHUNK_USE_INLINE -# include "cChunk.inl.h" -#endif - -- cgit v1.2.3 From d0cd9a2b36749b17f6c06998f5a766e498996b8a Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 22:52:21 +0000 Subject: added link dependency between WorldStorage and OSSupport --- src/WorldStorage/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/WorldStorage/CMakeLists.txt b/src/WorldStorage/CMakeLists.txt index d431bdf6a..2c83c4662 100644 --- a/src/WorldStorage/CMakeLists.txt +++ b/src/WorldStorage/CMakeLists.txt @@ -9,3 +9,5 @@ file(GLOB SOURCE ) add_library(WorldStorage ${SOURCE}) + +target_link_libraries(WorldStorage OSSupport) -- cgit v1.2.3 From a1211bcdff8e48a04b40ee60953918bbd97cc739 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 28 Dec 2013 14:42:11 +0100 Subject: Added support for out-of-source builds. --- src/Bindings/CMakeLists.txt | 23 ++++++++++++++--------- src/CMakeLists.txt | 25 ++++++++++++++++--------- 2 files changed, 30 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index 41c641d9d..50b81e42a 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -2,17 +2,22 @@ cmake_minimum_required (VERSION 2.6) project (MCServer) +# NOTE: This CMake file is processed only for Unix builds; Windows(MSVC) builds handle all the subfolders in /src in a single file, /src/CMakeLists.txt + include_directories ("${PROJECT_SOURCE_DIR}/../") - ADD_CUSTOM_COMMAND( -#add any new generated bindings here - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Bindings.cpp ${CMAKE_CURRENT_BINARY_DIR}/Bindings.h -#command execuded to regerate bindings - COMMAND tolua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg -#add any new generation dependencies here - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/virtual_method_hooks.lua ${CMAKE_CURRENT_SOURCE_DIR}/AllToLua.pkg tolua - ) - +ADD_CUSTOM_COMMAND( + # add any new generated bindings here + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/Bindings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Bindings.h + + # command execuded to regerate bindings + COMMAND tolua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + + # add any new generation dependencies here + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/virtual_method_hooks.lua ${CMAKE_CURRENT_SOURCE_DIR}/AllToLua.pkg tolua +) + #add cpp files here add_library(Bindings PluginManager LuaState WebPlugin Bindings ManualBindings LuaWindow Plugin PluginLua WebPlugin) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 88e469b74..bd06798ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities) -if (NOT WIN32) +if (NOT MSVC) foreach(folder ${FOLDERS}) add_subdirectory(${folder}) endforeach(folder) @@ -62,18 +62,25 @@ else () endif() -if (UNIX) - set(EXECUTABLE ../MCServer/MCServer) -else () - set(EXECUTABLE MCServer) -endif () - +set(EXECUTABLE MCServer) add_executable(${EXECUTABLE} ${SOURCE}) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/MCServer) + +if (MSVC) + # MSVC generator adds a "Debug" or "Release" postfixes to the EXECUTABLE_OUTPUT_PATH, we need to cancel them: + SET_TARGET_PROPERTIES(${EXECUTABLE} PROPERTIES PREFIX "../") + SET_TARGET_PROPERTIES(${EXECUTABLE} PROPERTIES IMPORT_PREFIX "../") +endif() + + +# Make the debug executable have a "_debug" suffix +SET_TARGET_PROPERTIES(${EXECUTABLE} PROPERTIES DEBUG_POSTFIX "_debug") + # Precompiled headers (2nd part) -if (WIN32) +if (MSVC) SET_TARGET_PROPERTIES( ${EXECUTABLE} PROPERTIES COMPILE_FLAGS "/Yu\"Globals.h\"" OBJECT_DEPENDS "$(IntDir)/$(TargetName.pch)" @@ -81,7 +88,7 @@ if (WIN32) endif () -if (NOT WIN32) +if (NOT MSVC) target_link_libraries(${EXECUTABLE} OSSupport HTTPServer Bindings Items Blocks) target_link_libraries(${EXECUTABLE} Protocol Generating WorldStorage) target_link_libraries(${EXECUTABLE} Mobs Entities Simulator UI BlockEntities) -- cgit v1.2.3 From ee15d4e08e90536afbb381a6d65a418e0027658d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 30 Dec 2013 17:41:59 +0100 Subject: Fixed compilation in VC2008. Also removed an unused inline header file (yuck). --- src/BlockEntities/BlockEntity.h | 3 +-- src/Chunk.cpp | 20 +++++++------------- src/Chunk.h | 23 ----------------------- src/Chunk.inl.h | 34 ---------------------------------- src/ChunkDef.h | 2 +- src/Entities/Entity.h | 6 ++++-- 6 files changed, 13 insertions(+), 75 deletions(-) delete mode 100644 src/Chunk.inl.h (limited to 'src') diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index c3b8d41c0..7c6688f8d 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -87,10 +87,9 @@ public: virtual void SendTo(cClientHandle & a_Client) = 0; /// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. - virtual bool Tick(float a_Dt, cChunk & a_Chunk) + virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) { UNUSED(a_Dt); - UNUSED(a_Chunk); return false; } diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a16d34f3b..b229a4aff 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -527,9 +527,10 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner) // MG TODO : check that "Level" really means Y - /*NIBBLETYPE SkyLight = 0; - - NIBBLETYPE BlockLight = 0;*/ + /* + NIBBLETYPE SkyLight = 0; + NIBBLETYPE BlockLight = 0; + */ if (IsLightValid()) { @@ -2323,8 +2324,9 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { - a_BlockType = cChunkDef::GetBlock (m_BlockTypes, a_RelX, a_RelY, a_RelZ); - a_BlockMeta = cChunkDef::GetNibble(m_BlockMeta, a_RelX, a_RelY, a_RelZ); + int Idx = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); + a_BlockType = cChunkDef::GetBlock (m_BlockTypes, Idx); + a_BlockMeta = cChunkDef::GetNibble(m_BlockMeta, Idx); } @@ -2896,11 +2898,3 @@ NIBBLETYPE cChunk::GetTimeAlteredLight(NIBBLETYPE a_Skylight) const - -#if !C_CHUNK_USE_INLINE -# include "cChunk.inl.h" -#endif - - - - diff --git a/src/Chunk.h b/src/Chunk.h index 05a96d419..f0a50c3c4 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -12,19 +12,6 @@ -#define C_CHUNK_USE_INLINE 1 - -// Do not touch -#if C_CHUNK_USE_INLINE - #define __C_CHUNK_INLINE__ inline -#else - #define __C_CHUNK_INLINE__ -#endif - - - - - namespace Json { class Value; @@ -436,8 +423,6 @@ private: void RemoveBlockEntity(cBlockEntity * a_BlockEntity); void AddBlockEntity (cBlockEntity * a_BlockEntity); - void SpreadLightOfBlock(NIBBLETYPE * a_LightBuffer, int a_X, int a_Y, int a_Z, char a_Falloff); - /// Creates a block entity for each block that needs a block entity and doesn't have one in the list void CreateBlockEntities(void); @@ -482,11 +467,3 @@ typedef std::list cChunkPtrList; - -#if C_CHUNK_USE_INLINE - #include "Chunk.inl.h" -#endif - - - - diff --git a/src/Chunk.inl.h b/src/Chunk.inl.h deleted file mode 100644 index fb9c4dad1..000000000 --- a/src/Chunk.inl.h +++ /dev/null @@ -1,34 +0,0 @@ - -#ifndef __C_CHUNK_INL_H__ -#define __C_CHUNK_INL_H__ - -#ifndef MAX -# define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - - - - - -__C_CHUNK_INLINE__ -void cChunk::SpreadLightOfBlock(NIBBLETYPE * a_LightBuffer, int a_X, int a_Y, int a_Z, char a_Falloff) -{ - unsigned char CurrentLight = cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y, a_Z ); - cChunkDef::SetNibble( a_LightBuffer, a_X-1, a_Y, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X-1, a_Y, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X+1, a_Y, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X+1, a_Y, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y-1, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y-1, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y+1, a_Z, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y+1, a_Z ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y, a_Z-1, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y, a_Z-1 ), MAX(0,CurrentLight-a_Falloff) ) ); - cChunkDef::SetNibble( a_LightBuffer, a_X, a_Y, a_Z+1, MAX(cChunkDef::GetNibble( a_LightBuffer, a_X, a_Y, a_Z+1 ), MAX(0,CurrentLight-a_Falloff) ) ); - MarkDirty(); -} - - - - - -#endif - - - - diff --git a/src/ChunkDef.h b/src/ChunkDef.h index bf41aa625..7d727a4d4 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -180,7 +180,7 @@ public: /// Converts absolute block coords into relative (chunk + block) coords: - inline static void AbsoluteToRelative(/* in-out */ int & a_X, int& a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) + inline static void AbsoluteToRelative(/* in-out */ int & a_X, int & a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) { UNUSED(a_Y); BlockToChunk(a_X, a_Z, a_ChunkX, a_ChunkZ); diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 3634f087c..2ba1b303d 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -424,11 +424,13 @@ protected: void Dereference( cEntity*& a_EntityPtr ); private: - // Measured in degrees (MAX 360 degrees) + // Measured in degrees, [-180, +180) double m_HeadYaw; + // Measured in meter/second (m/s) Vector3d m_Speed; - // Measured in degrees (MAX 360 degrees) + + // Measured in degrees, [-180, +180) Vector3d m_Rot; /// Position of the entity's XZ center and Y bottom -- cgit v1.2.3 From cd435ffca970f954d2ade1e81c7c4ae7df75907e Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 30 Dec 2013 22:56:08 +0100 Subject: Implented OnPlayerFishing and OnPlayerFished. --- src/Bindings/Plugin.h | 2 ++ src/Bindings/PluginLua.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/Bindings/PluginLua.h | 2 ++ src/Bindings/PluginManager.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Bindings/PluginManager.h | 4 ++++ src/Items/ItemFishingRod.h | 8 +++++++- 6 files changed, 97 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index ee0f8a062..80356304a 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -68,6 +68,8 @@ public: virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0; + virtual bool OnPlayerFished (cPlayer & a_Player, cItems & a_Reward) = 0; + virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0; virtual bool OnPlayerJoined (cPlayer & a_Player) = 0; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0; virtual bool OnPlayerMoved (cPlayer & a_Player) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 69e83fb0a..66a60efe8 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -630,6 +630,46 @@ bool cPluginLua::OnPlayerEating(cPlayer & a_Player) +bool cPluginLua::OnPlayerFished(cPlayer & a_Player, cItems & a_Reward) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHED]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Player, &a_Reward, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + +bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, cItems & a_Reward) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHING]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Player, &a_Reward, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnPlayerJoined(cPlayer & a_Player) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 1b257285e..d0cb209f1 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -64,6 +64,8 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual bool OnPlayerFished (cPlayer & a_Player, cItems & a_Reward) override; + virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override; virtual bool OnPlayerEating (cPlayer & a_Player) override; virtual bool OnPlayerJoined (cPlayer & a_Player) override; virtual bool OnPlayerMoved (cPlayer & a_Player) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index ffffe1a23..b863a95b5 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -694,6 +694,48 @@ bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player) +bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, cItems a_Reward) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHED); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPlayerFished(a_Player, a_Reward)) + { + return true; + } + } + return false; +} + + + + + +bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, cItems a_Reward) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHING); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPlayerFishing(a_Player, a_Reward)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookPlayerJoined(cPlayer & a_Player) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_JOINED); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index e94421057..da867c7b0 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -80,6 +80,8 @@ public: // tolua_export HOOK_PLAYER_BREAKING_BLOCK, HOOK_PLAYER_BROKEN_BLOCK, HOOK_PLAYER_EATING, + HOOK_PLAYER_FISHED, + HOOK_PLAYER_FISHING, HOOK_PLAYER_JOINED, HOOK_PLAYER_LEFT_CLICK, HOOK_PLAYER_MOVING, @@ -168,6 +170,8 @@ public: // tolua_export bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerEating (cPlayer & a_Player); + bool CallHookPlayerFished (cPlayer & a_Player, cItems a_Reward); + bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward); bool CallHookPlayerJoined (cPlayer & a_Player); bool CallHookPlayerMoving (cPlayer & a_Player); bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 941ce3b71..b2eaee63a 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -9,9 +9,11 @@ #pragma once +#include "../Bindings/PluginManager.h" #include "../Entities/Floater.h" #include "../Entities/Entity.h" #include "../Item.h" +#include "../Root.h" @@ -210,10 +212,14 @@ public: } } - + if (cRoot::Get()->GetPluginManager()->CallHookPlayerFishing(*a_Player, Drops)) + { + return true; + } Vector3d FloaterPos = FloaterInfo.GetPos(); Vector3d FlyDirection = a_Player->GetEyePosition() - FloaterPos; a_World->SpawnItemPickups(Drops, FloaterPos.x, FloaterPos.y, FloaterPos.z, FlyDirection.x, FlyDirection.y + 1, FlyDirection.z); + cRoot::Get()->GetPluginManager()->CallHookPlayerFished(*a_Player, Drops); } } else -- cgit v1.2.3 From 782818ffb520553e772bc5a4638009664a821f90 Mon Sep 17 00:00:00 2001 From: Morgan Redshaw Date: Mon, 30 Dec 2013 21:30:20 -0700 Subject: Fixed a cPlayer::IsGameModeAdventure. It was determined based off of gmCreate rather than gmAdventure. --- src/Entities/Player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 67d5a47ef..bc92790aa 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -908,8 +908,8 @@ bool cPlayer::IsGameModeSurvival(void) const bool cPlayer::IsGameModeAdventure(void) const { - return (m_GameMode == gmCreative) || // Either the player is explicitly in Adventure - ((m_GameMode == gmNotSet) && m_World->IsGameModeCreative()); // or they inherit from the world and the world is Adventure + return (m_GameMode == gmAdventure) || // Either the player is explicitly in Adventure + ((m_GameMode == gmNotSet) && m_World->IsGameModeAdventure()); // or they inherit from the world and the world is Adventure } -- cgit v1.2.3 From 25d42c44d5d9cbd3eb1178fde50cf9b271e4a96e Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 13:55:06 +0000 Subject: fixed warnings in BlockArea.cpp --- src/BlockArea.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 1148908c6..dd8e0da31 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -28,6 +28,8 @@ template void InternalMergeBlocks( Combinator a_Combinator ) { + UNUSED(a_SrcSizeY); + UNUSED(a_DstSizeY); for (int y = 0; y < a_SizeY; y++) { int SrcBaseY = (y + a_SrcOffY) * a_SrcSizeX * a_SrcSizeZ; -- cgit v1.2.3 From 9ebc623a0a453c71add19eb67e05782248a7b7ab Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 14:00:32 +0000 Subject: fixed warnings in webadmin.cpp --- src/WebAdmin.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index a1f0842aa..e6a5a01b3 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -305,6 +305,7 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque void cWebAdmin::HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) { + UNUSED(a_Request); static const char LoginForm[] = \ "

MCServer WebAdmin

" \ "
" \ @@ -450,6 +451,7 @@ AString cWebAdmin::GetBaseURL(const AStringVector & a_URLSplit) void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) { + UNUSED(a_Connection); const AString & URL = a_Request.GetURL(); if ( (strncmp(URL.c_str(), "/webadmin", 9) == 0) || @@ -473,6 +475,7 @@ void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_ void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) { + UNUSED(a_Connection); cRequestData * Data = (cRequestData *)(a_Request.GetUserData()); if (Data == NULL) { -- cgit v1.2.3 From e41dec458c690c5c99ef75fe4baf6dc7371e5b64 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 14:05:53 +0000 Subject: fixed ClientHandle warnings --- src/ClientHandle.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 99df47bfb..17412c265 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1409,6 +1409,7 @@ void cClientHandle::SendData(const char * a_Data, int a_Size) void cClientHandle::MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket) { + UNUSED(a_World); ASSERT(m_Player != NULL); if (a_SendRespawnPacket) -- cgit v1.2.3 From c83dfdb66e096f16805d0a842e0492645dc086c2 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 14:19:29 +0000 Subject: fixed warnings in bytebuffer.cpp --- src/ByteBuffer.cpp | 6 +++--- src/ByteBuffer.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 64c03d0d3..510018005 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -773,7 +773,7 @@ void cByteBuffer::ReadAll(AString & a_Data) -bool cByteBuffer::ReadToByteBuffer(cByteBuffer & a_Dst, int a_NumBytes) +bool cByteBuffer::ReadToByteBuffer(cByteBuffer & a_Dst, size_t a_NumBytes) { if (!a_Dst.CanWriteBytes(a_NumBytes) || !CanReadBytes(a_NumBytes)) { @@ -781,9 +781,9 @@ bool cByteBuffer::ReadToByteBuffer(cByteBuffer & a_Dst, int a_NumBytes) return false; } char buf[1024]; - while (a_NumBytes > 0) + while (a_NumBytes > static_cast(0)) { - int num = (a_NumBytes > sizeof(buf)) ? sizeof(buf) : a_NumBytes; + size_t num = (a_NumBytes > sizeof(buf)) ? sizeof(buf) : a_NumBytes; VERIFY(ReadBuf(buf, num)); VERIFY(a_Dst.Write(buf, num)); a_NumBytes -= num; diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index 06c846fa9..cbce119b1 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -110,7 +110,7 @@ public: void ReadAll(AString & a_Data); /// Reads the specified number of bytes and writes it into the destinatio bytebuffer. Returns true on success. - bool ReadToByteBuffer(cByteBuffer & a_Dst, int a_NumBytes); + bool ReadToByteBuffer(cByteBuffer & a_Dst, size_t a_NumBytes); /// Removes the bytes that have been read from the ringbuffer void CommitRead(void); -- cgit v1.2.3 From 3152c7295983418a905f3f6404a54cc7b038ead9 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 14:28:47 +0000 Subject: fixed warnings in Inventory.cpp --- src/Inventory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Inventory.cpp b/src/Inventory.cpp index a9b4ab9c5..a7f77cf6d 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -57,6 +57,8 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, bool a_ConsiderEmptySlo int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int a_EndSlotNum, bool a_ConsiderEmptySlots) { + + UNUSED(a_ConsiderEmptySlots); if ((a_BeginSlotNum < 0) || (a_BeginSlotNum >= invNumSlots)) { LOGWARNING("%s: Bad BeginSlotNum, got %d, there are %d slots; correcting to 0.", __FUNCTION__, a_BeginSlotNum, invNumSlots - 1); @@ -96,8 +98,6 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int - - int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst) { cItem ToAdd(a_Item); -- cgit v1.2.3 From 2e113c63f9dce41beea8597b173f072487e07d34 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 14:42:17 +0000 Subject: fixxed warnings in Server.cpp --- src/Server.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/Server.cpp b/src/Server.cpp index a93be9a5b..7dedc3904 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -173,6 +173,7 @@ void cServer::ClientMovedToWorld(const cClientHandle * a_Client) void cServer::PlayerCreated(const cPlayer * a_Player) { + UNUSED(a_Player); // To avoid deadlocks, the player count is not handled directly, but rather posted onto the tick thread cCSLock Lock(m_CSPlayerCountDiff); m_PlayerCountDiff += 1; @@ -184,6 +185,7 @@ void cServer::PlayerCreated(const cPlayer * a_Player) void cServer::PlayerDestroying(const cPlayer * a_Player) { + UNUSED(a_Player); // To avoid deadlocks, the player count is not handled directly, but rather posted onto the tick thread cCSLock Lock(m_CSPlayerCountDiff); m_PlayerCountDiff -= 1; @@ -514,6 +516,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output) { + UNUSED(a_Split); typedef std::pair AStringPair; typedef std::vector AStringPairs; @@ -525,6 +528,8 @@ void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override { + UNUSED(a_Plugin); + UNUSED(a_Permission); if (!a_HelpString.empty()) { m_Commands.push_back(AStringPair(a_Command, a_HelpString)); -- cgit v1.2.3 From 2e1588820d3c27a82d4bd6401dc9af728130908c Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 14:55:24 +0000 Subject: fixed warnings in World.cpp --- src/BlockTracer.h | 25 ++++++++++++++++++++++--- src/Simulator/NoopFluidSimulator.h | 10 ++++++++-- src/World.cpp | 4 +++- src/World.h | 1 + 4 files changed, 34 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/BlockTracer.h b/src/BlockTracer.h index d0a34811d..40d80da1a 100644 --- a/src/BlockTracer.h +++ b/src/BlockTracer.h @@ -36,7 +36,14 @@ public: /** Called on each block encountered along the path, including the first block (path start), if chunk data is not loaded When this callback returns true, the tracing is aborted. */ - virtual bool OnNextBlockNoData(int a_BlockX, int a_BlockY, int a_BlockZ, char a_EntryFace) { return false; } + virtual bool OnNextBlockNoData(int a_BlockX, int a_BlockY, int a_BlockZ, char a_EntryFace) + { + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_EntryFace); + return false; + } /** Called when the path goes out of world, either below (a_BlockY < 0) or above (a_BlockY >= cChunkDef::Height) The coords specify the exact point at which the path exited the world. @@ -44,7 +51,13 @@ public: Note that some paths can go out of the world and come back again (parabola), in such a case this callback is followed by OnIntoWorld() and further OnNextBlock() calls */ - virtual bool OnOutOfWorld(double a_BlockX, double a_BlockY, double a_BlockZ) { return false; } + virtual bool OnOutOfWorld(double a_BlockX, double a_BlockY, double a_BlockZ) + { + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + return false; + } /** Called when the path goes into the world, from either below (a_BlockY < 0) or above (a_BlockY >= cChunkDef::Height) The coords specify the exact point at which the path entered the world. @@ -52,7 +65,13 @@ public: Note that some paths can go out of the world and come back again (parabola), in such a case this callback is followed by further OnNextBlock() calls */ - virtual bool OnIntoWorld(double a_BlockX, double a_BlockY, double a_BlockZ) { return false; } + virtual bool OnIntoWorld(double a_BlockX, double a_BlockY, double a_BlockZ) + { + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + return false; + } /** Called when the path is sure not to hit any more blocks. Note that for some shapes this might never happen (line with constant Y) diff --git a/src/Simulator/NoopFluidSimulator.h b/src/Simulator/NoopFluidSimulator.h index 8f894433f..9113aec3c 100644 --- a/src/Simulator/NoopFluidSimulator.h +++ b/src/Simulator/NoopFluidSimulator.h @@ -27,8 +27,14 @@ public: } // cSimulator overrides: - virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override {} - virtual void Simulate(float a_Dt) override {} + virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override + { + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + UNUSED(a_Chunk); + } + virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} } ; diff --git a/src/World.cpp b/src/World.cpp index 28c46c27e..cc543d460 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -723,6 +723,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) void cWorld::TickWeather(float a_Dt) { + UNUSED(a_Dt); // There are no weather changes anywhere but in the Overworld: if (GetDimension() != dimOverworld) { @@ -794,7 +795,7 @@ void cWorld::TickMobs(float a_Dt) cMonster::mfAmbient, cMonster::mfWater, } ; - for (int i = 0; i < ARRAYCOUNT(AllFamilies); i++) + for (size_t i = 0; i < ARRAYCOUNT(AllFamilies); i++) { cMonster::eFamily Family = AllFamilies[i]; int SpawnDelay = cMonster::GetSpawnDelay(Family); @@ -1643,6 +1644,7 @@ int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff) { + UNUSED(a_InitialVelocityCoeff); cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTimeInSec); TNT->Initialize(this); // TODO: Add a bit of speed in horiz and vert axes, based on the a_InitialVelocityCoeff diff --git a/src/World.h b/src/World.h index c067252d9..67f1275c0 100644 --- a/src/World.h +++ b/src/World.h @@ -78,6 +78,7 @@ public: class cTask { public: + virtual ~cTask(){}; virtual void Run(cWorld & a_World) = 0; } ; -- cgit v1.2.3 From 3da41de5539337438e6091dd1830505b755124eb Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 15:01:04 +0000 Subject: take Z axis into account when calculating neighboors in LightingThread::ChunkReady --- src/LightingThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index d7e60e458..d9c41481a 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -189,7 +189,7 @@ void cLightingThread::ChunkReady(int a_ChunkX, int a_ChunkZ) { if ( (itr->x - a_ChunkX >= -1) && (itr->x - a_ChunkX <= 1) && - (itr->x - a_ChunkX >= -1) && (itr->x - a_ChunkX <= 1) + (itr->z - a_ChunkZ >= -1) && (itr->z - a_ChunkZ <= 1) ) { // It is a neighbor -- cgit v1.2.3 From 8e7e990cfe5be08030ff2b7e0323c9bf64b15201 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 15:04:29 +0000 Subject: fixed warnings in LightingThread.cpp --- src/LightingThread.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index d9c41481a..7c3cc9c76 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -495,6 +495,7 @@ void cLightingThread::CalcLightStep( int & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut ) { + UNUSED(a_IsSeedIn); int NumSeedsOut = 0; for (int i = 0; i < a_NumSeedsIn; i++) { -- cgit v1.2.3 From 1957f982bc7be250f52bac2ccc0450e60c965fba Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 15:06:41 +0000 Subject: fixed warnings in LineBlockTracer.cpp --- src/LineBlockTracer.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index 9fcbca915..110c6b5dc 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -196,7 +196,6 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk) ASSERT((m_CurrentY >= 0) && (m_CurrentY < cChunkDef::Height)); // This should be provided by FixStartAboveWorld() / FixStartBelowWorld() // This is the actual line tracing loop. - bool Finished = false; while (true) { // Report the current block through the callbacks: -- cgit v1.2.3 From c3e34ee81af71c70514d53f4e54e3a6c2ac5a976 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Sun, 22 Dec 2013 17:02:36 +0000 Subject: removed unneccisary cast --- src/ByteBuffer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 510018005..e06f63a0e 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -781,7 +781,8 @@ bool cByteBuffer::ReadToByteBuffer(cByteBuffer & a_Dst, size_t a_NumBytes) return false; } char buf[1024]; - while (a_NumBytes > static_cast(0)) + // > 0 without generating warnings about unsigned comparisons where size_t is unsigned + while (a_NumBytes != 0) { size_t num = (a_NumBytes > sizeof(buf)) ? sizeof(buf) : a_NumBytes; VERIFY(ReadBuf(buf, num)); -- cgit v1.2.3 From 020a8b457d67a70f407482322188823af9ac7f72 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 31 Dec 2013 14:53:10 +0100 Subject: implemented the recommendations Xoft gave. --- src/Bindings/LuaState.cpp | 12 ++++++++++++ src/Bindings/LuaState.h | 1 + src/Bindings/Plugin.h | 4 ++-- src/Bindings/PluginLua.cpp | 8 ++++---- src/Bindings/PluginLua.h | 4 ++-- src/Bindings/PluginManager.cpp | 4 ++-- src/Bindings/PluginManager.h | 4 ++-- 7 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 64a818a60..a684620f3 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -468,6 +468,18 @@ void cLuaState::Push(cItems * a_Items) +void cLuaState::Push(const cItems & a_Items) +{ + ASSERT(IsValid()); + + tolua_pushusertype(m_LuaState, (void *)&a_Items, "cItems"); + m_NumCurrentFunctionArgs += 1; +} + + + + + void cLuaState::Push(cClientHandle * a_Client) { ASSERT(IsValid()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index a6c31b6d3..796559b6f 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -165,6 +165,7 @@ public: void Push(cMonster * a_Monster); void Push(cItem * a_Item); void Push(cItems * a_Items); + void Push(const cItems & a_Items); void Push(cClientHandle * a_ClientHandle); void Push(cPickup * a_Pickup); void Push(cChunkDesc * a_ChunkDesc); diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 80356304a..80d9316e4 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -68,8 +68,8 @@ public: virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0; - virtual bool OnPlayerFished (cPlayer & a_Player, cItems & a_Reward) = 0; - virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0; + virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0; + virtual bool OnPlayerFishing (cPlayer & a_Player, const cItems & a_Reward) = 0; virtual bool OnPlayerJoined (cPlayer & a_Player) = 0; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0; virtual bool OnPlayerMoved (cPlayer & a_Player) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 66a60efe8..d8108da54 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -630,14 +630,14 @@ bool cPluginLua::OnPlayerEating(cPlayer & a_Player) -bool cPluginLua::OnPlayerFished(cPlayer & a_Player, cItems & a_Reward) +bool cPluginLua::OnPlayerFished(cPlayer & a_Player, const cItems & a_Reward) { cCSLock Lock(m_CriticalSection); bool res = false; cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHED]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), &a_Player, &a_Reward, cLuaState::Return, res); + m_LuaState.Call((int)(**itr), &a_Player, a_Reward, cLuaState::Return, res); if (res) { return true; @@ -650,14 +650,14 @@ bool cPluginLua::OnPlayerFished(cPlayer & a_Player, cItems & a_Reward) -bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, cItems & a_Reward) +bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, const cItems & a_Reward) { cCSLock Lock(m_CriticalSection); bool res = false; cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHING]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), &a_Player, &a_Reward, cLuaState::Return, res); + m_LuaState.Call((int)(**itr), &a_Player, a_Reward, cLuaState::Return, res); if (res) { return true; diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index d0cb209f1..ab15279da 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -64,9 +64,9 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; - virtual bool OnPlayerFished (cPlayer & a_Player, cItems & a_Reward) override; - virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override; virtual bool OnPlayerEating (cPlayer & a_Player) override; + virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override; + virtual bool OnPlayerFishing (cPlayer & a_Player, const cItems & a_Reward) override; virtual bool OnPlayerJoined (cPlayer & a_Player) override; virtual bool OnPlayerMoved (cPlayer & a_Player) override; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index b863a95b5..027b87545 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -694,7 +694,7 @@ bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player) -bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, cItems a_Reward) +bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, const cItems a_Reward) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHED); if (Plugins == m_Hooks.end()) @@ -715,7 +715,7 @@ bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, cItems a_Reward) -bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, cItems a_Reward) +bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, const cItems a_Reward) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHING); if (Plugins == m_Hooks.end()) diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index da867c7b0..c6a8b8b9f 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -170,8 +170,8 @@ public: // tolua_export bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerEating (cPlayer & a_Player); - bool CallHookPlayerFished (cPlayer & a_Player, cItems a_Reward); - bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward); + bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward); + bool CallHookPlayerFishing (cPlayer & a_Player, const cItems a_Reward); bool CallHookPlayerJoined (cPlayer & a_Player); bool CallHookPlayerMoving (cPlayer & a_Player); bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); -- cgit v1.2.3 From f3736b1eb7bf698518cdb853ee29ee96b9c24a52 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Tue, 31 Dec 2013 15:48:57 +0000 Subject: refactored chunk Queue to seperate class --- src/ChunkDef.h | 1 - src/OSSupport/Event.h | 6 +- src/OSSupport/IsThread.h | 1 - src/OSSupport/Queue.h | 110 +++++++++++++++++++++++++----- src/OSSupport/Queue.inc | 4 -- src/WorldStorage/WorldStorage.cpp | 136 ++++++++++++-------------------------- src/WorldStorage/WorldStorage.h | 28 ++++++-- 7 files changed, 162 insertions(+), 124 deletions(-) delete mode 100644 src/OSSupport/Queue.inc (limited to 'src') diff --git a/src/ChunkDef.h b/src/ChunkDef.h index bf41aa625..c68ae5106 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -14,7 +14,6 @@ - /** This is really only a placeholder to be used in places where we need to "make up" a chunk's Y coord. It will help us when the new chunk format comes out and we need to patch everything up for compatibility. */ diff --git a/src/OSSupport/Event.h b/src/OSSupport/Event.h index 71f418c0c..31f32f8c6 100644 --- a/src/OSSupport/Event.h +++ b/src/OSSupport/Event.h @@ -20,10 +20,10 @@ class cEvent { public: cEvent(void); - ~cEvent(); + virtual ~cEvent(); - void Wait(void); - void Set (void); + virtual void Wait(void); + virtual void Set (void); private: diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h index b8784ea33..af4367636 100644 --- a/src/OSSupport/IsThread.h +++ b/src/OSSupport/IsThread.h @@ -22,7 +22,6 @@ In the descending class' constructor call the Start() method to start the thread - class cIsThread { protected: diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index 838a101e0..eb323b067 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -1,30 +1,104 @@ + #pragma once +#include + +#include "../OSSupport/Promise.h" + +//this empty struct allows function inlining template -class cDeleter +struct cQueueFuncs { public: static void Delete(T) {}; -} + static void Combine(T&, const T) {}; +}; -template +template > class cQueue { + +typedef typename std::list ListType; +//magic typedef to persuade clang that the iterator is a type +typedef typename ListType::iterator iterator; public: - cQueue(int warnsize); - cQueue(cQueue& queue); - ~cQueue(); - - void EnqueueItem(T item); - bool TryDequeueItem(T& item); - T DequeueItem(); - void BlockTillEmpty(cEvent CancelationEvent); - void Clear(); - int Size(); - + cQueue() {} + ~cQueue() {} + + void EnqueueItem(ItemType a_item) + { + cCSLock Lock(m_CS); + m_contents.push_back(a_item); + m_evtAdded.Set(); + } + void EnqueueItemIfNotPresent(ItemType a_item) + { + cCSLock Lock(m_CS); + + for (iterator itr = m_contents.begin(); itr != m_contents.end(); ++itr) + { + if((*itr) == a_item) { + Funcs funcTable; + funcTable.Combine(*itr,a_item); + return; + } + } + m_contents.push_back(a_item); + m_evtAdded.Set(); + } + bool TryDequeueItem(ItemType& item) + { + cCSLock Lock(m_CS); + if (m_contents.size() == 0) return false; + item = m_contents.front(); + m_contents.pop_front(); + return true; + } + ItemType DequeueItem() + { + cCSLock Lock(m_CS); + while (m_contents.size() == 0) + { + cCSUnlock Unlock(m_CS); + m_evtAdded.Wait(); + } + return m_contents.pop_front(); + } + cPromise* BlockTillEmpty() { + return new cEmptyQueuePromise(this); + } + //can all be inlined when delete is a noop + void Clear() + { + cCSLock Lock(m_CS); + Funcs funcTable; + while (!m_contents.empty()) + { + funcTable.Delete(m_contents.front()); + m_contents.pop_front(); + } + } + size_t Size() + { + cCSLock Lock(m_CS); + return m_contents.size(); + } + bool Remove(ItemType item) + { + cCSLock Lock(m_CS); + m_contents.remove(item); + } + private: - int warnsize; -} + ListType m_contents; + cCriticalSection m_CS; + cEvent m_evtAdded; -//template classes must be implemented in the header -#include "Queue.inc" + class cEmptyQueuePromise : public cPromise { + public: + cEmptyQueuePromise(cQueue* a_Queue) : cPromise(), m_Queue(a_Queue) {} + virtual bool IsCompleted() {return m_Queue->Size() != 0;} + private: + cQueue* m_Queue; + }; +}; diff --git a/src/OSSupport/Queue.inc b/src/OSSupport/Queue.inc deleted file mode 100644 index f172e9794..000000000 --- a/src/OSSupport/Queue.inc +++ /dev/null @@ -1,4 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - - diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index f290ec128..c3bfbd4f6 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -13,7 +13,7 @@ #include "../Generating/ChunkGenerator.h" #include "../Entities/Entity.h" #include "../BlockEntities/BlockEntity.h" - +#include "../OSSupport/Promise.h" @@ -63,8 +63,6 @@ cWorldStorage::~cWorldStorage() { delete *itr; } // for itr - m_Schemas[] - m_LoadQueue.clear(); - m_SaveQueue.clear(); } @@ -98,9 +96,7 @@ void cWorldStorage::WaitForFinish(void) LOG("Waiting for the world storage to finish saving"); { - // Cancel all loading requests: - cCSLock Lock(m_CSQueues); - m_LoadQueue.clear(); + m_LoadQueue.Clear(); } // Wait for the saving to finish: @@ -120,32 +116,36 @@ void cWorldStorage::WaitForFinish(void) void cWorldStorage::WaitForQueuesEmpty(void) { - cCSLock Lock(m_CSQueues); - while (!m_ShouldTerminate && (!m_LoadQueue.empty() || !m_SaveQueue.empty())) - { - cCSUnlock Unlock(Lock); - m_evtRemoved.Wait(); - } + + cPromise * LoadPromise = m_LoadQueue.BlockTillEmpty(); + cPromise * SavePromise = m_SaveQueue.BlockTillEmpty(); + cPromise * QueuePromise = LoadPromise->WaitFor(SavePromise); + cPromise * CancelPromise = QueuePromise->CancelOn(m_ShouldTerminate); + CancelPromise->Wait(); + delete CancelPromise; + delete QueuePromise; + delete SavePromise; + delete LoadPromise; } -int cWorldStorage::GetLoadQueueLength(void) +size_t cWorldStorage::GetLoadQueueLength(void) { cCSLock Lock(m_CSQueues); - return (int)m_LoadQueue.size(); + return m_LoadQueue.Size(); } -int cWorldStorage::GetSaveQueueLength(void) +size_t cWorldStorage::GetSaveQueueLength(void) { cCSLock Lock(m_CSQueues); - return (int)m_SaveQueue.size(); + return m_SaveQueue.Size(); } @@ -154,22 +154,7 @@ int cWorldStorage::GetSaveQueueLength(void) void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) { - // Queues the chunk for loading; if not loaded, the chunk will be generated - { - cCSLock Lock(m_CSQueues); - - // Check if already in the queue: - for (sChunkLoadQueue::iterator itr = m_LoadQueue.begin(); itr != m_LoadQueue.end(); ++itr) - { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ) && (itr->m_Generate == a_Generate)) - { - return; - } - } - m_LoadQueue.push_back(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); - } - - m_Event.Set(); + m_LoadQueue.EnqueueItemIfNotPresent(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); } @@ -178,12 +163,7 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { - { - cCSLock Lock(m_CSQueues); - m_SaveQueue.remove (cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); // Don't add twice - m_SaveQueue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); - } - m_Event.Set(); + m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); } @@ -192,12 +172,8 @@ void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cWorldStorage::QueueSavedMessage(void) { - // Pushes a special coord pair into the queue, signalizing a message instead: - { - cCSLock Lock(m_CSQueues); - m_SaveQueue.push_back(cChunkCoords(0, CHUNK_Y_MESSAGE, 0)); - } - m_Event.Set(); + // Pushes a special coord pair into the queue, signalizing a message instead + m_SaveQueue.EnqueueItem(cChunkCoords(0, CHUNK_Y_MESSAGE, 0)); } @@ -206,7 +182,7 @@ void cWorldStorage::QueueSavedMessage(void) void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { - cCSLock Lock(m_CSQueues); + /*cCSLock Lock(m_CSQueues); for (sChunkLoadQueue::iterator itr = m_LoadQueue.begin(); itr != m_LoadQueue.end(); ++itr) { if ((itr->m_ChunkX != a_ChunkX) || (itr->m_ChunkY != a_ChunkY) || (itr->m_ChunkZ != a_ChunkZ)) @@ -217,7 +193,8 @@ void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ) Lock.Unlock(); m_evtRemoved.Set(); return; - } // for itr - m_LoadQueue[] + } // for itr - m_LoadQueue[]*/ + m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ,true)); } @@ -226,11 +203,7 @@ void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cWorldStorage::UnqueueSave(const cChunkCoords & a_Chunk) { - { - cCSLock Lock(m_CSQueues); - m_SaveQueue.remove(a_Chunk); - } - m_evtRemoved.Set(); + m_SaveQueue.Remove(a_Chunk); } @@ -281,19 +254,19 @@ void cWorldStorage::Execute(void) m_Event.Wait(); // Process both queues until they are empty again: - bool HasMore; + bool Success; do { - HasMore = false; + Success = false; if (m_ShouldTerminate) { return; } - HasMore = LoadOneChunk(); - HasMore = HasMore | SaveOneChunk(); + Success = LoadOneChunk(); + Success |= SaveOneChunk(); m_evtRemoved.Set(); - } while (HasMore); + } while (Success); } } @@ -304,19 +277,7 @@ void cWorldStorage::Execute(void) bool cWorldStorage::LoadOneChunk(void) { sChunkLoad ToLoad(0, 0, 0, false); - bool HasMore; - bool ShouldLoad = false; - { - cCSLock Lock(m_CSQueues); - if (!m_LoadQueue.empty()) - { - ToLoad = m_LoadQueue.front(); - m_LoadQueue.pop_front(); - ShouldLoad = true; - } - HasMore = !m_LoadQueue.empty(); - } - + bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad); if (ShouldLoad && !LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ)) { if (ToLoad.m_Generate) @@ -330,7 +291,7 @@ bool cWorldStorage::LoadOneChunk(void) // m_World->ChunkLoadFailed(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ); } } - return HasMore; + return ShouldLoad; } @@ -339,33 +300,24 @@ bool cWorldStorage::LoadOneChunk(void) bool cWorldStorage::SaveOneChunk(void) { - cChunkCoords Save(0, 0, 0); - bool HasMore; - bool ShouldSave = false; - { - cCSLock Lock(m_CSQueues); - if (!m_SaveQueue.empty()) + cChunkCoords ToSave(0, 0, 0); + bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave); + if(ShouldSave) { + if (ToSave.m_ChunkY == CHUNK_Y_MESSAGE) { - Save = m_SaveQueue.front(); - m_SaveQueue.pop_front(); - ShouldSave = true; + LOGINFO("Saved all chunks in world %s", m_World->GetName().c_str()); + return ShouldSave; } - HasMore = !m_SaveQueue.empty(); - } - if (Save.m_ChunkY == CHUNK_Y_MESSAGE) - { - LOGINFO("Saved all chunks in world %s", m_World->GetName().c_str()); - return HasMore; - } - if (ShouldSave && m_World->IsChunkValid(Save.m_ChunkX, Save.m_ChunkZ)) - { - m_World->MarkChunkSaving(Save.m_ChunkX, Save.m_ChunkZ); - if (m_SaveSchema->SaveChunk(Save)) + if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ)) { - m_World->MarkChunkSaved(Save.m_ChunkX, Save.m_ChunkZ); + m_World->MarkChunkSaving(ToSave.m_ChunkX, ToSave.m_ChunkZ); + if (m_SaveSchema->SaveChunk(ToSave)) + { + m_World->MarkChunkSaved(ToSave.m_ChunkX, ToSave.m_ChunkZ); + } } } - return HasMore; + return ShouldSave; } diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index 007d37571..c3eb96ce8 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,6 +16,7 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" +#include "../OSSupport/Queue.h" @@ -24,6 +25,8 @@ // fwd: class cWorld; +typedef cQueue cChunkCoordsQueue; + @@ -78,8 +81,8 @@ public: void WaitForFinish(void); void WaitForQueuesEmpty(void); - int GetLoadQueueLength(void); - int GetSaveQueueLength(void); + size_t GetLoadQueueLength(void); + size_t GetSaveQueueLength(void); protected: @@ -91,9 +94,24 @@ protected: bool m_Generate; // If true, the chunk will be generated if it cannot be loaded sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {} + + bool operator==(const sChunkLoad other) const + { + return this->m_ChunkX == other.m_ChunkX && + this->m_ChunkY == other.m_ChunkY && + this->m_ChunkZ == other.m_ChunkZ; + } } ; - - typedef std::list sChunkLoadQueue; + + struct FuncTable { + static void Delete(sChunkLoad) {}; + static void Combine(sChunkLoad& a_orig, const sChunkLoad a_new) + { + a_orig.m_Generate |= a_new.m_Generate; + }; + }; + + typedef cQueue sChunkLoadQueue; cWorld * m_World; AString m_StorageSchemaName; @@ -101,7 +119,7 @@ protected: // Both queues are locked by the same CS cCriticalSection m_CSQueues; sChunkLoadQueue m_LoadQueue; - cChunkCoordsList m_SaveQueue; + cChunkCoordsQueue m_SaveQueue; cEvent m_Event; // Set when there's any addition to the queues cEvent m_evtRemoved; // Set when an item has been removed from the queue, either by the worker thread or the Unqueue methods -- cgit v1.2.3 From 512d1b9ebebaf205756dde352c4e714dd632ca2d Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Tue, 31 Dec 2013 15:58:21 +0000 Subject: clean up code for patching --- src/ChunkDef.h | 1 + src/OSSupport/Event.h | 6 +++--- src/OSSupport/IsThread.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 8919bcbb8..7d727a4d4 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -14,6 +14,7 @@ + /** This is really only a placeholder to be used in places where we need to "make up" a chunk's Y coord. It will help us when the new chunk format comes out and we need to patch everything up for compatibility. */ diff --git a/src/OSSupport/Event.h b/src/OSSupport/Event.h index 31f32f8c6..71f418c0c 100644 --- a/src/OSSupport/Event.h +++ b/src/OSSupport/Event.h @@ -20,10 +20,10 @@ class cEvent { public: cEvent(void); - virtual ~cEvent(); + ~cEvent(); - virtual void Wait(void); - virtual void Set (void); + void Wait(void); + void Set (void); private: diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h index af4367636..b8784ea33 100644 --- a/src/OSSupport/IsThread.h +++ b/src/OSSupport/IsThread.h @@ -22,6 +22,7 @@ In the descending class' constructor call the Start() method to start the thread + class cIsThread { protected: -- cgit v1.2.3 From 098ed91a48df9fef58590b22fe34225ed1f44cfa Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Tue, 31 Dec 2013 16:13:13 +0000 Subject: fogot to add promise classes --- src/OSSupport/Promise.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/OSSupport/Promise.h | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/OSSupport/Promise.cpp create mode 100644 src/OSSupport/Promise.h (limited to 'src') diff --git a/src/OSSupport/Promise.cpp b/src/OSSupport/Promise.cpp new file mode 100644 index 000000000..b31869334 --- /dev/null +++ b/src/OSSupport/Promise.cpp @@ -0,0 +1,54 @@ + +#include "Globals.h" + +#include "Promise.h" + +cPromise * cPromise::WaitFor(cPromise * a_Promise) +{ + return new cCombinedPromise(this, a_Promise); +} + +cPromise * cPromise::CancelOn(volatile bool& cancelation) +{ + return new cCancelablePromise(this, cancelation); +} + +void cPromise::Wait() +{ + while(!IsCompleted()){}; //busywait best we can do until waitany +} + + +cCombinedPromise::cCombinedPromise(cPromise* a_left, cPromise* a_right) : + cPromise(), + m_left(a_left), + m_right(a_right) +{ +} + +cCombinedPromise::~cCombinedPromise() +{ +} + +bool cCombinedPromise::IsCompleted() +{ + return m_left->IsCompleted() || m_right->IsCompleted(); +} + +cCancelablePromise::cCancelablePromise(cPromise* a_wrapped, volatile bool& a_cancel) : + cPromise(), + m_cancel(a_cancel), + m_wrapped(a_wrapped) +{ +} + +cCancelablePromise::~cCancelablePromise () +{ +} + +bool cCancelablePromise::IsCompleted() +{ + return m_cancel || m_wrapped->IsCompleted(); +} + + diff --git a/src/OSSupport/Promise.h b/src/OSSupport/Promise.h new file mode 100644 index 000000000..83d04860b --- /dev/null +++ b/src/OSSupport/Promise.h @@ -0,0 +1,38 @@ +#pragma once + +class cCombinedPromise; + + +class cPromise { + public: + cPromise() {} + virtual ~cPromise () {} + cPromise * WaitFor(cPromise * a_Promise); + cPromise * CancelOn(volatile bool& cancelationtoken); + void Wait(); + virtual bool IsCompleted() = 0; + //TODO:Expose Events for waiting on +}; + +class cCombinedPromise : public cPromise { +public: + cCombinedPromise(cPromise*, cPromise*); + ~cCombinedPromise(); + virtual bool IsCompleted(); +private: + cPromise* m_left; + cPromise* m_right; +}; + +class cCancelablePromise : public cPromise { +public: + cCancelablePromise(cPromise*, volatile bool&); + ~cCancelablePromise(); + virtual bool IsCompleted(); +private: + volatile bool& m_cancel; + cPromise* m_wrapped; +}; + + + -- cgit v1.2.3 From 852c52bee9ffcc7857ea5d112fef8a4254c57253 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 1 Jan 2014 11:18:56 +0200 Subject: Fixed GetPhysicalRAMUsage on Linux --- src/Root.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Root.cpp b/src/Root.cpp index 16a521698..fa1fdb37a 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -701,9 +701,9 @@ int cRoot::GetPhysicalRAMUsage(void) { AString Line; std::getline(StatFile, Line); - if (strncmp(Line.c_str(), "VmRSS:", 7) == 0) + if (strncmp(Line.c_str(), "VmRSS:", 6) == 0) { - int res = atoi(Line.c_str() + 8); + int res = atoi(Line.c_str() + 7); return (res == 0) ? -1 : res; // If parsing failed, return -1 } } -- cgit v1.2.3 From db00a36ff8d8f96c9554f29656196ecd4e08c6a9 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 1 Jan 2014 15:09:53 +0100 Subject: OnPlayerFishing doesn't have a const cItems anymore --- src/Bindings/Plugin.h | 2 +- src/Bindings/PluginLua.cpp | 2 +- src/Bindings/PluginLua.h | 2 +- src/Bindings/PluginManager.cpp | 2 +- src/Bindings/PluginManager.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 80d9316e4..2c893a65d 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -69,7 +69,7 @@ public: virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0; - virtual bool OnPlayerFishing (cPlayer & a_Player, const cItems & a_Reward) = 0; + virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0; virtual bool OnPlayerJoined (cPlayer & a_Player) = 0; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0; virtual bool OnPlayerMoved (cPlayer & a_Player) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index d8108da54..87212ed85 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -650,7 +650,7 @@ bool cPluginLua::OnPlayerFished(cPlayer & a_Player, const cItems & a_Reward) -bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, const cItems & a_Reward) +bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, cItems & a_Reward) { cCSLock Lock(m_CriticalSection); bool res = false; diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index ab15279da..a47ab32e0 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -66,7 +66,7 @@ public: virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerEating (cPlayer & a_Player) override; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override; - virtual bool OnPlayerFishing (cPlayer & a_Player, const cItems & a_Reward) override; + virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override; virtual bool OnPlayerJoined (cPlayer & a_Player) override; virtual bool OnPlayerMoved (cPlayer & a_Player) override; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 027b87545..3a6c542b1 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -715,7 +715,7 @@ bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, const cItems a_Rew -bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, const cItems a_Reward) +bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, cItems a_Reward) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHING); if (Plugins == m_Hooks.end()) diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index c6a8b8b9f..16c64d86f 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -171,7 +171,7 @@ public: // tolua_export bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerEating (cPlayer & a_Player); bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward); - bool CallHookPlayerFishing (cPlayer & a_Player, const cItems a_Reward); + bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward); bool CallHookPlayerJoined (cPlayer & a_Player); bool CallHookPlayerMoving (cPlayer & a_Player); bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); -- cgit v1.2.3 From 042b72bc172e7eb4e9ef7668ae28be6e7a3b4036 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Thu, 2 Jan 2014 12:32:55 +0000 Subject: rewrote queue not to use promises for waits --- src/OSSupport/Promise.cpp | 54 --------------------------------------- src/OSSupport/Promise.h | 38 --------------------------- src/OSSupport/Queue.h | 24 ++++++++--------- src/World.cpp | 5 +++- src/WorldStorage/WorldStorage.cpp | 21 +++++---------- src/WorldStorage/WorldStorage.h | 3 ++- 6 files changed, 24 insertions(+), 121 deletions(-) delete mode 100644 src/OSSupport/Promise.cpp delete mode 100644 src/OSSupport/Promise.h (limited to 'src') diff --git a/src/OSSupport/Promise.cpp b/src/OSSupport/Promise.cpp deleted file mode 100644 index b31869334..000000000 --- a/src/OSSupport/Promise.cpp +++ /dev/null @@ -1,54 +0,0 @@ - -#include "Globals.h" - -#include "Promise.h" - -cPromise * cPromise::WaitFor(cPromise * a_Promise) -{ - return new cCombinedPromise(this, a_Promise); -} - -cPromise * cPromise::CancelOn(volatile bool& cancelation) -{ - return new cCancelablePromise(this, cancelation); -} - -void cPromise::Wait() -{ - while(!IsCompleted()){}; //busywait best we can do until waitany -} - - -cCombinedPromise::cCombinedPromise(cPromise* a_left, cPromise* a_right) : - cPromise(), - m_left(a_left), - m_right(a_right) -{ -} - -cCombinedPromise::~cCombinedPromise() -{ -} - -bool cCombinedPromise::IsCompleted() -{ - return m_left->IsCompleted() || m_right->IsCompleted(); -} - -cCancelablePromise::cCancelablePromise(cPromise* a_wrapped, volatile bool& a_cancel) : - cPromise(), - m_cancel(a_cancel), - m_wrapped(a_wrapped) -{ -} - -cCancelablePromise::~cCancelablePromise () -{ -} - -bool cCancelablePromise::IsCompleted() -{ - return m_cancel || m_wrapped->IsCompleted(); -} - - diff --git a/src/OSSupport/Promise.h b/src/OSSupport/Promise.h deleted file mode 100644 index 83d04860b..000000000 --- a/src/OSSupport/Promise.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -class cCombinedPromise; - - -class cPromise { - public: - cPromise() {} - virtual ~cPromise () {} - cPromise * WaitFor(cPromise * a_Promise); - cPromise * CancelOn(volatile bool& cancelationtoken); - void Wait(); - virtual bool IsCompleted() = 0; - //TODO:Expose Events for waiting on -}; - -class cCombinedPromise : public cPromise { -public: - cCombinedPromise(cPromise*, cPromise*); - ~cCombinedPromise(); - virtual bool IsCompleted(); -private: - cPromise* m_left; - cPromise* m_right; -}; - -class cCancelablePromise : public cPromise { -public: - cCancelablePromise(cPromise*, volatile bool&); - ~cCancelablePromise(); - virtual bool IsCompleted(); -private: - volatile bool& m_cancel; - cPromise* m_wrapped; -}; - - - diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index eb323b067..153e201c1 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -3,8 +3,6 @@ #include -#include "../OSSupport/Promise.h" - //this empty struct allows function inlining template struct cQueueFuncs @@ -52,6 +50,7 @@ public: if (m_contents.size() == 0) return false; item = m_contents.front(); m_contents.pop_front(); + m_evtRemoved.Set(); return true; } ItemType DequeueItem() @@ -62,10 +61,15 @@ public: cCSUnlock Unlock(m_CS); m_evtAdded.Wait(); } - return m_contents.pop_front(); + ItemType item = m_contents.front(); + m_contents.pop_front(); + m_evtRemoved.Set(); + return item; } - cPromise* BlockTillEmpty() { - return new cEmptyQueuePromise(this); + void BlockTillEmpty() { + //There is a very slight race condition here if the load completes between the check + //and the wait. + while(!(Size() == 0)){m_evtRemoved.Wait();} } //can all be inlined when delete is a noop void Clear() @@ -87,18 +91,12 @@ public: { cCSLock Lock(m_CS); m_contents.remove(item); + m_evtRemoved.Set(); } private: ListType m_contents; cCriticalSection m_CS; cEvent m_evtAdded; - - class cEmptyQueuePromise : public cPromise { - public: - cEmptyQueuePromise(cQueue* a_Queue) : cPromise(), m_Queue(a_Queue) {} - virtual bool IsCompleted() {return m_Queue->Size() != 0;} - private: - cQueue* m_Queue; - }; + cEvent m_evtRemoved; }; diff --git a/src/World.cpp b/src/World.cpp index cc543d460..39300d419 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -367,10 +367,13 @@ void cWorld::InitializeSpawn(void) cWorldLoadProgress Progress(this); // Wait for the loader to finish loading - m_Storage.WaitForQueuesEmpty(); + m_Storage.WaitForLoadQueueEmpty(); // Wait for the generator to finish generating m_Generator.WaitForQueueEmpty(); + + // Wait for the loader to finish saving + m_Storage.WaitForSaveQueueEmpty(); Progress.Stop(); } diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index c3bfbd4f6..9ad995c82 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -13,7 +13,6 @@ #include "../Generating/ChunkGenerator.h" #include "../Entities/Entity.h" #include "../BlockEntities/BlockEntity.h" -#include "../OSSupport/Promise.h" @@ -100,7 +99,7 @@ void cWorldStorage::WaitForFinish(void) } // Wait for the saving to finish: - WaitForQueuesEmpty(); + WaitForSaveQueueEmpty(); // Wait for the thread to finish: m_ShouldTerminate = true; @@ -114,21 +113,15 @@ void cWorldStorage::WaitForFinish(void) -void cWorldStorage::WaitForQueuesEmpty(void) +void cWorldStorage::WaitForLoadQueueEmpty(void) { - - cPromise * LoadPromise = m_LoadQueue.BlockTillEmpty(); - cPromise * SavePromise = m_SaveQueue.BlockTillEmpty(); - cPromise * QueuePromise = LoadPromise->WaitFor(SavePromise); - cPromise * CancelPromise = QueuePromise->CancelOn(m_ShouldTerminate); - CancelPromise->Wait(); - delete CancelPromise; - delete QueuePromise; - delete SavePromise; - delete LoadPromise; + m_LoadQueue.BlockTillEmpty(); } - +void cWorldStorage::WaitForSaveQueueEmpty(void) +{ + m_SaveQueue.BlockTillEmpty(); +} diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index c3eb96ce8..98eb5fce7 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -79,7 +79,8 @@ public: bool Start(cWorld * a_World, const AString & a_StorageSchemaName); // Hide the cIsThread's Start() method, we need to provide args void Stop(void); // Hide the cIsThread's Stop() method, we need to signal the event void WaitForFinish(void); - void WaitForQueuesEmpty(void); + void WaitForLoadQueueEmpty(void); + void WaitForSaveQueueEmpty(void); size_t GetLoadQueueLength(void); size_t GetSaveQueueLength(void); -- cgit v1.2.3 From c510683d2a64e75a667134ef0b63e9638c474c28 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 2 Jan 2014 17:33:18 +0100 Subject: Fixed unaligned memory access in FastNBT. This should fix #420. --- src/StringUtils.cpp | 30 ++++++++++++++++++++++++++++++ src/StringUtils.h | 9 +++++++++ src/WorldStorage/FastNBT.cpp | 10 +++++----- 3 files changed, 44 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index f7aeeed26..5c6b99d88 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -764,3 +764,33 @@ AString Base64Decode(const AString & a_Base64String) + +short GetBEShort(const char * a_Mem) +{ + return (((short)a_Mem[0]) << 8) | a_Mem[1]; +} + + + + + +int GetBEInt(const char * a_Mem) +{ + return (((int)a_Mem[0]) << 24) | (((int)a_Mem[1]) << 16) | (((int)a_Mem[2]) << 8) | a_Mem[3]; +} + + + + + +void SetBEInt(char * a_Mem, Int32 a_Value) +{ + a_Mem[0] = a_Value >> 24; + a_Mem[1] = (a_Value >> 16) & 0xff; + a_Mem[2] = (a_Value >> 8) & 0xff; + a_Mem[3] = a_Value & 0xff; +} + + + + diff --git a/src/StringUtils.h b/src/StringUtils.h index 3917cc4ec..471e843e4 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -81,6 +81,15 @@ extern AString ReplaceAllCharOccurrences(const AString & a_String, char a_From, /// Decodes a Base64-encoded string into the raw data extern AString Base64Decode(const AString & a_Base64String); +/// Reads two bytes from the specified memory location and interprets them as BigEndian short +extern short GetBEShort(const char * a_Mem); + +/// Reads four bytes from the specified memory location and interprets them as BigEndian int +extern int GetBEInt(const char * a_Mem); + +/// Writes four bytes to the specified memory location so that they interpret as BigEndian int +extern void SetBEInt(char * a_Mem, Int32 a_Value); + // If you have any other string helper functions, declare them here diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index e55011069..64220f09a 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -80,7 +80,7 @@ bool cParsedNBT::ReadString(int & a_StringStart, int & a_StringLen) { NEEDBYTES(2); a_StringStart = m_Pos + 2; - a_StringLen = ntohs(*((short *)(m_Data + m_Pos))); + a_StringLen = GetBEShort(m_Data + m_Pos); if (a_StringLen < 0) { // Invalid string length @@ -135,7 +135,7 @@ bool cParsedNBT::ReadList(eTagType a_ChildrenType) // Read the count: NEEDBYTES(4); - int Count = ntohl(*((int *)(m_Data + m_Pos))); + int Count = GetBEInt(m_Data + m_Pos); m_Pos += 4; if (Count < 0) { @@ -197,7 +197,7 @@ bool cParsedNBT::ReadTag(void) case TAG_ByteArray: { NEEDBYTES(4); - int len = ntohl(*((int *)(m_Data + m_Pos))); + int len = GetBEInt(m_Data + m_Pos); m_Pos += 4; if (len < 0) { @@ -229,7 +229,7 @@ bool cParsedNBT::ReadTag(void) case TAG_IntArray: { NEEDBYTES(4); - int len = ntohl(*((int *)(m_Data + m_Pos))); + int len = GetBEInt(m_Data + m_Pos); m_Pos += 4; if (len < 0) { @@ -401,7 +401,7 @@ void cFastNBTWriter::EndList(void) ASSERT(m_Stack[m_CurrentStack].m_Type == TAG_List); // Update the list count: - *((int *)(m_Result.c_str() + m_Stack[m_CurrentStack].m_Pos)) = htonl(m_Stack[m_CurrentStack].m_Count); + SetBEInt((char *)(m_Result.c_str() + m_Stack[m_CurrentStack].m_Pos), m_Stack[m_CurrentStack].m_Count); --m_CurrentStack; } -- cgit v1.2.3 From 15dddc77013f5366b77a73ca02f58680eaef9736 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 2 Jan 2014 18:08:38 +0100 Subject: More memory alignment fixes. Ref.: #420. --- src/Protocol/Protocol132.cpp | 6 +++--- src/WorldStorage/FastNBT.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 346607b79..46ac4ef89 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -886,15 +886,15 @@ void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const A time_t CurTime = time(NULL); CryptoPP::RandomPool rng; rng.Put((const byte *)&CurTime, sizeof(CurTime)); - byte DecryptedNonce[MAX_ENC_LEN]; - DecodingResult res = rsaDecryptor.Decrypt(rng, (const byte *)a_EncNonce.data(), a_EncNonce.size(), DecryptedNonce); + Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)]; + DecodingResult res = rsaDecryptor.Decrypt(rng, (const byte *)a_EncNonce.data(), a_EncNonce.size(), (byte *)DecryptedNonce); if (!res.isValidCoding || (res.messageLength != 4)) { LOGD("Bad nonce length"); m_Client->Kick("Hacked client"); return; } - if (ntohl(*((int *)DecryptedNonce)) != (unsigned)(uintptr_t)this) + if (ntohl(DecryptedNonce[0]) != (unsigned)(uintptr_t)this) { LOGD("Bad nonce value"); m_Client->Kick("Hacked client"); diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index 7323c29cb..b84eda1a1 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -154,13 +154,13 @@ public: inline Int16 GetShort(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Short); - return ntohs(*((Int16 *)(m_Data + m_Tags[a_Tag].m_DataStart))); + return GetBEShort(m_Data + m_Tags[a_Tag].m_DataStart); } inline Int32 GetInt(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Int); - return ntohl(*((Int32 *)(m_Data + m_Tags[a_Tag].m_DataStart))); + return GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); } inline Int64 GetLong(int a_Tag) const @@ -172,7 +172,7 @@ public: inline float GetFloat(int a_Tag) const { ASSERT(m_Tags[a_Tag].m_Type == TAG_Float); - Int32 tmp = ntohl(*((Int32 *)(m_Data + m_Tags[a_Tag].m_DataStart))); + Int32 tmp = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); return *((float *)&tmp); } -- cgit v1.2.3 From bbdb34252e9c1023405b58585fd5999cc8f39b45 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Thu, 2 Jan 2014 17:37:34 +0000 Subject: fixed a few remaining issues with worldstorage --- src/WorldStorage/WorldStorage.cpp | 21 +++------------------ src/WorldStorage/WorldStorage.h | 9 +++------ 2 files changed, 6 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index 9ad995c82..5f4c112d5 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -103,8 +103,7 @@ void cWorldStorage::WaitForFinish(void) // Wait for the thread to finish: m_ShouldTerminate = true; - m_Event.Set(); - m_evtRemoved.Set(); // Wake up anybody waiting in the WaitForQueuesEmpty() method + m_Event.Set(); // Wake up the thread if waiting super::Wait(); LOG("World storage thread finished"); } @@ -127,7 +126,6 @@ void cWorldStorage::WaitForSaveQueueEmpty(void) size_t cWorldStorage::GetLoadQueueLength(void) { - cCSLock Lock(m_CSQueues); return m_LoadQueue.Size(); } @@ -137,7 +135,6 @@ size_t cWorldStorage::GetLoadQueueLength(void) size_t cWorldStorage::GetSaveQueueLength(void) { - cCSLock Lock(m_CSQueues); return m_SaveQueue.Size(); } @@ -147,6 +144,7 @@ size_t cWorldStorage::GetSaveQueueLength(void) void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) { + m_Event.Set(); m_LoadQueue.EnqueueItemIfNotPresent(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); } @@ -156,6 +154,7 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { + m_Event.Set(); m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); } @@ -175,18 +174,6 @@ void cWorldStorage::QueueSavedMessage(void) void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { - /*cCSLock Lock(m_CSQueues); - for (sChunkLoadQueue::iterator itr = m_LoadQueue.begin(); itr != m_LoadQueue.end(); ++itr) - { - if ((itr->m_ChunkX != a_ChunkX) || (itr->m_ChunkY != a_ChunkY) || (itr->m_ChunkZ != a_ChunkZ)) - { - continue; - } - m_LoadQueue.erase(itr); - Lock.Unlock(); - m_evtRemoved.Set(); - return; - } // for itr - m_LoadQueue[]*/ m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ,true)); } @@ -245,7 +232,6 @@ void cWorldStorage::Execute(void) while (!m_ShouldTerminate) { m_Event.Wait(); - // Process both queues until they are empty again: bool Success; do @@ -258,7 +244,6 @@ void cWorldStorage::Execute(void) Success = LoadOneChunk(); Success |= SaveOneChunk(); - m_evtRemoved.Set(); } while (Success); } } diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index 98eb5fce7..06cae1717 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -116,15 +116,10 @@ protected: cWorld * m_World; AString m_StorageSchemaName; - - // Both queues are locked by the same CS - cCriticalSection m_CSQueues; + sChunkLoadQueue m_LoadQueue; cChunkCoordsQueue m_SaveQueue; - cEvent m_Event; // Set when there's any addition to the queues - cEvent m_evtRemoved; // Set when an item has been removed from the queue, either by the worker thread or the Unqueue methods - /// All the storage schemas (all used for loading) cWSSchemaList m_Schemas; @@ -135,6 +130,8 @@ protected: virtual void Execute(void) override; + cEvent m_Event; // Set when there's any addition to the queues + /// Loads one chunk from the queue (if any queued); returns true if there are more chunks in the load queue bool LoadOneChunk(void); -- cgit v1.2.3 From d522619ce2ac05831febedea675d121445dcbdbe Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Thu, 2 Jan 2014 17:43:57 +0000 Subject: added documentation --- src/OSSupport/Queue.h | 52 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index 153e201c1..1f0c19f40 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -1,34 +1,55 @@ +// Queue.h + +// Implements the cQueue class representing a thread safe queue + #pragma once #include -//this empty struct allows function inlining +/* +Usage: +To use the callback functions Delete and Combine create a class with the two +methods and pass it as a second template parameter to cQueue. The class does +not need to inherit cQueueFuncs but you do so to document the classes purpose. +The second template parmeter is optional if not overriding the callback +functions +*/ + +// this empty struct allows for the callback functions to be inlined template struct cQueueFuncs { public: + // Called when an Item is deleted form the queue without being returned static void Delete(T) {}; - static void Combine(T&, const T) {}; + // Called when an Item is inserted with EnqueueItemIfNotPresent and + // there is another equal value already inserted + static void Combine(T& a_existing, const T a_new) {}; }; template > class cQueue { - +// internal typedef for a List of Items typedef typename std::list ListType; -//magic typedef to persuade clang that the iterator is a type +// magic typedef to persuade clang that the iterator is a type typedef typename ListType::iterator iterator; public: cQueue() {} ~cQueue() {} + // Enqueues an item to the queue, may block if other threads are accessing + // the queue. void EnqueueItem(ItemType a_item) { cCSLock Lock(m_CS); m_contents.push_back(a_item); m_evtAdded.Set(); } + + // Enqueues an item to the queue if not already present as determined with + // operator ==. Will block other threads from accessing the queue. void EnqueueItemIfNotPresent(ItemType a_item) { cCSLock Lock(m_CS); @@ -44,6 +65,11 @@ public: m_contents.push_back(a_item); m_evtAdded.Set(); } + + // Dequeues an Item from the queue if any are present, provides no + // guarantees about success if the list is empty but an item is enqueued at + // the same time. Returns true if successful. Value of item is undefined if + // Dequeuing was unsuccessful. bool TryDequeueItem(ItemType& item) { cCSLock Lock(m_CS); @@ -53,6 +79,8 @@ public: m_evtRemoved.Set(); return true; } + + // Dequeues an Item from the Queue, blocking until an Item is Available. ItemType DequeueItem() { cCSLock Lock(m_CS); @@ -66,12 +94,17 @@ public: m_evtRemoved.Set(); return item; } + + // Blocks Until the queue is Empty, Has a slight race condition which may + // cause it to miss the queue being empty. void BlockTillEmpty() { - //There is a very slight race condition here if the load completes between the check - //and the wait. + // There is a very slight race condition here if the load completes between the check + // and the wait. while(!(Size() == 0)){m_evtRemoved.Wait();} } - //can all be inlined when delete is a noop + + // Removes all Items from the Queue, calling Delete on each of them. + // can all be inlined when delete is a noop void Clear() { cCSLock Lock(m_CS); @@ -82,11 +115,16 @@ public: m_contents.pop_front(); } } + + // Returns the Size at time of being called + // Do not use to detirmine weather to call DequeueItem, use TryDequeue instead size_t Size() { cCSLock Lock(m_CS); return m_contents.size(); } + + // Removes an Item from the queue bool Remove(ItemType item) { cCSLock Lock(m_CS); -- cgit v1.2.3 From 6f3c5b806eb59e2610f8bac9ad3fff24994609c9 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Fri, 3 Jan 2014 11:22:01 +0000 Subject: implement xsofts recommendations --- src/OSSupport/Queue.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index 1f0c19f40..65f9bd258 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -5,15 +5,18 @@ #pragma once -#include - /* +Items can be added multiple times to a queue, there are two functions for +adding, EnqueueItem() and EnqueueItemIfNotPresent(). The first one always +enqueues the specified item, the second one checks if the item is already +present and only queues it if it isn't. + Usage: -To use the callback functions Delete and Combine create a class with the two -methods and pass it as a second template parameter to cQueue. The class does -not need to inherit cQueueFuncs but you do so to document the classes purpose. -The second template parmeter is optional if not overriding the callback -functions +To create a queue of type T, instantiate a cQueue object. You can also +modify the behavior of the queue when deleting items and when adding items +that are already in the queue by providing a second parameter, a class that +implements the functions Delete() and Combine(). An example is given in +cQueueFuncs and is used as the default behavior. */ // this empty struct allows for the callback functions to be inlined @@ -25,7 +28,7 @@ struct cQueueFuncs static void Delete(T) {}; // Called when an Item is inserted with EnqueueItemIfNotPresent and // there is another equal value already inserted - static void Combine(T& a_existing, const T a_new) {}; + static void Combine(T& a_existing, const T& a_new) {}; }; template > @@ -73,7 +76,10 @@ public: bool TryDequeueItem(ItemType& item) { cCSLock Lock(m_CS); - if (m_contents.size() == 0) return false; + if (m_contents.size() == 0) + { + return false; + } item = m_contents.front(); m_contents.pop_front(); m_evtRemoved.Set(); -- cgit v1.2.3 From 0e8bb3bf415e4c0fe6c8bd0aa06dc2d9af2823c4 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 3 Jan 2014 08:34:41 -0800 Subject: fixed failure to return a value from Remove --- src/OSSupport/Queue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index 65f9bd258..bf6d7e451 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -134,8 +134,8 @@ public: bool Remove(ItemType item) { cCSLock Lock(m_CS); - m_contents.remove(item); m_evtRemoved.Set(); + return m_contents.remove(item); } private: -- cgit v1.2.3 From 14ec68d8d309d3fdf8e0af47196b1cf8609d017d Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 3 Jan 2014 08:49:14 -0800 Subject: actual fix --- src/OSSupport/Queue.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index bf6d7e451..fc942b3e1 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -134,8 +134,15 @@ public: bool Remove(ItemType item) { cCSLock Lock(m_CS); - m_evtRemoved.Set(); - return m_contents.remove(item); + for (iterator itr = m_contents.begin(); itr != m_contents.end(); ++itr) + { + if((*itr) == a_item) { + m_contents.erase(itr); + m_evtRemoved.Set(); + return true; + } + } + return false; } private: -- cgit v1.2.3 From 13bbb3d99dee8041d47279cae3484c3083491f18 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 3 Jan 2014 08:56:20 -0800 Subject: derp --- src/OSSupport/Queue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index fc942b3e1..ab42c871e 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -131,7 +131,7 @@ public: } // Removes an Item from the queue - bool Remove(ItemType item) + bool Remove(ItemType a_item) { cCSLock Lock(m_CS); for (iterator itr = m_contents.begin(); itr != m_contents.end(); ++itr) -- cgit v1.2.3 From d26c0e3815a8e3c38447eeb65b052a5d7c43da73 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 3 Jan 2014 09:42:35 -0800 Subject: Fixed Documentation --- src/OSSupport/Queue.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index ab42c871e..cde26e415 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -69,10 +69,8 @@ public: m_evtAdded.Set(); } - // Dequeues an Item from the queue if any are present, provides no - // guarantees about success if the list is empty but an item is enqueued at - // the same time. Returns true if successful. Value of item is undefined if - // Dequeuing was unsuccessful. + // Dequeues an Item from the queue if any are present. Returns true if + // successful. Value of item is undefined if Dequeuing was unsuccessful. bool TryDequeueItem(ItemType& item) { cCSLock Lock(m_CS); -- cgit v1.2.3 From 0a712931b1b547c7e7702ced73251e23dbc7737a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 5 Jan 2014 15:15:44 +0100 Subject: Fixed a race condition in the cQueue class. Fixes #505. --- src/OSSupport/Queue.h | 145 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 86 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index cde26e415..6c3d58295 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -19,123 +19,139 @@ implements the functions Delete() and Combine(). An example is given in cQueueFuncs and is used as the default behavior. */ -// this empty struct allows for the callback functions to be inlined +/// This empty struct allows for the callback functions to be inlined template struct cQueueFuncs { - public: - // Called when an Item is deleted form the queue without being returned - static void Delete(T) {}; - // Called when an Item is inserted with EnqueueItemIfNotPresent and - // there is another equal value already inserted - static void Combine(T& a_existing, const T& a_new) {}; +public: + + /// Called when an Item is deleted from the queue without being returned + static void Delete(T) {}; + + /// Called when an Item is inserted with EnqueueItemIfNotPresent and there is another equal value already inserted + static void Combine(T & a_existing, const T & a_new) {}; }; -template > + + + + +template > class cQueue { -// internal typedef for a List of Items -typedef typename std::list ListType; -// magic typedef to persuade clang that the iterator is a type -typedef typename ListType::iterator iterator; + // The actual storage type for the queue + typedef typename std::list QueueType; + + // Make iterator an alias for the QueueType's iterator + typedef typename QueueType::iterator iterator; + public: cQueue() {} ~cQueue() {} - // Enqueues an item to the queue, may block if other threads are accessing - // the queue. - void EnqueueItem(ItemType a_item) + + /// Enqueues an item to the queue, may block if other threads are accessing the queue. + void EnqueueItem(ItemType a_Item) { cCSLock Lock(m_CS); - m_contents.push_back(a_item); + m_Contents.push_back(a_Item); m_evtAdded.Set(); } - // Enqueues an item to the queue if not already present as determined with - // operator ==. Will block other threads from accessing the queue. - void EnqueueItemIfNotPresent(ItemType a_item) + + /// Enqueues an item in the queue if not already present (as determined by operator ==). Blocks other threads from accessing the queue. + void EnqueueItemIfNotPresent(ItemType a_Item) { cCSLock Lock(m_CS); - for (iterator itr = m_contents.begin(); itr != m_contents.end(); ++itr) + for (iterator itr = m_Contents.begin(); itr != m_Contents.end(); ++itr) { - if((*itr) == a_item) { - Funcs funcTable; - funcTable.Combine(*itr,a_item); + if ((*itr) == a_Item) + { + Funcs::Combine(*itr, a_Item); return; } } - m_contents.push_back(a_item); + m_Contents.push_back(a_Item); m_evtAdded.Set(); } - // Dequeues an Item from the queue if any are present. Returns true if - // successful. Value of item is undefined if Dequeuing was unsuccessful. - bool TryDequeueItem(ItemType& item) + + /// Dequeues an item from the queue if any are present. + /// Returns true if successful. Value of item is undefined if dequeuing was unsuccessful. + bool TryDequeueItem(ItemType & item) { cCSLock Lock(m_CS); - if (m_contents.size() == 0) + if (m_Contents.size() == 0) { return false; } - item = m_contents.front(); - m_contents.pop_front(); + item = m_Contents.front(); + m_Contents.pop_front(); m_evtRemoved.Set(); return true; } - // Dequeues an Item from the Queue, blocking until an Item is Available. - ItemType DequeueItem() + + /// Dequeues an item from the queue, blocking until an item is available. + ItemType DequeueItem(void) { cCSLock Lock(m_CS); - while (m_contents.size() == 0) + while (m_Contents.size() == 0) { - cCSUnlock Unlock(m_CS); + cCSUnlock Unlock(Lock); m_evtAdded.Wait(); } - ItemType item = m_contents.front(); - m_contents.pop_front(); + ItemType item = m_Contents.front(); + m_Contents.pop_front(); m_evtRemoved.Set(); return item; } - // Blocks Until the queue is Empty, Has a slight race condition which may - // cause it to miss the queue being empty. - void BlockTillEmpty() { - // There is a very slight race condition here if the load completes between the check - // and the wait. - while(!(Size() == 0)){m_evtRemoved.Wait();} + + /// Blocks until the queue is empty. + void BlockTillEmpty(void) + { + cCSLock Lock(m_CS); + while (!m_Contents.empty()) + { + cCSUnlock Unlock(Lock); + m_evtRemoved.Wait(); + } } - // Removes all Items from the Queue, calling Delete on each of them. - // can all be inlined when delete is a noop - void Clear() + + /// Removes all Items from the Queue, calling Delete on each of them. + void Clear(void) { cCSLock Lock(m_CS); - Funcs funcTable; - while (!m_contents.empty()) + while (!m_Contents.empty()) { - funcTable.Delete(m_contents.front()); - m_contents.pop_front(); + Funcs::Delete(m_Contents.front()); + m_Contents.pop_front(); } } - // Returns the Size at time of being called - // Do not use to detirmine weather to call DequeueItem, use TryDequeue instead - size_t Size() + + /// Returns the size at time of being called. + /// Do not use to determine whether to call DequeueItem(), use TryDequeueItem() instead + size_t Size(void) { cCSLock Lock(m_CS); - return m_contents.size(); + return m_Contents.size(); } - // Removes an Item from the queue - bool Remove(ItemType a_item) + + /// Removes the item from the queue. If there are multiple such items, only the first one is removed. + /// Returns true if the item has been removed, false if no such item found. + bool Remove(ItemType a_Item) { cCSLock Lock(m_CS); - for (iterator itr = m_contents.begin(); itr != m_contents.end(); ++itr) + for (iterator itr = m_Contents.begin(); itr != m_Contents.end(); ++itr) { - if((*itr) == a_item) { - m_contents.erase(itr); + if ((*itr) == a_Item) + { + m_Contents.erase(itr); m_evtRemoved.Set(); return true; } @@ -144,8 +160,19 @@ public: } private: - ListType m_contents; + /// The contents of the queue + QueueType m_Contents; + + /// Mutex that protects access to the queue contents cCriticalSection m_CS; + + /// Event that is signalled when an item is added cEvent m_evtAdded; + + /// Event that is signalled when an item is removed (both dequeued or erased) cEvent m_evtRemoved; }; + + + + -- cgit v1.2.3 From 84bf32f857f890ce50c82a2612fe1bfe072886c9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 5 Jan 2014 15:46:45 +0100 Subject: Fixed cPluginManager:AddHook() binding. Fixes #401. Old formats are still accepted, for compatibility reasons. --- src/Bindings/ManualBindings.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2e19c2581..64f542880 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1137,16 +1137,17 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S) { /* Function signatures: - cPluginManager.AddHook(HOOK_TYPE, CallbackFunction) -- (1) recommended - cPluginManager:Get():AddHook(HOOK_TYPE, CallbackFunction) -- (2) accepted silently - cPluginManager:Get():AddHook(Plugin, HOOK_TYPE) -- (3) old style (#121), accepted but complained about - cPluginManager.AddHook(Plugin, HOOK_TYPE) -- (4) old style (#121) mangled, accepted but complained about + cPluginManager:AddHook(HOOK_TYPE, CallbackFunction) -- (1) recommended + cPluginManager.AddHook(HOOK_TYPE, CallbackFunction) -- (2) accepted silently (#401 deprecates this) + cPluginManager:Get():AddHook(HOOK_TYPE, CallbackFunction) -- (3) accepted silently + cPluginManager:Get():AddHook(Plugin, HOOK_TYPE) -- (4) old style (#121), accepted but complained about in the console + cPluginManager.AddHook(Plugin, HOOK_TYPE) -- (5) old style (#121) mangled, accepted but complained about in the console */ cLuaState S(tolua_S); cPluginManager * PlgMgr = cPluginManager::Get(); - // If the first param is a cPluginManager, use it instead of the global one: + // If the first param is a cPluginManager instance, use it instead of the global one: int ParamIdx = 1; tolua_Error err; if (tolua_isusertype(S, 1, "cPluginManager", 0, &err)) @@ -1161,6 +1162,12 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S) } ParamIdx += 1; } + else if (tolua_isusertable(S, 1, "cPluginManager", 0, &err)) + { + LOGD("AddHook recommended style"); + // Style 1, use the global PlgMgr, but increment ParamIdx + ParamIdx++; + } if (lua_isnumber(S, ParamIdx) && lua_isfunction(S, ParamIdx + 1)) { @@ -1177,7 +1184,7 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S) AString ParamDesc; Printf(ParamDesc, "%s, %s, %s", S.GetTypeText(1).c_str(), S.GetTypeText(2).c_str(), S.GetTypeText(3).c_str()); - LOGWARNING("cPluginManager.AddHook(): bad parameters. Expected HOOK_TYPE and CallbackFunction, got %s. Hook not added.", ParamDesc.c_str()); + LOGWARNING("cPluginManager:AddHook(): bad parameters. Expected HOOK_TYPE and CallbackFunction, got %s. Hook not added.", ParamDesc.c_str()); S.LogStackTrace(); return 0; } -- cgit v1.2.3 From 0d5b581fcd07c0bb61373abd6b0404215c0b2301 Mon Sep 17 00:00:00 2001 From: Diusrex Date: Sun, 5 Jan 2014 14:42:22 -0700 Subject: Making all of the useful level 4 warnings be active. --- src/Globals.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Globals.h b/src/Globals.h index 58badf4dd..6a9b2050d 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -14,7 +14,19 @@ #pragma warning(disable:4481) // Disable some warnings that we don't care about: - #pragma warning(disable:4100) + #pragma warning(disable:4100) // Unreferenced formal parameter + + // Useful warnings from warning level 4: + #pragma warning(3 : 4189) // Local variable is initialized but not referenced + #pragma warning(3 : 4702) // Unreachable code + #pragma warning(3 : 4245) // Conversion from 'type1' to 'type2', signed/unsigned mismatch + #pragma warning(3 : 4389) // Signed/unsigned mismatch + #pragma warning(3 : 4701) // Potentially unitialized local variable used + #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data + #pragma warning(3 : 4310) // Cast truncates constant value + #pragma warning(3 : 4505) // Unreferenced local function has been removed + #pragma warning(3 : 4127) // Conditional expression is constant + #pragma warning(3 : 4706) // Assignment within conditional expression #define OBSOLETE __declspec(deprecated) -- cgit v1.2.3 From 2dbe5033ca30ce791e3cb28cc59f47d52225b7ae Mon Sep 17 00:00:00 2001 From: Diusrex Date: Sun, 5 Jan 2014 15:06:17 -0700 Subject: Added warning(push) and warning(pop) around all of the inclusions of cryptopp/*.h I also added a warning(push)/(pop) around crpytlib.cpp because it would go crazy with warnings. So now, the only warning from cryptopp that is not blocked is 'unreferenced local function has been removed', which also occurs at a single function. --- src/Protocol/Protocol132.cpp | 13 ++++++++++++- src/Protocol/Protocol132.h | 14 ++++++++++++++ src/Protocol/Protocol14x.cpp | 13 ++++++++++++- src/Protocol/Protocol17x.h | 14 ++++++++++++++ src/Server.h | 17 ++++++++++++++++- 5 files changed, 68 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 46ac4ef89..ab15509b7 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -5,7 +5,6 @@ #include "Globals.h" #include "ChunkDataSerializer.h" -#include "cryptopp/randpool.h" #include "Protocol132.h" #include "../Root.h" #include "../Server.h" @@ -19,8 +18,20 @@ #include "../WorldStorage/FastNBT.h" #include "../StringCompression.h" +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4127) + #pragma warning(disable:4244) + #pragma warning(disable:4231) + #pragma warning(disable:4189) + #pragma warning(disable:4702) +#endif +#include "cryptopp/randpool.h" +#ifdef _MSC_VER + #pragma warning(pop) +#endif #define HANDLE_PACKET_READ(Proc, Type, Var) \ diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index f76272b8d..d36384a88 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -10,9 +10,23 @@ #pragma once #include "Protocol125.h" + +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4127) + #pragma warning(disable:4244) + #pragma warning(disable:4231) + #pragma warning(disable:4189) + #pragma warning(disable:4702) +#endif + #include "cryptopp/modes.h" #include "cryptopp/aes.h" +#ifdef _MSC_VER + #pragma warning(pop) +#endif + diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp index 28122034c..926fe6ee8 100644 --- a/src/Protocol/Protocol14x.cpp +++ b/src/Protocol/Protocol14x.cpp @@ -16,7 +16,6 @@ Implements the 1.4.x protocol classes representing these protocols: #include "../Root.h" #include "../Server.h" #include "../ClientHandle.h" -#include "cryptopp/randpool.h" #include "../Item.h" #include "ChunkDataSerializer.h" #include "../Entities/Player.h" @@ -25,8 +24,20 @@ Implements the 1.4.x protocol classes representing these protocols: #include "../Entities/Pickup.h" #include "../Entities/FallingBlock.h" +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4127) + #pragma warning(disable:4244) + #pragma warning(disable:4231) + #pragma warning(disable:4189) + #pragma warning(disable:4702) +#endif +#include "cryptopp/randpool.h" +#ifdef _MSC_VER + #pragma warning(pop) +#endif #define HANDLE_PACKET_READ(Proc, Type, Var) \ diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index cc0eda1e7..23ff2365d 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -16,9 +16,23 @@ Declares the 1.7.x protocol classes: #include "Protocol.h" #include "../ByteBuffer.h" + +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4127) + #pragma warning(disable:4244) + #pragma warning(disable:4231) + #pragma warning(disable:4189) + #pragma warning(disable:4702) +#endif + #include "cryptopp/modes.h" #include "cryptopp/aes.h" +#ifdef _MSC_VER + #pragma warning(pop) +#endif + diff --git a/src/Server.h b/src/Server.h index 1f94bb3da..e62c4c7b7 100644 --- a/src/Server.h +++ b/src/Server.h @@ -11,9 +11,24 @@ #include "OSSupport/SocketThreads.h" #include "OSSupport/ListenThread.h" + +#include "RCONServer.h" + +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4127) + #pragma warning(disable:4244) + #pragma warning(disable:4231) + #pragma warning(disable:4189) + #pragma warning(disable:4702) +#endif + #include "cryptopp/rsa.h" #include "cryptopp/randpool.h" -#include "RCONServer.h" + +#ifdef _MSC_VER + #pragma warning(pop) +#endif -- cgit v1.2.3 From 1acbf07445d4dbd2d8badd3a4be709ebc4cb2a3e Mon Sep 17 00:00:00 2001 From: Diusrex Date: Sun, 5 Jan 2014 15:07:46 -0700 Subject: Changed the release version of ASSERT. This was so a variable only used in ASSERT statements will not give a warning about not being used. --- src/Globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Globals.h b/src/Globals.h index 6a9b2050d..a761da404 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -204,7 +204,7 @@ typedef unsigned short UInt16; #ifdef _DEBUG #define ASSERT( x ) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), assert(0), 0 ) ) #else - #define ASSERT(x) ((void)0) + #define ASSERT(x) ((void)(x)) #endif // Pretty much the same as ASSERT() but stays in Release builds -- cgit v1.2.3 From 487c1a24de3c375365c77232a47b99ddef0de68b Mon Sep 17 00:00:00 2001 From: Diusrex Date: Sun, 5 Jan 2014 15:08:30 -0700 Subject: Added fake functions into cCriticalSection because of the change to ASSERT --- src/OSSupport/CriticalSection.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/OSSupport/CriticalSection.h b/src/OSSupport/CriticalSection.h index 1bfe81439..73a71f5e1 100644 --- a/src/OSSupport/CriticalSection.h +++ b/src/OSSupport/CriticalSection.h @@ -14,9 +14,14 @@ public: void Lock(void); void Unlock(void); + // IsLocked/IsLockedByCurrentThread are only used in ASSERT statements, but because of the changes with ASSERT they must always be defined + // The fake versions (in Release) will not effect the program in any way #ifdef _DEBUG bool IsLocked(void); bool IsLockedByCurrentThread(void); + #else + bool IsLocked(void) { return false; } + bool IsLockedByCurrentThread(void) { return false; } #endif // _DEBUG private: -- cgit v1.2.3 From c9c71fe5a75992672013d021a918054b4795385b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 6 Jan 2014 10:09:00 +0100 Subject: Fixed wrong enqueueing. Fixes #505. --- src/WorldStorage/WorldStorage.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index 5f4c112d5..6aec525a8 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -117,6 +117,10 @@ void cWorldStorage::WaitForLoadQueueEmpty(void) m_LoadQueue.BlockTillEmpty(); } + + + + void cWorldStorage::WaitForSaveQueueEmpty(void) { m_SaveQueue.BlockTillEmpty(); @@ -124,6 +128,8 @@ void cWorldStorage::WaitForSaveQueueEmpty(void) + + size_t cWorldStorage::GetLoadQueueLength(void) { return m_LoadQueue.Size(); @@ -144,8 +150,8 @@ size_t cWorldStorage::GetSaveQueueLength(void) void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) { - m_Event.Set(); m_LoadQueue.EnqueueItemIfNotPresent(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); + m_Event.Set(); } @@ -154,8 +160,8 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { - m_Event.Set(); m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); + m_Event.Set(); } @@ -166,6 +172,7 @@ void cWorldStorage::QueueSavedMessage(void) { // Pushes a special coord pair into the queue, signalizing a message instead m_SaveQueue.EnqueueItem(cChunkCoords(0, CHUNK_Y_MESSAGE, 0)); + m_Event.Set(); } -- cgit v1.2.3 From 4b54f3e3ea9aa9cc80bd5eab9066b186e6dec25e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 6 Jan 2014 10:13:19 +0100 Subject: Output dir set to $/MCServer. Ref.: #510. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd06798ff..853138769 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,7 +66,7 @@ set(EXECUTABLE MCServer) add_executable(${EXECUTABLE} ${SOURCE}) -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/MCServer) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/MCServer) if (MSVC) # MSVC generator adds a "Debug" or "Release" postfixes to the EXECUTABLE_OUTPUT_PATH, we need to cancel them: -- cgit v1.2.3 From 0d5a5cc990a9674bdf53000285076491fce1356f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 6 Jan 2014 16:01:20 +0100 Subject: Exported cWorld::BroadcastBlockAction(). As requested in #508; no guarantees about it. --- src/World.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/World.h b/src/World.h index 67f1275c0..f90ddd90f 100644 --- a/src/World.h +++ b/src/World.h @@ -146,7 +146,7 @@ public: // Broadcast respective packets to all clients of the chunk where the event is taking place // (Please keep these alpha-sorted) void BroadcastAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle); - void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = NULL); + void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = NULL); // tolua_export void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL); void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export -- cgit v1.2.3 From 9c8af58b7546448e9168ca6d70b5ba9a7f4330d7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 6 Jan 2014 22:22:33 +0100 Subject: Fixed a few MSVC warnings. --- src/BlockEntities/FurnaceEntity.cpp | 8 ++++---- src/BlockEntities/HopperEntity.cpp | 1 - src/HTTPServer/HTTPConnection.cpp | 2 +- src/HTTPServer/HTTPFormParser.cpp | 1 - src/HTTPServer/NameValueParser.cpp | 1 - src/Item.cpp | 2 +- src/Item.h | 4 ++-- src/Protocol/Protocol132.cpp | 4 ++-- src/Protocol/Protocol15x.cpp | 2 +- src/Protocol/Protocol17x.cpp | 1 - src/Protocol/ProtocolRecognizer.cpp | 2 +- 11 files changed, 12 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index b1409f5cc..f15553968 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -70,8 +70,8 @@ void cFurnaceEntity::UsedBy(cPlayer * a_Player) if (a_Player->GetWindow() != Window) { a_Player->OpenWindow(Window); - BroadcastProgress(PROGRESSBAR_FUEL, m_LastProgressFuel); - BroadcastProgress(PROGRESSBAR_SMELTING, m_LastProgressCook); + BroadcastProgress(PROGRESSBAR_FUEL, (short)m_LastProgressFuel); + BroadcastProgress(PROGRESSBAR_SMELTING, (short)m_LastProgressCook); } } } @@ -445,14 +445,14 @@ void cFurnaceEntity::UpdateProgressBars(void) int CurFuel = (m_FuelBurnTime > 0) ? (200 - 200 * m_TimeBurned / m_FuelBurnTime) : 0; if ((CurFuel / 8) != (m_LastProgressFuel / 8)) { - BroadcastProgress(PROGRESSBAR_FUEL, CurFuel); + BroadcastProgress(PROGRESSBAR_FUEL, (short)CurFuel); m_LastProgressFuel = CurFuel; } int CurCook = (m_NeedCookTime > 0) ? (200 * m_TimeCooked / m_NeedCookTime) : 0; if ((CurCook / 8) != (m_LastProgressCook / 8)) { - BroadcastProgress(PROGRESSBAR_SMELTING, CurCook); + BroadcastProgress(PROGRESSBAR_SMELTING, (short)CurCook); m_LastProgressCook = CurCook; } } diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 0aca3209f..eac59e74d 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -488,7 +488,6 @@ bool cHopperEntity::MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_Blo // Feed the fuel slot of the furnace return MoveItemsToSlot(*Furnace, cFurnaceEntity::fsFuel); } - return false; } diff --git a/src/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index 68afdfc11..3d30ab177 100644 --- a/src/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp @@ -57,7 +57,7 @@ void cHTTPConnection::SendNeedAuth(const AString & a_Realm) void cHTTPConnection::Send(const cHTTPResponse & a_Response) { - ASSERT(m_State = wcsRecvIdle); + ASSERT(m_State == wcsRecvIdle); a_Response.AppendToData(m_OutgoingData); m_State = wcsSendingResp; m_HTTPServer.NotifyConnectionWrite(*this); diff --git a/src/HTTPServer/HTTPFormParser.cpp b/src/HTTPServer/HTTPFormParser.cpp index 01c68881a..e661ea6f9 100644 --- a/src/HTTPServer/HTTPFormParser.cpp +++ b/src/HTTPServer/HTTPFormParser.cpp @@ -133,7 +133,6 @@ bool cHTTPFormParser::HasFormData(const cHTTPRequest & a_Request) (a_Request.GetURL().find('?') != AString::npos) ) ); - return false; } diff --git a/src/HTTPServer/NameValueParser.cpp b/src/HTTPServer/NameValueParser.cpp index fd56f6b24..9ea8594ae 100644 --- a/src/HTTPServer/NameValueParser.cpp +++ b/src/HTTPServer/NameValueParser.cpp @@ -253,7 +253,6 @@ void cNameValueParser::Parse(const char * a_Data, int a_Size) m_State = psValueRaw; break; } - i++; } // while (i < a_Size) break; } // case psEqual diff --git a/src/Item.cpp b/src/Item.cpp index 196a260ef..a44515019 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -246,7 +246,7 @@ void cItems::Delete(int a_Idx) -void cItems::Set(int a_Idx, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemDamage) +void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDamage) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { diff --git a/src/Item.h b/src/Item.h index c60d0542c..64a30ade1 100644 --- a/src/Item.h +++ b/src/Item.h @@ -181,9 +181,9 @@ public: void Delete(int a_Idx); void Clear (void) {clear(); } int Size (void) {return size(); } - void Set (int a_Idx, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemDamage); + void Set (int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDamage); - void Add (ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemDamage) + void Add (short a_ItemType, char a_ItemCount, short a_ItemDamage) { push_back(cItem(a_ItemType, a_ItemCount, a_ItemDamage)); } diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index ab15509b7..302d1298c 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -877,7 +877,7 @@ void cProtocol132::SendCompass(const cWorld & a_World) void cProtocol132::SendEncryptionKeyRequest(void) { cCSLock Lock(m_CSPacket); - WriteByte((char)0xfd); + WriteByte(0xfd); WriteString(cRoot::Get()->GetServer()->GetServerID()); WriteShort((short)m_ServerPublicKey.size()); SendData(m_ServerPublicKey.data(), m_ServerPublicKey.size()); @@ -925,7 +925,7 @@ void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const A { // Send encryption key response: cCSLock Lock(m_CSPacket); - WriteByte((char)0xfc); + WriteByte(0xfc); WriteShort(0); WriteShort(0); Flush(); diff --git a/src/Protocol/Protocol15x.cpp b/src/Protocol/Protocol15x.cpp index 7e2aa9490..0f1e59f10 100644 --- a/src/Protocol/Protocol15x.cpp +++ b/src/Protocol/Protocol15x.cpp @@ -112,7 +112,7 @@ int cProtocol150::ParseWindowClick(void) } // Convert Button, Mode, SlotNum and HeldItem into eClickAction: - eClickAction Action; + eClickAction Action = caUnknown; switch ((Mode << 8) | Button) { case 0x0000: Action = (SlotNum != -999) ? caLeftClick : caLeftClickOutside; break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index bbbd5e973..8536689c3 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -986,7 +986,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) while (true) { UInt32 PacketLen; - int PacketStart = m_ReceivedData.GetDataStart(); if (!m_ReceivedData.ReadVarInt(PacketLen)) { // Not enough data diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 1cae4a750..e2ea0e6e5 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -198,7 +198,7 @@ void cProtocolRecognizer::SendDisconnect(const AString & a_Reason) else { // This is used when the client sends a server-ping, respond with the default packet: - WriteByte ((char)0xff); // PACKET_DISCONNECT + WriteByte (0xff); // PACKET_DISCONNECT WriteString(a_Reason); } } -- cgit v1.2.3 From 778c329ad2ff9af5595b695fc264b9fc2ad3d538 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 6 Jan 2014 22:23:03 +0100 Subject: Disabled the type conversion MSVC warning. It was hitting way too many false positives. --- src/Globals.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Globals.h b/src/Globals.h index a761da404..1765c53d8 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -22,11 +22,13 @@ #pragma warning(3 : 4245) // Conversion from 'type1' to 'type2', signed/unsigned mismatch #pragma warning(3 : 4389) // Signed/unsigned mismatch #pragma warning(3 : 4701) // Potentially unitialized local variable used - #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data #pragma warning(3 : 4310) // Cast truncates constant value #pragma warning(3 : 4505) // Unreferenced local function has been removed #pragma warning(3 : 4127) // Conditional expression is constant #pragma warning(3 : 4706) // Assignment within conditional expression + + // 2014_01_06 xoft: Disabled this warning because MSVC is stupid and reports it in obviously wrong places + // #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data #define OBSOLETE __declspec(deprecated) -- cgit v1.2.3 From e3bb82d95a0bf270f9d43d0504bf155b52dc516b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 7 Jan 2014 12:36:36 +0100 Subject: Added Base64Encode(). --- src/StringUtils.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/StringUtils.h | 3 +++ 2 files changed, 51 insertions(+) (limited to 'src') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 5c6b99d88..8d2352331 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -765,6 +765,54 @@ AString Base64Decode(const AString & a_Base64String) +AString Base64Encode(const AString & a_Input) +{ + static const char BASE64[64] = { + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', + 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', + 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', + 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' + }; + + std::string output; + output.resize(((a_Input.size() + 2) / 3) * 4); + + size_t output_index = 0; + size_t size_full24 = (a_Input.size() / 3) * 3; + + for (size_t i = 0; i < size_full24; i += 3) + { + output[output_index++] = BASE64[(unsigned char)a_Input[i] >> 2]; + output[output_index++] = BASE64[((unsigned char)a_Input[i] << 4 | (unsigned char)a_Input[i + 1] >> 4) & 63]; + output[output_index++] = BASE64[((unsigned char)a_Input[i + 1] << 2 | (unsigned char)a_Input[i + 2] >> 6) & 63]; + output[output_index++] = BASE64[(unsigned char)a_Input[i + 2] & 63]; + } + + if (size_full24 < a_Input.size()) + { + output[output_index++] = BASE64[(unsigned char)a_Input[size_full24] >> 2]; + if (size_full24 + 1 == a_Input.size()) + { + output[output_index++] = BASE64[((unsigned char)a_Input[size_full24] << 4) & 63]; + output[output_index++] = '='; + } + else + { + output[output_index++] = BASE64[((unsigned char)a_Input[size_full24] << 4 | (unsigned char)a_Input[size_full24 + 1] >> 4) & 63]; + output[output_index++] = BASE64[((unsigned char)a_Input[size_full24 + 1] << 2) & 63]; + } + + output[output_index++] = '='; + } + assert(output_index == output.size()); + + return output; +} + + + + + short GetBEShort(const char * a_Mem) { return (((short)a_Mem[0]) << 8) | a_Mem[1]; diff --git a/src/StringUtils.h b/src/StringUtils.h index 471e843e4..2373f3843 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -81,6 +81,9 @@ extern AString ReplaceAllCharOccurrences(const AString & a_String, char a_From, /// Decodes a Base64-encoded string into the raw data extern AString Base64Decode(const AString & a_Base64String); +/// Encodes a string into Base64 +extern AString Base64Encode(const AString & a_Input); + /// Reads two bytes from the specified memory location and interprets them as BigEndian short extern short GetBEShort(const char * a_Mem); -- cgit v1.2.3 From 934b90c121def4f6f9a7c919727cadeeca49981f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 7 Jan 2014 14:24:25 +0100 Subject: Fixed a few MSVC warnings. --- src/BlockArea.cpp | 6 +++--- src/Generating/Caves.cpp | 8 ++++---- src/Generating/DistortedHeightmap.cpp | 3 ++- src/Generating/FinishGen.cpp | 2 +- src/Items/ItemSeeds.h | 1 - src/Protocol/Protocol132.h | 4 ++-- src/Protocol/Protocol17x.cpp | 2 +- src/WorldStorage/FastNBT.cpp | 13 ++++++++----- 8 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index dd8e0da31..910661f60 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -828,7 +828,7 @@ void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int int yd = dy - dx / 2; int zd = dz - dx / 2; - while (true) + for (;;) { RelSetData(a_RelX1, a_RelY1, a_RelZ1, a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight); @@ -860,7 +860,7 @@ void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int int xd = dx - dy / 2; int zd = dz - dy / 2; - while (true) + for (;;) { RelSetData(a_RelX1, a_RelY1, a_RelZ1, a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight); @@ -894,7 +894,7 @@ void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int int xd = dx - dz / 2; int yd = dy - dz / 2; - while (true) + for (;;) { RelSetData(a_RelX1, a_RelY1, a_RelZ1, a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight); diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index df45bb4c2..c94113f5c 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -285,7 +285,7 @@ bool cCaveTunnel::RefineDefPoints(const cCaveDefPoints & a_Src, cCaveDefPoints & void cCaveTunnel::Smooth(void) { cCaveDefPoints Pts; - while (true) + for (;;) { if (!RefineDefPoints(m_Points, Pts)) { @@ -331,7 +331,7 @@ void cCaveTunnel::FinishLinear(void) int yd = dy - dx / 2; int zd = dz - dx / 2; - while (true) + for (;;) { m_Points.push_back(cCaveDefPoint(PrevX, PrevY, PrevZ, R)); @@ -363,7 +363,7 @@ void cCaveTunnel::FinishLinear(void) int xd = dx - dy / 2; int zd = dz - dy / 2; - while (true) + for (;;) { m_Points.push_back(cCaveDefPoint(PrevX, PrevY, PrevZ, R)); @@ -397,7 +397,7 @@ void cCaveTunnel::FinishLinear(void) int xd = dx - dz / 2; int yd = dy - dz / 2; - while (true) + for (;;) { m_Points.push_back(cCaveDefPoint(PrevX, PrevY, PrevZ, R)); diff --git a/src/Generating/DistortedHeightmap.cpp b/src/Generating/DistortedHeightmap.cpp index 15e352e30..eb9fe92ba 100644 --- a/src/Generating/DistortedHeightmap.cpp +++ b/src/Generating/DistortedHeightmap.cpp @@ -774,10 +774,11 @@ void cDistortedHeightmap::ComposeColumn(cChunkDesc & a_ChunkDesc, int a_RelX, in return; } default: + { ASSERT(!"Unhandled biome"); return; + } } // switch (Biome) - ASSERT(!"Unexpected fallthrough"); } diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 866551e8a..145fe22e0 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -528,7 +528,7 @@ cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cI bool IsWater = (a_Fluid == E_BLOCK_WATER); AString SectionName = IsWater ? "WaterSprings" : "LavaSprings"; AString DefaultHeightDistribution; - int DefaultChance; + int DefaultChance = 0; switch (a_World.GetDimension()) { case dimNether: diff --git a/src/Items/ItemSeeds.h b/src/Items/ItemSeeds.h index 8ca86663f..67f0d38bd 100644 --- a/src/Items/ItemSeeds.h +++ b/src/Items/ItemSeeds.h @@ -56,7 +56,6 @@ public: case E_ITEM_SEEDS: a_BlockType = E_BLOCK_CROPS; return true; default: a_BlockType = E_BLOCK_AIR; return true; } - return false; } } ; diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index d36384a88..80fc8740a 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -14,9 +14,9 @@ #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4127) - #pragma warning(disable:4244) - #pragma warning(disable:4231) #pragma warning(disable:4189) + #pragma warning(disable:4231) + #pragma warning(disable:4244) #pragma warning(disable:4702) #endif diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 8536689c3..7d1f723a3 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -983,7 +983,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) } // Handle all complete packets: - while (true) + for (;;) { UInt32 PacketLen; if (!m_ReceivedData.ReadVarInt(PacketLen)) diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index 64220f09a..8f80c3f75 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -16,9 +16,12 @@ #define NBT_RESERVE_SIZE 200 #endif // NBT_RESERVE_SIZE -#define RETURN_FALSE_IF_FALSE(X) do { if (!X) return false; } while (0) - - +#ifdef _MSC_VER + // Dodge a C4127 (conditional expression is constant) for this specific macro usage + #define RETURN_FALSE_IF_FALSE(X) do { if (!X) return false; } while ((false, false)) +#else + #define RETURN_FALSE_IF_FALSE(X) do { if (!X) return false; } while (false) +#endif @@ -99,7 +102,7 @@ bool cParsedNBT::ReadCompound(void) // Reads the latest tag as a compound int ParentIdx = m_Tags.size() - 1; int PrevSibling = -1; - while (true) + for (;;) { NEEDBYTES(1); eTagType TagType = (eTagType)(m_Data[m_Pos]); @@ -276,7 +279,7 @@ int cParsedNBT::FindChildByName(int a_Tag, const char * a_Name, size_t a_NameLen for (int Child = m_Tags[a_Tag].m_FirstChild; Child != -1; Child = m_Tags[Child].m_NextSibling) { if ( - (m_Tags[Child].m_NameLength == a_NameLength) && + (m_Tags[Child].m_NameLength == (int)a_NameLength) && (memcmp(m_Data + m_Tags[Child].m_NameStart, a_Name, a_NameLength) == 0) ) { -- cgit v1.2.3 From 913841f50115379ebaaba1cb88c3f1cdfed09320 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:31:06 -0600 Subject: Implement favicon for 1.7.2 Favicon data is a png encoded in base64 which is stored in the server and sent in the server response packet --- src/Protocol/Protocol17x.cpp | 13 +++++++++++++ src/Protocol/Protocol17x.h | 1 + src/Server.cpp | 11 +++++++++++ src/Server.h | 3 +++ 4 files changed, 28 insertions(+) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index bbbd5e973..c75fc9878 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -383,6 +383,16 @@ void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc +void cProtocol172::SendFavicon(void) +{ + cPacketizer Pkt(*this, 0x0); // Favicon packet + Pkt.WriteString(cRoot::Get()->GetServer()->GetFaviconData()); +} + + + + + void cProtocol172::SendGameMode(eGameMode a_GameMode) { cPacketizer Pkt(*this, 0x2b); // Change Game State packet @@ -1116,6 +1126,9 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) AppendPrintf(Response, "\"description\":{\"text\":\"%s\"}", cRoot::Get()->GetServer()->GetDescription().c_str() ); + AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", + cRoot::Get()->GetServer()->GetFaviconData() + ); Response.append("}"); cPacketizer Pkt(*this, 0x00); // Response packet diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 23ff2365d..29fc75ee4 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -72,6 +72,7 @@ public: virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; virtual void SendEntityVelocity (const cEntity & a_Entity) override; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; + virtual void SendFavicon (void); virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; diff --git a/src/Server.cpp b/src/Server.cpp index 7dedc3904..e5050f321 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -203,6 +203,8 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) m_PlayerCount = 0; m_PlayerCountDiff = 0; + if (cFile::Exists("favicon.png")) m_Favicon = Base64Encode(cFile::ReadWholeFile("favicon.png")); + if (m_bIsConnected) { LOGERROR("ERROR: Trying to initialize server while server is already running!"); @@ -289,6 +291,15 @@ int cServer::GetNumPlayers(void) +AString cServer::GetFaviconData(void) +{ + return m_Favicon; +} + + + + + void cServer::PrepareKeys(void) { // TODO: Save and load key for persistence across sessions diff --git a/src/Server.h b/src/Server.h index e62c4c7b7..e33264277 100644 --- a/src/Server.h +++ b/src/Server.h @@ -106,6 +106,8 @@ public: // tolua_export /// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players void PlayerDestroying(const cPlayer * a_Player); + + AString GetFaviconData(void); CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } @@ -183,6 +185,7 @@ private: cRCONServer m_RCONServer; AString m_Description; + AString m_Favicon; int m_MaxPlayers; bool m_bIsHardcore; -- cgit v1.2.3 From 5fd62f9cd7c1a1594b6331a79f2b375bc0dfb9e2 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:38:51 -0600 Subject: Removed unused line --- src/Protocol/Protocol17x.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 29fc75ee4..23ff2365d 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -72,7 +72,6 @@ public: virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; virtual void SendEntityVelocity (const cEntity & a_Entity) override; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; - virtual void SendFavicon (void); virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; -- cgit v1.2.3 From ede6757f6731fbdabb07092f8785fa09a59c5375 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:40:59 -0600 Subject: A few touch ups --- src/Server.cpp | 5 ++++- src/Server.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Server.cpp b/src/Server.cpp index e5050f321..0afd8958d 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -203,7 +203,10 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) m_PlayerCount = 0; m_PlayerCountDiff = 0; - if (cFile::Exists("favicon.png")) m_Favicon = Base64Encode(cFile::ReadWholeFile("favicon.png")); + if (cFile::Exists("favicon.png")) + { + m_FaviconData = Base64Encode(cFile::ReadWholeFile("favicon.png")); + } if (m_bIsConnected) { diff --git a/src/Server.h b/src/Server.h index e33264277..62fdf225a 100644 --- a/src/Server.h +++ b/src/Server.h @@ -185,7 +185,7 @@ private: cRCONServer m_RCONServer; AString m_Description; - AString m_Favicon; + AString m_FaviconData; int m_MaxPlayers; bool m_bIsHardcore; -- cgit v1.2.3 From 1c2eb4a1c07167e2fb53f9398383d3fda0940b0b Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:49:52 -0600 Subject: A few more touch ups --- src/Protocol/Protocol17x.cpp | 12 +----------- src/Server.cpp | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index c75fc9878..2d00776ae 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -383,16 +383,6 @@ void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc -void cProtocol172::SendFavicon(void) -{ - cPacketizer Pkt(*this, 0x0); // Favicon packet - Pkt.WriteString(cRoot::Get()->GetServer()->GetFaviconData()); -} - - - - - void cProtocol172::SendGameMode(eGameMode a_GameMode) { cPacketizer Pkt(*this, 0x2b); // Change Game State packet @@ -1127,7 +1117,7 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) cRoot::Get()->GetServer()->GetDescription().c_str() ); AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", - cRoot::Get()->GetServer()->GetFaviconData() + cRoot::Get()->GetServer()->GetFaviconData().c_str() ); Response.append("}"); diff --git a/src/Server.cpp b/src/Server.cpp index 0afd8958d..30c401d59 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -296,7 +296,7 @@ int cServer::GetNumPlayers(void) AString cServer::GetFaviconData(void) { - return m_Favicon; + return m_FaviconData; } -- cgit v1.2.3 From bcd41dc1aafcbfc12803e5326f80ee0b5ebf7fdf Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 7 Jan 2014 15:55:23 +0100 Subject: LuaState can push strings with embedded NULs. This also marginally improves performance, since a strlen() isn't called (inside lua_pushstring()), the string length is stored in the AString object directly. --- src/Bindings/LuaState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index a684620f3..83351591c 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -297,7 +297,7 @@ void cLuaState::Push(const AString & a_String) { ASSERT(IsValid()); - tolua_pushcppstring(m_LuaState, a_String); + lua_pushlstring(m_LuaState, a_String.data(), a_String.size()); m_NumCurrentFunctionArgs += 1; } -- cgit v1.2.3 From 39a1bcdea0a5897a7090748529e3b903918882ec Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 7 Jan 2014 16:00:19 +0100 Subject: More MSVC warning fixes. --- src/ChunkMap.cpp | 2 +- src/Generating/Ravines.cpp | 2 +- src/HTTPServer/MultipartParser.cpp | 2 +- src/LightingThread.cpp | 2 +- src/LineBlockTracer.cpp | 2 +- src/Server.cpp | 2 +- src/StringCompression.cpp | 4 ++-- src/StringUtils.cpp | 2 +- src/UI/SlotArea.cpp | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 86fbceff7..e14090b18 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -991,7 +991,7 @@ bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) int cChunkMap::GetHeight(int a_BlockX, int a_BlockZ) { - while (true) + for (;;) { cCSLock Lock(m_CSLayers); int ChunkX, ChunkZ, BlockY = 0; diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index 6413b963b..cfda47e32 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -381,7 +381,7 @@ void cStructGenRavines::cRavine::FinishLinear(void) int R = itr->m_Radius; int T = itr->m_Top; int B = itr->m_Bottom; - while (true) + for (;;) { m_Points.push_back(cRavDefPoint(PrevX, PrevZ, R, T, B)); if ((PrevX == x1) && (PrevZ == z1)) diff --git a/src/HTTPServer/MultipartParser.cpp b/src/HTTPServer/MultipartParser.cpp index b49f6ec07..14c2c00fa 100644 --- a/src/HTTPServer/MultipartParser.cpp +++ b/src/HTTPServer/MultipartParser.cpp @@ -156,7 +156,7 @@ void cMultipartParser::Parse(const char * a_Data, int a_Size) // Append to buffer, then parse it: m_IncomingData.append(a_Data, a_Size); - while (true) + for (;;) { if (m_EnvelopeParser.IsInHeaders()) { diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 7c3cc9c76..a823c08cc 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -216,7 +216,7 @@ void cLightingThread::ChunkReady(int a_ChunkX, int a_ChunkZ) void cLightingThread::Execute(void) { - while (true) + for (;;) { { cCSLock Lock(m_CS); diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index 110c6b5dc..da1c7f2fd 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -196,7 +196,7 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk) ASSERT((m_CurrentY >= 0) && (m_CurrentY < cChunkDef::Height)); // This should be provided by FixStartAboveWorld() / FixStartBelowWorld() // This is the actual line tracing loop. - while (true) + for (;;) { // Report the current block through the callbacks: if (a_Chunk == NULL) diff --git a/src/Server.cpp b/src/Server.cpp index 7dedc3904..e707235a8 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -493,7 +493,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac if (split[0].compare("killmem") == 0) { - while (true) + for (;;) { new char[100 * 1024 * 1024]; // Allocate and leak 100 MiB in a loop -> fill memory and kill MCS } diff --git a/src/StringCompression.cpp b/src/StringCompression.cpp index 36946b282..e15058840 100644 --- a/src/StringCompression.cpp +++ b/src/StringCompression.cpp @@ -74,7 +74,7 @@ int CompressStringGZIP(const char * a_Data, int a_Length, AString & a_Compressed return res; } - while (true) + for (;;) { res = deflate(&strm, Z_FINISH); switch (res) @@ -137,7 +137,7 @@ extern int UncompressStringGZIP(const char * a_Data, int a_Length, AString & a_U return res; } - while (true) + for (;;) { res = inflate(&strm, Z_FINISH); switch (res) diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 8d2352331..e6deb0705 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -612,7 +612,7 @@ AString StripColorCodes(const AString & a_Message) { AString res(a_Message); size_t idx = 0; - while (true) + for (;;) { idx = res.find("\xc2\xa7", idx); if (idx == AString::npos) diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 61e432665..a721e6b7e 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -491,7 +491,7 @@ void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player) return; } cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; - do + for (;;) { // Try distributing the result. If it fails, bail out: cItem ResultCopy(Result); @@ -517,7 +517,7 @@ void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player) // The recipe has changed, bail out return; } - } while (true); + } } -- cgit v1.2.3 From 8b9b09bf60860a591c78cce07dbc1c35804bd7c2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 7 Jan 2014 16:10:39 +0100 Subject: Removed a debugging log output in cPluginManager:AddHook(). --- src/Bindings/ManualBindings.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 64f542880..6221727c4 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1164,7 +1164,6 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S) } else if (tolua_isusertable(S, 1, "cPluginManager", 0, &err)) { - LOGD("AddHook recommended style"); // Style 1, use the global PlgMgr, but increment ParamIdx ParamIdx++; } -- cgit v1.2.3 From a33b157dc9748e5126176df20fde5e96541b55f9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 7 Jan 2014 17:15:08 +0100 Subject: Disabled an unneeded MSVC warning. Also sorted the enabled warnings by their numerical code for easier searching.. --- src/Globals.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Globals.h b/src/Globals.h index 1765c53d8..f886ba2d0 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -17,16 +17,19 @@ #pragma warning(disable:4100) // Unreferenced formal parameter // Useful warnings from warning level 4: + #pragma warning(3 : 4127) // Conditional expression is constant #pragma warning(3 : 4189) // Local variable is initialized but not referenced - #pragma warning(3 : 4702) // Unreachable code #pragma warning(3 : 4245) // Conversion from 'type1' to 'type2', signed/unsigned mismatch - #pragma warning(3 : 4389) // Signed/unsigned mismatch - #pragma warning(3 : 4701) // Potentially unitialized local variable used #pragma warning(3 : 4310) // Cast truncates constant value + #pragma warning(3 : 4389) // Signed/unsigned mismatch #pragma warning(3 : 4505) // Unreferenced local function has been removed - #pragma warning(3 : 4127) // Conditional expression is constant + #pragma warning(3 : 4701) // Potentially unitialized local variable used + #pragma warning(3 : 4702) // Unreachable code #pragma warning(3 : 4706) // Assignment within conditional expression + // Disabling this warning, because we know what we're doing when we're doing this: + #pragma warning(disable: 4355) // 'this' used in initializer list + // 2014_01_06 xoft: Disabled this warning because MSVC is stupid and reports it in obviously wrong places // #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data -- cgit v1.2.3 From 5012b81578396154150cb4696d57c455766e22f2 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 10:26:56 -0600 Subject: Avoid making copies of favicon string --- src/Server.cpp | 2 +- src/Server.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Server.cpp b/src/Server.cpp index 30c401d59..e2a73541a 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -294,7 +294,7 @@ int cServer::GetNumPlayers(void) -AString cServer::GetFaviconData(void) +const AString & cServer::GetFaviconData(void) const { return m_FaviconData; } diff --git a/src/Server.h b/src/Server.h index 62fdf225a..2609b6874 100644 --- a/src/Server.h +++ b/src/Server.h @@ -107,7 +107,7 @@ public: // tolua_export /// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players void PlayerDestroying(const cPlayer * a_Player); - AString GetFaviconData(void); + const AString & GetFaviconData(void) const; CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } -- cgit v1.2.3 From e353f29d4ab5deec7ac8b3aac5f3f5c2b8fa56e9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 7 Jan 2014 17:47:05 +0100 Subject: Plugin messages are received and handed to plugins. Note that MCS doesn't currently handle any channel registrations, this will come later on. --- src/Bindings/Plugin.h | 1 + src/Bindings/PluginLua.cpp | 33 ++++++++++++++++++++++++++++++++- src/Bindings/PluginLua.h | 1 + src/Bindings/PluginManager.cpp | 21 +++++++++++++++++++++ src/Bindings/PluginManager.h | 2 ++ src/ClientHandle.cpp | 9 +++++++++ src/ClientHandle.h | 1 + src/Protocol/Protocol17x.cpp | 2 +- 8 files changed, 68 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 2c893a65d..f4a117721 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -84,6 +84,7 @@ public: virtual bool OnPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0; virtual bool OnPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0; + virtual bool OnPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) = 0; virtual bool OnPluginsLoaded (void) = 0; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 87212ed85..209842e55 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -950,6 +950,26 @@ bool cPluginLua::OnPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_Block +bool cPluginLua::OnPluginMessage(cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLUGIN_MESSAGE]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Client, a_Channel, a_Message); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnPluginsLoaded(void) { cCSLock Lock(m_CriticalSection); @@ -1382,6 +1402,8 @@ const char * cPluginLua::GetHookFnName(int a_HookType) case cPluginManager::HOOK_PLAYER_USED_ITEM: return "OnPlayerUsedItem"; case cPluginManager::HOOK_PLAYER_USING_BLOCK: return "OnPlayerUsingBlock"; case cPluginManager::HOOK_PLAYER_USING_ITEM: return "OnPlayerUsingItem"; + case cPluginManager::HOOK_PLUGIN_MESSAGE: return "OnPluginMessage"; + case cPluginManager::HOOK_PLUGINS_LOADED: return "OnPluginsLoaded"; case cPluginManager::HOOK_POST_CRAFTING: return "OnPostCrafting"; case cPluginManager::HOOK_PRE_CRAFTING: return "OnPreCrafting"; case cPluginManager::HOOK_SPAWNED_ENTITY: return "OnSpawnedEntity"; @@ -1395,8 +1417,17 @@ const char * cPluginLua::GetHookFnName(int a_HookType) case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged"; case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging"; case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick"; - default: return NULL; + + case cPluginManager::HOOK_NUM_HOOKS: + { + // Satisfy a warning that all enum values should be used in a switch + // but don't want a default branch, so that we catch new hooks missing from this list. + break; + } } // switch (a_Hook) + LOGWARNING("Requested name of an unknown hook type function: %d (max is %d)", a_HookType, cPluginManager::HOOK_MAX); + ASSERT(!"Unknown hook requested!"); + return NULL; } diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index a47ab32e0..c01f5ca89 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -81,6 +81,7 @@ public: virtual bool OnPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual bool OnPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; + virtual bool OnPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) override; virtual bool OnPluginsLoaded (void) override; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 3a6c542b1..68e6aea33 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1030,6 +1030,27 @@ bool cPluginManager::CallHookPlayerUsingItem(cPlayer & a_Player, int a_BlockX, i +bool cPluginManager::CallHookPluginMessage(cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PLUGIN_MESSAGE); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPluginMessage(a_Client, a_Channel, a_Message)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookPluginsLoaded(void) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLUGINS_LOADED); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 16c64d86f..9936f5a35 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -96,6 +96,7 @@ public: // tolua_export HOOK_PLAYER_USED_ITEM, HOOK_PLAYER_USING_BLOCK, HOOK_PLAYER_USING_ITEM, + HOOK_PLUGIN_MESSAGE, HOOK_PLUGINS_LOADED, HOOK_POST_CRAFTING, HOOK_PRE_CRAFTING, @@ -186,6 +187,7 @@ public: // tolua_export bool CallHookPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); bool CallHookPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); + bool CallHookPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message); bool CallHookPluginsLoaded (void); bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 17412c265..8125acb47 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -543,6 +543,15 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, +void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message) +{ + cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message); +} + + + + + void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) { LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i", diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 26d5e74b7..bc17df780 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -178,6 +178,7 @@ public: void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround); void HandlePlayerMoveLook (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround); // While m_bPositionConfirmed (normal gameplay) void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround); + void HandlePluginMessage (const AString & a_Channel, const AString & a_Message); void HandleRespawn (void); void HandleRightClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem); void HandleSlotSelected (short a_SlotNum); diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 4d08df2d9..5947415dd 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1376,7 +1376,7 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEShort, short, Length); AString Data; a_ByteBuffer.ReadString(Data, Length); - // TODO: m_Client->HandlePluginMessage(Channel, Data); + m_Client->HandlePluginMessage(Channel, Data); } -- cgit v1.2.3 From 1d96a615b5d1578912ec2e95c03dee6781cb3396 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 7 Jan 2014 16:53:40 +0000 Subject: Fixed favicons --- src/Protocol/Protocol17x.cpp | 2 +- src/Server.cpp | 14 +------------- src/Server.h | 3 ++- src/StringUtils.cpp | 7 ++++--- 4 files changed, 8 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 4d08df2d9..e1ba4936f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1112,7 +1112,7 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) cRoot::Get()->GetServer()->GetMaxPlayers(), cRoot::Get()->GetServer()->GetNumPlayers() ); - AppendPrintf(Response, "\"description\":{\"text\":\"%s\"}", + AppendPrintf(Response, "\"description\":{\"text\":\"%s\"},", cRoot::Get()->GetServer()->GetDescription().c_str() ); AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", diff --git a/src/Server.cpp b/src/Server.cpp index b0439391c..49067c17f 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -203,10 +203,7 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) m_PlayerCount = 0; m_PlayerCountDiff = 0; - if (cFile::Exists("favicon.png")) - { - m_FaviconData = Base64Encode(cFile::ReadWholeFile("favicon.png")); - } + m_FaviconData = Base64Encode(cFile::ReadWholeFile("favicon.png")); // Will return empty string if file nonexistant; client doesn't mind if (m_bIsConnected) { @@ -294,15 +291,6 @@ int cServer::GetNumPlayers(void) -const AString & cServer::GetFaviconData(void) const -{ - return m_FaviconData; -} - - - - - void cServer::PrepareKeys(void) { // TODO: Save and load key for persistence across sessions diff --git a/src/Server.h b/src/Server.h index 2609b6874..d79417fb0 100644 --- a/src/Server.h +++ b/src/Server.h @@ -107,7 +107,8 @@ public: // tolua_export /// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players void PlayerDestroying(const cPlayer * a_Player); - const AString & GetFaviconData(void) const; + /* Returns base64 encoded favicon data (obtained from favicon.png) */ + const AString & GetFaviconData(void) const { return m_FaviconData; } CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index e6deb0705..5d16616c5 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -759,7 +759,8 @@ AString Base64Decode(const AString & a_Base64String) } } res.resize(o >> 3); - return res;} + return res; +} @@ -774,7 +775,7 @@ AString Base64Encode(const AString & a_Input) 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; - std::string output; + AString output; output.resize(((a_Input.size() + 2) / 3) * 4); size_t output_index = 0; @@ -804,7 +805,7 @@ AString Base64Encode(const AString & a_Input) output[output_index++] = '='; } - assert(output_index == output.size()); + ASSERT(output_index == output.size()); return output; } -- cgit v1.2.3 From e0d94e0f06e5e39319f68497479720e04f10ce58 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 13:47:15 -0600 Subject: Add missing plugin error Previously, if a plugin was included but the folder had no lua files, the error given was ambiguous. Now, it explicitly describes lack of lua files. See issue #512 P.S. This probably isn't the best way, but this is where the fix can be made. --- src/Bindings/PluginLua.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 209842e55..196a4f730 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -90,6 +90,8 @@ bool cPluginLua::Initialize(void) // Load all files for this plugin, and execute them AStringVector Files = cFile::GetFolderContents(PluginPath.c_str()); + + int numFiles = 0; for (AStringVector::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { if (itr->rfind(".lua") == AString::npos) @@ -101,9 +103,19 @@ bool cPluginLua::Initialize(void) { Close(); return false; + } else + { + numFiles++; } } // for itr - Files[] + if (numFiles == 0) // no lua files found + { + LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str()); + Close(); + return false; + } + // Call intialize function bool res = false; if (!m_LuaState.Call("Initialize", this, cLuaState::Return, res)) -- cgit v1.2.3 From f578dbfc54e4fd17cd897c9dd86871b1d3c19f8f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 7 Jan 2014 21:23:26 +0000 Subject: Graceful shutdown on SIGTERM --- src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 81c6b41e4..0620e0f0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,6 +50,11 @@ void NonCtrlHandler(int a_Signal) LOGWARN("Segmentation fault; MCServer has crashed :("); exit(EXIT_FAILURE); } + case SIGTERM: + { + std::signal(SIGTERM, SIG_IGN); // Server is shutting down, wait for it... + break; + } default: break; } } -- cgit v1.2.3 From 38d0bdf00a370fa12ce4611789439fe8a57880e8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 8 Jan 2014 14:23:15 +0100 Subject: Fixed AppendVPrintf() handling for large strings. This caused a failure in server favicons. --- src/StringUtils.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 5d16616c5..0b38297ef 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -47,15 +47,13 @@ AString & AppendVPrintf(AString & str, const char *format, va_list args) #endif // _MSC_VER // Allocate a buffer and printf into it: - str.resize(len + 1); - // HACK: we're accessing AString's internal buffer in a way that is NOT guaranteed to always work. But it works on all STL implementations tested. - // I can't think of any other way that is safe, doesn't allocate twice as much space as needed and doesn't use C++11 features like the move constructor + std::vector Buffer(len + 1); #ifdef _MSC_VER - vsprintf_s((char *)str.data(), len + 1, format, args); + vsprintf_s((char *)&(Buffer.front()), Buffer.size(), format, args); #else // _MSC_VER - vsnprintf((char *)str.data(), len + 1, format, args); + vsnprintf((char *)&(Buffer.front()), Buffer.size(), format, args); #endif // else _MSC_VER - str.resize(len); + str.append(&(Buffer.front()), Buffer.size() - 1); return str; } -- cgit v1.2.3 From ca8421fe26f8dcd83fb66cdca0cdef5a5503b54a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 8 Jan 2014 15:26:43 +0100 Subject: NetherGen: Now generates SoulSand. --- src/Generating/CompoGen.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index f929ddc2f..9c67170d8 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -589,7 +589,17 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) for (int y = 0; y < SEGMENT_HEIGHT; y++) { int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; - a_ChunkDesc.SetBlockType(x, y + Segment, z, (Val < m_Threshold) ? E_BLOCK_NETHERRACK : E_BLOCK_AIR); + NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(BaseX * cChunkDef::Width + x)) / 8; + NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(BaseZ * cChunkDef::Width + z)) / 8; + NOISE_DATATYPE CompBlock = m_Noise1.CubicNoise3D(NoiseX, (float) y, NoiseY); + if (CompBlock < -0.5) + { + a_ChunkDesc.SetBlockType(x, y + Segment, z, (Val < m_Threshold) ? E_BLOCK_SOULSAND : E_BLOCK_AIR); + } + else + { + a_ChunkDesc.SetBlockType(x, y + Segment, z, (Val < m_Threshold) ? E_BLOCK_NETHERRACK : E_BLOCK_AIR); + } } } -- cgit v1.2.3 From 5aa34cf77d3687442f148ffbb325e61a8f6ed249 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 8 Jan 2014 15:34:49 +0100 Subject: WormNestCaves now remove soul sand. --- src/Generating/Caves.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index c94113f5c..2571e6b77 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -509,6 +509,7 @@ void cCaveTunnel::ProcessChunk( case E_BLOCK_GRAVEL: case E_BLOCK_SAND: case E_BLOCK_SANDSTONE: + case E_BLOCK_SOULSAND: case E_BLOCK_NETHERRACK: case E_BLOCK_COAL_ORE: case E_BLOCK_IRON_ORE: -- cgit v1.2.3 From 154d6b989a242b8d3c6bb24cc64c6fedb2109ad6 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Wed, 8 Jan 2014 13:45:16 -0600 Subject: A couple touchups --- src/Bindings/PluginLua.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 196a4f730..eefcd2b09 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -103,13 +103,14 @@ bool cPluginLua::Initialize(void) { Close(); return false; - } else + } + else { numFiles++; } } // for itr - Files[] - if (numFiles == 0) // no lua files found + if (numFiles == 0) { LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str()); Close(); -- cgit v1.2.3 From d46208510870039a4e4870781ca88d0c80a00e32 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 8 Jan 2014 22:23:26 +0100 Subject: Speed-up. I got about 40 extra ch/s --- src/Generating/CompoGen.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index 9c67170d8..3545863fe 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -589,17 +589,22 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) for (int y = 0; y < SEGMENT_HEIGHT; y++) { int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; - NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(BaseX * cChunkDef::Width + x)) / 8; - NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(BaseZ * cChunkDef::Width + z)) / 8; - NOISE_DATATYPE CompBlock = m_Noise1.CubicNoise3D(NoiseX, (float) y, NoiseY); - if (CompBlock < -0.5) + BLOCKTYPE Block = E_BLOCK_AIR; + if (Val < m_Threshold) // Don't calculate if the block should be Netherrack or Soulsand when it's already decided that it's air. { - a_ChunkDesc.SetBlockType(x, y + Segment, z, (Val < m_Threshold) ? E_BLOCK_SOULSAND : E_BLOCK_AIR); - } - else - { - a_ChunkDesc.SetBlockType(x, y + Segment, z, (Val < m_Threshold) ? E_BLOCK_NETHERRACK : E_BLOCK_AIR); + NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(BaseX * cChunkDef::Width + x)) / 8; + NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(BaseZ * cChunkDef::Width + z)) / 8; + NOISE_DATATYPE CompBlock = m_Noise1.CubicNoise3D(NoiseX, (float) y, NoiseY); + if (CompBlock < -0.5) + { + Block = E_BLOCK_SOULSAND; + } + else + { + Block = E_BLOCK_NETHERRACK; + } } + a_ChunkDesc.SetBlockType(x, y + Segment, z, Block); } } -- cgit v1.2.3 From 1ef20e858fd5b38ede0e2de2d697cb894e245964 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 9 Jan 2014 10:21:26 +0100 Subject: Height generator creating moved info HeiGen.cpp. The generator also explicitly sets the default back into the INI file. --- src/Generating/ComposableGenerator.cpp | 54 +------------------------ src/Generating/ComposableGenerator.h | 9 ++++- src/Generating/HeiGen.cpp | 73 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index c86568c95..a6fcbc9ed 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -173,60 +173,8 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile) { - AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", ""); - if (HeightGenName.empty()) - { - LOGWARN("[Generator] HeightGen value not set in world.ini, using \"Biomal\"."); - HeightGenName = "Biomal"; - } - - int Seed = m_ChunkGenerator.GetSeed(); bool CacheOffByDefault = false; - if (NoCaseCompare(HeightGenName, "flat") == 0) - { - m_HeightGen = new cHeiGenFlat; - CacheOffByDefault = true; // We're generating faster than a cache would retrieve data - } - else if (NoCaseCompare(HeightGenName, "classic") == 0) - { - m_HeightGen = new cHeiGenClassic(Seed); - } - else if (NoCaseCompare(HeightGenName, "DistortedHeightmap") == 0) - { - m_HeightGen = new cDistortedHeightmap(Seed, *m_BiomeGen); - } - else if (NoCaseCompare(HeightGenName, "End") == 0) - { - m_HeightGen = new cEndGen(Seed); - } - else if (NoCaseCompare(HeightGenName, "Noise3D") == 0) - { - m_HeightGen = new cNoise3DComposable(Seed); - } - else // "biomal" or - { - if (NoCaseCompare(HeightGenName, "biomal") != 0) - { - LOGWARN("Unknown HeightGen \"%s\", using \"Biomal\" instead.", HeightGenName.c_str()); - } - m_HeightGen = new cHeiGenBiomal(Seed, *m_BiomeGen); - - /* - // Performance-testing: - LOGINFO("Measuring performance of cHeiGenBiomal..."); - clock_t BeginTick = clock(); - for (int x = 0; x < 500; x++) - { - cChunkDef::HeightMap Heights; - m_HeightGen->GenHeightMap(x * 5, x * 5, Heights); - } - clock_t Duration = clock() - BeginTick; - LOGINFO("HeightGen for 500 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC); - //*/ - } - - // Read the settings: - m_HeightGen->InitializeHeightGen(a_IniFile); + m_HeightGen = cTerrainHeightGen::CreateHeightGen(a_IniFile, *m_BiomeGen, m_ChunkGenerator.GetSeed(), CacheOffByDefault); // Add a cache, if requested: int CacheSize = a_IniFile.GetValueSetI("Generator", "HeightGenCacheSize", CacheOffByDefault ? 0 : 64); diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h index 732f64303..a6b77f7be 100644 --- a/src/Generating/ComposableGenerator.h +++ b/src/Generating/ComposableGenerator.h @@ -50,7 +50,7 @@ public: virtual void InitializeBiomeGen(cIniFile & a_IniFile) {} /// Creates the correct BiomeGen descendant based on the ini file settings and the seed provided. - /// a_CacheOffByDefault gets set to whether the cache should be enabled by default + /// a_CacheOffByDefault gets set to whether the cache should be disabled by default /// Used in BiomeVisualiser, too. /// Implemented in BioGen.cpp! static cBiomeGen * CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault); @@ -77,6 +77,13 @@ public: /// Reads parameters from the ini file, prepares generator for use. virtual void InitializeHeightGen(cIniFile & a_IniFile) {} + + /** Creates the correct TerrainHeightGen descendant based on the ini file settings and the seed provided. + a_BiomeGen is the underlying biome generator, some height generators may depend on it to generate more biomes + a_CacheOffByDefault gets set to whether the cache should be disabled by default + Implemented in HeiGen.cpp! + */ + static cTerrainHeightGen * CreateHeightGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault); } ; diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index 2bf641089..051758f71 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -7,12 +7,85 @@ #include "HeiGen.h" #include "../LinearUpscale.h" #include "inifile/iniFile.h" +#include "DistortedHeightmap.h" +#include "EndGen.h" +#include "Noise3DGenerator.h" +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cTerrainHeightGen: + +cTerrainHeightGen * cTerrainHeightGen::CreateHeightGen(cIniFile &a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault) +{ + AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", ""); + if (HeightGenName.empty()) + { + LOGWARN("[Generator] HeightGen value not set in world.ini, using \"Biomal\"."); + HeightGenName = "Biomal"; + } + + a_CacheOffByDefault = false; + cTerrainHeightGen * res = NULL; + if (NoCaseCompare(HeightGenName, "flat") == 0) + { + res = new cHeiGenFlat; + a_CacheOffByDefault = true; // We're generating faster than a cache would retrieve data + } + else if (NoCaseCompare(HeightGenName, "classic") == 0) + { + res = new cHeiGenClassic(a_Seed); + } + else if (NoCaseCompare(HeightGenName, "DistortedHeightmap") == 0) + { + res = new cDistortedHeightmap(a_Seed, a_BiomeGen); + } + else if (NoCaseCompare(HeightGenName, "End") == 0) + { + res = new cEndGen(a_Seed); + } + else if (NoCaseCompare(HeightGenName, "Noise3D") == 0) + { + res = new cNoise3DComposable(a_Seed); + } + else if (NoCaseCompare(HeightGenName, "biomal") == 0) + { + res = new cHeiGenBiomal(a_Seed, a_BiomeGen); + + /* + // Performance-testing: + LOGINFO("Measuring performance of cHeiGenBiomal..."); + clock_t BeginTick = clock(); + for (int x = 0; x < 500; x++) + { + cChunkDef::HeightMap Heights; + res->GenHeightMap(x * 5, x * 5, Heights); + } + clock_t Duration = clock() - BeginTick; + LOGINFO("HeightGen for 500 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC); + //*/ + } + else + { + // No match found, force-set the default and retry + LOGWARN("Unknown HeightGen \"%s\", using \"Biomal\" instead.", HeightGenName.c_str()); + a_IniFile.SetValue("Generator", "HeightGen", "Biomal"); + return CreateHeightGen(a_IniFile, a_BiomeGen, a_Seed, a_CacheOffByDefault); + } + + // Read the settings: + res->InitializeHeightGen(a_IniFile); + + return res; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cHeiGenFlat: -- cgit v1.2.3 From bd17662412e68463f38fb73b1b1aa43032262b78 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 9 Jan 2014 10:35:51 +0100 Subject: Composition generator creating moved to a separate function. Also it forces the defaults into the INI file. --- src/Generating/ComposableGenerator.cpp | 138 ++++++++++++++++++--------------- src/Generating/ComposableGenerator.h | 6 ++ 2 files changed, 83 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index a6fcbc9ed..76d06724d 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -28,10 +28,86 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cTerrainCompositionGen: +cTerrainCompositionGen * cTerrainCompositionGen::CreateCompositionGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_Seed) +{ + AString CompoGenName = a_IniFile.GetValueSet("Generator", "CompositionGen", ""); + if (CompoGenName.empty()) + { + LOGWARN("[Generator] CompositionGen value not set in world.ini, using \"Biomal\"."); + CompoGenName = "Biomal"; + a_IniFile.SetValue("Generator", "CompositionGen", CompoGenName); + } + + cTerrainCompositionGen * res = NULL; + if (NoCaseCompare(CompoGenName, "sameblock") == 0) + { + res = new cCompoGenSameBlock; + } + else if (NoCaseCompare(CompoGenName, "debugbiomes") == 0) + { + res = new cCompoGenDebugBiomes; + } + else if (NoCaseCompare(CompoGenName, "classic") == 0) + { + res = new cCompoGenClassic; + } + else if (NoCaseCompare(CompoGenName, "DistortedHeightmap") == 0) + { + res = new cDistortedHeightmap(a_Seed, a_BiomeGen); + } + else if (NoCaseCompare(CompoGenName, "end") == 0) + { + res = new cEndGen(a_Seed); + } + else if (NoCaseCompare(CompoGenName, "nether") == 0) + { + res = new cCompoGenNether(a_Seed); + } + else if (NoCaseCompare(CompoGenName, "Noise3D") == 0) + { + res = new cNoise3DComposable(a_Seed); + } + else if (NoCaseCompare(CompoGenName, "biomal") == 0) + { + res = new cCompoGenBiomal(a_Seed); + + /* + // Performance-testing: + LOGINFO("Measuring performance of cCompoGenBiomal..."); + clock_t BeginTick = clock(); + for (int x = 0; x < 500; x++) + { + cChunkDesc Desc(200 + x * 8, 200 + x * 8); + a_BiomeGen->GenBiomes(Desc.GetChunkX(), Desc.GetChunkZ(), Desc.GetBiomeMap()); + a_HeightGen->GenHeightMap(Desc.GetChunkX(), Desc.GetChunkZ(), Desc.GetHeightMap()); + res->ComposeTerrain(Desc); + } + clock_t Duration = clock() - BeginTick; + LOGINFO("CompositionGen for 500 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC); + //*/ + } + else + { + LOGWARN("Unknown CompositionGen \"%s\", using \"biomal\" instead.", CompoGenName.c_str()); + a_IniFile.SetValue("Generator", "CompositionGen", "Biomal"); + return CreateCompositionGen(a_IniFile, a_BiomeGen, a_HeightGen, a_Seed); + } + ASSERT(res != NULL); + + // Read the settings from the ini file: + res->InitializeCompoGen(a_IniFile); + + return res; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cComposableGenerator: cComposableGenerator::cComposableGenerator(cChunkGenerator & a_ChunkGenerator) : super(a_ChunkGenerator), @@ -199,67 +275,7 @@ void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile) void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile) { - int Seed = m_ChunkGenerator.GetSeed(); - AString CompoGenName = a_IniFile.GetValueSet("Generator", "CompositionGen", ""); - if (CompoGenName.empty()) - { - LOGWARN("[Generator] CompositionGen value not set in world.ini, using \"Biomal\"."); - CompoGenName = "Biomal"; - } - if (NoCaseCompare(CompoGenName, "sameblock") == 0) - { - m_CompositionGen = new cCompoGenSameBlock; - } - else if (NoCaseCompare(CompoGenName, "debugbiomes") == 0) - { - m_CompositionGen = new cCompoGenDebugBiomes; - } - else if (NoCaseCompare(CompoGenName, "classic") == 0) - { - m_CompositionGen = new cCompoGenClassic; - } - else if (NoCaseCompare(CompoGenName, "DistortedHeightmap") == 0) - { - m_CompositionGen = new cDistortedHeightmap(Seed, *m_BiomeGen); - } - else if (NoCaseCompare(CompoGenName, "end") == 0) - { - m_CompositionGen = new cEndGen(Seed); - } - else if (NoCaseCompare(CompoGenName, "nether") == 0) - { - m_CompositionGen = new cCompoGenNether(Seed); - } - else if (NoCaseCompare(CompoGenName, "Noise3D") == 0) - { - m_CompositionGen = new cNoise3DComposable(m_ChunkGenerator.GetSeed()); - } - else - { - if (NoCaseCompare(CompoGenName, "biomal") != 0) - { - LOGWARN("Unknown CompositionGen \"%s\", using \"biomal\" instead.", CompoGenName.c_str()); - } - m_CompositionGen = new cCompoGenBiomal(Seed); - - /* - // Performance-testing: - LOGINFO("Measuring performance of cCompoGenBiomal..."); - clock_t BeginTick = clock(); - for (int x = 0; x < 500; x++) - { - cChunkDesc Desc(200 + x * 8, 200 + x * 8); - m_BiomeGen->GenBiomes(Desc.GetChunkX(), Desc.GetChunkZ(), Desc.GetBiomeMap()); - m_HeightGen->GenHeightMap(Desc.GetChunkX(), Desc.GetChunkZ(), Desc.GetHeightMap()); - m_CompositionGen->ComposeTerrain(Desc); - } - clock_t Duration = clock() - BeginTick; - LOGINFO("CompositionGen for 500 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC); - //*/ - } - - // Read the settings from the ini file: - m_CompositionGen->InitializeCompoGen(a_IniFile); + m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen(a_IniFile, *m_BiomeGen, *m_HeightGen, m_ChunkGenerator.GetSeed()); int CompoGenCacheSize = a_IniFile.GetValueSetI("Generator", "CompositionGenCacheSize", 64); if (CompoGenCacheSize > 1) diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h index a6b77f7be..7c9c97586 100644 --- a/src/Generating/ComposableGenerator.h +++ b/src/Generating/ComposableGenerator.h @@ -104,6 +104,12 @@ public: /// Reads parameters from the ini file, prepares generator for use. virtual void InitializeCompoGen(cIniFile & a_IniFile) {} + + /** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided. + a_BiomeGen is the underlying biome generator, some composition generators may depend on it to generate more biomes + a_HeightGen is the underlying height generator, some composition generators may depend on it providing additional values + */ + static cTerrainCompositionGen * CreateCompositionGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_Seed); } ; -- cgit v1.2.3 From fe978f0d1e01e284b591e1d5a08ebb24161fd587 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 9 Jan 2014 11:39:42 +0100 Subject: Added cClientHandle::SendPluginMessage(). It is not yet exported in the API, though. --- src/ClientHandle.cpp | 9 +++++++++ src/ClientHandle.h | 1 + src/Protocol/Protocol.h | 1 + src/Protocol/Protocol125.cpp | 14 ++++++++++++++ src/Protocol/Protocol125.h | 1 + src/Protocol/Protocol17x.cpp | 12 ++++++++++++ src/Protocol/Protocol17x.h | 1 + src/Protocol/ProtocolRecognizer.cpp | 10 ++++++++++ src/Protocol/ProtocolRecognizer.h | 1 + 9 files changed, 50 insertions(+) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8125acb47..9348a1825 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1978,6 +1978,15 @@ void cClientHandle::SendPlayerSpawn(const cPlayer & a_Player) +void cClientHandle::SendPluginMessage(const AString & a_Channel, const AString & a_Message) +{ + m_Protocol->SendPluginMessage(a_Channel, a_Message); +} + + + + + void cClientHandle::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { m_Protocol->SendRemoveEntityEffect(a_Entity, a_EffectID); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index bc17df780..297d62d57 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -120,6 +120,7 @@ public: void SendPlayerMoveLook (void); void SendPlayerPosition (void); void SendPlayerSpawn (const cPlayer & a_Player); + void SendPluginMessage (const AString & a_Channel, const AString & a_Message); // Exported in ManualBindings.cpp void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID); void SendRespawn (void); void SendExperience (void); diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index fdbffb3e9..3293da32c 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -87,6 +87,7 @@ public: virtual void SendPlayerMoveLook (void) = 0; virtual void SendPlayerPosition (void) = 0; virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; + virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) = 0; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) = 0; virtual void SendRespawn (void) = 0; virtual void SendExperience (void) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index e49dd43ff..48c085ae5 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -704,6 +704,20 @@ void cProtocol125::SendPlayerSpawn(const cPlayer & a_Player) +void cProtocol125::SendPluginMessage(const AString & a_Channel, const AString & a_Message) +{ + cCSLock Lock(m_CSPacket); + WriteByte(PACKET_PLUGIN_MESSAGE); + WriteString(a_Channel); + WriteShort((short)a_Message.size()); + SendData(a_Message.data(), a_Message.size()); + Flush(); +} + + + + + void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { cCSLock Lock(m_CSPacket); diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 0b32137d8..d0e5c9428 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -63,6 +63,7 @@ public: virtual void SendPlayerMoveLook (void) override; virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; + virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; virtual void SendRespawn (void) override; virtual void SendExperience (void) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 8ec5dec29..c64aa0881 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -628,6 +628,18 @@ void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player) +void cProtocol172::SendPluginMessage(const AString & a_Channel, const AString & a_Message) +{ + cPacketizer Pkt(*this, 0x17); + Pkt.WriteString(a_Channel); + Pkt.WriteShort((short)a_Message.size()); + Pkt.WriteBuf(a_Message.data(), a_Message.size()); +} + + + + + void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { cPacketizer Pkt(*this, 0x1E); diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 23ff2365d..fd6b1fc0f 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -86,6 +86,7 @@ public: virtual void SendPlayerMoveLook (void) override; virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; + virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; virtual void SendRespawn (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index e2ea0e6e5..a21f4f042 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -476,6 +476,16 @@ void cProtocolRecognizer::SendPlayerSpawn(const cPlayer & a_Player) +void cProtocolRecognizer::SendPluginMessage(const AString & a_Channel, const AString & a_Message) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendPluginMessage(a_Channel, a_Message); +} + + + + + void cProtocolRecognizer::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { ASSERT(m_Protocol != NULL); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index fbcf59f3b..e94f4cde8 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -98,6 +98,7 @@ public: virtual void SendPlayerMoveLook (void) override; virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; + virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; virtual void SendRespawn (void) override; virtual void SendExperience (void) override; -- cgit v1.2.3 From 6c75cbc8d75b5a2ba9ee071740edd43efeaac1e9 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 9 Jan 2014 13:30:04 +0100 Subject: Fixed chunk borders. --- src/Generating/CompoGen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index 3545863fe..8d6c918ca 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -592,9 +592,9 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) BLOCKTYPE Block = E_BLOCK_AIR; if (Val < m_Threshold) // Don't calculate if the block should be Netherrack or Soulsand when it's already decided that it's air. { - NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(BaseX * cChunkDef::Width + x)) / 8; - NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(BaseZ * cChunkDef::Width + z)) / 8; - NOISE_DATATYPE CompBlock = m_Noise1.CubicNoise3D(NoiseX, (float) y, NoiseY); + NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(BaseX + x)) / 8; + NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(BaseZ + z)) / 8; + NOISE_DATATYPE CompBlock = m_Noise1.CubicNoise3D(NoiseX, (float) y / 2, NoiseY); if (CompBlock < -0.5) { Block = E_BLOCK_SOULSAND; -- cgit v1.2.3 From f3bedb3c32dc39424712f5f98de7c9eab2fc56d1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 9 Jan 2014 14:24:57 +0100 Subject: Fixed wrong packet number for PluginMessage packet. --- src/Protocol/Protocol17x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index c64aa0881..9c46c6843 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -630,7 +630,7 @@ void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player) void cProtocol172::SendPluginMessage(const AString & a_Channel, const AString & a_Message) { - cPacketizer Pkt(*this, 0x17); + cPacketizer Pkt(*this, 0x3f); Pkt.WriteString(a_Channel); Pkt.WriteShort((short)a_Message.size()); Pkt.WriteBuf(a_Message.data(), a_Message.size()); -- cgit v1.2.3 From bb96737f455bbfb52864703e74397c61475936b4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 9 Jan 2014 14:25:37 +0100 Subject: Exported cClientHandle::SendPluginMessage() to Lua. --- src/Bindings/ManualBindings.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 6221727c4..344d5d2e0 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1904,6 +1904,35 @@ static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S) +static int tolua_cClientHandle_SendPluginMessage(lua_State * L) +{ + cLuaState S(L); + if ( + !S.CheckParamUserType(1, "cClientHandle") || + !S.CheckParamString(2, 3) || + !S.CheckParamEnd(4) + ) + { + return 0; + } + cClientHandle * Client = (cClientHandle *)tolua_tousertype(L, 1, NULL); + if (Client == NULL) + { + LOGWARNING("ClientHandle is nil in cClientHandle:SendPluginMessage()"); + S.LogStackTrace(); + return 0; + } + AString Channel, Message; + Channel.assign(lua_tostring(L, 2), lua_strlen(L, 2)); + Message.assign(lua_tostring(L, 3), lua_strlen(L, 3)); + Client->SendPluginMessage(Channel, Message); + return 0; +} + + + + + static int Lua_ItemGrid_GetSlotCoords(lua_State * L) { tolua_Error tolua_err; @@ -2292,6 +2321,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cClientHandle"); tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); + tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cItemGrid"); -- cgit v1.2.3 From cee76f1ace49fea1ed3a3ebd6476cca9b799c5b2 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Thu, 9 Jan 2014 15:21:46 -0600 Subject: Move biome definition to separate files --- src/Bindings/AllToLua.pkg | 1 + src/BiomeDef.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++ src/BiomeDef.h | 107 ++++++++++++++++++++++++++++++++++++++ src/BlockID.cpp | 100 ----------------------------------- src/BlockID.h | 3 -- src/ChunkDef.h | 93 +-------------------------------- src/Defines.h | 28 ---------- src/Globals.h | 1 + 8 files changed, 241 insertions(+), 222 deletions(-) create mode 100644 src/BiomeDef.cpp create mode 100644 src/BiomeDef.h (limited to 'src') diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index e9a5ea0c6..f209d6768 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -14,6 +14,7 @@ typedef unsigned short UInt16; $cfile "../ChunkDef.h" +$cfile "../BiomeDef.h" $cfile "../../lib/inifile/iniFile.h" diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp new file mode 100644 index 000000000..06b48e9d0 --- /dev/null +++ b/src/BiomeDef.cpp @@ -0,0 +1,130 @@ + +// BiomeDef.cpp + +// Implements biome helper functions + + + + +EMCSBiome StringToBiome(const AString & a_BiomeString) +{ + // If it is a number, return it: + int res = atoi(a_BiomeString.c_str()); + if ((res != 0) || (a_BiomeString.compare("0") == 0)) + { + // It was a valid number + return (EMCSBiome)res; + } + + // Convert using the built-in map: + static struct { + EMCSBiome m_Biome; + const char * m_String; + } BiomeMap[] = + { + {biOcean, "Ocean"} , + {biPlains, "Plains"}, + {biDesert, "Desert"}, + {biExtremeHills, "ExtremeHills"}, + {biForest, "Forest"}, + {biTaiga, "Taiga"}, + {biSwampland, "Swampland"}, + {biRiver, "River"}, + {biNether, "Hell"}, + {biNether, "Nether"}, + {biEnd, "Sky"}, + {biEnd, "End"}, + {biFrozenOcean, "FrozenOcean"}, + {biFrozenRiver, "FrozenRiver"}, + {biIcePlains, "IcePlains"}, + {biIcePlains, "Tundra"}, + {biIceMountains, "IceMountains"}, + {biMushroomIsland, "MushroomIsland"}, + {biMushroomShore, "MushroomShore"}, + {biBeach, "Beach"}, + {biDesertHills, "DesertHills"}, + {biForestHills, "ForestHills"}, + {biTaigaHills, "TaigaHills"}, + {biExtremeHillsEdge, "ExtremeHillsEdge"}, + {biJungle, "Jungle"}, + {biJungleHills, "JungleHills"}, + + // Release 1.7 biomes: + {biJungleEdge, "JungleEdge"}, + {biDeepOcean, "DeepOcean"}, + {biStoneBeach, "StoneBeach"}, + {biColdBeach, "ColdBeach"}, + {biBirchForest, "BirchForest"}, + {biBirchForestHills, "BirchForestHills"}, + {biRoofedForest, "RoofedForest"}, + {biColdTaiga, "ColdTaiga"}, + {biColdTaigaHills, "ColdTaigaHills"}, + {biMegaTaiga, "MegaTaiga"}, + {biMegaTaigaHills, "MegaTaigaHills"}, + {biExtremeHillsPlus, "ExtremeHillsPlus"}, + {biSavanna, "Savanna"}, + {biSavannaPlateau, "SavannaPlateau"}, + {biMesa, "Mesa"}, + {biMesaPlateauF, "MesaPlateauF"}, + {biMesaPlateau, "MesaPlateau"}, + + // Release 1.7 variants: + {biSunflowerPlains, "SunflowerPlains"}, + {biDesertM, "DesertM"}, + {biExtremeHillsM, "ExtremeHillsM"}, + {biFlowerForest, "FlowerForest"}, + {biTaigaM, "TaigaM"}, + {biSwamplandM, "SwamplandM"}, + {biIcePlainsSpikes, "IcePlainsSpikes"}, + {biJungleM, "JungleM"}, + {biJungleEdgeM, "JungleEdgeM"}, + {biBirchForestM, "BirchForestM"}, + {biBirchForestHillsM, "BirchForestHillsM"}, + {biRoofedForestM, "RoofedForestM"}, + {biColdTaigaM, "ColdTaigaM"}, + {biMegaSpruceTaiga, "MegaSpruceTaiga"}, + {biMegaSpruceTaigaHills, "MegaSpruceTaigaHills"}, + {biExtremeHillsPlusM, "ExtremeHillsPlusM"}, + {biSavannaM, "SavannaM"}, + {biSavannaPlateauM, "SavannaPlateauM"}, + {biMesaBryce, "MesaBryce"}, + {biMesaPlateauFM, "MesaPlateauFM"}, + {biMesaPlateauM, "MesaPlateauM"}, + } ; + + for (size_t i = 0; i < ARRAYCOUNT(BiomeMap); i++) + { + if (NoCaseCompare(BiomeMap[i].m_String, a_BiomeString) == 0) + { + return BiomeMap[i].m_Biome; + } + } // for i - BiomeMap[] + return (EMCSBiome)-1; +} + + + + + +bool IsBiomeNoDownfall(EMCSBiome a_Biome) +{ + switch (a_Biome) + { + case biDesert: + case biDesertHills: + case biDesertM: + case biSavanna: + case biSavannaM: + case biSavannaPlateau: + case biSavannaPlateauM: + case biNether: + case biEnd: + { + return true; + } + default: + { + return false; + } + } +} \ No newline at end of file diff --git a/src/BiomeDef.h b/src/BiomeDef.h new file mode 100644 index 000000000..e1c29bc00 --- /dev/null +++ b/src/BiomeDef.h @@ -0,0 +1,107 @@ + +// BiomeDef.h + +// Defines relevant information and methods related to biomes + + + + + +#pragma once + + + + + +// tolua_begin +/** Biome IDs +The first batch corresponds to the clientside biomes, used by MineCraft. +BiomeIDs over 255 are used by MCServer internally and are translated to MC biomes before sending them to client +*/ +enum EMCSBiome +{ + biOcean = 0, + biPlains = 1, + biDesert = 2, + biExtremeHills = 3, + biForest = 4, + biTaiga = 5, + biSwampland = 6, + biRiver = 7, + biHell = 8, // same as Nether + biNether = 8, + biSky = 9, // same as biEnd + biEnd = 9, + biFrozenOcean = 10, + biFrozenRiver = 11, + biIcePlains = 12, + biTundra = 12, // same as Ice Plains + biIceMountains = 13, + biMushroomIsland = 14, + biMushroomShore = 15, + biBeach = 16, + biDesertHills = 17, + biForestHills = 18, + biTaigaHills = 19, + biExtremeHillsEdge = 20, + biJungle = 21, + biJungleHills = 22, + + // Release 1.7 biomes: + biJungleEdge = 23, + biDeepOcean = 24, + biStoneBeach = 25, + biColdBeach = 26, + biBirchForest = 27, + biBirchForestHills = 28, + biRoofedForest = 29, + biColdTaiga = 30, + biColdTaigaHills = 31, + biMegaTaiga = 32, + biMegaTaigaHills = 33, + biExtremeHillsPlus = 34, + biSavanna = 35, + biSavannaPlateau = 36, + biMesa = 37, + biMesaPlateauF = 38, + biMesaPlateau = 39, + + // Automatically capture the maximum consecutive biome value into biMaxBiome: + biNumBiomes, // True number of biomes, since they are zero-based + biMaxBiome = biNumBiomes - 1, // The maximum biome value + + // Add this number to the biomes to get the variant + biVariant = 128, + + // Release 1.7 biome variants: + biSunflowerPlains = 129, + biDesertM = 130, + biExtremeHillsM = 131, + biFlowerForest = 132, + biTaigaM = 133, + biSwamplandM = 134, + biIcePlainsSpikes = 140, + biJungleM = 149, + biJungleEdgeM = 151, + biBirchForestM = 155, + biBirchForestHillsM = 156, + biRoofedForestM = 157, + biColdTaigaM = 158, + biMegaSpruceTaiga = 160, + biMegaSpruceTaigaHills = 161, + biExtremeHillsPlusM = 162, + biSavannaM = 163, + biSavannaPlateauM = 164, + biMesaBryce = 165, + biMesaPlateauFM = 166, + biMesaPlateauM = 167, +} ; + +/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns -1 on failure. +extern EMCSBiome StringToBiome(const AString & a_BiomeString); + +/// Returns true if the biome has no downfall - deserts and savannas +extern bool IsBiomeNoDownfall(EMCSBiome a_Biome); + + +// tolua_end \ No newline at end of file diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 05d4c6595..b609af571 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -267,106 +267,6 @@ AString ItemToFullString(const cItem & a_Item) -EMCSBiome StringToBiome(const AString & a_BiomeString) -{ - // If it is a number, return it: - int res = atoi(a_BiomeString.c_str()); - if ((res != 0) || (a_BiomeString.compare("0") == 0)) - { - // It was a valid number - return (EMCSBiome)res; - } - - // Convert using the built-in map: - static struct { - EMCSBiome m_Biome; - const char * m_String; - } BiomeMap[] = - { - {biOcean, "Ocean"} , - {biPlains, "Plains"}, - {biDesert, "Desert"}, - {biExtremeHills, "ExtremeHills"}, - {biForest, "Forest"}, - {biTaiga, "Taiga"}, - {biSwampland, "Swampland"}, - {biRiver, "River"}, - {biNether, "Hell"}, - {biNether, "Nether"}, - {biEnd, "Sky"}, - {biEnd, "End"}, - {biFrozenOcean, "FrozenOcean"}, - {biFrozenRiver, "FrozenRiver"}, - {biIcePlains, "IcePlains"}, - {biIcePlains, "Tundra"}, - {biIceMountains, "IceMountains"}, - {biMushroomIsland, "MushroomIsland"}, - {biMushroomShore, "MushroomShore"}, - {biBeach, "Beach"}, - {biDesertHills, "DesertHills"}, - {biForestHills, "ForestHills"}, - {biTaigaHills, "TaigaHills"}, - {biExtremeHillsEdge, "ExtremeHillsEdge"}, - {biJungle, "Jungle"}, - {biJungleHills, "JungleHills"}, - - // Release 1.7 biomes: - {biJungleEdge, "JungleEdge"}, - {biDeepOcean, "DeepOcean"}, - {biStoneBeach, "StoneBeach"}, - {biColdBeach, "ColdBeach"}, - {biBirchForest, "BirchForest"}, - {biBirchForestHills, "BirchForestHills"}, - {biRoofedForest, "RoofedForest"}, - {biColdTaiga, "ColdTaiga"}, - {biColdTaigaHills, "ColdTaigaHills"}, - {biMegaTaiga, "MegaTaiga"}, - {biMegaTaigaHills, "MegaTaigaHills"}, - {biExtremeHillsPlus, "ExtremeHillsPlus"}, - {biSavanna, "Savanna"}, - {biSavannaPlateau, "SavannaPlateau"}, - {biMesa, "Mesa"}, - {biMesaPlateauF, "MesaPlateauF"}, - {biMesaPlateau, "MesaPlateau"}, - - // Release 1.7 variants: - {biSunflowerPlains, "SunflowerPlains"}, - {biDesertM, "DesertM"}, - {biExtremeHillsM, "ExtremeHillsM"}, - {biFlowerForest, "FlowerForest"}, - {biTaigaM, "TaigaM"}, - {biSwamplandM, "SwamplandM"}, - {biIcePlainsSpikes, "IcePlainsSpikes"}, - {biJungleM, "JungleM"}, - {biJungleEdgeM, "JungleEdgeM"}, - {biBirchForestM, "BirchForestM"}, - {biBirchForestHillsM, "BirchForestHillsM"}, - {biRoofedForestM, "RoofedForestM"}, - {biColdTaigaM, "ColdTaigaM"}, - {biMegaSpruceTaiga, "MegaSpruceTaiga"}, - {biMegaSpruceTaigaHills, "MegaSpruceTaigaHills"}, - {biExtremeHillsPlusM, "ExtremeHillsPlusM"}, - {biSavannaM, "SavannaM"}, - {biSavannaPlateauM, "SavannaPlateauM"}, - {biMesaBryce, "MesaBryce"}, - {biMesaPlateauFM, "MesaPlateauFM"}, - {biMesaPlateauM, "MesaPlateauM"}, - } ; - - for (size_t i = 0; i < ARRAYCOUNT(BiomeMap); i++) - { - if (NoCaseCompare(BiomeMap[i].m_String, a_BiomeString) == 0) - { - return BiomeMap[i].m_Biome; - } - } // for i - BiomeMap[] - return (EMCSBiome)-1; -} - - - - - int StringToMobType(const AString & a_MobString) { static struct { diff --git a/src/BlockID.h b/src/BlockID.h index 288719ccf..899336fa6 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -876,9 +876,6 @@ extern AString ItemTypeToString(short a_ItemType); /// Translates a full item into a fully-specified string (including meta and count). If the ItemType is not recognized, the ItemType number is output into the string. extern AString ItemToFullString(const cItem & a_Item); -/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns -1 on failure. -extern EMCSBiome StringToBiome(const AString & a_BiomeString); - /// Translates a mob string ("ocelot") to mobtype (E_ENTITY_TYPE_OCELOT) extern int StringToMobType(const AString & a_MobString); diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 7d727a4d4..442c9633d 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -38,6 +38,8 @@ class cBlockEntity; typedef std::list cEntityList; typedef std::list cBlockEntityList; +enum EMCSBiome; + @@ -57,97 +59,6 @@ typedef unsigned char HEIGHTTYPE; - - -// tolua_begin -/** Biome IDs -The first batch corresponds to the clientside biomes, used by MineCraft. -BiomeIDs over 255 are used by MCServer internally and are translated to MC biomes before sending them to client -*/ -enum EMCSBiome -{ - biOcean = 0, - biPlains = 1, - biDesert = 2, - biExtremeHills = 3, - biForest = 4, - biTaiga = 5, - biSwampland = 6, - biRiver = 7, - biHell = 8, // same as Nether - biNether = 8, - biSky = 9, // same as biEnd - biEnd = 9, - biFrozenOcean = 10, - biFrozenRiver = 11, - biIcePlains = 12, - biTundra = 12, // same as Ice Plains - biIceMountains = 13, - biMushroomIsland = 14, - biMushroomShore = 15, - biBeach = 16, - biDesertHills = 17, - biForestHills = 18, - biTaigaHills = 19, - biExtremeHillsEdge = 20, - biJungle = 21, - biJungleHills = 22, - - // Release 1.7 biomes: - biJungleEdge = 23, - biDeepOcean = 24, - biStoneBeach = 25, - biColdBeach = 26, - biBirchForest = 27, - biBirchForestHills = 28, - biRoofedForest = 29, - biColdTaiga = 30, - biColdTaigaHills = 31, - biMegaTaiga = 32, - biMegaTaigaHills = 33, - biExtremeHillsPlus = 34, - biSavanna = 35, - biSavannaPlateau = 36, - biMesa = 37, - biMesaPlateauF = 38, - biMesaPlateau = 39, - - // Automatically capture the maximum consecutive biome value into biMaxBiome: - biNumBiomes, // True number of biomes, since they are zero-based - biMaxBiome = biNumBiomes - 1, // The maximum biome value - - // Add this number to the biomes to get the variant - biVariant = 128, - - // Release 1.7 biome variants: - biSunflowerPlains = 129, - biDesertM = 130, - biExtremeHillsM = 131, - biFlowerForest = 132, - biTaigaM = 133, - biSwamplandM = 134, - biIcePlainsSpikes = 140, - biJungleM = 149, - biJungleEdgeM = 151, - biBirchForestM = 155, - biBirchForestHillsM = 156, - biRoofedForestM = 157, - biColdTaigaM = 158, - biMegaSpruceTaiga = 160, - biMegaSpruceTaigaHills = 161, - biExtremeHillsPlusM = 162, - biSavannaM = 163, - biSavannaPlateauM = 164, - biMesaBryce = 165, - biMesaPlateauFM = 166, - biMesaPlateauM = 167, -} ; - -// tolua_end - - - - /// Constants used throughout the code, useful typedefs and utility functions class cChunkDef { diff --git a/src/Defines.h b/src/Defines.h index 534802d55..c75effa44 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -563,34 +563,6 @@ namespace ItemCategory } } - - - - -/// Returns true if the biome has no downfall - deserts and savannas -inline bool IsBiomeNoDownfall(EMCSBiome a_Biome) -{ - switch (a_Biome) - { - case biDesert: - case biDesertHills: - case biDesertM: - case biSavanna: - case biSavannaM: - case biSavannaPlateau: - case biSavannaPlateauM: - case biNether: - case biEnd: - { - return true; - } - default: - { - return false; - } - } -} - // tolua_end diff --git a/src/Globals.h b/src/Globals.h index f886ba2d0..d2080b8eb 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -233,6 +233,7 @@ public: // Common headers (part 2, with macros): #include "ChunkDef.h" +#include "BiomeDef.h" #include "BlockID.h" #include "Entities/Effects.h" -- cgit v1.2.3 From 36c100a53ed70c38d304c3d2837940e699e9f2a1 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Fri, 10 Jan 2014 16:12:45 +0100 Subject: Fixed recurring pattern. --- src/Generating/CompoGen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index 8d6c918ca..60356fe46 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -594,7 +594,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) { NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(BaseX + x)) / 8; NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(BaseZ + z)) / 8; - NOISE_DATATYPE CompBlock = m_Noise1.CubicNoise3D(NoiseX, (float) y / 2, NoiseY); + NOISE_DATATYPE CompBlock = m_Noise1.CubicNoise3D(NoiseX, (float) (y + Segment) / 2, NoiseY); if (CompBlock < -0.5) { Block = E_BLOCK_SOULSAND; -- cgit v1.2.3 From 1c2004dfbbd520b929357bce13cdeb06d41ce0ff Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Fri, 10 Jan 2014 09:23:53 -0600 Subject: Fixed missing externals Turns out you actually have to include the .cpp in the project file --- src/BiomeDef.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index 06b48e9d0..f7f48db9f 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -3,7 +3,8 @@ // Implements biome helper functions - +#include "BiomeDef.h" +#include "Globals.h" EMCSBiome StringToBiome(const AString & a_BiomeString) -- cgit v1.2.3 From 712e6e0bb2ef2accf4ffc7792c1ad0ab0ae96662 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 10 Jan 2014 16:33:53 +0100 Subject: Fixed generator adding values to ini file. --- src/Generating/ComposableGenerator.cpp | 3 ++- src/Generating/HeiGen.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 76d06724d..971ff4538 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -90,7 +90,8 @@ cTerrainCompositionGen * cTerrainCompositionGen::CreateCompositionGen(cIniFile & } else { - LOGWARN("Unknown CompositionGen \"%s\", using \"biomal\" instead.", CompoGenName.c_str()); + LOGWARN("Unknown CompositionGen \"%s\", using \"Biomal\" instead.", CompoGenName.c_str()); + a_IniFile.DeleteValue("Generator", "CompositionGen"); a_IniFile.SetValue("Generator", "CompositionGen", "Biomal"); return CreateCompositionGen(a_IniFile, a_BiomeGen, a_HeightGen, a_Seed); } diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index 051758f71..10710b4a1 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -72,6 +72,7 @@ cTerrainHeightGen * cTerrainHeightGen::CreateHeightGen(cIniFile &a_IniFile, cBio { // No match found, force-set the default and retry LOGWARN("Unknown HeightGen \"%s\", using \"Biomal\" instead.", HeightGenName.c_str()); + a_IniFile.DeleteValue("Generator", "HeightGen"); a_IniFile.SetValue("Generator", "HeightGen", "Biomal"); return CreateHeightGen(a_IniFile, a_BiomeGen, a_Seed, a_CacheOffByDefault); } -- cgit v1.2.3 From ee74411024f1ba21b6a23eafadc9ab13ec6b3685 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Fri, 10 Jan 2014 10:10:24 -0600 Subject: Added newlines at ends of files --- src/BiomeDef.cpp | 2 +- src/BiomeDef.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index f7f48db9f..f41f4bce4 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -128,4 +128,4 @@ bool IsBiomeNoDownfall(EMCSBiome a_Biome) return false; } } -} \ No newline at end of file +} diff --git a/src/BiomeDef.h b/src/BiomeDef.h index e1c29bc00..df1e387f0 100644 --- a/src/BiomeDef.h +++ b/src/BiomeDef.h @@ -104,4 +104,4 @@ extern EMCSBiome StringToBiome(const AString & a_BiomeString); extern bool IsBiomeNoDownfall(EMCSBiome a_Biome); -// tolua_end \ No newline at end of file +// tolua_end -- cgit v1.2.3 From fe48f62575427c0b3f7449c5b9f067ba3186c3b9 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Fri, 10 Jan 2014 10:30:56 -0600 Subject: Include Biome enum in ChunkDef Can't forward declare an enum --- src/ChunkDef.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 442c9633d..edeb7c0a0 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -10,6 +10,7 @@ #pragma once #include "Vector3i.h" +#include "BiomeDef.h" @@ -38,8 +39,6 @@ class cBlockEntity; typedef std::list cEntityList; typedef std::list cBlockEntityList; -enum EMCSBiome; - -- cgit v1.2.3 From cea997426b7d66f5aa9f8aac5fd5b603bcaa3fb8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 10 Jan 2014 22:22:54 +0100 Subject: Decoupled cChunkGenerator from cWorld and cRoot. Now the chunk generator can be used by other projects without depending on the two hugest structures in MCS. --- src/Generating/ChunkGenerator.cpp | 48 +++++++++------------ src/Generating/ChunkGenerator.h | 63 ++++++++++++++++++++++++--- src/Generating/ComposableGenerator.cpp | 11 ++--- src/Generating/ComposableGenerator.h | 2 +- src/Generating/FinishGen.cpp | 4 +- src/Generating/FinishGen.h | 2 +- src/Generating/Noise3DGenerator.cpp | 4 +- src/Generating/Noise3DGenerator.h | 2 +- src/World.cpp | 78 +++++++++++++++++++++++++++++++++- src/World.h | 24 +++++++++++ 10 files changed, 188 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index 126a896af..baa5b76b8 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -2,13 +2,11 @@ #include "Globals.h" #include "ChunkGenerator.h" -#include "../World.h" #include "inifile/iniFile.h" -#include "../Root.h" -#include "../Bindings/PluginManager.h" #include "ChunkDesc.h" #include "ComposableGenerator.h" #include "Noise3DGenerator.h" +#include "../MersenneTwister.h" @@ -29,8 +27,9 @@ const unsigned int QUEUE_SKIP_LIMIT = 500; cChunkGenerator::cChunkGenerator(void) : super("cChunkGenerator"), - m_World(NULL), - m_Generator(NULL) + m_Generator(NULL), + m_PluginInterface(NULL), + m_ChunkSink(NULL) { } @@ -47,10 +46,12 @@ cChunkGenerator::~cChunkGenerator() -bool cChunkGenerator::Start(cWorld * a_World, cIniFile & a_IniFile) +bool cChunkGenerator::Start(cPluginInterface & a_PluginInterface, cChunkSink & a_ChunkSink, cIniFile & a_IniFile) { + m_PluginInterface = &a_PluginInterface; + m_ChunkSink = &a_ChunkSink; + MTRand rnd; - m_World = a_World; m_Seed = a_IniFile.GetValueSetI("Seed", "Seed", rnd.randInt()); AString GeneratorName = a_IniFile.GetValueSet("Generator", "Generator", "Composable"); @@ -73,7 +74,7 @@ bool cChunkGenerator::Start(cWorld * a_World, cIniFile & a_IniFile) return false; } - m_Generator->Initialize(a_World, a_IniFile); + m_Generator->Initialize(a_IniFile); return super::Start(); } @@ -237,14 +238,14 @@ void cChunkGenerator::Execute(void) } // Hack for regenerating chunks: if Y != 0, the chunk is considered invalid, even if it has its data set - if ((coords.m_ChunkY == 0) && m_World->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ)) + if ((coords.m_ChunkY == 0) && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ)) { LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ); // Already generated, ignore request continue; } - if (SkipEnabled && !m_World->HasChunkAnyClients(coords.m_ChunkX, coords.m_ChunkZ)) + if (SkipEnabled && !m_ChunkSink->HasChunkAnyClients(coords.m_ChunkX, coords.m_ChunkZ)) { LOGWARNING("Chunk generator overloaded, skipping chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ); continue; @@ -253,9 +254,6 @@ void cChunkGenerator::Execute(void) LOGD("Generating chunk [%d, %d, %d]", coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); DoGenerate(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); - // Save the chunk right after generating, so that we don't have to generate it again on next run - m_World->GetStorage().QueueSaveChunk(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); - NumChunksGenerated++; } // while (!bStop) } @@ -265,27 +263,20 @@ void cChunkGenerator::Execute(void) void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { + ASSERT(m_PluginInterface != NULL); + ASSERT(m_ChunkSink != NULL); + cChunkDesc ChunkDesc(a_ChunkX, a_ChunkZ); - cRoot::Get()->GetPluginManager()->CallHookChunkGenerating(m_World, a_ChunkX, a_ChunkZ, &ChunkDesc); + m_PluginInterface->CallHookChunkGenerating(ChunkDesc); m_Generator->DoGenerate(a_ChunkX, a_ChunkZ, ChunkDesc); - cRoot::Get()->GetPluginManager()->CallHookChunkGenerated(m_World, a_ChunkX, a_ChunkZ, &ChunkDesc); + m_PluginInterface->CallHookChunkGenerated(ChunkDesc); #ifdef _DEBUG // Verify that the generator has produced valid data: ChunkDesc.VerifyHeightmap(); #endif - cChunkDef::BlockNibbles BlockMetas; - ChunkDesc.CompressBlockMetas(BlockMetas); - - m_World->SetChunkData( - a_ChunkX, a_ChunkZ, - ChunkDesc.GetBlockTypes(), BlockMetas, - NULL, NULL, // We don't have lighting, chunk will be lighted when needed - &ChunkDesc.GetHeightMap(), &ChunkDesc.GetBiomeMap(), - ChunkDesc.GetEntities(), ChunkDesc.GetBlockEntities(), - true - ); + m_ChunkSink->OnChunkGenerated(ChunkDesc); } @@ -304,9 +295,8 @@ cChunkGenerator::cGenerator::cGenerator(cChunkGenerator & a_ChunkGenerator) : -void cChunkGenerator::cGenerator::Initialize(cWorld * a_World, cIniFile & a_IniFile) +void cChunkGenerator::cGenerator::Initialize(cIniFile & a_IniFile) { - m_World = a_World; UNUSED(a_IniFile); } @@ -319,7 +309,7 @@ EMCSBiome cChunkGenerator::cGenerator::GetBiomeAt(int a_BlockX, int a_BlockZ) cChunkDef::BiomeMap Biomes; int Y = 0; int ChunkX, ChunkZ; - cWorld::AbsoluteToRelative(a_BlockX, Y, a_BlockZ, ChunkX, Y, ChunkZ); + cChunkDef::AbsoluteToRelative(a_BlockX, Y, a_BlockZ, ChunkX, ChunkZ); GenerateBiomes(ChunkX, ChunkZ, Biomes); return cChunkDef::GetBiome(Biomes, a_BlockX, a_BlockZ); } diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h index 2d3bb8082..9b2d9eb3c 100644 --- a/src/Generating/ChunkGenerator.h +++ b/src/Generating/ChunkGenerator.h @@ -26,7 +26,6 @@ If the generator queue is overloaded, the generator skips chunks with no clients // fwd: -class cWorld; class cIniFile; class cChunkDesc; @@ -40,7 +39,7 @@ class cChunkGenerator : typedef cIsThread super; public: - /// The interface that a class has to implement to become a generator + /** The interface that a class has to implement to become a generator */ class cGenerator { public: @@ -48,7 +47,7 @@ public: virtual ~cGenerator() {} ; // Force a virtual destructor /// Called to initialize the generator on server startup. - virtual void Initialize(cWorld * a_World, cIniFile & a_IniFile); + virtual void Initialize(cIniFile & a_IniFile); /// Generates the biomes for the specified chunk (directly, not in a separate thread). Used by the world loader if biomes failed loading. virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) = 0; @@ -61,14 +60,59 @@ public: protected: cChunkGenerator & m_ChunkGenerator; - cWorld * m_World; + } ; + + + /** The interface through which the plugins are called for their OnChunkGenerating / OnChunkGenerated hooks. */ + class cPluginInterface + { + public: + // Force a virtual destructor + virtual ~cPluginInterface() {} + + /** Called when the chunk is about to be generated. + The generator may be partly or fully overriden by the implementation + */ + virtual void CallHookChunkGenerating(cChunkDesc & a_ChunkDesc) = 0; + + /** Called after the chunk is generated, before it is handed to the chunk sink. + a_ChunkDesc contains the generated chunk data. Implementation may modify this data. + */ + virtual void CallHookChunkGenerated(cChunkDesc & a_ChunkDesc) = 0; + } ; + + + /** The interface through which the generated chunks are handed to the cWorld or whoever created us. */ + class cChunkSink + { + public: + // Force a virtual destructor + virtual ~cChunkSink() {} + + /** Called after the chunk has been generated + The interface may store the chunk, send it over network, whatever. + The chunk is not expected to be modified, but the generator will survive if the implementation + changes the data within. All changes are ignored, though. + */ + virtual void OnChunkGenerated(cChunkDesc & a_ChunkDesc) = 0; + + /** Called just before the chunk generation is started, + to verify that it hasn't been generated in the meantime. + If this callback returns true, the chunk is not generated. + */ + virtual bool IsChunkValid(int a_ChunkX, int a_ChunkZ) = 0; + + /** Called when the generator is overloaded to skip chunks that are no longer needed. + If this callback returns false, the chunk is not generated. + */ + virtual bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) = 0; } ; cChunkGenerator (void); ~cChunkGenerator(); - bool Start(cWorld * a_World, cIniFile & a_IniFile); + bool Start(cPluginInterface & a_PluginInterface, cChunkSink & a_ChunkSink, cIniFile & a_IniFile); void Stop(void); /// Queues the chunk for generation; removes duplicate requests @@ -91,8 +135,6 @@ public: private: - cWorld * m_World; - int m_Seed; cCriticalSection m_CS; @@ -101,6 +143,13 @@ private: cEvent m_evtRemoved; ///< Set when an item is removed from the queue cGenerator * m_Generator; ///< The actual generator engine used to generate chunks + + /** The plugin interface that may modify the generated chunks */ + cPluginInterface * m_PluginInterface; + + /** The destination where the generated chunks are sent */ + cChunkSink * m_ChunkSink; + // cIsThread override: virtual void Execute(void) override; diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 971ff4538..87c4d2c52 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -157,9 +157,9 @@ cComposableGenerator::~cComposableGenerator() -void cComposableGenerator::Initialize(cWorld * a_World, cIniFile & a_IniFile) +void cComposableGenerator::Initialize(cIniFile & a_IniFile) { - super::Initialize(a_World, a_IniFile); + super::Initialize(a_IniFile); InitBiomeGen(a_IniFile); InitHeightGen(a_IniFile); @@ -369,13 +369,14 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) int Seed = m_ChunkGenerator.GetSeed(); AString Structures = a_IniFile.GetValueSet("Generator", "Finishers", "SprinkleFoliage,Ice,Snow,Lilypads,BottomLava,DeadBushes,PreSimulator"); + eDimension Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld")); AStringVector Str = StringSplitAndTrim(Structures, ","); for (AStringVector::const_iterator itr = Str.begin(); itr != Str.end(); ++itr) { // Finishers, alpha-sorted: if (NoCaseCompare(*itr, "BottomLava") == 0) { - int DefaultBottomLavaLevel = (m_World->GetDimension() == dimNether) ? 30 : 10; + int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10; int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel); m_FinishGens.push_back(new cFinishGenBottomLava(BottomLavaLevel)); } @@ -389,7 +390,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "LavaSprings") == 0) { - m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, *m_World)); + m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, Dimension)); } else if (NoCaseCompare(*itr, "Lilypads") == 0) { @@ -409,7 +410,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "WaterSprings") == 0) { - m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_WATER, a_IniFile, *m_World)); + m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_WATER, a_IniFile, Dimension)); } } // for itr - Str[] } diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h index 7c9c97586..29add0636 100644 --- a/src/Generating/ComposableGenerator.h +++ b/src/Generating/ComposableGenerator.h @@ -162,7 +162,7 @@ public: cComposableGenerator(cChunkGenerator & a_ChunkGenerator); virtual ~cComposableGenerator(); - virtual void Initialize(cWorld * a_World, cIniFile & a_IniFile) override; + virtual void Initialize(cIniFile & a_IniFile) override; virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) override; diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 145fe22e0..4915e6818 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -520,7 +520,7 @@ void cFinishGenPreSimulator::StationarizeFluid( /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cFinishGenFluidSprings: -cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, const cWorld & a_World) : +cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, eDimension a_Dimension) : m_Noise(a_Seed + a_Fluid * 100), // Need to take fluid into account, otherwise water and lava springs generate next to each other m_HeightDistribution(255), m_Fluid(a_Fluid) @@ -529,7 +529,7 @@ cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cI AString SectionName = IsWater ? "WaterSprings" : "LavaSprings"; AString DefaultHeightDistribution; int DefaultChance = 0; - switch (a_World.GetDimension()) + switch (a_Dimension) { case dimNether: { diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index ed7df5909..d89ffed15 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -164,7 +164,7 @@ class cFinishGenFluidSprings : public cFinishGen { public: - cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, const cWorld & a_World); + cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, eDimension a_Dimension); protected: diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp index 2511bb656..afa40c647 100644 --- a/src/Generating/Noise3DGenerator.cpp +++ b/src/Generating/Noise3DGenerator.cpp @@ -150,10 +150,8 @@ cNoise3DGenerator::~cNoise3DGenerator() -void cNoise3DGenerator::Initialize(cWorld * a_World, cIniFile & a_IniFile) +void cNoise3DGenerator::Initialize(cIniFile & a_IniFile) { - m_World = a_World; - // Params: m_SeaLevel = a_IniFile.GetValueSetI("Generator", "Noise3DSeaLevel", 62); m_HeightAmplification = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0); diff --git a/src/Generating/Noise3DGenerator.h b/src/Generating/Noise3DGenerator.h index 0d211cddc..42f61a854 100644 --- a/src/Generating/Noise3DGenerator.h +++ b/src/Generating/Noise3DGenerator.h @@ -24,7 +24,7 @@ public: cNoise3DGenerator(cChunkGenerator & a_ChunkGenerator); virtual ~cNoise3DGenerator(); - virtual void Initialize(cWorld * a_World, cIniFile & a_IniFile) override; + virtual void Initialize(cIniFile & a_IniFile) override; virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) override; diff --git a/src/World.cpp b/src/World.cpp index 39300d419..1cf82d641 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -10,6 +10,7 @@ #include "Root.h" #include "inifile/iniFile.h" #include "ChunkMap.h" +#include "Generating/ChunkDesc.h" #include "OSSupport/Timer.h" // Entities (except mobs): @@ -238,6 +239,7 @@ cWorld::cWorld(const AString & a_WorldName) : m_SkyDarkness(0), m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) + m_GeneratorCallbacks(*this), m_TickThread(*this) { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); @@ -583,7 +585,7 @@ void cWorld::Start(void) m_Lighting.Start(this); m_Storage.Start(this, m_StorageSchema); - m_Generator.Start(this, IniFile); + m_Generator.Start(m_GeneratorCallbacks, m_GeneratorCallbacks, IniFile); m_ChunkSender.Start(this); m_TickThread.Start(); @@ -2843,3 +2845,77 @@ void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World) +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cWorld::cChunkGeneratorCallbacks: + +cWorld::cChunkGeneratorCallbacks::cChunkGeneratorCallbacks(cWorld & a_World) : + m_World(&a_World) +{ +} + + + + + +void cWorld::cChunkGeneratorCallbacks::OnChunkGenerated(cChunkDesc & a_ChunkDesc) +{ + cChunkDef::BlockNibbles BlockMetas; + a_ChunkDesc.CompressBlockMetas(BlockMetas); + + m_World->SetChunkData( + a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ(), + a_ChunkDesc.GetBlockTypes(), BlockMetas, + NULL, NULL, // We don't have lighting, chunk will be lighted when needed + &a_ChunkDesc.GetHeightMap(), &a_ChunkDesc.GetBiomeMap(), + a_ChunkDesc.GetEntities(), a_ChunkDesc.GetBlockEntities(), + true + ); + + // Save the chunk right after generating, so that we don't have to generate it again on next run + m_World->GetStorage().QueueSaveChunk(a_ChunkDesc.GetChunkX(), 0, a_ChunkDesc.GetChunkZ()); +} + + + + + +bool cWorld::cChunkGeneratorCallbacks::IsChunkValid(int a_ChunkX, int a_ChunkZ) +{ + return m_World->IsChunkValid(a_ChunkX, a_ChunkZ); +} + + + + + +bool cWorld::cChunkGeneratorCallbacks::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) +{ + return m_World->HasChunkAnyClients(a_ChunkX, a_ChunkZ); +} + + + + + +void cWorld::cChunkGeneratorCallbacks::CallHookChunkGenerating(cChunkDesc & a_ChunkDesc) +{ + cPluginManager::Get()->CallHookChunkGenerating( + m_World, a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ(), &a_ChunkDesc + ); +} + + + + + +void cWorld::cChunkGeneratorCallbacks::CallHookChunkGenerated (cChunkDesc & a_ChunkDesc) +{ + cPluginManager::Get()->CallHookChunkGenerated( + m_World, a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ(), &a_ChunkDesc + ); +} + + + + + diff --git a/src/World.h b/src/World.h index f90ddd90f..b61708d03 100644 --- a/src/World.h +++ b/src/World.h @@ -636,6 +636,27 @@ private: virtual void Execute(void) override; } ; + + /** Implementation of the callbacks that the ChunkGenerator uses to store new chunks and interface to plugins */ + class cChunkGeneratorCallbacks : + public cChunkGenerator::cChunkSink, + public cChunkGenerator::cPluginInterface + { + cWorld * m_World; + + // cChunkSink overrides: + virtual void OnChunkGenerated (cChunkDesc & a_ChunkDesc) override; + virtual bool IsChunkValid (int a_ChunkX, int a_ChunkZ) override; + virtual bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) override; + + // cPluginInterface overrides: + virtual void CallHookChunkGenerating(cChunkDesc & a_ChunkDesc) override; + virtual void CallHookChunkGenerated (cChunkDesc & a_ChunkDesc) override; + + public: + cChunkGeneratorCallbacks(cWorld & a_World); + } ; + AString m_WorldName; AString m_IniFileName; @@ -714,6 +735,9 @@ private: cChunkGenerator m_Generator; + /** The callbacks that the ChunkGenerator uses to store new chunks and interface to plugins */ + cChunkGeneratorCallbacks m_GeneratorCallbacks; + cChunkSender m_ChunkSender; cLightingThread m_Lighting; cTickThread m_TickThread; -- cgit v1.2.3 From af89794d760c04f1caf5f437de0f1dfa2803307c Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Fri, 10 Jan 2014 15:50:52 -0600 Subject: Globals.h needs to be first include --- src/BiomeDef.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index f41f4bce4..89a1cdefb 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -3,8 +3,8 @@ // Implements biome helper functions -#include "BiomeDef.h" #include "Globals.h" +#include "BiomeDef.h" EMCSBiome StringToBiome(const AString & a_BiomeString) -- cgit v1.2.3 From 05e22dccf2682b61b32aa83241bbc52d57ddecaa Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 11 Jan 2014 11:38:34 +0200 Subject: Fixed glowstone drop count --- src/Blocks/BlockGlowstone.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockGlowstone.h b/src/Blocks/BlockGlowstone.h index 5f0d95dee..6c198efc4 100644 --- a/src/Blocks/BlockGlowstone.h +++ b/src/Blocks/BlockGlowstone.h @@ -20,8 +20,8 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { // Reset meta to 0 - // TODO: More drops? - a_Pickups.push_back(cItem(E_ITEM_GLOWSTONE_DUST, 1, 0)); + MTRand r1; + a_Pickups.push_back(cItem(E_ITEM_GLOWSTONE_DUST, (char)(2 + r1.randInt(2)), 0)); } } ; -- cgit v1.2.3 From 2634261a289a856dd0d96eaebbc68b831d982aff Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 11 Jan 2014 20:29:56 +0100 Subject: Removed unused variables. The Lua API calls had no side-effects, either. --- src/Bindings/ManualBindings.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 344d5d2e0..f0dd00300 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -991,7 +991,6 @@ static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S) const cPluginManager::PluginMap & AllPlugins = self->GetAllPlugins(); lua_newtable(tolua_S); - int newTable = lua_gettop(tolua_S); int index = 1; cPluginManager::PluginMap::const_iterator iter = AllPlugins.begin(); while (iter != AllPlugins.end()) @@ -1883,7 +1882,6 @@ static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S) const cWebPlugin::TabNameList & TabNames = self->GetTabNames(); lua_newtable(tolua_S); - int newTable = lua_gettop(tolua_S); int index = 1; cWebPlugin::TabNameList::const_iterator iter = TabNames.begin(); while(iter != TabNames.end()) -- cgit v1.2.3 From acfebab0272e605a05e39ef1926f1d4216faf236 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 11 Jan 2014 21:22:40 +0100 Subject: Removed an unused file. --- src/Bindings/AllToLua.pkg | 2 - src/Bindings/tolua_base.h | 128 ---------------------------------------------- 2 files changed, 130 deletions(-) delete mode 100644 src/Bindings/tolua_base.h (limited to 'src') diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index e9a5ea0c6..0dcead7d2 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -1,8 +1,6 @@ $#include "../Globals.h" -$#include "tolua_base.h" - // Typedefs from Globals.h, so that we don't have to process that file: typedef long long Int64; typedef int Int32; diff --git a/src/Bindings/tolua_base.h b/src/Bindings/tolua_base.h deleted file mode 100644 index 6a76f97b1..000000000 --- a/src/Bindings/tolua_base.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef TOLUA_BASE_H -#define TOLUA_BASE_H - -#pragma warning(disable:4800) // This file is ONLY included by Bindings.cpp and it throws lots of C4800 warnings - -#include "tolua++/include/tolua++.h" - - - - - -class ToluaBase { - - int lua_instance; - -protected: - - lua_State* lua_state; - - void lua_stacktrace(lua_State* L) const - { - lua_Debug entry; - int depth = 0; - - while (lua_getstack(L, depth, &entry)) - { - lua_getinfo(L, "Sln", &entry); - - LOGERROR("%s(%d): %s", entry.short_src, entry.currentline, entry.name ? entry.name : "?"); - depth++; - } - } - - - bool report_errors(int status) const - { - if ( status!=0 ) - { - const char* s = lua_tostring(lua_state, -1); - LOGERROR("-- %s", s ); - //lua_pop(lua_state, 1); - LOGERROR("Stack:"); - lua_stacktrace( lua_state ); - return true; - } - return false; - } - - bool push_method(const char* name, lua_CFunction f) const { - - if (!lua_state) return false; - - lua_getref(lua_state, lua_instance); - lua_pushstring(lua_state, name); - //LOGINFO("1. push_method() Stack size: %i", lua_gettop( lua_state ) ); - lua_gettable(lua_state, -2); - //LOGINFO("2. push_method() Stack size: %i", lua_gettop( lua_state ) ); - - if (lua_isnil(lua_state, -1)) { - - // pop the table - lua_pop(lua_state, 2); - return false; - - } else { - - if (f) { - if (lua_iscfunction(lua_state, -1)) { - lua_pop(lua_state, 2); - return false; - }; - /* // not for now - lua_pushcfunction(lua_state, f); - if (lua_rawequal(lua_state, -1, -2)) { - - // avoid recursion, pop both functions and the table - lua_pop(lua_state, 3); - return false; - }; - - // pop f - lua_pop(lua_state, 1); - */ - }; - - // swap table with function - lua_insert(lua_state, -2); - }; - - return true; - }; - - void dbcall(lua_State* L, int nargs, int nresults) const { - - // using lua_call for now - int s = lua_pcall(L, nargs, nresults, 0); - report_errors( s ); - }; -public: - - int GetInstance() { return lua_instance; } - lua_State* GetLuaState() { return lua_state; } - - void tolua__set_instance(lua_State* L, lua_Object lo) { - - lua_state = L; - - lua_pushvalue(L, lo); - lua_instance = lua_ref(lua_state, 1); - }; - - ToluaBase() { - - lua_state = NULL; - }; - - ~ToluaBase() { - - if (lua_state) { - - lua_unref(lua_state, lua_instance); - }; - }; -}; - -#endif - - -- cgit v1.2.3 From b2b7e457570e87c87a3c158271ae3bffd823987c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 11 Jan 2014 22:51:10 +0100 Subject: Removed internal methods from public cLuaState interface. PushFunction(), CallFunction() and GetReturn() are not to be called independently, but rather only by using the Call() templated overrides. Push() needs to be left in the public part, it is used for pushing results in the ManualBindings. Preparation for #418. --- src/Bindings/LuaState.cpp | 26 +++++++---- src/Bindings/LuaState.h | 98 +++++++++++++++++++++++++---------------- src/Bindings/ManualBindings.cpp | 98 +++++++++++------------------------------ 3 files changed, 103 insertions(+), 119 deletions(-) (limited to 'src') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 83351591c..1dd2b4dd8 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -264,27 +264,26 @@ bool cLuaState::PushFunction(int a_FnRef) -bool cLuaState::PushFunctionFromRefTable(cRef & a_TableRef, const char * a_FnName) +bool cLuaState::PushFunction(const cTableRef & a_TableRef) { ASSERT(IsValid()); ASSERT(m_NumCurrentFunctionArgs == -1); // If not, there's already something pushed onto the stack - - lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_TableRef); // Get the table ref + + lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_TableRef.GetTableRef()); // Get the table ref if (!lua_istable(m_LuaState, -1)) { // Not a table, bail out lua_pop(m_LuaState, 1); return false; } - lua_getfield(m_LuaState, -1, a_FnName); + lua_getfield(m_LuaState, -1, a_TableRef.GetFnName()); if (lua_isnil(m_LuaState, -1) || !lua_isfunction(m_LuaState, -1)) { // Not a valid function, bail out lua_pop(m_LuaState, 2); return false; } - lua_remove(m_LuaState, -2); // Remove the table ref from the stack - m_CurrentFunctionName = ""; + Printf(m_CurrentFunctionName, "", a_TableRef.GetFnName()); m_NumCurrentFunctionArgs = 0; return true; } @@ -963,16 +962,25 @@ bool cLuaState::ReportErrors(lua_State * a_LuaState, int a_Status) void cLuaState::LogStackTrace(void) +{ + LogStackTrace(m_LuaState); +} + + + + + +void cLuaState::LogStackTrace(lua_State * a_LuaState) { LOGWARNING("Stack trace:"); lua_Debug entry; int depth = 0; - while (lua_getstack(m_LuaState, depth, &entry)) + while (lua_getstack(a_LuaState, depth, &entry)) { - int status = lua_getinfo(m_LuaState, "Sln", &entry); + int status = lua_getinfo(a_LuaState, "Sln", &entry); assert(status); - LOGWARNING(" %s(%d): %s", entry.short_src, entry.currentline, entry.name ? entry.name : "?"); + LOGWARNING(" %s(%d): %s", entry.short_src, entry.currentline, entry.name ? entry.name : "(no name)"); depth++; } LOGWARNING("Stack trace end"); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 796559b6f..c77dbeb7f 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -85,6 +85,23 @@ public: } ; + /** Used for calling functions stored in a reference-stored table */ + class cTableRef + { + int m_TableRef; + const char * m_FnName; + public: + cTableRef(int a_TableRef, const char * a_FnName) : + m_TableRef(a_TableRef), + m_FnName(a_FnName) + { + } + + int GetTableRef(void) const { return m_TableRef; } + const char * GetFnName(void) const { return m_FnName; } + } ; + + /// A dummy class that's used only to delimit function args from return values for cLuaState::Call() class cRet { @@ -133,24 +150,6 @@ public: /// Returns true if a_FunctionName is a valid Lua function that can be called bool HasFunction(const char * a_FunctionName); - /** Pushes the function of the specified name onto the stack. - Returns true if successful. Logs a warning on failure (incl. m_SubsystemName) - */ - bool PushFunction(const char * a_FunctionName); - - /** Pushes a function that has been saved into the global registry, identified by a_FnRef. - Returns true if successful. Logs a warning on failure - */ - bool PushFunction(int a_FnRef); - - /** Pushes a function that is stored in a table ref. - Returns true if successful, false on failure. Doesn't log failure. - */ - bool PushFunctionFromRefTable(cRef & a_TableRef, const char * a_FnName); - - /// Pushes a usertype of the specified class type onto the stack - void PushUserType(void * a_Object, const char * a_Type); - // Push a value onto the stack void Push(const AString & a_String); void Push(const AStringVector & a_Vector); @@ -183,7 +182,7 @@ public: void Push(void * a_Ptr); void Push(cHopperEntity * a_Hopper); void Push(cBlockEntity * a_BlockEntity); - + /// Call any 0-param 0-return Lua function in a single line: template bool Call(FnT a_FnName) @@ -802,25 +801,6 @@ public: } - /// Retrieve value returned at a_StackPos, if it is a valid bool. If not, a_ReturnedVal is unchanged - void GetReturn(int a_StackPos, bool & a_ReturnedVal); - - /// Retrieve value returned at a_StackPos, if it is a valid string. If not, a_ReturnedVal is unchanged - void GetReturn(int a_StackPos, AString & a_ReturnedVal); - - /// Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged - void GetReturn(int a_StackPos, int & a_ReturnedVal); - - /// Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged - void GetReturn(int a_StackPos, double & a_ReturnedVal); - - /** - Calls the function that has been pushed onto the stack by PushFunction(), - with arguments pushed by PushXXX(). - Returns true if successful, logs a warning on failure. - */ - bool CallFunction(int a_NumReturnValues); - /// Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions bool CheckParamUserTable(int a_StartParam, const char * a_UserTable, int a_EndParam = -1); @@ -848,6 +828,9 @@ public: /// Logs all items in the current stack trace to the server console void LogStackTrace(void); + /// Logs all items in the current stack trace to the server console + static void LogStackTrace(lua_State * a_LuaState); + /// Returns the type of the item on the specified position in the stack AString GetTypeText(int a_StackPos); @@ -867,6 +850,45 @@ protected: /// Number of arguments currently pushed (for the Push / Call chain) int m_NumCurrentFunctionArgs; + + + /** Pushes the function of the specified name onto the stack. + Returns true if successful. Logs a warning on failure (incl. m_SubsystemName) + */ + bool PushFunction(const char * a_FunctionName); + + /** Pushes a function that has been saved into the global registry, identified by a_FnRef. + Returns true if successful. Logs a warning on failure + */ + bool PushFunction(int a_FnRef); + + /** Pushes a function that is stored in a referenced table by name + Returns true if successful. Logs a warning on failure + */ + bool PushFunction(const cTableRef & a_TableRef); + + /// Pushes a usertype of the specified class type onto the stack + void PushUserType(void * a_Object, const char * a_Type); + + /// Retrieve value returned at a_StackPos, if it is a valid bool. If not, a_ReturnedVal is unchanged + void GetReturn(int a_StackPos, bool & a_ReturnedVal); + + /// Retrieve value returned at a_StackPos, if it is a valid string. If not, a_ReturnedVal is unchanged + void GetReturn(int a_StackPos, AString & a_ReturnedVal); + + /// Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged + void GetReturn(int a_StackPos, int & a_ReturnedVal); + + /// Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged + void GetReturn(int a_StackPos, double & a_ReturnedVal); + + /** + Calls the function that has been pushed onto the stack by PushFunction(), + with arguments pushed by PushXXX(). + Returns true if successful, logs a warning on failure. + */ + bool CallFunction(int a_NumReturnValues); + } ; diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index f0dd00300..a9368f613 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1980,118 +1980,72 @@ public: virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override { - if (!m_LuaState.PushFunctionFromRefTable(m_TableRef, "OnNextBlock")) + bool res = false; + if (!m_LuaState.Call( + cLuaState::cTableRef(m_TableRef, "OnNextBlock"), + a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_EntryFace, + cLuaState::Return, res + )) { // No such function in the table, skip the callback return false; } - m_LuaState.Push(a_BlockX); - m_LuaState.Push(a_BlockY); - m_LuaState.Push(a_BlockZ); - m_LuaState.Push(a_BlockType); - m_LuaState.Push(a_BlockMeta); - m_LuaState.Push(a_EntryFace); - if (!m_LuaState.CallFunction(1)) - { - return false; - } - bool res = false; - if (lua_isboolean(m_LuaState, -1)) - { - res = (lua_toboolean(m_LuaState, -1) != 0); - } - lua_pop(m_LuaState, 1); return res; } virtual bool OnNextBlockNoData(int a_BlockX, int a_BlockY, int a_BlockZ, char a_EntryFace) override { - if (!m_LuaState.PushFunctionFromRefTable(m_TableRef, "OnNextBlockNoData")) + bool res = false; + if (!m_LuaState.Call( + cLuaState::cTableRef(m_TableRef, "OnNextBlockNoData"), + a_BlockX, a_BlockY, a_BlockZ, a_EntryFace, + cLuaState::Return, res + )) { // No such function in the table, skip the callback return false; } - m_LuaState.Push(a_BlockX); - m_LuaState.Push(a_BlockY); - m_LuaState.Push(a_BlockZ); - m_LuaState.Push(a_EntryFace); - if (!m_LuaState.CallFunction(1)) - { - return false; - } - bool res = false; - if (lua_isboolean(m_LuaState, -1)) - { - res = (lua_toboolean(m_LuaState, -1) != 0); - } - lua_pop(m_LuaState, 1); return res; } virtual bool OnOutOfWorld(double a_BlockX, double a_BlockY, double a_BlockZ) override { - if (!m_LuaState.PushFunctionFromRefTable(m_TableRef, "OnOutOfWorld")) + bool res = false; + if (!m_LuaState.Call( + cLuaState::cTableRef(m_TableRef, "OnOutOfWorld"), + a_BlockX, a_BlockY, a_BlockZ, + cLuaState::Return, res + )) { // No such function in the table, skip the callback return false; } - m_LuaState.Push(a_BlockX); - m_LuaState.Push(a_BlockY); - m_LuaState.Push(a_BlockZ); - if (!m_LuaState.CallFunction(1)) - { - return false; - } - bool res = false; - if (lua_isboolean(m_LuaState, -1)) - { - res = (lua_toboolean(m_LuaState, -1) != 0); - } - lua_pop(m_LuaState, 1); return res; } virtual bool OnIntoWorld(double a_BlockX, double a_BlockY, double a_BlockZ) override { - if (!m_LuaState.PushFunctionFromRefTable(m_TableRef, "OnIntoWorld")) + bool res = false; + if (!m_LuaState.Call( + cLuaState::cTableRef(m_TableRef, "OnIntoWorld"), + a_BlockX, a_BlockY, a_BlockZ, + cLuaState::Return, res + )) { // No such function in the table, skip the callback return false; } - m_LuaState.Push(a_BlockX); - m_LuaState.Push(a_BlockY); - m_LuaState.Push(a_BlockZ); - if (!m_LuaState.CallFunction(1)) - { - return false; - } - bool res = false; - if (lua_isboolean(m_LuaState, -1)) - { - res = (lua_toboolean(m_LuaState, -1) != 0); - } - lua_pop(m_LuaState, 1); return res; } virtual void OnNoMoreHits(void) override { - if (!m_LuaState.PushFunctionFromRefTable(m_TableRef, "OnNoMoreHits")) - { - // No such function in the table, skip the callback - return; - } - m_LuaState.CallFunction(0); + m_LuaState.Call(cLuaState::cTableRef(m_TableRef, "OnNoMoreHits")); } virtual void OnNoChunk(void) override { - if (!m_LuaState.PushFunctionFromRefTable(m_TableRef, "OnNoChunk")) - { - // No such function in the table, skip the callback - return; - } - m_LuaState.CallFunction(0); + m_LuaState.Call(cLuaState::cTableRef(m_TableRef, "OnNoChunk")); } protected: -- cgit v1.2.3 From 023ba1768837e4a8c29996dbcf82a64366b30629 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 11 Jan 2014 23:10:40 +0100 Subject: Lua errors display stack trace. Fixes #418. --- src/Bindings/LuaState.cpp | 28 +++++++++++++++++++++++++--- src/Bindings/LuaState.h | 2 ++ 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 1dd2b4dd8..149c304ed 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -228,6 +228,9 @@ bool cLuaState::PushFunction(const char * a_FunctionName) return false; } + // Push the error handler for lua_pcall() + lua_pushcfunction(m_LuaState, &ReportFnCallErrors); + lua_getglobal(m_LuaState, a_FunctionName); if (!lua_isfunction(m_LuaState, -1)) { @@ -249,6 +252,9 @@ bool cLuaState::PushFunction(int a_FnRef) ASSERT(IsValid()); ASSERT(m_NumCurrentFunctionArgs == -1); // If not, there's already something pushed onto the stack + // Push the error handler for lua_pcall() + lua_pushcfunction(m_LuaState, &ReportFnCallErrors); + lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_FnRef); // same as lua_getref() if (!lua_isfunction(m_LuaState, -1)) { @@ -269,6 +275,9 @@ bool cLuaState::PushFunction(const cTableRef & a_TableRef) ASSERT(IsValid()); ASSERT(m_NumCurrentFunctionArgs == -1); // If not, there's already something pushed onto the stack + // Push the error handler for lua_pcall() + lua_pushcfunction(m_LuaState, &ReportFnCallErrors); + lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_TableRef.GetTableRef()); // Get the table ref if (!lua_istable(m_LuaState, -1)) { @@ -731,11 +740,13 @@ void cLuaState::GetReturn(int a_StackPos, double & a_ReturnedVal) bool cLuaState::CallFunction(int a_NumResults) { ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first - ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 1)); + ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 1)); // The function to call + ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 2)); // The error handler - int s = lua_pcall(m_LuaState, m_NumCurrentFunctionArgs, a_NumResults, 0); - if (ReportErrors(s)) + int s = lua_pcall(m_LuaState, m_NumCurrentFunctionArgs, a_NumResults, -m_NumCurrentFunctionArgs - 2); + if (s != 0) { + // The error has already been printed together with the stacktrace LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), m_CurrentFunctionName.c_str()); m_NumCurrentFunctionArgs = -1; m_CurrentFunctionName.clear(); @@ -1013,6 +1024,17 @@ AString cLuaState::GetTypeText(int a_StackPos) +int cLuaState::ReportFnCallErrors(lua_State * a_LuaState) +{ + LOGWARNING("LUA: %s", lua_tostring(a_LuaState, -1)); + LogStackTrace(a_LuaState); + return 1; // We left the error message on the stack as the return value +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cLuaState::cRef: diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index c77dbeb7f..a43d39732 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -889,6 +889,8 @@ protected: */ bool CallFunction(int a_NumReturnValues); + /** Used as the error reporting function for function calls */ + static int ReportFnCallErrors(lua_State * a_LuaState); } ; -- cgit v1.2.3 From 328b2db252fe42774cc001bf1a62d32fe7317c72 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 12 Jan 2014 08:43:13 +0100 Subject: Disabled a useless MSVC warning in Bindings.cpp. --- src/Bindings/tolua++.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/Bindings/tolua++.h b/src/Bindings/tolua++.h index 4dfd06318..73e65b746 100644 --- a/src/Bindings/tolua++.h +++ b/src/Bindings/tolua++.h @@ -2,12 +2,18 @@ // tolua++.h // Redirection file, needed because ToLua++ generates the Bindings.cpp file with >> #include "tolua++.h" << +// Only used from Bindings.cpp #include "tolua++/include/tolua++.h" +#ifdef _MSC_VER + // Disable specific warnings for the generated Bindings.cpp file: + #pragma warning(disable: 4800) // 'int' : forcing value to bool 'true' or 'false' (performance warning) +#endif // _MSC_VER + -- cgit v1.2.3