summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Bindings/ManualBindings.cpp2
-rw-r--r--src/Globals.h7
-rw-r--r--src/World.cpp53
-rw-r--r--src/World.h18
4 files changed, 41 insertions, 39 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index f643f06ec..0558533ce 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1160,7 +1160,7 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S)
return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1");
}
- self->QueueTask(new cLuaWorldTask(*Plugin, FnRef));
+ self->QueueTask(make_unique<cLuaWorldTask>(*Plugin, FnRef));
return 0;
}
diff --git a/src/Globals.h b/src/Globals.h
index 4ee1352eb..5c5a8b3d2 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -419,6 +419,12 @@ typename std::enable_if<std::is_arithmetic<T>::value, C>::type CeilC(T a_Value)
+//temporary replacement for std::make_unique until we get c++14
+template< class T, class... Args >
+std::unique_ptr<T> make_unique( Args&&... args )
+{
+ return std::unique_ptr<T>(new T(args...));
+}
#ifndef TOLUA_TEMPLATE_BIND
@@ -436,3 +442,4 @@ typename std::enable_if<std::is_arithmetic<T>::value, C>::type CeilC(T a_Value)
#include "BlockInfo.h"
+
diff --git a/src/World.cpp b/src/World.cpp
index a3c804b44..a23db6242 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -256,14 +256,14 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
m_IsDeepSnowEnabled(false),
m_ShouldLavaSpawnFire(true),
m_VillagersShouldHarvestCrops(true),
- m_SimulatorManager(NULL),
- m_SandSimulator(NULL),
+ m_SimulatorManager(),
+ m_SandSimulator(),
m_WaterSimulator(NULL),
- m_LavaSimulator(NULL),
- m_FireSimulator(NULL),
+ m_LavaSimulator(nullptr),
+ m_FireSimulator(),
m_RedstoneSimulator(NULL),
m_MaxPlayers(10),
- m_ChunkMap(NULL),
+ m_ChunkMap(),
m_bAnimals(true),
m_Weather(eWeather_Sunny),
m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :)
@@ -303,11 +303,8 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
cWorld::~cWorld()
{
- delete m_SimulatorManager; m_SimulatorManager = NULL;
- delete m_SandSimulator; m_SandSimulator = NULL;
delete m_WaterSimulator; m_WaterSimulator = NULL;
delete m_LavaSimulator; m_LavaSimulator = NULL;
- delete m_FireSimulator; m_FireSimulator = NULL;
delete m_RedstoneSimulator; m_RedstoneSimulator = NULL;
UnloadUnusedChunks();
@@ -319,8 +316,6 @@ cWorld::~cWorld()
Serializer.Save();
m_MapManager.SaveMapData();
-
- delete m_ChunkMap;
}
@@ -631,7 +626,7 @@ void cWorld::Start(void)
InitialiseAndLoadMobSpawningValues(IniFile);
SetTimeOfDay(IniFile.GetValueSetI("General", "TimeInTicks", m_TimeOfDay));
- m_ChunkMap = new cChunkMap(this);
+ m_ChunkMap = make_unique<cChunkMap>(this);
m_LastSave = 0;
m_LastUnload = 0;
@@ -641,16 +636,16 @@ void cWorld::Start(void)
m_BlockTickQueueCopy.reserve(1000);
// Simulators:
- m_SimulatorManager = new cSimulatorManager(*this);
+ m_SimulatorManager = make_unique<cSimulatorManager>(*this);
m_WaterSimulator = InitializeFluidSimulator(IniFile, "Water", E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER);
m_LavaSimulator = InitializeFluidSimulator(IniFile, "Lava", E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
- m_SandSimulator = new cSandSimulator(*this, IniFile);
- m_FireSimulator = new cFireSimulator(*this, IniFile);
+ m_SandSimulator = make_unique<cSandSimulator>(*this, IniFile);
+ m_FireSimulator = make_unique<cFireSimulator>(*this, IniFile);
m_RedstoneSimulator = InitializeRedstoneSimulator(IniFile);
// Water, Lava and Redstone simulators get registered in their initialize function.
- m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1);
- m_SimulatorManager->RegisterSimulator(m_FireSimulator, 1);
+ m_SimulatorManager->RegisterSimulator(m_SandSimulator.get(), 1);
+ m_SimulatorManager->RegisterSimulator(m_FireSimulator.get(), 1);
m_Lighting.Start(this);
m_Storage.Start(this, m_StorageSchema, m_StorageCompressionFactor);
@@ -1059,7 +1054,6 @@ void cWorld::TickQueuedTasks(void)
for (cTasks::iterator itr = Tasks.begin(), end = Tasks.end(); itr != end; ++itr)
{
(*itr)->Run(*this);
- delete *itr;
} // for itr - m_Tasks[]
}
@@ -1073,18 +1067,19 @@ void cWorld::TickScheduledTasks(void)
cScheduledTasks Tasks;
{
cCSLock Lock(m_CSScheduledTasks);
- while (!m_ScheduledTasks.empty() && (m_ScheduledTasks.front()->m_TargetTick < m_WorldAge))
- {
- Tasks.push_back(m_ScheduledTasks.front());
- m_ScheduledTasks.pop_front();
- }
+ std::move(
+ m_ScheduledTasks.begin(),
+ std::find_if(
+ m_ScheduledTasks.begin(),
+ m_ScheduledTasks.end(),
+ [m_WorldAge] (std::unique_ptr<cScheduledTask>& Task) { return Task->m_TargetTick < m_WorldAge;}),
+ std::back_inserter(Tasks));
}
// Execute and delete each task:
for (cScheduledTasks::iterator itr = Tasks.begin(), end = Tasks.end(); itr != end; ++itr)
{
(*itr)->m_Task->Run(*this);
- delete *itr;
} // for itr - m_Tasks[]
}
@@ -2593,7 +2588,7 @@ void cWorld::UnloadUnusedChunks(void)
void cWorld::QueueUnloadUnusedChunks(void)
{
- QueueTask(new cWorld::cTaskUnloadUnusedChunks);
+ QueueTask(make_unique<cWorld::cTaskUnloadUnusedChunks>());
}
@@ -3049,17 +3044,17 @@ void cWorld::SaveAllChunks(void)
void cWorld::QueueSaveAllChunks(void)
{
- QueueTask(new cWorld::cTaskSaveAllChunks);
+ QueueTask(make_unique<cWorld::cTaskSaveAllChunks>());
}
-void cWorld::QueueTask(cTask * a_Task)
+void cWorld::QueueTask(std::unique_ptr<cTask> a_Task)
{
cCSLock Lock(m_CSTasks);
- m_Tasks.push_back(a_Task);
+ m_Tasks.push_back(std::move(a_Task));
}
@@ -3076,11 +3071,11 @@ void cWorld::ScheduleTask(int a_DelayTicks, cTask * a_Task)
{
if ((*itr)->m_TargetTick >= TargetTick)
{
- m_ScheduledTasks.insert(itr, new cScheduledTask(TargetTick, a_Task));
+ m_ScheduledTasks.insert(itr, make_unique<cScheduledTask>(TargetTick, a_Task));
return;
}
}
- m_ScheduledTasks.push_back(new cScheduledTask(TargetTick, a_Task));
+ m_ScheduledTasks.push_back(make_unique<cScheduledTask>(TargetTick, a_Task));
}
diff --git a/src/World.h b/src/World.h
index 90dada259..66dd2494e 100644
--- a/src/World.h
+++ b/src/World.h
@@ -103,7 +103,7 @@ public:
virtual void Run(cWorld & a_World) = 0;
} ;
- typedef std::vector<cTask *> cTasks;
+ typedef std::vector<std::unique_ptr<cTask>> cTasks;
class cTaskSaveAllChunks :
@@ -506,7 +506,7 @@ public:
// tolua_end
- inline cSimulatorManager * GetSimulatorManager(void) { return m_SimulatorManager; }
+ inline cSimulatorManager * GetSimulatorManager(void) { return m_SimulatorManager.get(); }
inline cFluidSimulator * GetWaterSimulator(void) { return m_WaterSimulator; }
inline cFluidSimulator * GetLavaSimulator (void) { return m_LavaSimulator; }
@@ -671,7 +671,7 @@ public:
void QueueSaveAllChunks(void); // tolua_export
/** Queues a task onto the tick thread. The task object will be deleted once the task is finished */
- void QueueTask(cTask * a_Task); // Exported in ManualBindings.cpp
+ void QueueTask(std::unique_ptr<cTask> a_Task); // Exported in ManualBindings.cpp
/** Queues a task onto the tick thread, with the specified delay.
The task object will be deleted once the task is finished */
@@ -764,7 +764,7 @@ public:
cChunkGenerator & GetGenerator(void) { return m_Generator; }
cWorldStorage & GetStorage (void) { return m_Storage; }
- cChunkMap * GetChunkMap (void) { return m_ChunkMap; }
+ cChunkMap * GetChunkMap (void) { return m_ChunkMap.get(); }
/** Sets the blockticking to start at the specified block. Only one blocktick per chunk may be set, second call overwrites the first call */
void SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export
@@ -861,7 +861,7 @@ private:
}
};
- typedef std::list<cScheduledTask *> cScheduledTasks;
+ typedef std::list<std::unique_ptr<cScheduledTask>> cScheduledTasks;
AString m_WorldName;
@@ -913,11 +913,11 @@ private:
std::vector<BlockTickQueueItem *> m_BlockTickQueue;
std::vector<BlockTickQueueItem *> m_BlockTickQueueCopy; // Second is for safely removing the objects from the queue
- cSimulatorManager * m_SimulatorManager;
- cSandSimulator * m_SandSimulator;
+ std::unique_ptr<cSimulatorManager> m_SimulatorManager;
+ std::unique_ptr<cSandSimulator> m_SandSimulator;
cFluidSimulator * m_WaterSimulator;
cFluidSimulator * m_LavaSimulator;
- cFireSimulator * m_FireSimulator;
+ std::unique_ptr<cFireSimulator> m_FireSimulator;
cRedstoneSimulator<cChunk, cWorld> * m_RedstoneSimulator;
cCriticalSection m_CSPlayers;
@@ -927,7 +927,7 @@ private:
unsigned int m_MaxPlayers;
- cChunkMap * m_ChunkMap;
+ std::unique_ptr<cChunkMap> m_ChunkMap;
bool m_bAnimals;
std::set<eMonsterType> m_AllowedMobs;