Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a multicellular statistics panel #5820

Merged
merged 70 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
bc6f1f9
Start working on the multicellular stats panel
dligr Jan 15, 2025
407c517
Implement energy balance display
dligr Jan 16, 2025
6a6ee6d
Implement a proper way of finding energy balance
dligr Jan 16, 2025
bcfb111
Make the process list work, but only show the leader's processes for now
dligr Jan 16, 2025
551a9e0
Remove a comment that clarifies the obvious
dligr Jan 16, 2025
13aad3d
Add some new triggers to update colony stats
dligr Jan 16, 2025
ecf2749
Improve the speed estimate
dligr Jan 16, 2025
3d81c87
Merge branch 'master' of https://github.com/Revolutionary-Games/Thriv…
dligr Jan 16, 2025
3092dd1
Fix ATP bars' colors
dligr Jan 16, 2025
1b0b006
Revert an accidental change to editor buttons
dligr Jan 16, 2025
ee2bf39
Revert changes to ProcessList.tscn
dligr Jan 16, 2025
8965112
Rename a variable to slightly clean up the diff, reword a comment
dligr Jan 16, 2025
3e28b3e
Clean up the no more used UI nodes
dligr Jan 16, 2025
5531f1f
Address format issues
dligr Jan 16, 2025
d271dba
Move a function to `CellBodyPlanInternalCalculations.cs`, make its he…
dligr Jan 17, 2025
983d056
Simplify a code block
dligr Jan 17, 2025
b35250f
Make the StringBuilder readonly (and fix the same mistake in `CellEdi…
dligr Jan 17, 2025
962812f
Remake the `ComputeEnergyBalance` to have no return value, but rather…
dligr Jan 17, 2025
f2e25f7
Convert more methods to have no return
dligr Jan 17, 2025
ba7e9f2
Convert some exact type declarations to vars
dligr Jan 17, 2025
7acade0
Remove `SetupTrackingForRequiredCompounds` in places where it didn't …
dligr Jan 17, 2025
98040bd
Move movement and rotation speed calculations to a separate static sc…
dligr Jan 18, 2025
1681db6
Fix code exceptions
dligr Jan 18, 2025
bfcf381
Move the organism statistics panel functionality to a separate class …
dligr Jan 20, 2025
94f3d24
Make the cell body plan editor use the new organism stats class
dligr Jan 20, 2025
5381cdf
Fix the top panel not scaling properly
dligr Jan 21, 2025
db02a1e
Make the low ATP warning work in the multicellular body plan editor
dligr Jan 21, 2025
1b4038b
Make the ATP warning show initially if necessary
dligr Jan 22, 2025
deda956
Fix code style issues
dligr Jan 22, 2025
72ea0bc
Make the process list show all cells' processes, fix linter issues
dligr Jan 22, 2025
325c4ba
Merge branch 'master' of https://github.com/Revolutionary-Games/Thriv…
dligr Jan 22, 2025
d98aede
Show a limited count of stats in the organism statistics; remove some…
dligr Jan 22, 2025
18694d4
Revert some accidental changes after the merge
dligr Jan 22, 2025
6ea50ac
Format fixes, revert another accidental change
dligr Jan 22, 2025
7b940ea
Improve the architecture surrounding energy balance and compound bala…
dligr Jan 24, 2025
7266960
Change a return in the speed calculation for accuracy; change to `var…
dligr Jan 24, 2025
64a1ab0
Remove some repeated code in the two methods calculating colony speed,
dligr Jan 24, 2025
65cb330
Separate the light level configuration panel into its own scene and c…
dligr Jan 24, 2025
89cc4da
Return a visibility update to Init()
dligr Jan 24, 2025
eafa432
Change some functions to be property getters
dligr Jan 25, 2025
820fc4b
Move a variable for code style
dligr Jan 25, 2025
f05c0a6
Forward tutorial state to organism stats panel
dligr Jan 25, 2025
515fc6c
Add a todo
dligr Jan 25, 2025
22c8942
Remove editorUserOverrides in CellBodyPlanEditorComponent and CellEdi…
dligr Jan 26, 2025
0cc6acf
Make the process list calculate processes per cell
dligr Jan 26, 2025
d5ba5d8
Add a TODO
dligr Jan 26, 2025
4efea7a
Make the organism stats panel update its localisation without stat re…
dligr Jan 26, 2025
7e11d90
Fix linter issues
dligr Jan 26, 2025
4073111
Move a comment to the right place
dligr Jan 26, 2025
1457dea
Fix linter issues
dligr Jan 26, 2025
df8efb8
Add some comments
dligr Jan 27, 2025
c429e61
Move LightLevelOption enum to a different file; change the signal's t…
dligr Jan 27, 2025
93d3c0b
Make EnergyBalanceInfo not-nullable in the process panel's method
dligr Jan 27, 2025
85fc11f
Edit a comment to make its purpose clearer
dligr Jan 27, 2025
b9ffaaf
Make a parameter non-ref
dligr Jan 27, 2025
8bcd580
Code style fix
dligr Jan 27, 2025
3a0446e
Separate some editor's light level changing logic into the base hex e…
dligr Jan 27, 2025
3b35581
Fix a warning disable
dligr Jan 29, 2025
1249477
Remove a redundant argument
dligr Jan 29, 2025
e859875
Correct two comments
dligr Jan 29, 2025
427e322
Fix some editor components' issues; slightly optimize memory allocations
dligr Jan 29, 2025
92fe4c6
Refactor the cell type counter
dligr Jan 29, 2025
7b85400
Add a comment, remove a line break, reduce ATPComparer allocations
dligr Jan 29, 2025
7748a67
Update cell type counts before each data use, simplify the counting
dligr Jan 30, 2025
2e084f6
Merge branch 'master' of https://github.com/Revolutionary-Games/Thriv…
dligr Jan 30, 2025
da4bbd2
Update the accidentally downgraded submodules
dligr Jan 30, 2025
4080b1a
Checkout the submodules to the master branch's version
dligr Jan 30, 2025
93db700
Add some TODOs
dligr Jan 30, 2025
54fadb2
Line break
dligr Jan 30, 2025
d7c7b3d
Fix the tutorial bug
dligr Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/auto-evo/simulation/SimulationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ public EnergyBalanceInfo GetEnergyBalanceForSpecies(MicrobeSpecies species, IBio

var maximumMovementDirection = MicrobeInternalCalculations.MaximumSpeedDirection(species.Organelles);

cached = new EnergyBalanceInfo();

// Auto-evo uses the average values of compound during the course of a simulated day
cached = ProcessSystem.ComputeEnergyBalance(species.Organelles, biomeConditions, species.MembraneType,
maximumMovementDirection, true, species.PlayerSpecies, worldSettings, CompoundAmountType.Average, false,
this);
ProcessSystem.ComputeEnergyBalance(species.Organelles, biomeConditions, species.MembraneType,
maximumMovementDirection, true, species.PlayerSpecies, worldSettings, CompoundAmountType.Average, this,
cached);

cachedEnergyBalances.Add(key, cached);
return cached;
Expand Down
21 changes: 21 additions & 0 deletions src/general/base_stage/HexEditorComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,27 @@ public void UpdateArrow(bool animateMovement = true)
}
}

