From 7e9e7f79110e398a4d2b07de3093eaccd551f013 Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Sat, 3 Sep 2016 18:38:29 +0300 Subject: Configurable dirty unused chunk cap to avoid RAM overuse (#3359) Configurable dirty unused chunk cap to avoid RAM overuse --- src/World.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index a00e181b6..a33831eb9 100644 --- a/src/World.h +++ b/src/World.h @@ -683,7 +683,10 @@ public: void ScheduleTask(int a_DelayTicks, std::function a_Task); /** Returns the number of chunks loaded */ - int GetNumChunks() const; // tolua_export + size_t GetNumChunks() const; // tolua_export + + /** Returns the number of unused dirty chunks. That's the number of chunks that we can save and then unload. */ + size_t GetNumUnusedDirtyChunks(void) const; // tolua_export /** Returns the number of chunks loaded and dirty, and in the lighting queue */ void GetChunkStats(int & a_NumValid, int & a_NumDirty, int & a_NumInLightingQueue); @@ -851,6 +854,11 @@ private: } ; + /** The maximum number of allowed unused dirty chunks for this world. + Loaded from config, enforced every 10 seconds by freeing some unused dirty chunks + if this was exceeded. */ + size_t m_UnusedDirtyChunksCap; + AString m_WorldName; /** The name of the overworld that portals in this world should link to. @@ -889,7 +897,7 @@ private: std::chrono::milliseconds m_WorldAge; std::chrono::milliseconds m_TimeOfDay; cTickTimeLong m_LastTimeUpdate; // The tick in which the last time update has been sent. - cTickTimeLong m_LastUnload; // The last WorldAge (in ticks) in which unloading was triggerred + cTickTimeLong m_LastChunkCheck; // The last WorldAge (in ticks) in which unloading and possibly saving was triggered cTickTimeLong m_LastSave; // The last WorldAge (in ticks) in which save-all was triggerred std::map m_LastSpawnMonster; // The last WorldAge (in ticks) in which a monster was spawned (for each megatype of monster) // MG TODO : find a way to optimize without creating unmaintenability (if mob IDs are becoming unrowed) -- cgit v1.2.3