Lighting optimization (caching shadow vertices & only checking hulls in range if the position or range of the light changes), ragdoll optimization, itemcomponent optimization, dragging stunned/dead characters

This commit is contained in:
Regalis11
2015-10-11 21:04:42 +03:00
parent 0a96254696
commit 8df9133e84
25 changed files with 377 additions and 201 deletions
@@ -282,6 +282,12 @@ namespace Subsurface.Items.Components
private int loopingSoundIndex;
public void PlaySound(ActionType type, Vector2 position)
{
if (loopingSound != null)
{
loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, GetSoundVolume(loopingSound), position, loopingSound.Range);
return;
}
List<ItemSound> matchingSounds = sounds.FindAll(x => x.Type == type);
if (matchingSounds.Count == 0) return;
@@ -292,24 +298,18 @@ namespace Subsurface.Items.Components
itemSound = matchingSounds[index];
}
if (itemSound == null) return;
if (loopingSound!=null)
if (itemSound.Loop)
{
loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, GetSoundVolume(loopingSound), position, loopingSound.Range);
loopingSound = itemSound;
}
else if (itemSound!=null)
else
{
if (itemSound.Loop)
{
loopingSound = itemSound;
}
else
{
float volume = GetSoundVolume(itemSound);
if (volume == 0.0f) return;
itemSound.Sound.Play(volume, itemSound.Range, position);
}
}
float volume = GetSoundVolume(itemSound);
if (volume == 0.0f) return;
itemSound.Sound.Play(volume, itemSound.Range, position);
}
}
public void StopSounds(ActionType type)
@@ -12,6 +12,8 @@ namespace Subsurface.Items.Components
List<RelatedItem> containableItems;
public ItemInventory inventory;
private bool hasStatusEffects;
//how many items can be contained
[HasDefaultValue(5, false)]
public int Capacity
@@ -89,12 +91,6 @@ namespace Subsurface.Items.Components
{
inventory = new ItemInventory(this, capacity, hudPos, slotsPerRow);
containableItems = new List<RelatedItem>();
//itemPos = ToolBox.GetAttributeVector2(element, "ItemPos", Vector2.Zero);
//itemPos = ConvertUnits.ToSimUnits(itemPos);
//itemInterval = ToolBox.GetAttributeVector2(element, "ItemInterval", Vector2.Zero);
//itemInterval = ConvertUnits.ToSimUnits(itemInterval);
foreach (XElement subElement in element.Elements())
{
@@ -102,7 +98,15 @@ namespace Subsurface.Items.Components
{
case "containable":
RelatedItem containable = RelatedItem.Load(subElement);
if (containable!=null) containableItems.Add(containable);
if (containable == null) continue;
foreach (StatusEffect effect in containable.statusEffects)
{
if (effect.type == ActionType.OnContaining) hasStatusEffects = true;
}
containableItems.Add(containable);
break;
}
}
@@ -121,11 +125,12 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (!hasStatusEffects) return;
foreach (Item contained in inventory.items)
{
if (contained == null || contained.Condition<=0.0f) continue;
if (contained.body!=null) contained.body.Enabled = false;
if (contained == null || contained.Condition <= 0.0f) continue;
//if (contained.body != null) contained.body.Enabled = false;
RelatedItem ri = containableItems.Find(x => x.MatchesItem(contained));
if (ri == null) continue;
@@ -136,16 +141,15 @@ namespace Subsurface.Items.Components
if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, item, contained.AllPropertyObjects);
}
contained.ApplyStatusEffects(ActionType.OnContained, deltaTime);
//contained.ApplyStatusEffects(ActionType.OnContained, deltaTime);
}
}
public override void Draw(SpriteBatch spriteBatch, bool editing)
{
base.Draw(spriteBatch);
if (hideItems || (item.body!=null && !item.body.Enabled)) return;
if (hideItems || (item.body != null && !item.body.Enabled)) return;
Vector2 transformedItemPos = itemPos;
Vector2 transformedItemInterval = itemInterval;
@@ -79,23 +79,22 @@ namespace Subsurface.Items.Components
//lightColor = new Color(ToolBox.GetAttributeVector4(element, "color", Vector4.One));
}
public override void Update(float deltaTime, Camera cam)
{
base.Update(deltaTime, cam);
if (item.body != null)
{
light.Position = ConvertUnits.ToDisplayUnits(item.body.SimPosition);
}
Pickable pickable = item.GetComponent<Pickable>();
if (item.container!= null)
if (item.container != null)
{
light.Color = Color.Transparent;
return;
}
if (item.body != null)
{
light.Position = ConvertUnits.ToDisplayUnits(item.body.SimPosition);
}
if (powerConsumption == 0.0f)
{
voltage = 1.0f;
@@ -116,7 +115,6 @@ namespace Subsurface.Items.Components
}
light.Color = lightColor * lightBrightness * (1.0f-Rand.Range(0.0f,Flicker));
light.Range = range * (float)Math.Sqrt(lightBrightness);
voltage = 0.0f;
@@ -35,6 +35,8 @@ namespace Subsurface.Items.Components
Nodes = new List<Vector2>();
connections = new Connection[2];
IsActive = false;
}
public override void Move(Vector2 amount)