Lighting fixes & teleporting characters to sub
This commit is contained in:
Binary file not shown.
@@ -735,7 +735,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
Limb head = AnimController.GetLimb(LimbType.Head);
|
Limb head = AnimController.GetLimb(LimbType.Head);
|
||||||
|
|
||||||
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(head.SimPosition);
|
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(WorldPosition);
|
||||||
|
|
||||||
if (!DisableControls)
|
if (!DisableControls)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
Vector2[] corners = GetConvexHullCorners(doorRect);
|
Vector2[] corners = GetConvexHullCorners(doorRect);
|
||||||
|
|
||||||
convexHull = new ConvexHull(corners, Color.Black);
|
convexHull = new ConvexHull(corners, Color.Black, item.CurrentHull == null ? null : item.CurrentHull.Submarine);
|
||||||
if (window!=Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black);
|
if (window!=Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black, item.CurrentHull == null ? null : item.CurrentHull.Submarine);
|
||||||
|
|
||||||
UpdateConvexHulls();
|
UpdateConvexHulls();
|
||||||
|
|
||||||
@@ -303,7 +303,12 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (stuck>0.0f && weldedSprite!=null)
|
if (stuck>0.0f && weldedSprite!=null)
|
||||||
{
|
{
|
||||||
weldedSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y), Color.White*(stuck/100.0f), 0.0f, 1.0f);
|
Vector2 weldSpritePos = new Vector2(item.Rect.X, item.Rect.Y);
|
||||||
|
if (item.Submarine != null) weldSpritePos += item.Submarine.Position;
|
||||||
|
weldSpritePos.Y = -weldSpritePos.Y;
|
||||||
|
|
||||||
|
weldedSprite.Draw(spriteBatch,
|
||||||
|
weldSpritePos, Color.White*(stuck/100.0f), 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openState == 1.0f)
|
if (openState == 1.0f)
|
||||||
@@ -311,8 +316,12 @@ namespace Barotrauma.Items.Components
|
|||||||
body.Enabled = false;
|
body.Enabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteBatch.Draw(doorSprite.Texture, new Vector2(item.Rect.Center.X, -item.Rect.Y),
|
Vector2 pos = new Vector2(item.Rect.Center.X, -item.Rect.Y);
|
||||||
|
if (item.Submarine != null) pos += item.Submarine.Position;
|
||||||
|
pos.Y = -pos.Y;
|
||||||
|
|
||||||
|
spriteBatch.Draw(doorSprite.Texture, pos,
|
||||||
new Rectangle(doorSprite.SourceRect.X, (int)(doorSprite.size.Y * openState),
|
new Rectangle(doorSprite.SourceRect.X, (int)(doorSprite.size.Y * openState),
|
||||||
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
|
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
|
||||||
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
|
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace Barotrauma.Items.Components
|
|||||||
// break;
|
// break;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
light = new LightSource(item.Position, 100.0f, Color.White);
|
light = new LightSource(item.Position, 100.0f, Color.White, item.CurrentHull == null ? null : item.CurrentHull.Submarine);
|
||||||
|
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace Barotrauma
|
|||||||
public Submarine Submarine
|
public Submarine Submarine
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
protected set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AITarget AiTarget
|
public AITarget AiTarget
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
float displayRange = ConvertUnits.ToDisplayUnits(attack.Range);
|
float displayRange = ConvertUnits.ToDisplayUnits(attack.Range);
|
||||||
|
|
||||||
light = new LightSource(displayPosition, displayRange, Color.LightYellow);
|
light = new LightSource(displayPosition, displayRange, Color.LightYellow, hull != null ? hull.Submarine : null);
|
||||||
CoroutineManager.StartCoroutine(DimLight());
|
CoroutineManager.StartCoroutine(DimLight());
|
||||||
|
|
||||||
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, displayPosition)/2.0f;
|
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, displayPosition)/2.0f;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace Barotrauma
|
|||||||
fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg");
|
fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg");
|
||||||
}
|
}
|
||||||
|
|
||||||
lightSource = new LightSource(position, 50.0f, new Color(1.0f, 0.9f, 0.6f));
|
lightSource = new LightSource(position, 50.0f, new Color(1.0f, 0.9f, 0.6f), hull == null ? null : hull.Submarine);
|
||||||
|
|
||||||
hull.AddFireSource(this, !networkEvent);
|
hull.AddFireSource(this, !networkEvent);
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
private Dictionary<LightSource, CachedShadow> cachedShadows;
|
private Dictionary<LightSource, CachedShadow> cachedShadows;
|
||||||
|
|
||||||
|
private Vector2[] worldVertices;
|
||||||
private Vector2[] vertices;
|
private Vector2[] vertices;
|
||||||
private int primitiveCount;
|
private int primitiveCount;
|
||||||
|
|
||||||
@@ -38,6 +39,8 @@ namespace Barotrauma.Lights
|
|||||||
private VertexPositionColor[] shadowVertices;
|
private VertexPositionColor[] shadowVertices;
|
||||||
private VertexPositionTexture[] penumbraVertices;
|
private VertexPositionTexture[] penumbraVertices;
|
||||||
|
|
||||||
|
private Entity parentEntity;
|
||||||
|
|
||||||
private Rectangle boundingBox;
|
private Rectangle boundingBox;
|
||||||
|
|
||||||
public bool Enabled
|
public bool Enabled
|
||||||
@@ -51,7 +54,7 @@ namespace Barotrauma.Lights
|
|||||||
get { return boundingBox; }
|
get { return boundingBox; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConvexHull(Vector2[] points, Color color)
|
public ConvexHull(Vector2[] points, Color color, Entity parent)
|
||||||
{
|
{
|
||||||
if (shadowEffect == null)
|
if (shadowEffect == null)
|
||||||
{
|
{
|
||||||
@@ -67,9 +70,12 @@ namespace Barotrauma.Lights
|
|||||||
penumbraEffect.Texture = TextureLoader.FromFile("Content/Lights/penumbra.png");
|
penumbraEffect.Texture = TextureLoader.FromFile("Content/Lights/penumbra.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parentEntity = parent;
|
||||||
|
|
||||||
cachedShadows = new Dictionary<LightSource, CachedShadow>();
|
cachedShadows = new Dictionary<LightSource, CachedShadow>();
|
||||||
|
|
||||||
vertices = points;
|
vertices = points;
|
||||||
|
worldVertices = new Vector2[vertices.Length];
|
||||||
primitiveCount = vertices.Length;
|
primitiveCount = vertices.Length;
|
||||||
|
|
||||||
CalculateDimensions();
|
CalculateDimensions();
|
||||||
@@ -109,6 +115,7 @@ namespace Barotrauma.Lights
|
|||||||
for (int i = 0; i < vertices.Count(); i++)
|
for (int i = 0; i < vertices.Count(); i++)
|
||||||
{
|
{
|
||||||
vertices[i] += amount;
|
vertices[i] += amount;
|
||||||
|
worldVertices[i] += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalculateDimensions();
|
CalculateDimensions();
|
||||||
@@ -118,17 +125,26 @@ namespace Barotrauma.Lights
|
|||||||
{
|
{
|
||||||
cachedShadows.Clear();
|
cachedShadows.Clear();
|
||||||
|
|
||||||
|
worldVertices = points;
|
||||||
vertices = points;
|
vertices = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true)
|
private void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < vertices.Length; i++)
|
||||||
|
{
|
||||||
|
worldVertices[i] = vertices[i];
|
||||||
|
if (parentEntity != null && parentEntity.Submarine != null)
|
||||||
|
{
|
||||||
|
worldVertices[i] += parentEntity.Submarine.Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
//compute facing of each edge, using N*L
|
//compute facing of each edge, using N*L
|
||||||
for (int i = 0; i < primitiveCount; i++)
|
for (int i = 0; i < primitiveCount; i++)
|
||||||
{
|
{
|
||||||
Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y);
|
Vector2 firstVertex = new Vector2(worldVertices[i].X, worldVertices[i].Y);
|
||||||
int secondIndex = (i + 1) % primitiveCount;
|
int secondIndex = (i + 1) % primitiveCount;
|
||||||
Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y);
|
Vector2 secondVertex = new Vector2(worldVertices[secondIndex].X, worldVertices[secondIndex].Y);
|
||||||
Vector2 middle = (firstVertex + secondVertex) / 2;
|
Vector2 middle = (firstVertex + secondVertex) / 2;
|
||||||
|
|
||||||
Vector2 L = lightSourcePos - middle;
|
Vector2 L = lightSourcePos - middle;
|
||||||
@@ -171,7 +187,7 @@ namespace Barotrauma.Lights
|
|||||||
int svCount = 0;
|
int svCount = 0;
|
||||||
while (svCount != shadowVertexCount * 2)
|
while (svCount != shadowVertexCount * 2)
|
||||||
{
|
{
|
||||||
Vector3 vertexPos = new Vector3(vertices[currentIndex], 0.0f);
|
Vector3 vertexPos = new Vector3(worldVertices[currentIndex], 0.0f);
|
||||||
|
|
||||||
//one vertex on the hull
|
//one vertex on the hull
|
||||||
shadowVertices[svCount] = new VertexPositionColor();
|
shadowVertices[svCount] = new VertexPositionColor();
|
||||||
@@ -201,7 +217,7 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
for (int n = 0; n < 4; n += 3)
|
for (int n = 0; n < 4; n += 3)
|
||||||
{
|
{
|
||||||
Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex] : vertices[endingIndex], 0.0f);
|
Vector3 penumbraStart = new Vector3((n == 0) ? worldVertices[startingIndex] : worldVertices[endingIndex], 0.0f);
|
||||||
|
|
||||||
penumbraVertices[n] = new VertexPositionTexture();
|
penumbraVertices[n] = new VertexPositionTexture();
|
||||||
penumbraVertices[n].Position = penumbraStart;
|
penumbraVertices[n].Position = penumbraStart;
|
||||||
@@ -248,7 +264,7 @@ namespace Barotrauma.Lights
|
|||||||
if (cachedShadows.TryGetValue(light, out cachedShadow))
|
if (cachedShadows.TryGetValue(light, out cachedShadow))
|
||||||
{
|
{
|
||||||
if (light.Position == cachedShadow.LightPos ||
|
if (light.Position == cachedShadow.LightPos ||
|
||||||
Vector2.DistanceSquared(light.Position, cachedShadow.LightPos) < 1.0f)
|
Vector2.DistanceSquared(light.WorldPosition, cachedShadow.LightPos) < 1.0f)
|
||||||
{
|
{
|
||||||
shadowVertices = cachedShadow.ShadowVertices;
|
shadowVertices = cachedShadow.ShadowVertices;
|
||||||
penumbraVertices = cachedShadow.PenumbraVertices;
|
penumbraVertices = cachedShadow.PenumbraVertices;
|
||||||
@@ -256,8 +272,8 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CalculateShadowVertices(light.Position, los);
|
CalculateShadowVertices(light.WorldPosition, los);
|
||||||
cachedShadow.LightPos = light.Position;
|
cachedShadow.LightPos = light.WorldPosition;
|
||||||
cachedShadow.ShadowVertices = shadowVertices;
|
cachedShadow.ShadowVertices = shadowVertices;
|
||||||
cachedShadow.PenumbraVertices = penumbraVertices;
|
cachedShadow.PenumbraVertices = penumbraVertices;
|
||||||
|
|
||||||
@@ -266,7 +282,7 @@ namespace Barotrauma.Lights
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
CalculateShadowVertices(light.Position, los);
|
CalculateShadowVertices(light.Position, los);
|
||||||
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.Position);
|
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.WorldPosition);
|
||||||
cachedShadows.Add(light, cachedShadow);
|
cachedShadows.Add(light, cachedShadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
private Texture2D texture;
|
private Texture2D texture;
|
||||||
|
|
||||||
|
public Entity Submarine;
|
||||||
|
|
||||||
private Vector2 position;
|
private Vector2 position;
|
||||||
public Vector2 Position
|
public Vector2 Position
|
||||||
{
|
{
|
||||||
@@ -32,6 +34,11 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 WorldPosition
|
||||||
|
{
|
||||||
|
get { return (Submarine == null) ? position : position + Submarine.Position; }
|
||||||
|
}
|
||||||
|
|
||||||
public static Texture2D LightTexture
|
public static Texture2D LightTexture
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -64,10 +71,12 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LightSource(Vector2 position, float range, Color color)
|
public LightSource(Vector2 position, float range, Color color, Submarine submarine)
|
||||||
{
|
{
|
||||||
hullsInRange = new List<ConvexHull>();
|
hullsInRange = new List<ConvexHull>();
|
||||||
|
|
||||||
|
this.Submarine = submarine;
|
||||||
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.range = range;
|
this.range = range;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ namespace Barotrauma
|
|||||||
corners[2] = new Vector2(rect.Right, rect.Y);
|
corners[2] = new Vector2(rect.Right, rect.Y);
|
||||||
corners[3] = new Vector2(rect.Right, rect.Y - rect.Height);
|
corners[3] = new Vector2(rect.Right, rect.Y - rect.Height);
|
||||||
|
|
||||||
convexHull = new ConvexHull(corners, Color.Black);
|
convexHull = new ConvexHull(corners, Color.Black, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertToList();
|
InsertToList();
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using Microsoft.Xna.Framework;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Voronoi2;
|
using Voronoi2;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
@@ -32,7 +31,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private float depthDamageTimer;
|
private float depthDamageTimer;
|
||||||
|
|
||||||
private Submarine sub;
|
private Submarine submarine;
|
||||||
|
|
||||||
private Body body;
|
private Body body;
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public SubmarineBody(Submarine sub)
|
public SubmarineBody(Submarine sub)
|
||||||
{
|
{
|
||||||
this.sub = sub;
|
this.submarine = sub;
|
||||||
|
|
||||||
|
|
||||||
List<Vector2> convexHull = GenerateConvexHull();
|
List<Vector2> convexHull = GenerateConvexHull();
|
||||||
@@ -119,7 +118,7 @@ namespace Barotrauma
|
|||||||
body.BodyType = BodyType.Dynamic;
|
body.BodyType = BodyType.Dynamic;
|
||||||
|
|
||||||
body.CollisionCategories = Physics.CollisionMisc;
|
body.CollisionCategories = Physics.CollisionMisc;
|
||||||
body.CollidesWith = Physics.CollisionLevel;
|
body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter;
|
||||||
body.Restitution = 0.0f;
|
body.Restitution = 0.0f;
|
||||||
body.FixedRotation = true;
|
body.FixedRotation = true;
|
||||||
body.Awake = true;
|
body.Awake = true;
|
||||||
@@ -387,8 +386,14 @@ namespace Barotrauma
|
|||||||
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
|
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
|
||||||
if (cell == null)
|
if (cell == null)
|
||||||
{
|
{
|
||||||
lastContactCell = null;
|
Limb limb = f2.Body.UserData as Limb;
|
||||||
lastContactPoint = null;
|
if (limb!=null && limb.character.Submarine==null)
|
||||||
|
{
|
||||||
|
var ragdoll = limb.character.AnimController;
|
||||||
|
ragdoll.SetPosition(ragdoll.RefLimb.Position - body.Position);
|
||||||
|
limb.character.Submarine = submarine;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user