- Home /
Best way to store large list
Hi everyone, I'm working on a endless map generator and I don't know the best way to store large amount of data.
First, my (simplified) world is chunked (because it's endless) and handled in 3 levels:
World: Largest chunks (10000x10000)
Region: Sub-world chunks (1000x1000) (So every World Chunk contain an array of [10x10] region Chunks)
Details: Sub-region chunks (100x100) (Same here, Region Chunk contain an array of [10x10] details)
public enum ChunkLevel:int {World=1, Region=2, Detail=3}
I load only chunks who need to be displayed on screen, but I must load every parent-chunks to get high-levels informations (in-game restriction).
I'm a web-developer and I don't really know what's the best choices to store all ChunkData classes into my Generator. I came with 2 ideas:
A Dictionary of Dictionary
My first way was to store every same-level chunks on a Dictionary<Coord, ChunkData>
, and list all level on an other Dictionary: Dictionary<ChunkLevel, Dictionary<Coord, ChunkData>>
That way, I can easily get /set the ChunkData object but i'm concern about the size of the Detail Dictionary. If the game go long, it will be hudge ! And a lots of request'll search on it..
// Simple Chunk Data Class
public class ChunkData {
public Coord coord;
public ChunkData(Coord _coord, ChunkLevel _chunkLevel) {
this.coord = _coord;
/* ... */
}
}
// MapGenerator
public class mapGenerator: MonoBehaviour {
// Chunks
Dictionary<ChunkLevel, Dictionary<Coord, ChunkData>> chunks = new Dictionary<ChunkLevel, Dictionary<Coord, ChunkData>>();
}
// Example : mapGenerator.chunks[ChunkLevel.Detail][coord]
Dictionary of World containing Array of child
Another way to do it is just to store into my Generator a Dictionary<Coord, ChunkData>
for World (higher parent), and add an array on it with (in this case) 100 chunks for child.
It will be harder to get data (starting everytime on world and going through children to find the good ChunkData) but every avoid large Dictionary.
// New ChunkData
public class ChunkData {
public Coord coord;
public ChunkData[] children;
public ChunkData(Coord _coord, ChunkLevel _chunkLevel) {
this.coord = _coord;
this.children = new ChunkData[100]; // This will create a big array even if I never call this.children[x] = new ChunkData() ???
}
}
// MapGenerator
public class mapGenerator: MonoBehaviour {
// World Chunks only
Dictionary<Coord, ChunkData>> worldChunks = new Dictionary<Coord, ChunkData>();
}
// Example : mapGenerator.worldChunks [coord][regionInWorldCoord][detailInregionCoord]
Thank everyone for reading/taking time.
Your answer
Follow this Question
Related Questions
Tilemap Per Chunk? 0 Answers
Data Storage Access 0 Answers
Fastest way to store huge amounts of data? 2 Answers
Storing and Accessing Abilities 2 Answers
chest items get added to inventory 2 Answers