xray-16 icon indicating copy to clipboard operation
xray-16 copied to clipboard

[Bugfix]: Save/load camera data with packet, fix incorrect camera yaw/pitch/roll on load

Open yohjimane opened this issue 1 year ago • 2 comments

Description:

Camera yaw/pitch/roll can be incorrect when loading a save.

Bug repro steps:

  1. Load new game
  2. Look all the way up
  3. Save game
  4. check cam_Active()->pitch evaluates to -1.5 (which is within limits. 1.5 = looking down, -1.5 = looking up)
  5. Load game from step 3
  6. Observe with breakpoint in CameraBase.h line 79: cam_Active()->pitch is set to value of o_torso (evaluates to ~4.865). This value is both incorrect, and invalid for pitch, as pitch values must be between -1.5 to 1.5.

Notes:

This bug is present, but does not cause any direct problems (that i can notice) in latest OpenXray dev build (429519f).

I found this bug while working on some hud inertia logic for my subproject, where some logic dependent on camera yaw value would get messed up after reloading a save while looking upwards.

Solution:

The bug is fixed by using packet to save and load camera yaw/pitch/roll. Now, we only initialize yaw/pitch/roll values from CSE_ALifeCreatureAbstract::o_torso when packet data is missing.

Initializing values from CSE_ALifeCreatureAbstract::o_torso is necessary for correct camera orientation when loading into new levels.

Unfortunately this approach will make save files incompatible.

yohjimane avatar May 30 '23 03:05 yohjimane

Can we fix it without adding data to net packets? Doing so will cause previous game saves incompatibility

Xottab-DUTY avatar May 31 '23 09:05 Xottab-DUTY

@Xottab-DUTY i am not sure 😢

I was thinking maybe we could just clamp the pitch/yaw values from o_torso, but the values are too different. For example, when camera pitch = -1.5 then o_torso pitch = 4.5, clamping that to proper limits would give inverted value of 1.5.

yohjimane avatar May 31 '23 10:05 yohjimane