protected void UpdateVisualLightLevel(float dayLightFraction, Patch currentPatch)
{
var maxLightLevel = currentPatch.Biome.GetCompound(Compound.Sunlight, CompoundAmountType.Biome).Ambient;
var templateMaxLightLevel =
currentPatch.GetCompoundAmountForDisplay(Compound.Sunlight, CompoundAmountType.Template);

// Currently, patches whose templates have zero sunlight can be given non-zero sunlight as an instance. But
// nighttime shaders haven't been created for these patches (specifically the sea floor) so for now we can't
// reduce light level in such patches without things looking bad. So we have to check the template light level
// is non-zero too.
if (maxLightLevel > 0.0f && templateMaxLightLevel > 0.0f)
{
camera!.LightLevel = dayLightFraction;
}
else
{
// Don't change lighting for patches without day/night effects
camera!.LightLevel = 1.0f;
}
}

protected MeshInstance3D CreateEditorHex()
{
var hex = (MeshInstance3D)hexScene.Instantiate();
Expand Down
79 changes: 45 additions & 34 deletions src/microbe_stage/MicrobeInternalCalculations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,20 @@ public static float GetTotalNominalCapacity(IEnumerable<OrganelleTemplate> organ
public static Dictionary<Compound, float> GetTotalSpecificCapacity(IReadOnlyList<OrganelleTemplate> organelles,
out float nominalCapacity)
{
var totalNominalCap = 0.0f;
var totalNominalCap = GetTotalNominalCapacity(organelles);
nominalCapacity = totalNominalCap;

int count = organelles.Count;
var capacities = new Dictionary<Compound, float>();

for (int i = 0; i < count; ++i)
{
var organelle = organelles[i];
totalNominalCap += GetNominalCapacityForOrganelle(organelle.Definition, organelle.Upgrades);
}
AddSpecificCapacity(organelles, capacities);

var capacities = new Dictionary<Compound, float>();
return capacities;
}

public static void AddSpecificCapacity(IReadOnlyList<OrganelleTemplate> organelles,
Dictionary<Compound, float> capacities)
{
var count = organelles.Count;

// Update the variant of this logic in UpdateSpecificCapacities if changes are made
for (int i = 0; i < count; ++i)
Expand All @@ -77,23 +80,15 @@ public static Dictionary<Compound, float> GetTotalSpecificCapacity(IReadOnlyList
continue;

// If this is updated the code in CompoundBag.AddSpecificCapacityForCompound must also be updated
if (capacities.TryGetValue(specificCapacity.Compound, out var currentCapacity))
{
capacities[specificCapacity.Compound] = currentCapacity + specificCapacity.Capacity;
}
else
{
capacities.Add(specificCapacity.Compound, specificCapacity.Capacity + totalNominalCap);
}
capacities.TryGetValue(specificCapacity.Compound, out var currentCapacity);
capacities[specificCapacity.Compound] = currentCapacity + specificCapacity.Capacity;
}

nominalCapacity = totalNominalCap;
return capacities;
}

/// <summary>
/// Variant of <see cref="GetTotalSpecificCapacity"/> to update spawned microbe stats. The used
/// <see cref="CompoundBag"/> must already have the correct nominal capacity set for this to work correctly.
/// Variant of <see cref="GetTotalSpecificCapacity(IReadOnlyList{OrganelleTemplate}, out float)"/> to update
/// spawned microbe stats. The used <see cref="CompoundBag"/> must already have the correct nominal capacity set
/// for this to work correctly.
/// </summary>
/// <param name="compoundBag">Target compound bag to set info in (this doesn't update nominal capacity)</param>
/// <param name="organelles">Organelles to find specific capacity from</param>
Expand Down Expand Up @@ -467,15 +462,21 @@ public static void GiveNearNightInitialCompoundBuff(CompoundBag compoundReceiver
IReadOnlyList<OrganelleTemplate> organelles, MembraneType membraneType, bool moving, bool playerSpecies,
BiomeConditions biomeConditions, WorldGenerationSettings worldSettings)
{
var energyBalance = ProcessSystem.ComputeEnergyBalance(organelles, biomeConditions, membraneType,
moving, playerSpecies, worldSettings, CompoundAmountType.Biome, false);
var energyBalance = new EnergyBalanceInfo();

ProcessSystem.ComputeEnergyBalance(organelles, biomeConditions, membraneType,
moving, playerSpecies, worldSettings, CompoundAmountType.Biome, energyBalance);

var compoundBalances = new Dictionary<Compound, CompoundBalance>();

var compoundBalances = ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles,
biomeConditions, CompoundAmountType.Biome, energyBalance);
ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles,
biomeConditions, CompoundAmountType.Biome, energyBalance, compoundBalances);

// TODO: is it fine to use energy balance calculated with the biome numbers here?
var minimums = ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles,
biomeConditions, CompoundAmountType.Minimum, energyBalance);
var minimums = new Dictionary<Compound, CompoundBalance>();

ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles,
biomeConditions, CompoundAmountType.Minimum, energyBalance, minimums);

