v0.10.5.1
This commit is contained in:
@@ -14,7 +14,7 @@ namespace Barotrauma
|
||||
Vector2.Zero, 0.0f, hull);
|
||||
}
|
||||
|
||||
hull = hull ?? Hull.FindHull(worldPosition, useWorldCoordinates: true);
|
||||
hull ??= Hull.FindHull(worldPosition, useWorldCoordinates: true);
|
||||
bool underwater = hull == null || worldPosition.Y < hull.WorldSurface;
|
||||
|
||||
if (underwater && underwaterBubble)
|
||||
@@ -44,7 +44,7 @@ namespace Barotrauma
|
||||
}
|
||||
if (smoke)
|
||||
{
|
||||
var smokeParticle = GameMain.ParticleManager.CreateParticle(Rand.Range(0.0f, 1.0f) < 0.5f ? "explosionsmoke" : "smoke",
|
||||
GameMain.ParticleManager.CreateParticle(Rand.Range(0.0f, 1.0f) < 0.5f ? "explosionsmoke" : "smoke",
|
||||
ClampParticlePos(worldPosition + Rand.Vector((float)System.Math.Sqrt(Rand.Range(0.0f, attack.Range))), hull),
|
||||
Rand.Vector(Rand.Range(0.0f, particleSpeed)), 0.0f, hull);
|
||||
}
|
||||
@@ -75,11 +75,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (hull != null && !string.IsNullOrWhiteSpace(decal) && decalSize > 0.0f)
|
||||
{
|
||||
hull.AddDecal(decal, worldPosition, decalSize);
|
||||
}
|
||||
|
||||
if (flash)
|
||||
{
|
||||
float displayRange = flashRange.HasValue ? flashRange.Value : attack.Range;
|
||||
|
||||
@@ -12,35 +12,10 @@ namespace Barotrauma
|
||||
partial void UpdateProjSpecific(float growModifier)
|
||||
{
|
||||
EmitParticles(size, WorldPosition, hull, growModifier, OnChangeHull);
|
||||
|
||||
|
||||
lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f);
|
||||
if (Math.Abs((lightSource.Range * 0.2f) - Math.Max(size.X, size.Y)) > 1.0f) lightSource.Range = Math.Max(size.X, size.Y) * 5.0f;
|
||||
if (Vector2.DistanceSquared(lightSource.Position,position) > 5.0f) lightSource.Position = position + Vector2.UnitY * 30.0f;
|
||||
|
||||
if (size.X > 256.0f)
|
||||
{
|
||||
if (burnDecals.Count == 0)
|
||||
{
|
||||
var newDecal = hull.AddDecal("burnt", WorldPosition + size/2);
|
||||
if (newDecal != null) burnDecals.Add(newDecal);
|
||||
}
|
||||
else if (WorldPosition.X < burnDecals[0].WorldPosition.X - 256.0f)
|
||||
{
|
||||
var newDecal = hull.AddDecal("burnt", WorldPosition);
|
||||
if (newDecal != null) burnDecals.Insert(0, newDecal);
|
||||
}
|
||||
else if (WorldPosition.X + size.X > burnDecals[burnDecals.Count-1].WorldPosition.X + 256.0f)
|
||||
{
|
||||
var newDecal = hull.AddDecal("burnt", WorldPosition + Vector2.UnitX * size.X);
|
||||
if (newDecal != null) burnDecals.Add(newDecal);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Decal d in burnDecals)
|
||||
{
|
||||
//prevent the decals from fading out as long as the firesource is alive
|
||||
d.FadeTimer = Math.Min(d.FadeTimer, d.FadeInTime);
|
||||
}
|
||||
if (Vector2.DistanceSquared(lightSource.Position, position) > 5.0f) lightSource.Position = position + Vector2.UnitY * 30.0f;
|
||||
}
|
||||
|
||||
public static void EmitParticles(Vector2 size, Vector2 worldPosition, Hull hull, float growModifier, Particle.OnChangeHullHandler onChangeHull = null)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.Particles;
|
||||
using Barotrauma.Sounds;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
@@ -12,16 +10,10 @@ namespace Barotrauma
|
||||
{
|
||||
partial class Hull : MapEntity, ISerializableEntity, IServerSerializable, IClientSerializable
|
||||
{
|
||||
public const int MaxDecalsPerHull = 10;
|
||||
|
||||
private readonly List<Decal> decals = new List<Decal>();
|
||||
|
||||
private float serverUpdateDelay;
|
||||
private float remoteWaterVolume, remoteOxygenPercentage;
|
||||
private List<Vector3> remoteFireSources;
|
||||
|
||||
private bool networkUpdatePending;
|
||||
private float networkUpdateTimer;
|
||||
private readonly List<BackgroundSection> remoteBackgroundSections = new List<BackgroundSection>();
|
||||
|
||||
private double lastAmbientLightEditTime;
|
||||
|
||||
@@ -49,11 +41,14 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private float paintAmount = 0.0f;
|
||||
private float minimumPaintAmountToDraw;
|
||||
|
||||
public override bool IsVisible(Rectangle worldView)
|
||||
{
|
||||
if (Screen.Selected != GameMain.SubEditorScreen && !GameMain.DebugDraw)
|
||||
{
|
||||
if (decals.Count == 0) { return false; }
|
||||
if (decals.Count == 0 && paintAmount < minimumPaintAmountToDraw) { return false; }
|
||||
|
||||
Rectangle worldRect = WorldRect;
|
||||
if (worldRect.X > worldView.Right || worldRect.Right < worldView.X) { return false; }
|
||||
@@ -70,20 +65,6 @@ namespace Barotrauma
|
||||
!Submarine.RectContains(MathUtils.ExpandRect(WorldRect, -8), position));
|
||||
}
|
||||
|
||||
public Decal AddDecal(string decalName, Vector2 worldPosition, float scale = 1.0f)
|
||||
{
|
||||
if (decals.Count >= MaxDecalsPerHull) return null;
|
||||
|
||||
var decal = GameMain.DecalManager.CreateDecal(decalName, scale, worldPosition, this);
|
||||
|
||||
if (decal != null)
|
||||
{
|
||||
decals.Add(decal);
|
||||
}
|
||||
|
||||
return decal;
|
||||
}
|
||||
|
||||
private GUIComponent CreateEditingHUD(bool inGame = false)
|
||||
{
|
||||
editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight) { MinSize = new Point(400, 0) }) { UserData = this };
|
||||
@@ -101,39 +82,32 @@ namespace Barotrauma
|
||||
{
|
||||
editingHUD = CreateEditingHUD(Screen.Selected != GameMain.SubEditorScreen);
|
||||
}
|
||||
|
||||
if (!PlayerInput.KeyDown(Keys.Space)) return;
|
||||
|
||||
if (!PlayerInput.KeyDown(Keys.Space)) { return; }
|
||||
bool lClick = PlayerInput.PrimaryMouseButtonClicked();
|
||||
bool rClick = PlayerInput.SecondaryMouseButtonClicked();
|
||||
if (!lClick && !rClick) return;
|
||||
if (!lClick && !rClick) { return; }
|
||||
|
||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
|
||||
if (lClick)
|
||||
foreach (MapEntity entity in mapEntityList)
|
||||
{
|
||||
foreach (MapEntity entity in mapEntityList)
|
||||
if (entity == this || !entity.IsHighlighted) { continue; }
|
||||
if (!entity.IsMouseOn(position)) { continue; }
|
||||
if (entity.linkedTo != null && entity.linkedTo.Contains(this))
|
||||
{
|
||||
if (entity == this || !entity.IsHighlighted) continue;
|
||||
if (!entity.IsMouseOn(position)) continue;
|
||||
if (entity.Linkable && entity.linkedTo != null)
|
||||
if (entity.Linkable && entity.linkedTo != null && !entity.linkedTo.Contains(this))
|
||||
{
|
||||
entity.linkedTo.Add(this);
|
||||
linkedTo.Add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (MapEntity entity in mapEntityList)
|
||||
else if (entity.Linkable && entity.linkedTo != null)
|
||||
{
|
||||
if (entity == this || !entity.IsHighlighted) continue;
|
||||
if (!entity.IsMouseOn(position)) continue;
|
||||
if (entity.linkedTo != null && entity.linkedTo.Contains(this))
|
||||
{
|
||||
entity.linkedTo.Remove(this);
|
||||
linkedTo.Remove(entity);
|
||||
|
||||
}
|
||||
entity.linkedTo.Add(this);
|
||||
linkedTo.Add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,7 +125,15 @@ namespace Barotrauma
|
||||
networkUpdateTimer += deltaTime;
|
||||
if (networkUpdateTimer > 0.2f)
|
||||
{
|
||||
GameMain.NetworkMember?.CreateEntityEvent(this);
|
||||
if (!pendingSectionUpdates.Any())
|
||||
{
|
||||
GameMain.NetworkMember?.CreateEntityEvent(this);
|
||||
}
|
||||
foreach (int pendingSectionUpdate in pendingSectionUpdates)
|
||||
{
|
||||
GameMain.NetworkMember?.CreateEntityEvent(this, new object[] { pendingSectionUpdate });
|
||||
}
|
||||
pendingSectionUpdates.Clear();
|
||||
networkUpdatePending = false;
|
||||
networkUpdateTimer = 0.0f;
|
||||
}
|
||||
@@ -189,14 +171,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Decal decal in decals)
|
||||
{
|
||||
decal.Update(deltaTime);
|
||||
}
|
||||
|
||||
decals.RemoveAll(d => d.FadeTimer >= d.LifeTime);
|
||||
|
||||
|
||||
if (waterVolume < 1.0f) return;
|
||||
for (int i = 1; i < waveY.Length - 1; i++)
|
||||
{
|
||||
@@ -324,6 +299,35 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawSectionColors(SpriteBatch spriteBatch)
|
||||
{
|
||||
Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
|
||||
Point sectionSize = BackgroundSections[0].Rect.Size;
|
||||
Vector2 drawPos = drawOffset + new Vector2(rect.Location.X + sectionSize.X / 2, rect.Location.Y - sectionSize.Y / 2);
|
||||
|
||||
for (int i = 0; i < BackgroundSections.Count; i++)
|
||||
{
|
||||
BackgroundSection section = BackgroundSections[i];
|
||||
|
||||
if (section.ColorStrength < 0.01f || section.Color.A < 1) { continue; }
|
||||
|
||||
if (GameMain.DecalManager.GrimeSprites.Count == 0)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(drawOffset.X + rect.X + section.Rect.X, -(drawOffset.Y + rect.Y + section.Rect.Y)),
|
||||
new Vector2(sectionSize.X, sectionSize.Y),
|
||||
section.GetStrengthAdjustedColor(), true, 0.0f, (int)Math.Max(1.5f / Screen.Selected.Cam.Zoom, 1.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 sectionPos = new Vector2(drawPos.X + section.Rect.Location.X, -(drawPos.Y + section.Rect.Location.Y));
|
||||
Vector2 randomOffset = new Vector2(section.Noise.X - 0.5f, section.Noise.Y - 0.5f) * 15.0f;
|
||||
var sprite = GameMain.DecalManager.GrimeSprites[i % GameMain.DecalManager.GrimeSprites.Count];
|
||||
sprite.Draw(spriteBatch, sectionPos + randomOffset, section.GetStrengthAdjustedColor(), scale: 1.25f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateVertices(Camera cam, WaterRenderer renderer)
|
||||
{
|
||||
foreach (EntityGrid entityGrid in EntityGrids)
|
||||
@@ -526,22 +530,38 @@ namespace Barotrauma
|
||||
|
||||
public void ClientWrite(IWriteMessage msg, object[] extraData = null)
|
||||
{
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8);
|
||||
|
||||
msg.Write(FireSources.Count > 0);
|
||||
if (FireSources.Count > 0)
|
||||
msg.Write(extraData != null);
|
||||
if (extraData == null)
|
||||
{
|
||||
msg.WriteRangedInteger(Math.Min(FireSources.Count, 16), 0, 16);
|
||||
for (int i = 0; i < Math.Min(FireSources.Count, 16); i++)
|
||||
{
|
||||
var fireSource = FireSources[i];
|
||||
Vector2 normalizedPos = new Vector2(
|
||||
(fireSource.Position.X - rect.X) / rect.Width,
|
||||
(fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height);
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8);
|
||||
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 8);
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 8);
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8);
|
||||
msg.Write(FireSources.Count > 0);
|
||||
if (FireSources.Count > 0)
|
||||
{
|
||||
msg.WriteRangedInteger(Math.Min(FireSources.Count, 16), 0, 16);
|
||||
for (int i = 0; i < Math.Min(FireSources.Count, 16); i++)
|
||||
{
|
||||
var fireSource = FireSources[i];
|
||||
Vector2 normalizedPos = new Vector2(
|
||||
(fireSource.Position.X - rect.X) / rect.Width,
|
||||
(fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height);
|
||||
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 8);
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 8);
|
||||
msg.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int sectorToUpdate = (int)extraData[0];
|
||||
int start = sectorToUpdate * BackgroundSectionsPerNetworkEvent;
|
||||
int end = Math.Min((sectorToUpdate + 1) * BackgroundSectionsPerNetworkEvent, BackgroundSections.Count - 1);
|
||||
msg.WriteRangedInteger(sectorToUpdate, 0, BackgroundSections.Count - 1);
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
msg.WriteRangedSingle(BackgroundSections[i].ColorStrength, 0.0f, 1.0f, 8);
|
||||
msg.Write(BackgroundSections[i].Color.PackedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -565,6 +585,54 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
bool hasExtraData = message.ReadBoolean();
|
||||
if (hasExtraData)
|
||||
{
|
||||
bool hasSectionUpdate = message.ReadBoolean();
|
||||
if (hasSectionUpdate)
|
||||
{
|
||||
int sectorToUpdate = message.ReadRangedInteger(0, BackgroundSections.Count - 1);
|
||||
int start = sectorToUpdate * BackgroundSectionsPerNetworkEvent;
|
||||
int end = Math.Min((sectorToUpdate + 1) * BackgroundSectionsPerNetworkEvent, BackgroundSections.Count - 1);
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
float colorStrength = message.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
Color color = new Color(message.ReadUInt32());
|
||||
float prevColorStrength = BackgroundSections[i].ColorStrength;
|
||||
BackgroundSections[i].SetColorStrength(colorStrength);
|
||||
BackgroundSections[i].SetColor(color);
|
||||
paintAmount = Math.Max(0, paintAmount + (BackgroundSections[i].ColorStrength - prevColorStrength) / BackgroundSections.Count);
|
||||
|
||||
var remoteBackgroundSection = remoteBackgroundSections.Find(s => s.Index == i);
|
||||
if (remoteBackgroundSection != null)
|
||||
{
|
||||
remoteBackgroundSection.SetColorStrength(colorStrength);
|
||||
remoteBackgroundSection.SetColor(color);
|
||||
}
|
||||
else
|
||||
{
|
||||
remoteBackgroundSections.Add(new BackgroundSection(new Rectangle(0, 0, 1, 1), i, colorStrength, color, 0));
|
||||
}
|
||||
}
|
||||
paintAmount = BackgroundSections.Sum(s => s.ColorStrength);
|
||||
}
|
||||
else
|
||||
{
|
||||
int decalCount = message.ReadRangedInteger(0, MaxDecalsPerHull);
|
||||
decals.Clear();
|
||||
for (int i = 0; i < decalCount; i++)
|
||||
{
|
||||
UInt32 decalId = message.ReadUInt32();
|
||||
float normalizedXPos = message.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
float normalizedYPos = message.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
float decalPosX = MathHelper.Lerp(rect.X, rect.Right, normalizedXPos);
|
||||
float decalPosY = MathHelper.Lerp(rect.Y - rect.Height, rect.Y, normalizedYPos);
|
||||
float decalScale = message.ReadRangedSingle(0.0f, 2.0f, 12);
|
||||
AddDecal(decalId, new Vector2(decalPosX, decalPosY), decalScale, isNetworkEvent: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (serverUpdateDelay > 0.0f) { return; }
|
||||
|
||||
ApplyRemoteState();
|
||||
@@ -572,10 +640,14 @@ namespace Barotrauma
|
||||
|
||||
private void ApplyRemoteState()
|
||||
{
|
||||
if (remoteFireSources == null)
|
||||
foreach (BackgroundSection remoteBackgroundSection in remoteBackgroundSections)
|
||||
{
|
||||
return;
|
||||
BackgroundSections[remoteBackgroundSection.Index].SetColor(remoteBackgroundSection.Color);
|
||||
BackgroundSections[remoteBackgroundSection.Index].SetColorStrength(remoteBackgroundSection.ColorStrength);
|
||||
}
|
||||
remoteBackgroundSections.Clear();
|
||||
|
||||
if (remoteFireSources == null) { return; }
|
||||
|
||||
WaterVolume = remoteWaterVolume;
|
||||
OxygenPercentage = remoteOxygenPercentage;
|
||||
@@ -609,7 +681,6 @@ namespace Barotrauma
|
||||
FireSources.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
remoteFireSources = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace Barotrauma
|
||||
public const int DefaultBufferSize = 2000;
|
||||
public const int DefaultIndoorsBufferSize = 3000;
|
||||
|
||||
public static Vector2 DistortionScale = new Vector2(2f, 2f);
|
||||
public static Vector2 DistortionStrength = new Vector2(0.25f, 0.25f);
|
||||
public static Vector2 DistortionScale = new Vector2(2f, 1.5f);
|
||||
public static Vector2 DistortionStrength = new Vector2(0.01f, 0.33f);
|
||||
public static float BlurAmount = 0.0f;
|
||||
|
||||
public Vector2 WavePos
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Barotrauma.Items.Components;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using SharpFont;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -87,6 +88,12 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
class VectorPair
|
||||
{
|
||||
public Vector2? A = null;
|
||||
public Vector2? B = null;
|
||||
}
|
||||
|
||||
class ConvexHull
|
||||
{
|
||||
public static List<ConvexHullList> HullLists = new List<ConvexHullList>();
|
||||
@@ -96,6 +103,7 @@ namespace Barotrauma.Lights
|
||||
private readonly Segment[] segments = new Segment[4];
|
||||
private readonly SegmentPoint[] vertices = new SegmentPoint[4];
|
||||
private readonly SegmentPoint[] losVertices = new SegmentPoint[4];
|
||||
private readonly VectorPair[] losOffsets = new VectorPair[4];
|
||||
|
||||
private readonly bool[] backFacing;
|
||||
private readonly bool[] ignoreEdge;
|
||||
@@ -105,6 +113,7 @@ namespace Barotrauma.Lights
|
||||
public VertexPositionColor[] ShadowVertices { get; private set; }
|
||||
public VertexPositionTexture[] PenumbraVertices { get; private set; }
|
||||
public int ShadowVertexCount { get; private set; }
|
||||
public int PenumbraVertexCount { get; private set; }
|
||||
|
||||
private readonly HashSet<ConvexHull> overlappingHulls = new HashSet<ConvexHull>();
|
||||
|
||||
@@ -157,15 +166,24 @@ namespace Barotrauma.Lights
|
||||
|
||||
ParentEntity = parent;
|
||||
|
||||
ShadowVertices = new VertexPositionColor[6 * 2];
|
||||
PenumbraVertices = new VertexPositionTexture[6];
|
||||
ShadowVertices = new VertexPositionColor[6 * 4];
|
||||
PenumbraVertices = new VertexPositionTexture[6 * 4];
|
||||
|
||||
backFacing = new bool[4];
|
||||
ignoreEdge = new bool[4];
|
||||
|
||||
SetVertices(points);
|
||||
|
||||
Enabled = true;
|
||||
float minX = points[0].X, minY = points[0].Y, maxX = points[0].X, maxY = points[0].Y;
|
||||
|
||||
for (int i = 1; i < vertices.Length; i++)
|
||||
{
|
||||
if (points[i].X < minX) minX = points[i].X;
|
||||
if (points[i].Y < minY) minY = points[i].Y;
|
||||
|
||||
if (points[i].X > maxX) maxX = points[i].X;
|
||||
if (points[i].Y > minY) maxY = points[i].Y;
|
||||
}
|
||||
|
||||
BoundingBox = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
|
||||
|
||||
isHorizontal = BoundingBox.Width > BoundingBox.Height;
|
||||
if (ParentEntity is Structure structure)
|
||||
@@ -180,6 +198,10 @@ namespace Barotrauma.Lights
|
||||
if (door != null) { isHorizontal = door.IsHorizontal; }
|
||||
}
|
||||
|
||||
SetVertices(points);
|
||||
|
||||
Enabled = true;
|
||||
|
||||
var chList = HullLists.Find(h => h.Submarine == parent.Submarine);
|
||||
if (chList == null)
|
||||
{
|
||||
@@ -202,11 +224,17 @@ namespace Barotrauma.Lights
|
||||
|
||||
if (isHorizontal == ch.isHorizontal)
|
||||
{
|
||||
if (BoundingBox == ch.BoundingBox) { return; }
|
||||
|
||||
//hide segments that are roughly at the some position as some other segment (e.g. the ends of two adjacent wall pieces)
|
||||
float mergeDist = 32;
|
||||
float mergeDist = 16;
|
||||
float mergeDistSqr = mergeDist * mergeDist;
|
||||
|
||||
Rectangle intersection = Rectangle.Intersect(BoundingBox, ch.BoundingBox);
|
||||
int intersectionArea = intersection.Width * intersection.Height;
|
||||
int bboxArea = BoundingBox.Width * BoundingBox.Height;
|
||||
int otherBboxArea = ch.BoundingBox.Width * ch.BoundingBox.Height;
|
||||
if (Math.Abs(intersectionArea - bboxArea) < mergeDistSqr) { return; }
|
||||
if (Math.Abs(intersectionArea - otherBboxArea) < mergeDistSqr) { return; }
|
||||
|
||||
for (int i = 0; i < segments.Length; i++)
|
||||
{
|
||||
for (int j = 0; j < ch.segments.Length; j++)
|
||||
@@ -237,21 +265,67 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
for (int i = 0; i < segments.Length; i++)
|
||||
{
|
||||
//TODO: do something to corner areas where a vertical wall meets a horizontal one
|
||||
if (ignoreEdge[i]) { continue; }
|
||||
if (Vector2.DistanceSquared(segments[i].Start.Pos, segments[i].End.Pos) < 1.0f) { continue; }
|
||||
for (int j = 0; j < ch.segments.Length; j++)
|
||||
{
|
||||
if (ch.ignoreEdge[j]) { continue; }
|
||||
if (Vector2.DistanceSquared(ch.segments[j].Start.Pos, ch.segments[j].End.Pos) < 1.0f) { continue; }
|
||||
if (IsSegmentAInB(segments[i], ch.segments[j]))
|
||||
{
|
||||
ignoreEdge[i] = true;
|
||||
if (Vector2.DistanceSquared(ch.segments[j].Start.Pos, segments[i].Start.Pos) < 4.0f)
|
||||
{
|
||||
ch.ShiftSegmentPoint(j, false, segments[i].End.Pos);
|
||||
}
|
||||
else if (Vector2.DistanceSquared(ch.segments[j].Start.Pos, segments[i].End.Pos) < 4.0f)
|
||||
{
|
||||
ch.ShiftSegmentPoint(j, false, segments[i].Start.Pos);
|
||||
}
|
||||
|
||||
if (Vector2.DistanceSquared(ch.segments[j].End.Pos, segments[i].Start.Pos) < 4.0f)
|
||||
{
|
||||
ch.ShiftSegmentPoint(j, true, segments[i].End.Pos);
|
||||
}
|
||||
else if (Vector2.DistanceSquared(ch.segments[j].End.Pos, segments[i].End.Pos) < 4.0f)
|
||||
{
|
||||
ch.ShiftSegmentPoint(j, true, segments[i].Start.Pos);
|
||||
}
|
||||
}
|
||||
else if (IsSegmentAInB(ch.segments[j], segments[i]))
|
||||
{
|
||||
ch.ignoreEdge[j] = true;
|
||||
|
||||
if (Vector2.DistanceSquared(segments[i].Start.Pos, ch.segments[j].Start.Pos) < 4.0f)
|
||||
{
|
||||
ShiftSegmentPoint(i, false, ch.segments[j].End.Pos);
|
||||
}
|
||||
else if (Vector2.DistanceSquared(segments[i].Start.Pos, ch.segments[j].End.Pos) < 4.0f)
|
||||
{
|
||||
ShiftSegmentPoint(i, false, ch.segments[j].Start.Pos);
|
||||
}
|
||||
|
||||
if (Vector2.DistanceSquared(segments[i].End.Pos, ch.segments[j].Start.Pos) < 4.0f)
|
||||
{
|
||||
ShiftSegmentPoint(i, true, ch.segments[j].End.Pos);
|
||||
}
|
||||
else if (Vector2.DistanceSquared(segments[i].End.Pos, ch.segments[j].End.Pos) < 4.0f)
|
||||
{
|
||||
ShiftSegmentPoint(i, true, ch.segments[j].Start.Pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ignore edges that are inside some other convex hull
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
if (vertices[i].Pos.X >= ch.BoundingBox.X && vertices[i].Pos.X <= ch.BoundingBox.Right &&
|
||||
vertices[i].Pos.Y >= ch.BoundingBox.Y && vertices[i].Pos.Y <= ch.BoundingBox.Bottom)
|
||||
if (ch.IsPointInside(vertices[i].Pos))
|
||||
{
|
||||
Vector2 p = vertices[(i + 1) % vertices.Length].Pos;
|
||||
|
||||
if (p.X >= ch.BoundingBox.X && p.X <= ch.BoundingBox.Right &&
|
||||
p.Y >= ch.BoundingBox.Y && p.Y <= ch.BoundingBox.Bottom)
|
||||
if (ch.IsPointInside(vertices[(i + 1) % vertices.Length].Pos))
|
||||
{
|
||||
ignoreEdge[i] = true;
|
||||
overlappingHulls.Add(ch);
|
||||
@@ -260,6 +334,75 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
private void ShiftSegmentPoint(int segmentIndex, bool end, Vector2 newPos)
|
||||
{
|
||||
var segment = segments[segmentIndex];
|
||||
|
||||
losOffsets[segmentIndex] ??= new VectorPair();
|
||||
bool flipped = false;
|
||||
if (Vector2.DistanceSquared(vertices[segmentIndex].Pos, segment.Start.Pos) > Vector2.DistanceSquared(vertices[segmentIndex].Pos, segment.End.Pos))
|
||||
{
|
||||
flipped = true;
|
||||
}
|
||||
if (end == !flipped)
|
||||
{
|
||||
losOffsets[segmentIndex].B = newPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
losOffsets[segmentIndex].A = newPos;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSegmentAInB(Segment a, Segment b)
|
||||
{
|
||||
if (Vector2.DistanceSquared(a.Start.Pos, a.End.Pos) > Vector2.DistanceSquared(b.Start.Pos, b.End.Pos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector2 min = new Vector2(Math.Min(b.Start.Pos.X, b.End.Pos.X), Math.Min(b.Start.Pos.Y, b.End.Pos.Y));
|
||||
Vector2 max = new Vector2(Math.Max(b.Start.Pos.X, b.End.Pos.X), Math.Max(b.Start.Pos.Y, b.End.Pos.Y));
|
||||
min.X -= 1.0f; min.Y -= 1.0f;
|
||||
max.X += 1.0f; max.Y += 1.0f;
|
||||
|
||||
if (a.Start.Pos.X < min.X) { return false; }
|
||||
if (a.Start.Pos.Y < min.Y) { return false; }
|
||||
if (a.End.Pos.X < min.X) { return false; }
|
||||
if (a.End.Pos.Y < min.Y) { return false; }
|
||||
|
||||
if (a.Start.Pos.X > max.X) { return false; }
|
||||
if (a.Start.Pos.Y > max.Y) { return false; }
|
||||
if (a.End.Pos.X > max.X) { return false; }
|
||||
if (a.End.Pos.Y > max.Y) { return false; }
|
||||
|
||||
float startDist = MathUtils.LineToPointDistanceSquared(b.Start.Pos, b.End.Pos, a.Start.Pos);
|
||||
if (startDist > 1.0f) { return false; }
|
||||
float endDist = MathUtils.LineToPointDistanceSquared(b.Start.Pos, b.End.Pos, a.End.Pos);
|
||||
if (endDist > 1.0f) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsPointInside(Vector2 point)
|
||||
{
|
||||
if (!BoundingBox.Contains(point)) { return false; }
|
||||
|
||||
Vector2 center = (vertices[0].Pos + vertices[1].Pos + vertices[2].Pos + vertices[3].Pos) * 0.25f;
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
Vector2 segmentVector = vertices[(i + 1) % 4].Pos - vertices[i].Pos;
|
||||
Vector2 centerToVertex = center - vertices[i].Pos;
|
||||
Vector2 pointToVertex = point - vertices[i].Pos;
|
||||
|
||||
float dotCenter = Vector2.Dot(centerToVertex, segmentVector);
|
||||
float dotPoint = Vector2.Dot(pointToVertex, segmentVector);
|
||||
|
||||
if ((dotCenter > 0f && dotPoint < 0f) || (dotCenter < 0f && dotPoint > 0f)) { return false; }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void MergeSegments(Segment segment1, Segment segment2, bool startPointsMatch)
|
||||
{
|
||||
int startPointIndex = -1, endPointIndex = -1;
|
||||
@@ -344,6 +487,8 @@ namespace Barotrauma.Lights
|
||||
vertices[i].Pos += amount;
|
||||
losVertices[i].Pos += amount;
|
||||
|
||||
losOffsets[i] = null;
|
||||
|
||||
segments[i].Start.Pos += amount;
|
||||
segments[i].End.Pos += amount;
|
||||
}
|
||||
@@ -406,6 +551,7 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
vertices[i] = new SegmentPoint(points[i], this);
|
||||
losVertices[i] = new SegmentPoint(points[i], this);
|
||||
losOffsets[i] = null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
@@ -517,7 +663,7 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
public void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true)
|
||||
public void CalculateLosVertices(Vector2 lightSourcePos)
|
||||
{
|
||||
Vector3 offset = Vector3.Zero;
|
||||
if (ParentEntity != null && ParentEntity.Submarine != null)
|
||||
@@ -527,8 +673,6 @@ namespace Barotrauma.Lights
|
||||
|
||||
ShadowVertexCount = 0;
|
||||
|
||||
var vertices = los ? losVertices : this.vertices;
|
||||
|
||||
//compute facing of each edge, using N*L
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
@@ -538,8 +682,8 @@ namespace Barotrauma.Lights
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector2 firstVertex = vertices[i].Pos;
|
||||
Vector2 secondVertex = vertices[(i+1) % 4].Pos;
|
||||
Vector2 firstVertex = losVertices[i].Pos;
|
||||
Vector2 secondVertex = losVertices[(i+1) % 4].Pos;
|
||||
|
||||
Vector2 L = lightSourcePos - ((firstVertex + secondVertex) / 2.0f);
|
||||
|
||||
@@ -547,121 +691,144 @@ namespace Barotrauma.Lights
|
||||
-(secondVertex.Y - firstVertex.Y),
|
||||
secondVertex.X - firstVertex.X);
|
||||
|
||||
backFacing[i] = (Vector2.Dot(N, L) < 0) == los;
|
||||
backFacing[i] = (Vector2.Dot(N, L) < 0);
|
||||
}
|
||||
|
||||
//find beginning and ending vertices which
|
||||
//belong to the shadow
|
||||
int startingIndex = -1;
|
||||
int endingIndex = -1;
|
||||
for (int i = 0; i < 4; i++)
|
||||
ShadowVertexCount = 0;
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
int currentEdge = i;
|
||||
int nextEdge = (i + 1) % 4;
|
||||
if (!backFacing[i]) { continue; }
|
||||
int currentIndex = i;
|
||||
Vector3 vertexPos0 = new Vector3(losOffsets[currentIndex]?.A ?? losVertices[currentIndex].Pos, 0.0f);
|
||||
Vector3 vertexPos1 = new Vector3(losOffsets[currentIndex]?.B ?? losVertices[(currentIndex + 1) % 4].Pos, 0.0f);
|
||||
|
||||
if (backFacing[currentEdge] && !backFacing[nextEdge])
|
||||
endingIndex = nextEdge;
|
||||
if (Vector3.DistanceSquared(vertexPos0, vertexPos1) < 1.0f) { continue; }
|
||||
|
||||
if (!backFacing[currentEdge] && backFacing[nextEdge])
|
||||
startingIndex = nextEdge;
|
||||
}
|
||||
Vector3 L2P0 = vertexPos0 - new Vector3(lightSourcePos, 0);
|
||||
L2P0.Normalize();
|
||||
Vector3 extruded0 = new Vector3(lightSourcePos, 0) + L2P0 * 9000;
|
||||
|
||||
if (startingIndex == -1 || endingIndex == -1) { return; }
|
||||
Vector3 L2P1 = vertexPos1 - new Vector3(lightSourcePos, 0);
|
||||
L2P1.Normalize();
|
||||
Vector3 extruded1 = new Vector3(lightSourcePos, 0) + L2P1 * 9000;
|
||||
|
||||
//nr of vertices that are in the shadow
|
||||
if (endingIndex > startingIndex)
|
||||
ShadowVertexCount = endingIndex - startingIndex + 1;
|
||||
else
|
||||
ShadowVertexCount = 4 + 1 - startingIndex + endingIndex;
|
||||
|
||||
//shadowVertices = new VertexPositionColor[shadowVertexCount * 2];
|
||||
|
||||
//create a triangle strip that has the shape of the shadow
|
||||
int currentIndex = startingIndex;
|
||||
int svCount = 0;
|
||||
while (svCount != ShadowVertexCount * 2)
|
||||
{
|
||||
Vector3 vertexPos = new Vector3(vertices[currentIndex].Pos, 0.0f);
|
||||
|
||||
int i = los ? svCount : svCount + 1;
|
||||
int j = los ? svCount + 1 : svCount;
|
||||
|
||||
//one vertex on the hull
|
||||
ShadowVertices[i] = new VertexPositionColor
|
||||
ShadowVertices[ShadowVertexCount + 0] = new VertexPositionColor
|
||||
{
|
||||
Color = los ? Color.Black : Color.Transparent,
|
||||
Position = vertexPos + offset
|
||||
Color = Color.Black,
|
||||
Position = vertexPos1 + offset
|
||||
};
|
||||
|
||||
//one extruded by the light direction
|
||||
ShadowVertices[j] = new VertexPositionColor
|
||||
ShadowVertices[ShadowVertexCount + 1] = new VertexPositionColor
|
||||
{
|
||||
Color = ShadowVertices[i].Color
|
||||
Color = Color.Black,
|
||||
Position = vertexPos0 + offset
|
||||
};
|
||||
|
||||
Vector3 L2P = vertexPos - new Vector3(lightSourcePos, 0);
|
||||
L2P.Normalize();
|
||||
|
||||
ShadowVertices[j].Position = new Vector3(lightSourcePos, 0) + L2P * 9000 + offset;
|
||||
ShadowVertices[ShadowVertexCount + 2] = new VertexPositionColor
|
||||
{
|
||||
Color = Color.Black,
|
||||
Position = extruded0 + offset
|
||||
};
|
||||
|
||||
svCount += 2;
|
||||
currentIndex = (currentIndex + 1) % 4;
|
||||
ShadowVertices[ShadowVertexCount + 3] = new VertexPositionColor
|
||||
{
|
||||
Color = Color.Black,
|
||||
Position = vertexPos1 + offset
|
||||
};
|
||||
|
||||
ShadowVertices[ShadowVertexCount + 4] = new VertexPositionColor
|
||||
{
|
||||
Color = Color.Black,
|
||||
Position = extruded0 + offset
|
||||
};
|
||||
|
||||
ShadowVertices[ShadowVertexCount + 5] = new VertexPositionColor
|
||||
{
|
||||
Color = Color.Black,
|
||||
Position = extruded1 + offset
|
||||
};
|
||||
|
||||
ShadowVertexCount += 6;
|
||||
}
|
||||
|
||||
if (los)
|
||||
{
|
||||
CalculatePenumbraVertices(startingIndex, endingIndex, lightSourcePos, los);
|
||||
}
|
||||
CalculateLosPenumbraVertices(lightSourcePos);
|
||||
}
|
||||
|
||||
private void CalculatePenumbraVertices(int startingIndex, int endingIndex, Vector2 lightSourcePos, bool los)
|
||||
private void CalculateLosPenumbraVertices(Vector2 lightSourcePos)
|
||||
{
|
||||
var vertices = los ? losVertices : this.vertices;
|
||||
|
||||
Vector3 offset = Vector3.Zero;
|
||||
if (ParentEntity != null && ParentEntity.Submarine != null)
|
||||
{
|
||||
offset = new Vector3(ParentEntity.Submarine.DrawPosition.X, ParentEntity.Submarine.DrawPosition.Y, 0.0f);
|
||||
}
|
||||
|
||||
for (int n = 0; n < 4; n += 3)
|
||||
PenumbraVertexCount = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex].Pos : vertices[endingIndex].Pos, 0.0f);
|
||||
int currentIndex = i;
|
||||
int prevIndex = (i + 3) % 4;
|
||||
int nextIndex = (i + 1) % 4;
|
||||
bool disjointed = losOffsets[i]?.A != null;
|
||||
Vector2 vertexPos0 = losOffsets[currentIndex]?.A ?? losVertices[currentIndex].Pos;
|
||||
Vector2 vertexPos1 = losOffsets[currentIndex]?.B ?? losVertices[nextIndex].Pos;
|
||||
|
||||
PenumbraVertices[n] = new VertexPositionTexture
|
||||
if (Vector2.DistanceSquared(vertexPos0, vertexPos1) < 1.0f) { continue; }
|
||||
|
||||
if (backFacing[currentIndex] && (disjointed || (!backFacing[prevIndex])))
|
||||
{
|
||||
Position = penumbraStart + offset,
|
||||
TextureCoordinate = new Vector2(0.0f, 1.0f)
|
||||
};
|
||||
Vector3 penumbraStart = new Vector3(vertexPos0, 0.0f);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
PenumbraVertices[n + i + 1] = new VertexPositionTexture();
|
||||
Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
|
||||
vertexDir.Normalize();
|
||||
|
||||
Vector3 normal = (i == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f) * 0.05f;
|
||||
if (n > 0) normal = -normal;
|
||||
|
||||
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
|
||||
vertexDir.Normalize();
|
||||
PenumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000 + offset;
|
||||
|
||||
if (los)
|
||||
PenumbraVertices[PenumbraVertexCount] = new VertexPositionTexture
|
||||
{
|
||||
PenumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
|
||||
}
|
||||
else
|
||||
Position = penumbraStart + offset,
|
||||
TextureCoordinate = new Vector2(0.0f, 1.0f)
|
||||
};
|
||||
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
PenumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f) : Vector2.Zero;
|
||||
PenumbraVertices[PenumbraVertexCount + j + 1] = new VertexPositionTexture();
|
||||
Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
|
||||
vertexDir.Normalize();
|
||||
|
||||
Vector3 normal = (j == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f) * 0.05f;
|
||||
|
||||
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
|
||||
vertexDir.Normalize();
|
||||
PenumbraVertices[PenumbraVertexCount + j + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000 + offset;
|
||||
|
||||
PenumbraVertices[PenumbraVertexCount + j + 1].TextureCoordinate = (j == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
|
||||
}
|
||||
|
||||
PenumbraVertexCount += 3;
|
||||
}
|
||||
|
||||
if (n > 0)
|
||||
disjointed = losOffsets[i]?.B != null;
|
||||
if (backFacing[currentIndex] && (disjointed || (!backFacing[nextIndex])))
|
||||
{
|
||||
var temp = PenumbraVertices[4];
|
||||
PenumbraVertices[4] = PenumbraVertices[5];
|
||||
PenumbraVertices[5] = temp;
|
||||
Vector3 penumbraStart = new Vector3(vertexPos1, 0.0f);
|
||||
|
||||
PenumbraVertices[PenumbraVertexCount] = new VertexPositionTexture
|
||||
{
|
||||
Position = penumbraStart + offset,
|
||||
TextureCoordinate = new Vector2(0.0f, 1.0f)
|
||||
};
|
||||
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
PenumbraVertices[PenumbraVertexCount + (1 - j) + 1] = new VertexPositionTexture();
|
||||
Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
|
||||
vertexDir.Normalize();
|
||||
|
||||
Vector3 normal = (j == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f) * 0.05f;
|
||||
|
||||
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) + normal * 20.0f);
|
||||
vertexDir.Normalize();
|
||||
PenumbraVertices[PenumbraVertexCount + (1 - j) + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000 + offset;
|
||||
|
||||
PenumbraVertices[PenumbraVertexCount + (1 - j) + 1].TextureCoordinate = (j == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
|
||||
}
|
||||
|
||||
PenumbraVertexCount += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ namespace Barotrauma.Lights
|
||||
if (GUI.DisableItemHighlights) { return false; }
|
||||
|
||||
highlightedEntities.Clear();
|
||||
if (Character.Controlled != null)
|
||||
if (Character.Controlled != null && (!Character.Controlled.IsKeyDown(InputType.Aim) || Character.Controlled.SelectedItems.Any(it => it?.GetComponent<Sprayer>() == null)))
|
||||
{
|
||||
if (Character.Controlled.FocusedItem != null)
|
||||
{
|
||||
@@ -532,28 +532,16 @@ namespace Barotrauma.Lights
|
||||
Vector2 relativeLightPos = pos;
|
||||
if (convexHull.ParentEntity?.Submarine != null) relativeLightPos -= convexHull.ParentEntity.Submarine.Position;
|
||||
|
||||
convexHull.CalculateShadowVertices(relativeLightPos, true);
|
||||
convexHull.CalculateLosVertices(relativeLightPos);
|
||||
|
||||
//convert triangle strips to a triangle list
|
||||
for (int i = 0; i < convexHull.ShadowVertexCount * 2 - 2; i++)
|
||||
for (int i = 0; i < convexHull.ShadowVertexCount; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
shadowVerts.Add(convexHull.ShadowVertices[i]);
|
||||
shadowVerts.Add(convexHull.ShadowVertices[i + 1]);
|
||||
shadowVerts.Add(convexHull.ShadowVertices[i + 2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
shadowVerts.Add(convexHull.ShadowVertices[i]);
|
||||
shadowVerts.Add(convexHull.ShadowVertices[i + 2]);
|
||||
shadowVerts.Add(convexHull.ShadowVertices[i + 1]);
|
||||
}
|
||||
shadowVerts.Add(convexHull.ShadowVertices[i]);
|
||||
}
|
||||
|
||||
if (convexHull.ShadowVertexCount > 0)
|
||||
for (int i = 0; i < convexHull.PenumbraVertexCount; i++)
|
||||
{
|
||||
penumbraVerts.AddRange(convexHull.PenumbraVertices);
|
||||
penumbraVerts.Add(convexHull.PenumbraVertices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Barotrauma.Lights
|
||||
private short[] indices;
|
||||
|
||||
private List<ConvexHullList> hullsInRange;
|
||||
|
||||
|
||||
public Texture2D texture;
|
||||
|
||||
public SpriteEffects LightSpriteEffect;
|
||||
@@ -300,6 +300,14 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
public float TextureRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return lightSourceParams.TextureRange;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Background lights are drawn behind submarines and they don't cast shadows.
|
||||
/// </summary>
|
||||
@@ -366,7 +374,7 @@ namespace Barotrauma.Lights
|
||||
var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub);
|
||||
if (fullChList == null) return;
|
||||
|
||||
chList.List = fullChList.List.FindAll(ch => ch.Enabled && MathUtils.CircleIntersectsRectangle(lightPos, Range, ch.BoundingBox));
|
||||
chList.List = fullChList.List.FindAll(ch => ch.Enabled && MathUtils.CircleIntersectsRectangle(lightPos, TextureRange, ch.BoundingBox));
|
||||
|
||||
NeedsHullCheck = true;
|
||||
}
|
||||
@@ -418,7 +426,7 @@ namespace Barotrauma.Lights
|
||||
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height);
|
||||
|
||||
//only draw if the light overlaps with the sub
|
||||
if (!MathUtils.CircleIntersectsRectangle(lightPos, Range, subBorders))
|
||||
if (!MathUtils.CircleIntersectsRectangle(lightPos, TextureRange, subBorders))
|
||||
{
|
||||
if (chList.List.Count > 0) NeedsRecalculation = true;
|
||||
chList.List.Clear();
|
||||
@@ -452,7 +460,7 @@ namespace Barotrauma.Lights
|
||||
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height);
|
||||
|
||||
//don't draw any shadows if the light doesn't overlap with the borders of the sub
|
||||
if (!MathUtils.CircleIntersectsRectangle(lightPos, Range, subBorders))
|
||||
if (!MathUtils.CircleIntersectsRectangle(lightPos, TextureRange, subBorders))
|
||||
{
|
||||
if (chList.List.Count > 0) NeedsRecalculation = true;
|
||||
chList.List.Clear();
|
||||
@@ -495,7 +503,7 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
foreach (ConvexHull hull in chList.List)
|
||||
{
|
||||
if (!chList.IsHidden.Contains(hull)) hulls.Add(hull);
|
||||
if (!chList.IsHidden.Contains(hull)) { hulls.Add(hull); }
|
||||
}
|
||||
foreach (ConvexHull hull in chList.List)
|
||||
{
|
||||
@@ -503,7 +511,7 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
float bounds = Range * 2;
|
||||
float bounds = TextureRange;
|
||||
//find convexhull segments that are close enough and facing towards the light source
|
||||
List<Segment> visibleSegments = new List<Segment>();
|
||||
List<SegmentPoint> points = new List<SegmentPoint>();
|
||||
@@ -513,6 +521,49 @@ namespace Barotrauma.Lights
|
||||
hull.GetVisibleSegments(drawPos, visibleSegments, ignoreEdges: false);
|
||||
}
|
||||
|
||||
//add a square-shaped boundary to make sure we've got something to construct the triangles from
|
||||
//even if there aren't enough hull segments around the light source
|
||||
|
||||
//(might be more effective to calculate if we actually need these extra points)
|
||||
|
||||
Vector2 drawOffset = Vector2.Zero;
|
||||
float boundsExtended = bounds;
|
||||
if (OverrideLightTexture != null)
|
||||
{
|
||||
float cosAngle = (float)Math.Cos(Rotation);
|
||||
float sinAngle = -(float)Math.Sin(Rotation);
|
||||
|
||||
var overrideTextureDims = new Vector2(OverrideLightTexture.SourceRect.Width, OverrideLightTexture.SourceRect.Height);
|
||||
|
||||
Vector2 origin = OverrideLightTexture.Origin;
|
||||
|
||||
origin /= Math.Max(overrideTextureDims.X, overrideTextureDims.Y);
|
||||
origin -= Vector2.One * 0.5f;
|
||||
|
||||
if (Math.Abs(origin.X) >= 0.45f || Math.Abs(origin.Y) >= 0.45f)
|
||||
{
|
||||
boundsExtended += 5.0f;
|
||||
}
|
||||
|
||||
origin *= TextureRange;
|
||||
|
||||
drawOffset.X = -origin.X * cosAngle - origin.Y * sinAngle;
|
||||
drawOffset.Y = origin.X * sinAngle + origin.Y * cosAngle;
|
||||
}
|
||||
|
||||
var boundaryCorners = new SegmentPoint[] {
|
||||
new SegmentPoint(new Vector2(drawPos.X + drawOffset.X + boundsExtended, drawPos.Y + drawOffset.Y + boundsExtended), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X + drawOffset.X + boundsExtended, drawPos.Y + drawOffset.Y - boundsExtended), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X + drawOffset.X - boundsExtended, drawPos.Y + drawOffset.Y - boundsExtended), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X + drawOffset.X - boundsExtended, drawPos.Y + drawOffset.Y + boundsExtended), null)
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
var s = new Segment(boundaryCorners[i], boundaryCorners[(i + 1) % 4], null);
|
||||
visibleSegments.Add(s);
|
||||
}
|
||||
|
||||
//Generate new points at the intersections between segments
|
||||
//This is necessary for the light volume to generate properly on some subs
|
||||
for (int i = 0; i < visibleSegments.Count; i++)
|
||||
@@ -532,10 +583,10 @@ namespace Barotrauma.Lights
|
||||
Vector2 p2a = visibleSegments[j].Start.WorldPos;
|
||||
Vector2 p2b = visibleSegments[j].End.WorldPos;
|
||||
|
||||
if (Vector2.DistanceSquared(p1a, p2a) < 25.0f ||
|
||||
Vector2.DistanceSquared(p1a, p2b) < 25.0f ||
|
||||
Vector2.DistanceSquared(p1b, p2a) < 25.0f ||
|
||||
Vector2.DistanceSquared(p1b, p2b) < 25.0f)
|
||||
if (Vector2.DistanceSquared(p1a, p2a) < 5.0f ||
|
||||
Vector2.DistanceSquared(p1a, p2b) < 5.0f ||
|
||||
Vector2.DistanceSquared(p1b, p2a) < 5.0f ||
|
||||
Vector2.DistanceSquared(p1b, p2b) < 5.0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -565,8 +616,8 @@ namespace Barotrauma.Lights
|
||||
mid.Pos -= visibleSegments[i].ConvexHull.ParentEntity.Submarine.DrawPosition;
|
||||
}
|
||||
|
||||
if (Vector2.DistanceSquared(start.WorldPos, mid.WorldPos) < 25.0f ||
|
||||
Vector2.DistanceSquared(end.WorldPos, mid.WorldPos) < 25.0f)
|
||||
if (Vector2.DistanceSquared(start.WorldPos, mid.WorldPos) < 5.0f ||
|
||||
Vector2.DistanceSquared(end.WorldPos, mid.WorldPos) < 5.0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -580,6 +631,7 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
IsHorizontal = visibleSegments[i].IsHorizontal
|
||||
};
|
||||
|
||||
visibleSegments[i] = seg1;
|
||||
visibleSegments.Insert(i + 1, seg2);
|
||||
i--;
|
||||
@@ -588,34 +640,27 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Segment s in visibleSegments)
|
||||
//remove segments that fall out of bounds
|
||||
for (int i = 0; i < visibleSegments.Count; i++)
|
||||
{
|
||||
points.Add(s.Start);
|
||||
points.Add(s.End);
|
||||
if (Math.Abs(s.Start.WorldPos.X - drawPos.X) > bounds) bounds = Math.Abs(s.Start.WorldPos.X - drawPos.X);
|
||||
if (Math.Abs(s.Start.WorldPos.Y - drawPos.Y) > bounds) bounds = Math.Abs(s.Start.WorldPos.Y - drawPos.Y);
|
||||
if (Math.Abs(s.End.WorldPos.X - drawPos.X) > bounds) bounds = Math.Abs(s.End.WorldPos.X - drawPos.X);
|
||||
if (Math.Abs(s.End.WorldPos.Y - drawPos.Y) > bounds) bounds = Math.Abs(s.End.WorldPos.Y - drawPos.Y);
|
||||
Segment s = visibleSegments[i];
|
||||
if (Math.Abs(s.Start.WorldPos.X - drawPos.X - drawOffset.X) > boundsExtended + 1.0f ||
|
||||
Math.Abs(s.Start.WorldPos.Y - drawPos.Y - drawOffset.Y) > boundsExtended + 1.0f ||
|
||||
Math.Abs(s.End.WorldPos.X - drawPos.X - drawOffset.X) > boundsExtended + 1.0f ||
|
||||
Math.Abs(s.End.WorldPos.Y - drawPos.Y - drawOffset.Y) > boundsExtended + 1.0f)
|
||||
{
|
||||
visibleSegments.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
else
|
||||
{
|
||||
points.Add(s.Start);
|
||||
points.Add(s.End);
|
||||
}
|
||||
}
|
||||
|
||||
//add a square-shaped boundary to make sure we've got something to construct the triangles from
|
||||
//even if there aren't enough hull segments around the light source
|
||||
visibleSegments = visibleSegments.OrderBy(s => MathUtils.LineToPointDistanceSquared(s.Start.WorldPos, s.End.WorldPos, drawPos)).ToList();
|
||||
|
||||
//(might be more effective to calculate if we actually need these extra points)
|
||||
var boundaryCorners = new List<SegmentPoint> {
|
||||
new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y + bounds), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y - bounds), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y - bounds), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y + bounds), null)
|
||||
};
|
||||
|
||||
points.AddRange(boundaryCorners);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
visibleSegments.Add(new Segment(boundaryCorners[i], boundaryCorners[(i + 1) % 4], null));
|
||||
}
|
||||
|
||||
var compareCCW = new CompareSegmentPointCW(drawPos);
|
||||
try
|
||||
{
|
||||
@@ -635,13 +680,15 @@ namespace Barotrauma.Lights
|
||||
//List<Pair<int, Vector2>> preOutput = new List<Pair<int, Vector2>>();
|
||||
|
||||
//remove points that are very close to each other
|
||||
for (int i = 0; i < points.Count - 1; i++)
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
if (Math.Abs(points[i].WorldPos.X - points[i + 1].WorldPos.X) < 6 &&
|
||||
Math.Abs(points[i].WorldPos.Y - points[i + 1].WorldPos.Y) < 6)
|
||||
for (int j = Math.Min(i + 4, points.Count-1); j > i; j--)
|
||||
{
|
||||
points.RemoveAt(i + 1);
|
||||
i--;
|
||||
if (Math.Abs(points[i].WorldPos.X - points[j].WorldPos.X) < 6 &&
|
||||
Math.Abs(points[i].WorldPos.Y - points[j].WorldPos.Y) < 6)
|
||||
{
|
||||
points.RemoveAt(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,16 +698,16 @@ namespace Barotrauma.Lights
|
||||
Vector2 dirNormal = new Vector2(-dir.Y, dir.X) * 3;
|
||||
|
||||
//do two slightly offset raycasts to hit the segment itself and whatever's behind it
|
||||
Pair<int,Vector2> intersection1 = RayCast(drawPos, drawPos + dir * bounds * 2 - dirNormal, visibleSegments);
|
||||
Pair<int,Vector2> intersection2 = RayCast(drawPos, drawPos + dir * bounds * 2 + dirNormal, visibleSegments);
|
||||
Pair<int,Vector2> intersection1 = RayCast(drawPos, drawPos + dir * boundsExtended * 2 - dirNormal, visibleSegments);
|
||||
Pair<int,Vector2> intersection2 = RayCast(drawPos, drawPos + dir * boundsExtended * 2 + dirNormal, visibleSegments);
|
||||
|
||||
if (intersection1.First < 0) return new List<Vector2>();
|
||||
if (intersection2.First < 0) return new List<Vector2>();
|
||||
if (intersection1.First < 0) return null;
|
||||
if (intersection2.First < 0) return null;
|
||||
Segment seg1 = visibleSegments[intersection1.First];
|
||||
Segment seg2 = visibleSegments[intersection2.First];
|
||||
|
||||
bool isPoint1 = MathUtils.LineToPointDistance(seg1.Start.WorldPos, seg1.End.WorldPos, p.WorldPos) < 5.0f;
|
||||
bool isPoint2 = MathUtils.LineToPointDistance(seg2.Start.WorldPos, seg2.End.WorldPos, p.WorldPos) < 5.0f;
|
||||
bool isPoint1 = MathUtils.LineToPointDistanceSquared(seg1.Start.WorldPos, seg1.End.WorldPos, p.WorldPos) < 25.0f;
|
||||
bool isPoint2 = MathUtils.LineToPointDistanceSquared(seg2.Start.WorldPos, seg2.End.WorldPos, p.WorldPos) < 25.0f;
|
||||
|
||||
if (isPoint1 && isPoint2)
|
||||
{
|
||||
@@ -696,11 +743,13 @@ namespace Barotrauma.Lights
|
||||
//remove points that are very close to each other
|
||||
for (int i = 0; i < output.Count - 1; i++)
|
||||
{
|
||||
if (Math.Abs(output[i].X - output[i + 1].X) < 6 &&
|
||||
Math.Abs(output[i].Y - output[i + 1].Y) < 6)
|
||||
for (int j = Math.Min(i + 4, output.Count - 1); j > i; j--)
|
||||
{
|
||||
output.RemoveAt(i + 1);
|
||||
i--;
|
||||
if (Math.Abs(output[i].X - output[j].X) < 6 &&
|
||||
Math.Abs(output[i].Y - output[j].Y) < 6)
|
||||
{
|
||||
output.RemoveAt(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,7 +758,6 @@ namespace Barotrauma.Lights
|
||||
|
||||
private Pair<int, Vector2> RayCast(Vector2 rayStart, Vector2 rayEnd, List<Segment> segments)
|
||||
{
|
||||
float closestDist = float.PositiveInfinity;
|
||||
Vector2? closestIntersection = null;
|
||||
int segment = -1;
|
||||
|
||||
@@ -724,11 +772,11 @@ namespace Barotrauma.Lights
|
||||
|
||||
//segment's end position always has a higher or equal y coordinate than the start position
|
||||
//so we can do this comparison and skip segments that are at the wrong side of the ray
|
||||
if (s.End.WorldPos.Y < s.Start.WorldPos.Y)
|
||||
/*if (s.End.WorldPos.Y < s.Start.WorldPos.Y)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(s.End.WorldPos.Y >= s.Start.WorldPos.Y,
|
||||
"LightSource raycast failed. Segment's end positions should never be below the start position. Parent entity: " + (s.ConvexHull?.ParentEntity == null ? "null" : s.ConvexHull.ParentEntity.ToString()));
|
||||
}
|
||||
}*/
|
||||
if (s.Start.WorldPos.Y > maxY || s.End.WorldPos.Y < minY) { continue; }
|
||||
//same for the x-axis
|
||||
if (s.Start.WorldPos.X > s.End.WorldPos.X)
|
||||
@@ -741,18 +789,29 @@ namespace Barotrauma.Lights
|
||||
if (s.End.WorldPos.X < minX) continue;
|
||||
if (s.Start.WorldPos.X > maxX) continue;
|
||||
}
|
||||
|
||||
if (s.IsAxisAligned ?
|
||||
MathUtils.GetAxisAlignedLineIntersection(rayStart, rayEnd, s.Start.WorldPos, s.End.WorldPos, s.IsHorizontal, out Vector2 intersection) :
|
||||
MathUtils.GetLineIntersection(rayStart, rayEnd, s.Start.WorldPos, s.End.WorldPos, out intersection))
|
||||
|
||||
bool intersects;
|
||||
Vector2 intersection;
|
||||
if (s.IsAxisAligned)
|
||||
{
|
||||
float dist = Vector2.DistanceSquared(intersection, rayStart);
|
||||
if (dist < closestDist)
|
||||
{
|
||||
closestDist = dist;
|
||||
closestIntersection = intersection;
|
||||
segment = i;
|
||||
}
|
||||
intersects = MathUtils.GetAxisAlignedLineIntersection(rayStart, rayEnd, s.Start.WorldPos, s.End.WorldPos, s.IsHorizontal, out intersection);
|
||||
}
|
||||
else
|
||||
{
|
||||
intersects = MathUtils.GetLineIntersection(rayStart, rayEnd, s.Start.WorldPos, s.End.WorldPos, out intersection);
|
||||
}
|
||||
|
||||
if (intersects)
|
||||
{
|
||||
closestIntersection = intersection;
|
||||
|
||||
rayEnd = intersection;
|
||||
minX = Math.Min(rayStart.X, rayEnd.X);
|
||||
maxX = Math.Max(rayStart.X, rayEnd.X);
|
||||
minY = Math.Min(rayStart.Y, rayEnd.Y);
|
||||
maxY = Math.Max(rayStart.Y, rayEnd.Y);
|
||||
|
||||
segment = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,7 +856,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
//hacky fix to exc excessively large light volumes (they used to be up to 4x the range of the light if there was nothing to block the rays).
|
||||
//might want to tweak the raycast logic in a way that this isn't necessary
|
||||
float boundRadius = Range * 1.1f / (1.0f - Math.Max(Math.Abs(uvOffset.X), Math.Abs(uvOffset.Y)));
|
||||
/*float boundRadius = Range * 1.1f / (1.0f - Math.Max(Math.Abs(uvOffset.X), Math.Abs(uvOffset.Y)));
|
||||
Rectangle boundArea = new Rectangle((int)(drawPos.X - boundRadius), (int)(drawPos.Y + boundRadius), (int)(boundRadius * 2), (int)(boundRadius * 2));
|
||||
for (int i = 0; i < rayCastHits.Count; i++)
|
||||
{
|
||||
@@ -805,7 +864,7 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
rayCastHits[i] = intersection;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// Add all the other encounter points as vertices
|
||||
// storing their world position as UV coordinates
|
||||
@@ -818,7 +877,7 @@ namespace Barotrauma.Lights
|
||||
//so we can add new vertices based on these normals
|
||||
Vector2 prevVertex = rayCastHits[i > 0 ? i - 1 : rayCastHits.Count - 1];
|
||||
Vector2 nextVertex = rayCastHits[i < rayCastHits.Count - 1 ? i + 1 : 0];
|
||||
|
||||
|
||||
Vector2 rawDiff = vertex - drawPos;
|
||||
|
||||
//calculate normal of first segment
|
||||
@@ -836,12 +895,18 @@ namespace Barotrauma.Lights
|
||||
//if the normal is pointing towards the light origin
|
||||
//rather than away from it, invert it
|
||||
if (Vector2.DistanceSquared(nDiff2, rawDiff) > Vector2.DistanceSquared(-nDiff2, rawDiff)) nDiff2 = -nDiff2;
|
||||
|
||||
|
||||
//add the normals together and use some magic numbers to create
|
||||
//a somewhat useful/good-looking blur
|
||||
Vector2 nDiff = nDiff1 + nDiff2;
|
||||
nDiff /= Math.Max(Math.Abs(nDiff.X), Math.Abs(nDiff.Y));
|
||||
nDiff *= 50.0f;
|
||||
Vector2 nDiff = nDiff1 * 40.0f;
|
||||
if (MathUtils.GetLineIntersection(vertex + (nDiff1 * 40.0f), nextVertex + (nDiff1 * 40.0f), vertex + (nDiff2 * 40.0f), prevVertex + (nDiff2 * 40.0f), true, out Vector2 intersection))
|
||||
{
|
||||
nDiff = intersection - vertex;
|
||||
if (nDiff.LengthSquared() > 10000.0f)
|
||||
{
|
||||
nDiff /= Math.Max(Math.Abs(nDiff.X), Math.Abs(nDiff.Y)); nDiff *= 100.0f;
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 diff = rawDiff;
|
||||
diff /= Range * 2.0f;
|
||||
@@ -948,6 +1013,50 @@ namespace Barotrauma.Lights
|
||||
/// <param name="spriteBatch"></param>
|
||||
public void DrawSprite(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
Vector2 drawPos = position;
|
||||
if (ParentSub != null)
|
||||
{
|
||||
drawPos += ParentSub.DrawPosition;
|
||||
}
|
||||
drawPos.Y = -drawPos.Y;
|
||||
|
||||
float cosAngle = (float)Math.Cos(Rotation);
|
||||
float sinAngle = -(float)Math.Sin(Rotation);
|
||||
|
||||
float bounds = TextureRange;
|
||||
|
||||
if (OverrideLightTexture != null)
|
||||
{
|
||||
var overrideTextureDims = new Vector2(OverrideLightTexture.SourceRect.Width, OverrideLightTexture.SourceRect.Height);
|
||||
|
||||
Vector2 origin = OverrideLightTexture.Origin;
|
||||
|
||||
origin /= Math.Max(overrideTextureDims.X, overrideTextureDims.Y);
|
||||
origin *= TextureRange;
|
||||
|
||||
drawPos.X += origin.X * sinAngle + origin.Y * cosAngle;
|
||||
drawPos.Y += origin.X * cosAngle + origin.Y * sinAngle;
|
||||
}
|
||||
|
||||
//add a square-shaped boundary to make sure we've got something to construct the triangles from
|
||||
//even if there aren't enough hull segments around the light source
|
||||
|
||||
//(might be more effective to calculate if we actually need these extra points)
|
||||
var boundaryCorners = new SegmentPoint[] {
|
||||
new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y + bounds), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y - bounds), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y - bounds), null),
|
||||
new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y + bounds), null)
|
||||
};
|
||||
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch, boundaryCorners[i].Pos, boundaryCorners[(i + 1) % 4].Pos, Color.White, 0, 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (DeformableLightSprite != null)
|
||||
{
|
||||
Vector2 origin = DeformableLightSprite.Origin;
|
||||
@@ -976,11 +1085,11 @@ namespace Barotrauma.Lights
|
||||
if (LightSprite != null)
|
||||
{
|
||||
Vector2 origin = LightSprite.Origin;
|
||||
if (LightSpriteEffect == SpriteEffects.FlipHorizontally)
|
||||
if ((LightSpriteEffect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally)
|
||||
{
|
||||
origin.X = LightSprite.SourceRect.Width - origin.X;
|
||||
}
|
||||
if (LightSpriteEffect == SpriteEffects.FlipVertically)
|
||||
if ((LightSpriteEffect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically)
|
||||
{
|
||||
origin.Y = LightSprite.SourceRect.Height - origin.Y;
|
||||
}
|
||||
@@ -1088,7 +1197,7 @@ namespace Barotrauma.Lights
|
||||
PrimitiveType.TriangleList, 0, 0, indexCount / 3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
hullsInRange.Clear();
|
||||
|
||||
@@ -9,8 +9,6 @@ namespace Barotrauma
|
||||
{
|
||||
partial class Map
|
||||
{
|
||||
public bool AllowDebugTeleport;
|
||||
|
||||
class MapAnim
|
||||
{
|
||||
public Location StartLocation;
|
||||
@@ -380,6 +378,7 @@ namespace Barotrauma
|
||||
Location prevLocation = CurrentDisplayLocation;
|
||||
CurrentLocation = HighlightedLocation;
|
||||
Level.Loaded.DebugSetStartLocation(CurrentLocation);
|
||||
Level.Loaded.DebugSetEndLocation(null);
|
||||
|
||||
CurrentLocation.Discovered = true;
|
||||
CurrentLocation.CreateStore();
|
||||
@@ -573,7 +572,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.DebugDraw && location == HighlightedLocation)
|
||||
if (GameMain.DebugDraw && location == HighlightedLocation && (!location.Discovered || !location.Type.HasOutpost))
|
||||
{
|
||||
if (location.Reputation != null)
|
||||
{
|
||||
@@ -589,7 +588,7 @@ namespace Barotrauma
|
||||
Color barColor = ToolBox.GradientLerp(location.Reputation.NormalizedValue, Color.Red, Color.Yellow, Color.LightGreen);
|
||||
GUI.DrawRectangle(spriteBatch, bgRect, Color.Black * 0.8f, isFilled: true);
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)dPos.X, (int)dPos.Y, (int)(location.Reputation.NormalizedValue * 255), 32), barColor, isFilled: true);
|
||||
string reputationValue = location.Reputation.Value.ToString(CultureInfo.InvariantCulture);
|
||||
string reputationValue = ((int)location.Reputation.Value).ToString();
|
||||
Vector2 repValueSize = GUI.SubHeadingFont.MeasureString(reputationValue);
|
||||
GUI.DrawString(spriteBatch, dPos + (new Vector2(256, 32) / 2) - (repValueSize / 2), reputationValue, Color.White, Color.Black, font: GUI.SubHeadingFont);
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)dPos.X, (int)dPos.Y, 256, 32), Color.White);
|
||||
@@ -607,12 +606,34 @@ namespace Barotrauma
|
||||
Vector2 nameSize = GUI.LargeFont.MeasureString(HighlightedLocation.Name);
|
||||
Vector2 typeSize = GUI.Font.MeasureString(HighlightedLocation.Type.Name);
|
||||
Vector2 size = new Vector2(Math.Max(nameSize.X, typeSize.X), nameSize.Y + typeSize.Y);
|
||||
bool showReputation = HighlightedLocation.Discovered && HighlightedLocation.Type.HasOutpost && HighlightedLocation.Reputation != null;
|
||||
string repLabelText = null, repValueText = null;
|
||||
Vector2 repLabelSize = Vector2.Zero, repBarSize = Vector2.Zero;
|
||||
if (showReputation)
|
||||
{
|
||||
repLabelText = TextManager.Get("reputation");
|
||||
repLabelSize = GUI.Font.MeasureString(repLabelText);
|
||||
size.X = Math.Max(size.X, repLabelSize.X);
|
||||
repBarSize = new Vector2(Math.Max(0.75f * size.X, 100), repLabelSize.Y);
|
||||
size.X = Math.Max(size.X, (4.0f / 3.0f) * repBarSize.X);
|
||||
size.Y += 2 * repLabelSize.Y + 4 + repBarSize.Y;
|
||||
repValueText = ((int)HighlightedLocation.Reputation.Value).ToString();
|
||||
}
|
||||
GUI.Style.GetComponentStyle("OuterGlow").Sprites[GUIComponent.ComponentState.None][0].Draw(
|
||||
spriteBatch, new Rectangle((int)(pos.X - 60 * GUI.Scale), (int)(pos.Y - size.Y), (int)(size.X + 120 * GUI.Scale), (int)(size.Y * 2.2f)), Color.Black * hudVisibility);
|
||||
GUI.DrawString(spriteBatch, pos - new Vector2(0.0f, size.Y / 2),
|
||||
HighlightedLocation.Name, GUI.Style.TextColor * hudVisibility * 1.5f, font: GUI.LargeFont);
|
||||
GUI.DrawString(spriteBatch, pos + new Vector2(0.0f, size.Y / 2 - GUI.Font.MeasureString(HighlightedLocation.Type.Name).Y),
|
||||
HighlightedLocation.Type.Name, GUI.Style.TextColor * hudVisibility * 1.5f);
|
||||
spriteBatch, new Rectangle((int)(pos.X - 60 * GUI.Scale), (int)(pos.Y - size.Y), (int)(size.X + 120 * GUI.Scale), (int)(size.Y * 2.2f)), Color.Black * hudVisibility);
|
||||
var topLeftPos = pos - new Vector2(0.0f, size.Y / 2);
|
||||
GUI.DrawString(spriteBatch, topLeftPos, HighlightedLocation.Name, GUI.Style.TextColor * hudVisibility * 1.5f, font: GUI.LargeFont);
|
||||
topLeftPos += new Vector2(0.0f, nameSize.Y);
|
||||
GUI.DrawString(spriteBatch, topLeftPos, HighlightedLocation.Type.Name, GUI.Style.TextColor * hudVisibility * 1.5f);
|
||||
if (showReputation)
|
||||
{
|
||||
topLeftPos += new Vector2(0.0f, typeSize.Y + repLabelSize.Y);
|
||||
GUI.DrawString(spriteBatch, topLeftPos, repLabelText, GUI.Style.TextColor * hudVisibility * 1.5f);
|
||||
topLeftPos += new Vector2(0.0f, repLabelSize.Y + 4);
|
||||
Rectangle repBarRect = new Rectangle(new Point((int)topLeftPos.X, (int)topLeftPos.Y), new Point((int)repBarSize.X, (int)repBarSize.Y));
|
||||
RoundSummary.DrawReputationBar(spriteBatch, repBarRect, HighlightedLocation.Reputation.NormalizedValue);
|
||||
GUI.DrawString(spriteBatch, new Vector2(repBarRect.Right + 4, repBarRect.Top), repValueText, GUI.Style.TextColor);
|
||||
}
|
||||
}
|
||||
if (tooltip != null)
|
||||
{
|
||||
|
||||
@@ -159,6 +159,31 @@ namespace Barotrauma
|
||||
|
||||
if (PlayerInput.IsCtrlDown())
|
||||
{
|
||||
#if DEBUG
|
||||
if (PlayerInput.KeyHit(Keys.D))
|
||||
{
|
||||
bool terminate = false;
|
||||
foreach (MapEntity entity in selectedList)
|
||||
{
|
||||
if (entity is Item item && item.GetComponent<Planter>() is { } planter)
|
||||
{
|
||||
planter.Update(1.0f, cam);
|
||||
for (var i = 0; i < planter.GrowableSeeds.Length; i++)
|
||||
{
|
||||
Growable seed = planter.GrowableSeeds[i];
|
||||
PlantSlot slot = planter.PlantSlots.ContainsKey(i) ? planter.PlantSlots[i] : Planter.NullSlot;
|
||||
if (seed == null) { continue; }
|
||||
|
||||
seed.CreateDebugHUD(planter, slot);
|
||||
terminate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (terminate) { break; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (PlayerInput.KeyHit(Keys.C))
|
||||
{
|
||||
Copy(selectedList);
|
||||
@@ -897,8 +922,9 @@ namespace Barotrauma
|
||||
Clone(copiedList);
|
||||
|
||||
var clones = mapEntityList.Except(prevEntities).ToList();
|
||||
|
||||
var nonWireClones = clones.Where(c => !(c is Item item) || item.GetComponent<Wire>() == null);
|
||||
if (!nonWireClones.Any()) { nonWireClones = clones; }
|
||||
|
||||
Vector2 center = Vector2.Zero;
|
||||
nonWireClones.ForEach(c => center += c.WorldPosition);
|
||||
center = Submarine.VectorToWorldGrid(center / nonWireClones.Count());
|
||||
|
||||
@@ -185,9 +185,20 @@ namespace Barotrauma
|
||||
public override bool IsVisible(Rectangle worldView)
|
||||
{
|
||||
Rectangle worldRect = WorldRect;
|
||||
Vector2 worldPos = WorldPosition;
|
||||
|
||||
if (worldRect.X > worldView.Right || worldRect.Right < worldView.X) { return false; }
|
||||
if (worldRect.Y < worldView.Y - worldView.Height || worldRect.Y - worldRect.Height > worldView.Y) { return false; }
|
||||
Vector2 min = new Vector2(worldRect.X, worldRect.Y - worldRect.Height);
|
||||
Vector2 max = new Vector2(worldRect.Right, worldRect.Y);
|
||||
foreach (DecorativeSprite decorativeSprite in Prefab.DecorativeSprites)
|
||||
{
|
||||
min.X = Math.Min(worldPos.X - decorativeSprite.Sprite.size.X * decorativeSprite.Sprite.RelativeOrigin.X * decorativeSprite.Scale * Scale, min.X);
|
||||
max.X = Math.Max(worldPos.X + decorativeSprite.Sprite.size.X * (1.0f - decorativeSprite.Sprite.RelativeOrigin.X) * decorativeSprite.Scale * Scale, max.X);
|
||||
min.Y = Math.Min(worldPos.Y - decorativeSprite.Sprite.size.Y * (1.0f - decorativeSprite.Sprite.RelativeOrigin.Y) * decorativeSprite.Scale * Scale, min.Y);
|
||||
max.Y = Math.Max(worldPos.Y + decorativeSprite.Sprite.size.Y * decorativeSprite.Sprite.RelativeOrigin.Y * decorativeSprite.Scale * Scale, max.Y);
|
||||
}
|
||||
|
||||
if (min.X > worldView.Right || max.X < worldView.X) { return false; }
|
||||
if ( min.Y > worldView.Y || max.Y < worldView.Y - worldView.Height) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -455,8 +466,16 @@ namespace Barotrauma
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
byte sectionCount = msg.ReadByte();
|
||||
if (sectionCount != Sections.Length)
|
||||
|
||||
bool invalidMessage = false;
|
||||
if (type != ServerNetObject.ENTITY_EVENT && type != ServerNetObject.ENTITY_EVENT_INITIAL)
|
||||
{
|
||||
DebugConsole.NewMessage($"Error while reading a network event for the structure \"{Name} ({ID})\". Invalid event type ({type}).", Color.Red);
|
||||
return;
|
||||
}
|
||||
else if (sectionCount != Sections.Length)
|
||||
{
|
||||
invalidMessage = true;
|
||||
string errorMsg = $"Error while reading a network event for the structure \"{Name} ({ID})\". Section count does not match (server: {sectionCount} client: {Sections.Length})";
|
||||
DebugConsole.NewMessage(errorMsg, Color.Red);
|
||||
GameAnalyticsManager.AddErrorEventOnce("Structure.ClientRead:SectionCountMismatch", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
@@ -465,7 +484,7 @@ namespace Barotrauma
|
||||
for (int i = 0; i < sectionCount; i++)
|
||||
{
|
||||
float damage = msg.ReadRangedSingle(0.0f, 1.0f, 8) * MaxHealth;
|
||||
if (i < Sections.Length)
|
||||
if (!invalidMessage && i < Sections.Length)
|
||||
{
|
||||
SetDamage(i, damage);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Items.Components;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -19,6 +20,7 @@ namespace Barotrauma
|
||||
public Sound Sound;
|
||||
public readonly float Volume;
|
||||
public readonly float Range;
|
||||
public readonly Vector2 FrequencyMultiplierRange;
|
||||
public readonly bool Stream;
|
||||
|
||||
public string Filename
|
||||
@@ -32,8 +34,34 @@ namespace Barotrauma
|
||||
Stream = sound.Stream;
|
||||
Range = element.GetAttributeFloat("range", 1000.0f);
|
||||
Volume = element.GetAttributeFloat("volume", 1.0f);
|
||||
FrequencyMultiplierRange = new Vector2(1.0f);
|
||||
string freqMultAttr = element.GetAttributeString("frequencymultiplier", element.GetAttributeString("frequency", "1.0"));
|
||||
if (!freqMultAttr.Contains(','))
|
||||
{
|
||||
if (float.TryParse(freqMultAttr, NumberStyles.Any, CultureInfo.InvariantCulture, out float freqMult))
|
||||
{
|
||||
FrequencyMultiplierRange = new Vector2(freqMult);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var freqMult = XMLExtensions.ParseVector2(freqMultAttr, false);
|
||||
if (freqMult.Y >= 0.25f)
|
||||
{
|
||||
FrequencyMultiplierRange = freqMult;
|
||||
}
|
||||
}
|
||||
if (FrequencyMultiplierRange.Y > 4.0f)
|
||||
{
|
||||
DebugConsole.ThrowError($"Loaded frequency range exceeds max value: {FrequencyMultiplierRange} (original string was \"{freqMultAttr}\")");
|
||||
}
|
||||
sound.IgnoreMuffling = element.GetAttributeBool("dontmuffle", false);
|
||||
}
|
||||
|
||||
public float GetRandomFrequencyMultiplier()
|
||||
{
|
||||
return Rand.Range(FrequencyMultiplierRange.X, FrequencyMultiplierRange.Y);
|
||||
}
|
||||
}
|
||||
|
||||
partial class Submarine : Entity, IServerSerializable
|
||||
@@ -288,6 +316,27 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawPaintedColors(SpriteBatch spriteBatch, bool editing = false, Predicate<MapEntity> predicate = null)
|
||||
{
|
||||
var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList;
|
||||
|
||||
foreach (MapEntity e in entitiesToRender)
|
||||
{
|
||||
if (e is Hull hull)
|
||||
{
|
||||
if (hull.SupportsPaintedColors)
|
||||
{
|
||||
if (predicate != null)
|
||||
{
|
||||
if (!predicate(e)) continue;
|
||||
}
|
||||
|
||||
hull.DrawSectionColors(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawBack(SpriteBatch spriteBatch, bool editing = false, Predicate<MapEntity> predicate = null)
|
||||
{
|
||||
var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList;
|
||||
@@ -511,6 +560,11 @@ namespace Barotrauma
|
||||
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
if (type != ServerNetObject.ENTITY_POSITION)
|
||||
{
|
||||
DebugConsole.NewMessage($"Error while reading a network event for the submarine \"{Info.Name} ({ID})\". Invalid event type ({type}).", Color.Red);
|
||||
}
|
||||
|
||||
var posInfo = PhysicsBody.ClientRead(type, msg, sendingTime, parentDebugName: Info.Name);
|
||||
msg.ReadPadBits();
|
||||
|
||||
|
||||
@@ -238,42 +238,7 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool EnterIDCardDesc(GUITextBox textBox, string text)
|
||||
{
|
||||
IdCardDesc = text;
|
||||
textBox.Text = text;
|
||||
textBox.Color = GUI.Style.Green;
|
||||
|
||||
textBox.Deselect();
|
||||
|
||||
return true;
|
||||
}
|
||||
private bool EnterIDCardTags(GUITextBox textBox, string text)
|
||||
{
|
||||
IdCardTags = text.Split(',');
|
||||
textBox.Text = string.Join(",", IdCardTags);
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
textBox.Deselect();
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool EnterTags(GUITextBox textBox, string text)
|
||||
{
|
||||
tags = text.Split(',').ToList();
|
||||
textBox.Text = string.Join(",", Tags);
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
textBox.Deselect();
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TextBoxChanged(GUITextBox textBox, string text)
|
||||
{
|
||||
textBox.Color = GUI.Style.Red;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private GUIComponent CreateEditingHUD(bool inGame = false)
|
||||
private GUIComponent CreateEditingHUD()
|
||||
{
|
||||
int width = 500;
|
||||
int height = spawnType == SpawnType.Path ? 80 : 200;
|
||||
@@ -326,21 +291,48 @@ namespace Barotrauma
|
||||
GUITextBox propertyBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), descText.RectTransform, Anchor.CenterRight), IdCardDesc)
|
||||
{
|
||||
MaxTextLength = 150,
|
||||
OnEnterPressed = EnterIDCardDesc,
|
||||
ToolTip = TextManager.Get("IDCardDescriptionTooltip")
|
||||
};
|
||||
propertyBox.OnTextChanged += TextBoxChanged;
|
||||
propertyBox.OnTextChanged += (textBox, text) =>
|
||||
{
|
||||
IdCardDesc = text;
|
||||
return true;
|
||||
};
|
||||
propertyBox.OnEnterPressed += (textBox, text) =>
|
||||
{
|
||||
IdCardDesc = text;
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
return true;
|
||||
};
|
||||
propertyBox.OnDeselected += (textBox, keys) =>
|
||||
{
|
||||
IdCardDesc = textBox.Text;
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
};
|
||||
|
||||
var idCardTagsText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
|
||||
TextManager.Get("IDCardTags"), font: GUI.SmallFont);
|
||||
propertyBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), idCardTagsText.RectTransform, Anchor.CenterRight), string.Join(", ", idCardTags))
|
||||
{
|
||||
MaxTextLength = 60,
|
||||
OnEnterPressed = EnterIDCardTags,
|
||||
ToolTip = TextManager.Get("IDCardTagsTooltip")
|
||||
};
|
||||
propertyBox.OnTextChanged += TextBoxChanged;
|
||||
|
||||
propertyBox.OnTextChanged += (textBox, text) =>
|
||||
{
|
||||
IdCardTags = text.Split(',');
|
||||
return true;
|
||||
};
|
||||
propertyBox.OnEnterPressed += (textBox, text) =>
|
||||
{
|
||||
textBox.Text = string.Join(",", IdCardTags);
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
return true;
|
||||
};
|
||||
propertyBox.OnDeselected += (textBox, keys) =>
|
||||
{
|
||||
textBox.Text = string.Join(",", IdCardTags);
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
};
|
||||
|
||||
var jobsText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
|
||||
TextManager.Get("SpawnpointJobs"), font: GUI.SmallFont)
|
||||
@@ -368,12 +360,26 @@ namespace Barotrauma
|
||||
propertyBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), tagsText.RectTransform, Anchor.CenterRight), string.Join(", ", tags))
|
||||
{
|
||||
MaxTextLength = 60,
|
||||
OnEnterPressed = EnterTags,
|
||||
ToolTip = TextManager.Get("spawnpointtagstooltip")
|
||||
};
|
||||
propertyBox.OnTextChanged += TextBoxChanged;
|
||||
propertyBox.OnTextChanged += (textBox, text) =>
|
||||
{
|
||||
tags = text.Split(',').ToList();
|
||||
return true;
|
||||
};
|
||||
propertyBox.OnEnterPressed += (textBox, text) =>
|
||||
{
|
||||
textBox.Text = string.Join(",", tags);
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
return true;
|
||||
};
|
||||
propertyBox.OnDeselected += (textBox, keys) =>
|
||||
{
|
||||
textBox.Text = string.Join(",", tags);
|
||||
textBox.Flash(GUI.Style.Green);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
PositionEditingHUD();
|
||||
|
||||
return editingHUD;
|
||||
|
||||
Reference in New Issue
Block a user