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);
|
||||
|
||||
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(head.SimPosition);
|
||||
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(WorldPosition);
|
||||
|
||||
if (!DisableControls)
|
||||
{
|
||||
|
||||
@@ -144,8 +144,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Vector2[] corners = GetConvexHullCorners(doorRect);
|
||||
|
||||
convexHull = new ConvexHull(corners, Color.Black);
|
||||
if (window!=Rectangle.Empty) convexHull2 = 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, item.CurrentHull == null ? null : item.CurrentHull.Submarine);
|
||||
|
||||
UpdateConvexHulls();
|
||||
|
||||
@@ -303,7 +303,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
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)
|
||||
@@ -311,8 +316,12 @@ namespace Barotrauma.Items.Components
|
||||
body.Enabled = false;
|
||||
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),
|
||||
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
|
||||
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace Barotrauma.Items.Components
|
||||
// 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;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Barotrauma
|
||||
public Submarine Submarine
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
set;
|
||||
}
|
||||
|
||||
public AITarget AiTarget
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Barotrauma
|
||||
|
||||
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());
|
||||
|
||||
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, displayPosition)/2.0f;
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Barotrauma
|
||||
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);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
private Dictionary<LightSource, CachedShadow> cachedShadows;
|
||||
|
||||
private Vector2[] worldVertices;
|
||||
private Vector2[] vertices;
|
||||
private int primitiveCount;
|
||||
|
||||
@@ -38,6 +39,8 @@ namespace Barotrauma.Lights
|
||||
private VertexPositionColor[] shadowVertices;
|
||||
private VertexPositionTexture[] penumbraVertices;
|
||||
|
||||
private Entity parentEntity;
|
||||
|
||||
private Rectangle boundingBox;
|
||||
|
||||
public bool Enabled
|
||||
@@ -51,7 +54,7 @@ namespace Barotrauma.Lights
|
||||
get { return boundingBox; }
|
||||
}
|
||||
|
||||
public ConvexHull(Vector2[] points, Color color)
|
||||
public ConvexHull(Vector2[] points, Color color, Entity parent)
|
||||
{
|
||||
if (shadowEffect == null)
|
||||
{
|
||||
@@ -67,9 +70,12 @@ namespace Barotrauma.Lights
|
||||
penumbraEffect.Texture = TextureLoader.FromFile("Content/Lights/penumbra.png");
|
||||
}
|
||||
|
||||
parentEntity = parent;
|
||||
|
||||
cachedShadows = new Dictionary<LightSource, CachedShadow>();
|
||||
|
||||
vertices = points;
|
||||
worldVertices = new Vector2[vertices.Length];
|
||||
primitiveCount = vertices.Length;
|
||||
|
||||
CalculateDimensions();
|
||||
@@ -109,6 +115,7 @@ namespace Barotrauma.Lights
|
||||
for (int i = 0; i < vertices.Count(); i++)
|
||||
{
|
||||
vertices[i] += amount;
|
||||
worldVertices[i] += amount;
|
||||
}
|
||||
|
||||
CalculateDimensions();
|
||||
@@ -118,17 +125,26 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
cachedShadows.Clear();
|
||||
|
||||
worldVertices = points;
|
||||
vertices = points;
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
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 L = lightSourcePos - middle;
|
||||
@@ -171,7 +187,7 @@ namespace Barotrauma.Lights
|
||||
int svCount = 0;
|
||||
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
|
||||
shadowVertices[svCount] = new VertexPositionColor();
|
||||
@@ -201,7 +217,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
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].Position = penumbraStart;
|
||||
@@ -248,7 +264,7 @@ namespace Barotrauma.Lights
|
||||
if (cachedShadows.TryGetValue(light, out cachedShadow))
|
||||
{
|
||||
if (light.Position == cachedShadow.LightPos ||
|
||||
Vector2.DistanceSquared(light.Position, cachedShadow.LightPos) < 1.0f)
|
||||
Vector2.DistanceSquared(light.WorldPosition, cachedShadow.LightPos) < 1.0f)
|
||||
{
|
||||
shadowVertices = cachedShadow.ShadowVertices;
|
||||
penumbraVertices = cachedShadow.PenumbraVertices;
|
||||
@@ -256,8 +272,8 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
else
|
||||
{
|
||||
CalculateShadowVertices(light.Position, los);
|
||||
cachedShadow.LightPos = light.Position;
|
||||
CalculateShadowVertices(light.WorldPosition, los);
|
||||
cachedShadow.LightPos = light.WorldPosition;
|
||||
cachedShadow.ShadowVertices = shadowVertices;
|
||||
cachedShadow.PenumbraVertices = penumbraVertices;
|
||||
|
||||
@@ -266,7 +282,7 @@ namespace Barotrauma.Lights
|
||||
else
|
||||
{
|
||||
CalculateShadowVertices(light.Position, los);
|
||||
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.Position);
|
||||
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.WorldPosition);
|
||||
cachedShadows.Add(light, cachedShadow);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Barotrauma.Lights
|
||||
|
||||
private Texture2D texture;
|
||||
|
||||
public Entity Submarine;
|
||||
|
||||
private 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
|
||||
{
|
||||
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>();
|
||||
|
||||
this.Submarine = submarine;
|
||||
|
||||
this.position = position;
|
||||
this.range = range;
|
||||
this.color = color;
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace Barotrauma
|
||||
corners[2] = new Vector2(rect.Right, rect.Y);
|
||||
corners[3] = new Vector2(rect.Right, rect.Y - rect.Height);
|
||||
|
||||
convexHull = new ConvexHull(corners, Color.Black);
|
||||
convexHull = new ConvexHull(corners, Color.Black, this);
|
||||
}
|
||||
|
||||
InsertToList();
|
||||
|
||||
@@ -9,7 +9,6 @@ using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Voronoi2;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -32,7 +31,7 @@ namespace Barotrauma
|
||||
|
||||
private float depthDamageTimer;
|
||||
|
||||
private Submarine sub;
|
||||
private Submarine submarine;
|
||||
|
||||
private Body body;
|
||||
|
||||
@@ -88,7 +87,7 @@ namespace Barotrauma
|
||||
|
||||
public SubmarineBody(Submarine sub)
|
||||
{
|
||||
this.sub = sub;
|
||||
this.submarine = sub;
|
||||
|
||||
|
||||
List<Vector2> convexHull = GenerateConvexHull();
|
||||
@@ -119,7 +118,7 @@ namespace Barotrauma
|
||||
body.BodyType = BodyType.Dynamic;
|
||||
|
||||
body.CollisionCategories = Physics.CollisionMisc;
|
||||
body.CollidesWith = Physics.CollisionLevel;
|
||||
body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter;
|
||||
body.Restitution = 0.0f;
|
||||
body.FixedRotation = true;
|
||||
body.Awake = true;
|
||||
@@ -387,8 +386,14 @@ namespace Barotrauma
|
||||
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
|
||||
if (cell == null)
|
||||
{
|
||||
lastContactCell = null;
|
||||
lastContactPoint = null;
|
||||
Limb limb = f2.Body.UserData as Limb;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user