Exemple #1
0
			//generating
			public void ThreadFn ()
			{	
				if (locked) return;
				
				lock (locker) while (true)
				{
					stop=false;  //in case it was restarted
					start = false; 
					clear = false;
					apply.Clear();

					//clearing debug timers to know what generators were processed
					MapMagic.instance.guiDebugProcessTimes.Clear(); 
					MapMagic.instance.guiDebugApplyTimes.Clear();

					try 
					{
						

						#region Generating Main graph first
							
							//calculating the list of changed outputs
							List<Generator> changedOutputs = new List<Generator>();
							foreach (Generator outGen in MapMagic.instance.gens.OutputGenerators(onlyEnabled:true, checkBiomes:false))
							{
								outGen.CheckClearRecursive(this);
								if (!ready.Contains(outGen)) changedOutputs.Add(outGen);
							}

							//preview (checking it twice - here and in the fn end)
							if (MapMagic.instance.previewGenerator!=null && MapMagic.instance.previewOutput!=null)
								MapMagic.instance.previewGenerator.CheckClearRecursive(this);

							//types of objects that were changed (for process)
							HashSet<System.Type> changedTypes = new HashSet<Type>();
							for (int i=0; i<changedOutputs.Count; i++) 
							{
								changedTypes.Add(changedOutputs[i].GetType());
								
								//adding all of the biome outgens to processing list
								if (changedOutputs[i] is Biome)
								{
									Biome biome = (Biome)changedOutputs[i];
									if (biome.data == null) continue;
									foreach (Generator outGen in biome.data.OutputGenerators(onlyEnabled:true, checkBiomes:false))
										changedTypes.Add(outGen.GetType());
								}
							}

							//generating
							for (int i=0; i<changedOutputs.Count; i++) 
							{
								changedOutputs[i].GenerateWithPriors(this);
								if (stop) return;
							}

						#endregion

						#region Generating Biomes

							//calculating the list of changed outputs
							changedOutputs.Clear();
							foreach (Biome biome in MapMagic.instance.gens.GeneratorsOfType<Biome>(onlyEnabled:true, checkBiomes:false))
							{
								if (biome.data==null) continue;
								if (biome.mask.linkGen==null) continue;

								Matrix biomeMask = (Matrix)biome.mask.GetObject(this);
								if (biomeMask==null || biomeMask.IsEmpty()) continue;

								foreach (Generator outGen in biome.data.OutputGenerators(onlyEnabled:true, checkBiomes:false))
								{
									outGen.CheckClearRecursive(this);
									if (!ready.Contains(outGen)) changedOutputs.Add(outGen);
								}
							}

							//adding changed types
							for (int i=0; i<changedOutputs.Count; i++) 
								changedTypes.Add(changedOutputs[i].GetType());

							//generating
							for (int i=0; i<changedOutputs.Count; i++) 
							{
								changedOutputs[i].GenerateWithPriors(this);
								if (stop) return;
							}

						#endregion

						#region Preview

							if (MapMagic.instance.previewGenerator!=null && MapMagic.instance.previewOutput!=null)
							{
								MapMagic.instance.previewGenerator.CheckClearRecursive(this);
								MapMagic.instance.previewGenerator.GenerateWithPriors(this);
								if (stop) return;

								//if (results.ContainsKey(MapMagic.instance.previewOutput)) previewObject = results[MapMagic.instance.previewOutput];  
								//else previewObject = defaultMatrix;
							}

						#endregion

						
						/*//checking and resetting ready state recursive
						foreach (Generator outGen in MapMagic.instance.gens.OutputGenerators(onlyEnabled:true, checkBiomes:true)) //for outputs (including biomes)
							outGen.CheckClearRecursive(this);
						if (MapMagic.instance.previewOutput != null) MapMagic.instance.previewGenerator.CheckClearRecursive(this); //for preview

						//types of objects that were changed (for process)
						HashSet<System.Type> changedTypes = new HashSet<Type>();
						foreach (Generator outGen in MapMagic.instance.gens.OutputGenerators(onlyEnabled:true, checkBiomes:true)) 
							if (!ready.Contains(outGen)) 
								changedTypes.Add(outGen.GetType());

						//resseting all biome output if it has changed
						foreach (Biome biome in MapMagic.instance.gens.GeneratorsOfType<Biome>(onlyEnabled:true, checkBiomes:true))
							if (!ready.Contains(biome) && biome.data!=null && biome.mask.linkGen!=null)
							{
								foreach (Generator outGen in biome.data.OutputGenerators(onlyEnabled:true, checkBiomes:false))
									changedTypes.Add(outGen.GetType());
							}

						//generating main
						foreach (Generator outGen in MapMagic.instance.gens.OutputGenerators(onlyEnabled:true, checkBiomes:true)) //generating outputs
							if (!ready.Contains(outGen)) 
								outGen.GenerateWithPriors(this);

						if (MapMagic.instance.previewOutput != null) //generating preview
						{
							MapMagic.instance.previewGenerator.GenerateWithPriors(this);
							if (!stop) 
							{
								if (results.ContainsKey(MapMagic.instance.previewOutput)) previewObject = results[MapMagic.instance.previewOutput];
								else previewObject = defaultMatrix;
							}
						}*/

						//resetting objects if height changed (to floor them)
						if (changedTypes.Contains(typeof(HeightOutput))) { changedTypes.Add(typeof(TreesOutput)); changedTypes.Add(typeof(ObjectOutput)); }

						//finalizing (processing)
						if (changedTypes.Contains(typeof(HeightOutput))) HeightOutput.Process(this); //typeof(HeightOutput).GetMethod("Process", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).Invoke(null,new object[] {this});
						if (changedTypes.Contains(typeof(SplatOutput))) SplatOutput.Process(this);
						if (changedTypes.Contains(typeof(ObjectOutput))) ObjectOutput.Process(this);
						if (changedTypes.Contains(typeof(TreesOutput))) TreesOutput.Process(this);
						if (changedTypes.Contains(typeof(GrassOutput))) GrassOutput.Process(this);
						if (changedTypes.Contains(typeof(RTPOutput))) RTPOutput.Process(this);
					}

					catch (System.Exception e) { Debug.LogError("Generate Thread Error:\n" + e); }

					//if (!stop) Thread.Sleep(2000);
					//exiting thread - only if it should not be restared
					if (!start) { queuedApply=true; break; }
				}
			}