NebulaModTeam / nebula

A multiplayer mod for the game Dyson Sphere Program
GNU General Public License v3.0
824 stars 125 forks source link

Rework power tower syncing #627

Closed starfi5h closed 6 months ago

starfi5h commented 6 months ago

Replace the vanilla logic of power chargers and simply sync ON/OFF state.

PowerTowerManager now only maintains two pool, one is LocalChargerIds which stores all nodeIds of power chargers charging the local player. When add/remove nodeId from LocalChargerIds, it is broadcast to other players and stored in RemoteChargerHashIds as 64 bits hashIds, which planetId is the upper bits and nodeId is the lower bits.

If the player is in range of the charger, or RemoteChargerHashIds contains the id, then the charger will be set to working state, otherwise, it is set to idle state.

The pools are reset and recalculated whenever a player is disconnected to prevent persistent energy charges. Fix #448 #470