Performance Optimization
Asteroid positioning is now multithreaded Item quality calculation is now allocation free Various other garbage reductions
This commit is contained in:
parent
cf74519cd9
commit
8d6770ab15
21 changed files with 151 additions and 72 deletions
|
|
@ -55,10 +55,10 @@ public class MiningTool : IBehavior
|
|||
public bool Execute(float delta)
|
||||
{
|
||||
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
||||
var asteroidTransform = Entity.Zone.GetAsteroidTransform(AsteroidBelt, Asteroid);
|
||||
var belt = Entity.Zone.AsteroidBelts[AsteroidBelt];
|
||||
if (AsteroidBelt != Guid.Empty &&
|
||||
Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) &&
|
||||
length(Entity.Position.xz - asteroidTransform.xz) - asteroidTransform.w < Range)
|
||||
length(Entity.Position.xz - belt.Positions[Asteroid].xz) - belt.Scales[Asteroid] < Range)
|
||||
{
|
||||
Entity.Zone.MineAsteroid(
|
||||
Entity,
|
||||
|
|
|
|||
|
|
@ -75,18 +75,21 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
// We have an energy deficit, try to get some energy out of our capacitors first
|
||||
if (Entity.Energy < 0)
|
||||
{
|
||||
Capacitor[] chargedCapacitors;
|
||||
int chargedCapacitors = 0;
|
||||
do
|
||||
{
|
||||
var chargeToRemove = -Entity.Energy;
|
||||
chargedCapacitors = _capacitors.Where(x => x.Charge > 0.01f).ToArray();
|
||||
foreach (var cap in chargedCapacitors)
|
||||
foreach (var cap in _capacitors)
|
||||
{
|
||||
var chargeRemoved = min(chargeToRemove / chargedCapacitors.Length, cap.Charge);
|
||||
cap.AddCharge(-chargeRemoved);
|
||||
Entity.Energy += chargeRemoved;
|
||||
if(cap.Charge > 0.01f)
|
||||
{
|
||||
chargedCapacitors++;
|
||||
var chargeRemoved = min(chargeToRemove / chargedCapacitors, cap.Charge);
|
||||
cap.AddCharge(-chargeRemoved);
|
||||
Entity.Energy += chargeRemoved;
|
||||
}
|
||||
}
|
||||
} while (chargedCapacitors.Length > 0 && Entity.Energy < -.01f);
|
||||
} while (chargedCapacitors > 0 && Entity.Energy < -.01f);
|
||||
}
|
||||
|
||||
// We still have an energy deficit, have to overload the reactor, run at reduced efficiency
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
{
|
||||
if(Asteroid > -1 &&
|
||||
Asteroid < beltData.Asteroids.Length &&
|
||||
length(Entity.Position.xz - Entity.Zone.GetAsteroidTransform(ScanTarget, Asteroid).xy) < Range)
|
||||
length(Entity.Position.xz - Entity.Zone.AsteroidBelts[ScanTarget].Positions[Asteroid].xz) < Range)
|
||||
{
|
||||
_scanTime += delta;
|
||||
if (_scanTime > ScanDuration)
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position.xz);
|
||||
return Zone.GetAsteroidTransform(planet.ID, asteroid).xy;
|
||||
return Zone.AsteroidBelts[planet.ID].Positions[asteroid].xz;
|
||||
}
|
||||
return Zone.GetOrbitPosition(planet.Orbit);
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position.xz);
|
||||
return Zone.GetAsteroidVelocity(planet.ID, asteroid);
|
||||
return Zone.AsteroidBelts[planet.ID].Velocities[asteroid];
|
||||
}
|
||||
return Zone.GetOrbitVelocity(planet.Orbit);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue