Optimization: FindHull spatial hashing, itemcomponent sounds in a dictionary, got rid of Item.Updated, rendering fixes, disposing shadow vertex buffers
This commit is contained in:
Binary file not shown.
@@ -79,11 +79,6 @@ namespace FarseerPhysics.Collision.Shapes
|
|||||||
|
|
||||||
// If the code crashes here, it means your vertices are too close together.
|
// If the code crashes here, it means your vertices are too close together.
|
||||||
|
|
||||||
if (Vector2.DistanceSquared(v1, v2) < Settings.LinearSlop * Settings.LinearSlop)
|
|
||||||
{
|
|
||||||
int asldmfk = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.Assert(Vector2.DistanceSquared(v1, v2) > Settings.LinearSlop * Settings.LinearSlop);
|
Debug.Assert(Vector2.DistanceSquared(v1, v2) > Settings.LinearSlop * Settings.LinearSlop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,7 @@
|
|||||||
<Compile Include="Source\Items\Components\ItemLabel.cs" />
|
<Compile Include="Source\Items\Components\ItemLabel.cs" />
|
||||||
<Compile Include="Source\Items\FixRequirement.cs" />
|
<Compile Include="Source\Items\FixRequirement.cs" />
|
||||||
<Compile Include="Source\Items\ItemSpawner.cs" />
|
<Compile Include="Source\Items\ItemSpawner.cs" />
|
||||||
|
<Compile Include="Source\Map\EntityGrid.cs" />
|
||||||
<Compile Include="Source\Map\FireSource.cs" />
|
<Compile Include="Source\Map\FireSource.cs" />
|
||||||
<Compile Include="Source\Map\Levels\LevelRenderer.cs" />
|
<Compile Include="Source\Map\Levels\LevelRenderer.cs" />
|
||||||
<Compile Include="Source\Map\Levels\WrappingWall.cs" />
|
<Compile Include="Source\Map\Levels\WrappingWall.cs" />
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public List<Skill> requiredSkills;
|
public List<Skill> requiredSkills;
|
||||||
|
|
||||||
private List<ItemSound> sounds;
|
private Dictionary<ActionType,List<ItemSound>> sounds;
|
||||||
|
|
||||||
private GUIFrame guiFrame;
|
private GUIFrame guiFrame;
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
requiredSkills = new List<Skill>();
|
requiredSkills = new List<Skill>();
|
||||||
|
|
||||||
sounds = new List<ItemSound>();
|
sounds = new Dictionary<ActionType, List<ItemSound>>();
|
||||||
|
|
||||||
statusEffects = new List<StatusEffect>();
|
statusEffects = new List<StatusEffect>();
|
||||||
|
|
||||||
@@ -283,7 +283,15 @@ namespace Barotrauma.Items.Components
|
|||||||
ItemSound itemSound = new ItemSound(sound, type, range, loop);
|
ItemSound itemSound = new ItemSound(sound, type, range, loop);
|
||||||
itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", "");
|
itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", "");
|
||||||
itemSound.VolumeMultiplier = ToolBox.GetAttributeFloat(subElement, "volumemultiplier", 1.0f);
|
itemSound.VolumeMultiplier = ToolBox.GetAttributeFloat(subElement, "volumemultiplier", 1.0f);
|
||||||
sounds.Add(itemSound);
|
|
||||||
|
List<ItemSound> soundList = null;
|
||||||
|
if (!sounds.TryGetValue(itemSound.Type, out soundList))
|
||||||
|
{
|
||||||
|
soundList = new List<ItemSound>();
|
||||||
|
sounds.Add(itemSound.Type, soundList);
|
||||||
|
}
|
||||||
|
|
||||||
|
soundList.Add(itemSound);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ItemComponent ic = ItemComponent.Load(subElement, item, item.ConfigFile, false);
|
ItemComponent ic = ItemComponent.Load(subElement, item, item.ConfigFile, false);
|
||||||
@@ -307,8 +315,8 @@ namespace Barotrauma.Items.Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ItemSound> matchingSounds = sounds.FindAll(x => x.Type == type);
|
List<ItemSound> matchingSounds = null;
|
||||||
if (matchingSounds.Count == 0) return;
|
if (!sounds.TryGetValue(type, out matchingSounds)) return;
|
||||||
|
|
||||||
ItemSound itemSound = null;
|
ItemSound itemSound = null;
|
||||||
if (!Sounds.SoundManager.IsPlaying(loopingSoundIndex))
|
if (!Sounds.SoundManager.IsPlaying(loopingSoundIndex))
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ namespace Barotrauma.Items.Components
|
|||||||
static float fullPower;
|
static float fullPower;
|
||||||
static float fullLoad;
|
static float fullLoad;
|
||||||
|
|
||||||
|
//private bool updated;
|
||||||
|
|
||||||
|
private int updateTimer;
|
||||||
|
|
||||||
const float FireProbability = 0.15f;
|
const float FireProbability = 0.15f;
|
||||||
|
|
||||||
//affects how fast changes in power/load are carried over the grid
|
//affects how fast changes in power/load are carried over the grid
|
||||||
@@ -40,9 +44,14 @@ namespace Barotrauma.Items.Components
|
|||||||
fullLoad = 0.0f;
|
fullLoad = 0.0f;
|
||||||
connectedList.Clear();
|
connectedList.Clear();
|
||||||
|
|
||||||
if (updated) return;
|
if (updateTimer > 0)
|
||||||
|
{
|
||||||
|
updateTimer--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CheckJunctions(deltaTime);
|
CheckJunctions(deltaTime);
|
||||||
|
updateTimer = 0;
|
||||||
|
|
||||||
foreach (Powered p in connectedList)
|
foreach (Powered p in connectedList)
|
||||||
{
|
{
|
||||||
@@ -54,51 +63,43 @@ namespace Barotrauma.Items.Components
|
|||||||
pt.Item.SendSignal("", "power", fullPower / Math.Max(fullLoad, 1.0f));
|
pt.Item.SendSignal("", "power", fullPower / Math.Max(fullLoad, 1.0f));
|
||||||
|
|
||||||
//damage the item if voltage is too high
|
//damage the item if voltage is too high
|
||||||
if (-pt.currPowerConsumption > Math.Max(pt.powerLoad * 2.0f, 200.0f))
|
if (-pt.currPowerConsumption < Math.Max(pt.powerLoad * 2.0f, 200.0f)) continue;
|
||||||
|
|
||||||
|
float prevCondition = pt.item.Condition;
|
||||||
|
pt.item.Condition -= deltaTime * 10.0f;
|
||||||
|
|
||||||
|
if (pt.item.Condition <= 0.0f && prevCondition > 0.0f)
|
||||||
{
|
{
|
||||||
|
sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.WorldPosition);
|
||||||
|
|
||||||
float prevCondition = pt.item.Condition;
|
Vector2 baseVel = Rand.Vector(300.0f);
|
||||||
pt.item.Condition -= deltaTime * 10.0f;
|
for (int i = 0; i < 10; i++)
|
||||||
|
|
||||||
if (pt.item.Condition<=0.0f && prevCondition > 0.0f)
|
|
||||||
{
|
{
|
||||||
sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.WorldPosition);
|
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.WorldPosition,
|
||||||
|
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
|
||||||
|
|
||||||
Vector2 baseVel = Rand.Vector(300.0f);
|
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
|
||||||
for (int i = 0; i < 10; i++)
|
}
|
||||||
{
|
|
||||||
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.WorldPosition,
|
|
||||||
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
|
|
||||||
|
|
||||||
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
|
if (FireProbability > 0.0f && Rand.Int((int)(1.0f / FireProbability)) == 1)
|
||||||
}
|
{
|
||||||
|
new FireSource(pt.item.WorldPosition);
|
||||||
if (FireProbability > 0.0f && Rand.Int((int)(1.0f / FireProbability)) == 1)
|
|
||||||
{
|
|
||||||
new FireSource(pt.item.WorldPosition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Pick(Character picker)
|
public override bool Pick(Character picker)
|
||||||
{
|
{
|
||||||
if (picker == null) return false;
|
return picker != null;
|
||||||
|
|
||||||
//picker.SelectedConstruction = (picker.SelectedConstruction == item) ? null : item;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//a recursive function that goes through all the junctions and adds up
|
//a recursive function that goes through all the junctions and adds up
|
||||||
//all the generated/consumed power of the constructions connected to the grid
|
//all the generated/consumed power of the constructions connected to the grid
|
||||||
private void CheckJunctions(float deltaTime)
|
private void CheckJunctions(float deltaTime)
|
||||||
{
|
{
|
||||||
updated = true;
|
updateTimer = 1;
|
||||||
connectedList.Add(this);
|
connectedList.Add(this);
|
||||||
|
|
||||||
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
||||||
@@ -119,11 +120,12 @@ namespace Barotrauma.Items.Components
|
|||||||
//if (it.Updated) continue;
|
//if (it.Updated) continue;
|
||||||
|
|
||||||
Powered powered = it.GetComponent<Powered>();
|
Powered powered = it.GetComponent<Powered>();
|
||||||
if (powered == null || powered.Updated) continue;
|
if (powered == null) continue;
|
||||||
|
|
||||||
PowerTransfer powerTransfer = powered as PowerTransfer;
|
PowerTransfer powerTransfer = powered as PowerTransfer;
|
||||||
if (powerTransfer != null)
|
if (powerTransfer != null)
|
||||||
{
|
{
|
||||||
|
if (powerTransfer.updateTimer>0) continue;
|
||||||
powerTransfer.CheckJunctions(deltaTime);
|
powerTransfer.CheckJunctions(deltaTime);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -143,7 +145,6 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ namespace Barotrauma
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
|
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
|
||||||
#else
|
#else
|
||||||
if (slotIndex<0 || slotIndex>=items.Length) return;
|
if (slotIndex<0 || slotIndex>=Items.Length) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5,
|
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5,
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ namespace Barotrauma
|
|||||||
get { return condition; }
|
get { return condition; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (float.IsNaN(value)) return;
|
if (!MathUtils.IsValid(value)) return;
|
||||||
|
|
||||||
float prev = condition;
|
float prev = condition;
|
||||||
condition = MathHelper.Clamp(value, 0.0f, 100.0f);
|
condition = MathHelper.Clamp(value, 0.0f, 100.0f);
|
||||||
@@ -167,14 +167,6 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Updated
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
foreach (ItemComponent ic in components) ic.Updated = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemPrefab Prefab
|
public ItemPrefab Prefab
|
||||||
{
|
{
|
||||||
get { return prefab; }
|
get { return prefab; }
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Barotrauma
|
||||||
|
{
|
||||||
|
class EntityGrid
|
||||||
|
{
|
||||||
|
private List<MapEntity>[,] entities;
|
||||||
|
|
||||||
|
private Rectangle limits;
|
||||||
|
|
||||||
|
private float cellSize;
|
||||||
|
|
||||||
|
public EntityGrid(Rectangle limits, float cellSize)
|
||||||
|
{
|
||||||
|
this.limits = limits;
|
||||||
|
this.cellSize = cellSize;
|
||||||
|
|
||||||
|
entities = new List<MapEntity>[(int)Math.Ceiling(limits.Width / cellSize),(int)Math.Ceiling(limits.Height / cellSize)];
|
||||||
|
for (int x = 0; x<entities.GetLength(0); x++)
|
||||||
|
{
|
||||||
|
for (int y=0; y<entities.GetLength(1); y++)
|
||||||
|
{
|
||||||
|
entities[x, y] = new List<MapEntity>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertEntity(MapEntity entity)
|
||||||
|
{
|
||||||
|
Rectangle rect = entity.Rect;
|
||||||
|
//if (Submarine.Loaded != null) rect.Offset(-Submarine.HiddenSubPosition);
|
||||||
|
Rectangle indices = GetIndices(rect);
|
||||||
|
if (indices.X<0 || indices.Width>=entities.GetLength(0) ||
|
||||||
|
indices.Y<0 || indices.Height>=entities.GetLength(1))
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error in EntityGrid.InsertEntity: "+entity+" is outside the grid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x=indices.X; x<=indices.Width; x++)
|
||||||
|
{
|
||||||
|
for (int y = indices.Y; y<=indices.Height; y++)
|
||||||
|
{
|
||||||
|
entities[x, y].Add(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveEntity(MapEntity entity)
|
||||||
|
{
|
||||||
|
Rectangle indices = GetIndices(entity.Rect);
|
||||||
|
if (indices.X < 0 || indices.Width >= entities.GetLength(0) ||
|
||||||
|
indices.Y < 0 || indices.Height >= entities.GetLength(1))
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error in EntityGrid.RemoveEntity: " + entity + " is outside the grid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = indices.X; x <= indices.Width; x++)
|
||||||
|
{
|
||||||
|
for (int y = indices.Y; y <= indices.Height; y++)
|
||||||
|
{
|
||||||
|
entities[x, y].Remove(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
for (int x = 0; x < entities.GetLength(0); x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < entities.GetLength(1); y++)
|
||||||
|
{
|
||||||
|
entities[x, y].Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MapEntity> GetEntities(Vector2 position)
|
||||||
|
{
|
||||||
|
if (Submarine.Loaded != null) position -= Submarine.HiddenSubPosition;
|
||||||
|
|
||||||
|
if (position.X < limits.X || position.Y > limits.Y ||
|
||||||
|
position.X > limits.Right || position.Y < limits.Y - limits.Height)
|
||||||
|
{
|
||||||
|
return new List<MapEntity>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Point indices = GetIndices(position);
|
||||||
|
|
||||||
|
return entities[indices.X, indices.Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle GetIndices(Rectangle rect)
|
||||||
|
{
|
||||||
|
Rectangle indices = Rectangle.Empty;
|
||||||
|
indices.X = (int)Math.Floor((rect.X - limits.X) / cellSize);
|
||||||
|
indices.Y = (int)Math.Floor((limits.Y - rect.Y)/cellSize);
|
||||||
|
|
||||||
|
indices.Width = (int)Math.Floor((rect.Right - limits.X) / cellSize);
|
||||||
|
indices.Height = (int)Math.Floor((limits.Y - (rect.Y-rect.Height)) / cellSize);
|
||||||
|
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point GetIndices(Vector2 position)
|
||||||
|
{
|
||||||
|
return new Point(
|
||||||
|
(int)Math.Floor((position.X - limits.X) / cellSize),
|
||||||
|
(int)Math.Floor((limits.Y - position.Y) / cellSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ namespace Barotrauma
|
|||||||
class Hull : MapEntity
|
class Hull : MapEntity
|
||||||
{
|
{
|
||||||
public static List<Hull> hullList = new List<Hull>();
|
public static List<Hull> hullList = new List<Hull>();
|
||||||
|
private static EntityGrid entityGrid;
|
||||||
|
|
||||||
public static bool EditWater, EditFire;
|
public static bool EditWater, EditFire;
|
||||||
|
|
||||||
@@ -165,9 +166,21 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Volume = 0.0f;
|
Volume = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
InsertToList();
|
InsertToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnMapLoaded()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (entityGrid == null)
|
||||||
|
{
|
||||||
|
entityGrid = new EntityGrid(Submarine.Borders, 200.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
entityGrid.InsertEntity(this);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Contains(Vector2 position)
|
public override bool Contains(Vector2 position)
|
||||||
{
|
{
|
||||||
return (Submarine.RectContains(WorldRect, position) &&
|
return (Submarine.RectContains(WorldRect, position) &&
|
||||||
@@ -210,6 +223,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
//renderer.Dispose();
|
//renderer.Dispose();
|
||||||
|
|
||||||
|
entityGrid.RemoveEntity(this);
|
||||||
|
|
||||||
hullList.Remove(this);
|
hullList.Remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,10 +496,30 @@ namespace Barotrauma
|
|||||||
//returns the water block which contains the point (or null if it isn't inside any)
|
//returns the water block which contains the point (or null if it isn't inside any)
|
||||||
public static Hull FindHull(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
|
public static Hull FindHull(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
|
||||||
{
|
{
|
||||||
return FindHull(position, hullList, guess, useWorldCoordinates);
|
if (entityGrid == null) return null;
|
||||||
|
|
||||||
|
if (guess != null)
|
||||||
|
{
|
||||||
|
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position)) return guess;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entities = entityGrid.GetEntities(useWorldCoordinates ? position-Submarine.Loaded.Position : position);
|
||||||
|
|
||||||
|
foreach (Hull hull in entities)
|
||||||
|
{
|
||||||
|
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position)) return hull;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Hull FindHull(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
|
//returns the water block which contains the point (or null if it isn't inside any)
|
||||||
|
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
|
||||||
|
{
|
||||||
|
return FindHullOld(position, hullList, guess, useWorldCoordinates);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
|
||||||
{
|
{
|
||||||
if (guess != null && hulls.Contains(guess))
|
if (guess != null && hulls.Contains(guess))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -314,8 +314,8 @@ namespace Barotrauma
|
|||||||
wrappingWalls[side, i] = new WrappingWall(pathCells, cells, borders.Height * 0.5f,
|
wrappingWalls[side, i] = new WrappingWall(pathCells, cells, borders.Height * 0.5f,
|
||||||
(side == 0 ? -1 : 1) * (i == 0 ? 1 : 2));
|
(side == 0 ? -1 : 1) * (i == 0 ? 1 : 2));
|
||||||
|
|
||||||
wrappingWalls[side, i].BodyVertices = GeneratePolygons(wrappingWalls[side, i].Cells, new List<VoronoiCell>(), false);
|
wrappingWalls[side, i].SetBodyVertices(GeneratePolygons(wrappingWalls[side, i].Cells, new List<VoronoiCell>(), false));
|
||||||
wrappingWalls[side, i].WallVertices = GenerateWallShapes(wrappingWalls[side, i].Cells);
|
wrappingWalls[side, i].SetWallVertices(GenerateWallShapes(wrappingWalls[side, i].Cells));
|
||||||
//wrappingWalls[side, i].Cells[0].edges[1].isSolid = false;
|
//wrappingWalls[side, i].Cells[0].edges[1].isSolid = false;
|
||||||
//wrappingWalls[side, i].Cells[0].edges[3].isSolid = false;
|
//wrappingWalls[side, i].Cells[0].edges[3].isSolid = false;
|
||||||
|
|
||||||
@@ -1091,6 +1091,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private void Unload()
|
private void Unload()
|
||||||
{
|
{
|
||||||
|
renderer.Dispose();
|
||||||
renderer = null;
|
renderer = null;
|
||||||
|
|
||||||
cells = null;
|
cells = null;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
class LevelRenderer
|
class LevelRenderer : IDisposable
|
||||||
{
|
{
|
||||||
private static BasicEffect basicEffect;
|
private static BasicEffect basicEffect;
|
||||||
|
|
||||||
@@ -182,16 +182,18 @@ namespace Barotrauma
|
|||||||
|
|
||||||
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f));
|
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f));
|
||||||
|
|
||||||
//for (int side = 0; side < 2; side++)
|
for (int side = 0; side < 2; side++)
|
||||||
//{
|
{
|
||||||
// for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
// {
|
{
|
||||||
// graphicsDevice.DrawUserPrimitives(
|
graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].BodyVertices);
|
||||||
// PrimitiveType.TriangleList, level.WrappingWalls[side, i].BodyVertices, 0,
|
|
||||||
// (int)Math.Floor(level.WrappingWalls[side, i].BodyVertices.Length / 3.0f));
|
|
||||||
|
|
||||||
// }
|
graphicsDevice.DrawPrimitives(
|
||||||
//}
|
PrimitiveType.TriangleList, 0,
|
||||||
|
(int)Math.Floor(level.WrappingWalls[side, i].BodyVertices.VertexCount / 3.0f));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
graphicsDevice.SetVertexBuffer(wallVertices);
|
graphicsDevice.SetVertexBuffer(wallVertices);
|
||||||
@@ -201,25 +203,42 @@ namespace Barotrauma
|
|||||||
basicEffect.CurrentTechnique.Passes[0].Apply();
|
basicEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f));
|
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f));
|
||||||
|
|
||||||
//for (int side = 0; side < 2; side++)
|
basicEffect.VertexColorEnabled = false;
|
||||||
//{
|
basicEffect.TextureEnabled = true;
|
||||||
// for (int i = 0; i < 2; i++)
|
basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"];
|
||||||
// {
|
basicEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
// basicEffect.VertexColorEnabled = false;
|
|
||||||
// basicEffect.TextureEnabled = true;
|
|
||||||
// basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"];
|
|
||||||
// basicEffect.CurrentTechnique.Passes[0].Apply();
|
|
||||||
// graphicsDevice.DrawUserPrimitives(
|
|
||||||
// PrimitiveType.TriangleList, level.WrappingWalls[side, i].WallVertices, 0,
|
|
||||||
// (int)Math.Floor(level.WrappingWalls[side, i].WallVertices.Length / 3.0f));
|
|
||||||
|
|
||||||
// }
|
for (int side = 0; side < 2; side++)
|
||||||
//}
|
{
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].WallVertices);
|
||||||
|
|
||||||
|
graphicsDevice.DrawPrimitives(
|
||||||
|
PrimitiveType.TriangleList, 0,
|
||||||
|
(int)Math.Floor(level.WrappingWalls[side, i].WallVertices.VertexCount / 3.0f));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
|
|
||||||
Debug.WriteLine("level render: "+sw.ElapsedTicks);
|
Debug.WriteLine("level render: "+sw.ElapsedTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
wallVertices.Dispose();
|
||||||
|
bodyVertices.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public const float WallWidth = 20000.0f;
|
public const float WallWidth = 20000.0f;
|
||||||
|
|
||||||
public VertexPositionTexture[] WallVertices;
|
private VertexBuffer wallVertices, bodyVertices;
|
||||||
|
|
||||||
public VertexPositionColor[] BodyVertices;
|
|
||||||
|
|
||||||
private Vector2 midPos;
|
private Vector2 midPos;
|
||||||
private int slot;
|
private int slot;
|
||||||
@@ -26,6 +24,16 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private List<VoronoiCell> cells;
|
private List<VoronoiCell> cells;
|
||||||
|
|
||||||
|
public VertexBuffer WallVertices
|
||||||
|
{
|
||||||
|
get { return wallVertices; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public VertexBuffer BodyVertices
|
||||||
|
{
|
||||||
|
get { return bodyVertices; }
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 Offset
|
public Vector2 Offset
|
||||||
{
|
{
|
||||||
get { return offset; }
|
get { return offset; }
|
||||||
@@ -116,6 +124,18 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetWallVertices(VertexPositionTexture[] vertices)
|
||||||
|
{
|
||||||
|
wallVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
|
||||||
|
wallVertices.SetData(vertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetBodyVertices(VertexPositionColor[] vertices)
|
||||||
|
{
|
||||||
|
bodyVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
|
||||||
|
bodyVertices.SetData(vertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void UpdateWallShift(Vector2 pos, WrappingWall[,] walls)
|
public static void UpdateWallShift(Vector2 pos, WrappingWall[,] walls)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Barotrauma.Lights
|
namespace Barotrauma.Lights
|
||||||
{
|
{
|
||||||
class CachedShadow
|
class CachedShadow : IDisposable
|
||||||
{
|
{
|
||||||
|
|
||||||
public VertexPositionColor[] ShadowVertices;
|
//public VertexPositionColor[] ShadowVertices;
|
||||||
public VertexPositionTexture[] PenumbraVertices;
|
//public VertexPositionTexture[] PenumbraVertices;
|
||||||
|
|
||||||
|
public VertexBuffer ShadowBuffer;
|
||||||
|
|
||||||
public Vector2 LightPos;
|
public Vector2 LightPos;
|
||||||
|
|
||||||
@@ -18,14 +21,29 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
public CachedShadow(VertexPositionColor[] shadowVertices, VertexPositionTexture[] penumbraVertices, Vector2 lightPos, int shadowVertexCount, int penumbraVertexCount)
|
public CachedShadow(VertexPositionColor[] shadowVertices, VertexPositionTexture[] penumbraVertices, Vector2 lightPos, int shadowVertexCount, int penumbraVertexCount)
|
||||||
{
|
{
|
||||||
ShadowVertices = shadowVertices;
|
//var ShadowVertices = new VertexPositionColor [shadowVertices.Count()];
|
||||||
PenumbraVertices = penumbraVertices;
|
//shadowVertices.CopyTo(ShadowVertices, 0);
|
||||||
|
|
||||||
|
ShadowBuffer = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, 6*2, BufferUsage.None);
|
||||||
|
ShadowBuffer.SetData(shadowVertices, 0, shadowVertices.Length);
|
||||||
|
|
||||||
ShadowVertexCount = shadowVertexCount;
|
ShadowVertexCount = shadowVertexCount;
|
||||||
PenumbraVertexCount = penumbraVertexCount;
|
PenumbraVertexCount = penumbraVertexCount;
|
||||||
|
|
||||||
LightPos = lightPos;
|
LightPos = lightPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
ShadowBuffer.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConvexHull
|
class ConvexHull
|
||||||
@@ -44,8 +62,6 @@ namespace Barotrauma.Lights
|
|||||||
private VertexPositionColor[] shadowVertices;
|
private VertexPositionColor[] shadowVertices;
|
||||||
private VertexPositionTexture[] penumbraVertices;
|
private VertexPositionTexture[] penumbraVertices;
|
||||||
|
|
||||||
private VertexBuffer shadowBuffer, penumbraBuffer;
|
|
||||||
|
|
||||||
int shadowVertexCount;
|
int shadowVertexCount;
|
||||||
|
|
||||||
private Entity parentEntity;
|
private Entity parentEntity;
|
||||||
@@ -86,9 +102,6 @@ namespace Barotrauma.Lights
|
|||||||
shadowVertices = new VertexPositionColor[6 * 2];
|
shadowVertices = new VertexPositionColor[6 * 2];
|
||||||
penumbraVertices = new VertexPositionTexture[6];
|
penumbraVertices = new VertexPositionTexture[6];
|
||||||
|
|
||||||
shadowBuffer = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, 6*2, BufferUsage.WriteOnly);
|
|
||||||
|
|
||||||
|
|
||||||
vertices = points;
|
vertices = points;
|
||||||
primitiveCount = vertices.Length;
|
primitiveCount = vertices.Length;
|
||||||
|
|
||||||
@@ -225,10 +238,6 @@ namespace Barotrauma.Lights
|
|||||||
{
|
{
|
||||||
CalculatePenumbraVertices(startingIndex, endingIndex, lightSourcePos, los);
|
CalculatePenumbraVertices(startingIndex, endingIndex, lightSourcePos, los);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
shadowBuffer.SetData(shadowVertices);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculatePenumbraVertices(int startingIndex, int endingIndex, Vector2 lightSourcePos, bool los)
|
private void CalculatePenumbraVertices(int startingIndex, int endingIndex, Vector2 lightSourcePos, bool los)
|
||||||
@@ -283,21 +292,9 @@ namespace Barotrauma.Lights
|
|||||||
(light.Position == cachedShadow.LightPos || Vector2.DistanceSquared(light.Position, cachedShadow.LightPos) < 1.0f))
|
(light.Position == cachedShadow.LightPos || Vector2.DistanceSquared(light.Position, cachedShadow.LightPos) < 1.0f))
|
||||||
{
|
{
|
||||||
//{
|
//{
|
||||||
shadowVertices = cachedShadow.ShadowVertices;
|
graphicsDevice.SetVertexBuffer(cachedShadow.ShadowBuffer);
|
||||||
penumbraVertices = cachedShadow.PenumbraVertices;
|
|
||||||
|
|
||||||
shadowVertexCount = cachedShadow.ShadowVertexCount;
|
shadowVertexCount = cachedShadow.ShadowVertexCount;
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
|
|
||||||
//CalculateShadowVertices(light.Position, los);
|
|
||||||
//cachedShadow.LightPos = light.Position;
|
|
||||||
//cachedShadow.ShadowVertices = shadowVertices;
|
|
||||||
//cachedShadow.PenumbraVertices = penumbraVertices;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -309,7 +306,11 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
CalculateShadowVertices(lightPos, los);
|
CalculateShadowVertices(lightPos, los);
|
||||||
|
|
||||||
if (cachedShadows.ContainsKey(light)) cachedShadows.Remove(light);
|
if (cachedShadow != null)
|
||||||
|
{
|
||||||
|
cachedShadow.Dispose();
|
||||||
|
cachedShadows.Remove(light);
|
||||||
|
}
|
||||||
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.Position, shadowVertexCount, 0);
|
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.Position, shadowVertexCount, 0);
|
||||||
cachedShadows.Add(light, cachedShadow);
|
cachedShadows.Add(light, cachedShadow);
|
||||||
}
|
}
|
||||||
@@ -340,19 +341,16 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
if (shadowVertexCount>0)
|
if (shadowVertexCount>0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
shadowEffect.World = Matrix.CreateTranslation(offset) * transform;
|
shadowEffect.World = Matrix.CreateTranslation(offset) * transform;
|
||||||
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
|
||||||
|
|
||||||
if (los || true)
|
if (los)
|
||||||
{
|
{
|
||||||
|
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
|
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
graphicsDevice.SetVertexBuffer(shadowBuffer);
|
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, shadowVertexCount);
|
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, shadowVertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,6 +371,12 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
public void Remove()
|
public void Remove()
|
||||||
{
|
{
|
||||||
|
foreach (KeyValuePair<LightSource, CachedShadow> cachedShadow in cachedShadows)
|
||||||
|
{
|
||||||
|
cachedShadow.Value.Dispose();
|
||||||
|
}
|
||||||
|
cachedShadows.Clear();
|
||||||
|
|
||||||
list.Remove(this);
|
list.Remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,10 @@ namespace Barotrauma.Lights
|
|||||||
get { return range; }
|
get { return range; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
float newRange = MathHelper.Clamp(value, 0.0f, 2048.0f);
|
|
||||||
if (range == newRange) return;
|
float prevRange = range;
|
||||||
range = newRange;
|
range = MathHelper.Clamp(value, 0.0f, 2048.0f);
|
||||||
|
if (Math.Abs(prevRange - range)<5.0f) return;
|
||||||
|
|
||||||
UpdateHullsInRange();
|
UpdateHullsInRange();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,11 +206,6 @@ namespace Barotrauma
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void UpdateAll(Camera cam, float deltaTime)
|
public static void UpdateAll(Camera cam, float deltaTime)
|
||||||
{
|
{
|
||||||
foreach (Item item in Item.ItemList)
|
|
||||||
{
|
|
||||||
item.Updated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Hull hull in Hull.hullList)
|
foreach (Hull hull in Hull.hullList)
|
||||||
{
|
{
|
||||||
hull.Update(cam, deltaTime);
|
hull.Update(cam, deltaTime);
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ namespace Barotrauma
|
|||||||
Sounds.SoundManager.LowPassHFGain = 1.0f;
|
Sounds.SoundManager.LowPassHFGain = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rendc;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the game to run logic such as updating the world,
|
/// Allows the game to run logic such as updating the world,
|
||||||
/// checking for collisions, gathering input, and playing audio.
|
/// checking for collisions, gathering input, and playing audio.
|
||||||
@@ -61,6 +59,39 @@ namespace Barotrauma
|
|||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
public override void Update(double deltaTime)
|
public override void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
|
//if (PlayerInput.KeyHit(Keys.T))
|
||||||
|
//{
|
||||||
|
// Stopwatch sw = new Stopwatch();
|
||||||
|
// sw.Start();
|
||||||
|
|
||||||
|
// Rand.SetSyncedSeed(123);
|
||||||
|
|
||||||
|
// for (int i = 0; i<10000; i++)
|
||||||
|
// {
|
||||||
|
// Hull.FindHull(new Vector2(
|
||||||
|
// Rand.Range(Submarine.Borders.X, Submarine.Borders.Right, false),
|
||||||
|
// Rand.Range(Submarine.Borders.Y - Submarine.Borders.Height, Submarine.Borders.Y, false)),
|
||||||
|
// Hull.hullList[Rand.Int(Hull.hullList.Count-1)], false);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// sw.Stop();
|
||||||
|
// Debug.WriteLine("FindHull1: "+sw.ElapsedMilliseconds);
|
||||||
|
// sw.Restart();
|
||||||
|
// Rand.SetSyncedSeed(123);
|
||||||
|
// for (int i = 0; i < 10000; i++)
|
||||||
|
// {
|
||||||
|
// Hull.FindHull2(new Vector2(
|
||||||
|
// Rand.Range(Submarine.Borders.X, Submarine.Borders.Right, false),
|
||||||
|
// Rand.Range(Submarine.Borders.Y - Submarine.Borders.Height, Submarine.Borders.Y, false)),
|
||||||
|
// Hull.hullList[Rand.Int(Hull.hullList.Count - 1)], false);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// sw.Stop();
|
||||||
|
// Debug.WriteLine("FindHull2: " + sw.ElapsedMilliseconds);
|
||||||
|
// var askdnkjd = 1;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
//the accumulator code is based on this article:
|
//the accumulator code is based on this article:
|
||||||
//http://gafferongames.com/game-physics/fix-your-timestep/
|
//http://gafferongames.com/game-physics/fix-your-timestep/
|
||||||
Physics.accumulator += deltaTime;
|
Physics.accumulator += deltaTime;
|
||||||
|
|||||||
Reference in New Issue
Block a user