From 9c372137bd3b43b652e30e8781e5e08a5a30d013 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 15 Aug 2017 19:19:48 +0300 Subject: [PATCH] Added randomly generated ocean floors. Atm the bottom is too deep to reach in most levels and there's not much to explore down there, but the plan is to have some levels where the bottom or some of the bottom formations are reachable (because we need hydrothermal vents!). Ice walls also use vertex colors now, could be used to add some cosmetic variety to the levels. --- .../BarotraumaClient/BarotraumaClient.csproj | 2 +- Barotrauma/BarotraumaClient/Source/Camera.cs | 17 +- .../Source/Map/Levels/LevelRenderer.cs | 118 +++++++++--- .../Source/Map/Levels/LevelWall.cs | 47 +++++ .../Source/Map/Levels/WrappingWall.cs | 32 ---- .../Source/Screens/GameScreen.cs | 2 +- .../BarotraumaShared.projitems | 2 +- .../Content/Map/LevelGenerationParameters.xml | 20 +- .../Source/Map/Levels/Level.cs | 135 +++++++++----- .../Map/Levels/LevelGenerationParams.cs | 70 ++++++- .../Source/Map/Levels/LevelWall.cs | 90 +++++++++ .../Source/Map/Levels/WrappingWall.cs | 174 ------------------ .../Source/Map/SubmarineBody.cs | 6 + .../Source/Map/TransitionCinematic.cs | 4 +- .../Source/Networking/RespawnManager.cs | 8 +- .../Source/Screens/GameScreen.cs | 4 +- 16 files changed, 426 insertions(+), 305 deletions(-) create mode 100644 Barotrauma/BarotraumaClient/Source/Map/Levels/LevelWall.cs delete mode 100644 Barotrauma/BarotraumaClient/Source/Map/Levels/WrappingWall.cs create mode 100644 Barotrauma/BarotraumaShared/Source/Map/Levels/LevelWall.cs delete mode 100644 Barotrauma/BarotraumaShared/Source/Map/Levels/WrappingWall.cs diff --git a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj index 9fa825506..f133ac605 100644 --- a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj +++ b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj @@ -158,7 +158,7 @@ - + diff --git a/Barotrauma/BarotraumaClient/Source/Camera.cs b/Barotrauma/BarotraumaClient/Source/Camera.cs index 483e73790..487bb3b87 100644 --- a/Barotrauma/BarotraumaClient/Source/Camera.cs +++ b/Barotrauma/BarotraumaClient/Source/Camera.cs @@ -128,7 +128,7 @@ namespace Barotrauma } - public void UpdateTransform(bool interpolate = true, bool clampPos = false) + public void UpdateTransform(bool interpolate = true) { Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position; @@ -136,20 +136,7 @@ namespace Barotrauma worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0); worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0); - - if (Level.Loaded != null && clampPos) - { - float maxY = Level.Loaded.Size.Y + 100; - - position.Y -= Math.Max(worldView.Y - maxY, 0.0f); - interpolatedPosition.Y -= Math.Max(worldView.Y - maxY, 0.0f); - - position.Y = Math.Max(position.Y, (int)Level.MaxCameraDepth); - interpolatedPosition.Y = Math.Max(interpolatedPosition.Y, (int)Level.MaxCameraDepth); - worldView.Y = MathHelper.Clamp(worldView.Y, (int)Level.MaxCameraDepth, (int)maxY); - } - - + transform = Matrix.CreateTranslation( new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) * Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) * diff --git a/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs index 6fa8abd97..4cd7d27b8 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs @@ -40,7 +40,7 @@ namespace Barotrauma wallEdgeEffect = new BasicEffect(GameMain.Instance.GraphicsDevice) { DiffuseColor = new Vector3(0.8f, 0.8f, 0.8f), - VertexColorEnabled = false, + VertexColorEnabled = true, TextureEnabled = true, Texture = shaftTexture }; @@ -51,7 +51,7 @@ namespace Barotrauma { wallCenterEffect = new BasicEffect(GameMain.Instance.GraphicsDevice) { - VertexColorEnabled = false, + VertexColorEnabled = true, TextureEnabled = true, Texture = backgroundTop.Texture }; @@ -84,15 +84,37 @@ namespace Barotrauma backgroundSpriteManager.Update(deltaTime); } - public void SetWallVertices(VertexPositionTexture[] vertices) + public static VertexPositionColorTexture[] GetColoredVertices(VertexPositionTexture[] vertices, Color color) { - wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length,BufferUsage.WriteOnly); + VertexPositionColorTexture[] verts = new VertexPositionColorTexture[vertices.Length]; + for (int i = 0; i < vertices.Length; i++) + { + verts[i] = new VertexPositionColorTexture(vertices[i].Position, color, vertices[i].TextureCoordinate); + } + return verts; + } + + public void SetWallVertices(VertexPositionTexture[] vertices, Color color) + { + wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + wallVertices.SetData(GetColoredVertices(vertices, color)); + } + + public void SetBodyVertices(VertexPositionTexture[] vertices, Color color) + { + bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + bodyVertices.SetData(GetColoredVertices(vertices, color)); + } + + public void SetWallVertices(VertexPositionColorTexture[] vertices) + { + wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length,BufferUsage.WriteOnly); wallVertices.SetData(vertices); } - public void SetBodyVertices(VertexPositionTexture[] vertices) + public void SetBodyVertices(VertexPositionColorTexture[] vertices) { - bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); bodyVertices.SetData(vertices); } @@ -188,48 +210,94 @@ namespace Barotrauma GUI.DrawRectangle(spriteBatch, new Vector2(point.X, -point.Y), new Vector2(10.0f, 10.0f), Color.White, true); } } - } - Vector2 pos = new Vector2(0.0f, -level.Size.Y); - if (GameMain.GameScreen.Cam.WorldView.Y < -pos.Y - 1024) return; + if (GameMain.GameScreen.Cam.WorldView.Y >= -pos.Y - 1024) + { + pos.X = GameMain.GameScreen.Cam.WorldView.X -1024; + int width = (int)(Math.Ceiling(GameMain.GameScreen.Cam.WorldView.Width / 1024 + 4.0f) * 1024); - pos.X = GameMain.GameScreen.Cam.WorldView.X -1024; + GUI.DrawRectangle(spriteBatch,new Rectangle( + (int)(MathUtils.Round(pos.X, 1024)), + -GameMain.GameScreen.Cam.WorldView.Y, + width, + (int)(GameMain.GameScreen.Cam.WorldView.Y + pos.Y) - 30), + Color.Black, true); - int width = (int)(Math.Ceiling(GameMain.GameScreen.Cam.WorldView.Width / 1024 + 4.0f) * 1024); + spriteBatch.Draw(shaftTexture, + new Rectangle((int)(MathUtils.Round(pos.X, 1024)), (int)pos.Y-1000, width, 1024), + new Rectangle(0, 0, width, -1024), + level.BackgroundColor, 0.0f, + Vector2.Zero, + SpriteEffects.None, 0.0f); + } - GUI.DrawRectangle(spriteBatch,new Rectangle((int)(MathUtils.Round(pos.X, 1024)), (int)-GameMain.GameScreen.Cam.WorldView.Y, width, (int)(GameMain.GameScreen.Cam.WorldView.Y + pos.Y) - 30),Color.Black, true); - spriteBatch.Draw(shaftTexture, - new Rectangle((int)(MathUtils.Round(pos.X, 1024)), (int)pos.Y-1000, width, 1024), - new Rectangle(0, 0, width, -1024), - level.BackgroundColor, 0.0f, - Vector2.Zero, - SpriteEffects.None, 0.0f); + if (GameMain.GameScreen.Cam.WorldView.Y - GameMain.GameScreen.Cam.WorldView.Height < level.SeaFloorTopPos + 1024) + { + pos = new Vector2(GameMain.GameScreen.Cam.WorldView.X - 1024, -level.BottomPos); + int width = (int)(Math.Ceiling(GameMain.GameScreen.Cam.WorldView.Width / 1024 + 4.0f) * 1024); + + GUI.DrawRectangle(spriteBatch, new Rectangle( + (int)(MathUtils.Round(pos.X, 1024)), + (int)-(level.BottomPos - 30), + width, + (int)(level.BottomPos - (GameMain.GameScreen.Cam.WorldView.Y - GameMain.GameScreen.Cam.WorldView.Height))), + Color.Black, true); + + spriteBatch.Draw(shaftTexture, + new Rectangle((int)(MathUtils.Round(pos.X, 1024)), (int)-level.BottomPos, width, 1024), + new Rectangle(0, 0, width, -1024), + level.BackgroundColor, 0.0f, + Vector2.Zero, + SpriteEffects.FlipVertically, 0.0f); + } } public void RenderWalls(GraphicsDevice graphicsDevice, Camera cam) { if (wallVertices == null) return; - + wallEdgeEffect.World = cam.ShaderTransform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 100) * 0.5f; wallCenterEffect.World = wallEdgeEffect.World; //render the solid center of the wall cells graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; - graphicsDevice.SetVertexBuffer(bodyVertices); wallCenterEffect.CurrentTechnique.Passes[0].Apply(); - - graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f)); - + if (GameMain.GameScreen.Cam.WorldView.Y - GameMain.GameScreen.Cam.WorldView.Height < level.SeaFloorTopPos + 1024) + { + foreach (LevelWall wall in level.WrappingWalls) + { + graphicsDevice.SetVertexBuffer(wall.BodyVertices); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wall.BodyVertices.VertexCount / 3.0f)); + } + } + else + { + graphicsDevice.SetVertexBuffer(bodyVertices); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f)); + } + //render the edges of the wall cells - graphicsDevice.SetVertexBuffer(wallVertices); wallEdgeEffect.CurrentTechnique.Passes[0].Apply(); - graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f)); + + if (GameMain.GameScreen.Cam.WorldView.Y - GameMain.GameScreen.Cam.WorldView.Height < level.SeaFloorTopPos + 1024) + { + foreach (LevelWall wall in level.WrappingWalls) + { + graphicsDevice.SetVertexBuffer(wall.WallVertices); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wall.WallVertices.VertexCount / 3.0f)); + } + } + else + { + graphicsDevice.SetVertexBuffer(wallVertices); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f)); + } } public void Dispose() diff --git a/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelWall.cs b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelWall.cs new file mode 100644 index 000000000..d27374c35 --- /dev/null +++ b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelWall.cs @@ -0,0 +1,47 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; + +namespace Barotrauma +{ + partial class LevelWall : IDisposable + { + private VertexBuffer wallVertices, bodyVertices; + + public VertexBuffer WallVertices + { + get { return wallVertices; } + } + + public VertexBuffer BodyVertices + { + get { return bodyVertices; } + } + + public void SetWallVertices(VertexPositionTexture[] vertices, Color color) + { + wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + wallVertices.SetData(LevelRenderer.GetColoredVertices(vertices, color)); + } + + public void SetBodyVertices(VertexPositionTexture[] vertices, Color color) + { + bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + bodyVertices.SetData(LevelRenderer.GetColoredVertices(vertices, color)); + } + + public void SetWallVertices(VertexPositionColorTexture[] vertices) + { + if (wallVertices != null && !wallVertices.IsDisposed) wallVertices.Dispose(); + wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + wallVertices.SetData(vertices); + } + + public void SetBodyVertices(VertexPositionColorTexture[] vertices) + { + if (bodyVertices != null && !bodyVertices.IsDisposed) bodyVertices.Dispose(); + bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + bodyVertices.SetData(vertices); + } + } +} diff --git a/Barotrauma/BarotraumaClient/Source/Map/Levels/WrappingWall.cs b/Barotrauma/BarotraumaClient/Source/Map/Levels/WrappingWall.cs deleted file mode 100644 index 9070c66cb..000000000 --- a/Barotrauma/BarotraumaClient/Source/Map/Levels/WrappingWall.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Xna.Framework.Graphics; -using System; - -namespace Barotrauma -{ - partial class WrappingWall : IDisposable - { - private VertexBuffer wallVertices, bodyVertices; - - public VertexBuffer WallVertices - { - get { return wallVertices; } - } - - public VertexBuffer BodyVertices - { - get { return bodyVertices; } - } - - public void SetWallVertices(VertexPositionTexture[] vertices) - { - wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); - wallVertices.SetData(vertices); - } - - public void SetBodyVertices(VertexPositionColor[] vertices) - { - bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); - bodyVertices.SetData(vertices); - } - } -} diff --git a/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs index 8d3d610db..41e4055dc 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs @@ -68,7 +68,7 @@ namespace Barotrauma public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { - cam.UpdateTransform(true, !GameMain.DebugDraw); + cam.UpdateTransform(true); Submarine.CullEntities(cam); DrawMap(graphics, spriteBatch); diff --git a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems index 845907934..e44727471 100644 --- a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems +++ b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems @@ -1442,7 +1442,7 @@ - + diff --git a/Barotrauma/BarotraumaShared/Content/Map/LevelGenerationParameters.xml b/Barotrauma/BarotraumaShared/Content/Map/LevelGenerationParameters.xml index add72c487..911976c9c 100644 --- a/Barotrauma/BarotraumaShared/Content/Map/LevelGenerationParameters.xml +++ b/Barotrauma/BarotraumaShared/Content/Map/LevelGenerationParameters.xml @@ -12,6 +12,11 @@ RuinCount="1" BottomHoleProbability="0.4" BackgroundSpriteAmount="1000" + MountainCountMin="0" + MountainCountMax="3" + SeaFloorDepth="-300000.0" + MountainHeightMin="10000" + MountainHeightMax="20000" /> \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index 56f8382fe..3b994e415 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -3,7 +3,6 @@ using FarseerPhysics; using FarseerPhysics.Dynamics; using FarseerPhysics.Factories; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Diagnostics; @@ -16,7 +15,6 @@ namespace Barotrauma { //all entities are disabled after they reach this depth public const float MaxEntityDepth = -300000.0f; - public const float MaxCameraDepth = -290000.0f; public const float ShaftHeight = 1000.0f; @@ -53,7 +51,7 @@ namespace Barotrauma public const int GridCellSize = 2000; private List[,] cellGrid; - //private WrappingWall[,] wrappingWalls; + private LevelWall[] extraWalls; //private float shaftHeight; @@ -76,6 +74,7 @@ namespace Barotrauma private LevelGenerationParams generationParams; + public Vector2 StartPosition { get { return startPosition; } @@ -91,15 +90,27 @@ namespace Barotrauma get { return endPosition; } } + public float BottomPos + { + get; + private set; + } + + public float SeaFloorTopPos + { + get; + private set; + } + public List Ruins { get { return ruins; } } - //public WrappingWall[,] WrappingWalls - //{ - // get { return wrappingWalls; } - //} + public LevelWall[] WrappingWalls + { + get { return extraWalls; } + } public string Seed { @@ -112,12 +123,19 @@ namespace Barotrauma private set; } - public Body ShaftBody + public Body TopBarrier { get; private set; } + public Body BottomBarrier + { + get; + private set; + } + + public LevelGenerationParams GenerationParams { get { return generationParams; } @@ -446,24 +464,23 @@ namespace Barotrauma bodies = CaveGenerator.GeneratePolygons(cellsWithBody, out triangles); #if CLIENT - List bodyVertices = CaveGenerator.GenerateRenderVerticeList(triangles); - - renderer.SetBodyVertices(bodyVertices.ToArray()); - renderer.SetWallVertices(CaveGenerator.GenerateWallShapes(cells)); + renderer.SetBodyVertices(CaveGenerator.GenerateRenderVerticeList(triangles).ToArray(), Color.White); + renderer.SetWallVertices(CaveGenerator.GenerateWallShapes(cells), Color.White); renderer.PlaceSprites(generationParams.BackgroundSpriteAmount); #endif - ShaftBody = BodyFactory.CreateEdge(GameMain.World, + TopBarrier = BodyFactory.CreateEdge(GameMain.World, ConvertUnits.ToSimUnits(new Vector2(borders.X, 0)), ConvertUnits.ToSimUnits(new Vector2(borders.Right, 0))); - ShaftBody.SetTransform(ConvertUnits.ToSimUnits(new Vector2(0.0f, borders.Height)), 0.0f); - - ShaftBody.BodyType = BodyType.Static; - ShaftBody.CollisionCategories = Physics.CollisionLevel; + TopBarrier.SetTransform(ConvertUnits.ToSimUnits(new Vector2(0.0f, borders.Height)), 0.0f); + TopBarrier.BodyType = BodyType.Static; + TopBarrier.CollisionCategories = Physics.CollisionLevel; - bodies.Add(ShaftBody); + bodies.Add(TopBarrier); + + GenerateSeaFloor(); foreach (VoronoiCell cell in cells) { @@ -534,21 +551,9 @@ namespace Barotrauma var newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, borders.Height, 10, 10), null); newWaypoint.MoveWithLevel = true; wayPoints.Add(newWaypoint); - - //WayPoint prevWaypoint = newWaypoint; - + for (int i = 0; i < pathCells.Count; i++) { - ////clean "loops" from the path - //for (int n = 0; n < i; n++) - //{ - // if (pathCells[n] != pathCells[i]) continue; - - // pathCells.RemoveRange(n + 1, i - n); - // break; - //} - //if (i >= pathCells.Count) break; - pathCells[i].CellType = CellType.Path; newWaypoint = new WayPoint(new Rectangle((int)pathCells[i].Center.X, (int)pathCells[i].Center.Y, 10, 10), null); @@ -567,8 +572,6 @@ namespace Barotrauma break; } - - //prevWaypoint = newWaypoint; } newWaypoint = new WayPoint(new Rectangle((int)pathCells[pathCells.Count - 1].Center.X, borders.Height, 10, 10), null); @@ -666,9 +669,57 @@ namespace Barotrauma return newCells; } + private void GenerateSeaFloor() + { + BottomPos = generationParams.SeaFloorDepth; + SeaFloorTopPos = BottomPos; + + List bottomPositions = new List(); + bottomPositions.Add(new Vector2(0, BottomPos)); + + int mountainCount = Rand.Range(generationParams.MountainCountMin, generationParams.MountainCountMax, Rand.RandSync.Server); + for (int i = 0; i < mountainCount; i++) + { + bottomPositions.Add( + new Vector2(Size.X / (mountainCount + 1) * (i + 1), + BottomPos + Rand.Range(generationParams.MountainHeightMin, generationParams.MountainHeightMax, Rand.RandSync.Server))); + } + bottomPositions.Add(new Vector2(Size.X, BottomPos)); + + + float minVertexInterval = 5000.0f; + float currInverval = Size.X / 2.0f; + while (currInverval > minVertexInterval) + { + for (int i = 0; i < bottomPositions.Count - 1; i++) + { + bottomPositions.Insert(i+1, + (bottomPositions[i] + bottomPositions[i + 1]) / 2.0f + + Vector2.UnitY * Rand.Range(0.0f, generationParams.SeaFloorVariance, Rand.RandSync.Server)); + + i++; + } + + currInverval /= 2.0f; + } + + SeaFloorTopPos = bottomPositions.Max(p => p.Y); + + extraWalls = new LevelWall[] { new LevelWall(bottomPositions, new Vector2(0.0f, -2000.0f), backgroundColor) }; + + BottomBarrier = BodyFactory.CreateEdge(GameMain.World, + ConvertUnits.ToSimUnits(new Vector2(borders.X, 0)), + ConvertUnits.ToSimUnits(new Vector2(borders.Right, 0))); + + BottomBarrier.SetTransform(ConvertUnits.ToSimUnits(new Vector2(0.0f, BottomPos)), 0.0f); + BottomBarrier.BodyType = BodyType.Static; + BottomBarrier.CollisionCategories = Physics.CollisionLevel; + + bodies.Add(BottomBarrier); + } + private void GenerateRuin(List mainPath) { - Vector2 ruinSize = new Vector2(Rand.Range(5000.0f, 8000.0f, Rand.RandSync.Server), Rand.Range(5000.0f, 8000.0f, Rand.RandSync.Server)); float ruinRadius = Math.Max(ruinSize.X, ruinSize.Y) * 0.5f; @@ -893,20 +944,16 @@ namespace Barotrauma ruins = null; } - /* - if (wrappingWalls!=null) + + if (extraWalls != null) { - for (int side = 0; side < 2; side++) + foreach (LevelWall w in extraWalls) { - for (int i = 0; i < 2; i++) - { - if (wrappingWalls[side, i] != null) wrappingWalls[side, i].Dispose(); - } + w.Dispose(); } - wrappingWalls = null; - }*/ - + extraWalls = null; + } cells = null; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs index 4aa881f80..05b66376a 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelGenerationParams.cs @@ -36,6 +36,15 @@ namespace Barotrauma //if 1.0f, the bottom will be completely open private float bottomHoleProbability; + //the y-position of the ocean floor (= the position from which the bottom formations extend upwards) + private float seaFloorBaseDepth; + //how much random variance there can be in the height of the formations + private float seaFloorVariance; + + private int mountainCountMin, mountainCountMax; + + private float mountainHeightMin, mountainHeightMax; + private int ruinCount; public Color BackgroundColor @@ -74,9 +83,10 @@ namespace Barotrauma public Vector2 VoronoiSiteInterval { get { return voronoiSiteInterval; } - set { - voronoiSiteInterval.X = MathHelper.Clamp(value.X, 100.0f, width/2); - voronoiSiteInterval.Y = MathHelper.Clamp(value.Y, 100.0f, height/2); + set + { + voronoiSiteInterval.X = MathHelper.Clamp(value.X, 100.0f, width / 2); + voronoiSiteInterval.Y = MathHelper.Clamp(value.Y, 100.0f, height / 2); } } @@ -118,6 +128,60 @@ namespace Barotrauma } } + [HasDefaultValue(-300000.0f, false)] + public float SeaFloorDepth + { + get { return seaFloorBaseDepth; } + set { seaFloorBaseDepth = MathHelper.Clamp(value, Level.MaxEntityDepth, 0.0f); } + } + + [HasDefaultValue(1000.0f, false)] + public float SeaFloorVariance + { + get { return seaFloorVariance; } + set { seaFloorVariance = value; } + } + + [HasDefaultValue(0, false)] + public int MountainCountMin + { + get { return mountainCountMin; } + set + { + mountainCountMin = Math.Max(value, 0); + } + } + + [HasDefaultValue(0, false)] + public int MountainCountMax + { + get { return mountainCountMax; } + set + { + mountainCountMax = Math.Max(value, 0); + } + } + + [HasDefaultValue(1000.0f, false)] + public float MountainHeightMin + { + get { return mountainHeightMin; } + set + { + mountainHeightMin = Math.Max(value, 0); + } + } + + [HasDefaultValue(5000.0f, false)] + public float MountainHeightMax + { + get { return mountainHeightMax; } + set + { + mountainHeightMax = Math.Max(value, 0); + } + } + [HasDefaultValue(1, false)] public int RuinCount { diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelWall.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelWall.cs new file mode 100644 index 000000000..059301862 --- /dev/null +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelWall.cs @@ -0,0 +1,90 @@ +using FarseerPhysics.Dynamics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using Voronoi2; + +namespace Barotrauma +{ + partial class LevelWall : IDisposable + { + private List cells; + + public List Cells + { + get { return cells; } + } + + private List bodies; + + public LevelWall(List edgePositions, Vector2 extendAmount, Color color) + { + cells = new List(); + + for (int i = 0; i < edgePositions.Count - 1; i++) + { + Vector2[] vertices = new Vector2[4]; + vertices[0] = edgePositions[i]; + vertices[1] = edgePositions[i + 1]; + vertices[2] = vertices[0] + extendAmount; + vertices[3] = vertices[1] + extendAmount; + + VoronoiCell wallCell = new VoronoiCell(vertices); + wallCell.edges[0].cell1 = wallCell; + wallCell.edges[1].cell1 = wallCell; + wallCell.edges[2].cell1 = wallCell; + wallCell.edges[3].cell1 = wallCell; + + wallCell.edges[0].isSolid = true; + + if (i > 1) + { + wallCell.edges[3].cell2 = cells[i - 1]; + cells[i - 1].edges[1].cell2 = wallCell; + } + + cells.Add(wallCell); + } + + List triangles; + bodies = CaveGenerator.GeneratePolygons(cells, out triangles, false); + +#if CLIENT + List bodyVertices = CaveGenerator.GenerateRenderVerticeList(triangles); + + SetBodyVertices(bodyVertices.ToArray(), color); + SetWallVertices(CaveGenerator.GenerateWallShapes(cells), color); +#endif + } + + public void Dispose() + { + Dispose(true); + + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { +#if CLIENT + if (wallVertices != null) + { + wallVertices.Dispose(); + wallVertices = null; + } + if (bodyVertices != null) + { + BodyVertices.Dispose(); + bodyVertices = null; + } +#endif + + if (bodies != null) + { + bodies.Clear(); + bodies = null; + } + } + } +} diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/WrappingWall.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/WrappingWall.cs deleted file mode 100644 index 84736c71b..000000000 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/WrappingWall.cs +++ /dev/null @@ -1,174 +0,0 @@ -using FarseerPhysics; -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using Voronoi2; - -namespace Barotrauma -{ - partial class WrappingWall : IDisposable - { - public const float WallWidth = 20000.0f; - - private Vector2 midPos; - private int slot; - - private Vector2 offset; - - private List cells; - - public Vector2 Offset - { - get { return offset; } - } - - public List Cells - { - get { return cells; } - } - - public Vector2 MidPos - { - get { return midPos; } - } - - public WrappingWall(List pathCells, List mapCells, Rectangle ignoredArea, int dir = -1) - { - cells = new List(); - - VoronoiCell edgeCell = null; - foreach (VoronoiCell cell in mapCells) - { - if (ignoredArea.Contains(cell.Center)) continue; - if (Math.Sign(cell.Center.X - ignoredArea.Center.X) != Math.Sign(dir)) continue; - if (edgeCell == null || cell.Center.Y < edgeCell.Center.Y) - { - edgeCell = cell; - } - } - - Vector2 wallSectionSize = new Vector2(2000.0f, 2000.0f); - Vector2 startPos = (dir < 0) ? - edgeCell.Center + Vector2.UnitX * WallWidth * dir : - edgeCell.Center + WallWidth * Vector2.UnitX * (dir - 1); - - midPos = startPos + Vector2.UnitX * WallWidth/2; - - List bottomVertices = new List(); - - for (float x = 0; x <= WallWidth; x += wallSectionSize.X) - { - Vector2 center = new Vector2(startPos.X + x, edgeCell.Center.Y); - float distFromCenter = Math.Abs(x - WallWidth / 2); - float distFromEdge = WallWidth / 2 - distFromCenter; - float normalizedDist = distFromEdge / (WallWidth / 2); - - float variance = 1000.0f * normalizedDist; - bottomVertices.Add(center + new Vector2(Rand.Range(-variance, variance, Rand.RandSync.Server), Rand.Range(-variance, variance, Rand.RandSync.Server) *2.0f)); - } - - for (int i = 1; i < bottomVertices.Count; i++) - { - Vector2[] vertices = new Vector2[4]; - vertices[0] = bottomVertices[i]; - vertices[1] = bottomVertices[i - 1]; - vertices[2] = vertices[1] + Vector2.UnitY * wallSectionSize.Y; - vertices[3] = vertices[0] + Vector2.UnitY * wallSectionSize.Y; - - VoronoiCell wallCell = new VoronoiCell(vertices); - wallCell.edges[0].cell1 = wallCell; - wallCell.edges[1].cell1 = wallCell; - wallCell.edges[2].cell1 = wallCell; - wallCell.edges[3].cell1 = wallCell; - - wallCell.edges[0].isSolid = true; - wallCell.edges[2].isSolid = true; - - - if (i > 1) - { - wallCell.edges[1].cell2 = cells[i - 2]; - cells[i - 2].edges[3].cell2 = wallCell; - } - - cells.Add(wallCell); - } - } - - public static void UpdateWallShift(Vector2 pos, WrappingWall[,] walls) - { - if (pos.X < walls[0, 1].midPos.X && walls[0,0].midPos.X > pos.X) - { - walls[0, 0].Shift(-2); - - var temp = walls[0, 0]; - walls[0, 0] = walls[0, 1]; - walls[0, 1] = temp; - } - else if (pos.X > walls[0, 0].midPos.X && walls[0,1].midPos.X < pos.X && walls[0,1].slot<0) - { - walls[0, 1].Shift(2); - - var temp = walls[0, 0]; - walls[0, 0] = walls[0, 1]; - walls[0, 1] = temp; - } - else if (pos.X > walls[1, 1].midPos.X && walls[1,0].midPos.X < pos.X) - { - walls[1, 0].Shift(2); - - var temp = walls[1, 0]; - walls[1, 0] = walls[1, 1]; - walls[1, 1] = temp; - } - else if (pos.X < walls[1, 0].midPos.X && walls[1, 1].midPos.X > pos.X && walls[1, 1].slot > 0) - { - walls[1, 1].Shift(-2); - - var temp = walls[0, 0]; - walls[1, 0] = walls[1, 1]; - walls[1, 1] = temp; - } - } - - public void Shift(int amount) - { - slot += amount; - - Vector2 moveAmount = Vector2.UnitX * WallWidth * amount; - Vector2 simMoveAmount = ConvertUnits.ToSimUnits(moveAmount); - - foreach (VoronoiCell cell in cells) - { - cell.body.SetTransform(cell.body.Position + simMoveAmount, 0.0f); - cell.Translation += moveAmount; - } - - midPos += moveAmount; - offset += moveAmount; - } - - public void Dispose() - { - Dispose(true); - - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { -#if CLIENT - if (wallVertices != null) - { - wallVertices.Dispose(); - wallVertices = null; - } - if (bodyVertices != null) - { - bodyVertices.Dispose(); - bodyVertices = null; - } -#endif - } - } -} diff --git a/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs b/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs index faa349cff..9d873cc9a 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs @@ -242,6 +242,12 @@ namespace Barotrauma Body.LinearVelocity.X, Math.Min(Body.LinearVelocity.Y, ConvertUnits.ToSimUnits(Level.Loaded.Size.Y - worldBorders.Y))); } + else if (worldBorders.Y - worldBorders.Height < Level.Loaded.BottomPos) + { + Body.LinearVelocity = new Vector2( + Body.LinearVelocity.X, + Math.Max(Body.LinearVelocity.Y, ConvertUnits.ToSimUnits(Level.Loaded.BottomPos - (worldBorders.Y - worldBorders.Height)))); + } } //------------------------- diff --git a/Barotrauma/BarotraumaShared/Source/Map/TransitionCinematic.cs b/Barotrauma/BarotraumaShared/Source/Map/TransitionCinematic.cs index 6edeff425..60a9a8449 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/TransitionCinematic.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/TransitionCinematic.cs @@ -58,7 +58,7 @@ namespace Barotrauma //Vector2 diff = targetPos - sub.Position; float targetSpeed = 10.0f; - Level.Loaded.ShaftBody.Enabled = false; + Level.Loaded.TopBarrier.Enabled = false; cam.TargetPos = Vector2.Zero; float timer = 0.0f; @@ -80,7 +80,7 @@ namespace Barotrauma cam.Zoom = Math.Max(0.2f, cam.Zoom - CoroutineManager.UnscaledDeltaTime * 0.1f); Vector2 cameraPos = subs.First().Position + Submarine.MainSub.HiddenSubPosition; - cameraPos.Y = Math.Min(cameraPos.Y, ConvertUnits.ToDisplayUnits(Level.Loaded.ShaftBody.Position.Y) - cam.WorldView.Height / 2.0f); + cameraPos.Y = Math.Min(cameraPos.Y, ConvertUnits.ToDisplayUnits(Level.Loaded.TopBarrier.Position.Y) - cam.WorldView.Height / 2.0f); cam.Translate((cameraPos - cam.Position) * CoroutineManager.UnscaledDeltaTime * 10.0f); #if CLIENT GUI.ScreenOverlayColor = Color.Lerp(Color.TransparentBlack, Color.Black, timer/duration); diff --git a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs index deba6b86c..d8fa87f55 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs @@ -233,7 +233,7 @@ namespace Barotrauma.Networking { updateReturnTimer = 0.0f; - respawnShuttle.PhysicsBody.FarseerBody.IgnoreCollisionWith(Level.Loaded.ShaftBody); + respawnShuttle.PhysicsBody.FarseerBody.IgnoreCollisionWith(Level.Loaded.TopBarrier); shuttleSteering.SetDestinationLevelStart(); @@ -304,7 +304,7 @@ namespace Barotrauma.Networking private IEnumerable ForceShuttleToPos(Vector2 position, float speed) { - respawnShuttle.PhysicsBody.FarseerBody.IgnoreCollisionWith(Level.Loaded.ShaftBody); + respawnShuttle.PhysicsBody.FarseerBody.IgnoreCollisionWith(Level.Loaded.TopBarrier); while (Math.Abs(position.Y - respawnShuttle.WorldPosition.Y) > 100.0f) { @@ -315,7 +315,7 @@ namespace Barotrauma.Networking if (respawnShuttle.SubBody == null) yield return CoroutineStatus.Success; } - respawnShuttle.PhysicsBody.FarseerBody.RestoreCollisionWith(Level.Loaded.ShaftBody); + respawnShuttle.PhysicsBody.FarseerBody.RestoreCollisionWith(Level.Loaded.TopBarrier); yield return CoroutineStatus.Success; } @@ -389,7 +389,7 @@ namespace Barotrauma.Networking respawnShuttle.Velocity = Vector2.Zero; - respawnShuttle.PhysicsBody.FarseerBody.RestoreCollisionWith(Level.Loaded.ShaftBody); + respawnShuttle.PhysicsBody.FarseerBody.RestoreCollisionWith(Level.Loaded.TopBarrier); } diff --git a/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs b/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs index c43ad2c2b..bb7673f51 100644 --- a/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs @@ -27,12 +27,12 @@ namespace Barotrauma if (Character.Controlled != null) { cam.Position = Character.Controlled.WorldPosition; - cam.UpdateTransform(true, !GameMain.DebugDraw); + cam.UpdateTransform(true); } else if (Submarine.MainSub != null) { cam.Position = Submarine.MainSub.WorldPosition; - cam.UpdateTransform(true, !GameMain.DebugDraw); + cam.UpdateTransform(true); } foreach (MapEntity entity in MapEntity.mapEntityList)