diff --git a/common/main/fwdobject.h b/common/main/fwdobject.h index ccc6e0fd8..91bb472f8 100644 --- a/common/main/fwdobject.h +++ b/common/main/fwdobject.h @@ -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); diff --git a/similar/main/gameseg.cpp b/similar/main/gameseg.cpp index 6bd9be4e1..f181cfc42 100644 --- a/similar/main/gameseg.cpp +++ b/similar/main/gameseg.cpp @@ -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); diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index ecf313f38..635f06419 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -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(&multibuf[count]), obj, 0); + create_shortpos_little(reinterpret_cast(&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(&multibuf[count]), miss, 0); + create_shortpos_little(reinterpret_cast(&multibuf[count]), miss); count += sizeof(shortpos); } multi_send_data(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); diff --git a/similar/main/multibot.cpp b/similar/main/multibot.cpp index c7e4cfa69..003bca15c 100644 --- a/similar/main/multibot.cpp +++ b/similar/main/multibot.cpp @@ -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(&multibuf[loc]), objnum, 0); + create_shortpos_little(reinterpret_cast(&multibuf[loc]), objnum); loc += sizeof(shortpos); } multi_send_data(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])); } } diff --git a/similar/main/newdemo.cpp b/similar/main/newdemo.cpp index 19b0286fa..d99b5258f 100644 --- a/similar/main/newdemo.cpp +++ b/similar/main/newdemo.cpp @@ -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)) {