v0.11.0.9
This commit is contained in:
@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Voronoi2;
|
||||
using System.Linq;
|
||||
#if CLIENT
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
#endif
|
||||
@@ -11,18 +12,15 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class LevelWall : IDisposable
|
||||
{
|
||||
private List<VoronoiCell> cells;
|
||||
public List<VoronoiCell> Cells
|
||||
{
|
||||
get { return cells; }
|
||||
}
|
||||
{
|
||||
public List<VoronoiCell> Cells { get; private set; }
|
||||
|
||||
private Body body;
|
||||
public Body Body
|
||||
{
|
||||
get { return body; }
|
||||
}
|
||||
public Body Body { get; private set; }
|
||||
|
||||
protected readonly Level level;
|
||||
|
||||
private readonly List<Vector2[]> triangles;
|
||||
private readonly Color color;
|
||||
|
||||
private float moveState;
|
||||
private float moveLength;
|
||||
@@ -38,6 +36,17 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private float wallDamageOnTouch;
|
||||
public float WallDamageOnTouch
|
||||
{
|
||||
get { return wallDamageOnTouch; }
|
||||
set
|
||||
{
|
||||
Cells.ForEach(c => c.DoesDamage = !MathUtils.NearlyEqual(value, 0.0f));
|
||||
wallDamageOnTouch = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float MoveSpeed;
|
||||
|
||||
private Vector2? originalPos;
|
||||
@@ -50,30 +59,32 @@ namespace Barotrauma
|
||||
|
||||
public LevelWall(List<Vector2> vertices, Color color, Level level, bool giftWrap = false)
|
||||
{
|
||||
if (giftWrap)
|
||||
this.level = level;
|
||||
this.color = color;
|
||||
List<Vector2> originalVertices = new List<Vector2>(vertices);
|
||||
if (giftWrap) { vertices = MathUtils.GiftWrap(vertices); }
|
||||
if (vertices.Count < 3)
|
||||
{
|
||||
vertices = MathUtils.GiftWrap(vertices);
|
||||
throw new ArgumentException("Failed to generate a wall (not enough vertices). Original vertices: " + string.Join(", ", originalVertices.Select(v => v.ToString())));
|
||||
}
|
||||
|
||||
VoronoiCell wallCell = new VoronoiCell(vertices.ToArray());
|
||||
for (int i = 0; i < wallCell.Edges.Count; i++)
|
||||
{
|
||||
wallCell.Edges[i].Cell1 = wallCell;
|
||||
wallCell.Edges[i].IsSolid = true;
|
||||
}
|
||||
cells = new List<VoronoiCell>() { wallCell };
|
||||
|
||||
body = CaveGenerator.GeneratePolygons(cells, level, out List<Vector2[]> triangles);
|
||||
Cells = new List<VoronoiCell>() { wallCell };
|
||||
Body = CaveGenerator.GeneratePolygons(Cells, level, out triangles);
|
||||
#if CLIENT
|
||||
List<VertexPositionTexture> bodyVertices = CaveGenerator.GenerateRenderVerticeList(triangles);
|
||||
SetBodyVertices(bodyVertices.ToArray(), color);
|
||||
SetWallVertices(CaveGenerator.GenerateWallShapes(cells, level), color);
|
||||
GenerateVertices();
|
||||
#endif
|
||||
}
|
||||
|
||||
public LevelWall(List<Vector2> edgePositions, Vector2 extendAmount, Color color, Level level)
|
||||
{
|
||||
cells = new List<VoronoiCell>();
|
||||
this.level = level;
|
||||
this.color = color;
|
||||
Cells = new List<VoronoiCell>();
|
||||
for (int i = 0; i < edgePositions.Count - 1; i++)
|
||||
{
|
||||
Vector2[] vertices = new Vector2[4];
|
||||
@@ -84,7 +95,7 @@ namespace Barotrauma
|
||||
|
||||
VoronoiCell wallCell = new VoronoiCell(vertices)
|
||||
{
|
||||
CellType = CellType.Edge
|
||||
CellType = CellType.Solid
|
||||
};
|
||||
wallCell.Edges[0].Cell1 = wallCell;
|
||||
wallCell.Edges[1].Cell1 = wallCell;
|
||||
@@ -94,31 +105,28 @@ namespace Barotrauma
|
||||
|
||||
if (i > 1)
|
||||
{
|
||||
wallCell.Edges[3].Cell2 = cells[i - 1];
|
||||
cells[i - 1].Edges[1].Cell2 = wallCell;
|
||||
wallCell.Edges[3].Cell2 = Cells[i - 1];
|
||||
Cells[i - 1].Edges[1].Cell2 = wallCell;
|
||||
}
|
||||
|
||||
cells.Add(wallCell);
|
||||
Cells.Add(wallCell);
|
||||
}
|
||||
|
||||
body = CaveGenerator.GeneratePolygons(cells, level, out List<Vector2[]> triangles);
|
||||
body.CollisionCategories = Physics.CollisionLevel;
|
||||
|
||||
Body = CaveGenerator.GeneratePolygons(Cells, level, out triangles);
|
||||
Body.CollisionCategories = Physics.CollisionLevel;
|
||||
#if CLIENT
|
||||
List<VertexPositionTexture> bodyVertices = CaveGenerator.GenerateRenderVerticeList(triangles);
|
||||
SetBodyVertices(bodyVertices.ToArray(), color);
|
||||
SetWallVertices(CaveGenerator.GenerateWallShapes(cells, level), color);
|
||||
GenerateVertices();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
if (body.BodyType == BodyType.Static) return;
|
||||
if (Body.BodyType == BodyType.Static) { return; }
|
||||
|
||||
Vector2 bodyPos = ConvertUnits.ToDisplayUnits(body.Position);
|
||||
Vector2 bodyPos = ConvertUnits.ToDisplayUnits(Body.Position);
|
||||
Cells.ForEach(c => c.Translation = bodyPos);
|
||||
|
||||
if (!originalPos.HasValue) originalPos = bodyPos;
|
||||
if (!originalPos.HasValue) { originalPos = bodyPos; }
|
||||
|
||||
if (moveLength > 0.0f && MoveSpeed > 0.0f)
|
||||
{
|
||||
@@ -126,10 +134,15 @@ namespace Barotrauma
|
||||
moveState %= MathHelper.TwoPi;
|
||||
|
||||
Vector2 targetPos = ConvertUnits.ToSimUnits(originalPos.Value + moveAmount * (float)Math.Sin(moveState));
|
||||
body.ApplyForce((targetPos - body.Position).ClampLength(1.0f) * body.Mass);
|
||||
Body.ApplyForce((targetPos - Body.Position).ClampLength(1.0f) * Body.Mass);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPointInside(Vector2 point)
|
||||
{
|
||||
return Cells.Any(c => c.IsPointInside(point));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
@@ -139,16 +152,8 @@ namespace Barotrauma
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
#if CLIENT
|
||||
if (wallVertices != null)
|
||||
{
|
||||
wallVertices.Dispose();
|
||||
wallVertices = null;
|
||||
}
|
||||
if (bodyVertices != null)
|
||||
{
|
||||
BodyVertices.Dispose();
|
||||
bodyVertices = null;
|
||||
}
|
||||
VertexBuffer?.Dispose();
|
||||
VertexBuffer = null;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user