KeenSoftwareHouse / SpaceEngineers

2.94k stars 896 forks source link

Solar panel current output is not updated correctly #464

Open FKuerten opened 8 years ago

FKuerten commented 8 years ago

Description

The detailed info text for the SolarPanel is not updated when only the current power changes. Instead it is only updated whenever the maximum power changes. Changes to maximum power happen frequently if the sun rotates or ships (but not players) fly between the sun and the panel. However if sun rotation is disabled it is quite likely that the maximum power does not change and thus the detailed text will not be updated. This is problematic because the text also displays the current output which will be outdated.

To reproduce:

  1. Create a new empty world without sun rotation.
  2. Add one solar panel, a control panel, and a thruster.
  3. Turn thrust override on.
  4. Observe that the solar panel does not display any current output.

    Possible cause / fix

The info text is updated in the UpdateDisplay method in MySolarPanel but only if the maximum power changed:

public override void UpdateBeforeSimulation100()
{
    base.UpdateBeforeSimulation100();
    if (CubeGrid.Physics == null)
        return;

    float maxPowerOutput = SolarComponent.MaxOutput * SolarPanelDefinition.MaxPowerOutput;

    if (maxPowerOutput != SourceComp.MaxOutput)
    {
        float oldPowerOutput = SourceComp.MaxOutput;
        SourceComp.SetMaxOutput(maxPowerOutput);
        if (oldPowerOutput != maxPowerOutput)
        {
            SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, maxPowerOutput != 0f);
            UpdateDisplay();
        }
    }
}

This should be changed to update the text also if the current power changed.

FKuerten commented 8 years ago

This might be related to #457 but we can observe this on a listen server (both client and host).