public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { while (true) { IAstronaut currentAstronauth = astronauts.FirstOrDefault(a => a.CanBreath); if (currentAstronauth == null) { break; } while (planet.Items.Count != 0) { var currentItem = planet.Items.FirstOrDefault(); currentAstronauth.Breath(); currentAstronauth.Bag.AddItem(currentItem); planet.RemoveItem(currentItem); if (!currentAstronauth.CanBreath) { break; } } if (planet.Items.Count == 0) { break; } } }
public override void Populate(IDefinitionManager definitionManager, IPlanet planet, IChunkColumn column00, IChunkColumn column10, IChunkColumn column01, IChunkColumn column11) { // Tree Definitions initialisieren if (treeDefinitions == null) { treeDefinitions = definitionManager.GetDefinitions<ITreeDefinition>().OrderBy(d => d.Order).ToArray(); foreach (var treeDefinition in treeDefinitions) treeDefinition.Init(definitionManager); } int salt = (column00.Index.X & 0xffff) + ((column00.Index.Y & 0xffff) << 16); Random random = new Random(planet.Seed + salt); Index3 sample = new Index3(column00.Index.X * Chunk.CHUNKSIZE_X, column00.Index.Y * Chunk.CHUNKSIZE_Y, column00.Heights[0, 0]); foreach (var treeDefinition in treeDefinitions) { int density = treeDefinition.GetDensity(planet, sample); if (density <= 0) continue; for (int i = 0; i < density; i++) { int x = random.Next(Chunk.CHUNKSIZE_X / 2, Chunk.CHUNKSIZE_X * 3 / 2); int y = random.Next(Chunk.CHUNKSIZE_Y / 2, Chunk.CHUNKSIZE_Y * 3 / 2); int z = LocalBuilder.GetSurfaceHeight(column00, column10, column01, column11, x, y); LocalBuilder builder = new LocalBuilder(x, y, z + 1, column00, column10, column01, column11); treeDefinition.PlantTree(definitionManager, planet, new Index3(x, y, z), builder, random.Next(int.MaxValue)); } } }
/// <summary> /// Initilises an instance of the <see cref="Simulation"/> class. /// </summary> /// <param name="planet">The planet in this simulation</param> /// <param name="rovers">The Rovers in this simulation</param> public Simulation(IPlanet planet, IEnumerable <IRover> rovers) { this.Planet = planet; this.Rovers = rovers; this.Planet.BuildPlanet(this.Rovers); }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { while (true) { if (planet.Items.Count == 0) { break; } IAstronaut astronaut = astronauts.First(a => a.CanBreath); astronaut.Breath(); astronaut.Bag.Items.Add(planet.Items.First()); planet.Items.Remove(planet.Items.First()); if (astronaut.CanBreath == false) { astronauts.Remove(astronaut); } if (astronauts.Count == 0) { break; } } }
public string ExplorePlanet(string planetName) { List <IAstronaut> astronauts = this.astronautRepository.Models .Where(a => a.Oxygen >= 60) .ToList(); IPlanet planet = this.planetRepository.FindByName(planetName); IMission mission = new Mission(); if (planetName == "Jupiter") { ; } if (astronauts.Count == 0) { throw new InvalidOperationException(ExceptionMessages.InvalidAstronautCount); } mission.Explore(planet, astronauts); this.exploredPlanets++; return(string.Format(OutputMessages.PlanetExplored, planetName, astronauts.Count(a => !a.CanBreath))); }
public static void ExploreArea(IPlanet mars, IRover rover) { Console.WriteLine(string.Format("Initial rover location- X:{0}, Y:{1}, Direction:{2}", rover.XPosition, rover.YPosition, rover.CurrentDirection.ToString())); foreach (char command in rover.Instruction) { bool resultMove = true; Console.WriteLine("Processing : " + command); if (command == (char)Common.TurnDirection.L) { rover.TurnRight(); } else if (command == (char)Common.TurnDirection.R) { rover.TurnLeft(); } else if (command == Common.ForwardCommand) { resultMove = mars.MoveRover(rover); } else { Console.WriteLine("Invalid Command: " + command); } // For each robot position/ instruction in the input, the output should indicate the final grid position and orientation of the robot. // If a robot falls off the edge of the grid the word "LOST" should be printed after the position and orientation. Console.WriteLine(string.Format("{0}, {1}, {2} {3}", rover.XPosition, rover.YPosition, rover.CurrentDirection.ToString(), resultMove? "": "LOST")); } Console.WriteLine(string.Format("Final rover location- X:{0}, Y:{1}, Direction:{2}", rover.XPosition, rover.YPosition, rover.CurrentDirection.ToString())); }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { while (true) { IAstronaut astronaut = astronauts.FirstOrDefault(a => a.CanBreath); if (astronaut == null) { break; } while (planet.Items.Count != 0) { string item = planet.Items.FirstOrDefault(); astronaut.Breath(); astronaut.Bag.AddItem(item); planet.RemoveItem(item); if (astronaut.CanBreath == false) { break; } } if (planet.Items.Count == 0) { break; } } }
/* an encircled planet is one that is surrounded by enemy planets */ /* for now, its only for single planets that have more than 2 connections */ public bool IsPlanetEncircled(IPlanet planet) { if (planet == null) { throw new ArgumentNullException("planet"); } var links = GetLinks(planet); if (links == null || links.Count < 2) { return(false); } foreach (var link in links) { string planet1fac = GetPlanet(link.PlanetIDs[0]).FactionName; string planet2fac = GetPlanet(link.PlanetIDs[1]).FactionName; // if factions differ and neither faction is neutral if ((planet1fac == planet2fac) || (planet1fac == null) || (planet2fac == null)) { return(false); } } return(true); }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { foreach (var astronaut in astronauts) { if (astronaut.CanBreath) { List <string> itemsOnPlanet = (List <string>)planet.Items; for (int i = 0; i < itemsOnPlanet.Count; i++) { var currentItem = itemsOnPlanet[i]; astronaut.Breath(); astronaut.Bag.Items.Add(currentItem); itemsOnPlanet.Remove(currentItem); i--; if (!astronaut.CanBreath) { DeadAstronauts++; break; } } } } }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { while (true) { IAstronaut astronaut = astronauts.FirstOrDefault(a => a.CanBreath == true); if (astronaut == null) { break; } string item = planet.Items.FirstOrDefault(); if (item == null) { break; } astronaut.Breath(); if (astronaut.CanBreath == false) { continue; } astronaut.Bag.Items.Add(item); planet.Items.Remove(item); } }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { while (true) { IAstronaut currentAstronaut = astronauts.FirstOrDefault(x => x.CanBreath); if (currentAstronaut == null) { break; } while (planet.Items.Count > 0) { string item = planet.Items.FirstOrDefault(); currentAstronaut.Breath(); currentAstronaut.Bag.Items.Add(item); planet.Items.Remove(item); if (!currentAstronaut.CanBreath) { break; } } if (planet.Items.Count == 0) { break; } } }
private static List <IRover> ExtractRoverDataFromInput(string inputFile, IPlanet mars) { try { List <IRover> roverDataCollection = new List <IRover>(); string[] lines = File.ReadAllLines(inputFile); RoverController.SetMapGrid(mars, lines[0]); for (int counter = 1; counter < lines.Length - 1; counter = counter + 2) { Rover rover = RoverController.GetRover(lines[counter], lines[counter + 1]); if (rover != null) { roverDataCollection.Add(rover); } else { Console.WriteLine(string.Format("A rover could not be created. Invalid Raw material: {0} {1}", lines[counter], lines[counter + 1])); } } return(roverDataCollection); } catch (Exception ex) { Console.WriteLine("Error while processing the input. Please make sure the input file is in correct format." + ex.Message); return(null); } }
public ITransmission Build(HipsterEngine.Core.HipsterEngine engine, IPlanet planet, float x, float y, float angle, float size) { _engine = engine; Planet = planet; Radius = size; RigidBody = (RigidBodyCircle)_engine.Physics.FactoryBody .CreateRigidCircle() .CreateCircleDef(0.2f, 0.8f, 50, Radius) .CreateBodyDef(x, y, angle, true, false) .Build(1f); Paint = new SKPaint { Style = SKPaintStyle.Stroke, IsAntialias = true, PathEffect = SKPathEffect.CreateDash(new[] { 10.0f, 10.0f }, 10), StrokeWidth = 5, Color = new SKColor(100, 70, 30) }; Paint1 = new SKPaint { Style = SKPaintStyle.Fill, IsAntialias = true, Color = new SKColor(150, 100, 50) }; return(this); }
public IChunk[] GenerateChunk(IEnumerable<IBlockDefinition> blockDefinitions, IPlanet planet, Index2 index) { IBlockDefinition sandDefinition = blockDefinitions.FirstOrDefault(d => typeof(SandBlockDefinition) == d.GetType()); ushort sandIndex = (ushort)(Array.IndexOf(blockDefinitions.ToArray(), sandDefinition) + 1); IChunk[] result = new IChunk[planet.Size.Z]; for (int layer = 0; layer < planet.Size.Z; layer++) result[layer] = new Chunk(new Index3(index.X, index.Y, layer), planet.Id); int part = (planet.Size.Z * Chunk.CHUNKSIZE_Z) / 4; for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++) { float heightY = (float)Math.Sin((float)(y * Math.PI) / 15f); for (int x = 0; x < Chunk.CHUNKSIZE_X; x++) { float heightX = (float)Math.Sin((float)(x * Math.PI) / 18f); float height = ((heightX + heightY + 2) / 4) * (2 * part); for (int z = 0; z < planet.Size.Z * Chunk.CHUNKSIZE_Z; z++) { if (z < (int)(height + part)) { int block = z % (Chunk.CHUNKSIZE_Z); int layer = (int)(z / Chunk.CHUNKSIZE_Z); result[layer].SetBlock(x, y, block, sandIndex); } } } } return result; }
/// <summary> /// Lädt eine <see cref="IChunkColumn"/>. /// </summary> /// <param name="universeGuid">GUID des Universums.</param> /// <param name="planet">Index des Planeten.</param> /// <param name="columnIndex">Zu serialisierende ChunkColumn.</param> /// <returns>Die neu geladene ChunkColumn.</returns> public Awaiter Load(out IChunkColumn column, Guid universeGuid, IPlanet planet, Index2 columnIndex) { string file = Path.Combine(GetRoot(), universeGuid.ToString(), planet.Id.ToString(), string.Format(ColumnFilename, columnIndex.X, columnIndex.Y)); column = new ChunkColumn(); if (!File.Exists(file)) { return(null); } try { using (Stream stream = File.Open(file, FileMode.Open, FileAccess.Read)) { using (GZipStream zip = new GZipStream(stream, CompressionMode.Decompress)) { var awaiter = new Awaiter(); awaiter.Serializable = column; awaiter.SetResult(planet.Generator.GenerateColumn(zip, definitionManager, planet.Id, columnIndex)); return(awaiter); } } } catch (IOException) { try { File.Delete(file); } catch (IOException) { } return(null); } }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { foreach (var astronaut in astronauts.Where(x => x.CanBreath)) { while (true) { if (!astronaut.CanBreath) { break; } if (planet.Items.Count == 0) { break; } string item = planet.Items.First(); astronaut.Breath(); astronaut.Bag.Items.Add(item); planet.Items.Remove(item); } if (planet.Items.Count == 0) { break; } } }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { List <string> items = planet.Items.ToList(); foreach (var astronaut in astronauts) { if (!astronaut.CanBreath) { continue; } else { while (astronaut.Oxygen > 0) { if (items.Count != 0) { astronaut.Bag.Items.Add(items[0]); items.RemoveAt(0); } else { break; } astronaut.Breath(); } } if (items.Count == 0) { break; } } }
public string ExplorePlanet(string planetName) { List <IAstronaut> suitableAstronauts = this.astronautRepository .Models .Where(a => a.Oxygen > 60) .ToList(); if (suitableAstronauts.Count == 0) { throw new InvalidOperationException(ExceptionMessages.InvalidAstronautCount); } IPlanet planet = this.planetRepository.FindByName(planetName); this.mission.Explore(planet, suitableAstronauts); this.exploredPlanetsCount++; int deadAstronauts = 0; foreach (var astronaut in suitableAstronauts) { if (astronaut.CanBreath == false) { deadAstronauts++; } } return(string.Format(OutputMessages.PlanetExplored, planet.Name, deadAstronauts)); }
/// <summary> /// Setzt den Zentrums-Chunk für diesen lokalen Cache. /// </summary> /// <param name="planet">Der Planet, auf dem sich der Chunk befindet</param> /// <param name="index">Die Koordinaten an der sich der Chunk befindet</param> /// <param name="successCallback">Routine die Aufgerufen werden soll, falls das setzen erfolgreich war oder nicht</param> public bool SetCenter(IPlanet planet, Index2 index, Action <bool> successCallback = null) { if (IsPassive && !globalCache.IsChunkLoaded(planet.Id, index)) { return(false); } // Planet resetten falls notwendig if (Planet != planet) { InitializePlanet(planet); } CenterPosition = index; if (_loadingTask != null && !_loadingTask.IsCompleted) { _cancellationToken.Cancel(); _cancellationToken = new CancellationTokenSource(); _loadingTask = _loadingTask.ContinueWith(_ => InternalSetCenter(_cancellationToken.Token, planet, index, successCallback)); } else { _cancellationToken = new CancellationTokenSource(); _loadingTask = Task.Factory.StartNew(() => InternalSetCenter(_cancellationToken.Token, planet, index, successCallback)); } return(true); }
public SuperBiomeBase(IPlanet planet, float valueRangeOffset, float valueRange) { this.Planet = planet; this.SubBiomes = new List <IBiome>(); this.ValueRangeOffset = valueRangeOffset; this.ValueRange = valueRange; }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { if (astronauts.Count > 0) { foreach (var astronaut in astronauts) { List <string> items = planet.Items.ToList(); for (int itemNum = 0; itemNum < planet.Items.Count; itemNum++) { if (astronaut.Oxygen > 0) { astronaut.Bag.Items.Add(items[itemNum]); items.Remove(items[itemNum]); astronaut.Breath(); } if (astronaut.Oxygen <= 0) { break; } } } } else { throw new ArgumentException(ExceptionMessages.InvalidAstronautCount); } }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { while (true) { IAstronaut astronautCurrent = astronauts.FirstOrDefault(a => a.CanBreath); if (astronautCurrent == null) { break; } string item = planet.Items.FirstOrDefault(); if (item == null) { break; } astronautCurrent.Bag.Items.Add(item); astronautCurrent.Breath(); planet.Items.Remove(item); //if (!astronautCurrent.CanBreath) //{ // break; //} } }
public string ExplorePlanet(string planetName) { List <IAstronaut> suitables = this.astronautRepository.Models .Where(x => x.Oxygen > 60) .ToList(); if (suitables.Count == 0) { throw new InvalidOperationException(ExceptionMessages.InvalidAstronautCount); } IPlanet planet = this.planetRepository .FindByName(planetName); this.mission.Explore(planet, suitables); this.exploredPlanetsCount++; int deadAstronauts = suitables .Where(x => x.Oxygen == 0) .Count(); return(string.Format(OutputMessages.PlanetExplored, planetName, deadAstronauts)); }
/// <summary> /// Lädt eine <see cref="IChunkColumn"/>. /// </summary> /// <param name="universeGuid">GUID des Universums.</param> /// <param name="planet">Index des Planeten.</param> /// <param name="columnIndex">Zu serialisierende ChunkColumn.</param> /// <returns>Die neu geladene ChunkColumn.</returns> public IChunkColumn LoadColumn(Guid universeGuid, IPlanet planet, Index2 columnIndex) { string file = Path.Combine(GetRoot(), universeGuid.ToString(), planet.Id.ToString(), string.Format(ColumnFilename, columnIndex.X, columnIndex.Y)); if (!File.Exists(file)) { return(null); } try { using (Stream stream = File.Open(file, FileMode.Open, FileAccess.Read)) { using (GZipStream zip = new GZipStream(stream, CompressionMode.Decompress)) { return(planet.Generator.GenerateColumn(zip, DefinitionManager.Instance, planet.Id, columnIndex)); } } } catch (IOException) { try { File.Delete(file); } catch (IOException) { } return(null); } }
public string ExplorePlanet(string planetName) { IList <IAstronaut> availableAtsra = new List <IAstronaut>(); foreach (var item in astronauts.Models) { if (item.Oxygen > 60) { availableAtsra.Add(item); } } if (availableAtsra.Count == 0) { throw new InvalidOperationException(string.Format(Utilities.Messages.ExceptionMessages.InvalidAstronautCount)); } Mission mission = new Mission(); string result; this.exploredPlanetCounnt++; IPlanet planet = planets.Models.FirstOrDefault(n => n.Name == planetName); mission.Explore(planet, (IList <IAstronaut>)availableAtsra); int countOfDeadAstro = availableAtsra.Where(a => a.CanBreath == false).Count(); result = string.Format(Utilities.Messages.OutputMessages.PlanetExplored, planet.Name, countOfDeadAstro); return(result); }
public List <IVector> GetFinalsVectors(IPlanet mars) { List <IVector> finalVectorList = new List <IVector>(); foreach (var rover in mars.RoverList) { Queue <Directive> directiveQueue = _directiveBusiness.GetDirectiveQueue(rover.DirectiveList); while (directiveQueue.Count > 0) { Directive directive = directiveQueue.Dequeue(); switch (directive) { case Directive.R: rover.Vector.Direction = _roverBusiness.TurnRight(rover.Vector.Direction); break; case Directive.L: rover.Vector.Direction = _roverBusiness.TurnLeft(rover.Vector.Direction); break; case Directive.M: rover.Vector = _roverBusiness.Move(rover.Vector); break; default: break; } } finalVectorList.Add(rover.Vector); } return(finalVectorList); }
public SuperBiomeBase(IPlanet planet, float valueRangeOffset, float valueRange) { this.Planet = planet; this.SubBiomes = new List<IBiome>(); this.ValueRangeOffset = valueRangeOffset; this.ValueRange = valueRange; }
// TODO: dependency injection static void Main(string[] args) { // The first line of input is the upper-right coordinates of the rectangular world, the lower-left coordinates are assumed to be 0, 0. Console.WriteLine("Hello to Martian Robot sequence!"); Console.WriteLine("Please, the file path with then instructions"); string filepath = Console.ReadLine(); IPlanet mars = CreatePlanet("Mars"); List <IRover> rovers = ExtractRoverDataFromInput(filepath, mars); if (rovers == null) { Console.WriteLine("Could not create any rover with provided instructions"); } foreach (IRover rover in rovers) { Console.WriteLine("----Processing Rover------"); if (!mars.AddRover(rover)) { Console.WriteLine("Could not add rover to plateau."); } else { RoverController.ExploreArea(mars, rover); } } Console.Read(); return; }
public IChunk[] GenerateChunk(IPlanet planet, Index2 index) { IChunk[] result = new IChunk[planet.Size.Z]; for (int layer = 0; layer < planet.Size.Z; layer++) result[layer] = new Chunk(new Index3(index.X, index.Y, layer), planet.Id); int part = (planet.Size.Z * Chunk.CHUNKSIZE_Z) / 4; for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++) { float heightY = (float)Math.Sin((float)(y * Math.PI) / 15f); for (int x = 0; x < Chunk.CHUNKSIZE_X; x++) { float heightX = (float)Math.Sin((float)(x * Math.PI) / 18f); float height = ((heightX + heightY + 2) / 4) * (2 * part); for (int z = 0; z < planet.Size.Z * Chunk.CHUNKSIZE_Z; z++) { if (z < (int)(height + part)) { int block = z % (Chunk.CHUNKSIZE_Z); int layer = (int)(z / Chunk.CHUNKSIZE_Z); result[layer].SetBlock(x, y, block, new SandBlock()); } } } } return result; }
/// <summary> /// Lädt eine <see cref="IChunkColumn"/>. /// </summary> /// <param name="universeGuid">GUID des Universums.</param> /// <param name="planet">Index des Planeten.</param> /// <param name="columnIndex">Zu serialisierende ChunkColumn.</param> /// <returns>Die neu geladene ChunkColumn.</returns> public IChunkColumn LoadColumn(Guid universeGuid, IPlanet planet, Index2 columnIndex) { string file = Path.Combine(GetRoot(), universeGuid.ToString(), planet.Id.ToString(), string.Format(ColumnFilename, columnIndex.X, columnIndex.Y)); if (!File.Exists(file)) return null; try { using (Stream stream = File.Open(file, FileMode.Open, FileAccess.Read)) { using (GZipStream zip = new GZipStream(stream, CompressionMode.Decompress)) { return planet.Generator.GenerateColumn(zip, DefinitionManager.Instance, planet.Id, columnIndex); } } } catch (IOException) { try { File.Delete(file); } catch (IOException) { } return null; } }
/// <summary> /// Speichert einen Planeten. /// </summary> /// <param name="universeGuid">Guid des Universums</param> /// <param name="planet">Zu speichernder Planet</param> public void SavePlanet(Guid universeGuid, IPlanet planet) { string path = Path.Combine(GetRoot(), universeGuid.ToString(), planet.Id.ToString()); Directory.CreateDirectory(path); string generatorInfo = Path.Combine(path, PlanetGeneratorInfo); using (Stream stream = File.Open(generatorInfo, FileMode.Create, FileAccess.Write)) { using (BinaryWriter bw = new BinaryWriter(stream)) { bw.Write(planet.Generator.GetType().FullName); } } string file = Path.Combine(path, PlanetFilename); using (Stream stream = File.Open(file, FileMode.Create, FileAccess.Write)) { using (GZipStream zip = new GZipStream(stream, CompressionMode.Compress)) { planet.Serialize(zip); } } }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { IAstronaut astronaut = astronauts.FirstOrDefault(a => a.CanBreath); if (planet == null) { return; } if (astronauts == null) { return; } if (planet.Items.Count == 0) { return; } while (astronauts.Any(a => a.CanBreath) && planet.Items.Count > 0) { string item = planet.Items.FirstOrDefault(); if (!astronaut.CanBreath) { astronaut = astronauts.FirstOrDefault(a => a.CanBreath); continue; } else { astronaut.Breath(); astronaut.Bag.Items.Add(item); planet.Items.Remove(item); } } }
public string ExplorePlanet(string planetName) { List <IAstronaut> astronautsForMission = new List <IAstronaut>(); IMission mission = new Mission(); IPlanet planetToExplore = planets.FindByName(planetName); foreach (var astronaut in astronauts.Models) { if (astronaut.Oxygen > 60) { astronautsForMission.Add(astronaut); } } if (!astronautsForMission.Any()) { throw new InvalidOperationException("You need at least one astronaut to explore the planet"); } int deadAstronauts = astronautsForMission.Count(x => !x.CanBreath); mission.Explore(planetToExplore, astronautsForMission); this.explorePlanetes++; return($"Planet: {planetName} was explored! Exploration finished with {deadAstronauts} dead astronauts!"); }
public void Explore(IPlanet planet, ICollection <IAstronaut> astronauts) { while (true) { var astronaut = astronauts .FirstOrDefault(x => x.CanBreath); if (astronaut == null) { break; } var item = planet .Items .FirstOrDefault(); if (item == null) { break; } astronaut.Breath(); astronaut .Bag .Items .Add(item); planet .Items .Remove(item); } }
public string ExplorePlanet(string planetName) { var suitable = this.astronauts.Models.Where(a => a.Oxygen > 60).ToList(); if (!suitable.Any()) { throw new InvalidOperationException(ExceptionMessages.InvalidAstronautCount); } int beforeCount = suitable.Count(); IPlanet planet = this.planets.FindByName(planetName); this.mission.Explore(planet, suitable); this.exploredPlanetsCount++; int after = 0; foreach (var astronaut in suitable) { if (!astronaut.CanBreath) { after++; } } return(String.Format(OutputMessages.PlanetExplored, planetName, after)); }
public ActorHost(Player player) { Player = player; localChunkCache = new Cache<Index3, IChunk>(10, loadChunk, null); planet = ResourceManager.Instance.GetPlanet(Player.Position.Planet); ActiveTool = null; }
public OceanBiomeGenerator(IPlanet planet, float minVal, float maxVal, float valueRangeOffset, float valueRange) { this.Planet = planet; this.MinValue = minVal; this.MaxValue = maxVal; this.ValueRangeOffset = valueRangeOffset; this.ValueRange = valueRange; }
public FlatlandBiome(IPlanet planet, float minValue, float maxValue, float valueRangeOffset, float valueRange) { this.BiomeNoiseGenerator = new SimplexNoiseGenerator(planet.Seed + 2) { FrequencyX = 1f / 256, FrequencyY = 1f / 256, Persistance = 0.25f, Octaves = 3, Factor = 1f }; this.Planet = planet; this.MinValue = minValue; this.MaxValue = maxValue; this.ValueRangeOffset = valueRangeOffset; this.ValueRange = valueRange; }
/// <summary> /// Default constructor /// </summary> /// <param name="planet">Planet to render</param> /// <param name="effectPath">Path to the terrain effect</param> public PlanetPackTextureTechnique( IPlanet planet, string effectPath ) { Arguments.CheckNotNull( planet, "planet" ); Arguments.CheckNotNullOrEmpty( effectPath, "effectPath" ); m_Planet = planet; m_NoiseTexture = ( ITexture2d )AssetManager.Instance.Load( "Terrain/TiledNoise.noise.jpg" ); m_Effect = new EffectAssetHandle( effectPath, true ); m_Effect.OnReload += Effect_OnReload; m_Technique = new TechniqueSelector( m_Effect, "DefaultTechnique" ); }
public ActorHost(Player player) { Player = player; planet = ResourceManager.Instance.GetPlanet(Player.Position.Planet); localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, 2, 1, true); _oldIndex = Player.Position.ChunkIndex; ActiveTool = null; ReadyState = false; }
public override void PlantTree(IDefinitionManager definitionManager, IPlanet planet, Index3 index, LocalBuilder builder, int seed) { ushort ground = builder.GetBlock(0, 0, -1); if (ground == water) return; Random rand = new Random(seed); int height = rand.Next(2, 4); for (int i = 0; i < height; i++) builder.SetBlock(0, 0, i, cactus); }
public ActorHost(Player player, IChunkLoader chunkLoader) { _chunkLoader = chunkLoader; Player = player; planet = ResourceManager.Instance.GetPlanet(Player.Position.Planet); _oldIndex = Player.Position.ChunkIndex; ActiveTool = null; State = WorldState.Loading; }
public void DeployTo(IPlanet planet, int landingPointX, int landingPointY, Movement.CardinalHeading landingCardinalHeading) { this.DeployedTo = planet; if (landingPointX < 0 || landingPointY < 0 || landingPointX > planet.Size.Width || landingPointY > planet.Size.Height) { throw new ArgumentException("Rover cannot be deployed to a point outside the bounds of a planet."); } this.Position = new Position(landingPointX, landingPointY, landingCardinalHeading); }
public SurfaceBiomeGenerator(IPlanet planet, int seaLevel) : base(planet, 0f, 1f) { this.SeaLevel = seaLevel; BiomeNoiseGenerator = new SimplexNoiseGenerator(planet.Seed) { FrequencyX = 1f / 10000, FrequencyY = 1f / 10000, Factor = 1f }; float offset = (float)seaLevel / (Planet.Size.Z * Chunk.CHUNKSIZE_Z); SubBiomes.Add(new OceanBiomeGenerator(planet, 0f, 0.3f, 0f, offset)); SubBiomes.Add(new LandBiomeGenerator(planet, 0.5f, 1f, offset, 1 - offset)); SortSubBiomes(); }
/// <summary> /// Setzt den Zentrums-Chunk für diesen lokalen Cache. /// </summary> /// <param name="planet">Der Planet, auf dem sich der Chunk befindet</param> /// <param name="index">Die Koordinaten an der sich der Chunk befindet</param> /// <param name="successCallback">Routine die Aufgerufen werden soll, falls das setzen erfolgreich war oder nicht</param> public void SetCenter(IPlanet planet, Index3 index, Action<bool> successCallback = null) { if (_loadingTask != null && !_loadingTask.IsCompleted) { _cancellationToken.Cancel(); _cancellationToken = new CancellationTokenSource(); _loadingTask = _loadingTask.ContinueWith(_ => InternalSetCenter(_cancellationToken.Token, planet, index, successCallback)); } else { _cancellationToken = new CancellationTokenSource(); _loadingTask = Task.Factory.StartNew(() => InternalSetCenter(_cancellationToken.Token, planet, index, successCallback)); } }
/// <summary> /// Setup constructor /// </summary> /// <param name="projectType">Project type that created this project</param> /// <param name="name">Project name</param> /// <param name="modelFactory">Factory used for creating environment models from templates</param> /// <param name="renderFactory">Factory used for creating environment renderers from models</param> /// <param name="template">ProjectType to use</param> /// <param name="planet">Planet to use</param> protected PlanetProject( ProjectType projectType, string name, IPlanetEnvironmentModelFactory modelFactory, IPlanetEnvironmentRendererFactory renderFactory, IPlanetModelTemplate template, IPlanet planet ) : base(projectType, name, null, null) { Arguments.CheckNotNull( template, "template" ); Arguments.CheckNotNull( modelFactory, "modelFactory" ); Arguments.CheckNotNull( renderFactory, "renderFactory" ); Arguments.CheckNotNull( planet, "planet" ); new PlanetTemplateWatcher( template, planet, modelFactory, renderFactory ); m_Planet = planet; m_PlanetTemplate = template; template.CreateModelInstance( planet.Model, modelFactory, InstanceContext ); }
/// <summary> /// Setup constructor /// </summary> public PlanetTemplateWatcher( IPlanetModelTemplate planetTemplate, IPlanet planet, IPlanetEnvironmentModelFactory modelFactory, IPlanetEnvironmentRendererFactory rendererFactory ) { Arguments.CheckNotNull( planetTemplate, "planetTemplate" ); Arguments.CheckNotNull( planet, "planet" ); m_ModelFactory = modelFactory; m_RendererFactory = rendererFactory; m_PlanetTemplate = planetTemplate; m_Planet = planet; m_PlanetTemplate.ComponentAdded += OnTemplateAdded; m_PlanetTemplate.ComponentRemoved += OnTemplateRemoved; m_Planet.Model.ComponentAdded += OnModelAdded; m_Planet.Model.ComponentRemoved += OnModelRemoved; }
public override void PlantTree(IDefinitionManager definitionManager, IPlanet planet, Index3 index, LocalBuilder builder, int seed) { ushort ground = builder.GetBlock(0, 0, -1); if (ground == water) return; Random rand = new Random(seed); int height = rand.Next(3, 5); int radius = rand.Next(3, height); builder.FillSphere(0, 0, height, radius, leave); for (int i = 0; i < height + 2; i++) { builder.SetBlock(0, 0, 0 + i, wood); } }
public LandBiomeGenerator(IPlanet planet, float minVal, float maxVal, float valueRangeOffset, float valueRange) : base(planet, valueRangeOffset, valueRange) { BiomeNoiseGenerator = new SimplexNoiseGenerator(planet.Seed + 1) { FrequencyX = 1f / 1000, FrequencyY = 1f / 1000, Persistance = 0.25f, Octaves = 5, Factor = 1f }; this.MinValue = minVal; this.MaxValue = maxVal; SubBiomes.Add(new FlatlandBiome(planet, 0f, 0.2f, 0f, 0.1f)); SubBiomes.Add(new HillsBiome(planet, 0.3f, 0.5f, 0.1f, 0.4f)); SubBiomes.Add(new HighMountainBiome(planet, 0.8f, 1f, 0.2f, 0.8f)); SortSubBiomes(); }
/// <summary> /// Sets up the terrain rendering effect /// </summary> protected virtual void SetupTerrainEffect( IEffect effect, IPlanet planet ) { IPlanetTerrainPackTextureModel textureModel = ( IPlanetTerrainPackTextureModel )planet.PlanetModel.TerrainModel; ITexture2d packTexture = textureModel.TerrainPackTexture; ITexture2d typesTexture = textureModel.TerrainTypesTexture; effect.Parameters[ "PlanetMaximumTerrainHeight" ].Set( planet.PlanetModel.TerrainModel.MaximumHeight.ToRenderUnits ); effect.Parameters[ "TerrainPackTexture" ].Set( packTexture ); effect.Parameters[ "TerrainTypeTexture" ].Set( typesTexture ); effect.Parameters[ "NoiseTexture" ].Set( m_NoiseTexture ); IPlanetAtmosphereRenderer atmosphereRenderer = planet.PlanetRenderer.AtmosphereRenderer; if ( atmosphereRenderer != null ) { atmosphereRenderer.SetupAtmosphereEffectParameters( effect, true, false ); } }
/// <summary> /// Resolve references to non-service entities. /// Subscribe to events. /// </summary> void Start() { // get registry lookups planet = registry.LookUp<IPlanet>("Planet"); gameUI = registry.LookUp<IGameUI>("GameUI"); // subscribe to events time.CountdownFinished += OnCountdownFinished; gameUI.onGameReady += OnGameReady; // turn on controls shipController.Connect(); // start the first wave gameUI.TriggerWaveStartAnimation(); }
protected override void LoadContent() { List<Bitmap> bitmaps = new List<Bitmap>(); var definitions = BlockDefinitionManager.GetBlockDefinitions(); foreach (var definition in definitions) bitmaps.AddRange(definition.Textures); int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count)); Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE); using (Graphics g = Graphics.FromImage(blocks)) { int counter = 0; foreach (var bitmap in bitmaps) { int x = counter % size; int y = (int)(counter / size); g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE)); counter++; } } using (MemoryStream stream = new MemoryStream()) { blocks.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); blockTextures = Texture2D.FromStream(GraphicsDevice, stream); } planet = ResourceManager.Instance.GetPlanet(0); chunkRenderer = new ChunkRenderer[ ((VIEWRANGE * 2) + 1) * ((VIEWRANGE * 2) + 1) * ((VIEWHEIGHT * 2) + 1)]; for (int i = 0; i < chunkRenderer.Length; i++) { chunkRenderer[i] = new ChunkRenderer(GraphicsDevice, camera.Projection, blockTextures); freeChunkRenderer.Enqueue(chunkRenderer[i]); } // Entfernungsarray erzeugen for (int x = -VIEWRANGE; x <= VIEWRANGE; x++) for (int y = -VIEWRANGE; y <= VIEWRANGE; y++) for (int z = -VIEWHEIGHT; z <= VIEWHEIGHT; z++) distances.Add(new Index3(x, y, z)); distances = distances.OrderBy(d => d.LengthSquared()).ToList(); backgroundThread = new Thread(BackgroundLoop); backgroundThread.Priority = ThreadPriority.Lowest; backgroundThread.IsBackground = true; backgroundThread.Start(); selectionLines = new[] { new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), }; selectionIndeces = new short[] { 0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6, 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7 }; selectionEffect = new BasicEffect(GraphicsDevice); selectionEffect.VertexColorEnabled = true; MiniMapTexture = new RenderTarget2D(GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); minimapEffect = new BasicEffect(GraphicsDevice); minimapEffect.Projection = Matrix.CreateOrthographic(100, 100, 1, 10000); minimapEffect.EnableDefaultLighting(); base.LoadContent(); }
public IChunk[] GenerateChunk(IEnumerable<IBlockDefinition> blockDefinitions, IPlanet planet, Index2 index) { IBlockDefinition sandDefinition = blockDefinitions.FirstOrDefault(d => typeof(SandBlockDefinition) == d.GetType()); ushort sandIndex = (ushort)(Array.IndexOf(blockDefinitions.ToArray(), sandDefinition) + 1); IBlockDefinition groundDefinition = blockDefinitions.FirstOrDefault(d => typeof(GroundBlockDefinition) == d.GetType()); ushort groundIndex = (ushort)(Array.IndexOf(blockDefinitions.ToArray(), groundDefinition) + 1); IBlockDefinition stoneDefinition = blockDefinitions.FirstOrDefault(d => typeof(StoneBlockDefinition) == d.GetType()); ushort stoneIndex = (ushort)(Array.IndexOf(blockDefinitions.ToArray(), stoneDefinition) + 1); IBlockDefinition waterDefinition = blockDefinitions.FirstOrDefault(d => typeof(WaterBlockDefinition) == d.GetType()); ushort waterIndex = (ushort)(Array.IndexOf(blockDefinitions.ToArray(), waterDefinition) + 1); IBlockDefinition grassDefinition = blockDefinitions.FirstOrDefault(d => typeof(GrassBlockDefinition) == d.GetType()); ushort grassIndex = (ushort)(Array.IndexOf(blockDefinitions.ToArray(), grassDefinition) + 1); if (!(planet is ComplexPlanet)) throw new ArgumentException("planet is not a Type of ComplexPlanet"); ComplexPlanet localPlanet = (ComplexPlanet)planet; float[,] localHeightmap = localPlanet.BiomeGenerator.GetHeightmap(index); IChunk[] chunks = new IChunk[planet.Size.Z]; for (int i = 0; i < planet.Size.Z; i++) chunks[i] = new Chunk(new Index3(index, i), planet.Id); int obersteSchicht; bool surfaceBlock; bool ozeanSurface; for (int x = 0; x < Chunk.CHUNKSIZE_X; x++) { for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++) { obersteSchicht = 5; surfaceBlock = true; ozeanSurface = false; for (int i = chunks.Length - 1; i >= 0; i--) { for (int z = Chunk.CHUNKSIZE_Z - 1; z >= 0; z--) { int absoluteZ = (z + (i * Chunk.CHUNKSIZE_Z)); if (absoluteZ <= localHeightmap[x, y] * localPlanet.Size.Z * Chunk.CHUNKSIZE_Z) { if (obersteSchicht > 0) { float temp = localPlanet.ClimateMap.GetTemperature(new Index3(index.X * Chunk.CHUNKSIZE_X + x, index.Y * Chunk.CHUNKSIZE_Y + y, i * Chunk.CHUNKSIZE_Z + z)); if ((ozeanSurface || surfaceBlock) && (absoluteZ <= (localPlanet.BiomeGenerator.SeaLevel + 2)) && (absoluteZ >= (localPlanet.BiomeGenerator.SeaLevel - 2))) { chunks[i].SetBlock(x, y, z, sandIndex); } else if (temp >= 35) { chunks[i].SetBlock(x, y, z, sandIndex); } else if (absoluteZ >= localPlanet.Size.Z * Chunk.CHUNKSIZE_Z * 0.6f) { if (temp > 12) chunks[i].SetBlock(x, y, z, groundIndex); else chunks[i].SetBlock(x, y, z, stoneIndex); } else if (temp >= 8) { if (surfaceBlock && !ozeanSurface) { chunks[i].SetBlock(x, y, z, grassIndex); surfaceBlock = false; } else { chunks[i].SetBlock(x, y, z, groundIndex); } } else { chunks[i].SetBlock(x, y, z, groundIndex); } obersteSchicht--; } else { chunks[i].SetBlock(x, y, z, stoneIndex); } } else if ((z + (i * Chunk.CHUNKSIZE_Z)) <= localPlanet.BiomeGenerator.SeaLevel) { chunks[i].SetBlock(x, y, z, waterIndex); ozeanSurface = true; } } } } } //float[,] cloudmap = null; ////Biomes.BiomeBlockValue[, ,] blockValues = localPlanet.BiomeGenerator.GetBlockValues(index,heightmap,0f,1f); ////for (int x = 0; x < Chunk.CHUNKSIZE_X; x++) //Parallel.For(0, Chunk.CHUNKSIZE_X, x => //{ // for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++) // { // bool grass = true, sand = false; // for (int i = chunks.Length - 1; i >= 0; i--) // { // for (int z = Chunk.CHUNKSIZE_Z - 1; z >= 0; z--) // { // //Biomes.BiomeBlockValue blockValue = blockValues[x, y, z + i * Chunk.CHUNKSIZE_Z]; // int blockHeight = Math.Max(z + Chunk.CHUNKSIZE_Z * (i), 0); // //float density = heightmap[x,y] * (Chunk.CHUNKSIZE_Z * (planet.Size.Z)) - blockHeight; // Index3 blockIndex = new Index3(index.X * Chunk.CHUNKSIZE_X + x, index.Y * Chunk.CHUNKSIZE_Y + y, i * Chunk.CHUNKSIZE_Z + z); // if (blockValue.Density > 0.6f || (z < 3 && i == 0)) // { // if (blockValue.IsDessert || (grass | sand) && (z + (i * Chunk.CHUNKSIZE_Z)) <= localPlanet.BiomeGenerator.SeaLevel && (z + (i * Chunk.CHUNKSIZE_Z)) >= localPlanet.BiomeGenerator.SeaLevel - 2) // { // chunks[i].SetBlock(new Index3(x, y, z), new SandBlock()); // grass = false; // sand = true; // } // else if (grass && planet.ClimateMap.GetTemperature(blockIndex) > 18.0f) // { // chunks[i].SetBlock(new Index3(x, y, z), new GrassBlock()); // grass = false; // } // //else if (z < Chunk.CHUNKSIZE_Z - 1 && noiseplus >= resDensity) // //{ // // chunks[i].SetBlock(new Index3(x, y, z), new StoneBlock()); // //} // else // { // chunks[i].SetBlock(new Index3(x, y, z), new GroundBlock()); // grass = false; // } // } // else if ((z + (i * Chunk.CHUNKSIZE_Z)) <= localPlanet.BiomeGenerator.SeaLevel) // { // grass = false; // sand = true; // chunks[i].SetBlock(new Index3(x, y, z), new WaterBlock()); // } // } // } // } //}); return chunks; }
public SceneControl(ScreenComponent manager, string style = "") : base(manager, style) { player = manager.Player; camera = manager.Camera; Manager = manager; simpleShader = manager.Game.Content.Load<Effect>("simple"); sunTexture = manager.Game.Content.LoadTexture2DFromFile("./Assets/OctoAwesome.Client/sun.png", manager.GraphicsDevice); List<Bitmap> bitmaps = new List<Bitmap>(); var definitions = DefinitionManager.Instance.GetBlockDefinitions(); foreach (var definition in definitions) bitmaps.AddRange(definition.Textures); int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count)); Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE); using (Graphics g = Graphics.FromImage(blocks)) { int counter = 0; foreach (var bitmap in bitmaps) { int x = counter % size; int y = (int)(counter / size); g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE)); counter++; } } using (MemoryStream stream = new MemoryStream()) { blocks.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream); } planet = ResourceManager.Instance.GetPlanet(0); // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1 int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2; localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range); chunkRenderer = new ChunkRenderer[ (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE), planet.Size.Z]; orderedChunkRenderer = new List<ChunkRenderer>( (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z); for (int i = 0; i < chunkRenderer.GetLength(0); i++) { for (int j = 0; j < chunkRenderer.GetLength(1); j++) { ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures); chunkRenderer[i, j] = renderer; orderedChunkRenderer.Add(renderer); } } backgroundThread = new Thread(BackgroundLoop); backgroundThread.Priority = ThreadPriority.Lowest; backgroundThread.IsBackground = true; backgroundThread.Start(); selectionLines = new[] { new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), }; billboardVertices = new[] { new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), }; selectionIndeces = new short[] { 0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6, 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7 }; sunEffect = new BasicEffect(manager.GraphicsDevice); sunEffect.TextureEnabled = true; selectionEffect = new BasicEffect(manager.GraphicsDevice); selectionEffect.VertexColorEnabled = true; MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000); }
void Start() { ship = registry.LookUp<IShip>("Ship"); planet = registry.LookUp<IPlanet>("Planet"); }
private void savePlanet(int index, IPlanet value) { }
public void Show() { _planet = _planetFactory.Create(DoubleVector3.Zero, PhysicalConstants.RadiusOfEarth); _cameraController.AttachToPlanet(_planet); _windowManager.ShowAllWindows(); }
public SceneControl(ScreenComponent manager, string style = "") : base(manager, style) { player = manager.Player; camera = manager.Camera; assets = manager.Game.Assets; Manager = manager; simpleShader = manager.Game.Content.Load<Effect>("simple"); sunTexture = assets.LoadTexture(typeof(ScreenComponent), "sun"); //List<Bitmap> bitmaps = new List<Bitmap>(); var definitions = DefinitionManager.Instance.GetBlockDefinitions(); int textureCount = 0; foreach (var definition in definitions) { textureCount += definition.Textures.Length; } int bitmapSize = 128; blockTextures = new Texture2DArray(manager.GraphicsDevice, 1, bitmapSize, bitmapSize, textureCount); int layer = 0; foreach (var definition in definitions) { foreach (var bitmap in definition.Textures) { System.Drawing.Bitmap texture = manager.Game.Assets.LoadBitmap(definition.GetType(), bitmap); var scaled = texture;//new Bitmap(bitmap, new System.Drawing.Size(bitmapSize, bitmapSize)); int[] data = new int[scaled.Width * scaled.Height]; var bitmapData = scaled.LockBits(new System.Drawing.Rectangle(0, 0, scaled.Width, scaled.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, data, 0, data.Length); blockTextures.SetData(data, layer); scaled.UnlockBits(bitmapData); layer++; } } /*int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count)); Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE); using (Graphics g = Graphics.FromImage(blocks)) { int counter = 0; foreach (var bitmap in bitmaps) { int x = counter % size; int y = (int)(counter / size); g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE)); counter++; } } using (MemoryStream stream = new MemoryStream()) { blocks.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream); }*/ planet = ResourceManager.Instance.GetPlanet(0); // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1 int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2; localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range); chunkRenderer = new ChunkRenderer[ (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE), planet.Size.Z]; orderedChunkRenderer = new List<ChunkRenderer>( (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z); for (int i = 0; i < chunkRenderer.GetLength(0); i++) { for (int j = 0; j < chunkRenderer.GetLength(1); j++) { ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures); chunkRenderer[i, j] = renderer; orderedChunkRenderer.Add(renderer); } } backgroundThread = new Thread(BackgroundLoop); backgroundThread.Priority = ThreadPriority.Lowest; backgroundThread.IsBackground = true; backgroundThread.Start(); var selectionVertices = new[] { new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Color.Black * 0.5f), }; var billboardVertices = new[] { new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), }; var selectionIndices = new short[] { 0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6, 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7 }; selectionLines = new VertexBuffer(manager.GraphicsDevice, VertexPositionColor.VertexDeclaration, selectionVertices.Length); selectionLines.SetData(selectionVertices); selectionIndexBuffer = new IndexBuffer(manager.GraphicsDevice, DrawElementsType.UnsignedShort, selectionIndices.Length); selectionIndexBuffer.SetData(selectionIndices); billboardVertexbuffer = new VertexBuffer(manager.GraphicsDevice, VertexPositionTexture.VertexDeclaration, billboardVertices.Length); billboardVertexbuffer.SetData(billboardVertices); sunEffect = new BasicEffect(manager.GraphicsDevice); sunEffect.TextureEnabled = true; selectionEffect = new BasicEffect(manager.GraphicsDevice); selectionEffect.VertexColorEnabled = true; MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, PixelInternalFormat.Rgb8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000); }
public SceneControl(ScreenComponent manager, string style = "") : base(manager, style) { player = manager.Player; camera = manager.Camera; Manager = manager; simpleShader = manager.Game.Content.Load<Effect>("simple"); sunTexture = manager.Game.Content.Load<Texture2D>("Textures/sun"); List<Bitmap> bitmaps = new List<Bitmap>(); var definitions = DefinitionManager.GetBlockDefinitions(); foreach (var definition in definitions) bitmaps.AddRange(definition.Textures); int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count)); Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE); using (Graphics g = Graphics.FromImage(blocks)) { int counter = 0; foreach (var bitmap in bitmaps) { int x = counter % size; int y = (int)(counter / size); g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE)); counter++; } } using (MemoryStream stream = new MemoryStream()) { blocks.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream); } planet = ResourceManager.Instance.GetPlanet(0); _manager = ResourceManager.Instance.GetManagerForPlanet(planet.Id); chunkRenderer = new ChunkRenderer[ (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE), planet.Size.Z]; for (int i = 0; i < chunkRenderer.GetLength(0); i++) for (int j = 0; j < chunkRenderer.GetLength(1); j++) chunkRenderer[i, j] = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures); // Entfernungsarray erzeugen //for (int x = -VIEWRANGE; x <= VIEWRANGE; x++) // for (int y = -VIEWRANGE; y <= VIEWRANGE; y++) // for (int z = 0; z <= planet.Size.Z; z++) // distances.Add(new Index3(x, y, z)); //distances = distances.OrderBy(d => d.LengthSquared()).ToList(); backgroundThread = new Thread(BackgroundLoop); backgroundThread.Priority = ThreadPriority.Lowest; backgroundThread.IsBackground = true; backgroundThread.Start(); selectionLines = new[] { new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f), }; billboardVertices = new[] { new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)), }; selectionIndeces = new short[] { 0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6, 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7 }; sunEffect = new BasicEffect(manager.GraphicsDevice); sunEffect.TextureEnabled = true; selectionEffect = new BasicEffect(manager.GraphicsDevice); selectionEffect.VertexColorEnabled = true; MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000); }
public override int GetDensity(IPlanet planet, Index3 index) { return 4; }