private void Start() { Debug.Log($"Generating world using seed <{VoxelData.seed}>."); worldData = SaveSys.LoadWorld("Test world"); string jsonImport = File.ReadAllText(Application.dataPath + "/settings.cfg"); settings = JsonUtility.FromJson <Settings>(jsonImport); Random.InitState(VoxelData.seed); Shader.SetGlobalFloat("MinGlobalLightLevel", VoxelData.minLightLevel); Shader.SetGlobalFloat("MaxGlobalLightLevel", VoxelData.maxLightLevel); if (settings.enableThreading) { chunkUpdateThread = new Thread(new ThreadStart(ThreadedUpdate)); chunkUpdateThread.Start(); } // New world time begins at noon. timeHour = 12; timeMin = 00; globalLightLevel = 1f; SetGlobalLightValue(); spawnPosition = new Vector3(VoxelData.WorldCenter, VoxelData.ChunkHeight - 50f, VoxelData.WorldCenter); GenerateWorld(); playerLastChunkCoord = GetChunkCoordFromVector3(player.position); }
//Saving the current generation void SaveStatus(bool betterGenFound, int genNumber) { SaveSys.SaveGeneration(population, genNumber); if (betterGenFound) { SaveSys.SaveLastBestGen(genNumber); } }
private void Update() { // Update global light level, depending on what time it is. TimeCycle(); SetGlobalLightValue(); if (inLoadingScreen) { loadingScreenTimer -= Time.deltaTime; if (loadingScreenTimer < 0) { loadingScreenWindow.SetActive(false); inLoadingScreen = false; } } playerChunkCoord = GetChunkCoordFromVector3(player.position); // Updating the chunks when the player moves to new chunk. if (!playerChunkCoord.Equals(playerLastChunkCoord)) { CheckViewDistance(); } if (chunksToCreate.Count > 0) { CreateChunk(); } if (chunksToDraw.Count > 0) { chunksToDraw.Dequeue().CreateMesh(); } if (!settings.enableThreading) { if (!applyingModifiations) { ApplyModifications(); } if (chunksToUpdate.Count > 0) { UpdateChunks(); } } if (Input.GetKeyDown(KeyCode.F3)) { debugScreen.SetActive(!debugScreen.activeSelf); } if (Input.GetKeyDown(KeyCode.F1)) { SaveSys.SaveWorld(worldData); } }
// Start is called before the first frame update void Start() { for (int i = 0; i < 303; i++) { Generation gen = SaveSys.LoadGeneration(i); float aux = 0; for (int j = 0; j < gen.population.Length; j++) { aux += gen.population[j].score; } aux = aux / gen.population.Length; SaveSys.SaveToDataFrame(gen.generation, aux); } }
private void Start() { SwitchStatement(); foreach (string s in PlayerClasses) { max++; } Player_data data = SaveSys.LoadPlayerWithSave(saveSlot); if (data == null) { saveSlot = "saveSlot1"; } lvl = 1; }
//Initializing the population public void Setup() { int lastBestGen = SaveSys.CheckLastBestGen();//Check to see if there already is a generation if (!resetExperiment && lastBestGen >= 0) { Debug.Log("Loading previous generation..."); //FIXME: Sempre carregar a ultima geracao, porem carregar o numero da ultima melhor geracao Generation gen = SaveSys.LoadGeneration(lastBestGen); Individual[] aux = gen.population; popsize = aux.Length; population = new Individual[popsize]; for (int i = 0; i < population.Length; i++) { population[i] = new Individual(aux[i].angles, aux[i].score); } currentGeneration = lastBestGen; bestGeneration = lastBestGen; bestOfBest = GetBestIndividual(aux); } else { Debug.Log("So it begins anew..."); population = new Individual[popsize]; for (int i = 0; i < population.Length; i++) { float[] auxAngles = new float[shotQuantity]; for (int j = 0; j < auxAngles.Length; j++) { auxAngles[j] = UnityEngine.Random.Range(-89f, 89f); } population[i] = new Individual(auxAngles); } currentGeneration = 0; bestGeneration = 0; bestOfBest = new Individual(shotQuantity); } predationCounter = 0; mutationChance = initital_mutationChance; currentIndividualIndex = 0; currentIndividual = population[currentIndividualIndex]; individualReady = true; undergoingDraw = false; }
/// <summary> /// Saves all chunks. /// </summary> /// <param name="world"></param> public static void SaveChunks(WorldData world) { // Duplicating modified chunks list and using the new one, to prevent changes while game is saving. List <ChunkData> chunks = new List <ChunkData>(world.modifiedChunks); world.modifiedChunks.Clear(); int count = 0; foreach (ChunkData chunk in chunks) { SaveSys.SaveChunk(chunk, world.worldName); count++; } Debug.Log($"{count} chunks have been saved."); }
public void LoadPlayer() { Player_data data1 = SaveSys.LoadPlayerWithSave("saveSlot1"); lvl = data1.lvl + 1; if (data1 == null) { LoadMenu1.SetActive(false); } if (data1 != null) { createMenu1.SetActive(false); Nametext.GetComponent <TextMeshProUGUI>().text = data1.Name; ClasAndlvl.GetComponent <TextMeshProUGUI>().text = data1.classesString + " LVL. " + lvl; } }
/// <summary> /// Loads the chunk in memory, if it's not loaded already. /// </summary> /// <param name="coord"></param> public void LoadChunk(Vector2Int coord) { if (chunks.ContainsKey(coord)) { return; } ChunkData chunk = SaveSys.LoadChunk(worldName, coord); if (chunk != null) { chunks.Add(coord, chunk); return; } chunks.Add(coord, new ChunkData(coord)); chunks[coord].Populate(); }
//Evaluate fitness and choose next generation public void Draw() { this.undergoingDraw = true; Individual bestOfGen = new Individual(shotQuantity); //Sorting the array.... Array.Sort(population, delegate(Individual x, Individual y){ return(x.score.CompareTo(y.score)); }); bestOfGen = GetBestIndividual(population);//REDUNDANT bool isCurrentGenBetter = false; if (bestOfBest.score < bestOfGen.score) { predationCounter = 0; SaveSys.SaveToDataFrame(currentGeneration, bestOfGen.score, mutationChance); isCurrentGenBetter = true; mutationChance = initital_mutationChance; bestOfBest = bestOfGen; } else { predationCounter++; SaveSys.SaveToDataFrame(currentGeneration, bestOfBest.score, mutationChance); Debug.Log("Last Generation was better"); mutationChance += mutationIncreaseRate; //keep multiplying by 2, until it finds a better gen } SaveStatus(isCurrentGenBetter, currentGeneration);//Saving the result of this iteration NextGeneration(bestOfBest); this.undergoingDraw = false; }
public void LoadPlayer() { unit.GetComponent <stats>().load_is_true = true; if (File.Exists(path)) { Player_data_inGame dataInGame = SaveSys.LoadPlayerWithSaveInGame("saveSlot1"); xp = dataInGame.xp; Intellect = dataInGame.Intellect; Agility = dataInGame.Agility; Strength = dataInGame.Strength; Stamina = dataInGame.Stamina; PlayerClass = dataInGame.classesString; Name = dataInGame.Name; saveSlot = dataInGame.saveSlot; lvl = dataInGame.lvl; character = dataInGame.character; position.x = dataInGame.position[0]; position.y = dataInGame.position[1]; position.z = dataInGame.position[2]; } else { Player_data data = SaveSys.LoadPlayerWithSave("saveSlot1"); character = data.character; Intellect = data.Intellect; Agility = data.Agility; Strength = data.Strength; Stamina = data.Stamina; PlayerClass = data.classesString; playerClassInt = data.classesInt; Name = data.Name; saveSlot = data.saveSlot; lvl = data.lvl; } Debug.Log(Application.persistentDataPath); }
public void SavePlayer() { SaveSys.SavePlayerInGame(this, "saveSlot1"); }