- Added "LevelTriggers", areas that apply statuseffects and/or damage to entities. Atm can only be attached to background sprites.

- Moved background sprites to the shared project.
- The debug textures of physics bodies have a maximum size of 128x128 pixels to prevent large bodies from taking up excessive amounts of memory.
- Attacks can be set to only affect humans.
This commit is contained in:
Joonas Rikkonen
2017-08-23 20:37:30 +03:00
parent 2d1c00546f
commit c2da3a6af4
19 changed files with 467 additions and 225 deletions
@@ -11,9 +11,9 @@ namespace Barotrauma
{
const int MaxSprites = 100;
const float checkActiveInterval = 1.0f;
const float CheckActiveInterval = 1.0f;
float checkActiveTimer;
private float checkActiveTimer;
private List<BackgroundCreaturePrefab> prefabs = new List<BackgroundCreaturePrefab>();
private List<BackgroundCreature> activeSprites = new List<BackgroundCreature>();
@@ -104,15 +104,15 @@ namespace Barotrauma
public void Update(float deltaTime, Camera cam)
{
if (checkActiveTimer<0.0f)
if (checkActiveTimer < 0.0f)
{
foreach (BackgroundCreature sprite in activeSprites)
{
sprite.Enabled = (Math.Abs(sprite.TransformedPosition.X - cam.WorldViewCenter.X) < 4000.0f &&
Math.Abs(sprite.TransformedPosition.Y - cam.WorldViewCenter.Y) < 4000.0f);
sprite.Enabled = Math.Abs(sprite.TransformedPosition.X - cam.WorldViewCenter.X) < cam.WorldView.Width &&
Math.Abs(sprite.TransformedPosition.Y - cam.WorldViewCenter.Y) < cam.WorldView.Height;
}
checkActiveTimer = checkActiveInterval;
checkActiveTimer = CheckActiveInterval;
}
else
{
@@ -1,390 +0,0 @@
using Barotrauma.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Voronoi2;
namespace Barotrauma
{
class BackgroundSprite
{
public readonly BackgroundSpritePrefab Prefab;
public Vector3 Position;
public float Scale;
public float Rotation;
public Particles.ParticleEmitter ParticleEmitter;
//public Vector2[] spriteCorners;
public BackgroundSprite(BackgroundSpritePrefab prefab, Vector3 position, float scale, float rotation = 0.0f)
{
this.Prefab = prefab;
this.Position = position;
this.Scale = scale;
this.Rotation = rotation;
if (prefab.ParticleEmitterPrefab != null)
{
this.ParticleEmitter = new ParticleEmitter(prefab.ParticleEmitterPrefab);
}
}
}
class BackgroundSpriteManager
{
const int GridSize = 2000;
private List<BackgroundSpritePrefab> prefabs = new List<BackgroundSpritePrefab>();
private List<BackgroundSprite>[,] sprites;
private List<BackgroundSprite> visibleSprites = new List<BackgroundSprite>();
private Rectangle currentGridIndices;
private float swingTimer, swingState;
public BackgroundSpriteManager(string configPath)
{
LoadConfig(configPath);
}
public BackgroundSpriteManager(List<string> files)
{
foreach (var file in files)
{
LoadConfig(file);
}
}
private void LoadConfig(string configPath)
{
try
{
XDocument doc = ToolBox.TryLoadXml(configPath);
if (doc == null || doc.Root == null) return;
foreach (XElement element in doc.Root.Elements())
{
prefabs.Add(new BackgroundSpritePrefab(element));
}
}
catch (Exception e)
{
DebugConsole.ThrowError(String.Format("Failed to load BackgroundSprites from {0}", configPath), e);
}
}
public void PlaceSprites(Level level, int amount)
{
sprites = new List<BackgroundSprite>[
(int)Math.Ceiling(level.Size.X / GridSize),
(int)Math.Ceiling((level.Size.Y - level.BottomPos) / GridSize)];
for (int i = 0 ; i < amount; i++)
{
BackgroundSpritePrefab prefab = GetRandomPrefab(level.GenerationParams.Name);
GraphEdge selectedEdge = null;
Vector2 edgeNormal = Vector2.One;
Vector2? pos = FindSpritePosition(level, prefab, out selectedEdge, out edgeNormal);
if (pos == null) continue;
float rotation = 0.0f;
if (prefab.AlignWithSurface)
{
rotation = MathUtils.VectorToAngle(new Vector2(edgeNormal.Y, edgeNormal.X));
}
rotation += Rand.Range(prefab.RandomRotation.X, prefab.RandomRotation.Y, Rand.RandSync.ClientOnly);
var newSprite = new BackgroundSprite(prefab,
new Vector3((Vector2)pos, Rand.Range(prefab.DepthRange.X, prefab.DepthRange.Y, Rand.RandSync.ClientOnly)), Rand.Range(prefab.Scale.X, prefab.Scale.Y, Rand.RandSync.ClientOnly), rotation);
//calculate the positions of the corners of the rotated sprite
Vector2 halfSize = newSprite.Prefab.Sprite.size * newSprite.Scale / 2;
var spriteCorners = new List<Vector2>
{
-halfSize, new Vector2(-halfSize.X, halfSize.Y),
halfSize, new Vector2(halfSize.X, -halfSize.Y)
};
Vector2 pivotOffset = newSprite.Prefab.Sprite.Origin * newSprite.Scale - halfSize;
pivotOffset.X = -pivotOffset.X;
pivotOffset = new Vector2(
(float)(pivotOffset.X * Math.Cos(-rotation) - pivotOffset.Y * Math.Sin(-rotation)),
(float)(pivotOffset.X * Math.Sin(-rotation) + pivotOffset.Y * Math.Cos(-rotation)));
for (int j = 0; j < 4; j++)
{
spriteCorners[j] = new Vector2(
(float)(spriteCorners[j].X * Math.Cos(-rotation) - spriteCorners[j].Y * Math.Sin(-rotation)),
(float)(spriteCorners[j].X * Math.Sin(-rotation) + spriteCorners[j].Y * Math.Cos(-rotation)));
spriteCorners[j] += pos.Value + pivotOffset;
}
if (newSprite.ParticleEmitter != null)
{
Rectangle particleBounds = newSprite.ParticleEmitter.CalculateParticleBounds(pos.Value);
spriteCorners.Add(particleBounds.Location.ToVector2());
spriteCorners.Add(new Vector2(particleBounds.Right, particleBounds.Bottom));
}
int minX = (int)Math.Floor((spriteCorners.Min(c => c.X) - newSprite.Position.Z) / GridSize);
int maxX = (int)Math.Floor((spriteCorners.Max(c => c.X) + newSprite.Position.Z) / GridSize);
if (minX < 0 || maxX >= sprites.GetLength(0)) continue;
int minY = (int)Math.Floor((spriteCorners.Min(c => c.Y) - newSprite.Position.Z - level.BottomPos) / GridSize);
int maxY = (int)Math.Floor((spriteCorners.Max(c => c.Y) + newSprite.Position.Z - level.BottomPos) / GridSize);
if (minY < 0 || maxY >= sprites.GetLength(1)) continue;
for (int x = minX; x <= maxX; x++)
{
for (int y = minY; y <= maxY; y++)
{
if (sprites[x, y] == null) sprites[x, y] = new List<BackgroundSprite>();
sprites[x, y].Add(newSprite);
}
}
}
}
private Vector2? FindSpritePosition(Level level, BackgroundSpritePrefab prefab, out GraphEdge closestEdge, out Vector2 edgeNormal)
{
closestEdge = null;
edgeNormal = Vector2.One;
Vector2 randomPos = new Vector2(
Rand.Range(0.0f, level.Size.X, Rand.RandSync.ClientOnly),
Rand.Range(0.0f, level.Size.Y, Rand.RandSync.ClientOnly));
if (prefab.SpawnPos == BackgroundSpritePrefab.SpawnPosType.None) return randomPos;
List<GraphEdge> edges = new List<GraphEdge>();
List<Vector2> normals = new List<Vector2>();
System.Diagnostics.Debug.Assert(level.ExtraWalls.Length == 1);
List<VoronoiCell> cells = new List<VoronoiCell>();
if (prefab.SpawnPos.HasFlag(BackgroundSpritePrefab.SpawnPosType.Wall)) cells.AddRange(level.GetCells(randomPos));
if (prefab.SpawnPos.HasFlag(BackgroundSpritePrefab.SpawnPosType.SeaFloor)) cells.AddRange(level.ExtraWalls[0].Cells);
if (cells.Any())
{
VoronoiCell cell = cells[Rand.Int(cells.Count, Rand.RandSync.ClientOnly)];
foreach (GraphEdge edge in cell.edges)
{
if (!edge.isSolid || edge.OutsideLevel) continue;
Vector2 normal = edge.GetNormal(cell);
if (prefab.Alignment.HasFlag(Alignment.Bottom) && normal.Y < -0.5f)
{
edges.Add(edge);
}
else if (prefab.Alignment.HasFlag(Alignment.Top) && normal.Y > 0.5f)
{
edges.Add(edge);
}
else if (prefab.Alignment.HasFlag(Alignment.Left) && normal.X < -0.5f)
{
edges.Add(edge);
}
else if (prefab.Alignment.HasFlag(Alignment.Right) && normal.X > 0.5f)
{
edges.Add(edge);
}
else
{
continue;
}
normals.Add(normal);
}
}
if (prefab.SpawnPos.HasFlag(BackgroundSpritePrefab.SpawnPosType.RuinWall))
{
foreach (RuinGeneration.Ruin ruin in Level.Loaded.Ruins)
{
Rectangle expandedArea = ruin.Area;
expandedArea.Inflate(ruin.Area.Width, ruin.Area.Height);
if (!expandedArea.Contains(randomPos)) continue;
foreach (var ruinShape in ruin.RuinShapes)
{
foreach (var wall in ruinShape.Walls)
{
if (!prefab.Alignment.HasFlag(ruinShape.GetLineAlignment(wall))) continue;
edges.Add(new GraphEdge(wall.A, wall.B));
normals.Add((wall.A + wall.B) / 2.0f - ruinShape.Center);
}
}
}
}
if (!edges.Any()) return null;
int index = Rand.Int(edges.Count, Rand.RandSync.ClientOnly);
closestEdge = edges[index];
edgeNormal = normals[index];
float length = Vector2.Distance(closestEdge.point1, closestEdge.point2);
Vector2 dir = (closestEdge.point1 - closestEdge.point2) / length;
Vector2 pos = closestEdge.point2 + dir * Rand.Range(prefab.Sprite.size.X / 2.0f, length - prefab.Sprite.size.X / 2.0f, Rand.RandSync.ClientOnly);
return pos;
}
public void Update(float deltaTime)
{
swingTimer += deltaTime;
swingState = (float)Math.Sin(swingTimer * 0.1f);
foreach (BackgroundSprite s in visibleSprites)
{
if (s.Prefab.ParticleEmitterPrefab != null)
{
Vector2 emitterPos = new Vector2(s.Prefab.EmitterPosition.X, s.Prefab.EmitterPosition.Y) * s.Scale;
if (s.Rotation != 0.0f || s.Prefab.SwingAmount != 0.0f)
{
var ca = (float)Math.Cos(s.Rotation + swingState * s.Prefab.SwingAmount);
var sa = (float)Math.Sin(s.Rotation + swingState * s.Prefab.SwingAmount);
emitterPos = new Vector2(
ca * emitterPos.X + sa * emitterPos.Y,
-sa * emitterPos.X + ca * emitterPos.Y);
}
s.ParticleEmitter.Emit(deltaTime, new Vector2(s.Position.X, s.Position.Y) + emitterPos);
}
}
}
public void DrawSprites(SpriteBatch spriteBatch, Camera cam)
{
Rectangle indices = Rectangle.Empty;
indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize);
if (indices.X >= sprites.GetLength(0)) return;
indices.Y = (int)Math.Floor((cam.WorldView.Y - cam.WorldView.Height - Level.Loaded.BottomPos) / (float)GridSize);
if (indices.Y >= sprites.GetLength(1)) return;
indices.Width = (int)Math.Floor(cam.WorldView.Right / (float)GridSize)+1;
if (indices.Width < 0) return;
indices.Height = (int)Math.Floor((cam.WorldView.Y - Level.Loaded.BottomPos) / (float)GridSize)+1;
if (indices.Height < 0) return;
indices.X = Math.Max(indices.X, 0);
indices.Y = Math.Max(indices.Y, 0);
indices.Width = Math.Min(indices.Width, sprites.GetLength(0)-1);
indices.Height = Math.Min(indices.Height, sprites.GetLength(1)-1);
float z = 0.0f;
if (currentGridIndices != indices)
{
visibleSprites.Clear();
for (int x = indices.X; x <= indices.Width; x++)
{
for (int y = indices.Y; y <= indices.Height; y++)
{
if (sprites[x, y] == null) continue;
foreach (BackgroundSprite sprite in sprites[x, y])
{
int drawOrderIndex = 0;
for (int i = 0; i < visibleSprites.Count; i++)
{
if (visibleSprites[i] == sprite)
{
drawOrderIndex = -1;
break;
}
if (visibleSprites[i].Position.Z > sprite.Position.Z)
{
break;
}
else
{
drawOrderIndex = i + 1;
}
}
if (drawOrderIndex >= 0)
{
visibleSprites.Insert(drawOrderIndex, sprite);
}
}
}
}
currentGridIndices = indices;
}
foreach (BackgroundSprite sprite in visibleSprites)
{
Vector2 camDiff = new Vector2(sprite.Position.X, sprite.Position.Y) - cam.WorldViewCenter;
camDiff.Y = -camDiff.Y;
sprite.Prefab.Sprite.Draw(
spriteBatch,
new Vector2(sprite.Position.X, -sprite.Position.Y) - camDiff * sprite.Position.Z / 10000.0f,
Color.Lerp(Color.White, Level.Loaded.BackgroundColor, sprite.Position.Z / 5000.0f),
sprite.Rotation + swingState * sprite.Prefab.SwingAmount,
sprite.Scale,
SpriteEffects.None,
z);
/*for (int i = 0; i < 4; i++)
{
GUI.DrawLine(spriteBatch,
new Vector2(sprite.spriteCorners[i].X, -sprite.spriteCorners[i].Y),
new Vector2(sprite.spriteCorners[(i + 1) % 4].X, -sprite.spriteCorners[(i + 1) % 4].Y),
Color.White, 0, 5);
}*/
if (GameMain.DebugDraw)
{
GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true);
}
z += 0.0001f;
}
}
private BackgroundSpritePrefab GetRandomPrefab(string levelType)
{
int totalCommonness = 0;
foreach (BackgroundSpritePrefab prefab in prefabs)
{
totalCommonness += prefab.GetCommonness(levelType);
}
float randomNumber = Rand.Int(totalCommonness+1, Rand.RandSync.ClientOnly);
foreach (BackgroundSpritePrefab prefab in prefabs)
{
if (randomNumber <= prefab.GetCommonness(levelType))
{
return prefab;
}
randomNumber -= prefab.GetCommonness(levelType);
}
return null;
}
}
}
@@ -1,112 +0,0 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Barotrauma
{
class BackgroundSpritePrefab
{
[Flags]
public enum SpawnPosType
{
None = 0,
Wall = 1,
RuinWall = 2,
SeaFloor = 4
}
public readonly Sprite Sprite;
public readonly Alignment Alignment;
public readonly Vector2 Scale;
public SpawnPosType SpawnPos;
public readonly bool AlignWithSurface;
public readonly Vector2 RandomRotation;
public readonly Vector2 DepthRange;
public readonly Particles.ParticleEmitterPrefab ParticleEmitterPrefab;
public readonly Vector2 EmitterPosition;
public readonly float SwingAmount;
public readonly int Commonness;
public Dictionary<string, int> OverrideCommonness;
public BackgroundSpritePrefab(XElement element)
{
string alignmentStr = ToolBox.GetAttributeString(element, "alignment", "");
if (string.IsNullOrEmpty(alignmentStr) || !Enum.TryParse(alignmentStr, out Alignment))
{
Alignment = Alignment.Top | Alignment.Bottom | Alignment.Left | Alignment.Right;
}
Commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
string[] spawnPosStrs = ToolBox.GetAttributeString(element, "spawnpos", "Wall").Split(',');
foreach (string spawnPosStr in spawnPosStrs)
{
SpawnPosType parsedSpawnPos;
if (Enum.TryParse(spawnPosStr.Trim(), out parsedSpawnPos))
{
SpawnPos |= parsedSpawnPos;
}
}
Scale.X = ToolBox.GetAttributeFloat(element, "minsize", 1.0f);
Scale.Y = ToolBox.GetAttributeFloat(element, "maxsize", 1.0f);
DepthRange = ToolBox.GetAttributeVector2(element, "depthrange", new Vector2(0.0f, 1.0f));
AlignWithSurface = ToolBox.GetAttributeBool(element, "alignwithsurface", false);
RandomRotation = ToolBox.GetAttributeVector2(element, "randomrotation", Vector2.Zero);
RandomRotation.X = MathHelper.ToRadians(RandomRotation.X);
RandomRotation.Y = MathHelper.ToRadians(RandomRotation.Y);
SwingAmount = MathHelper.ToRadians(ToolBox.GetAttributeFloat(element, "swingamount", 0.0f));
OverrideCommonness = new Dictionary<string, int>();
foreach (XElement subElement in element.Elements())
{
switch(subElement.Name.ToString().ToLowerInvariant())
{
case "sprite":
Sprite = new Sprite(subElement);
break;
case "overridecommonness":
string levelType = ToolBox.GetAttributeString(subElement, "leveltype", "");
if (!OverrideCommonness.ContainsKey(levelType))
{
OverrideCommonness.Add(levelType, ToolBox.GetAttributeInt(subElement, "commonness", 1));
}
break;
case "particleemitter":
ParticleEmitterPrefab = new Particles.ParticleEmitterPrefab(subElement);
EmitterPosition = ToolBox.GetAttributeVector2(subElement, "position", Vector2.Zero);
break;
}
}
}
public int GetCommonness(string levelType)
{
int commonness = 0;
if (!OverrideCommonness.TryGetValue(levelType, out commonness))
{
return Commonness;
}
return commonness;
}
}
}
@@ -17,10 +17,6 @@ namespace Barotrauma.Tutorials
public override IEnumerable<object> UpdateState()
{
//spawn some fish next to the player
GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(2,
Submarine.MainSub.Position + Character.Controlled.Position);
foreach (Item item in Item.ItemList)
{
var wire = item.GetComponent<Wire>();
@@ -0,0 +1,132 @@
using Barotrauma.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
namespace Barotrauma
{
partial class BackgroundSprite
{
public ParticleEmitter ParticleEmitter;
}
partial class BackgroundSpriteManager
{
private List<BackgroundSprite> visibleSprites = new List<BackgroundSprite>();
private Rectangle currentGridIndices;
partial void UpdateProjSpecific(float deltaTime)
{
foreach (BackgroundSprite s in visibleSprites)
{
if (s.Prefab.ParticleEmitterPrefab != null)
{
Vector2 emitterPos = new Vector2(s.Prefab.EmitterPosition.X, s.Prefab.EmitterPosition.Y) * s.Scale;
if (s.Rotation != 0.0f || s.Prefab.SwingAmount != 0.0f)
{
var ca = (float)Math.Cos(s.Rotation + swingState * s.Prefab.SwingAmount);
var sa = (float)Math.Sin(s.Rotation + swingState * s.Prefab.SwingAmount);
emitterPos = new Vector2(
ca * emitterPos.X + sa * emitterPos.Y,
-sa * emitterPos.X + ca * emitterPos.Y);
}
s.ParticleEmitter.Emit(deltaTime, new Vector2(s.Position.X, s.Position.Y) + emitterPos);
}
}
}
public void DrawSprites(SpriteBatch spriteBatch, Camera cam)
{
Rectangle indices = Rectangle.Empty;
indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize);
if (indices.X >= spriteGrid.GetLength(0)) return;
indices.Y = (int)Math.Floor((cam.WorldView.Y - cam.WorldView.Height - Level.Loaded.BottomPos) / (float)GridSize);
if (indices.Y >= spriteGrid.GetLength(1)) return;
indices.Width = (int)Math.Floor(cam.WorldView.Right / (float)GridSize)+1;
if (indices.Width < 0) return;
indices.Height = (int)Math.Floor((cam.WorldView.Y - Level.Loaded.BottomPos) / (float)GridSize)+1;
if (indices.Height < 0) return;
indices.X = Math.Max(indices.X, 0);
indices.Y = Math.Max(indices.Y, 0);
indices.Width = Math.Min(indices.Width, spriteGrid.GetLength(0)-1);
indices.Height = Math.Min(indices.Height, spriteGrid.GetLength(1)-1);
float z = 0.0f;
if (currentGridIndices != indices)
{
visibleSprites.Clear();
for (int x = indices.X; x <= indices.Width; x++)
{
for (int y = indices.Y; y <= indices.Height; y++)
{
if (spriteGrid[x, y] == null) continue;
foreach (BackgroundSprite sprite in spriteGrid[x, y])
{
int drawOrderIndex = 0;
for (int i = 0; i < visibleSprites.Count; i++)
{
if (visibleSprites[i] == sprite)
{
drawOrderIndex = -1;
break;
}
if (visibleSprites[i].Position.Z > sprite.Position.Z)
{
break;
}
else
{
drawOrderIndex = i + 1;
}
}
if (drawOrderIndex >= 0)
{
visibleSprites.Insert(drawOrderIndex, sprite);
}
}
}
}
currentGridIndices = indices;
}
foreach (BackgroundSprite sprite in visibleSprites)
{
Vector2 camDiff = new Vector2(sprite.Position.X, sprite.Position.Y) - cam.WorldViewCenter;
camDiff.Y = -camDiff.Y;
sprite.Prefab.Sprite.Draw(
spriteBatch,
new Vector2(sprite.Position.X, -sprite.Position.Y) - camDiff * sprite.Position.Z / 10000.0f,
Color.Lerp(Color.White, Level.Loaded.BackgroundColor, sprite.Position.Z / 5000.0f),
sprite.Rotation + swingState * sprite.Prefab.SwingAmount,
sprite.Scale,
SpriteEffects.None,
z);
if (GameMain.DebugDraw)
{
GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true);
if (sprite.Trigger != null && sprite.Trigger.PhysicsBody != null)
{
sprite.Trigger.PhysicsBody.UpdateDrawPosition();
sprite.Trigger.PhysicsBody.DebugDraw(spriteBatch, Color.Cyan);
}
}
z += 0.0001f;
}
}
}
}
@@ -0,0 +1,10 @@
using Microsoft.Xna.Framework;
namespace Barotrauma
{
partial class BackgroundSpritePrefab
{
public readonly Particles.ParticleEmitterPrefab ParticleEmitterPrefab;
public readonly Vector2 EmitterPosition;
}
}
@@ -7,6 +7,8 @@ namespace Barotrauma
{
private LevelRenderer renderer;
private BackgroundCreatureManager backgroundCreatureManager;
public void DrawFront(SpriteBatch spriteBatch)
{
if (renderer == null) return;
@@ -32,7 +34,7 @@ namespace Barotrauma
}
}
public void DrawBack(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, BackgroundCreatureManager backgroundSpriteManager = null)
public void DrawBack(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, BackgroundCreatureManager backgroundCreatureManager = null)
{
float brightness = MathHelper.Clamp(50.0f + (cam.Position.Y - Size.Y) / 2000.0f, 10.0f, 40.0f);
@@ -42,7 +44,7 @@ namespace Barotrauma
graphics.Clear(backgroundColor);
if (renderer == null) return;
renderer.DrawBackground(spriteBatch, cam, backgroundSpriteManager);
renderer.DrawBackground(spriteBatch, cam, backgroundSpriteManager, backgroundCreatureManager);
}
}
}
@@ -13,8 +13,6 @@ namespace Barotrauma
private static Sprite dustParticles;
private static Texture2D shaftTexture;
private static BackgroundSpriteManager backgroundSpriteManager;
Vector2 dustOffset;
private Level level;
@@ -57,31 +55,13 @@ namespace Barotrauma
};
wallCenterEffect.CurrentTechnique = wallCenterEffect.Techniques["BasicEffect_Texture"];
}
if (backgroundSpriteManager==null)
{
var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.BackgroundSpritePrefabs);
if (files.Count > 0)
backgroundSpriteManager = new BackgroundSpriteManager(files);
else
backgroundSpriteManager = new BackgroundSpriteManager("Content/BackgroundSprites/BackgroundSpritePrefabs.xml");
}
this.level = level;
}
public void PlaceSprites(int amount)
{
backgroundSpriteManager.PlaceSprites(level, amount);
}
public void Update(float deltaTime)
{
dustOffset -= Vector2.UnitY * 10.0f * deltaTime;
backgroundSpriteManager.Update(deltaTime);
}
public static VertexPositionColorTexture[] GetColoredVertices(VertexPositionTexture[] vertices, Color color)
@@ -118,7 +98,9 @@ namespace Barotrauma
bodyVertices.SetData(vertices);
}
public void DrawBackground(SpriteBatch spriteBatch, Camera cam, BackgroundCreatureManager backgroundCreatureManager = null)
public void DrawBackground(SpriteBatch spriteBatch, Camera cam,
BackgroundSpriteManager backgroundSpriteManager = null,
BackgroundCreatureManager backgroundCreatureManager = null)
{
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap);
@@ -152,11 +134,9 @@ namespace Barotrauma
SamplerState.LinearWrap, DepthStencilState.Default, null, null,
cam.Transform);
backgroundSpriteManager.DrawSprites(spriteBatch, cam);
if (backgroundCreatureManager!=null) backgroundCreatureManager.Draw(spriteBatch);
if (backgroundSpriteManager != null) backgroundSpriteManager.DrawSprites(spriteBatch, cam);
if (backgroundCreatureManager != null) backgroundCreatureManager.Draw(spriteBatch);
for (int i = 0; i < 4; i++)
{
float scale = 1.0f - i * 0.2f;
@@ -7,6 +7,8 @@ namespace Barotrauma
{
partial class PhysicsBody
{
private float bodyShapeTextureScale;
private Texture2D bodyShapeTexture;
public Texture2D BodyShapeTexture
{
@@ -59,18 +61,45 @@ namespace Barotrauma
switch (BodyShape)
{
case PhysicsBody.Shape.Rectangle:
bodyShapeTexture = GUI.CreateRectangle(
(int)ConvertUnits.ToDisplayUnits(width),
(int)ConvertUnits.ToDisplayUnits(height));
break;
{
float maxSize = Math.Max(ConvertUnits.ToDisplayUnits(width), ConvertUnits.ToDisplayUnits(height));
if (maxSize > 128.0f)
{
bodyShapeTextureScale = 128.0f / maxSize;
}
else
{
bodyShapeTextureScale = 1.0f;
}
bodyShapeTexture = GUI.CreateRectangle(
(int)ConvertUnits.ToDisplayUnits(width * bodyShapeTextureScale),
(int)ConvertUnits.ToDisplayUnits(height * bodyShapeTextureScale));
break;
}
case PhysicsBody.Shape.Capsule:
bodyShapeTexture = GUI.CreateCapsule(
(int)ConvertUnits.ToDisplayUnits(radius),
(int)ConvertUnits.ToDisplayUnits(Math.Max(height, width)));
break;
{
float maxSize = Math.Max(ConvertUnits.ToDisplayUnits(radius), ConvertUnits.ToDisplayUnits(Math.Max(height, width)));
if (maxSize > 128.0f)
{
bodyShapeTextureScale = 128.0f / maxSize;
}
else
{
bodyShapeTextureScale = 1.0f;
}
bodyShapeTexture = GUI.CreateCapsule(
(int)ConvertUnits.ToDisplayUnits(radius * bodyShapeTextureScale),
(int)ConvertUnits.ToDisplayUnits(Math.Max(height, width) * bodyShapeTextureScale));
break;
}
case PhysicsBody.Shape.Circle:
bodyShapeTexture = GUI.CreateCircle((int)ConvertUnits.ToDisplayUnits(radius));
if (ConvertUnits.ToDisplayUnits(radius)> 128.0f)
{
bodyShapeTextureScale = 128.0f / ConvertUnits.ToDisplayUnits(radius);
}
bodyShapeTexture = GUI.CreateCircle((int)ConvertUnits.ToDisplayUnits(radius * bodyShapeTextureScale));
break;
}
}
@@ -80,7 +109,7 @@ namespace Barotrauma
{
rot -= MathHelper.PiOver2;
}
spriteBatch.Draw(
bodyShapeTexture,
new Vector2(DrawPosition.X, -DrawPosition.Y),
@@ -88,7 +117,7 @@ namespace Barotrauma
color,
rot,
new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2),
1.0f, SpriteEffects.None, 0.0f);
1.0f / bodyShapeTextureScale, SpriteEffects.None, 0.0f);
}
partial void DisposeProjSpecific()
@@ -22,7 +22,6 @@ namespace Barotrauma
private Texture2D damageStencil;
public BackgroundCreatureManager BackgroundCreatureManager;
public GameScreen(GraphicsDevice graphics, ContentManager content)
{
@@ -34,11 +33,6 @@ namespace Barotrauma
renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.BackgroundCreaturePrefabs);
if (files.Count > 0)
BackgroundCreatureManager = new BackgroundCreatureManager(files);
else
BackgroundCreatureManager = new BackgroundCreatureManager("Content/BackgroundSprites/BackgroundCreaturePrefabs.xml");
#if LINUX
var blurEffect = content.Load<Effect>("blurshader_opengl");
@@ -145,7 +139,7 @@ namespace Barotrauma
}
else
{
Level.Loaded.DrawBack(graphics, spriteBatch, cam, BackgroundCreatureManager);
Level.Loaded.DrawBack(graphics, spriteBatch, cam);
}
spriteBatch.Begin(SpriteSortMode.BackToFront,