From e88cdf8da714473624b221aca5a6feed2154a885 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 5 May 2013 19:56:45 +0000 Subject: Re-worked generator subobject ownership, added a cache for the CompositionGen git-svn-id: http://mc-server.googlecode.com/svn/trunk@1447 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Generating/CompoGen.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source/Generating/CompoGen.h') diff --git a/source/Generating/CompoGen.h b/source/Generating/CompoGen.h index 57233e2fd..8391de66e 100644 --- a/source/Generating/CompoGen.h +++ b/source/Generating/CompoGen.h @@ -6,6 +6,8 @@ - cCompoGenDebugBiomes - cCompoGenClassic - cCompoGenBiomal + - cCompoGenNether + - cCompoGenCache */ @@ -139,3 +141,41 @@ protected: + +/// Caches most-recently-used chunk composition of another composition generator. Caches only the types and metas +class cCompoGenCache : + public cTerrainCompositionGen +{ +public: + cCompoGenCache(cTerrainCompositionGen * a_Underlying, int a_CacheSize); // Doesn't take ownership of a_Underlying + ~cCompoGenCache(); + + // cTerrainCompositionGen override: + virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override; + +protected: + + cTerrainCompositionGen * m_Underlying; + + struct sCacheData + { + int m_ChunkX; + int m_ChunkZ; + cChunkDef::BlockTypes m_BlockTypes; + cChunkDesc::BlockNibbleBytes m_BlockMetas; // The metas are uncompressed, 1 meta per byte + } ; + + // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data + int m_CacheSize; + int * m_CacheOrder; // MRU-ized order, indices into m_CacheData array + sCacheData * m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used + + // Cache statistics + int m_NumHits; + int m_NumMisses; + int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) +} ; + + + + -- cgit v1.2.3