void PlaceTree(ProgressBar bar) { bar.Reset(); bar.SetText("Spawn Tree and cactus"); bar.SetMaxValue(_vectree.Count); foreach (Vector2 vec in _vectree) { if (ReferenceEquals(MapBiomes[(int)vec.X], ArrayResource.Desrt)) { var height = Rand.Next(2, 5); for (var i = 0; i < height; i++) { SetTexture((int)vec.X, (int)vec.Y - i, 28); } SetTexture((int)vec.X, (int)vec.Y - height, 28, 1); } else { AddTree((int)vec.X, (int)vec.Y); } bar.Add(1); } if (Program.Game.CurrentDimension != 1) { StructuresList.Add(new Home(0, MapHeight[5], true)); } }
protected override void GenerationTerrain(ProgressBar progressBar) { progressBar.Reset(); progressBar.SetText("Generation Terrain"); for (var i = 0; i < SizeGeneratior.WorldWidth; i++) { if (MapHeight[i] > 0) { for (var j = 0; j < MapHeight[i]; j++) { SetTexture(i, j + (SizeGeneratior.WorldHeight - SizeGeneratior.WorldHeight / 2) + 400, 10); } } else { SetTexture(i, SizeGeneratior.WorldHeight - 5, 10); } for (var j = MapHeight[i] + (SizeGeneratior.WorldHeight - SizeGeneratior.WorldHeight / 2) + 400; j < SizeGeneratior.WorldHeight; j++) { SetTexture(i, j, 11); } UpdateMaxY(i); progressBar.Add(1); } }
/// <param name="writer">todo: describe writer parameter on Save</param> /// <param name="bar">todo: describe bar parameter on Save</param> /// <exception cref="IOException">An I/O error occurs. </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="writer" /> is null. </exception> /// <exception cref="ObjectDisposedException">The stream is closed. </exception> public virtual void Save(BinaryWriter writer, ProgressBar bar) { bar.Reset(); bar.SetText("SAVE world"); writer.Write(@"World"); for (var i = 0; i < SizeGeneratior.WorldWidth; i++) { MapBiomes[i].Save(writer); writer.Write(MapHeight[i]); for (var j = 0; j < SizeGeneratior.WorldHeight; j++) { MapTile[i, j].Save(writer); } bar.Add(1); } /* bar.setText("SAVE NPC"); * writer.Write(Zombies.Count); * foreach (Zombie zombie in Zombies) * { * zombie.save(writer); * } * writer.Write(civil.Count); * foreach (Civilian civ in civil) * { * civ.save(writer); * }*/ }
/// <param name="reader">todo: describe reader parameter on Load</param> /// <param name="bar">todo: describe bar parameter on Load</param> /// <param name="version">todo: describe version parameter on Load</param> /// <exception cref="EndOfStreamException">The end of the stream is reached. </exception> /// <exception cref="IOException">An I/O error occurs. </exception> /// <exception cref="ObjectDisposedException">The stream is closed. </exception> public virtual void Load(BinaryReader reader, ProgressBar bar, int version) { bar.Reset(); bar.SetText("Load World"); reader.ReadString(); for (var i = 0; i < SizeGeneratior.WorldWidth; i++) { MapBiomes[i] = new Biome(); MapBiomes[i].Read(reader); MapHeight[i] = reader.ReadInt32(); for (var j = 0; j < SizeGeneratior.WorldHeight; j++) { MapTile[i, j].Read(reader, version); } bar.Add(1); } /* Zombies.Clear(); * int countBlocks = reader.ReadInt32(); * for (int i = 0; i < countBlocks; i++) * { * Zombie zombie = new Zombie(); * zombie.load(reader); * Zombies.Add(zombie); * } * civil.Clear(); * countBlocks = reader.ReadInt32(); * for (int i = 0; i < countBlocks; i++) * { * Civilian civ = new Civilian(Vector2.Zero); * civ.load(reader); * civil.Add(civ); * }*/ }
void PlaceStructures(ProgressBar bar) { bar.Reset(); bar.SetText("Place Structure"); bar.SetMaxValue(StructuresList.Count); foreach (BaseStruct structure in StructuresList) { structure.Spawn(this); bar.Add(1); } }
void GeneratorStructurePosition(ProgressBar bar) { for (var i = 0; i < SizeGeneratior.WorldWidth; i++) { GeneratorHomeAndFactory(bar, i); GeneratorTree(i); GeneratorCaves(i); bar.Add(1); } }
protected override void GenerationTerrain(ProgressBar bar) { bar.Reset(); bar.SetText("Generation Terrain"); for (var i = 0; i < SizeGeneratior.WorldWidth; i++) { for (var j = MapHeight[i]; j < SizeGeneratior.WorldHeight; j++) { if (j > MapHeight[i] + 6) { GeneratorOre(i, j); } } bar.Add(1); } for (var i = 0; i < _biomesIDs.Count - 1; i++) { var biomeCurrentX = _biomesIDs[i].X; var biomeNextX = _biomesIDs[i + 1].X; var wIdth = biomeNextX - biomeCurrentX; var idBiome = _biomesIDs[i].Y; switch (idBiome) { case 0: ArrayResource.Grass.Place(biomeCurrentX, this, wIdth, MapHeight); break; case 1: ArrayResource.Hills.Place(biomeCurrentX, this, wIdth, MapHeight); break; case 2: ArrayResource.Snow.Place(biomeCurrentX, this, wIdth, MapHeight); break; case 3: ArrayResource.Desrt.Place(biomeCurrentX, this, wIdth, MapHeight); break; } } _biomesIDs.Clear(); }
public void Smooth(ProgressBar bar) { bar.Reset(); bar.SetText("Smooth Map"); for (var i = 0; i + 2 < SizeGeneratior.WorldWidth; i++) { for (var j = i + 5; j > i; j--) { if (j + 1 >= SizeGeneratior.WorldWidth) { continue; } if (MapHeight[i] == MapHeight[j + 1]) { MapHeight[j] = MapHeight[i]; } } bar.Add(1); } }
protected override void GeneratorHeight(ProgressBar bar) { MapHeight[0] = Rand.Next(MapBiomes[0].MinHeight, MapBiomes[0].MaxHeight);//=50 Rand = new Random((int)DateTime.Now.Ticks); bool[] min = new bool[2]; bar.Reset(); bar.SetText("Generation HeightMap"); for (var i = 1; i < SizeGeneratior.WorldWidth; i++) { min[1] = min[0]; min[0] = false; var temp = Rand.Next(0, 3); MapHeight[i] = MapHeight[i - 1]; if (temp == 1 && MapHeight[i] > 0) { if (MapHeight[i] > MapBiomes[i].MinHeight) { MapHeight[i]--; } min[0] = true; } else if (temp == 2 && MapHeight[i] < SizeGeneratior.RockLayer - 2 || MapHeight[i] <= 2) { if (MapHeight[i] < MapBiomes[i].MaxHeight) { MapHeight[i]++; } } bar.Add(1); } if (Program.Game.CurrentDimension != 1) { Smooth(bar); } }
public WeaponInfoUI() { // Properties for this class this.Alignment = ControlAlignment.Left; this.Size = new Vector2(180, 100); // Init other things. // Holds weapon and ammo info Container weaponAmmoContainer = new Container(); weaponAmmoContainer.Size = new Vector2(this.Size.X - 10, this.Size.Y - 10); weaponAmmoContainer.Alignment = ControlAlignment.Center; //weaponAmmoContainer.parent = this; Add(weaponAmmoContainer); // Holds weapon img and name Container weaponImgInfoContainer = new Container(); weaponImgInfoContainer.Size = new Vector2(100, 90); //weaponImgInfoContainer.Border = new BorderInfo(Sprites.guiSpritesDictionary["circle_border"]); //weaponImgInfoContainer.parent = weaponAmmoContainer; weaponAmmoContainer.Add(weaponImgInfoContainer); // Weapon image weaponImageContainer = new Container(); weaponImageContainer.Fill = null; //weaponImageContainer.Border = new BorderInfo(Sprites.guiSpritesDictionary["circle_border"]); weaponImageContainer.Size = new Vector2(64, 64); weaponImageContainer.Location = new Vector2(0, -5); weaponImageContainer.Alignment = ControlAlignment.Center; //weaponImageContainer.parent = weaponImgInfoContainer; weaponImgInfoContainer.Add(weaponImageContainer); // Weapon name weaponNameLbl = new Label(); weaponNameLbl.Location = new Vector2(0, 35); //weaponNameLbl.Text = ""; weaponNameLbl.Alignment = ControlAlignment.Center; //weaponNameLbl.parent = weaponImgInfoContainer; weaponImgInfoContainer.Add(weaponNameLbl); // Ammo container Container ammoInfoContainer = new Container(); ammoInfoContainer.Size = new Vector2(75, 90); ammoInfoContainer.Alignment = ControlAlignment.Right; //ammoInfoContainer.parent = weaponAmmoContainer; weaponAmmoContainer.Add(ammoInfoContainer); // Ammo top ammoCurrentInClipLbl = new Label(); ammoCurrentInClipLbl.Location = new Vector2(0, -20); ammoCurrentInClipLbl.Text = ""; ammoCurrentInClipLbl.Alignment = ControlAlignment.Center; //ammoCurrentInClipLbl.parent = ammoInfoContainer; ammoInfoContainer.Add(ammoCurrentInClipLbl); // Ammo divider reloadBar = new ProgressBar(new Vector2(75, 10)); reloadBar.ProgressColor = Color.Black; reloadBar.MaxValue = 100; reloadBar.CurrentValue = 0; reloadBar.IncludeText = String.Empty; reloadBar.Alignment = ControlAlignment.Center; //reloadBar.parent = ammoInfoContainer; ammoInfoContainer.Add(reloadBar); isReloadingLbl = new Label(); isReloadingLbl.Scale = .5f; isReloadingLbl.Alignment = ControlAlignment.Center; isReloadingLbl.Text = ""; //isReloadingLbl.parent = reloadBar; reloadBar.Add(isReloadingLbl); /* * Container ammoDivisorContainer = new Container(); * ammoDivisorContainer.Size = new Vector2(75, 10); * ammoDivisorContainer.Location = new Vector2(0, 0); * ammoDivisorContainer.Alignment = ControlAlignment.Center; * ammoDivisorContainer.parent = ammoInfoContainer; * ammoInfoContainer.Add(ammoDivisorContainer); */ // Ammo bottom ammoTotalLbl = new Label(); ammoTotalLbl.Location = new Vector2(0, 20); ammoTotalLbl.Text = ""; ammoTotalLbl.Alignment = ControlAlignment.Center; //ammoTotalLbl.parent = ammoInfoContainer; ammoInfoContainer.Add(ammoTotalLbl); }
protected override void GenerationBiomes(ProgressBar progressBar) { var changeBiome = 0; var currentBiome = 0; progressBar.Reset(); progressBar.SetText("Generation Biomes"); for (var i = 0; i < SizeGeneratior.WorldWidth; i++) { if (changeBiome == 0) { if (Rand.Next(0, 100) < 50) { currentBiome = 0; //-V3003 } else if (Rand.Next(0, 100) < 50) { currentBiome = 1; //-V3003 } else if (Rand.Next(0, 100) < 50) { currentBiome = 2; } else { currentBiome = 3; //-V3030 } changeBiome = Rand.Next(100, 250); _biomesIDs.Add(new Point(i, currentBiome)); } else { changeBiome--; } switch (currentBiome) { case 0: MapBiomes[i] = ArrayResource.Grass; break; case 1: MapBiomes[i] = ArrayResource.Hills; break; case 2: MapBiomes[i] = ArrayResource.Snow; break; case 3: MapBiomes[i] = ArrayResource.Desrt; break; } progressBar.Add(1); } /* bool stop = false; * * do * { * stop = false; * int count = biomesIDs.Count - 2; * for (int i = 0; i < count; i++) * { * int IdBiome = biomesIDs[i].Y; * int IdBiomeNext = biomesIDs[i + 1].Y; * if (IdBiome == IdBiomeNext) * { * biomesIDs.RemoveAt(i + 1); * stop = true; * break; * } * } * } while (stop); * stop = false; * * do * { * stop = false; * int count = biomesIDs.Count - 2; * for (int i = 0; i < count; i++) * { * int IdBiome = biomesIDs[i].Y; * int IdBiomeNextNext = biomesIDs[i + 2].Y; * if (IdBiome == IdBiomeNextNext) * { * for (int x = biomesIDs[i + 1].X; x < biomesIDs[i + 2].X; x++) * { * currentBiome = IdBiome; * if (currentBiome == 0) MapBiomes[x] = ArrayResource.grass; * if (currentBiome == 1) MapBiomes[x] = ArrayResource.Hills; * if (currentBiome == 2) MapBiomes[x] = ArrayResource.snow; * if (currentBiome == 3) MapBiomes[x] = ArrayResource.Desrt; * * } * biomesIDs.RemoveAt(i + 1); * stop = true; * break; * } * * } * } while (stop);*/ }
static void Main(string[] args) { var parsed = Parser.Default.ParseArguments <IndexingOptions, RetrievalOptions, DescriptorOptions, SearchOptions>(args).MapResult((IndexingOptions opts) => { string[] Documents = Directory.GetFiles(Path.GetFullPath(opts.ImagesDirectory), "*." + opts.ImageFormat); if (Documents.Length == 0) { Error("We do not found any images. Please check if you defined the image format correctly"); } var myProgressBar = new ProgressBar(); Console.WriteLine($"Found and Indexing {Documents.Length} Documents..."); var Dataset = new ConcurrentDictionary <string, Retrieval.DocumentInfo>(); var myWatch = new Stopwatch(); myWatch.Start(); Dataset = opts.Segm == Options.SegmentationType.SegmBased ? Retrieval.IndexingSegmBased(Documents, myProgressBar) : Retrieval.IndexingSegmFree(Documents, myProgressBar); myWatch.Stop(); double duration = myWatch.Elapsed.TotalSeconds / Documents.Length; Console.WriteLine("Done!"); Console.WriteLine($"Average Time per Document: {duration.ToString("0.00")} sec"); Console.WriteLine("Writing Database file..."); using (var file = File.CreateText(Path.GetFullPath(opts.OutputDatabaseFile))) { var serializer = new JsonSerializer(); serializer.Serialize(file, Dataset); } return(true); }, (RetrievalOptions opts) => { if (!File.Exists(opts.DatabaseFile)) { Error("The Database File does not exists!"); } string[] queries = Directory.Exists(opts.Query) ? Directory.GetFiles(opts.Query, $"*.{opts.ImageFormat.ToString()}") : new[] { opts.Query }; double duration = 0; var hKws14XMLFormat = new VCGXMLFormat.RelevanceListings { gtrels = new List <VCGXMLFormat.RelevanceListings.rel>() }; var concurrentGtRels = new ConcurrentBag <VCGXMLFormat.RelevanceListings.rel>(); Console.WriteLine("Loading Database to memory..."); ConcurrentDictionary <string, Retrieval.DocumentInfo> Dataset = null; using (var file = File.OpenText(opts.DatabaseFile)) { var serializer = new JsonSerializer(); Dataset = (ConcurrentDictionary <string, Retrieval.DocumentInfo>)serializer.Deserialize(file, typeof(ConcurrentDictionary <string, Retrieval.DocumentInfo>)); } Console.WriteLine($"Found {queries.Length} queries. Running..."); Stopwatch totalDuration = new Stopwatch(); totalDuration.Start(); var myProgressBar = new ProgressBar(); //foreach (var q in queries) Parallel.ForEach(queries, q => { var queryimg = new NewImage(q); var mywatch = new Stopwatch(); mywatch.Start(); var results = opts.Segm == Options.SegmentationType.SegmBased ? Retrieval.SearchSegmBased(queryimg, Dataset) : Retrieval.SearchSegmFree(queryimg, Dataset); mywatch.Stop(); ProgressBar.Add(ref duration, mywatch.Elapsed.TotalSeconds); //add the results to the final xml file concurrentGtRels.Add(new VCGXMLFormat.RelevanceListings.rel { queryid = Path.GetFileNameWithoutExtension(q), words = results.Select(r => new VCGXMLFormat.QueryRelevanceJudgements.Rels { documentName = r.Document, x = r.X, y = r.Y, width = r.Width, height = r.Height, similarity = r.Similarity }).ToList() }); myProgressBar.Increase(100d / queries.Length); }); totalDuration.Stop(); hKws14XMLFormat.gtrels = concurrentGtRels.ToList(); //write the xml file and output the query time Console.WriteLine("Done!"); Console.WriteLine($"Average Time per Query: {(duration / queries.Length).ToString("0.00")} sec"); Console.WriteLine($"Total Time: {totalDuration.Elapsed.TotalSeconds.ToString("0.00")}"); Console.WriteLine("Writing the output xml file..."); try { VCGXMLFormat.serializeToXML(hKws14XMLFormat, opts.OutXMLResults); } catch { Console.WriteLine("ERROR saving the xml file to the defined output name. I will try to save the result to the file: default.xml at the current directory."); VCGXMLFormat.serializeToXML(hKws14XMLFormat, "default.xml"); } return(true); }, (DescriptorOptions Options) => { string imagebase64 = Options.ImageBase64 ?? Console.ReadLine(); if (string.IsNullOrEmpty(imagebase64)) { Error("Need to supply image base64 encoding through argument or standard input stream"); } var arrayString = Retrieval.GetDescriptor(imagebase64) .Select(x => Convert.ToString(x, CultureInfo.InvariantCulture)); Console.WriteLine( string.Join("@", arrayString) ); return(true); }, (SearchOptions Options) => { float[] documentDescriptors = Options.DocumentDescriptorFloatVector ?? Options.GetFloatVectors(Console.ReadLine()); if (documentDescriptors == null) { Error("Need to supply document descriptors through argument or standard input stream"); } if (Options.QueryDescriptorFloatVector == null) { Error("Need to supply query descriptors through argument"); } Console.WriteLine( string.Join("@", Retrieval.Search( Options.QueryDescriptorFloatVector, Options.QueryWidth, Options.QueryHeight, documentDescriptors ) ) ); return(true); }, err => false); //Console.ReadKey(); Console.WriteLine(); }