Removed BarotraumaServer's MonoGame dependency

This commit is contained in:
juanjp600
2017-06-23 14:43:43 -03:00
parent 89c92564b5
commit d6d8a5b868
45 changed files with 6385 additions and 212 deletions
+2 -2
View File
@@ -281,11 +281,11 @@ namespace Barotrauma
{
if (grid.Submarine != submarine) continue;
rect.Location -= submarine.HiddenSubPosition.ToPoint();
rect.Location -= MathUtils.ToPoint(submarine.HiddenSubPosition);
grid.InsertEntity(this);
rect.Location += submarine.HiddenSubPosition.ToPoint();
rect.Location += MathUtils.ToPoint(submarine.HiddenSubPosition);
return;
}
}
@@ -13,7 +13,7 @@ using FarseerPhysics.Factories;
namespace Barotrauma
{
static class CaveGenerator
static partial class CaveGenerator
{
public static List<VoronoiCell> CarveCave(List<VoronoiCell> cells, Vector2 startPoint, out List<VoronoiCell> newCells)
{
@@ -360,10 +360,9 @@ namespace Barotrauma
return pathCells;
}
public static List<Body> GeneratePolygons(List<VoronoiCell> cells, out List<VertexPositionTexture> verticeList, bool setSolid=true)
public static List<Body> GeneratePolygons(List<VoronoiCell> cells, out List<Vector2[]> renderTriangles, bool setSolid=true)
{
//TODO: consider separating body generation from render triangle generation
verticeList = new List<VertexPositionTexture>();
renderTriangles = null;
var bodies = new List<Body>();
List<Vector2> tempVertices = new List<Vector2>();
@@ -396,20 +395,8 @@ namespace Barotrauma
continue;
}
var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center);
for (int i = 0; i < triangles.Count; i++)
{
foreach (Vector2 vertex in triangles[i])
{
//shift the coordinates around a bit to make the texture repetition less obvious
Vector2 uvCoords = new Vector2(
vertex.X / 2000.0f + (float)Math.Sin(vertex.X / 500.0f) * 0.15f,
vertex.Y / 2000.0f + (float)Math.Sin(vertex.Y / 700.0f) * 0.15f);
verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 1.0f), uvCoords));
}
}
renderTriangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center);
if (bodyPoints.Count < 2) continue;
if (bodyPoints.Count < 3)
@@ -431,7 +418,7 @@ namespace Barotrauma
if (cell.CellType == CellType.Empty) continue;
triangles = MathUtils.TriangulateConvexHull(bodyPoints, ConvertUnits.ToSimUnits(cell.Center));
var triangles = MathUtils.TriangulateConvexHull(bodyPoints, ConvertUnits.ToSimUnits(cell.Center));
Body cellBody = new Body(GameMain.World);
@@ -459,135 +446,6 @@ namespace Barotrauma
return bodies;
}
public static VertexPositionTexture[] GenerateWallShapes(List<VoronoiCell> cells)
{
float inwardThickness = 500.0f, outWardThickness = 30.0f;
List<VertexPositionTexture> verticeList = new List<VertexPositionTexture>();
foreach (VoronoiCell cell in cells)
{
//if (cell.body == null) continue;
foreach (GraphEdge edge in cell.edges)
{
if (edge.cell1 != null && edge.cell1.body == null && edge.cell1.CellType != CellType.Empty) edge.cell1 = null;
if (edge.cell2 != null && edge.cell2.body == null && edge.cell2.CellType != CellType.Empty) edge.cell2 = null;
CompareCCW compare = new CompareCCW(cell.Center);
if (compare.Compare(edge.point1, edge.point2) == -1)
{
var temp = edge.point1;
edge.point1 = edge.point2;
edge.point2 = temp;
}
}
}
foreach (VoronoiCell cell in cells)
{
//if (cell.body == null) continue;
foreach (GraphEdge edge in cell.edges)
{
if (!edge.isSolid) continue;
GraphEdge leftEdge = cell.edges.Find(e => e != edge && (edge.point1 == e.point1 || edge.point1 == e.point2));
GraphEdge rightEdge = cell.edges.Find(e => e != edge && (edge.point2 == e.point1 || edge.point2 == e.point2));
Vector2 leftNormal = Vector2.Zero, rightNormal = Vector2.Zero;
if (leftEdge == null)
{
leftNormal = GetEdgeNormal(edge, cell);
}
else
{
leftNormal = (leftEdge.isSolid) ?
Vector2.Normalize(GetEdgeNormal(leftEdge) + GetEdgeNormal(edge, cell)) :
Vector2.Normalize(leftEdge.Center - edge.point1);
}
if (!MathUtils.IsValid(leftNormal))
{
#if DEBUG
DebugConsole.ThrowError("Invalid left normal");
#endif
if (cell.body != null)
{
GameMain.World.RemoveBody(cell.body);
cell.body = null;
}
leftNormal = Vector2.UnitX;
break;
}
if (rightEdge == null)
{
rightNormal = GetEdgeNormal(edge, cell);
}
else
{
rightNormal = (rightEdge.isSolid) ?
Vector2.Normalize(GetEdgeNormal(rightEdge) + GetEdgeNormal(edge, cell)) :
Vector2.Normalize(rightEdge.Center - edge.point2);
}
if (!MathUtils.IsValid(rightNormal))
{
#if DEBUG
DebugConsole.ThrowError("Invalid right normal");
#endif
if (cell.body != null)
{
GameMain.World.RemoveBody(cell.body);
cell.body = null;
}
rightNormal = Vector2.UnitX;
break;
}
for (int i = 0; i < 2; i++)
{
Vector2[] verts = new Vector2[3];
VertexPositionTexture[] vertPos = new VertexPositionTexture[3];
if (i == 0)
{
verts[0] = edge.point1 - leftNormal * outWardThickness;
verts[1] = edge.point2 - rightNormal * outWardThickness;
verts[2] = edge.point1 + leftNormal * inwardThickness;
vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), Vector2.Zero);
vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX);
vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(0, 0.5f));
}
else
{
verts[0] = edge.point1 + leftNormal * inwardThickness;
verts[1] = edge.point2 - rightNormal * outWardThickness;
verts[2] = edge.point2 + rightNormal * inwardThickness;
vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), new Vector2(0.0f, 0.5f));
vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX);
vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(1.0f, 0.5f));
}
var comparer = new CompareCCW((verts[0] + verts[1] + verts[2]) / 3.0f);
Array.Sort(verts, vertPos, comparer);
for (int j = 0; j < 3; j++)
{
verticeList.Add(vertPos[j]);
}
}
}
}
return verticeList.ToArray();
}
/// <summary>
/// find the index of the cell which the point is inside
/// (actually finds the cell whose center is closest, but it's always the correct cell assuming the point is inside the borders of the diagram)
+5 -4
View File
@@ -440,11 +440,12 @@ namespace Barotrauma
List<VoronoiCell> cellsWithBody = new List<VoronoiCell>(cells);
List<VertexPositionTexture> bodyVertices;
bodies = CaveGenerator.GeneratePolygons(cellsWithBody, out bodyVertices);
List<Vector2[]> triangles;
bodies = CaveGenerator.GeneratePolygons(cellsWithBody, out triangles);
#if CLIENT
List<VertexPositionTexture> bodyVertices = CaveGenerator.GenerateRenderVerticeList(triangles);
renderer.SetBodyVertices(bodyVertices.ToArray());
renderer.SetWallVertices(CaveGenerator.GenerateWallShapes(cells));
@@ -714,7 +715,7 @@ namespace Barotrauma
}
}
var ruin = new Ruin(closestPathCell, cells, new Rectangle((ruinPos - ruinSize * 0.5f).ToPoint(), ruinSize.ToPoint()));
var ruin = new Ruin(closestPathCell, cells, new Rectangle(MathUtils.ToPoint(ruinPos - ruinSize * 0.5f), MathUtils.ToPoint(ruinSize)));
ruins.Add(ruin);
ruin.RuinShapes.Sort((shape1, shape2) => shape2.DistanceFromEntrance.CompareTo(shape1.DistanceFromEntrance));
@@ -1,7 +1,6 @@
using Barotrauma.Items.Components;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.IO;
@@ -157,7 +156,7 @@ namespace Barotrauma
linkedSub.loadSub = true;
linkedSub.rect.Location = pos.ToPoint();
linkedSub.rect.Location = MathUtils.ToPoint(pos);
}
linkedSub.filePath = ToolBox.GetAttributeString(element, "filepath", "");
-1
View File
@@ -6,7 +6,6 @@ using System.Xml.Linq;
using FarseerPhysics;
using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
using System.Collections.ObjectModel;
using Barotrauma.Items.Components;
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Barotrauma
{
@@ -152,7 +151,7 @@ namespace Barotrauma
if (Submarine.MainSub != null)
{
newRect.Location -= Submarine.MainSub.Position.ToPoint();
newRect.Location -= MathUtils.ToPoint(Submarine.MainSub.Position);
}
if (PlayerInput.LeftButtonReleased())
@@ -175,7 +175,7 @@ namespace Barotrauma
//don't allow resizing width/height to zero
if ((!resizeHorizontal || placeSize.X != 0.0f) && (!resizeVertical || placeSize.Y != 0.0f))
{
newRect.Location -= Submarine.MainSub.Position.ToPoint();
newRect.Location -= MathUtils.ToPoint(Submarine.MainSub.Position);
var structure = new Structure(newRect, this, Submarine.MainSub);
structure.Submarine = Submarine.MainSub;
+2 -2
View File
@@ -307,7 +307,7 @@ namespace Barotrauma
Rectangle dockedSubBorders = dockedSub.Borders;
dockedSubBorders.Y -= dockedSubBorders.Height;
dockedSubBorders.Location += diff.ToPoint();
dockedSubBorders.Location += MathUtils.ToPoint(diff);
dockedBorders = Rectangle.Union(dockedBorders, dockedSubBorders);
}
@@ -740,7 +740,7 @@ namespace Barotrauma
foreach (Submarine sub in Submarine.Loaded)
{
Rectangle subBorders = sub.Borders;
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Microsoft.Xna.Framework.Point(0, sub.Borders.Height);
subBorders.Location += MathUtils.ToPoint(sub.HiddenSubPosition) - new Microsoft.Xna.Framework.Point(0, sub.Borders.Height);
subBorders.Inflate(500.0f, 500.0f);
+2 -2
View File
@@ -238,7 +238,7 @@ namespace Barotrauma
if (Position.X < 0 || Position.X > Level.Loaded.Size.X)
{
Rectangle worldBorders = Borders;
worldBorders.Location += Position.ToPoint();
worldBorders.Location += MathUtils.ToPoint(Position);
//push the sub back below the upper "barrier" of the level
if (worldBorders.Y > Level.Loaded.Size.Y)
@@ -276,7 +276,7 @@ namespace Barotrauma
private void DisplaceCharacters(Vector2 subTranslation)
{
Rectangle worldBorders = Borders;
worldBorders.Location += ConvertUnits.ToDisplayUnits(Body.SimPosition).ToPoint();
worldBorders.Location += MathUtils.ToPoint(ConvertUnits.ToDisplayUnits(Body.SimPosition));
Vector2 translateDir = Vector2.Normalize(subTranslation);
+1 -2
View File
@@ -5,7 +5,6 @@ using System.Xml.Linq;
using FarseerPhysics;
using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
using System.Collections.ObjectModel;
using Barotrauma.Items.Components;
using FarseerPhysics.Dynamics;
@@ -181,7 +180,7 @@ namespace Barotrauma
borders.Width += outsideWaypointDist * 2;
borders.Height += outsideWaypointDist * 2;
borders.Location -= submarine.HiddenSubPosition.ToPoint();
borders.Location -= MathUtils.ToPoint(submarine.HiddenSubPosition);
if (borders.Width <= outSideWaypointInterval*2)
{