Propagate swap_bytes argument for create_shortpos

In every case but one, create_shortpos was called with a constant flag
equal to words_bigendian.  The demo system called it with a constant 0.
Split create_shortpos into create_shortpos_little and
create_shortpos_native.  Use create_shortpos_native for the demo system,
and create_shortpos_little everywhere else.
This commit is contained in:
Kp 2015-06-13 22:42:21 +00:00
parent ce72014e2e
commit 1dc0e24f30
5 changed files with 26 additions and 19 deletions

View file

@ -254,11 +254,12 @@ void dead_player_end();
// Extract information from an object (objp->orient, objp->pos,
// objp->segnum), stuff in a shortpos structure. See typedef
// shortpos.
void create_shortpos(shortpos *spp, vcobjptr_t objp, int swap_bytes);
void create_shortpos_little(shortpos *spp, vcobjptr_t objp);
void create_shortpos_native(shortpos *spp, vcobjptr_t objp);
// Extract information from a shortpos, stuff in objp->orient
// (matrix), objp->pos, objp->segnum
void extract_shortpos(vobjptridx_t objp, shortpos *spp, int swap_bytes);
void extract_shortpos_little(vobjptridx_t objp, shortpos *spp);
// create and extract quaternion structure from object data which greatly saves bytes by using quaternion instead or orientation matrix
void create_quaternionpos(quaternionpos * qpp, vobjptr_t objp, int swap_bytes);

View file

