Skip to content

Commit

Permalink
Added PreUpdate and PostUpdate to the rewrite tool
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyyrylainen committed Oct 27, 2023
1 parent 526c648 commit 01f1fa8
Show file tree
Hide file tree
Showing 57 changed files with 231 additions and 200 deletions.
3 changes: 2 additions & 1 deletion Scripts/NativeLibs.cs
Expand Up @@ -383,7 +383,8 @@ private string GetLibraryDllName(Library library, PackagePlatform platform)
if (result.ExitCode != 0)
{
ColourConsole.WriteErrorLine(
$"CMake configuration failed (exit: {result.ExitCode}). Do you have the required build tools installed?");
$"CMake configuration failed (exit: {result.ExitCode}). " +
"Do you have the required build tools installed?");

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions simulation_parameters/common/visual_resources.json
@@ -1,11 +1,11 @@
{
"Error":{
"Error": {
"NormalQualityPath": "res://assets/models/ErrorModel.tscn"
},
"CellBurstEffect":{
"CellBurstEffect": {
"NormalQualityPath": "res://src/microbe_stage/particles/CellBurstEffect.tscn"
},
"AgentProjectile":{
"AgentProjectile": {
"NormalQualityPath": "res://src/microbe_stage/AgentProjectile.tscn"
}
}
24 changes: 18 additions & 6 deletions simulation_parameters/microbe_stage/organelles.json
Expand Up @@ -12,7 +12,9 @@
}
],
"processes": {},
"featureTags": ["Pilus"],
"featureTags": [
"Pilus"
],
"shouldScale": false,
"prokaryoteChance": 0.5,
"chanceToCreate": 0.5,
Expand Down Expand Up @@ -526,7 +528,9 @@
"capacity": 1
}
},
"featureTags": ["BindingAgent"],
"featureTags": [
"BindingAgent"
],
"prokaryoteChance": 0,
"chanceToCreate": 0,
"Density": 500,
Expand Down Expand Up @@ -663,7 +667,9 @@
"capacity": 4
}
},
"featureTags": ["Nucleus"],
"featureTags": [
"Nucleus"
],
"shouldScale": false,
"prokaryoteChance": 0,
"chanceToCreate": 0,
Expand Down Expand Up @@ -752,7 +758,9 @@
}
],
"processes": {},
"featureTags": ["SignalingAgent"],
"featureTags": [
"SignalingAgent"
],
"prokaryoteChance": 0,
"chanceToCreate": 0.4,
"Density": 900,
Expand Down Expand Up @@ -917,7 +925,9 @@
}
],
"processes": {},
"featureTags": ["Axon"],
"featureTags": [
"Axon"
],
"prokaryoteChance": 0,
"chanceToCreate": 0,
"Density": 1200,
Expand Down Expand Up @@ -959,7 +969,9 @@
}
],
"processes": {},
"featureTags": ["Myofibril"],
"featureTags": [
"Myofibril"
],
"prokaryoteChance": 0,
"chanceToCreate": 0,
"Density": 1200,
Expand Down
8 changes: 4 additions & 4 deletions src/benchmark/DummySpawnSystem.cs
Expand Up @@ -21,19 +21,19 @@ public void Init()
{
}

public void Clear()
public void Update(float delta)
{
}

public void DespawnAll()
public void Clear()
{
}

public void ReportPlayerPosition(Vector3 position)
public void DespawnAll()
{
}

public void Update(float delta)
public void ReportPlayerPosition(Vector3 position)
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/benchmark/microbe/MicrobeBenchmark.cs
Expand Up @@ -466,7 +466,8 @@ private void SetupSimulation()
microbeSimulation.Init(dynamicRoot, cloudSystem);
microbeSimulation.InitForCurrentGame(gameProperties ?? throw new Exception("game properties not set"));

microbeEntities = microbeSimulation.EntitySystem.GetEntities().With<MicrobeSpeciesMember>().With<Health>().AsSet();
microbeEntities = microbeSimulation.EntitySystem.GetEntities().With<MicrobeSpeciesMember>().With<Health>()
.AsSet();

