From 9a25952c645434326c780b0beef1f436926b209a Mon Sep 17 00:00:00 2001 From: CryoTheRenegade Date: Fri, 23 Oct 2026 17:01:27 -0600 Subject: [PATCH 1/4] refactor(ww3d2): Read motion channel packet floats with std::bit_cast TimeCodedMotionChannelClass and AdaptiveDeltaMotionChannelClass store their packets in uint32 arrays and read the float values through float pointers. Read each uint32 element and convert it with std::bit_cast. AdaptiveDeltaMotionChannelClass::decompress only used its float pointer to find where the packet bytes start, so it now points a uint32 pointer there instead. Co-Authored-By: Claude Opus 5.5 --- .../Source/WWVegas/WW3D2/motchan.cpp | 38 +++++++++---------- .../Source/WWVegas/WW3D2/motchan.cpp | 38 +++++++++---------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 74948ead0a2..9224c0e48c1 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -50,6 +50,7 @@ #include "WWLib/Vector.h" #include "WWMath/wwmath.h" #include "WWMath/quat.h" +#include //#include // Static Table, for Adaptive Delta Decompressor #define FILTER_TABLE_SIZE (256) @@ -430,11 +431,11 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - float32 *frm = (float32 *) &Data[pidx+1]; + const uint32 *frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { - setvec[i] = frm[i]; + setvec[i] = std::bit_cast(frm[i]); } @@ -448,9 +449,9 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - float32 *frm = (float32 *) &Data[pidx+1]; + const uint32 *frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { - setvec[i] = frm[i]; + setvec[i] = std::bit_cast(frm[i]); } return; } @@ -460,12 +461,12 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) float32 ratio = (frame - time1) / (time2 - time1); - float32 *frame1 = (float32 *) &Data[pidx+1]; - float32 *frame2 = (float32 *) &Data[p2idx+1]; + const uint32 *frame1 = &Data[pidx+1]; + const uint32 *frame2 = &Data[p2idx+1]; for (int i=0; i < VectorLen; i++) { - setvec[i] = WWMath::Lerp(frame1[i],frame2[i],ratio); + setvec[i] = WWMath::Lerp(std::bit_cast(frame1[i]),std::bit_cast(frame2[i]),ratio); } @@ -488,9 +489,9 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - float32 *vec = (float32 *) &Data[pidx+1]; + const uint32 *vec = &Data[pidx+1]; - q.Set(vec[0], vec[1], vec[2], vec[3]); + q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); return( q ); @@ -503,9 +504,9 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { // its a binary movement! - float32 *vec = (float32 *) &Data[pidx+1]; + const uint32 *vec = &Data[pidx+1]; - q.Set(vec[0], vec[1], vec[2], vec[3]); + q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); return( q ); } @@ -515,14 +516,14 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) float32 ratio = (frame - time1) / (time2 - time1); - float32 *frame1 = (float32 *) &Data[pidx+1]; - float32 *frame2 = (float32 *) &Data[p2idx+1]; + const uint32 *frame1 = &Data[pidx+1]; + const uint32 *frame2 = &Data[p2idx+1]; Quaternion q1(1); Quaternion q2(1); - q1.Set(frame1[0], frame1[1], frame1[2], frame1[3]); - q2.Set(frame2[0], frame2[1], frame2[2], frame2[3]); + q1.Set(std::bit_cast(frame1[0]), std::bit_cast(frame1[1]), std::bit_cast(frame1[2]), std::bit_cast(frame1[3])); + q2.Set(std::bit_cast(frame2[0]), std::bit_cast(frame2[1]), std::bit_cast(frame2[2]), std::bit_cast(frame2[3])); Fast_Slerp(q, q1, q2, ratio); @@ -972,7 +973,7 @@ bool AdaptiveDeltaMotionChannelClass::Load_W3D(ChunkLoadClass & cload) void AdaptiveDeltaMotionChannelClass::decompress(uint32 frame_idx, float *outdata) { // Start Over from the beginning - float *base = (float *) &Data[0]; // pointer to our true know beginning values + const uint32 *base = &Data[0]; // pointer to our true know beginning values bool done = false; @@ -982,7 +983,7 @@ void AdaptiveDeltaMotionChannelClass::decompress(uint32 frame_idx, float *outdat pPacket+= (sizeof(float) * VectorLen); // skip non-compressed header information pPacket+= PACKET_SIZE * vi; // skip to the appropriate packet start - float last_value = base[vi]; + float last_value = std::bit_cast(base[vi]); for (uint32 frame=1; frame<=frame_idx;) { // Frame Loop @@ -1048,8 +1049,7 @@ void AdaptiveDeltaMotionChannelClass::decompress(uint32 src_idx, float *srcdata, assert(src_idx < frame_idx); src_idx++; - float *base = (float *) &Data[0]; // pointer to our true know beginning values - base += VectorLen; // skip header information + const uint32 *base = &Data[VectorLen]; // skip header information bool done = false; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index d6bff509543..92cb2dfe41a 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -50,6 +50,7 @@ #include "WWLib/Vector.h" #include "WWMath/wwmath.h" #include "WWMath/quat.h" +#include //#include // Static Table, for Adaptive Delta Decompressor #define FILTER_TABLE_SIZE (256) @@ -430,11 +431,11 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - float32 *frm = (float32 *) &Data[pidx+1]; + const uint32 *frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { - setvec[i] = frm[i]; + setvec[i] = std::bit_cast(frm[i]); } @@ -448,9 +449,9 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - float32 *frm = (float32 *) &Data[pidx+1]; + const uint32 *frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { - setvec[i] = frm[i]; + setvec[i] = std::bit_cast(frm[i]); } return; } @@ -460,12 +461,12 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) float32 ratio = (frame - time1) / (time2 - time1); - float32 *frame1 = (float32 *) &Data[pidx+1]; - float32 *frame2 = (float32 *) &Data[p2idx+1]; + const uint32 *frame1 = &Data[pidx+1]; + const uint32 *frame2 = &Data[p2idx+1]; for (int i=0; i < VectorLen; i++) { - setvec[i] = WWMath::Lerp(frame1[i],frame2[i],ratio); + setvec[i] = WWMath::Lerp(std::bit_cast(frame1[i]),std::bit_cast(frame2[i]),ratio); } @@ -488,9 +489,9 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - float32 *vec = (float32 *) &Data[pidx+1]; + const uint32 *vec = &Data[pidx+1]; - q.Set(vec[0], vec[1], vec[2], vec[3]); + q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); return( q ); @@ -503,9 +504,9 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { // its a binary movement! - float32 *vec = (float32 *) &Data[pidx+1]; + const uint32 *vec = &Data[pidx+1]; - q.Set(vec[0], vec[1], vec[2], vec[3]); + q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); return( q ); } @@ -515,14 +516,14 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) float32 ratio = (frame - time1) / (time2 - time1); - float32 *frame1 = (float32 *) &Data[pidx+1]; - float32 *frame2 = (float32 *) &Data[p2idx+1]; + const uint32 *frame1 = &Data[pidx+1]; + const uint32 *frame2 = &Data[p2idx+1]; Quaternion q1(1); Quaternion q2(1); - q1.Set(frame1[0], frame1[1], frame1[2], frame1[3]); - q2.Set(frame2[0], frame2[1], frame2[2], frame2[3]); + q1.Set(std::bit_cast(frame1[0]), std::bit_cast(frame1[1]), std::bit_cast(frame1[2]), std::bit_cast(frame1[3])); + q2.Set(std::bit_cast(frame2[0]), std::bit_cast(frame2[1]), std::bit_cast(frame2[2]), std::bit_cast(frame2[3])); Fast_Slerp(q, q1, q2, ratio); @@ -972,7 +973,7 @@ bool AdaptiveDeltaMotionChannelClass::Load_W3D(ChunkLoadClass & cload) void AdaptiveDeltaMotionChannelClass::decompress(uint32 frame_idx, float *outdata) { // Start Over from the beginning - float *base = (float *) &Data[0]; // pointer to our true know beginning values + const uint32 *base = &Data[0]; // pointer to our true know beginning values bool done = false; @@ -982,7 +983,7 @@ void AdaptiveDeltaMotionChannelClass::decompress(uint32 frame_idx, float *outdat pPacket+= (sizeof(float) * VectorLen); // skip non-compressed header information pPacket+= PACKET_SIZE * vi; // skip to the appropriate packet start - float last_value = base[vi]; + float last_value = std::bit_cast(base[vi]); for (uint32 frame=1; frame<=frame_idx;) { // Frame Loop @@ -1048,8 +1049,7 @@ void AdaptiveDeltaMotionChannelClass::decompress(uint32 src_idx, float *srcdata, assert(src_idx < frame_idx); src_idx++; - float *base = (float *) &Data[0]; // pointer to our true know beginning values - base += VectorLen; // skip header information + const uint32 *base = &Data[VectorLen]; // skip header information bool done = false; From 9507acb21cdf9d55f7c4663cc7609703807661e7 Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Mon, 2 Nov 2026 09:53:55 -0700 Subject: [PATCH 2/4] refactor(ww3d2): Set motion channel quaternions from packets with a helper Co-Authored-By: Claude Opus 5.5 --- .../Source/WWVegas/WW3D2/motchan.cpp | 37 ++++++++++--------- .../Source/WWVegas/WW3D2/motchan.cpp | 37 ++++++++++--------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 9224c0e48c1..e0677389e13 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -431,7 +431,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - const uint32 *frm = &Data[pidx+1]; + const uint32* frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { @@ -449,7 +449,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - const uint32 *frm = &Data[pidx+1]; + const uint32* frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { setvec[i] = std::bit_cast(frm[i]); } @@ -461,8 +461,8 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) float32 ratio = (frame - time1) / (time2 - time1); - const uint32 *frame1 = &Data[pidx+1]; - const uint32 *frame2 = &Data[p2idx+1]; + const uint32* frame1 = &Data[pidx+1]; + const uint32* frame2 = &Data[p2idx+1]; for (int i=0; i < VectorLen; i++) { @@ -473,6 +473,16 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) } +// Sets a quaternion from the four floats stored in a packet. +static void Set_Quaternion_From_Packet(Quaternion& q, const uint32* packet) +{ + q.Set( + std::bit_cast(packet[0]), + std::bit_cast(packet[1]), + std::bit_cast(packet[2]), + std::bit_cast(packet[3])); +} + Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) { @@ -489,9 +499,7 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - const uint32 *vec = &Data[pidx+1]; - - q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); + Set_Quaternion_From_Packet(q, &Data[pidx+1]); return( q ); @@ -504,9 +512,7 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { // its a binary movement! - const uint32 *vec = &Data[pidx+1]; - - q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); + Set_Quaternion_From_Packet(q, &Data[pidx+1]); return( q ); } @@ -516,14 +522,11 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) float32 ratio = (frame - time1) / (time2 - time1); - const uint32 *frame1 = &Data[pidx+1]; - const uint32 *frame2 = &Data[p2idx+1]; - Quaternion q1(1); Quaternion q2(1); - q1.Set(std::bit_cast(frame1[0]), std::bit_cast(frame1[1]), std::bit_cast(frame1[2]), std::bit_cast(frame1[3])); - q2.Set(std::bit_cast(frame2[0]), std::bit_cast(frame2[1]), std::bit_cast(frame2[2]), std::bit_cast(frame2[3])); + Set_Quaternion_From_Packet(q1, &Data[pidx+1]); + Set_Quaternion_From_Packet(q2, &Data[p2idx+1]); Fast_Slerp(q, q1, q2, ratio); @@ -973,7 +976,7 @@ bool AdaptiveDeltaMotionChannelClass::Load_W3D(ChunkLoadClass & cload) void AdaptiveDeltaMotionChannelClass::decompress(uint32 frame_idx, float *outdata) { // Start Over from the beginning - const uint32 *base = &Data[0]; // pointer to our true know beginning values + const uint32* base = &Data[0]; // pointer to our true know beginning values bool done = false; @@ -1049,7 +1052,7 @@ void AdaptiveDeltaMotionChannelClass::decompress(uint32 src_idx, float *srcdata, assert(src_idx < frame_idx); src_idx++; - const uint32 *base = &Data[VectorLen]; // skip header information + const uint32* base = &Data[VectorLen]; // skip header information bool done = false; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 92cb2dfe41a..056b6624b53 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -431,7 +431,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - const uint32 *frm = &Data[pidx+1]; + const uint32* frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { @@ -449,7 +449,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - const uint32 *frm = &Data[pidx+1]; + const uint32* frm = &Data[pidx+1]; for (int i=0; i < VectorLen; i++) { setvec[i] = std::bit_cast(frm[i]); } @@ -461,8 +461,8 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) float32 ratio = (frame - time1) / (time2 - time1); - const uint32 *frame1 = &Data[pidx+1]; - const uint32 *frame2 = &Data[p2idx+1]; + const uint32* frame1 = &Data[pidx+1]; + const uint32* frame2 = &Data[p2idx+1]; for (int i=0; i < VectorLen; i++) { @@ -473,6 +473,16 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) } +// Sets a quaternion from the four floats stored in a packet. +static void Set_Quaternion_From_Packet(Quaternion& q, const uint32* packet) +{ + q.Set( + std::bit_cast(packet[0]), + std::bit_cast(packet[1]), + std::bit_cast(packet[2]), + std::bit_cast(packet[3])); +} + Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) { @@ -489,9 +499,7 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - const uint32 *vec = &Data[pidx+1]; - - q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); + Set_Quaternion_From_Packet(q, &Data[pidx+1]); return( q ); @@ -504,9 +512,7 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { // its a binary movement! - const uint32 *vec = &Data[pidx+1]; - - q.Set(std::bit_cast(vec[0]), std::bit_cast(vec[1]), std::bit_cast(vec[2]), std::bit_cast(vec[3])); + Set_Quaternion_From_Packet(q, &Data[pidx+1]); return( q ); } @@ -516,14 +522,11 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) float32 ratio = (frame - time1) / (time2 - time1); - const uint32 *frame1 = &Data[pidx+1]; - const uint32 *frame2 = &Data[p2idx+1]; - Quaternion q1(1); Quaternion q2(1); - q1.Set(std::bit_cast(frame1[0]), std::bit_cast(frame1[1]), std::bit_cast(frame1[2]), std::bit_cast(frame1[3])); - q2.Set(std::bit_cast(frame2[0]), std::bit_cast(frame2[1]), std::bit_cast(frame2[2]), std::bit_cast(frame2[3])); + Set_Quaternion_From_Packet(q1, &Data[pidx+1]); + Set_Quaternion_From_Packet(q2, &Data[p2idx+1]); Fast_Slerp(q, q1, q2, ratio); @@ -973,7 +976,7 @@ bool AdaptiveDeltaMotionChannelClass::Load_W3D(ChunkLoadClass & cload) void AdaptiveDeltaMotionChannelClass::decompress(uint32 frame_idx, float *outdata) { // Start Over from the beginning - const uint32 *base = &Data[0]; // pointer to our true know beginning values + const uint32* base = &Data[0]; // pointer to our true know beginning values bool done = false; @@ -1049,7 +1052,7 @@ void AdaptiveDeltaMotionChannelClass::decompress(uint32 src_idx, float *srcdata, assert(src_idx < frame_idx); src_idx++; - const uint32 *base = &Data[VectorLen]; // skip header information + const uint32* base = &Data[VectorLen]; // skip header information bool done = false; From 786a89887a611a7d0deb462cd349d12d5276c96f Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Tue, 3 Nov 2026 11:12:25 -0700 Subject: [PATCH 3/4] refactor(ww3d2): Copy motion channel vectors from packets with memcpy Co-Authored-By: Claude Opus 5.5 --- .../Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp | 13 ++----------- .../Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp | 13 ++----------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index e0677389e13..1e870f9a87a 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -431,13 +431,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - const uint32* frm = &Data[pidx+1]; - - for (int i=0; i < VectorLen; i++) { - - setvec[i] = std::bit_cast(frm[i]); - - } + memcpy(setvec, &Data[pidx+1], VectorLen * sizeof(float32)); return; @@ -449,10 +443,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - const uint32* frm = &Data[pidx+1]; - for (int i=0; i < VectorLen; i++) { - setvec[i] = std::bit_cast(frm[i]); - } + memcpy(setvec, &Data[pidx+1], VectorLen * sizeof(float32)); return; } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 056b6624b53..729e5598113 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -431,13 +431,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) if (pidx == ((NumTimeCodes - 1) * PacketSize)) { - const uint32* frm = &Data[pidx+1]; - - for (int i=0; i < VectorLen; i++) { - - setvec[i] = std::bit_cast(frm[i]); - - } + memcpy(setvec, &Data[pidx+1], VectorLen * sizeof(float32)); return; @@ -449,10 +443,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - const uint32* frm = &Data[pidx+1]; - for (int i=0; i < VectorLen; i++) { - setvec[i] = std::bit_cast(frm[i]); - } + memcpy(setvec, &Data[pidx+1], VectorLen * sizeof(float32)); return; } From c480a7c30357c6fa630412d3a87f072d54f7523c Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Sun, 8 Nov 2026 12:52:16 -0700 Subject: [PATCH 4/4] refactor(ww3d2): Take a packet array in the quaternion helper and drop dead initialization Co-Authored-By: Claude Opus 5.5 --- Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp | 7 +++---- GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 1e870f9a87a..47f6a14a65c 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -465,7 +465,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) // Sets a quaternion from the four floats stored in a packet. -static void Set_Quaternion_From_Packet(Quaternion& q, const uint32* packet) +static void Set_Quaternion_From_Packet(Quaternion& q, const uint32 packet[4]) { q.Set( std::bit_cast(packet[0]), @@ -502,7 +502,6 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - // its a binary movement! Set_Quaternion_From_Packet(q, &Data[pidx+1]); return( q ); @@ -513,8 +512,8 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) float32 ratio = (frame - time1) / (time2 - time1); - Quaternion q1(1); - Quaternion q2(1); + Quaternion q1; + Quaternion q2; Set_Quaternion_From_Packet(q1, &Data[pidx+1]); Set_Quaternion_From_Packet(q2, &Data[p2idx+1]); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 729e5598113..2485d251768 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -465,7 +465,7 @@ void TimeCodedMotionChannelClass::Get_Vector(float32 frame,float * setvec) // Sets a quaternion from the four floats stored in a packet. -static void Set_Quaternion_From_Packet(Quaternion& q, const uint32* packet) +static void Set_Quaternion_From_Packet(Quaternion& q, const uint32 packet[4]) { q.Set( std::bit_cast(packet[0]), @@ -502,7 +502,6 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) uint32 time = Data[p2idx]; if (time & W3D_TIMECODED_BINARY_MOVEMENT_FLAG) { - // its a binary movement! Set_Quaternion_From_Packet(q, &Data[pidx+1]); return( q ); @@ -513,8 +512,8 @@ Quaternion TimeCodedMotionChannelClass::Get_QuatVector(float32 frame) float32 ratio = (frame - time1) / (time2 - time1); - Quaternion q1(1); - Quaternion q2(1); + Quaternion q1; + Quaternion q2; Set_Quaternion_From_Packet(q1, &Data[pidx+1]); Set_Quaternion_From_Packet(q2, &Data[p2idx+1]);