@ -959,7 +959,7 @@ static sbyte convert_to_byte(fix f)
// Extract the matrix into byte values.
// Create a position relative to vertex 0 with 1/256 normal "fix" precision.
// Stuff segment in a short.
void create_shortpos(shortpos *spp, const vcobjptr_t objp, int swap_bytes)
void create_shortpos_native(shortpos *spp, const vcobjptr_t objp)
{
// int segnum;
sbyte *sp;
@ -986,10 +986,15 @@ void create_shortpos(shortpos *spp, const vcobjptr_t objp, int swap_bytes)
spp->velx = (objp->mtype.phys_info.velocity.x) >> VEL_PRECISION;
spp->vely = (objp->mtype.phys_info.velocity.y) >> VEL_PRECISION;
spp->velz = (objp->mtype.phys_info.velocity.z) >> VEL_PRECISION;
}
void create_shortpos_little(shortpos *spp, const vcobjptr_t objp)
{
create_shortpos_native(spp, objp);
// swap the short values for the big-endian machines.
if (swap_bytes) {
if (words_bigendian)
{
spp->xo = INTEL_SHORT(spp->xo);
spp->yo = INTEL_SHORT(spp->yo);
spp->zo = INTEL_SHORT(spp->zo);
@ -1000,7 +1005,7 @@ void create_shortpos(shortpos *spp, const vcobjptr_t objp, int swap_bytes)
}
}
void extract_shortpos(const vobjptridx_t objp, shortpos *spp, int swap_bytes)
void extract_shortpos_little(const vobjptridx_t objp, shortpos *spp)
{
sbyte *sp;
@ -1016,7 +1021,8 @@ void extract_shortpos(const vobjptridx_t objp, shortpos *spp, int swap_bytes)
objp->orient.uvec.z = *sp++ << MATRIX_PRECISION;
objp->orient.fvec.z = *sp++ << MATRIX_PRECISION;
if (swap_bytes) {
if (words_bigendian)
{
spp->xo = INTEL_SHORT(spp->xo);
spp->yo = INTEL_SHORT(spp->yo);
spp->zo = INTEL_SHORT(spp->zo);

View file

@ -1616,10 +1616,10 @@ static void multi_do_position(const playernum_t pnum, const ubyte *buf)
shortpos sp;
memcpy(sp.bytemat, &buf[2], 9);
memcpy(&sp.xo, &buf[11], 14);
extract_shortpos(obj, &sp, 1);
extract_shortpos_little(obj, &sp);
}
else
extract_shortpos(obj, (shortpos *)(&buf[2]), 0);
extract_shortpos_little(obj, (shortpos *)(&buf[2]));
if (obj->movement_type == MT_PHYSICS)
set_thrust_from_velocity(obj);
@ -2764,7 +2764,7 @@ void multi_send_position(const vobjptridx_t obj)
if (words_bigendian)
{
shortpos sp;
create_shortpos(&sp, obj, 1);
create_shortpos_little(&sp, obj);
memcpy(&multibuf[count], sp.bytemat, 9);
count += 9;
memcpy(&multibuf[count], &sp.xo, 14);
@ -2772,7 +2772,7 @@ void multi_send_position(const vobjptridx_t obj)
}
else
{
create_shortpos(reinterpret_cast<shortpos *>(&multibuf[count]), obj, 0);
create_shortpos_little(reinterpret_cast<shortpos *>(&multibuf[count]), obj);
count += sizeof(shortpos);
}
// send twice while first has priority so the next one will be attached to the next bigdata packet
@ -3604,7 +3604,7 @@ void multi_send_guided_info (const vobjptr_t miss,char done)
if (words_bigendian)
{
shortpos sp;
create_shortpos(&sp, miss, 1);
create_shortpos_little(&sp, miss);
memcpy(&multibuf[count], sp.bytemat, 9);
count += 9;
memcpy(&multibuf[count], &sp.xo, 14);
@ -3612,7 +3612,7 @@ void multi_send_guided_info (const vobjptr_t miss,char done)
}
else
{
create_shortpos(reinterpret_cast<shortpos *>(&multibuf[count]), miss, 0);
create_shortpos_little(reinterpret_cast<shortpos *>(&multibuf[count]), miss);
count += sizeof(shortpos);
}
multi_send_data<MULTI_GUIDED>(multibuf, count, 0);
@ -3638,11 +3638,11 @@ static void multi_do_guided (const playernum_t pnum, const ubyte *buf)
shortpos sp;
memcpy(sp.bytemat, &buf[count], 9);
memcpy(&sp.xo, &buf[count + 9], 14);
extract_shortpos(Guided_missile[(int)pnum], &sp, 1);
extract_shortpos_little(Guided_missile[(int)pnum], &sp);
}
else
{
extract_shortpos(Guided_missile[(int)pnum], (shortpos *)(&buf[count]), 0);
extract_shortpos_little(Guided_missile[(int)pnum], (shortpos *)(&buf[count]));
}
count+=sizeof (shortpos);

View file

@ -404,7 +404,7 @@ void multi_send_robot_position_sub(const vobjptridx_t objnum, int now)
if (words_bigendian)
{
shortpos sp;
create_shortpos(&sp, objnum, 1);
create_shortpos_little(&sp, objnum);
memcpy(&multibuf[loc], sp.bytemat, 9);
loc += 9;
memcpy(&multibuf[loc], &sp.xo, 14);
@ -412,7 +412,7 @@ void multi_send_robot_position_sub(const vobjptridx_t objnum, int now)
}
else
{
create_shortpos(reinterpret_cast<shortpos *>(&multibuf[loc]), objnum, 0);
create_shortpos_little(reinterpret_cast<shortpos *>(&multibuf[loc]), objnum);
loc += sizeof(shortpos);
}
multi_send_data<MULTI_ROBOT_POSITION>(multibuf, loc, now?1:0);
@ -758,11 +758,11 @@ void multi_do_robot_position(const playernum_t pnum, const ubyte *buf)
memcpy(sp.bytemat, &buf[loc], 9);
loc += 9;
memcpy(&sp.xo, &buf[loc], 14);
extract_shortpos(robot, &sp, 1);
extract_shortpos_little(robot, &sp);
}
else
{
extract_shortpos(robot, (shortpos *)(&buf[loc]), 0);
extract_shortpos_little(robot, (shortpos *)(&buf[loc]));
}
}

View file

@ -394,7 +394,7 @@ static void nd_write_shortpos(const vcobjptr_t obj)
shortpos sp;
ubyte render_type;
create_shortpos(&sp, obj, 0);
create_shortpos_native(&sp, obj);
render_type = obj->render_type;
if (((render_type == RT_POLYOBJ) || (render_type == RT_HOSTAGE) || (render_type == RT_MORPH)) || (obj->type == OBJ_CAMERA)) {