I'm developing in Unity a voxel-generated terrain and I'm trying to find an extensible design pattern for voxels and more in general, world objects caching. E.g. storing in a 'ChunkCache' class only the nearest Chunks and updating it after a set amount of time

As of now, I'm using a static World class with the following members in pseudocode

static class World
   Player reference
   Enemies reference
   WorldCache reference

The WorldCache instance contains a list of objects all deriving from the same base class 'Cache'. The implementation so far calls worldCache.update() method with an enum indexing this list of 'Cache' objects

WorldCache class
   List<Cache> differentTypesOfCache;

   void update(Enum whichCache) {

The problem I'm facing with this design pattern is different types of derived Cache classes need different types of information (e.g. a ChunkCache class will judge wether a chunk needs to be removed from the cache depending on the player's distance from the center of the chunk, whereas other types of derived Caches may need differing information) and as of now the only way to gather this information is to directly query the static World class members.

Also if a certain Cache object requires information from another Cache object, it starts to look spaghetti.

Is there a completely different pattern better suited for this scenario, or a way to modify the existing one for the better?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.