v0.11.0.9
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
using Barotrauma.Lights;
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.Particles;
|
||||
using Barotrauma.Sounds;
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.SpriteDeformations;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.SpriteDeformations;
|
||||
using System.Linq;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -74,10 +74,21 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool VisibleOnSonar
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public float SonarRadius
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
partial void InitProjSpecific()
|
||||
{
|
||||
Sprite?.EnsureLazyLoaded();
|
||||
SpecularSprite?.EnsureLazyLoaded();
|
||||
Prefab.DeformableSprite?.EnsureLazyLoaded();
|
||||
|
||||
CurrentSwingAmount = Prefab.SwingAmountRad;
|
||||
@@ -98,7 +109,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (Prefab.LightSourceParams != null)
|
||||
if (Prefab.LightSourceParams != null && Prefab.LightSourceParams.Count > 0)
|
||||
{
|
||||
LightSources = new LightSource[Prefab.LightSourceParams.Count];
|
||||
LightSourceTriggers = new LevelTrigger[Prefab.LightSourceParams.Count];
|
||||
@@ -138,6 +149,13 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VisibleOnSonar = Prefab.SonarDisruption > 0.0f || Prefab.OverrideProperties.Any(p => p != null && p.SonarDisruption > 0.0f) ||
|
||||
(Triggers != null && Triggers.Any(t => !MathUtils.NearlyEqual(t.Force, Vector2.Zero) && t.ForceMode != LevelTrigger.TriggerForceMode.LimitVelocity || !string.IsNullOrWhiteSpace(t.InfectIdentifier)));
|
||||
if (VisibleOnSonar && Triggers.Any())
|
||||
{
|
||||
SonarRadius = Triggers.Select(t => t.ColliderRadius * 1.5f).Max();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
@@ -232,17 +250,21 @@ namespace Barotrauma
|
||||
deformation.Update(deltaTime);
|
||||
}
|
||||
CurrentSpriteDeformation = SpriteDeformation.GetDeformation(spriteDeformations, ActivePrefab.DeformableSprite.Size);
|
||||
foreach (LightSource lightSource in LightSources)
|
||||
if (LightSources != null)
|
||||
{
|
||||
if (lightSource?.DeformableLightSprite != null)
|
||||
foreach (LightSource lightSource in LightSources)
|
||||
{
|
||||
lightSource.DeformableLightSprite.Deform(CurrentSpriteDeformation);
|
||||
if (lightSource?.DeformableLightSprite != null)
|
||||
{
|
||||
lightSource.DeformableLightSprite.Deform(CurrentSpriteDeformation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePositionalDeformation(PositionalDeformation positionalDeformation, float deltaTime)
|
||||
{
|
||||
if (Triggers == null) { return; }
|
||||
Matrix matrix = ActivePrefab.DeformableSprite.GetTransform(
|
||||
Position,
|
||||
ActivePrefab.DeformableSprite.Origin,
|
||||
@@ -258,7 +280,7 @@ namespace Barotrauma
|
||||
Vector2 moveAmount = triggerer.WorldPosition - trigger.TriggererPosition[triggerer];
|
||||
|
||||
moveAmount = Vector2.Transform(moveAmount, rotationMatrix);
|
||||
moveAmount /= (ActivePrefab.DeformableSprite.Size * Scale);
|
||||
moveAmount /= ActivePrefab.DeformableSprite.Size * Scale;
|
||||
moveAmount.Y = -moveAmount.Y;
|
||||
|
||||
positionalDeformation.Deform(trigger.WorldPosition, moveAmount, deltaTime, Matrix.Invert(matrix) *
|
||||
@@ -269,9 +291,10 @@ namespace Barotrauma
|
||||
|
||||
public void ClientRead(IReadMessage msg)
|
||||
{
|
||||
if (Triggers == null) { return; }
|
||||
for (int i = 0; i < Triggers.Count; i++)
|
||||
{
|
||||
if (!Triggers[i].UseNetworkSyncing) continue;
|
||||
if (!Triggers[i].UseNetworkSyncing) { continue; }
|
||||
Triggers[i].ClientRead(msg);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-8
@@ -12,6 +12,8 @@ namespace Barotrauma
|
||||
private readonly List<LevelObject> visibleObjectsBack = new List<LevelObject>();
|
||||
private readonly List<LevelObject> visibleObjectsFront = new List<LevelObject>();
|
||||
|
||||
private double NextRefreshTime;
|
||||
|
||||
//Maximum number of visible objects drawn at once. Should be large enough to not have an effect during normal gameplay,
|
||||
//but small enough to prevent wrecking performance when zooming out very far
|
||||
const int MaxVisibleObjects = 500;
|
||||
@@ -38,11 +40,13 @@ namespace Barotrauma
|
||||
/// <summary>
|
||||
/// Checks which level objects are in camera view and adds them to the visibleObjects lists
|
||||
/// </summary>
|
||||
private void RefreshVisibleObjects(Rectangle currentIndices)
|
||||
private void RefreshVisibleObjects(Rectangle currentIndices, float zoom)
|
||||
{
|
||||
visibleObjectsBack.Clear();
|
||||
visibleObjectsFront.Clear();
|
||||
|
||||
float minSizeToDraw = MathHelper.Lerp(10.0f, 5.0f, Math.Min(zoom * 20.0f, 1.0f));
|
||||
|
||||
for (int x = currentIndices.X; x <= currentIndices.Width; x++)
|
||||
{
|
||||
for (int y = currentIndices.Y; y <= currentIndices.Height; y++)
|
||||
@@ -50,6 +54,22 @@ namespace Barotrauma
|
||||
if (objectGrid[x, y] == null) { continue; }
|
||||
foreach (LevelObject obj in objectGrid[x, y])
|
||||
{
|
||||
if (zoom < 0.05f)
|
||||
{
|
||||
//hide if the sprite is very small when zoomed this far out
|
||||
if ((obj.Sprite != null && Math.Min(obj.Sprite.size.X * zoom, obj.Sprite.size.Y * zoom) < 5.0f) ||
|
||||
(obj.ActivePrefab?.DeformableSprite != null && Math.Min(obj.ActivePrefab.DeformableSprite.Sprite.size.X * zoom, obj.ActivePrefab.DeformableSprite.Sprite.size.Y * zoom) < minSizeToDraw))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float zCutoff = MathHelper.Lerp(5000.0f, 500.0f, (0.05f - zoom) * 20.0f);
|
||||
if (obj.Position.Z > zCutoff)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var objectList = obj.Position.Z >= 0 ? visibleObjectsBack : visibleObjectsFront;
|
||||
int drawOrderIndex = 0;
|
||||
for (int i = 0; i < objectList.Count; i++)
|
||||
@@ -83,7 +103,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
|
||||
public void DrawObjects(SpriteBatch spriteBatch, Camera cam, bool drawFront, bool specular = false)
|
||||
public void DrawObjects(SpriteBatch spriteBatch, Camera cam, bool drawFront)
|
||||
{
|
||||
Rectangle indices = Rectangle.Empty;
|
||||
indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize);
|
||||
@@ -102,9 +122,14 @@ namespace Barotrauma
|
||||
indices.Height = Math.Min(indices.Height, objectGrid.GetLength(1) - 1);
|
||||
|
||||
float z = 0.0f;
|
||||
if (currentGridIndices != indices)
|
||||
if (currentGridIndices != indices && Timing.TotalTime > NextRefreshTime)
|
||||
{
|
||||
RefreshVisibleObjects(indices);
|
||||
RefreshVisibleObjects(indices, cam.Zoom);
|
||||
if (cam.Zoom < 0.1f)
|
||||
{
|
||||
//when zoomed very far out, refresh a little less often
|
||||
NextRefreshTime = Timing.TotalTime + MathHelper.Lerp(1.0f, 0.0f, cam.Zoom * 10.0f);
|
||||
}
|
||||
}
|
||||
|
||||
var objectList = drawFront ? visibleObjectsFront : visibleObjectsBack;
|
||||
@@ -113,19 +138,17 @@ namespace Barotrauma
|
||||
Vector2 camDiff = new Vector2(obj.Position.X, obj.Position.Y) - cam.WorldViewCenter;
|
||||
camDiff.Y = -camDiff.Y;
|
||||
|
||||
Sprite activeSprite = specular ? obj.SpecularSprite : obj.Sprite;
|
||||
Sprite activeSprite = obj.Sprite;
|
||||
activeSprite?.Draw(
|
||||
spriteBatch,
|
||||
new Vector2(obj.Position.X, -obj.Position.Y) - camDiff * obj.Position.Z / 10000.0f,
|
||||
Color.Lerp(Color.White, Level.Loaded.BackgroundTextureColor, obj.Position.Z / 5000.0f),
|
||||
Color.Lerp(Color.White, Level.Loaded.BackgroundTextureColor, obj.Position.Z / 3000.0f),
|
||||
activeSprite.Origin,
|
||||
obj.CurrentRotation,
|
||||
obj.CurrentScale,
|
||||
SpriteEffects.None,
|
||||
z);
|
||||
|
||||
if (specular) continue;
|
||||
|
||||
if (obj.ActivePrefab.DeformableSprite != null)
|
||||
{
|
||||
if (obj.CurrentSpriteDeformation != null)
|
||||
@@ -149,6 +172,7 @@ namespace Barotrauma
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Vector2(obj.Position.X, -obj.Position.Y), new Vector2(10.0f, 10.0f), GUI.Style.Red, true);
|
||||
|
||||
if (obj.Triggers == null) { continue; }
|
||||
foreach (LevelTrigger trigger in obj.Triggers)
|
||||
{
|
||||
if (trigger.PhysicsBody == null) continue;
|
||||
|
||||
+25
-6
@@ -126,7 +126,6 @@ namespace Barotrauma
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "childobject":
|
||||
case "lightsource":
|
||||
subElement.Remove();
|
||||
break;
|
||||
case "deformablesprite":
|
||||
@@ -141,11 +140,31 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
foreach (LightSourceParams lightSourceParams in LightSourceParams)
|
||||
for (int i = 0; i < LightSourceParams.Count; i++)
|
||||
{
|
||||
var lightElement = new XElement("LightSource");
|
||||
SerializableProperty.SerializeProperties(lightSourceParams, lightElement);
|
||||
element.Add(lightElement);
|
||||
int elementIndex = 0;
|
||||
bool wasSaved = false;
|
||||
foreach (XElement subElement in element.Elements().ToList())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "lightsource":
|
||||
if (elementIndex == i)
|
||||
{
|
||||
SerializableProperty.SerializeProperties(LightSourceParams[i], subElement);
|
||||
wasSaved = true;
|
||||
break;
|
||||
}
|
||||
elementIndex++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!wasSaved)
|
||||
{
|
||||
var lightElement = new XElement("LightSource");
|
||||
SerializableProperty.SerializeProperties(LightSourceParams[i], lightElement);
|
||||
element.Add(lightElement);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ChildObject childObj in ChildObjects)
|
||||
@@ -162,7 +181,7 @@ namespace Barotrauma
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().Equals("overridecommonness", System.StringComparison.OrdinalIgnoreCase)
|
||||
&& subElement.GetAttributeString("leveltype", "") == overrideCommonness.Key)
|
||||
&& subElement.GetAttributeString("leveltype", "").Equals(overrideCommonness.Key, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
subElement.Attribute("commonness").Value = overrideCommonness.Value.ToString("G", CultureInfo.InvariantCulture);
|
||||
elementFound = true;
|
||||
|
||||
Reference in New Issue
Block a user