summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-06-15 23:16:37 +0200
committerMattes D <github@xoft.cz>2014-06-15 23:16:37 +0200
commita72ec6300d7f634f8ecab4ed3dd16e553dd10045 (patch)
tree11d5b4a1aed9b5e1c44394c218c10c6a6492c7f0 /src
parentFixed bad comparison crash (diff)
parentPlayers are saved regularly (diff)
downloadcuberite-a72ec6300d7f634f8ecab4ed3dd16e553dd10045.tar
cuberite-a72ec6300d7f634f8ecab4ed3dd16e553dd10045.tar.gz
cuberite-a72ec6300d7f634f8ecab4ed3dd16e553dd10045.tar.bz2
cuberite-a72ec6300d7f634f8ecab4ed3dd16e553dd10045.tar.lz
cuberite-a72ec6300d7f634f8ecab4ed3dd16e553dd10045.tar.xz
cuberite-a72ec6300d7f634f8ecab4ed3dd16e553dd10045.tar.zst
cuberite-a72ec6300d7f634f8ecab4ed3dd16e553dd10045.zip
Diffstat (limited to 'src')
-rw-r--r--src/Entities/Player.cpp19
-rw-r--r--src/Entities/Player.h5
2 files changed, 22 insertions, 2 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index f1e0aad7e..fdc0bb390 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -22,6 +22,12 @@
#include "inifile/iniFile.h"
#include "json/json.h"
+// 6000 ticks or 5 minutes
+#define PLAYER_INVENTORY_SAVE_INTERVAL 6000
+
+// 1000 = once per second
+#define PLAYER_LIST_TIME_MS 1000
+
@@ -64,6 +70,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
, m_BowCharge(0)
, m_FloaterID(-1)
, m_Team(NULL)
+ , m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL)
{
LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d",
a_PlayerName.c_str(), a_Client->GetIPString().c_str(),
@@ -250,7 +257,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
// Send Player List (Once per m_LastPlayerListTime/1000 ms)
cTimer t1;
- if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime())
+ if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime())
{
m_World->SendPlayerList(this);
m_LastPlayerListTime = t1.GetNowTime();
@@ -260,6 +267,16 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
{
m_LastGroundHeight = (float)GetPosY();
}
+
+ if (m_TicksUntilNextSave == 0)
+ {
+ SaveToDisk();
+ m_TicksUntilNextSave = PLAYER_INVENTORY_SAVE_INTERVAL;
+ }
+ else
+ {
+ m_TicksUntilNextSave--;
+ }
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 325ff9005..b2142a18b 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -462,7 +462,6 @@ protected:
cItem m_DraggingItem;
long long m_LastPlayerListTime;
- static const unsigned short PLAYER_LIST_TIME_MS = 1000; // 1000 = once per second
cClientHandle * m_ClientHandle;
@@ -543,6 +542,10 @@ protected:
Set by a right click on unoccupied bed, unset by a time fast forward or teleport */
bool m_bIsInBed;
+ /** How long till the player's inventory will be saved
+ Default save interval is #defined in PLAYER_INVENTORY_SAVE_INTERVAL */
+ unsigned int m_TicksUntilNextSave;
+
} ; // tolua_export