Fix ambiguous use of INTEL_SHORT/INTEL_INT

This commit is contained in:
Kp 2015-04-02 02:36:52 +00:00
parent 85a777d300
commit 6e96ff3e00
6 changed files with 28 additions and 22 deletions

View file

@ -399,7 +399,7 @@ static void gr_bm_ubitblt00_rle(unsigned w, unsigned h, int dx, int dy, int sx,
data_offset = 2;
auto sbits = &src.get_bitmap_data()[4 + (src.bm_h*data_offset)];
for (uint_fast32_t i = 0; i != sy; ++i)
sbits += (int)(INTEL_SHORT(src.bm_data[4+(i*data_offset)]));
sbits += src.bm_data[4+(i*data_offset)];
auto dbits = &dest.get_bitmap_data()[(dest.bm_rowsize * dy) + dx];
// No interlacing, copy the whole buffer.
for (uint_fast32_t i = 0; i != h; ++i)
@ -422,7 +422,7 @@ static void gr_bm_ubitblt00m_rle(unsigned w, unsigned h, int dx, int dy, int sx,
data_offset = 2;
auto sbits = &src.get_bitmap_data()[4 + (src.bm_h*data_offset)];
for (uint_fast32_t i = 0; i != sy; ++i)
sbits += (int)(INTEL_SHORT(src.bm_data[4+(i*data_offset)]));
sbits += src.bm_data[4+(i*data_offset)];
auto dbits = &dest.get_bitmap_data()[(dest.bm_rowsize * dy) + dx];
// No interlacing, copy the whole buffer.
for (uint_fast32_t i = 0; i != h; ++i)
@ -446,7 +446,7 @@ static void gr_bm_ubitblt0x_rle(unsigned w, unsigned h, int dx, int dy, int sx,
data_offset = 2;
auto sbits = &src.bm_data[4 + (src.bm_h*data_offset)];
for (uint_fast32_t i = 0; i != sy; ++i)
sbits += (int)(INTEL_SHORT(src.bm_data[4+(i*data_offset)]));
sbits += src.bm_data[4 + (i * data_offset)];
for (uint_fast32_t y1 = 0; y1 != h; ++y1)
{

View file

@ -549,7 +549,7 @@ void rle_swap_0_255(grs_bitmap &bmp)
}
}
if (rle_big) // set line size
*((unsigned short *)&temp[4 + 2 * i]) = INTEL_SHORT(ptr2 - start);
PUT_INTEL_SHORT(&temp[4 + 2 * i], static_cast<uint16_t>(ptr2 - start));
else
temp[4 + i] = ptr2 - start;
ptr += line_size; // go to next line
@ -596,7 +596,7 @@ void rle_remap(grs_bitmap &bmp, array<color_t, 256> &colormap)
}
}
if (rle_big) // set line size
*((unsigned short *)&temp[4 + 2 * i]) = INTEL_SHORT(ptr2 - start);
PUT_INTEL_SHORT(&temp[4 + 2 * i], static_cast<uint16_t>(ptr2 - start));
else
temp[4 + i] = ptr2 - start;
ptr += line_size; // go to next line

View file

