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

Oxygen and Carbon Dioxide Rebalance #5693

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft

Conversation

adQuid
Copy link
Contributor

@adQuid adQuid commented Nov 18, 2024

Brief Description of What This PR Does

Balances O2 and CO2 more tightly in the special case of that (mostly) closed loop between them. Also simplifies the diffusion simulation to let those compounds spread a little more, and modifies the auto-evo to make photosynthesisers more common to allow for more oxygen in the first place.

Related Issues

Progress Checklist

Note: before starting this checklist the PR should be marked as non-draft.

  • PR author has checked that this PR works as intended and doesn't
    break existing features:
    https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
    (this is important as to not waste the time of Thrive team
    members reviewing this PR)
  • Initial code review passed (this and further items should not be checked by the PR author)
  • Functionality is confirmed working by another person (see above checklist link)
  • Final code review is passed and code conforms to the
    styleguide.

Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.

@hhyyrylainen hhyyrylainen added this to the Release 0.8.0 milestone Nov 18, 2024
@@ -32,6 +33,8 @@ private void ApplyVolcanism()
{
foreach (var patchKeyValue in targetWorld.Map.Patches)
{
GD.Print(patchKeyValue.Value + " volcanism");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like leftover debugging code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew I forgot something!

@adQuid adQuid marked this pull request as ready for review November 21, 2024 01:13
@adQuid adQuid added the review label Nov 21, 2024
@adQuid
Copy link
Contributor Author

adQuid commented Nov 21, 2024

I want to make a future PR doing the diffusion better, but right now I think this is good enough for surface patches. Would appreciate lots of testing, since that gets very time-intensive.

@@ -27,14 +26,12 @@ public void OnTimePassed(double elapsed, double totalTimePassed)
HandlePatchCompoundDiffusion();
}

private static (float Ambient, float Density) CalculateWantedMoveAmounts(Patch sourcePatch, Patch adjacent,
private static (float Ambient, float Density) CalculateWantedMoveAmounts(Patch adjacent,
KeyValuePair<Compound, BiomeCompoundProperties> compound)
{
// Apply patch distance to diminish how much to move (to make ocean bottoms receive less surface
// resources like oxygen)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this comment now incorrect?

{
if (co2Out == 0)
{
// in the rare event we aren't making either compound, do nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now consuming the compounds also doesn't do anything? I think this is a wrong conclusion to make in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. If microbes had only bio processes that destroyed O2 or CO2 without producing anything in return, this code doesn't account for that. Right now the PhotosynthesisProductionEffect class is dependent on the special case of conservation of mass (and that CO2 and O2 are only being converted into each other)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code shouldn't depend on that then as someone will make a mod eventually that breaks the laws of physics and will get confused why it doesn't do things correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, I've modified the code to handle matter sinks, and while a matter generator will result in absurd numbers, I've protected against divide-by-zero exceptions.


if (co2Balance != 0)
changesToApply[Compound.Carbondioxide] = co2Balance;
changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) / 2.0f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more efficient to multiply by 0.5f than to do a float division.

}
else
{
oxygenTarget = oxygenOut / (oxygenIn + co2In) * total;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment here explaining the logic? I don't really understand this kind of scaling because ApplyLongTermCompoundChanges already does a relative applying of gases. So higher oxygen output reduces the effect of the co2 adding and vice versa. So to me it looks like this is now doing the same effect twice, which doesn't logically make a ton of sense as ApplyLongTermCompoundChanges needs to be given the absolute change wanted and then it automatically makes gases related to each other and caps it to a 100%.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. Rather than explain here, I will add the comment and see if the explanation makes sense to you.

// Special (but common) case where zero oxygen is being produced
if (oxygenProduced == 0 && oxygenConsumed > 0)
{
oxygenTarget = 0.0f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this make the game even more harsh? Wasn't the goal of this PR to make the changes less extreme? I think whatever trace oxygen there is should be allowed to be slowly consumed over time instead of immediately forcing it to zero...

// Special (but common) case where zero carbon dioxide is being produced
if (co2Produced == 0 && co2Consumed > 0)
{
co2Target = 0.0f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is flat out wrong, there's the volcanism effect that generates co2 so this would override that impact. So even if my previous comment doesn't absolutely need to be addressed, this does have to.


if (oxygenBalance != 0)
changesToApply[Compound.Oxygen] = oxygenBalance;
// if both compounds are being produced, calculate an aproximate steady state value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if both compounds are being produced, calculate an aproximate steady state value
// If both compounds are being produced, calculate an aproximate steady state value

if (co2Balance != 0)
changesToApply[Compound.Carbondioxide] = co2Balance;
changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) * 0.5f;
changesToApply[Compound.Carbondioxide] = (co2Target - existingCo2.Ambient) * 0.5f;

if (changesToApply.Count > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if no longer works correctly after your changes because even if the change to apply is less than EPSILON the value is added to the dictionary so this check no longer works. Either it needs to be reworked that small values (so close to target) are not processed or this needs to loop here to check if any of the changes are above EPSILON. I think the first approach will be easier to do and clearer to understand here.

Copy link
Member

@hhyyrylainen hhyyrylainen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a few more small changes (I forgot to post my last comment as part of this review).

@HexapodPhilosopher
Copy link
Contributor

On testing this today: the compounds are a lot more stable, but it's difficult to get the oxygen level to stay above 11%. My plant cells had to rely on hydrogenase to avoid using most of the oxygen in most patches. And even after 20 generations of maximizing my population in all surface patches, half of these had metabolosomes functioning worse than hydrogenase.

@hhyyrylainen hhyyrylainen marked this pull request as draft December 12, 2024 13:23
hhyyrylainen added a commit that referenced this pull request Dec 12, 2024
@hhyyrylainen
Copy link
Member

I'll mark this as a draft pending changes.

I've taken the compound diffusion change and made it into a separate PR: #5743

hhyyrylainen added a commit that referenced this pull request Dec 12, 2024
* Updated the normal effect variant documentation text

to not refer to the removed classes

* Added the simpler compound move multiplier calculation

from adQuid's PR #5693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

3 participants