ICB: Avoid casting PXMarker class to memory

This commit is contained in:
Paweł Kołodziejski 2022-07-30 16:17:54 +02:00
parent c0a35f0825
commit 0f4791ea28
No known key found for this signature in database
GPG Key ID: 0BDADC9E74440FF7
10 changed files with 87 additions and 99 deletions

View File

@ -389,7 +389,7 @@ void DrawFrame(const int32 frame) {
PXframe *frm = PXFrameEnOfAnim(framenum, pxanim);
PXmarker &marker = frm->markers[ORG_POS];
float mposx, mposy, mposz;
marker.GetXYZ(&mposx, &mposy, &mposz);
PXmarker_PSX_Object::GetXYZ(&marker, &mposx, &mposy, &mposz);
int32 dy = (int32)mposy;
g_av_actor->lw.t[0] = 0;

View File

@ -29,12 +29,11 @@
#include "engines/icb/common/px_common.h"
#include "common/endian.h"
namespace ICB {
#define PSX_PXANIM_SCHEMA 5
#define PC_PXANIM_SCHEMA 5
#define PXANIM_SCHEMA PC_PXANIM_SCHEMA
#define PXANIM_SCHEMA 5
#define PXANIM_TAG "Peas"
#define ORG_POS 0
@ -50,50 +49,35 @@ namespace ICB {
#define TRI_TYPE 3
#define OBJ_TYPE 4
#if PXANIM_SCHEMA == 1
#define TRI_POS 2
#define TRI_STRING "TRI"
#undef INT_TYPE
#define INT_TYPE *(uint32 *)INT_STRING
#undef TRI_TYPE
#define TRI_TYPE *(uint32 *)TRI_STRING
#endif // #if PXANIM_SCHEMA == 1
// PXmarker_PC : the PC version
class PXmarker_PC {
private:
typedef struct {
uint32 m_type;
float m_x, m_y, m_z;
float m_pan;
} PXmarker_PC;
#if PXANIM_SCHEMA == 1
float dummy1, dummy2;
#endif
// PXmarker_PC : the PC version
class PXmarker_PC_Object {
public:
void SetType(uint32 type) { m_type = type; }
void SetPan(float pan) { m_pan = pan; }
void SetXYZ(float x, float y, float z);
static void SetType(PXmarker_PC *marker, uint32 type) { marker->m_type = type; }
static void SetPan(PXmarker_PC *marker, float pan) { marker->m_pan = pan; }
static void SetXYZ(PXmarker_PC *marker, float x, float y, float z);
uint32 GetType(void) { return m_type; }
void GetPan(float *pan) { *pan = m_pan; }
void GetXYZ(float *x, float *y, float *z);
static uint32 GetType(PXmarker_PC *marker) { return marker->m_type; }
static void GetPan(PXmarker_PC *marker, float *pan) { *pan = marker->m_pan; }
static void GetXYZ(PXmarker_PC *marker, float *x, float *y, float *z);
};
inline void PXmarker_PC::SetXYZ(float x, float y, float z) {
m_x = x;
m_y = y;
m_z = z;
inline void PXmarker_PC_Object::SetXYZ(PXmarker_PC *marker, float x, float y, float z) {
marker->m_x = x;
marker->m_y = y;
marker->m_z = z;
}
inline void PXmarker_PC::GetXYZ(float *x, float *y, float *z) {
*x = m_x;
*y = m_y;
*z = m_z;
inline void PXmarker_PC_Object::GetXYZ(PXmarker_PC *marker, float *x, float *y, float *z) {
*x = marker->m_x;
*y = marker->m_y;
*z = marker->m_z;
}
// PXframe_PC : the PC version //
@ -108,43 +92,47 @@ typedef struct {
} PXframe_PC;
// PXmarker_PSX : the PSX version
class PXmarker_PSX {
private:
typedef struct {
uint8 m_type;
uint8 x8;
uint16 x7y9;
uint32 y6z15pan11;
} PXmarker_PSX;
// PXmarker_PSX : the PSX version
class PXmarker_PSX_Object {
public:
void SetType(uint8 type) { m_type = type; }
void SetPackedXYZPan(uint8 _x8, uint16 _x7y9, uint32 _y6z15pan11);
static void SetType(PXmarker_PSX *marker, uint8 type) { marker->m_type = type; }
static void SetPackedXYZPan(PXmarker_PSX *marker, uint8 _x8, uint16 _x7y9, uint32 _y6z15pan11);
uint8 GetType(void) const { return m_type; }
static uint8 GetType(PXmarker_PSX *marker) { return marker->m_type; }
void GetPan(float *pan) const;
void GetXYZ(float *x, float *y, float *z) const;
static void GetPan(PXmarker_PSX *marker, float *pan);
static void GetXYZ(PXmarker_PSX *marker, float *x, float *y, float *z);
};
inline void PXmarker_PSX::SetPackedXYZPan(uint8 _x8, uint16 _x7y9, uint32 _y6z15pan11) {
x8 = _x8;
x7y9 = _x7y9;
y6z15pan11 = _y6z15pan11;
inline void PXmarker_PSX_Object::SetPackedXYZPan(PXmarker_PSX *marker, uint8 _x8, uint16 _x7y9, uint32 _y6z15pan11) {
marker->x8 = _x8;
marker->x7y9 = _x7y9;
marker->y6z15pan11 = _y6z15pan11;
}
inline void PXmarker_PSX::GetPan(float *pan) const { *pan = (float)(((y6z15pan11 & 0x7FF) << 1)) / 4096.0f; }
inline void PXmarker_PSX_Object::GetPan(PXmarker_PSX *marker, float *pan) {
*pan = (float)(((marker->y6z15pan11 & 0x7FF) << 1)) / 4096.0f;
}
inline void PXmarker_PSX::GetXYZ(float *x, float *y, float *z) const {
inline void PXmarker_PSX_Object::GetXYZ(PXmarker_PSX *marker, float *x, float *y, float *z) {
int32 ix, iy, iz;
ix = ((x8 << 7) | (x7y9 >> 9));
ix = ((marker->x8 << 7) | (marker->x7y9 >> 9));
if (ix >= 16384)
ix = ix - 32768;
iy = (((x7y9 & 0x1FF) << 6) | (y6z15pan11 >> 26));
iy = (((marker->x7y9 & 0x1FF) << 6) | (marker->y6z15pan11 >> 26));
if (iy >= 16384)
iy = iy - 32768;
iz = ((y6z15pan11 >> 11) & 0x7FFF);
iz = ((marker->y6z15pan11 >> 11) & 0x7FFF);
if (iz >= 16384)
iz = iz - 32768;
@ -183,21 +171,21 @@ typedef struct {
inline void ConvertPXanim(PXanim_PSX *anim) {
// Support old schema type files
if (anim->schema == PSX_PXANIM_SCHEMA - 1) {
if (FROM_LE_32(anim->schema) == PXANIM_SCHEMA - 1) {
int32 nFrames = anim->frame_qty;
anim->frame_qty = (uint8)nFrames;
anim->speed = 1;
anim->schema = PSX_PXANIM_SCHEMA;
anim->schema = TO_LE_32(PXANIM_SCHEMA);
}
}
inline void ConvertPXanim(PXanim_PC *anim) {
// Support old schema type files
if (anim->schema == PC_PXANIM_SCHEMA - 1) {
if (FROM_LE_32(anim->schema) == PXANIM_SCHEMA - 1) {
int32 nFrames = anim->frame_qty;
anim->frame_qty = (uint8)nFrames;
anim->speed = 1;
anim->schema = PC_PXANIM_SCHEMA;
anim->schema = TO_LE_32(PXANIM_SCHEMA);
}
}

View File

@ -1476,9 +1476,9 @@ mcodeFunctionReturnCodes _game_session::fn_apply_anim_y(int32 &, int32 *params)
PXreal yend;
PXreal ystart;
PXFrameEnOfAnim(pAnim->frame_qty - 1, pAnim)->markers[ORG_POS].GetXYZ(&x, &yend, &z);
PXmarker_PSX_Object::GetXYZ(&PXFrameEnOfAnim(pAnim->frame_qty - 1, pAnim)->markers[ORG_POS], &x, &yend, &z);
PXFrameEnOfAnim(0, pAnim)->markers[ORG_POS].GetXYZ(&x, &ystart, &z);
PXmarker_PSX_Object::GetXYZ(&PXFrameEnOfAnim(0, pAnim)->markers[ORG_POS], &x, &ystart, &z);
y_next = yend - ystart;

View File

@ -483,7 +483,7 @@ mcodeFunctionReturnCodes _game_session::Core_prop_interact(int32 & /*result*/, i
for (j = 0; j < M->anim_speed; j++) {
PXframe *frame = PXFrameEnOfAnim(L->anim_pc + j, pAnim);
if ((frame->marker_qty > INT_POS) && (INT_TYPE == (frame->markers[INT_POS].GetType()))) {
if ((frame->marker_qty > INT_POS) && (INT_TYPE == (PXmarker_PSX_Object::GetType(&frame->markers[INT_POS])))) {
// run the trigger anim
if (!MS->Call_socket(M->target_id, "trigger", &retval)) {
Message_box("[%s] interact marker but no trigger script", (const char *)L->GetName());

View File

@ -68,7 +68,7 @@ bool8 _game_session::Find_interact_marker_in_anim(__mega_set_names animation, PX
// INT_TYPE : which means it was a real export of the INT marker on the frame when the anim made the INT marker visible
PXreal x_org, z_org, unused;
PXFrameEnOfAnim(0, pAnim)->markers[ORG_POS].GetXYZ(&x_org, &unused, &z_org);
PXmarker_PSX_Object::GetXYZ(&PXFrameEnOfAnim(0, pAnim)->markers[ORG_POS], &x_org, &unused, &z_org);
for (uint16 frame = 0; frame < pAnim->frame_qty; frame++) {
PXframe *frm = PXFrameEnOfAnim(frame, pAnim);
@ -76,13 +76,13 @@ bool8 _game_session::Find_interact_marker_in_anim(__mega_set_names animation, PX
if (frm->marker_qty > INT_POS) {
PXmarker *marker = &(frm->markers[INT_POS]);
uint8 mtype = (uint8)marker->GetType();
uint8 mtype = (uint8)PXmarker_PSX_Object::GetType(marker);
if ((INT0_TYPE == mtype) || (INT_TYPE == mtype)) {
// The interact marker exists
PXreal x_int, z_int;
marker->GetXYZ(&x_int, &unused, &z_int);
PXmarker_PSX_Object::GetXYZ(marker, &x_int, &unused, &z_int);
xoff[0] = x_int - x_org;
zoff[0] = z_int - z_org;

View File

@ -57,8 +57,8 @@ bool8 _game_session::Easy_frame_motion_and_pan(__mega_set_names anim_type, bool8
// Get current frame from the anim
PXframe *currentFrame = PXFrameEnOfAnim(L->anim_pc, pAnim);
nextFrame->markers[ORG_POS].GetPan(&pan1);
currentFrame->markers[ORG_POS].GetPan(&pan2);
PXmarker_PSX_Object::GetPan(&nextFrame->markers[ORG_POS], &pan1);
PXmarker_PSX_Object::GetPan(&currentFrame->markers[ORG_POS], &pan2);
L->pan += (pan1 - pan2); // update by difference
@ -66,8 +66,8 @@ bool8 _game_session::Easy_frame_motion_and_pan(__mega_set_names anim_type, bool8
// note that we always read frame+1 for motion of next frame even though the voxel frame itself will be looped back to 0
PXreal x1, x2, z1, z2, unused;
nextFrame->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
currentFrame->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&nextFrame->markers[ORG_POS], &x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[ORG_POS], &x1, &unused, &z1);
xnext = x2 - x1;
znext = z2 - z1;
@ -82,7 +82,7 @@ bool8 _game_session::Easy_frame_motion_and_pan(__mega_set_names anim_type, bool8
// as GCC got it all wrong if the same reference was re-used
currentFrame = PXFrameEnOfAnim(L->anim_pc, pAnim);
currentFrame->markers[ORG_POS].GetPan(&pan);
PXmarker_PSX_Object::GetPan(&currentFrame->markers[ORG_POS], &pan);
L->pan_adjust = pan; // this value will be unwound from the orientation of the frame at render time in stage draw
@ -132,8 +132,8 @@ bool8 _game_session::Easy_frame_and_motion(__mega_set_names anim_type, bool8 /*p
// Get current frame from the anim
PXframe *currentFrame = PXFrameEnOfAnim(L->anim_pc, pAnim);
nextFrame->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
currentFrame->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&nextFrame->markers[ORG_POS], &x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[ORG_POS], &x1, &unused, &z1);
xnext = x2 - x1;
znext = z2 - z1;
@ -213,8 +213,8 @@ __barrier_result _game_session::Core_advance(__mega_set_names anim_type, bool8 p
// Get current frame from the anim
PXframe *currentFrame = PXFrameEnOfAnim(L->anim_pc, pAnim);
nextFrame->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
currentFrame->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&nextFrame->markers[ORG_POS], &x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[ORG_POS], &x1, &unused, &z1);
xnext = x2 - x1;
znext = z2 - z1;
@ -326,8 +326,8 @@ __barrier_result _game_session::Core_reverse(__mega_set_names anim_type, bool8 p
// Get current frame from the anim
PXframe *currentFrame = PXFrameEnOfAnim(L->anim_pc, pAnim);
nextFrame->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
currentFrame->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&nextFrame->markers[ORG_POS], &x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[ORG_POS], &x1, &unused, &z1);
xnext = x2 - x1;
znext = z2 - z1;
@ -417,8 +417,8 @@ void _game_session::Animate_turn_to_pan(__mega_set_names anim_type, uint32 speed
// Get current frame from the anim
PXframe *currentFrame = PXFrameEnOfAnim(L->anim_pc, pAnim);
infoFrame->markers[ORG_POS].GetPan(&pan1);
currentFrame->markers[ORG_POS].GetPan(&pan2);
PXmarker_PSX_Object::GetPan(&infoFrame->markers[ORG_POS], &pan1);
PXmarker_PSX_Object::GetPan(&currentFrame->markers[ORG_POS], &pan2);
this_pan_change = (pan1 - pan2); // update by difference
@ -453,10 +453,10 @@ void _game_session::Animate_turn_to_pan(__mega_set_names anim_type, uint32 speed
// Get the next frame from the anim
PXframe *nextFrame = PXFrameEnOfAnim(next_pc, pAnim);
nextFrame->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&nextFrame->markers[ORG_POS], &x2, &unused, &z2);
// Note, assumes current frame hasn't changed i.e L->info_pc is same
currentFrame->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[ORG_POS], &x1, &unused, &z1);
// FIXME: xnext and znext are not used currently...
//PXreal xnext = x2 - x1;
@ -469,7 +469,7 @@ void _game_session::Animate_turn_to_pan(__mega_set_names anim_type, uint32 speed
PXreal pan;
// Note, L->anim_pc = next_pc
nextFrame->markers[ORG_POS].GetPan(&pan);
PXmarker_PSX_Object::GetPan(&nextFrame->markers[ORG_POS], &pan);
L->pan_adjust = pan;

View File

@ -1354,7 +1354,7 @@ __mode_return _player::Process_strike() {
currentFrame = PXFrameEnOfAnim(log->anim_pc, pAnim);
if (currentFrame->marker_qty > INT_POS) {
if (INT_TYPE == currentFrame->markers[INT_POS].GetType()) {
if (INT_TYPE == PXmarker_PSX_Object::GetType(&currentFrame->markers[INT_POS])) {
// punching a prop
if ((interact_selected) && (MS->logic_structs[cur_interact_id]->image_type == PROP)) {
MS->Call_socket(cur_interact_id, "ko", &retval); // call a ko script if there is one
@ -1372,12 +1372,12 @@ __mode_return _player::Process_strike() {
// get interact marker offset
PXreal x_org, z_org, unused;
PXFrameEnOfAnim(0, pAnim)->markers[ORG_POS].GetXYZ(&x_org, &unused, &z_org);
PXmarker_PSX_Object::GetXYZ(&PXFrameEnOfAnim(0, pAnim)->markers[ORG_POS], &x_org, &unused, &z_org);
// The interact marker exists
PXreal x_int, z_int;
currentFrame->markers[INT_POS].GetXYZ(&x_int, &unused, &z_int);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[INT_POS], &x_int, &unused, &z_int);
int_x = x_int - x_org;
int_z = z_int - z_org;
@ -2729,16 +2729,16 @@ bool8 _player::Advance_frame_motion_and_pan(__mega_set_names anim_type) {
// Get the current frame from the anim
PXframe *currentFrame = PXFrameEnOfAnim(log->anim_pc, pAnim);
nextFrame->markers[ORG_POS].GetPan(&pan1);
currentFrame->markers[ORG_POS].GetPan(&pan2);
PXmarker_PSX_Object::GetPan(&nextFrame->markers[ORG_POS], &pan1);
PXmarker_PSX_Object::GetPan(&currentFrame->markers[ORG_POS], &pan2);
log->pan += (pan1 - pan2); // update by difference
// get motion displacement from currently displayed frame to next one
// note that we always read frame+1 for motion of next frame even though the voxel frame itself will be looped back to 0
PXreal x1, x2, z1, z2, unused;
nextFrame->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
currentFrame->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&nextFrame->markers[ORG_POS], &x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[ORG_POS], &x2, &unused, &z2);
xnext = x1 - x2;
znext = z1 - z2;
@ -2748,7 +2748,7 @@ bool8 _player::Advance_frame_motion_and_pan(__mega_set_names anim_type) {
// get the pan unwind value of the frame to be printed
PXreal pan;
PXFrameEnOfAnim(log->anim_pc, pAnim)->markers[ORG_POS].GetPan(&pan);
PXmarker_PSX_Object::GetPan(&PXFrameEnOfAnim(log->anim_pc, pAnim)->markers[ORG_POS], &pan);
log->pan_adjust = pan; // this value will be unwound from the orientation of the frame at render time in stage draw
// calculate the new x and z coordinate from this frames motion offset
@ -2825,16 +2825,16 @@ bool8 _player::Reverse_frame_motion_and_pan(__mega_set_names anim_type) {
// Get the current frame from the anim
PXframe *currentFrame = PXFrameEnOfAnim(log->anim_pc, pAnim);
nextFrame->markers[ORG_POS].GetPan(&pan1);
currentFrame->markers[ORG_POS].GetPan(&pan2);
PXmarker_PSX_Object::GetPan(&nextFrame->markers[ORG_POS], &pan1);
PXmarker_PSX_Object::GetPan(&currentFrame->markers[ORG_POS], &pan2);
log->pan += (pan1 - pan2); // update by difference
// get motion displacement from currently displayed frame to next one
// note that we always read frame+1 for motion of next frame even though the voxel frame itself will be looped back to 0
PXreal x1, x2, z1, z2, unused;
nextFrame->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
currentFrame->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&nextFrame->markers[ORG_POS], &x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&currentFrame->markers[ORG_POS], &x2, &unused, &z2);
xnext = x1 - x2;
znext = z1 - z2;
@ -2844,7 +2844,7 @@ bool8 _player::Reverse_frame_motion_and_pan(__mega_set_names anim_type) {
// get the pan unwind value of the frame to be printed
PXreal pan;
nextFrame->markers[ORG_POS].GetPan(&pan);
PXmarker_PSX_Object::GetPan(&nextFrame->markers[ORG_POS], &pan);
log->pan_adjust = pan;

View File

@ -1057,8 +1057,8 @@ uint32 _game_session::Animate_points(_route_description *route) {
// get motion displacement from currently displayed frame to next one
// note that we always read frame+1 for motion of next frame even though the voxel frame itself will be looped back to 0
PXreal x1, z1, x2, z2, unused;
PXFrameEnOfAnim(L->anim_pc + 1, pAnim)->markers[ORG_POS].GetXYZ(&x1, &unused, &z1);
PXFrameEnOfAnim(L->anim_pc, pAnim)->markers[ORG_POS].GetXYZ(&x2, &unused, &z2);
PXmarker_PSX_Object::GetXYZ(&PXFrameEnOfAnim(L->anim_pc + 1, pAnim)->markers[ORG_POS], &x1, &unused, &z1);
PXmarker_PSX_Object::GetXYZ(&PXFrameEnOfAnim(L->anim_pc, pAnim)->markers[ORG_POS], &x2, &unused, &z2);
xnext = x1 - x2;
znext = z1 - z2;

View File

@ -109,7 +109,7 @@ void _game_session::Stage_draw_poly() {
}
PXmarker_PSX &marker = PXFrameEnOfAnim(f, pAnim)->markers[ORG_POS];
float dx, dy, dz;
marker.GetXYZ(&dx, &dy, &dz);
PXmarker_PSX_Object::GetXYZ(&marker, &dx, &dy, &dz);
// Make the actors orientation matrix
int32 pan;

View File

@ -499,15 +499,15 @@ int32 drawSpecialObjects(SDactor &actor, MATRIXPC *local2screen, int32 brightnes
PXframe *frm = PXFrameEnOfAnim(actor.frame, pAnim);
if (frm->marker_qty > INT_POS) {
PXmarker *marker = &(frm->markers[INT_POS]);
uint8 mtype = (uint8)marker->GetType();
uint8 mtype = (uint8)PXmarker_PSX_Object::GetType(marker);
if ((INT0_TYPE == mtype) || (INT_TYPE == mtype)) {
// The interact marker exists
PXfloat mx, my, mz;
marker->GetXYZ(&mx, &my, &mz);
PXmarker_PSX_Object::GetXYZ(marker, &mx, &my, &mz);
PXfloat ox, oy, oz;
marker = &(frm->markers[ORG_POS]);
marker->GetXYZ(&ox, &oy, &oz);
PXmarker_PSX_Object::GetXYZ(marker, &ox, &oy, &oz);
// Yeah - found a muzzle flash
mflash = 1;