// ReSharper disable once StringLiteralTypo
microbeSimulation.SetSimulationBiome(SimulationParameters.Instance.GetBiome("aavolcanic_vent").Conditions);
Expand Down
Expand Up @@ -10,7 +10,7 @@ public struct EarlyMulticellularSpeciesMember
public EarlyMulticellularSpecies Species;

/// <summary>
/// For each part of a multicellular species, the cell type they are must be known
/// For each part of a multicellular species, the cell type they are must be known
/// </summary>
public CellType MulticellularCellType;

Expand Down
Expand Up @@ -238,8 +238,8 @@ public static void BecomeFullyGrownMulticellularColony(this ref MulticellularGro
compoundRefundLocation.AddCompound(entry.Key, entry.Value);
}

// Adjust the already used compound amount to lose the progress we made for the current cell and also towards
// the lost cell, this we the total progress bar should be correct
// Adjust the already used compound amount to lose the progress we made for the current cell and also
// towards the lost cell, this we the total progress bar should be correct
if (multicellularGrowth.CompoundsUsedForMulticellularGrowth != null)
{
var totalNeededForLostCell = species.Cells[lostPartIndex]
Expand Down
Expand Up @@ -147,7 +147,8 @@ protected override void Update(float delta, in Entity entity)
usedAmount += usedFreeCompounds;
allowedUseAmount -= usedFreeCompounds;

// As we loop just once we don't need to update the free compounds or allowed use compounds variables
// As we loop just once we don't need to update the free compounds or allowed use compounds
// variables
}

stillNeedsSomething = true;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/attributes/ReadsComponentAttribute.cs
@@ -1,4 +1,4 @@
using System;
using System;
using DefaultEcs.System;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/engine/attributes/RunsAfterAttribute.cs
@@ -1,4 +1,4 @@
using System;
using System;

/// <summary>
/// Marks that the system with this attribute has to run after another system has finished
Expand Down
2 changes: 1 addition & 1 deletion src/engine/attributes/RunsBeforeAttribute.cs
@@ -1,4 +1,4 @@
using System;
using System;

/// <summary>
/// Marks that the system with this attribute has to run after another system has finished. For example due to
Expand Down
5 changes: 3 additions & 2 deletions src/engine/attributes/RunsOnFrameAttribute.cs
@@ -1,7 +1,8 @@
using System;
using System;

/// <summary>
/// Marks a system as running on each rendered frame rather than on logic update (most usually 60 times per second)
/// Marks a system as running on each rendered frame rather than on logic update (logic updates run most usually
/// 60 times per second at most)
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class RunsOnFrameAttribute : Attribute
Expand Down
2 changes: 1 addition & 1 deletion src/engine/attributes/RunsOnMainThreadAttribute.cs
@@ -1,4 +1,4 @@
using System;
using System;

