Skip to content

Commit 92f2c68

Browse files
committed
Server: Reimplement chunk cache
1 parent c996793 commit 92f2c68

13 files changed

Lines changed: 79 additions & 206 deletions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP TABLE "planet_generator_cache";
2+
ALTER TABLE "planet_chunks" ADD COLUMN "cache_state" INTEGER NOT NULL DEFAULT 0;

include/CommonLib/Chunk.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ namespace tsom
4141

4242
enum class ChunkFlag
4343
{
44-
PlayerModified,
45-
SaveToDatabase,
44+
PlayerModified, //< Chunk modified by a player
45+
SaveToDatabase, //< Chunk pending a save to the database
4646

4747
Max = SaveToDatabase
4848
};

include/ServerLib/Database/Schema.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace tsom::Database
3737
Nz::Vector3i32 position;
3838
Nz::UInt32 version;
3939
std::span<const Nz::UInt8> chunkData;
40+
bool cacheState;
4041
};
4142

4243
struct PlanetEntityPartial
@@ -59,6 +60,7 @@ namespace tsom::Database
5960
{
6061
std::string generatorName;
6162
std::string generatorHash;
63+
Nz::UInt32 seed;
6264
Nz::Vector3i32 chunkIndices;
6365
Nz::UInt32 chunkDataVersion;
6466
std::span<const Nz::UInt8> chunkData;

include/ServerLib/Database/ServerDatabase.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ namespace tsom
4141
void GetAllPlanetLinks(Nz::FunctionRef<bool(Database::PlanetLink&& /*planetLink*/)> callback) const;
4242
void GetAllPlanetChunks(Nz::UInt32 planetId, Nz::FunctionRef<bool(Database::PlanetChunk&& /*planetChunk*/)> callback) const;
4343
bool GetPlanetChunk(Nz::UInt32 planetId, const Nz::Vector3i32& chunkIndices, Nz::FunctionRef<void(Database::PlanetChunk&& /*planetChunk*/)> callback) const;
44-
bool GetPlanetGeneratorCache(const std::string& generatorName, const Nz::Vector3i32& chunkIndices, Nz::FunctionRef<void(Database::PlanetGeneratorCache&& /*planetGeneratorCache*/)> callback) const;
4544

4645
void StorePlanet(const Database::Planet& planetChunk);
4746
void StorePlanetChunk(const Database::PlanetChunk& planetChunk);
4847
void StorePlanetLink(const Database::PlanetLink& planetChunk);
49-
void StorePlanetGeneratorCache(const Database::PlanetGeneratorCache& planetGeneratorCache);
5048

5149
void Transaction(Nz::FunctionRef<bool(ServerDatabase& database)> callback);
5250

@@ -83,10 +81,6 @@ namespace tsom
8381
SQLite::Statement getAllPlanetEntitiesQuery;
8482
SQLite::Statement partialUpdatePlanetEntityQuery;
8583

86-
// planet generator cache
87-
SQLite::Statement getPlanetGeneratorCacheChunk;
88-
SQLite::Statement storePlanetGeneratorCacheChunk;
89-
9084
// planet links
9185
SQLite::Statement getAllPlanetLinkQuery;
9286
SQLite::Statement storePlanetLinkQuery;

include/ServerLib/ServerInstance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ namespace tsom
101101
std::string databaseFile;
102102
Nz::Time saveInterval = Nz::Time::Seconds(30);
103103
bool enableDebugDrawer = false;
104+
bool enableChunkCache = false;
104105
bool pauseWhenEmpty = true;
105106
};
106107

include/ServerLib/ServerPlanetEnvironment.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ namespace tsom
5858
ServerAtmosphere* GetFallbackAtmosphereAtPosition(const Nz::Vector3f& position) override;
5959
void LoadChunksFromDatabase();
6060
void LoadEntitiesFromDatabase();
61-
void SavePlanetGeneratorCache();
6261

6362
struct ChunkLoadingData
6463
{

serverconfig.lua.default

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Api = {
22
Url = "https://tsom-api.digitalpulse.software"
33
}
4+
Chunk = {
5+
EnableCache = false
6+
}
47
ConnectionToken = {
58
EncryptionKey = ""
69
}

src/Server/ServerConfigAppComponent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace tsom
1515
ServerConfigFile::ServerConfigFile()
1616
{
1717
RegisterStringOption(Config::Api_Url);
18+
RegisterBoolOption(Config::Chunk_EnableCache, false);
1819
RegisterStringOption(Config::ConnectionToken_EncryptionKey, "");
1920
RegisterIntegerOption(Config::Server_Port, 1, 0xFFFF, 29536);
2021
RegisterIntegerOption(Config::Server_MaxStuckSeconds, 0, 60, 10);

src/Server/ServerConfigs.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace tsom::Config
1313
{
14+
static constexpr auto Chunk_EnableCache = ConfigFile::BoolOptionName{ "Chunk.EnableCache" };
1415
static constexpr auto ConnectionToken_EncryptionKey = ConfigFile::StringOptionName{ "ConnectionToken.EncryptionKey" };
1516
static constexpr auto Database_Filename = ConfigFile::StringOptionName{ "Database.Filename" };
1617
static constexpr auto Debug_EnableDrawer = ConfigFile::BoolOptionName{ "Debug.EnableDrawer" };

src/Server/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ int ServerMain(int argc, char* argv[])
7777
instanceConfig.pauseWhenEmpty = config.GetBoolValue(tsom::Config::Server_SleepWhenEmpty);
7878
instanceConfig.saveInterval = Nz::Time::Seconds(config.GetIntegerValue<long long>(tsom::Config::Save_Interval));
7979
instanceConfig.connectionTokenEncryptionKey = config.GetConnectionTokenEncryptionKey();
80+
instanceConfig.enableChunkCache = config.GetBoolValue(tsom::Config::Chunk_EnableCache);
8081
instanceConfig.enableDebugDrawer = config.GetBoolValue(tsom::Config::Debug_EnableDrawer);
8182
instanceConfig.databaseFile = config.GetStringValue(tsom::Config::Database_Filename);
8283

0 commit comments

Comments
 (0)