Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

add amps in hatch in one go #851

Merged
merged 1 commit into from
Mar 17, 2024
Merged

add amps in hatch in one go #851

merged 1 commit into from
Mar 17, 2024

Conversation

boubou19
Copy link
Member

fixes GTNewHorizons/GT-New-Horizons-Modpack#15746

I couldn't see any obvious reason that could cause the multies to break, but i'm no expert in this part of the code.

Copy link
Contributor

@Glease Glease left a comment

Choose a reason for hiding this comment

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

increaseStoredEnergyUnits(X, false) is an "atomic" operation. You either add X amount of energy or you don't. No half-add-half-waste is ever done. Making it increase in one go will cause much greater waste when dynamo stored energy is near its capacity.

@boubou19
Copy link
Member Author

Yeah but i don't see the difference between using the loop or to do it in a single operation, given we don't even use the boolean returned to check if the energy has successfully been added to the hatch. So my understanding is that you'd waste the energy the same way with the loop, as the injected variable is unconditionally incremented no matter if the injection failed.

@Glease
Copy link
Contributor

Glease commented Mar 17, 2024

There is a difference when you have 2packets of free space, but want to inject 4 packets.

@boubou19
Copy link
Member Author

Sure, but i don't see any logic done by the Multi to check for room before injecting to the hatch, it seems to assume the power is always considered injected by the multi no matter what, all it does it to track down how many power was added to one hatch so it can properly distribute the power to the other hatches. But in the end, if there is some power left, it's discarded, so you lose this power in the end? And the amount of amps to add to a hatch is computed the same way in both the old code and new code, so if power is discarded, it's discarded the same way, we just avoid spam calling the method to add the energy. So i don't understand your point.

@Glease
Copy link
Contributor

Glease commented Mar 17, 2024

assume there is 2.5 packet worth of space, and we need to add 4 packet

before

makes 4 attempts

# 1: added 1 packet
# 2: added 1 packet
# 3: fail because less than 1 packet space
# 4: fail because less than 1 packet space

total: added 2 packet

after

make 1 attemp
# 1: fail to add anything at all, because there is no space for 4 packet

total: nothing

@boubou19
Copy link
Member Author

boubou19 commented Mar 17, 2024

the code used in increaseStoredEnergyUnits:

    @Override
    public boolean increaseStoredEnergyUnits(long aEnergy, boolean aIgnoreTooMuchEnergy) {
        if (!canAccessData()) return false;
        if (getStoredEU() < getEUCapacity() || aIgnoreTooMuchEnergy) {
            setStoredEU(mMetaTileEntity.getEUVar() + aEnergy);
            return true;
        }
        return false;
    }

We pass it with aIgnoreTooMuchEnergy to false, so the energy will fail to be added to the buffer, if and only if, there is not room for a single EU. Which means, if there is at least room for 1 EU, it will be added to the internal storage. So worse that can happen is to have the internal buffer way above the max capacity, but we don't actually lose any energy here. In fact, we even recover some, because with the loop, once it gets full, rest is lost until the loop is done to move to another hatch.

@boubou19 boubou19 merged commit 94a08e8 into master Mar 17, 2024
1 check passed
@boubou19 boubou19 deleted the fix_turbine_lag branch March 17, 2024 14:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XL Turbo SC Steam turbine is lagging when used with large laser hatches
2 participants