void Start() { BanditCampBuilder b = new BanditCampBuilder(new BanditCamp(new Vec2i(0,0), new Vec2i(4,4))); b.Generate(new GenerationRandom(0)); List<ChunkData> chunks = b.ToChunkData(); Chunks = new ChunkData[20, 20]; foreach (ChunkData c in chunks) { Chunks[c.X, c.Z] = c; } foreach (ChunkData cd in Chunks) { if (cd == null) continue; PreLoadedChunk plc = GeneratePreLoadedChunk(cd); CreateChunk(plc); } Player player = new Player(); PlayerManager.Instance.SetPlayer(player); }
private void GenerateAllChunkStructures() { //TODO - move to thread //Iterate all structures foreach (ChunkStructure cStruct in ChunkStructures) { if (cStruct is BanditCamp) { BanditCampBuilder bcb = new BanditCampBuilder(cStruct, null); //bcb.Generate(GenRan); Builders.Add(bcb); // } } }
private void InternalThreadStructureGeneration(ChunkStructure[] toGen) { //Ensure we have some structures to generate if (toGen[0] == null) { return; } //Create list to hold generated chunks. Create random (thread safe) List <ChunkData> generatedChunks = new List <ChunkData>(40); GenerationRandom genRan = new GenerationRandom(toGen[0].Position.x * 13 + toGen[0].Position.z * 3064); //iterate all structures to generate, ignore if null foreach (ChunkStructure str in toGen) { if (str == null) { continue; } //If a bandit camp, create a bandit camp builder then generate structure. if (str is BanditCamp) { BanditCampBuilder bcb = new BanditCampBuilder(str as BanditCamp); generatedChunks.AddRange(bcb.Generate(genRan)); str.SetLootChest(bcb.FinalLootChest); } } //Lock for thread safe adding lock (GeneratedChunksAddLock) { //iterate generated threads, add to dictionary foreach (ChunkData cd in generatedChunks) { GeneratedChunks.Add(new Vec2i(cd.X, cd.Z), cd); } } generatedChunks = null; genRan = null; }