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)); } } }
public void Index3ConstructorTest() { // Parameterlos Index3 i1 = new Index3(); Assert.AreEqual(0, i1.X); Assert.AreEqual(0, i1.Y); Assert.AreEqual(0, i1.Z); // Simpler Parameter Index3 i2 = new Index3(21, 32, 99); Assert.AreEqual(21, i2.X); Assert.AreEqual(32, i2.Y); Assert.AreEqual(99, i2.Z); // Index2-Parameter Index3 i3 = new Index3(new Index2(-2, 80), 76); Assert.AreEqual(-2, i3.X); Assert.AreEqual(80, i3.Y); Assert.AreEqual(76, i3.Z); // Index3 Parameter Index3 i4 = new Index3(new Index3(int.MinValue, int.MaxValue, 3)); Assert.AreEqual(int.MinValue, i4.X); Assert.AreEqual(int.MaxValue, i4.Y); Assert.AreEqual(3, i4.Z); }
public void Index3ComparerTest() { Index3 i1 = new Index3(12, 13, 14); Index3 i2 = new Index3(12, 15, 33); Index3 i3 = new Index3(22, 13, 2); Index3 i4 = new Index3(22, 11, 14); Index3 i5 = new Index3(12, 13, 0); Index3 i6 = new Index3(0, 13, 14); Index3 i7 = new Index3(12, 0, 14); Index3 i8 = new Index3(12, 13, 14); Assert.AreEqual(i1, i1); Assert.AreEqual(i1, i8); Assert.AreNotEqual(i1, i2); Assert.AreNotEqual(i1, i3); Assert.AreNotEqual(i1, i4); Assert.AreNotEqual(i1, i5); Assert.AreNotEqual(i1, i6); Assert.AreNotEqual(i1, i7); Assert.IsTrue(i1 == i1); Assert.IsTrue(i1 == i8); Assert.IsTrue(i1 != i2); Assert.IsTrue(i1 != i3); Assert.IsTrue(i1 != i4); Assert.IsTrue(i1 != i5); Assert.IsTrue(i1 != i6); Assert.IsTrue(i1 != i7); }
public void Draw(Matrix view, Matrix projection, Index3 shift) { if (!loaded) return; Matrix worldViewProj = Matrix.CreateTranslation( shift.X * Chunk.CHUNKSIZE_X, shift.Y * Chunk.CHUNKSIZE_Y, shift.Z * Chunk.CHUNKSIZE_Z) * view * projection; simple.Parameters["WorldViewProj"].SetValue(worldViewProj); simple.Parameters["BlockTextures"].SetValue(textures); simple.Parameters["AmbientIntensity"].SetValue(0.4f); simple.Parameters["AmbientColor"].SetValue(Color.White.ToVector4()); lock (this) { if (vb == null) return; graphicsDevice.SetVertexBuffer(vb); graphicsDevice.Indices = ib; foreach (var pass in simple.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexCount, 0, indexCount / 3); } } }
public ComplexPlanet(int id, int universe, Index3 size, IMapGenerator generator, int seed) : base(id, universe, size, seed) { BiomeGenerator = new SurfaceBiomeGenerator(this, 40); this.Heightmap = null; ClimateMap = new Climate.ComplexClimateMap(this); }
public IPlanet GeneratePlanet(int universe, int seed) { Index3 size = new Index3(12, 12, 3); ComplexPlanet planet = new ComplexPlanet(0, universe, size, this, seed); return planet; }
//public static Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone GetZone(Index3 cellIndex, List<Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone> Zones)//List<Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone> TopZone) //{ // foreach (Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone zone in Zones) // { // if (cellIndex.K > zone.BaseK && cellIndex.K) // { // } // } //} public static Point3[] GetCornerSet(CellSide SideOfCell, Grid gridInContext, Index3 CellIndex) { CellCorner[] CellCorners = new CellCorner[4]; Point3[] CellCornerPoints = new Point3[4]; switch (SideOfCell) { case CellSide.Up: CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.TopSouthWest; CellCorners[3] = CellCorner.TopSouthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.East: CellCorners[0] = CellCorner.TopSouthEast; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.BaseSouthEast; CellCorners[3] = CellCorner.BaseNorthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.West: CellCorners[0] = CellCorner.TopSouthWest; CellCorners[1] = CellCorner.TopNorthWest; CellCorners[2] = CellCorner.BaseSouthWest; CellCorners[3] = CellCorner.BaseNorthWest; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.South: CellCorners[0] = CellCorner.TopSouthWest; CellCorners[1] = CellCorner.TopSouthEast; CellCorners[2] = CellCorner.BaseSouthWest; CellCorners[3] = CellCorner.BaseSouthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.North: CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.BaseNorthWest; CellCorners[3] = CellCorner.BaseNorthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.Down: CellCorners[0] = CellCorner.BaseNorthWest; CellCorners[1] = CellCorner.BaseNorthEast; CellCorners[2] = CellCorner.BaseSouthWest; CellCorners[3] = CellCorner.BaseSouthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; default: CellCornerPoints = null; break; } return CellCornerPoints; }
/// <summary> /// Erzeugt eine neue Instanz der Klasse Chunk /// </summary> /// <param name="pos">Position des Chunks</param> /// <param name="planet">Index des Planeten</param> public Chunk(Index3 pos, int planet) { Blocks = new ushort[CHUNKSIZE_X * CHUNKSIZE_Y * CHUNKSIZE_Z]; MetaData = new int[CHUNKSIZE_X * CHUNKSIZE_Y * CHUNKSIZE_Z]; Resources = new ushort[CHUNKSIZE_X * CHUNKSIZE_Y * CHUNKSIZE_Z][]; Index = pos; Planet = planet; ChangeCounter = 0; }
public int GetPrecipitation(Index3 blockIndex) { int maxPrecipitation = 100; float rawValue = planet.BiomeGenerator.BiomeNoiseGenerator.GetTileableNoise2D(blockIndex.X, blockIndex.Y, Planet.Size.X * Chunk.CHUNKSIZE_X, Planet.Size.Y * Chunk.CHUNKSIZE_Y); int height = blockIndex.Z - planet.BiomeGenerator.SeaLevel; float precipitationDecreasePerBlock = 1; return (int)(((1 - rawValue) * maxPrecipitation) - (Math.Max(height, 0) * precipitationDecreasePerBlock)); }
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) { 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 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 IChunk Load(int universe, int planet, Index3 index) { var root = GetRoot(); string filename = planet.ToString() + "_" + index.X + "_" + index.Y + "_" + index.Z + ".chunk"; if (!File.Exists(root.FullName + Path.DirectorySeparatorChar + filename)) return null; using (Stream stream = File.Open(root.FullName + Path.DirectorySeparatorChar + filename, FileMode.Open, FileAccess.Read)) { return serializer.Deserialize(stream, new PlanetIndex3(planet, index)); } }
public void SetChunk(ILocalChunkCache manager, int x, int y, int z) { var newPosition = new Index3(x, y, z); if (_manager == manager && newPosition == ChunkPosition) return; _manager = manager; ChunkPosition = newPosition; chunk = null; loaded = false; }
public IChunk Load(int universe, int planet, Index3 index) { var root = GetRoot(); string filename = planet.ToString() + "_" + index.X + "_" + index.Y + "_" + index.Z + ".chunk"; if (!File.Exists(root.FullName + Path.DirectorySeparatorChar + filename)) return null; using (Stream stream = File.Open(root.FullName + Path.DirectorySeparatorChar + filename, FileMode.Open, FileAccess.Read)) { IChunk chunk = new Chunk(index, planet); chunk.Deserialize(stream, BlockDefinitionManager.GetBlockDefinitions()); return chunk; } }
public float GetTemperature(Index3 blockIndex) { int equator = (Planet.Size.Y * Chunk.CHUNKSIZE_Y) / 2; float equatorTemperature = 40f; float poleTemperature = -10f; float tempFluctuation = tempFluctuationGenerator.GetTileableNoise2D(blockIndex.X, blockIndex.Y, Planet.Size.X * Chunk.CHUNKSIZE_X, Planet.Size.Y * Chunk.CHUNKSIZE_Y) * 5f; float temperatureDifference = poleTemperature - equatorTemperature; float temperatureDecreasePerBlock = 0.1f; float distance = Math.Abs(blockIndex.Y - equator); float temperature = tempFluctuation + equatorTemperature + temperatureDifference * (float)Math.Sin((Math.PI / 2) * distance / equator); //equatorTemperature + distance * temperatureDifference / equator; float height = (blockIndex.Z - planet.BiomeGenerator.SeaLevel) / (Planet.Size.Z * Chunk.CHUNKSIZE_Z - planet.BiomeGenerator.SeaLevel); height = Math.Max(height, 0); height *= height; return temperature - height * temperatureDecreasePerBlock; }
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 void Index3AdditionTest() { Index3 i1 = new Index3(20, 15, 17); // Startwert Index2 in2 = new Index2(-100, -130); // Negativ Addition (2D) Index3 in3 = new Index3(-100, -130, -33); // Negativ Addition (3D) Index3 in2r = new Index3(-80, -115, 17); // Ergebnis i1 + in2 Index3 in3r = new Index3(-80, -115, -16); // Ergebnis i1 + in3 Index2 ip2 = new Index2(77, 44); // positive Addition (2D) Index3 ip3 = new Index3(77, 44, 54); // positive Addition (3D) Index3 ip2r = new Index3(97, 59, 17); // Ergebnis i1 + ip2 Index3 ip3r = new Index3(97, 59, 71); // Ergebnis i1 + ip3 // Addition Assert.AreEqual(in2r, i1 + in2); Assert.AreEqual(in3r, i1 + in3); Assert.AreEqual(ip2r, i1 + ip2); Assert.AreEqual(ip3r, i1 + ip3); }
/// <summary> /// Liefert den Block an der angegebenen Block-Koodinate zurück. /// </summary> /// <param name="index">Block Index</param> /// <returns>Block oder null, falls dort kein Block existiert</returns> public IBlock GetBlock(int planetId, Index3 index) { IPlanet planet = GetPlanet(planetId); index.NormalizeXY(new Index2( planet.Size.X * Chunk.CHUNKSIZE_X, planet.Size.Y * Chunk.CHUNKSIZE_Y)); Coordinate coordinate = new Coordinate(0, index, Vector3.Zero); // Betroffener Chunk ermitteln Index3 chunkIndex = coordinate.ChunkIndex; if (chunkIndex.X < 0 || chunkIndex.X >= planet.Size.X || chunkIndex.Y < 0 || chunkIndex.Y >= planet.Size.Y || chunkIndex.Z < 0 || chunkIndex.Z >= planet.Size.Z) return null; IChunk chunk = chunkCache.Get(new PlanetIndex3(planetId, chunkIndex)); if (chunk == null) return null; return chunk.GetBlock(coordinate.LocalBlockIndex); }
public IPlanet GeneratePlanet(int universe, int seed) { // Index3 size = new Index3(4096, 4096, 4); Index3 size = new Index3(8, 8, 2); ComplexPlanet planet = new ComplexPlanet(0, universe, size, this, seed); return planet; }
protected override void OnPreDraw(GameTime gameTime) { if (player.ActorHost == null) return; if (ControlTexture == null) { ControlTexture = new RenderTarget2D(Manager.GraphicsDevice, ActualClientArea.Width, ActualClientArea.Height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); } float octoDaysPerEarthDay = 360f; float inclinationVariance = MathHelper.Pi / 3f; float playerPosX = ((float)player.ActorHost.Player.Position.GlobalPosition.X / (planet.Size.X * Chunk.CHUNKSIZE_X)) * MathHelper.TwoPi; float playerPosY = ((float)player.ActorHost.Player.Position.GlobalPosition.Y / (planet.Size.Y * Chunk.CHUNKSIZE_Y)) * MathHelper.TwoPi; TimeSpan diff = DateTime.UtcNow - new DateTime(1888, 8, 8); float inclination = ((float)Math.Sin(playerPosY) * inclinationVariance) + MathHelper.Pi / 6f; //Console.WriteLine("Stand: " + (MathHelper.Pi + playerPosX) + " Neigung: " + inclination); Matrix sunMovement = Matrix.CreateRotationX(inclination) * //Matrix.CreateRotationY((((float)gameTime.TotalGameTime.TotalMinutes * MathHelper.TwoPi) + playerPosX) * -1); Matrix.CreateRotationY((float)(MathHelper.TwoPi - ((diff.TotalDays * octoDaysPerEarthDay * MathHelper.TwoPi) % MathHelper.TwoPi))); Vector3 sunDirection = Vector3.Transform(new Vector3(0, 0, 1), sunMovement); simpleShader.Parameters["DiffuseColor"].SetValue(new Microsoft.Xna.Framework.Color(190, 190, 190).ToVector4()); simpleShader.Parameters["DiffuseIntensity"].SetValue(0.6f); simpleShader.Parameters["DiffuseDirection"].SetValue(sunDirection); // Console.WriteLine(sunDirection); // Index3 chunkOffset = player.ActorHost.Position.ChunkIndex; Index3 chunkOffset = camera.CameraChunk; Microsoft.Xna.Framework.Color background = new Microsoft.Xna.Framework.Color(181, 224, 255); Manager.GraphicsDevice.SetRenderTarget(MiniMapTexture); Manager.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Manager.GraphicsDevice.Clear(background); foreach (var renderer in chunkRenderer) { if (!renderer.ChunkPosition.HasValue) continue; Index3 shift = chunkOffset.ShortestDistanceXY( renderer.ChunkPosition.Value, new Index2( planet.Size.X, planet.Size.Y)); BoundingBox chunkBox = new BoundingBox( new Vector3( shift.X * Chunk.CHUNKSIZE_X, shift.Y * Chunk.CHUNKSIZE_Y, shift.Z * Chunk.CHUNKSIZE_Z), new Vector3( (shift.X + 1) * Chunk.CHUNKSIZE_X, (shift.Y + 1) * Chunk.CHUNKSIZE_Y, (shift.Z + 1) * Chunk.CHUNKSIZE_Z)); int range = 3; if (shift.X >= -range && shift.X <= range && shift.Y >= -range && shift.Y <= range) renderer.Draw(camera.MinimapView, miniMapProjectionMatrix, shift); } Manager.GraphicsDevice.SetRenderTarget(ControlTexture); Manager.GraphicsDevice.Clear(background); Manager.GraphicsDevice.BlendState = BlendState.AlphaBlend; Manager.GraphicsDevice.DepthStencilState = DepthStencilState.None; // Draw Sun // GraphicsDevice.RasterizerState = RasterizerState.CullNone; sunEffect.Texture = sunTexture; Matrix billboard = Matrix.Invert(camera.View); billboard.Translation = player.ActorHost.Position.LocalPosition + (sunDirection * -10); sunEffect.World = billboard; sunEffect.View = camera.View; sunEffect.Projection = camera.Projection; sunEffect.CurrentTechnique.Passes[0].Apply(); Manager.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, billboardVertices, 0, 2); Manager.GraphicsDevice.DepthStencilState = DepthStencilState.Default; foreach (var renderer in chunkRenderer) { if (!renderer.ChunkPosition.HasValue) continue; Index3 shift = chunkOffset.ShortestDistanceXY( renderer.ChunkPosition.Value, new Index2( planet.Size.X, planet.Size.Y)); BoundingBox chunkBox = new BoundingBox( new Vector3( shift.X * Chunk.CHUNKSIZE_X, shift.Y * Chunk.CHUNKSIZE_Y, shift.Z * Chunk.CHUNKSIZE_Z), new Vector3( (shift.X + 1) * Chunk.CHUNKSIZE_X, (shift.Y + 1) * Chunk.CHUNKSIZE_Y, (shift.Z + 1) * Chunk.CHUNKSIZE_Z)); if (camera.Frustum.Intersects(chunkBox)) renderer.Draw(camera.View, camera.Projection, shift); } if (player.SelectedBox.HasValue) { // Index3 offset = player.ActorHost.Position.ChunkIndex * Chunk.CHUNKSIZE; Index3 offset = camera.CameraChunk * Chunk.CHUNKSIZE; Index3 planetSize = planet.Size * Chunk.CHUNKSIZE; Index3 relativePosition = new Index3( Index2.ShortestDistanceOnAxis(offset.X, player.SelectedBox.Value.X, planetSize.X), Index2.ShortestDistanceOnAxis(offset.Y, player.SelectedBox.Value.Y, planetSize.Y), player.SelectedBox.Value.Z - offset.Z); Vector3 selectedBoxPosition = new Vector3( player.SelectedBox.Value.X - (chunkOffset.X * Chunk.CHUNKSIZE_X), player.SelectedBox.Value.Y - (chunkOffset.Y * Chunk.CHUNKSIZE_Y), player.SelectedBox.Value.Z - (chunkOffset.Z * Chunk.CHUNKSIZE_Z)); // selectionEffect.World = Matrix.CreateTranslation(selectedBoxPosition); selectionEffect.World = Matrix.CreateTranslation(relativePosition); selectionEffect.View = camera.View; selectionEffect.Projection = camera.Projection; foreach (var pass in selectionEffect.CurrentTechnique.Passes) { pass.Apply(); Manager.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, selectionLines, 0, 8, selectionIndeces, 0, 12); } } Manager.GraphicsDevice.SetRenderTarget(null); }
public void Update(GameTime frameTime) { #region Inputverarbeitung // Input verarbeiten Player.Angle += (float)frameTime.ElapsedGameTime.TotalSeconds * Head.X; Player.Tilt += (float)frameTime.ElapsedGameTime.TotalSeconds * Head.Y; Player.Tilt = Math.Min(1.5f, Math.Max(-1.5f, Player.Tilt)); #endregion #region Physik float lookX = (float)Math.Cos(Player.Angle); float lookY = -(float)Math.Sin(Player.Angle); var velocitydirection = new Vector3(lookX, lookY, 0) * Move.Y; float stafeX = (float)Math.Cos(Player.Angle + MathHelper.PiOver2); float stafeY = -(float)Math.Sin(Player.Angle + MathHelper.PiOver2); velocitydirection += new Vector3(stafeX, stafeY, 0) * Move.X; Player.Velocity += PhysicalUpdate(velocitydirection, frameTime.ElapsedGameTime, !Player.FlyMode, Player.FlyMode); #endregion #region Playerbewegung Vector3 move = Player.Velocity * (float)frameTime.ElapsedGameTime.TotalSeconds; Player.OnGround = false; bool collision = false; int loop = 0; do { int minx = (int)Math.Floor(Math.Min( Player.Position.BlockPosition.X - Player.Radius, Player.Position.BlockPosition.X - Player.Radius + move.X)); int maxx = (int)Math.Floor(Math.Max( Player.Position.BlockPosition.X + Player.Radius, Player.Position.BlockPosition.X + Player.Radius + move.X)); int miny = (int)Math.Floor(Math.Min( Player.Position.BlockPosition.Y - Player.Radius, Player.Position.BlockPosition.Y - Player.Radius + move.Y)); int maxy = (int)Math.Floor(Math.Max( Player.Position.BlockPosition.Y + Player.Radius, Player.Position.BlockPosition.Y + Player.Radius + move.Y)); int minz = (int)Math.Floor(Math.Min( Player.Position.BlockPosition.Z, Player.Position.BlockPosition.Z + move.Z)); int maxz = (int)Math.Floor(Math.Max( Player.Position.BlockPosition.Z + Player.Height, Player.Position.BlockPosition.Z + Player.Height + move.Z)); // Relative PlayerBox BoundingBox playerBox = new BoundingBox( new Vector3( Player.Position.BlockPosition.X - Player.Radius, Player.Position.BlockPosition.Y - Player.Radius, Player.Position.BlockPosition.Z), new Vector3( Player.Position.BlockPosition.X + Player.Radius, Player.Position.BlockPosition.Y + Player.Radius, Player.Position.BlockPosition.Z + Player.Height)); collision = false; float min = 1f; Axis minAxis = Axis.None; for (int z = minz; z <= maxz; z++) { for (int y = miny; y <= maxy; y++) { for (int x = minx; x <= maxx; x++) { Index3 pos = new Index3(x, y, z); Index3 blockPos = pos + Player.Position.GlobalBlockIndex; ushort block = localChunkCache.GetBlock(blockPos); if (block == 0) continue; Axis? localAxis; IBlockDefinition blockDefinition = DefinitionManager.GetBlockDefinitionByIndex(block); float? moveFactor = Block.Intersect( blockDefinition.GetCollisionBoxes(localChunkCache, blockPos.X, blockPos.Y, blockPos.Z), pos, playerBox, move, out localAxis); if (moveFactor.HasValue && moveFactor.Value < min) { collision = true; min = moveFactor.Value; minAxis = localAxis.Value; } } } } Player.Position += (move * min); move *= (1f - min); switch (minAxis) { case Axis.X: Player.Velocity *= new Vector3(0, 1, 1); Player.Position += new Vector3(move.X > 0 ? -Gap : Gap, 0, 0); move.X = 0f; break; case Axis.Y: Player.Velocity *= new Vector3(1, 0, 1); Player.Position += new Vector3(0, move.Y > 0 ? -Gap : Gap, 0); move.Y = 0f; break; case Axis.Z: Player.OnGround = true; Player.Velocity *= new Vector3(1, 1, 0); Player.Position += new Vector3(0, 0, move.Z > 0 ? -Gap : Gap); move.Z = 0f; break; } // Koordinate normalisieren (Rundwelt) Coordinate position = Player.Position; position.NormalizeChunkIndexXY(planet.Size); //Beam me up KeyboardState ks = Keyboard.GetState(); if (ks.IsKeyDown(Keys.P)) { position = position + new Vector3(0, 0, 10); } Player.Position = position; loop++; } while (collision && loop < 3); if (Player.Position.ChunkIndex != _oldIndex) { _oldIndex = Player.Position.ChunkIndex; ReadyState = false; localChunkCache.SetCenter(planet, Player.Position.ChunkIndex, (success) => { ReadyState = success; }); } #endregion #region Block Interaction if (lastInteract.HasValue) { ushort lastBlock = localChunkCache.GetBlock(lastInteract.Value); localChunkCache.SetBlock(lastInteract.Value, 0); if (lastBlock != 0) { var blockDefinition = DefinitionManager.GetBlockDefinitionByIndex(lastBlock); var slot = Player.Inventory.Where(s => s.Definition == blockDefinition && s.Amount < blockDefinition.StackLimit).FirstOrDefault(); // Wenn noch kein Slot da ist oder der vorhandene voll, dann neuen Slot if (slot == null || slot.Amount >= blockDefinition.StackLimit) { slot = new InventorySlot() { Definition = blockDefinition, Amount = 0 }; Player.Inventory.Add(slot); } slot.Amount++; } lastInteract = null; } if (lastApply.HasValue) { if (ActiveTool != null) { Index3 add = new Index3(); switch (lastOrientation) { case OrientationFlags.SideWest: add = new Index3(-1, 0, 0); break; case OrientationFlags.SideEast: add = new Index3(1, 0, 0); break; case OrientationFlags.SideSouth: add = new Index3(0, -1, 0); break; case OrientationFlags.SideNorth: add = new Index3(0, 1, 0); break; case OrientationFlags.SideBottom: add = new Index3(0, 0, -1); break; case OrientationFlags.SideTop: add = new Index3(0, 0, 1); break; } if (ActiveTool.Definition is IBlockDefinition) { IBlockDefinition definition = ActiveTool.Definition as IBlockDefinition; localChunkCache.SetBlock(lastApply.Value + add, DefinitionManager.GetBlockDefinitionIndex(definition)); ActiveTool.Amount--; if (ActiveTool.Amount <= 0) { Player.Inventory.Remove(ActiveTool); ActiveTool = null; } } // TODO: Fix Interaction ;) //ushort block = _manager.GetBlock(lastApply.Value); //IBlockDefinition blockDefinition = BlockDefinitionManager.GetForType(block); //IItemDefinition itemDefinition = ActiveTool.Definition; //blockDefinition.Hit(blockDefinition, itemDefinition.GetProperties(null)); //itemDefinition.Hit(null, blockDefinition.GetProperties(block)); } lastApply = null; } #endregion }
protected override void OnUpdate(GameTime gameTime) { if (player.ActorHost == null) { return; } sunPosition += (float)gameTime.ElapsedGameTime.TotalMinutes * MathHelper.TwoPi; Index3 centerblock = player.ActorHost.Position.GlobalBlockIndex; Index3 renderOffset = player.ActorHost.Position.ChunkIndex * Chunk.CHUNKSIZE; Index3? selected = null; Axis? selectedAxis = null; Vector3?selectionPoint = null; float bestDistance = 9999; for (int z = -Player.SELECTIONRANGE; z < Player.SELECTIONRANGE; z++) { for (int y = -Player.SELECTIONRANGE; y < Player.SELECTIONRANGE; y++) { for (int x = -Player.SELECTIONRANGE; x < Player.SELECTIONRANGE; x++) { Index3 range = new Index3(x, y, z); Index3 pos = range + centerblock; ushort block = localChunkCache.GetBlock(pos); if (block == 0) { continue; } IBlockDefinition blockDefinition = DefinitionManager.Instance.GetBlockDefinitionByIndex(block); Axis? collisionAxis; float?distance = Block.Intersect(blockDefinition.GetCollisionBoxes(localChunkCache, pos.X, pos.Y, pos.Z), pos - renderOffset, camera.PickRay, out collisionAxis); if (distance.HasValue && distance.Value < bestDistance) { pos.NormalizeXY(planet.Size * Chunk.CHUNKSIZE); selected = pos; selectedAxis = collisionAxis; bestDistance = distance.Value; selectionPoint = (camera.PickRay.Position + (camera.PickRay.Direction * distance)) - (selected - renderOffset); } } } } if (selected.HasValue) { player.SelectedBox = selected; switch (selectedAxis) { case Axis.X: player.SelectedSide = (camera.PickRay.Direction.X > 0 ? OrientationFlags.SideWest : OrientationFlags.SideEast); break; case Axis.Y: player.SelectedSide = (camera.PickRay.Direction.Y > 0 ? OrientationFlags.SideSouth : OrientationFlags.SideNorth); break; case Axis.Z: player.SelectedSide = (camera.PickRay.Direction.Z > 0 ? OrientationFlags.SideBottom : OrientationFlags.SideTop); break; } player.SelectedPoint = new Vector2(); switch (player.SelectedSide) { case OrientationFlags.SideWest: player.SelectedPoint = new Vector2(1f - selectionPoint.Value.Y, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner011, OrientationFlags.Corner001, OrientationFlags.Corner010, OrientationFlags.Corner000); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeWestTop, OrientationFlags.EdgeWestBottom, OrientationFlags.EdgeNorthWest, OrientationFlags.EdgeSouthWest); break; case OrientationFlags.SideEast: player.SelectedPoint = new Vector2(selectionPoint.Value.Y, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner101, OrientationFlags.Corner111, OrientationFlags.Corner100, OrientationFlags.Corner110); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeEastTop, OrientationFlags.EdgeEastBottom, OrientationFlags.EdgeSouthEast, OrientationFlags.EdgeNorthEast); break; case OrientationFlags.SideTop: player.SelectedPoint = new Vector2(selectionPoint.Value.X, 1f - selectionPoint.Value.Y); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner011, OrientationFlags.Corner111, OrientationFlags.Corner001, OrientationFlags.Corner101); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeNorthTop, OrientationFlags.EdgeSouthTop, OrientationFlags.EdgeWestTop, OrientationFlags.EdgeEastTop); break; case OrientationFlags.SideBottom: player.SelectedPoint = new Vector2(selectionPoint.Value.X, selectionPoint.Value.Y); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner000, OrientationFlags.Corner100, OrientationFlags.Corner010, OrientationFlags.Corner110); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeSouthBottom, OrientationFlags.EdgeNorthBottom, OrientationFlags.EdgeWestBottom, OrientationFlags.EdgeEastBottom); break; case OrientationFlags.SideNorth: player.SelectedPoint = new Vector2(1f - selectionPoint.Value.X, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner111, OrientationFlags.Corner011, OrientationFlags.Corner110, OrientationFlags.Corner010); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeNorthTop, OrientationFlags.EdgeNorthBottom, OrientationFlags.EdgeNorthEast, OrientationFlags.EdgeNorthWest); break; case OrientationFlags.SideSouth: player.SelectedPoint = new Vector2(selectionPoint.Value.X, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner001, OrientationFlags.Corner101, OrientationFlags.Corner000, OrientationFlags.Corner100); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeSouthTop, OrientationFlags.EdgeSouthBottom, OrientationFlags.EdgeSouthWest, OrientationFlags.EdgeSouthEast); break; } player.SelectedPoint = new Vector2( Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.X)), Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.Y))); } else { player.SelectedBox = null; player.SelectedPoint = null; player.SelectedSide = OrientationFlags.None; player.SelectedEdge = OrientationFlags.None; player.SelectedCorner = OrientationFlags.None; } base.OnUpdate(gameTime); }
/// <summary> /// Allocates a 3D buffer with the specified number of elements on this accelerator. /// </summary> /// <typeparam name="T">The element type.</typeparam> /// <param name="extent">The extent (number of elements to allocate).</param> /// <returns>An allocated 3D buffer on the this accelerator.</returns> public MemoryBuffer3D <T> Allocate <T>(Index3 extent) where T : struct { return(new MemoryBuffer3D <T>(Allocate <T, Index3>(extent))); }
public void CopyTo( AcceleratorStream stream, T[][][] target, Index3 sourceOffset, Index3 targetOffset, Index3 extent) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (sourceOffset.X < 0 || sourceOffset.Y < 0 || sourceOffset.Z < 0 || sourceOffset.X >= Extent.X || sourceOffset.Y >= Extent.Y || sourceOffset.Z >= Extent.Z) { throw new ArgumentOutOfRangeException(nameof(sourceOffset)); } if (targetOffset.X < 0 || targetOffset.Y < 0 || targetOffset.Z < 0 || targetOffset.X >= target.Length) { throw new ArgumentOutOfRangeException(nameof(targetOffset)); } if (extent.X < 0 || extent.Y < 0 || extent.Z < 0 || sourceOffset.X + extent.X > Extent.X || sourceOffset.Y + extent.Y > Extent.Y || sourceOffset.Z + extent.Z > Extent.Z || targetOffset.X + extent.X > target.Length) { throw new ArgumentOutOfRangeException(nameof(extent)); } var tempBuffer = new T[extent.Size]; buffer.CopyTo( stream, tempBuffer, sourceOffset, 0, extent); for (int i = 0; i < extent.X; ++i) { var subData = target[i + targetOffset.X]; if (subData == null) { continue; } for (int j = 0; j < extent.Y; ++j) { var subSubData = subData[j + targetOffset.Y]; if (subSubData == null) { continue; } for (int k = 0; k < extent.Z; ++k) { var sourceIdx = new Index3(i, j, k).ComputeLinearIndex(extent); subSubData[k + targetOffset.Z] = tempBuffer[sourceIdx]; } } } }
public void UpdateWalls(bool chain = false) { GameController gc = gameController; Index3 index = gc.PositionToIndex(transform.localPosition); Index3 northIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward); Index3 eastIndex = gc.PositionToIndex(transform.localPosition + Vector3.right); Index3 southIndex = gc.PositionToIndex(transform.localPosition + Vector3.back); Index3 westIndex = gc.PositionToIndex(transform.localPosition + Vector3.left); Index3 upIndex = gc.PositionToIndex(transform.localPosition + Vector3.up); Index3 downIndex = gc.PositionToIndex(transform.localPosition + Vector3.down); Index3 neIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.right); Index3 nwIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.left); Index3 ntIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.up); Index3 nbIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.down); Index3 seIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.right); Index3 swIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.left); Index3 stIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.up); Index3 sbIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.down); Index3 etIndex = gc.PositionToIndex(transform.localPosition + Vector3.right + Vector3.up); Index3 ebIndex = gc.PositionToIndex(transform.localPosition + Vector3.right + Vector3.down); Index3 wtIndex = gc.PositionToIndex(transform.localPosition + Vector3.left + Vector3.up); Index3 wbIndex = gc.PositionToIndex(transform.localPosition + Vector3.left + Vector3.down); Index3 netIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.right + Vector3.up); Index3 nebIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.right + Vector3.down); Index3 nwtIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.left + Vector3.up); Index3 nwbIndex = gc.PositionToIndex(transform.localPosition + Vector3.forward + Vector3.left + Vector3.down); Index3 setIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.right + Vector3.up); Index3 sebIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.right + Vector3.down); Index3 swtIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.left + Vector3.up); Index3 swbIndex = gc.PositionToIndex(transform.localPosition + Vector3.back + Vector3.left + Vector3.down); Block north = gc.GetBlock(northIndex); Block east = gc.GetBlock(eastIndex); Block south = gc.GetBlock(southIndex); Block west = gc.GetBlock(westIndex); Block up = gc.GetBlock(upIndex); Block down = gc.GetBlock(downIndex); Block ne = gc.GetBlock(neIndex); Block nw = gc.GetBlock(nwIndex); Block nt = gc.GetBlock(ntIndex); Block nb = gc.GetBlock(nbIndex); Block se = gc.GetBlock(seIndex); Block sw = gc.GetBlock(swIndex); Block st = gc.GetBlock(stIndex); Block sb = gc.GetBlock(sbIndex); Block et = gc.GetBlock(etIndex); Block eb = gc.GetBlock(ebIndex); Block wt = gc.GetBlock(wtIndex); Block wb = gc.GetBlock(wbIndex); Block net = gc.GetBlock(netIndex); Block neb = gc.GetBlock(nebIndex); Block nwt = gc.GetBlock(nwtIndex); Block nwb = gc.GetBlock(nwbIndex); Block set = gc.GetBlock(setIndex); Block seb = gc.GetBlock(sebIndex); Block swt = gc.GetBlock(swtIndex); Block swb = gc.GetBlock(swbIndex); northWalls ["Wall"].SetActive(north == null); northWalls ["Left"].SetActive(north != null && nw == null && west == null); northWalls ["Right"].SetActive(north != null && ne == null && east == null); northWalls ["Top"].SetActive(north != null && nt == null && up == null); northWalls ["Bottom"].SetActive(north != null && nb == null && down == null); northWalls ["JLeft"].SetActive(north != null && nw != null && west == null); northWalls ["JRight"].SetActive(north != null && ne != null && east == null); northWalls ["JTop"].SetActive(north != null && nt != null && up == null); northWalls ["JBottom"].SetActive(north != null && nb != null && down == null); northWalls ["TL"].SetActive(north != null && nw == null && west == null && nt == null && up == null); northWalls ["TR"].SetActive(north != null && ne == null && east == null && nt == null && up == null); northWalls ["BL"].SetActive(north != null && nw == null && west == null && nb == null && down == null); northWalls ["BR"].SetActive(north != null && ne == null && east == null && nb == null && down == null); northWalls ["CET"].SetActive(north == null && east != null && up != null); northWalls ["CEB"].SetActive(north == null && east != null && down != null); northWalls ["CWT"].SetActive(north == null && west != null && up != null); northWalls ["CWB"].SetActive(north == null && west != null && down != null); northWalls ["ET"].SetActive(north != null && ne != null); northWalls ["EB"].SetActive(north != null && ne != null); northWalls ["WT"].SetActive(north != null && nw != null); northWalls ["WB"].SetActive(north != null && nw != null); northWalls ["TE"].SetActive(north != null && nt != null); northWalls ["TW"].SetActive(north != null && nt != null); northWalls ["BE"].SetActive(north != null && nb != null); northWalls ["BW"].SetActive(north != null && nb != null); southWalls ["Wall"].SetActive(south == null); southWalls ["Left"].SetActive(south != null && se == null && east == null); southWalls ["Right"].SetActive(south != null && sw == null && west == null); southWalls ["Top"].SetActive(south != null && st == null && up == null); southWalls ["Bottom"].SetActive(south != null && sb == null && down == null); southWalls ["JLeft"].SetActive(south != null && se != null && east == null); southWalls ["JRight"].SetActive(south != null && sw != null && west == null); southWalls ["JTop"].SetActive(south != null && st != null && up == null); southWalls ["JBottom"].SetActive(south != null && sb != null && down == null); southWalls ["TL"].SetActive(south != null && se == null && east == null && st == null && up == null); southWalls ["TR"].SetActive(south != null && sw == null && west == null && st == null && up == null); southWalls ["BL"].SetActive(south != null && se == null && east == null && sb == null && down == null); southWalls ["BR"].SetActive(south != null && sw == null && west == null && sb == null && down == null); southWalls ["CET"].SetActive(south == null && east != null && up != null); southWalls ["CEB"].SetActive(south == null && east != null && down != null); southWalls ["CWT"].SetActive(south == null && west != null && up != null); southWalls ["CWB"].SetActive(south == null && west != null && down != null); southWalls ["ET"].SetActive(south != null && se != null); southWalls ["EB"].SetActive(south != null && se != null); southWalls ["WT"].SetActive(south != null && sw != null); southWalls ["WB"].SetActive(south != null && sw != null); southWalls ["TE"].SetActive(south != null && st != null); southWalls ["TW"].SetActive(south != null && st != null); southWalls ["BE"].SetActive(south != null && sb != null); southWalls ["BW"].SetActive(south != null && sb != null); eastWalls ["Wall"].SetActive(east == null); eastWalls ["Left"].SetActive(east != null && ne == null && north == null); eastWalls ["Right"].SetActive(east != null && se == null && south == null); eastWalls ["Top"].SetActive(east != null && et == null && up == null); eastWalls ["Bottom"].SetActive(east != null && eb == null && down == null); eastWalls ["JLeft"].SetActive(east != null && ne != null && north == null); eastWalls ["JRight"].SetActive(east != null && se != null && south == null); eastWalls ["JTop"].SetActive(east != null && et != null && up == null); eastWalls ["JBottom"].SetActive(east != null && eb != null && down == null); eastWalls ["TL"].SetActive(east != null && ne == null && north == null && et == null && up == null); eastWalls ["TR"].SetActive(east != null && se == null && south == null && et == null && up == null); eastWalls ["BL"].SetActive(east != null && ne == null && north == null && eb == null && down == null); eastWalls ["BR"].SetActive(east != null && se == null && south == null && eb == null && down == null); eastWalls ["CNT"].SetActive(east == null && north != null && up != null); eastWalls ["CNB"].SetActive(east == null && north != null && down != null); eastWalls ["CST"].SetActive(east == null && south != null && up != null); eastWalls ["CSB"].SetActive(east == null && south != null && down != null); eastWalls ["NT"].SetActive(east != null && ne != null); eastWalls ["NB"].SetActive(east != null && ne != null); eastWalls ["ST"].SetActive(east != null && se != null); eastWalls ["SB"].SetActive(east != null && se != null); eastWalls ["TN"].SetActive(east != null && et != null); eastWalls ["TS"].SetActive(east != null && et != null); eastWalls ["BN"].SetActive(east != null && eb != null); eastWalls ["BS"].SetActive(east != null && eb != null); westWalls ["Wall"].SetActive(west == null); westWalls ["Left"].SetActive(west != null && sw == null && south == null); westWalls ["Right"].SetActive(west != null && nw == null && north == null); westWalls ["Top"].SetActive(west != null && wt == null && up == null); westWalls ["Bottom"].SetActive(west != null && wb == null && down == null); westWalls ["JLeft"].SetActive(west != null && sw != null && south == null); westWalls ["JRight"].SetActive(west != null && nw != null && north == null); westWalls ["JTop"].SetActive(west != null && wt != null && up == null); westWalls ["JBottom"].SetActive(west != null && wb != null && down == null); westWalls ["TL"].SetActive(west != null && sw == null && south == null && wt == null && up == null); westWalls ["TR"].SetActive(west != null && nw == null && north == null && wt == null && up == null); westWalls ["BL"].SetActive(west != null && sw == null && south == null && wb == null && down == null); westWalls ["BR"].SetActive(west != null && nw == null && north == null && wb == null && down == null); westWalls ["CNT"].SetActive(west == null && north != null && up != null); westWalls ["CNB"].SetActive(west == null && north != null && down != null); westWalls ["CST"].SetActive(west == null && south != null && up != null); westWalls ["CSB"].SetActive(west == null && south != null && down != null); westWalls ["NT"].SetActive(west != null && nw != null); westWalls ["NB"].SetActive(west != null && nw != null); westWalls ["ST"].SetActive(west != null && sw != null); westWalls ["SB"].SetActive(west != null && sw != null); westWalls ["TN"].SetActive(west != null && wt != null); westWalls ["TS"].SetActive(west != null && wt != null); westWalls ["BN"].SetActive(west != null && wb != null); westWalls ["BS"].SetActive(west != null && wb != null); upWalls ["Wall"].SetActive(up == null); upWalls ["North"].SetActive(up != null && nt == null && north == null); upWalls ["South"].SetActive(up != null && st == null && south == null); upWalls ["East"].SetActive(up != null && et == null && east == null); upWalls ["West"].SetActive(up != null && wt == null && west == null); upWalls ["JNorth"].SetActive(up != null && nt != null && north == null); upWalls ["JSouth"].SetActive(up != null && st != null && south == null); upWalls ["JEast"].SetActive(up != null && et != null && east == null); upWalls ["JWest"].SetActive(up != null && wt != null && west == null); upWalls ["NE"].SetActive(up != null && north == null && east == null && nt == null && et == null); upWalls ["NW"].SetActive(up != null && north == null && west == null && nt == null && wt == null); upWalls ["SE"].SetActive(up != null && south == null && east == null && st == null && et == null); upWalls ["SW"].SetActive(up != null && south == null && west == null && st == null && wt == null); upWalls ["CNE"].SetActive(up == null && north != null && east != null); upWalls ["CNW"].SetActive(up == null && north != null && west != null); upWalls ["CSE"].SetActive(up == null && south != null && east != null); upWalls ["CSW"].SetActive(up == null && south != null && west != null); upWalls ["TNE"].SetActive(up != null && nt != null); upWalls ["TNW"].SetActive(up != null && nt != null); upWalls ["TSE"].SetActive(up != null && st != null); upWalls ["TSW"].SetActive(up != null && st != null); upWalls ["TEN"].SetActive(up != null && et != null); upWalls ["TES"].SetActive(up != null && et != null); upWalls ["TWN"].SetActive(up != null && wt != null); upWalls ["TWS"].SetActive(up != null && wt != null); downWalls ["Wall"].SetActive(down == null); downWalls ["North"].SetActive(down != null && nb == null && north == null); downWalls ["South"].SetActive(down != null && sb == null && south == null); downWalls ["East"].SetActive(down != null && eb == null && east == null); downWalls ["West"].SetActive(down != null && wb == null && west == null); downWalls ["JNorth"].SetActive(down != null && nb != null && north == null); downWalls ["JSouth"].SetActive(down != null && sb != null && south == null); downWalls ["JEast"].SetActive(down != null && eb != null && east == null); downWalls ["JWest"].SetActive(down != null && wb != null && west == null); downWalls ["NE"].SetActive(down != null && north == null && east == null && nb == null && eb == null); downWalls ["NW"].SetActive(down != null && north == null && west == null && nb == null && wb == null); downWalls ["SE"].SetActive(down != null && south == null && east == null && sb == null && eb == null); downWalls ["SW"].SetActive(down != null && south == null && west == null && sb == null && wb == null); downWalls ["CNE"].SetActive(down == null && north != null && east != null); downWalls ["CNW"].SetActive(down == null && north != null && west != null); downWalls ["CSE"].SetActive(down == null && south != null && east != null); downWalls ["CSW"].SetActive(down == null && south != null && west != null); downWalls ["BNE"].SetActive(down != null && nb != null); downWalls ["BNW"].SetActive(down != null && nb != null); downWalls ["BSE"].SetActive(down != null && sb != null); downWalls ["BSW"].SetActive(down != null && sb != null); downWalls ["BEN"].SetActive(down != null && eb != null); downWalls ["BES"].SetActive(down != null && eb != null); downWalls ["BWN"].SetActive(down != null && wb != null); downWalls ["BWS"].SetActive(down != null && wb != null); walls ["NE"].SetActive(north == null && east == null); walls ["NW"].SetActive(north == null && west == null); walls ["SE"].SetActive(south == null && east == null); walls ["SW"].SetActive(south == null && west == null); walls ["NT"].SetActive(north == null && up == null); walls ["NB"].SetActive(north == null && down == null); walls ["ST"].SetActive(south == null && up == null); walls ["SB"].SetActive(south == null && down == null); walls ["ET"].SetActive(east == null && up == null); walls ["EB"].SetActive(east == null && down == null); walls ["WT"].SetActive(west == null && up == null); walls ["WB"].SetActive(west == null && down == null); walls ["NET"].SetActive(north == null && east == null && up == null); walls ["NEB"].SetActive(north == null && east == null && down == null); walls ["NWT"].SetActive(north == null && west == null && up == null); walls ["NWB"].SetActive(north == null && west == null && down == null); walls ["SET"].SetActive(south == null && east == null && up == null); walls ["SEB"].SetActive(south == null && east == null && down == null); walls ["SWT"].SetActive(south == null && west == null && up == null); walls ["SWB"].SetActive(south == null && west == null && down == null); if (chain) { if (north != null) { north.UpdateWalls(); } if (south != null) { south.UpdateWalls(); } if (east != null) { east.UpdateWalls(); } if (west != null) { west.UpdateWalls(); } if (up != null) { up.UpdateWalls(); } if (down != null) { down.UpdateWalls(); } if (ne != null) { ne.UpdateWalls(); } if (nw != null) { nw.UpdateWalls(); } if (nt != null) { nt.UpdateWalls(); } if (nb != null) { nb.UpdateWalls(); } if (se != null) { se.UpdateWalls(); } if (sw != null) { sw.UpdateWalls(); } if (st != null) { st.UpdateWalls(); } if (sb != null) { sb.UpdateWalls(); } if (et != null) { et.UpdateWalls(); } if (eb != null) { eb.UpdateWalls(); } if (wt != null) { wt.UpdateWalls(); } if (wb != null) { wb.UpdateWalls(); } if (net != null) { net.UpdateWalls(); } if (neb != null) { neb.UpdateWalls(); } if (nwt != null) { nwt.UpdateWalls(); } if (nwb != null) { nwb.UpdateWalls(); } if (set != null) { set.UpdateWalls(); } if (seb != null) { seb.UpdateWalls(); } if (swt != null) { swt.UpdateWalls(); } if (swb != null) { swb.UpdateWalls(); } } }
public void Index3NormaizeMethodenTest() { Index3 i1 = new Index3(20, 20, 20); // Startwert Index2 i2 = new Index2(12, 13); // 2D-Size Index3 i2b = new Index3(12, 13, 14); // 3D-Size Index3 ix = new Index3(8, 20, 20); // Ergebnis bei NormX Index3 iy = new Index3(20, 7, 20); // Ergebnis bei NormY Index3 iz = new Index3(20, 20, 6); // Ergebnis bei NormZ Index3 ixy = new Index3(8, 7, 20); // Ergebnis bei NormXY Index3 ixyz = new Index3(8, 7, 6); // Ergebnis bei NormXYZ // Norm X (int) Index3 t = i1; t.NormalizeX(i2.X); Assert.Equal(ix, t); // Norm X (index2) t = i1; t.NormalizeX(i2); Assert.Equal(ix, t); // Norm X (index3) t = i1; t.NormalizeX(i2b); Assert.Equal(ix, t); // Norm Y (int) t = i1; t.NormalizeY(i2.Y); Assert.Equal(iy, t); // Norm Y (index2) t = i1; t.NormalizeY(i2); Assert.Equal(iy, t); // Norm Y (index3) t = i1; t.NormalizeY(i2b); Assert.Equal(iy, t); // Norm Z (int) t = i1; t.NormalizeZ(i2b.Z); Assert.Equal(iz, t); // Norm Z (index3) t = i1; t.NormalizeZ(i2b); Assert.Equal(iz, t); // Norm XY (int) t = i1; t.NormalizeXY(i2.X, i2.Y); Assert.Equal(ixy, t); // Norm XY (index2) t = i1; t.NormalizeXY(i2); Assert.Equal(ixy, t); // Norm XY (index3) t = i1; t.NormalizeXY(i2b); Assert.Equal(ixy, t); // Norm XYZ (int) t = i1; t.NormalizeXYZ(i2.X, i2.Y, i2b.Z); Assert.Equal(ixyz, t); // Norm XYZ (index3) t = i1; t.NormalizeXYZ(i2b); Assert.Equal(ixyz, t); }
public void InstanceKernel(Index3 index, ArrayView <int> output, Index3 extent) { var linearIndex = index.ComputeLinearIndex(extent); output[linearIndex] = NestedFunction(linearIndex); }
/// <summary> /// Aktualisiert den Spieler (Bewegung, Interaktion) /// </summary> /// <param name="frameTime">Die aktuelle Zeit.</param> public void Update(GameTime frameTime) { #region Inputverarbeitung // Input verarbeiten Player.Angle += (float)frameTime.ElapsedGameTime.TotalSeconds * Head.X; Player.Tilt += (float)frameTime.ElapsedGameTime.TotalSeconds * Head.Y; Player.Tilt = Math.Min(1.5f, Math.Max(-1.5f, Player.Tilt)); #endregion #region Physik float lookX = (float)Math.Cos(Player.Angle); float lookY = -(float)Math.Sin(Player.Angle); var velocitydirection = new Vector3(lookX, lookY, 0) * Move.Y; float stafeX = (float)Math.Cos(Player.Angle + MathHelper.PiOver2); float stafeY = -(float)Math.Sin(Player.Angle + MathHelper.PiOver2); velocitydirection += new Vector3(stafeX, stafeY, 0) * Move.X; Player.Velocity += PhysicalUpdate(velocitydirection, frameTime.ElapsedGameTime, !Player.FlyMode, Player.FlyMode); #endregion #region Playerbewegung /Kollision Vector3 move = Player.Velocity * (float)frameTime.ElapsedGameTime.TotalSeconds; Player.OnGround = false; //Blocks finden die eine Kollision verursachen könnten int minx = (int)Math.Floor(Math.Min( Player.Position.BlockPosition.X - Player.Radius, Player.Position.BlockPosition.X - Player.Radius + move.X)); int maxx = (int)Math.Ceiling(Math.Max( Player.Position.BlockPosition.X + Player.Radius, Player.Position.BlockPosition.X + Player.Radius + move.X)); int miny = (int)Math.Floor(Math.Min( Player.Position.BlockPosition.Y - Player.Radius, Player.Position.BlockPosition.Y - Player.Radius + move.Y)); int maxy = (int)Math.Ceiling(Math.Max( Player.Position.BlockPosition.Y + Player.Radius, Player.Position.BlockPosition.Y + Player.Radius + move.Y)); int minz = (int)Math.Floor(Math.Min( Player.Position.BlockPosition.Z, Player.Position.BlockPosition.Z + move.Z)); int maxz = (int)Math.Ceiling(Math.Max( Player.Position.BlockPosition.Z + Player.Height, Player.Position.BlockPosition.Z + Player.Height + move.Z)); //Beteiligte Flächen des Spielers var playerplanes = CollisionPlane.GetPlayerCollisionPlanes(Player).ToList(); bool abort = false; for (int z = minz; z <= maxz && !abort; z++) { for (int y = miny; y <= maxy && !abort; y++) { for (int x = minx; x <= maxx && !abort; x++) { move = Player.Velocity * (float)frameTime.ElapsedGameTime.TotalSeconds; Index3 pos = new Index3(x, y, z); Index3 blockPos = pos + Player.Position.GlobalBlockIndex; ushort block = localChunkCache.GetBlock(blockPos); if (block == 0) { continue; } var blockplane = CollisionPlane.GetBlockCollisionPlanes(pos, Player.Velocity).ToList(); var planes = from pp in playerplanes from bp in blockplane where CollisionPlane.Intersect(bp, pp) let distance = CollisionPlane.GetDistance(bp, pp) where CollisionPlane.CheckDistance(distance, move) select new { BlockPlane = bp, PlayerPlane = pp, Distance = distance }; foreach (var plane in planes) { var subvelocity = (plane.Distance / (float)frameTime.ElapsedGameTime.TotalSeconds); var diff = Player.Velocity - subvelocity; float vx; float vy; float vz; if (plane.BlockPlane.normal.X != 0 && (Player.Velocity.X > 0 && diff.X >= 0 && subvelocity.X >= 0 || Player.Velocity.X < 0 && diff.X <= 0 && subvelocity.X <= 0)) { vx = subvelocity.X; } else { vx = Player.Velocity.X; } if (plane.BlockPlane.normal.Y != 0 && (Player.Velocity.Y > 0 && diff.Y >= 0 && subvelocity.Y >= 0 || Player.Velocity.Y < 0 && diff.Y <= 0 && subvelocity.Y <= 0)) { vy = subvelocity.Y; } else { vy = Player.Velocity.Y; } if (plane.BlockPlane.normal.Z != 0 && (Player.Velocity.Z > 0 && diff.Z >= 0 && subvelocity.Z >= 0 || Player.Velocity.Z < 0 && diff.Z <= 0 && subvelocity.Z <= 0)) { vz = subvelocity.Z; } else { vz = Player.Velocity.Z; } Player.Velocity = new Vector3(vx, vy, vz); if (vx == 0 && vy == 0 && vz == 0) { abort = true; break; } } } } } // TODO: Was ist für den Fall Gravitation = 0 oder im Scheitelpunkt des Sprungs? Player.OnGround = Player.Velocity.Z == 0f; Coordinate position = Player.Position + Player.Velocity * (float)frameTime.ElapsedGameTime.TotalSeconds; position.NormalizeChunkIndexXY(planet.Size); Player.Position = position; //Beam me up KeyboardState ks = Keyboard.GetState(); if (ks.IsKeyDown(Keys.P)) { Player.Position += new Vector3(0, 0, 10); } if (Player.Position.ChunkIndex != _oldIndex) { _oldIndex = Player.Position.ChunkIndex; ReadyState = false; localChunkCache.SetCenter(planet, new Index2(Player.Position.ChunkIndex), (success) => { ReadyState = success; }); } #endregion #region Block Interaction if (lastInteract.HasValue) { ushort lastBlock = localChunkCache.GetBlock(lastInteract.Value); localChunkCache.SetBlock(lastInteract.Value, 0); if (lastBlock != 0) { var blockDefinition = DefinitionManager.Instance.GetBlockDefinitionByIndex(lastBlock); var slot = Player.Inventory.Where(s => s.Definition == blockDefinition && s.Amount < blockDefinition.StackLimit).FirstOrDefault(); // Wenn noch kein Slot da ist oder der vorhandene voll, dann neuen Slot if (slot == null || slot.Amount >= blockDefinition.StackLimit) { slot = new InventorySlot() { Definition = blockDefinition, Amount = 0 }; Player.Inventory.Add(slot); } slot.Amount++; } lastInteract = null; } if (lastApply.HasValue) { if (ActiveTool != null) { Index3 add = new Index3(); switch (lastOrientation) { case OrientationFlags.SideWest: add = new Index3(-1, 0, 0); break; case OrientationFlags.SideEast: add = new Index3(1, 0, 0); break; case OrientationFlags.SideSouth: add = new Index3(0, -1, 0); break; case OrientationFlags.SideNorth: add = new Index3(0, 1, 0); break; case OrientationFlags.SideBottom: add = new Index3(0, 0, -1); break; case OrientationFlags.SideTop: add = new Index3(0, 0, 1); break; } if (ActiveTool.Definition is IBlockDefinition) { IBlockDefinition definition = ActiveTool.Definition as IBlockDefinition; Index3 idx = lastApply.Value + add; var boxes = definition.GetCollisionBoxes(localChunkCache, idx.X, idx.Y, idx.Z); float gap = 0.01f; var playerBox = new BoundingBox( new Vector3( Player.Position.GlobalBlockIndex.X + Player.Position.BlockPosition.X - Player.Radius + gap, Player.Position.GlobalBlockIndex.Y + Player.Position.BlockPosition.Y - Player.Radius + gap, Player.Position.GlobalBlockIndex.Z + Player.Position.BlockPosition.Z + gap), new Vector3( Player.Position.GlobalBlockIndex.X + Player.Position.BlockPosition.X + Player.Radius - gap, Player.Position.GlobalBlockIndex.Y + Player.Position.BlockPosition.Y + Player.Radius - gap, Player.Position.GlobalBlockIndex.Z + Player.Position.BlockPosition.Z + Player.Height - gap) ); // Nicht in sich selbst reinbauen bool intersects = false; foreach (var box in boxes) { var newBox = new BoundingBox(idx + box.Min, idx + box.Max); if (newBox.Intersects(playerBox)) { intersects = true; } } if (!intersects) { localChunkCache.SetBlock(idx, DefinitionManager.Instance.GetBlockDefinitionIndex(definition)); ActiveTool.Amount--; if (ActiveTool.Amount <= 0) { Player.Inventory.Remove(ActiveTool); ActiveTool = null; } } } // TODO: Fix Interaction ;) //ushort block = _manager.GetBlock(lastApply.Value); //IBlockDefinition blockDefinition = BlockDefinitionManager.GetForType(block); //IItemDefinition itemDefinition = ActiveTool.Definition; //blockDefinition.Hit(blockDefinition, itemDefinition.GetProperties(null)); //itemDefinition.Hit(null, blockDefinition.GetProperties(block)); } lastApply = null; } #endregion }
public override void Update(GameTime gameTime) { Index3 centerblock = player.Player.Position.GlobalBlockIndex; Index3 renderOffset = player.Player.Position.ChunkIndex * Chunk.CHUNKSIZE; Index3? selected = null; Axis? selectedAxis = null; Vector3? selectionPoint = null; float bestDistance = 9999; for (int z = -Player.SELECTIONRANGE; z < Player.SELECTIONRANGE; z++) { for (int y = -Player.SELECTIONRANGE; y < Player.SELECTIONRANGE; y++) { for (int x = -Player.SELECTIONRANGE; x < Player.SELECTIONRANGE; x++) { Index3 range = new Index3(x, y, z); Index3 pos = range + centerblock; IBlock block = GetBlock(player.Player.Position.Planet, pos); if (block == null) continue; Axis? collisionAxis; float? distance = block.Intersect(pos - renderOffset, camera.PickRay, out collisionAxis); if (distance.HasValue && distance.Value < bestDistance) { pos.NormalizeXY(planet.Size * Chunk.CHUNKSIZE); selected = pos; selectedAxis = collisionAxis; bestDistance = distance.Value; selectionPoint = (camera.PickRay.Position + (camera.PickRay.Direction * distance)) - (selected - renderOffset); } } } } if (selected.HasValue) { player.SelectedBox = selected; switch (selectedAxis) { case Axis.X: player.SelectedSide = (camera.PickRay.Direction.X > 0 ? OrientationFlags.SideWest : OrientationFlags.SideEast); break; case Axis.Y: player.SelectedSide = (camera.PickRay.Direction.Y > 0 ? OrientationFlags.SideSouth : OrientationFlags.SideNorth); break; case Axis.Z: player.SelectedSide = (camera.PickRay.Direction.Z > 0 ? OrientationFlags.SideBottom : OrientationFlags.SideTop); break; } player.SelectedPoint = new Vector2(); switch (player.SelectedSide) { case OrientationFlags.SideWest: player.SelectedPoint = new Vector2(1f - selectionPoint.Value.Y, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner011, OrientationFlags.Corner001, OrientationFlags.Corner010, OrientationFlags.Corner000); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeWestTop, OrientationFlags.EdgeWestBottom, OrientationFlags.EdgeNorthWest, OrientationFlags.EdgeSouthWest); break; case OrientationFlags.SideEast: player.SelectedPoint = new Vector2(selectionPoint.Value.Y, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner101, OrientationFlags.Corner111, OrientationFlags.Corner100, OrientationFlags.Corner110); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeEastTop, OrientationFlags.EdgeEastBottom, OrientationFlags.EdgeSouthEast, OrientationFlags.EdgeNorthEast); break; case OrientationFlags.SideTop: player.SelectedPoint = new Vector2(selectionPoint.Value.X, 1f - selectionPoint.Value.Y); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner011, OrientationFlags.Corner111, OrientationFlags.Corner001, OrientationFlags.Corner101); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeNorthTop, OrientationFlags.EdgeSouthTop, OrientationFlags.EdgeWestTop, OrientationFlags.EdgeEastTop); break; case OrientationFlags.SideBottom: player.SelectedPoint = new Vector2(selectionPoint.Value.X, selectionPoint.Value.Y); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner000, OrientationFlags.Corner100, OrientationFlags.Corner010, OrientationFlags.Corner110); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeSouthBottom, OrientationFlags.EdgeNorthBottom, OrientationFlags.EdgeWestBottom, OrientationFlags.EdgeEastBottom); break; case OrientationFlags.SideNorth: player.SelectedPoint = new Vector2(1f - selectionPoint.Value.X, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner111, OrientationFlags.Corner011, OrientationFlags.Corner110, OrientationFlags.Corner010); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeNorthTop, OrientationFlags.EdgeNorthBottom, OrientationFlags.EdgeNorthEast, OrientationFlags.EdgeNorthWest); break; case OrientationFlags.SideSouth: player.SelectedPoint = new Vector2(selectionPoint.Value.X, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner001, OrientationFlags.Corner101, OrientationFlags.Corner000, OrientationFlags.Corner100); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeSouthTop, OrientationFlags.EdgeSouthBottom, OrientationFlags.EdgeSouthWest, OrientationFlags.EdgeSouthEast); break; } player.SelectedPoint = new Vector2( Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.X)), Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.Y))); } else { player.SelectedBox = null; player.SelectedPoint = null; player.SelectedSide = OrientationFlags.None; player.SelectedEdge = OrientationFlags.None; player.SelectedCorner = OrientationFlags.None; } base.Update(gameTime); }
/// <summary> /// Setzt einen neuen Block. /// </summary> /// <param name="blockIndex"></param> /// <param name="orientation"></param> public void Apply(Index3 blockIndex, OrientationFlags orientation) { lastApply = blockIndex; lastOrientation = orientation; }
/// <summary> /// Returns a 3D view to this linear buffer. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The 3D view.</returns> public ArrayView3D <T> As3DView(Index3 extent) => View.As3DView(extent);
/// <summary> /// Setups all required settings. /// </summary> private void SetupAccelerator() { Bind(); CudaException.ThrowIfFailed( CurrentAPI.GetDeviceName(out string name, DeviceId)); Name = name; DefaultStream = new CudaStream(this, IntPtr.Zero); CudaException.ThrowIfFailed( CurrentAPI.GetTotalDeviceMemory(out long total, DeviceId)); MemorySize = total; // Resolve max grid size MaxGridSize = new Index3( CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X, DeviceId), CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y, DeviceId), CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z, DeviceId)); // Resolve max group size MaxGroupSize = new Index3( CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, DeviceId), CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y, DeviceId), CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z, DeviceId)); // Resolve max threads per group MaxNumThreadsPerGroup = CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, DeviceId); // Resolve max shared memory per block MaxSharedMemoryPerGroup = CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK, DeviceId); // Resolve total constant memory MaxConstantMemory = CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY, DeviceId); // Resolve clock rate ClockRate = CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_CLOCK_RATE, DeviceId); // Resolve warp size WarpSize = CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_WARP_SIZE, DeviceId); // Resolve number of multiprocessors NumMultiprocessors = CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, DeviceId); // Result max number of threads per multiprocessor MaxNumThreadsPerMultiprocessor = CurrentAPI.GetDeviceAttribute( DeviceAttribute.CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR, DeviceId); // Resolve cache configuration CudaException.ThrowIfFailed( CurrentAPI.GetSharedMemoryConfig(out sharedMemoryConfiguration)); CudaException.ThrowIfFailed( CurrentAPI.GetCacheConfig(out cacheConfiguration)); // Setup architecture and backend CudaException.ThrowIfFailed( CurrentAPI.GetDeviceComputeCapability(out int major, out int minor, DeviceId)); Architecture = PTXArchitectureUtils.GetArchitecture(major, minor); CudaException.ThrowIfFailed( CurrentAPI.GetDriverVersion(out var driverVersion)); InstructionSet = GetInstructionSet(Architecture, driverVersion); base.Backend = new PTXBackend(Context, Architecture, InstructionSet, Backends.Backend.OSPlatform); }
private IChunk loadChunk(Index3 index) { return ResourceManager.Instance.GetChunk(player.Player.Position.Planet, index); }
private bool FillChunkRenderer() { if (player.ActorHost == null) { return(false); } Index2 destinationChunk = new Index2(player.ActorHost.Position.ChunkIndex); // Nur ausführen wenn der Spieler den Chunk gewechselt hat if (destinationChunk != currentChunk) { localChunkCache.SetCenter(planet, new Index2(player.ActorHost.Position.ChunkIndex)); int mask = (int)Math.Pow(2, VIEWRANGE) - 1; int span = (int)Math.Pow(2, VIEWRANGE); int spanOver2 = span >> 1; for (int x = 0; x < span; x++) { for (int y = 0; y < span; y++) { Index2 local = new Index2(x - spanOver2, y - spanOver2) + destinationChunk; local.NormalizeXY(planet.Size); int virtualX = local.X & mask; int virtualY = local.Y & mask; int rendererIndex = virtualX + (virtualY << VIEWRANGE); for (int z = 0; z < planet.Size.Z; z++) { chunkRenderer[rendererIndex, z].SetChunk(localChunkCache, local.X, local.Y, z); } } } Index3 comparationIndex = player.ActorHost.Position.ChunkIndex; orderedChunkRenderer.Sort((x, y) => { if (!x.ChunkPosition.HasValue) { return(1); } if (!y.ChunkPosition.HasValue) { return(-1); } Index3 distX = comparationIndex.ShortestDistanceXYZ(x.ChunkPosition.Value, planet.Size); Index3 distY = comparationIndex.ShortestDistanceXYZ(y.ChunkPosition.Value, planet.Size); return(distX.LengthSquared().CompareTo(distY.LengthSquared())); }); currentChunk = destinationChunk; } foreach (var renderer in orderedChunkRenderer) { if (!renderer.NeedUpdate()) { continue; } renderer.RegenerateVertexBuffer(); return(true); } return(false); }
internal static void Copy3DKernel(Index3 index, ArrayView<long, Index3> data) { data[index] -= 5; }
protected override void OnPreDraw(GameTime gameTime) { if (player.ActorHost == null) { return; } if (ControlTexture == null) { ControlTexture = new RenderTarget2D(Manager.GraphicsDevice, ActualClientArea.Width, ActualClientArea.Height, PixelInternalFormat.Rgb8); } float octoDaysPerEarthDay = 360f; float inclinationVariance = MathHelper.Pi / 3f; float playerPosX = ((float)player.ActorHost.Player.Position.GlobalPosition.X / (planet.Size.X * Chunk.CHUNKSIZE_X)) * MathHelper.TwoPi; float playerPosY = ((float)player.ActorHost.Player.Position.GlobalPosition.Y / (planet.Size.Y * Chunk.CHUNKSIZE_Y)) * MathHelper.TwoPi; TimeSpan diff = DateTime.UtcNow - new DateTime(1888, 8, 8); float inclination = ((float)Math.Sin(playerPosY) * inclinationVariance) + MathHelper.Pi / 6f; //Console.WriteLine("Stand: " + (MathHelper.Pi + playerPosX) + " Neigung: " + inclination); Matrix sunMovement = Matrix.CreateRotationX(inclination) * //Matrix.CreateRotationY((((float)gameTime.TotalGameTime.TotalMinutes * MathHelper.TwoPi) + playerPosX) * -1); Matrix.CreateRotationY((float)(MathHelper.TwoPi - ((diff.TotalDays * octoDaysPerEarthDay * MathHelper.TwoPi) % MathHelper.TwoPi))); Vector3 sunDirection = Vector3.Transform(new Vector3(0, 0, 1), sunMovement); simpleShader.Parameters["DiffuseColor"].SetValue(new Color(190, 190, 190)); simpleShader.Parameters["DiffuseIntensity"].SetValue(0.6f); simpleShader.Parameters["DiffuseDirection"].SetValue(sunDirection); // Console.WriteLine(sunDirection); // Index3 chunkOffset = player.ActorHost.Position.ChunkIndex; Index3 chunkOffset = camera.CameraChunk; Color background = new Color(181, 224, 255); Manager.GraphicsDevice.SetRenderTarget(MiniMapTexture); Manager.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Manager.GraphicsDevice.Clear(background); foreach (var renderer in chunkRenderer) { if (!renderer.ChunkPosition.HasValue) { continue; } Index3 shift = chunkOffset.ShortestDistanceXY( renderer.ChunkPosition.Value, new Index2( planet.Size.X, planet.Size.Y)); BoundingBox chunkBox = new BoundingBox( new Vector3( shift.X * Chunk.CHUNKSIZE_X, shift.Y * Chunk.CHUNKSIZE_Y, shift.Z * Chunk.CHUNKSIZE_Z), new Vector3( (shift.X + 1) * Chunk.CHUNKSIZE_X, (shift.Y + 1) * Chunk.CHUNKSIZE_Y, (shift.Z + 1) * Chunk.CHUNKSIZE_Z)); int range = 3; if (shift.X >= -range && shift.X <= range && shift.Y >= -range && shift.Y <= range) { renderer.Draw(camera.MinimapView, miniMapProjectionMatrix, shift); } } Manager.GraphicsDevice.SetRenderTarget(ControlTexture); Manager.GraphicsDevice.Clear(background); Manager.GraphicsDevice.BlendState = BlendState.AlphaBlend; Manager.GraphicsDevice.DepthStencilState = DepthStencilState.None; // Draw Sun // GraphicsDevice.RasterizerState = RasterizerState.CullNone; sunEffect.Texture = sunTexture; Matrix billboard = Matrix.Invert(camera.View); billboard.Translation = player.ActorHost.Position.LocalPosition + (sunDirection * -10); sunEffect.World = billboard; sunEffect.View = camera.View; sunEffect.Projection = camera.Projection; sunEffect.CurrentTechnique.Passes[0].Apply(); Manager.GraphicsDevice.VertexBuffer = billboardVertexbuffer; Manager.GraphicsDevice.DrawPrimitives(PrimitiveType.Triangles, 0, 2); Manager.GraphicsDevice.DepthStencilState = DepthStencilState.Default; foreach (var renderer in chunkRenderer) { if (!renderer.ChunkPosition.HasValue) { continue; } Index3 shift = chunkOffset.ShortestDistanceXY( renderer.ChunkPosition.Value, new Index2( planet.Size.X, planet.Size.Y)); BoundingBox chunkBox = new BoundingBox( new Vector3( shift.X * Chunk.CHUNKSIZE_X, shift.Y * Chunk.CHUNKSIZE_Y, shift.Z * Chunk.CHUNKSIZE_Z), new Vector3( (shift.X + 1) * Chunk.CHUNKSIZE_X, (shift.Y + 1) * Chunk.CHUNKSIZE_Y, (shift.Z + 1) * Chunk.CHUNKSIZE_Z)); if (camera.Frustum.Intersects(chunkBox)) { renderer.Draw(camera.View, camera.Projection, shift); } } if (player.SelectedBox.HasValue) { // Index3 offset = player.ActorHost.Position.ChunkIndex * Chunk.CHUNKSIZE; Index3 offset = camera.CameraChunk * Chunk.CHUNKSIZE; Index3 planetSize = planet.Size * Chunk.CHUNKSIZE; Index3 relativePosition = new Index3( Index2.ShortestDistanceOnAxis(offset.X, player.SelectedBox.Value.X, planetSize.X), Index2.ShortestDistanceOnAxis(offset.Y, player.SelectedBox.Value.Y, planetSize.Y), player.SelectedBox.Value.Z - offset.Z); Vector3 selectedBoxPosition = new Vector3( player.SelectedBox.Value.X - (chunkOffset.X * Chunk.CHUNKSIZE_X), player.SelectedBox.Value.Y - (chunkOffset.Y * Chunk.CHUNKSIZE_Y), player.SelectedBox.Value.Z - (chunkOffset.Z * Chunk.CHUNKSIZE_Z)); // selectionEffect.World = Matrix.CreateTranslation(selectedBoxPosition); selectionEffect.World = Matrix.CreateTranslation(relativePosition); selectionEffect.View = camera.View; selectionEffect.Projection = camera.Projection; Manager.GraphicsDevice.VertexBuffer = selectionLines; Manager.GraphicsDevice.IndexBuffer = selectionIndexBuffer; foreach (var pass in selectionEffect.CurrentTechnique.Passes) { pass.Apply(); Manager.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.Lines, 0, 0, 8, 0, 12); //Manager.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.Lines, selectionLines, 0, 8, selectionIndeces, 0, 12); } } Manager.GraphicsDevice.SetRenderTarget(null); }
public void CopyFrom( AcceleratorStream stream, T[][][] source, Index3 sourceOffset, Index3 targetOffset, Index3 extent) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (sourceOffset.X < 0 || sourceOffset.Y < 0 || sourceOffset.Z < 0 || sourceOffset.X >= source.Length) { throw new ArgumentOutOfRangeException(nameof(sourceOffset)); } if (targetOffset.X < 0 || targetOffset.Y < 0 || targetOffset.Z < 0 || targetOffset.X >= Extent.X || targetOffset.Y >= Extent.Y || targetOffset.Z >= Extent.Z) { throw new ArgumentOutOfRangeException(nameof(targetOffset)); } if (extent.X < 0 || extent.Y < 0 || extent.Z < 0 || sourceOffset.X + extent.X > source.Length || targetOffset.X + extent.X > Extent.X || targetOffset.Y + extent.Y > Extent.Y || targetOffset.Z + extent.Z > Extent.Z) { throw new ArgumentOutOfRangeException(nameof(extent)); } var tempBuffer = new T[extent.Size]; for (int i = 0; i < extent.X; ++i) { var subData = source[i + sourceOffset.X]; if (subData == null) { continue; } for (int j = 0; j < extent.Y; ++j) { var subSubData = subData[j + sourceOffset.Y]; if (subSubData == null) { continue; } // Skip entries that are out of bounds for ( int k = 0, e = IntrinsicMath.Min(subSubData.Length, extent.Z); k < e; ++k) { var targetIdx = new Index3(i, j, k).ComputeLinearIndex(extent); tempBuffer[targetIdx] = subSubData[k + sourceOffset.Z]; } } } buffer.CopyFrom( stream, tempBuffer, 0, targetOffset, extent.Size); }
public void Apply(Index3 blockIndex, OrientationFlags orientation) { lastApply = blockIndex; lastOrientation = orientation; }
public void CopyFrom( AcceleratorStream stream, T[,,] source, Index3 sourceOffset, Index3 targetOffset, Index3 extent) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (sourceOffset.X < 0 || sourceOffset.Y < 0 || sourceOffset.Z < 0 || sourceOffset.X >= source.GetLength(0) || sourceOffset.Y >= source.GetLength(1) || sourceOffset.Z >= source.GetLength(2)) { throw new ArgumentOutOfRangeException(nameof(sourceOffset)); } if (targetOffset.X < 0 || targetOffset.Y < 0 || targetOffset.Z < 0 || targetOffset.X >= Extent.X || targetOffset.Y >= Extent.Y || targetOffset.Z >= Extent.Z) { throw new ArgumentOutOfRangeException(nameof(targetOffset)); } if (extent.X < 0 || extent.Y < 0 || extent.Z < 0 || sourceOffset.X + extent.X > source.GetLength(0) || sourceOffset.Y + extent.Y > source.GetLength(1) || sourceOffset.Z + extent.Z > source.GetLength(2) || targetOffset.X + extent.X > Extent.X || targetOffset.Y + extent.Y > Extent.Y || targetOffset.Z + extent.Z > Extent.Z) { throw new ArgumentOutOfRangeException(nameof(extent)); } var tempBuffer = new T[extent.Size]; for (int i = 0; i < extent.X; ++i) { for (int j = 0; j < extent.Y; ++j) { for (int k = 0; k < extent.Z; ++k) { var targetIdx = new Index3(i, j, k).ComputeLinearIndex(extent); tempBuffer[targetIdx] = source[ i + sourceOffset.X, j + sourceOffset.Y, k + sourceOffset.Z]; } } } buffer.CopyFrom( stream, tempBuffer, 0, targetOffset, extent.Size); }
public static BSPNode ReadBSPNode(BinaryReader reader) { var node = new BSPNode { flags = ((BSPNodeFlags)reader.ReadByte()), negChild = reader.ReadInt16(), posChild = reader.ReadInt16(), planeDist = reader.ReadSingle() }; var numIndices = reader.ReadUInt16(); if (numIndices > 0) { var indices = new Index3[numIndices]; for (var i = 0; i < numIndices; i++) { indices[i] = reader.ReadIndex3(); } node.TriIndices = indices; } else { node.TriIndices = null; } return node; }
public T[,,] GetAs3DArray(Index3 offset, Index3 extent) => GetAs3DArray(Accelerator.DefaultStream, offset, extent);
protected override void OnUpdate(GameTime gameTime) { if (player.ActorHost == null) return; sunPosition += (float)gameTime.ElapsedGameTime.TotalMinutes * MathHelper.TwoPi; Index3 centerblock = player.ActorHost.Position.GlobalBlockIndex; Index3 renderOffset = player.ActorHost.Position.ChunkIndex * Chunk.CHUNKSIZE; Index3? selected = null; Axis? selectedAxis = null; Vector3? selectionPoint = null; float bestDistance = 9999; for (int z = -Player.SELECTIONRANGE; z < Player.SELECTIONRANGE; z++) { for (int y = -Player.SELECTIONRANGE; y < Player.SELECTIONRANGE; y++) { for (int x = -Player.SELECTIONRANGE; x < Player.SELECTIONRANGE; x++) { Index3 range = new Index3(x, y, z); Index3 pos = range + centerblock; ushort block = localChunkCache.GetBlock(pos); if (block == 0) continue; IBlockDefinition blockDefinition = DefinitionManager.Instance.GetBlockDefinitionByIndex(block); Axis? collisionAxis; float? distance = Block.Intersect(blockDefinition.GetCollisionBoxes(localChunkCache, pos.X, pos.Y, pos.Z), pos - renderOffset, camera.PickRay, out collisionAxis); if (distance.HasValue && distance.Value < bestDistance) { pos.NormalizeXY(planet.Size * Chunk.CHUNKSIZE); selected = pos; selectedAxis = collisionAxis; bestDistance = distance.Value; selectionPoint = (camera.PickRay.Position + (camera.PickRay.Direction * distance)) - (selected - renderOffset); } } } } if (selected.HasValue) { player.SelectedBox = selected; switch (selectedAxis) { case Axis.X: player.SelectedSide = (camera.PickRay.Direction.X > 0 ? OrientationFlags.SideWest : OrientationFlags.SideEast); break; case Axis.Y: player.SelectedSide = (camera.PickRay.Direction.Y > 0 ? OrientationFlags.SideSouth : OrientationFlags.SideNorth); break; case Axis.Z: player.SelectedSide = (camera.PickRay.Direction.Z > 0 ? OrientationFlags.SideBottom : OrientationFlags.SideTop); break; } player.SelectedPoint = new Vector2(); switch (player.SelectedSide) { case OrientationFlags.SideWest: player.SelectedPoint = new Vector2(1f - selectionPoint.Value.Y, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner011, OrientationFlags.Corner001, OrientationFlags.Corner010, OrientationFlags.Corner000); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeWestTop, OrientationFlags.EdgeWestBottom, OrientationFlags.EdgeNorthWest, OrientationFlags.EdgeSouthWest); break; case OrientationFlags.SideEast: player.SelectedPoint = new Vector2(selectionPoint.Value.Y, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner101, OrientationFlags.Corner111, OrientationFlags.Corner100, OrientationFlags.Corner110); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeEastTop, OrientationFlags.EdgeEastBottom, OrientationFlags.EdgeSouthEast, OrientationFlags.EdgeNorthEast); break; case OrientationFlags.SideTop: player.SelectedPoint = new Vector2(selectionPoint.Value.X, 1f - selectionPoint.Value.Y); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner011, OrientationFlags.Corner111, OrientationFlags.Corner001, OrientationFlags.Corner101); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeNorthTop, OrientationFlags.EdgeSouthTop, OrientationFlags.EdgeWestTop, OrientationFlags.EdgeEastTop); break; case OrientationFlags.SideBottom: player.SelectedPoint = new Vector2(selectionPoint.Value.X, selectionPoint.Value.Y); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner000, OrientationFlags.Corner100, OrientationFlags.Corner010, OrientationFlags.Corner110); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeSouthBottom, OrientationFlags.EdgeNorthBottom, OrientationFlags.EdgeWestBottom, OrientationFlags.EdgeEastBottom); break; case OrientationFlags.SideNorth: player.SelectedPoint = new Vector2(1f - selectionPoint.Value.X, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner111, OrientationFlags.Corner011, OrientationFlags.Corner110, OrientationFlags.Corner010); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeNorthTop, OrientationFlags.EdgeNorthBottom, OrientationFlags.EdgeNorthEast, OrientationFlags.EdgeNorthWest); break; case OrientationFlags.SideSouth: player.SelectedPoint = new Vector2(selectionPoint.Value.X, 1f - selectionPoint.Value.Z); player.SelectedCorner = FindCorner(player.SelectedPoint.Value, OrientationFlags.Corner001, OrientationFlags.Corner101, OrientationFlags.Corner000, OrientationFlags.Corner100); player.SelectedEdge = FindEdge(player.SelectedPoint.Value, OrientationFlags.EdgeSouthTop, OrientationFlags.EdgeSouthBottom, OrientationFlags.EdgeSouthWest, OrientationFlags.EdgeSouthEast); break; } player.SelectedPoint = new Vector2( Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.X)), Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.Y))); } else { player.SelectedBox = null; player.SelectedPoint = null; player.SelectedSide = OrientationFlags.None; player.SelectedEdge = OrientationFlags.None; player.SelectedCorner = OrientationFlags.None; } base.OnUpdate(gameTime); }
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(6, 10); int radius = rand.Next(3, height - 2); builder.FillSphere(0, 0, height, radius, leave); for (int i = 0; i < height + 2; i++) { builder.SetBlock(0, 0, 0 + i, wood); } }
public PlanetIndex3(int planet, Index3 chunkIndex) { Planet = planet; ChunkIndex = chunkIndex; }
public override int GetDensity(IPlanet planet, Index3 index) { return(4); }
private bool FillChunkRenderer() { Index3 destinationChunk = player.Player.Position.ChunkIndex; IPlanet planet = ResourceManager.Instance.GetPlanet(player.Player.Position.Planet); destinationChunk.Z = Math.Max(VIEWHEIGHT, Math.Min(planet.Size.Z - VIEWHEIGHT, destinationChunk.Z)); // Nur ausführen wenn der Spieler den Chunk gewechselt hat if (destinationChunk != currentChunk) { #region Shift durchführen Index3 shift = currentChunk.ShortestDistanceXY( destinationChunk, new Index2(planet.Size.X, planet.Size.Y)); for (int i = activeChunkRenderer.Count - 1; i >= 0; i--) { ChunkRenderer renderer = activeChunkRenderer[i]; Index3 absoluteIndex = renderer.ChunkPosition.Value.ChunkIndex; Index3 relativeIndex = destinationChunk.ShortestDistanceXY( absoluteIndex, new Index2( planet.Size.X, planet.Size.Y)); if (!renderer.ChunkPosition.HasValue || relativeIndex.X < -VIEWRANGE || relativeIndex.X > VIEWRANGE || relativeIndex.Y < -VIEWRANGE || relativeIndex.Y > VIEWRANGE || relativeIndex.Z < -VIEWHEIGHT || relativeIndex.Z > VIEWHEIGHT) { renderer.SetChunk(null); freeChunkRenderer.Enqueue(renderer); activeChunkRenderer.Remove(renderer); } } #endregion #region Ungenutzte Chunks auffüllen foreach (var distance in distances) { Index3 chunkIndex = destinationChunk + distance; chunkIndex.NormalizeXY(planet.Size); PlanetIndex3 chunkPosition = new PlanetIndex3( player.Player.Position.Planet, chunkIndex); if (!activeChunkRenderer.Any(c => c.ChunkPosition == chunkPosition)) { ChunkRenderer renderer = freeChunkRenderer.Dequeue(); renderer.SetChunk(chunkPosition); activeChunkRenderer.Add(renderer); } } #endregion currentChunk = destinationChunk; } #region Chunkrenderer updaten int shortestDistance = int.MaxValue; ChunkRenderer updatableRenderer = null; foreach (var renderer in activeChunkRenderer) { if (!renderer.NeedUpdate()) continue; Index3 absoluteIndex = renderer.ChunkPosition.Value.ChunkIndex; Index3 relativeIndex = destinationChunk.ShortestDistanceXY( absoluteIndex, new Index2( planet.Size.X, planet.Size.Y)); int distance = relativeIndex.LengthSquared(); if (distance < shortestDistance) { updatableRenderer = renderer; shortestDistance = distance; } } if (updatableRenderer != null) updatableRenderer.RegenerateVertexBuffer(); #endregion return updatableRenderer != null; }
/// <summary> /// Lässt den Spieler einen Block entfernen. /// </summary> /// <param name="blockIndex"></param> public void Interact(Index3 blockIndex) { lastInteract = blockIndex; }
public override void Draw(GameTime gameTime) { Microsoft.Xna.Framework.Color background = new Microsoft.Xna.Framework.Color(181, 224, 255); GraphicsDevice.Clear(background); GraphicsDevice.BlendState = BlendState.AlphaBlend; GraphicsDevice.DepthStencilState = DepthStencilState.Default; Index3 chunkOffset = player.Player.Position.ChunkIndex; foreach (var renderer in chunkRenderer) { if (!renderer.ChunkPosition.HasValue) continue; Index3 shift = chunkOffset.ShortestDistanceXY( renderer.ChunkPosition.Value.ChunkIndex, new Index2( planet.Size.X, planet.Size.Y)); BoundingBox chunkBox = new BoundingBox( new Vector3( shift.X * OctoAwesome.Chunk.CHUNKSIZE_X, shift.Y * OctoAwesome.Chunk.CHUNKSIZE_Y, shift.Z * OctoAwesome.Chunk.CHUNKSIZE_Z), new Vector3( (shift.X + 1) * OctoAwesome.Chunk.CHUNKSIZE_X, (shift.Y + 1) * OctoAwesome.Chunk.CHUNKSIZE_Y, (shift.Z + 1) * OctoAwesome.Chunk.CHUNKSIZE_Z)); if (camera.Frustum.Intersects(chunkBox)) renderer.Draw(camera, shift); } if (player.SelectedBox.HasValue) { Index3 offset = player.Player.Position.ChunkIndex * Chunk.CHUNKSIZE; Index3 planetSize = planet.Size * Chunk.CHUNKSIZE; Index3 relativePosition = new Index3( Index2.ShortestDistanceOnAxis(offset.X, player.SelectedBox.Value.X, planetSize.X), Index2.ShortestDistanceOnAxis(offset.Y, player.SelectedBox.Value.Y, planetSize.Y), player.SelectedBox.Value.Z - offset.Z); Vector3 selectedBoxPosition = new Vector3( player.SelectedBox.Value.X - (chunkOffset.X * Chunk.CHUNKSIZE_X), player.SelectedBox.Value.Y - (chunkOffset.Y * Chunk.CHUNKSIZE_Y), player.SelectedBox.Value.Z - (chunkOffset.Z * Chunk.CHUNKSIZE_Z)); // selectionEffect.World = Matrix.CreateTranslation(selectedBoxPosition); selectionEffect.World = Matrix.CreateTranslation(relativePosition); selectionEffect.View = camera.View; selectionEffect.Projection = camera.Projection; foreach (var pass in selectionEffect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, selectionLines, 0, 8, selectionIndeces, 0, 12); } } GraphicsDevice.SetRenderTarget(MiniMapTexture); minimapEffect.View = camera.MinimapView; foreach (var renderer in chunkRenderer) { if (!renderer.ChunkPosition.HasValue) continue; Index3 shift = chunkOffset.ShortestDistanceXY( renderer.ChunkPosition.Value.ChunkIndex, new Index2( planet.Size.X, planet.Size.Y)); BoundingBox chunkBox = new BoundingBox( new Vector3( shift.X * OctoAwesome.Chunk.CHUNKSIZE_X, shift.Y * OctoAwesome.Chunk.CHUNKSIZE_Y, shift.Z * OctoAwesome.Chunk.CHUNKSIZE_Z), new Vector3( (shift.X + 1) * OctoAwesome.Chunk.CHUNKSIZE_X, (shift.Y + 1) * OctoAwesome.Chunk.CHUNKSIZE_Y, (shift.Z + 1) * OctoAwesome.Chunk.CHUNKSIZE_Z)); if (camera.Frustum.Intersects(chunkBox)) renderer.DrawMinimap(minimapEffect, shift); } GraphicsDevice.SetRenderTarget(null); }
/// <summary> /// Constructs a new OpenCL accelerator. /// </summary> /// <param name="context">The ILGPU context.</param> /// <param name="acceleratorId">The accelerator id.</param> public CLAccelerator(Context context, CLAcceleratorId acceleratorId) : base(context, AcceleratorType.OpenCL) { if (acceleratorId == null) { throw new ArgumentNullException(nameof(acceleratorId)); } PlatformId = acceleratorId.PlatformId; DeviceId = acceleratorId.DeviceId; CVersion = acceleratorId.CVersion; PlatformName = CLAPI.GetPlatformInfo( PlatformId, CLPlatformInfoType.CL_PLATFORM_NAME); VendorName = CLAPI.GetPlatformInfo( PlatformId, CLPlatformInfoType.CL_PLATFORM_VENDOR); // Create new context CLException.ThrowIfFailed( CLAPI.CreateContext(DeviceId, out contextPtr)); // Resolve device info Name = CLAPI.GetDeviceInfo( DeviceId, CLDeviceInfoType.CL_DEVICE_NAME); MemorySize = CLAPI.GetDeviceInfo <long>( DeviceId, CLDeviceInfoType.CL_DEVICE_GLOBAL_MEM_SIZE); DeviceType = (CLDeviceType)CLAPI.GetDeviceInfo <long>( DeviceId, CLDeviceInfoType.CL_DEVICE_TYPE); // Max grid size int workItemDimensions = IntrinsicMath.Max(CLAPI.GetDeviceInfo <int>( DeviceId, CLDeviceInfoType.CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS), 3); var workItemSizes = new IntPtr[workItemDimensions]; CLAPI.GetDeviceInfo( DeviceId, CLDeviceInfoType.CL_DEVICE_MAX_WORK_ITEM_SIZES, workItemSizes); MaxGridSize = new Index3( workItemSizes[0].ToInt32(), workItemSizes[1].ToInt32(), workItemSizes[2].ToInt32()); // Resolve max threads per group MaxNumThreadsPerGroup = CLAPI.GetDeviceInfo <IntPtr>( DeviceId, CLDeviceInfoType.CL_DEVICE_MAX_WORK_GROUP_SIZE).ToInt32(); // Resolve max shared memory per block MaxSharedMemoryPerGroup = (int)IntrinsicMath.Min( CLAPI.GetDeviceInfo <long>( DeviceId, CLDeviceInfoType.CL_DEVICE_LOCAL_MEM_SIZE), int.MaxValue); // Resolve total constant memory MaxConstantMemory = (int)CLAPI.GetDeviceInfo <long>( DeviceId, CLDeviceInfoType.CL_DEVICE_MAX_PARAMETER_SIZE); // Resolve clock rate ClockRate = CLAPI.GetDeviceInfo <int>( DeviceId, CLDeviceInfoType.CL_DEVICE_MAX_CLOCK_FREQUENCY); // Resolve number of multiprocessors NumMultiprocessors = CLAPI.GetDeviceInfo <int>( DeviceId, CLDeviceInfoType.CL_DEVICE_MAX_COMPUTE_UNITS); // Result max number of threads per multiprocessor MaxNumThreadsPerMultiprocessor = MaxNumThreadsPerGroup; InitVendorFeatures(); InitSubGroupSupport(acceleratorId); Bind(); DefaultStream = CreateStreamInternal(); base.Backend = new CLBackend(Context, Backends.Backend.OSPlatform, Vendor); }