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

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/xrGame/Actor_Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,11 @@ bool CActor::net_Spawn(CSE_Abstract* DC)
else
cam_Set(eacFirstEye);

cam_Active()->Set(-E->o_torso.yaw, E->o_torso.pitch, 0); // E->o_Angle.z);
bool cameraRestoredFromPacket = abs(cam_Active()->yaw) > 0.f || abs(cam_Active()->pitch) > 0.f || abs(cam_Active()->roll) > 0.f;
if (!cameraRestoredFromPacket)
{
cam_Active()->Set(-E->o_torso.yaw, E->o_torso.pitch, 0);
}

// *** movement state - respawn
// mstate_wishful = 0;
Expand Down Expand Up @@ -1411,6 +1415,14 @@ void CActor::save(NET_Packet& output_packet)
output_packet.w_stringZ(g_quick_use_slots[1]);
output_packet.w_stringZ(g_quick_use_slots[2]);
output_packet.w_stringZ(g_quick_use_slots[3]);

CCameraBase* camera = cam_Active();
if (camera)
{
output_packet.w_float(camera->yaw);
output_packet.w_float(camera->pitch);
output_packet.w_float(camera->roll);
}
}

void CActor::load(IReader& input_packet)
Expand Down Expand Up @@ -1438,6 +1450,15 @@ void CActor::load(IReader& input_packet)
input_packet.r_stringZ(g_quick_use_slots[1], sizeof(g_quick_use_slots[1]));
input_packet.r_stringZ(g_quick_use_slots[2], sizeof(g_quick_use_slots[2]));
input_packet.r_stringZ(g_quick_use_slots[3], sizeof(g_quick_use_slots[3]));

CCameraBase* camera = cam_Active();
if (camera)
{
const float yaw = input_packet.r_float();
const float pitch = input_packet.r_float();
const float roll = input_packet.r_float();
camera->Set(yaw, pitch, roll);
}
}

#ifdef DEBUG
Expand Down