@ -61,22 +61,30 @@ static inline int32_t SWAPINT(const int32_t &i)
#define SWAPINT64(x) ((((x) & 0xff00000000000000LL)/(2^56)) | (((x) & 0x00ff000000000000LL)/(2^40)) | (((x) & 0x0000ff0000000000LL)/(2^24)) | (((x) & 0x000000ff00000000LL)/(2^8)) | (((x) & 0x00000000ff000000LL)*(2^8)) | (((x) & 0x0000000000ff0000LL)*(2^24)) | (((x) & 0x000000000000ff00LL)*(2^40)) | (((x) & 0x00000000000000ffLL)*(2^56)))
#endif
#ifndef WORDS_BIGENDIAN
#define INTEL_INT64(x) x
#define INTEL_INT(x) x
#define INTEL_SHORT(x) x
#else // ! WORDS_BIGENDIAN
#define INTEL_INT64(x) SWAPINT64(x)
#define INTEL_INT(x) SWAPINT(x)
#define INTEL_SHORT(x) SWAPSHORT(x)
#endif // ! WORDS_BIGENDIAN
#ifndef WORDS_NEED_ALIGNMENT
/* Always resolve F(a), so ambiguous calls are flagged even on little
* endian.
*/
#define byteutil_choose_endian(F,a) (static_cast<void>(static_cast<decltype(F(a))>(0)), a)
#define byteutil_unaligned_copy(dt, d, s) (static_cast<dt &>(d) = *reinterpret_cast<const dt *>(s))
#else // ! WORDS_NEED_ALIGNMENT
#define byteutil_choose_endian(F,a) (F(a))
#define byteutil_unaligned_copy(dt, d, s) memcpy(&static_cast<dt &>(d), reinterpret_cast<const uint8_t *>(s), sizeof(d))
#endif // ! WORDS_NEED_ALIGNMENT
template <typename T>
static inline T INTEL_SHORT(const T &x)
{
return byteutil_choose_endian(SWAPSHORT, x);
}
template <typename T>
static inline T INTEL_INT(const T &x)
{
return byteutil_choose_endian(SWAPINT, x);
}
#undef byteutil_choose_endian
template <typename T>
static inline uint32_t GET_INTEL_INT(const T *p)
{

View file

@ -87,7 +87,7 @@ extern int multi_protocol; // set and determinate used protocol
#define MULTI_PROTO_UDP 1 // UDP protocol
// What version of the multiplayer protocol is this? Increment each time something drastic changes in Multiplayer without the version number changes. Reset to 0 each time the version of the game changes
#define MULTI_PROTO_VERSION 17
#define MULTI_PROTO_VERSION static_cast<uint16_t>(18)
// PROTOCOL VARIABLES AND DEFINES - END
// limits for Packets (i.e. positional updates) per sec
@ -499,7 +499,7 @@ uint_fast32_t multi_powerup_is_allowed(const unsigned id, const unsigned Allowed
extern void multi_send_stolen_items();
void multi_send_trigger_specific(playernum_t pnum,char trig);
void multi_send_door_open_specific(playernum_t pnum,segnum_t segnum, int side,ubyte flag);
void multi_send_wall_status_specific (playernum_t pnum,int wallnum,ubyte type,ubyte flags,ubyte state);
void multi_send_wall_status_specific(playernum_t pnum,uint16_t wallnum,ubyte type,ubyte flags,ubyte state);
void multi_send_light_specific (playernum_t pnum,segnum_t segnum,ubyte val);
void multi_send_capture_bonus (playernum_t pnum);
int multi_all_players_alive();

View file

@ -627,7 +627,7 @@ static ushort netmisc_calc_checksum()
s = INTEL_SHORT(j);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
}
range_for (uint16_t j, Segments[i].verts)
range_for (const uint16_t j, Segments[i].verts)
{
s = INTEL_SHORT(j);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
@ -641,8 +641,6 @@ static ushort netmisc_calc_checksum()
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
t = INTEL_INT(((int)Segments[i].static_light));
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
s = INTEL_SHORT(0); // no matter if we need alignment on our platform, if we have editor we MUST consider this integer to get the same checksum as non-editor games calculate
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
#endif
}
sum2 %= 255;

View file

@ -3525,7 +3525,7 @@ void multi_send_drop_weapon(objnum_t objnum, int seed)
count++;
multibuf[count++]=(char)get_powerup_id(objp);
PUT_INTEL_SHORT(multibuf+count, objnum); count += 2;
PUT_INTEL_SHORT(multibuf+count, ammo_count); count += 2;
PUT_INTEL_SHORT(multibuf+count, static_cast<uint16_t>(ammo_count)); count += 2;
PUT_INTEL_INT(multibuf+count, seed);
count += 4;
@ -3655,7 +3655,7 @@ static void multi_do_stolen_items (const ubyte *buf)
}
}
void multi_send_wall_status_specific (const playernum_t pnum,int wallnum,ubyte type,ubyte flags,ubyte state)
void multi_send_wall_status_specific(const playernum_t pnum,uint16_t wallnum,ubyte type,ubyte flags,ubyte state)
{
// Send wall states a specific rejoining player