var cachedCapacities = GetTotalSpecificCapacity(organelles, out var cachedCapacity);

Expand Down Expand Up @@ -558,16 +559,26 @@ public static (bool CanSurvive, Dictionary<Compound, float> RequiredStorage) Cal
{
if (dayCompoundBalances == null)
{
var energyBalance = ProcessSystem.ComputeEnergyBalance(organelles, biomeConditions, membraneType,
moving, playerSpecies, worldSettings, CompoundAmountType.Biome, false);
var energyBalance = new EnergyBalanceInfo();

ProcessSystem.ComputeEnergyBalance(organelles, biomeConditions, membraneType,
moving, playerSpecies, worldSettings, CompoundAmountType.Biome, energyBalance);

dayCompoundBalances = new Dictionary<Compound, CompoundBalance>();

dayCompoundBalances = ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles,
biomeConditions, CompoundAmountType.Biome, energyBalance);
ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles,
biomeConditions, CompoundAmountType.Biome, energyBalance, dayCompoundBalances);
}

var minimums = ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles,
biomeConditions, CompoundAmountType.Minimum, ProcessSystem.ComputeEnergyBalance(organelles, biomeConditions,
membraneType, moving, playerSpecies, worldSettings, CompoundAmountType.Minimum, false));
var energyBalanceAtMinimum = new EnergyBalanceInfo();

ProcessSystem.ComputeEnergyBalance(organelles, biomeConditions, membraneType, moving, playerSpecies,
worldSettings, CompoundAmountType.Minimum, energyBalanceAtMinimum);

var minimums = new Dictionary<Compound, CompoundBalance>();

ProcessSystem.ComputeCompoundBalanceAtEquilibrium(organelles, biomeConditions, CompoundAmountType.Minimum,
energyBalanceAtMinimum, minimums);

var cachedCapacities = GetTotalSpecificCapacity(organelles, out var cachedCapacity);

Expand Down
6 changes: 4 additions & 2 deletions src/microbe_stage/MicrobeSpecies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ public override void UpdateInitialCompounds()
// TODO: improve this depending on a hardcoded patch: https://github.com/Revolutionary-Games/Thrive/issues/5446
var biomeConditions = simulationParameters.GetBiome("speciesInitialCompoundsBiome").Conditions;

var compoundBalances = new Dictionary<Compound, CompoundBalance>();

// False is passed here until we can make the initial compounds patch specific
var compoundBalances = ProcessSystem.ComputeCompoundBalance(Organelles,
biomeConditions, CompoundAmountType.Biome, false);
ProcessSystem.ComputeCompoundBalance(Organelles, biomeConditions, CompoundAmountType.Biome, false,
compoundBalances);

bool giveBonusGlucose = Organelles.Count <= Constants.FULL_INITIAL_GLUCOSE_SMALL_SIZE_LIMIT && IsBacteria;

Expand Down
Loading