/// <summary>
/// Marks a system as needing to run on the main thread where it is allowed to do any Godot engine operations
Expand Down
2 changes: 1 addition & 1 deletion src/engine/attributes/WritesToComponentAttribute.cs
@@ -1,4 +1,4 @@
using System;
using System;
using DefaultEcs.System;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/engine/common_components/AnimationControl.cs
@@ -1,4 +1,4 @@
namespace Components
namespace Components
{
using Newtonsoft.Json;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/common_components/EntityRadiusInfo.cs
@@ -1,4 +1,4 @@
namespace Components
namespace Components
{
/// <summary>
/// Entity is roughly circular and this provides easy access to that entity's radius
Expand Down
2 changes: 1 addition & 1 deletion src/engine/common_systems/AnimationControlSystem.cs
@@ -1,4 +1,4 @@
namespace Systems
namespace Systems
{
using Components;
using DefaultEcs;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/common_systems/AttachedEntityPositionSystem.cs
@@ -1,4 +1,4 @@
namespace Systems
namespace Systems
{
using Components;
using DefaultEcs;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/common_systems/DisallowPlayerBodySleepSystem.cs
@@ -1,4 +1,4 @@
namespace Systems
namespace Systems
{
using System;
using Components;
Expand Down
36 changes: 18 additions & 18 deletions src/engine/common_systems/SpatialAttachSystem.cs
Expand Up @@ -32,24 +32,6 @@ protected override void PreUpdate(float state)
}
}

protected override void PostUpdate(float state)
{
// Delete unmarked
foreach (var pair in attachedSpatialInstances)
{
if (!pair.Value.Marked)
instancesToDelete.Add(pair.Key);
}

foreach (var spatial in instancesToDelete)
{
attachedSpatialInstances.Remove(spatial);
spatial.QueueFree();
}

instancesToDelete.Clear();
}

protected override void Update(float state, Span<SpatialInstance> components)
{
foreach (ref SpatialInstance spatial in components)
Expand All @@ -73,6 +55,24 @@ protected override void Update(float state, Span<SpatialInstance> components)
}
}

protected override void PostUpdate(float state)
{
// Delete unmarked
foreach (var pair in attachedSpatialInstances)
{
if (!pair.Value.Marked)
instancesToDelete.Add(pair.Key);
}

foreach (var spatial in instancesToDelete)
{
attachedSpatialInstances.Remove(spatial);
spatial.QueueFree();
}

instancesToDelete.Clear();
}

/// <summary>
/// Info (really just a marked status) for spatial instances. This breaks the use of only value types by
/// systems, so there might be some more efficient way to implement this (for example with two hash sets)
Expand Down
12 changes: 6 additions & 6 deletions src/engine/physics/NativePhysicsBody.cs
Expand Up @@ -33,7 +33,7 @@ public class NativePhysicsBody : IDisposable, IEquatable<NativePhysicsBody>

/// <summary>
/// Storage variable for collision recording, when this is active the pin handle is used to pin down this
/// piece of memory to ensure the native code size can directly write here with pointers
/// piece of memory to ensure the native code size can directly write here with pointers
/// </summary>
private PhysicsCollision[]? activeCollisions;

Expand Down Expand Up @@ -108,17 +108,17 @@ public override bool Equals(object? obj)
return Equals((NativePhysicsBody)obj);
}

public override int GetHashCode()
{
return nativeInstance.GetHashCode();
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

public override int GetHashCode()
{
return nativeInstance.GetHashCode();
}

internal (PhysicsCollision[] CollisionsArray, IntPtr ArrayAddress)
SetupCollisionRecording(int maxCollisions)
{
Expand Down
4 changes: 3 additions & 1 deletion src/microbe_stage/AgentProperties.cs
Expand Up @@ -16,9 +16,11 @@ public AgentProperties(Species species, Compound compound)
public string AgentType { get; set; } = "oxytoxy";
public Compound Compound { get; set; }

// This has to be used like this to ensure the translation extractor sees this
// ReSharper disable once ArrangeObjectCreationWhenTypeEvident
[JsonIgnore]
public LocalizedString Name =>
new("AGENT_NAME", new LocalizedString(Compound.GetUntranslatedName()));
new LocalizedString("AGENT_NAME", new LocalizedString(Compound.GetUntranslatedName()));

public void DealDamage(ref Health health, ref CellProperties hitCellProperties, float toxinAmount)
{
Expand Down
10 changes: 5 additions & 5 deletions src/microbe_stage/CompoundBag.cs
Expand Up @@ -128,11 +128,6 @@ public float AddCompound(Compound compound, float amount)
return Compounds.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public void ClearCompounds()
{
Compounds.Clear();
Expand Down Expand Up @@ -238,4 +233,9 @@ public void FixNaNCompounds()
Compounds[entry.Key] = 0;
}
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
2 changes: 1 addition & 1 deletion src/microbe_stage/MembranePointData.cs
@@ -1,4 +1,4 @@
using System;
using System;
using System.Buffers;
using System.Collections.Generic;
using Godot;
Expand Down

0 comments on commit 01f1fa8

Please sign in to comment.