From b8258da997b59d6c541b5323c806a2f5b9fd1675 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 30 Aug 2020 23:34:40 +0200 Subject: [PATCH] - cleaning out some trash from compat.h. The header from hell... --- source/blood/src/actor.cpp | 1 - source/blood/src/nnexts.cpp | 2 +- source/build/include/animvpx.h | 5 +- source/build/include/build.h | 6 +- source/build/include/compat.h | 452 +------------------------------ source/build/include/polymost.h | 2 +- source/build/src/animvpx.cpp | 10 +- source/build/src/clip.cpp | 2 +- source/build/src/defs.cpp | 2 +- source/build/src/engine.cpp | 18 +- source/build/src/mdsprite.cpp | 2 +- source/build/src/mhk.cpp | 2 +- source/build/src/polymost.cpp | 8 +- source/build/src/voxmodel.cpp | 4 +- source/core/searchpaths.cpp | 2 +- source/exhumed/src/view.cpp | 8 +- source/games/duke/src/d_menu.cpp | 5 - source/sw/src/game.h | 16 +- 18 files changed, 50 insertions(+), 497 deletions(-) diff --git a/source/blood/src/actor.cpp b/source/blood/src/actor.cpp index 54b718caa..d2cfd4e54 100644 --- a/source/blood/src/actor.cpp +++ b/source/blood/src/actor.cpp @@ -5097,7 +5097,6 @@ int MoveMissile(spritetype *pSprite) if (pTarget->statnum == kStatDude && pXTarget && pXTarget->health > 0) { int nTargetAngle = getangle(-(pTarget->y-pSprite->y), pTarget->x-pSprite->x); - int UNUSED(nAngle) = getangle(xvel[nSprite]>>12,yvel[nSprite]>>12); int vx = missileInfo[pSprite->type - kMissileBase].velocity; int vy = 0; RotatePoint(&vx, &vy, (nTargetAngle+1536)&2047, 0, 0); diff --git a/source/blood/src/nnexts.cpp b/source/blood/src/nnexts.cpp index fe4ad0265..49d7ac83f 100644 --- a/source/blood/src/nnexts.cpp +++ b/source/blood/src/nnexts.cpp @@ -2500,7 +2500,7 @@ bool condCmpb(int val, int arg1, int arg2, int comOp) { void condError(XSPRITE* pXCond, const char* pzFormat, ...) { char buffer[256]; char buffer2[512]; - Bsprintf(buffer, "\nCONDITION RX: %d, TX: %d, SPRITE: #%d RETURNS:\n----------\n\n", pXCond->rxID, pXCond->txID, pXCond->reference); + sprintf(buffer, "\nCONDITION RX: %d, TX: %d, SPRITE: #%d RETURNS:\n----------\n\n", pXCond->rxID, pXCond->txID, pXCond->reference); va_list args; va_start(args, pzFormat); vsprintf(buffer2, pzFormat, args); diff --git a/source/build/include/animvpx.h b/source/build/include/animvpx.h index 1aa98eebf..b6fc2cbbd 100644 --- a/source/build/include/animvpx.h +++ b/source/build/include/animvpx.h @@ -7,7 +7,6 @@ #define VPX_CODEC_DISABLE_COMPAT 1 #ifndef ANIMVPX_STANDALONE -# undef UNUSED # include //#include #endif @@ -93,14 +92,14 @@ void animvpx_print_stats(const animvpx_codec_ctx *codec); static inline int32_t animvpx_check_header(const animvpx_ivf_header_t *hdr) { - if (Bmemcmp(hdr->magic,"DKIF",4)) + if (memcmp(hdr->magic,"DKIF",4)) return 2; // "not an IVF file" if (hdr->version != 0) return 3; // "unrecognized IVF version" // fourcc is left as-is - if (Bmemcmp(hdr->fourcc, "VP80", 4)) + if (memcmp(hdr->fourcc, "VP80", 4)) return 4; // "only VP8 supported" return 0; diff --git a/source/build/include/build.h b/source/build/include/build.h index 172874b1b..aa8e69a0d 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -741,10 +741,10 @@ int32_t krand(void); #endif int32_t ksqrt(uint32_t num); -int32_t __fastcall getangle(int32_t xvect, int32_t yvect); -fix16_t __fastcall gethiq16angle(int32_t xvect, int32_t yvect); +int32_t getangle(int32_t xvect, int32_t yvect); +fix16_t gethiq16angle(int32_t xvect, int32_t yvect); -static FORCE_INLINE fix16_t __fastcall getq16angle(int32_t xvect, int32_t yvect) +static FORCE_INLINE fix16_t getq16angle(int32_t xvect, int32_t yvect) { return fix16_from_int(getangle(xvect, yvect)); } diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 0fc877251..57402b239 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -10,6 +10,7 @@ #include "xs_Float.h" #include "m_alloc.h" #include "intvec.h" +#include "m_swap.h" ////////// Compiler detection ////////// @@ -95,26 +96,12 @@ # endif #endif -#ifdef __GNUC__ -# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) -# define PRINTF_FORMAT(stringindex, firstargindex) __attribute__((format (printf, stringindex, firstargindex))) -#else -# define UNUSED(x) x -# define PRINTF_FORMAT(stringindex, firstargindex) -#endif - #if defined __GNUC__ || defined __clang__ # define ATTRIBUTE(attrlist) __attribute__(attrlist) #else # define ATTRIBUTE(attrlist) #endif -#if !defined __clang__ && !defined USING_LTO -# define ATTRIBUTE_OPTIMIZE(str) ATTRIBUTE((optimize(str))) -#else -# define ATTRIBUTE_OPTIMIZE(str) -#endif - #if EDUKE32_GCC_PREREQ(4,0) # define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #else @@ -145,39 +132,13 @@ # endif #endif -#ifndef _MSC_VER -# ifndef __fastcall -# if defined(__GNUC__) && defined(__i386__) -# define __fastcall __attribute__((fastcall)) -# else -# define __fastcall -# endif -# endif -#endif - -#ifndef DISABLE_INLINING -# define EXTERN_INLINE static inline -# define EXTERN_INLINE_HEADER static inline -#else -# define EXTERN_INLINE __fastcall -# define EXTERN_INLINE_HEADER extern __fastcall -#endif #if 0 && defined(__OPTIMIZE__) && (defined __GNUC__ || __has_builtin(__builtin_expect)) -#define EDUKE32_PREDICT_TRUE(x) __builtin_expect(!!(x),1) #define EDUKE32_PREDICT_FALSE(x) __builtin_expect(!!(x),0) #else -#define EDUKE32_PREDICT_TRUE(x) (x) #define EDUKE32_PREDICT_FALSE(x) (x) #endif -#if EDUKE32_GCC_PREREQ(4,5) || __has_builtin(__builtin_unreachable) -#define EDUKE32_UNREACHABLE_SECTION(...) __builtin_unreachable() -#elif _MSC_VER -#define EDUKE32_UNREACHABLE_SECTION(...) __assume(0) -#else -#define EDUKE32_UNREACHABLE_SECTION(...) __VA_ARGS__ -#endif #if EDUKE32_GCC_PREREQ(2,0) || defined _MSC_VER # define EDUKE32_FUNCTION __FUNCTION__ @@ -257,111 +218,15 @@ #endif -////////// Platform detection ////////// - -#if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __bsdi__ || defined __DragonFly__ -# define EDUKE32_BSD -#endif - -#ifdef __APPLE__ -# include -# if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR -# define EDUKE32_IOS -# else -# define EDUKE32_OSX -# endif -#endif - ////////// Architecture detection ////////// -#if defined _LP64 || defined __LP64__ || defined __64BIT__ || _ADDR64 || defined _WIN64 || defined __arch64__ || \ -__WORDSIZE == 64 || (defined __sparc && defined __sparcv9) || defined __x86_64 || defined __amd64 || \ -defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_IA64 || defined __ia64 || defined __IA64__ - -# define BITNESS64 - -#endif - -#if defined(__linux) -# include -# if __BYTE_ORDER == __LITTLE_ENDIAN -# define B_LITTLE_ENDIAN 1 -# define B_BIG_ENDIAN 0 -# elif __BYTE_ORDER == __BIG_ENDIAN +#ifdef WORDS_BIGENDIAN # define B_LITTLE_ENDIAN 0 # define B_BIG_ENDIAN 1 -# endif - -#elif defined(GEKKO) || defined(__ANDROID__) -# define B_LITTLE_ENDIAN 0 -# define B_BIG_ENDIAN 1 - -#elif defined(__OpenBSD__) -# include -# if _BYTE_ORDER == _LITTLE_ENDIAN +#else # define B_LITTLE_ENDIAN 1 # define B_BIG_ENDIAN 0 -# elif _BYTE_ORDER == _BIG_ENDIAN -# define B_LITTLE_ENDIAN 0 -# define B_BIG_ENDIAN 1 -# endif - -#elif defined EDUKE32_BSD -# include -# if _BYTE_ORDER == _LITTLE_ENDIAN -# define B_LITTLE_ENDIAN 1 -# define B_BIG_ENDIAN 0 -# elif _BYTE_ORDER == _BIG_ENDIAN -# define B_LITTLE_ENDIAN 0 -# define B_BIG_ENDIAN 1 -# endif - -#elif defined(__APPLE__) -# if defined(__LITTLE_ENDIAN__) -# define B_LITTLE_ENDIAN 1 -# define B_BIG_ENDIAN 0 -# elif defined(__BIG_ENDIAN__) -# define B_LITTLE_ENDIAN 0 -# define B_BIG_ENDIAN 1 -# endif -# include - -#elif defined(__BEOS__) -# include -# if LITTLE_ENDIAN != 0 -# define B_LITTLE_ENDIAN 1 -# define B_BIG_ENDIAN 0 -# elif BIG_ENDIAN != 0 -# define B_LITTLE_ENDIAN 0 -# define B_BIG_ENDIAN 1 -# endif - -#elif defined(__QNX__) -# if defined __LITTLEENDIAN__ -# define B_LITTLE_ENDIAN 1 -# define B_BIG_ENDIAN 0 -# elif defined __BIGENDIAN__ -# define B_LITTLE_ENDIAN 0 -# define B_BIG_ENDIAN 1 -# endif - -#elif defined(__sun) -# if defined _LITTLE_ENDIAN -# define B_LITTLE_ENDIAN 1 -# define B_BIG_ENDIAN 0 -# elif defined _BIG_ENDIAN -# define B_LITTLE_ENDIAN 0 -# define B_BIG_ENDIAN 1 -# endif - -#elif defined(_WIN32) || defined(SKYOS) || defined(__SYLLABLE__) -# define B_LITTLE_ENDIAN 1 -# define B_BIG_ENDIAN 0 -#endif - -#if !defined(B_LITTLE_ENDIAN) || !defined(B_BIG_ENDIAN) -# error Unknown endianness #endif @@ -437,26 +302,13 @@ defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_IA64 || ////////// DEPRECATED: Standard library prefixing ////////// -#ifdef _MSC_VER -# if defined _M_AMD64 || defined _M_ARM64 || defined _M_X64 || defined _WIN64 -typedef int64_t ssize_t; -# else -typedef int32_t ssize_t; -# endif -#endif +typedef intptr_t ssize_t; typedef size_t bsize_t; typedef ssize_t bssize_t; #define BMAX_PATH 256 -#define Bassert assert -#define Brand rand -#define Balloca alloca -#define Bmalloc malloc -#define Bcalloc calloc -#define Brealloc realloc - #define Bstrcpy strcpy #define Bstrncpy strncpy #define Bstrcmp strcmp @@ -470,15 +322,8 @@ typedef ssize_t bssize_t; #define Bstrtoul strtoul #define Bstrtod strtod #define Bstrstr strstr -#define Bislower islower -#define Bisupper isupper -#define Bisdigit isdigit -#define Btoupper toupper -#define Btolower tolower #define Bmemcpy memcpy #define Bmemset memset -#define Bmemcmp memcmp -#define Bsprintf sprintf ////////// Standard library wrappers ////////// @@ -510,121 +355,18 @@ static inline int Blrintf(const double x) # define Bsqrtf sqrtf #endif -inline void Bexit(int a) -{ - throw CExitEvent(a); -} - - -////////// Standard library monkey patching ////////// - -#ifndef NULL -# define NULL ((void *)0) -#endif - -#ifndef O_BINARY -# define O_BINARY 0 -#endif -#ifndef O_TEXT -# define O_TEXT 0 -#endif - -#ifndef F_OK -# define F_OK 0 -#endif - ////////// Metaprogramming structs ////////// -#ifdef __cplusplus - -# ifdef HAVE_CXX11_HEADERS -using std::is_integral; -template -struct is_signed -{ - static constexpr bool value = std::is_signed::value; -}; -template -struct is_unsigned -{ - static constexpr bool value = std::is_unsigned::value; -}; -# endif - # if CXXSTD >= 2014 using std::enable_if_t; -using std::conditional_t; -using std::make_signed_t; -using std::make_unsigned_t; -using std::remove_pointer_t; # elif defined HAVE_CXX11_HEADERS template using enable_if_t = typename std::enable_if::type; -template -using conditional_t = typename std::conditional::type; -template -using make_signed_t = typename std::make_signed::type; -template -using make_unsigned_t = typename std::make_unsigned::type; -template -using remove_pointer_t = typename std::remove_pointer::type; # endif -# ifdef HAVE_CXX11_HEADERS -template -using take_sign_t = conditional_t< is_signed::value, make_signed_t, make_unsigned_t >; -# endif -template -struct integers_of_size { }; -template <> -struct integers_of_size -{ - typedef int8_t i; - typedef uint8_t u; -}; -template <> -struct integers_of_size -{ - typedef int16_t i; - typedef uint16_t u; -}; -template <> -struct integers_of_size -{ - typedef int32_t i; - typedef uint32_t u; -}; -template <> -struct integers_of_size -{ - typedef int64_t i; - typedef uint64_t u; -}; - -#endif - - -////////// Typedefs ////////// - -#if defined(__x86_64__) -// for 32-bit pointers in x86_64 code, such as `gcc -mx32` -typedef uint64_t reg_t; -typedef int64_t sreg_t; -#else -typedef size_t reg_t; -typedef ssize_t sreg_t; -#endif - -#ifdef HAVE_CXX11_HEADERS -using native_t = typename integers_of_size::i; -using unative_t = typename integers_of_size::u; -#else -typedef sreg_t native_t; -typedef reg_t unative_t; -#endif -EDUKE32_STATIC_ASSERT(sizeof(native_t) == sizeof(unative_t)); +using native_t = intptr_t; typedef struct MAY_ALIAS { int32_t x, y; @@ -677,49 +419,14 @@ typedef struct { EDUKE32_STATIC_ASSERT(sizeof(vec3d_t) == sizeof(double) * 3); -typedef struct { - float x, y, z, w; -} vec4f_t; - -typedef struct { - float x, y, z, w; -} vec4d_t; - ////////// Language tricks that depend on size_t ////////// #include "basics.h" # define ARRAY_SIZE(arr) countof(arr) -#define ARRAY_SSIZE(arr) (native_t)ARRAY_SIZE(arr) -////////// Memory management ////////// - -#if !defined NO_ALIGNED_MALLOC -static FORCE_INLINE void *Baligned_alloc(const size_t alignment, const size_t size) -{ -#ifdef _WIN32 - void *ptr = _aligned_malloc(size, alignment); -#elif defined __APPLE__ || defined EDUKE32_BSD - void *ptr = NULL; - posix_memalign(&ptr, alignment, size); -#else - void *ptr = memalign(alignment, size); -#endif - - return ptr; -} -#else -# define Baligned_alloc(alignment, size) Bmalloc(size) -#endif - -#if defined _WIN32 && !defined NO_ALIGNED_MALLOC -# define Baligned_free _aligned_free -#else -# define Baligned_free free -#endif - ////////// Pointer management ////////// @@ -727,106 +434,18 @@ static FORCE_INLINE void *Baligned_alloc(const size_t alignment, const size_t si Xfree(var); (var) = NULL; \ } while (0) -#define ALIGNED_FREE_AND_NULL(var) do { \ - Xaligned_free(var); (var) = NULL; \ -} while (0) - ////////// Data serialization ////////// -static FORCE_INLINE CONSTEXPR uint16_t B_SWAP16_impl(uint16_t value) -{ - return - ((value & 0xFF00u) >> 8u) | - ((value & 0x00FFu) << 8u); -} -static FORCE_INLINE CONSTEXPR uint32_t B_SWAP32_impl(uint32_t value) -{ - return - ((value & 0xFF000000u) >> 24u) | - ((value & 0x00FF0000u) >> 8u) | - ((value & 0x0000FF00u) << 8u) | - ((value & 0x000000FFu) << 24u); -} -static FORCE_INLINE CONSTEXPR uint64_t B_SWAP64_impl(uint64_t value) -{ - return - ((value & 0xFF00000000000000ULL) >> 56ULL) | - ((value & 0x00FF000000000000ULL) >> 40ULL) | - ((value & 0x0000FF0000000000ULL) >> 24ULL) | - ((value & 0x000000FF00000000ULL) >> 8ULL) | - ((value & 0x00000000FF000000ULL) << 8ULL) | - ((value & 0x0000000000FF0000ULL) << 24ULL) | - ((value & 0x000000000000FF00ULL) << 40ULL) | - ((value & 0x00000000000000FFULL) << 56ULL); -} +inline int32_t B_LITTLE32(int32_t val) { return LittleLong(val); } +inline uint32_t B_LITTLE32(uint32_t val) { return LittleLong(val); } +inline int32_t B_LITTLE16(int16_t val) { return LittleShort(val); } +inline uint32_t B_LITTLE16(uint16_t val) { return LittleShort(val); } -/* The purpose of B_PASS* as functions, as opposed to macros, is to prevent them from being used as lvalues. */ -#if CXXSTD >= 2011 || EDUKE32_MSVC_PREREQ(1900) -template -static FORCE_INLINE CONSTEXPR take_sign_t B_SWAP16(T x) -{ - return static_cast< take_sign_t >(B_SWAP16_impl(static_cast(x))); -} -template -static FORCE_INLINE CONSTEXPR take_sign_t B_SWAP32(T x) -{ - return static_cast< take_sign_t >(B_SWAP32_impl(static_cast(x))); -} -template -static FORCE_INLINE CONSTEXPR take_sign_t B_SWAP64(T x) -{ - return static_cast< take_sign_t >(B_SWAP64_impl(static_cast(x))); -} - -template -static FORCE_INLINE CONSTEXPR take_sign_t B_PASS16(T x) -{ - return static_cast< take_sign_t >(x); -} -template -static FORCE_INLINE CONSTEXPR take_sign_t B_PASS32(T x) -{ - return static_cast< take_sign_t >(x); -} -template -static FORCE_INLINE CONSTEXPR take_sign_t B_PASS64(T x) -{ - return static_cast< take_sign_t >(x); -} -#else -#define B_SWAP16(x) B_SWAP16_impl(x) -#define B_SWAP32(x) B_SWAP32_impl(x) -#define B_SWAP64(x) B_SWAP64_impl(x) - -static FORCE_INLINE CONSTEXPR uint16_t B_PASS16(uint16_t const x) { return x; } -static FORCE_INLINE CONSTEXPR uint32_t B_PASS32(uint32_t const x) { return x; } -static FORCE_INLINE CONSTEXPR uint64_t B_PASS64(uint64_t const x) { return x; } -#endif - -#if B_LITTLE_ENDIAN == 1 -# define B_LITTLE64(x) B_PASS64(x) -# define B_BIG64(x) B_SWAP64(x) -# define B_LITTLE32(x) B_PASS32(x) -# define B_BIG32(x) B_SWAP32(x) -# define B_LITTLE16(x) B_PASS16(x) -# define B_BIG16(x) B_SWAP16(x) -#elif B_BIG_ENDIAN == 1 -# define B_LITTLE64(x) B_SWAP64(x) -# define B_BIG64(x) B_PASS64(x) -# define B_LITTLE32(x) B_SWAP32(x) -# define B_BIG32(x) B_PASS32(x) -# define B_LITTLE16(x) B_SWAP16(x) -# define B_BIG16(x) B_PASS16(x) -#endif - -static FORCE_INLINE void B_BUF16(void * const buf, uint16_t const x) { *(uint16_t *) buf = x; } static FORCE_INLINE void B_BUF32(void * const buf, uint32_t const x) { *(uint32_t *) buf = x; } -static FORCE_INLINE void B_BUF64(void * const buf, uint64_t const x) { *(uint64_t *) buf = x; } - -static FORCE_INLINE CONSTEXPR uint16_t B_UNBUF16(void const * const buf) { return *(uint16_t const *) buf; } static FORCE_INLINE CONSTEXPR uint32_t B_UNBUF32(void const * const buf) { return *(uint32_t const *) buf; } -static FORCE_INLINE CONSTEXPR uint64_t B_UNBUF64(void const * const buf) { return *(uint64_t const *) buf; } +static FORCE_INLINE CONSTEXPR uint16_t B_UNBUF16(void const * const buf) { return *(uint16_t const *) buf; } + ////////// Abstract data operations ////////// @@ -838,52 +457,6 @@ template ABSTRACT_DECL T clamp2(T in, X min using std::min; using std::max; -////////// Mathematical operations ////////// - -#ifdef __cplusplus -#ifdef HAVE_CXX11_HEADERS -template -struct DivResult -{ - T q; // quotient - T r; // remainder -}; -template -FORCE_INLINE CONSTEXPR DivResult divide(T lhs, T rhs) -{ - return DivResult{(T)(lhs / rhs), (T)(lhs % rhs)}; -} -template -FORCE_INLINE CONSTEXPR DivResult divrhs(T lhs) -{ - return divide(lhs, (T)base); -} - -template -static FORCE_INLINE CONSTEXPR_CXX14 enable_if_t::value, T> NEGATE_ON_CONDITION(T value, T2 condition) -{ - T const invert = !!condition; - return (value ^ -invert) + invert; -} -#endif - -template -CONSTEXPR size_t logbase(T n) -{ - return n < static_cast(base) ? 1 : 1 + logbase(n / static_cast(base)); -} -// hackish version to work around the impossibility of representing abs(INT*_MIN) -template -CONSTEXPR size_t logbasenegative(T n) -{ - return n > static_cast(-(native_t)base) ? 1 : 1 + logbase(n / static_cast(-(native_t)base)); -} - -#endif - -#define isPow2OrZero(v) (((v) & ((v) - 1)) == 0) -#define isPow2(v) (isPow2OrZero(v) && (v)) - ////////// Bitfield manipulation ////////// #if 0 @@ -941,10 +514,7 @@ static FORCE_INLINE char *Bstrncpyz(char *dst, const char *src, bsize_t n) #define Xmalloc(size) (M_Malloc(size)) #define Xcalloc(nmemb, size) (M_Calloc(nmemb, size)) #define Xrealloc(ptr, size) (M_Realloc(ptr, size)) -#define Xaligned_alloc(alignment, size) (M_Malloc(size)) -#define Xaligned_calloc(alignment, count, size) (M_Calloc(count, size)) #define Xfree(ptr) (M_Free(ptr)) -#define Xaligned_free(ptr) (M_Free(ptr)) ////////// Inlined external libraries ////////// diff --git a/source/build/include/polymost.h b/source/build/include/polymost.h index b981c149a..e183bbbe1 100644 --- a/source/build/include/polymost.h +++ b/source/build/include/polymost.h @@ -71,7 +71,7 @@ static FORCE_INLINE int check_nonpow2(int32_t const x) static inline float polymost_invsqrt_approximation(float x) { -#ifdef B_LITTLE_ENDIAN +#if !B_BIG_ENDIAN float const haf = x * .5f; union { float f; uint32_t i; } n = { x }; n.i = 0x5f375a86 - (n.i >> 1); diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index 55e7492e5..b953221e8 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -48,8 +48,8 @@ int32_t animvpx_read_ivf_header(FileReader & inhandle, animvpx_ivf_header_t *hdr hdr->width = B_LITTLE16(hdr->width); hdr->height = B_LITTLE16(hdr->height); - hdr->fpsnumer = B_LITTLE16(hdr->fpsnumer); - hdr->fpsdenom = B_LITTLE16(hdr->fpsdenom); + hdr->fpsnumer = B_LITTLE32(hdr->fpsnumer); + hdr->fpsdenom = B_LITTLE32(hdr->fpsdenom); hdr->numframes = B_LITTLE32(hdr->numframes); @@ -209,11 +209,7 @@ const char *animvpx_nextpic_errmsg[] = { // retrieves one picture-frame from the stream // pic format: lines of [Y U V 0] pixels // *picptr==NULL means EOF has been reached -#ifdef DEBUGGINGAIDS -ATTRIBUTE_OPTIMIZE("O1") -#else -ATTRIBUTE_OPTIMIZE("O3") -#endif + int32_t animvpx_nextpic(animvpx_codec_ctx *codec, uint8_t **picptr) { int32_t ret, corrupted; diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index d54587e64..451d31bc4 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -206,7 +206,7 @@ int32_t getflorzofslope_old(int32_t sectnum, int32_t dax, int32_t day) // Returns: should clip? static int cliptestsector(int const dasect, int const nextsect, int32_t const flordist, int32_t const ceildist, vec2_t const pos, int32_t const posz) { - Bassert((unsigned)dasect < (unsigned)numsectors && (unsigned)nextsect < (unsigned)numsectors); + assert((unsigned)dasect < (unsigned)numsectors && (unsigned)nextsect < (unsigned)numsectors); auto const sec2 = (usectorptr_t)§or[nextsect]; diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 5c68b5f50..cc39e3205 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -2032,7 +2032,7 @@ static int32_t defsparser(scriptfile *script) { char msgend[BMAX_PATH+64]; - Bsprintf(msgend, "for palookup definition near line %s:%d", + sprintf(msgend, "for palookup definition near line %s:%d", script->filename, scriptfile_getlinum(script,starttokptr)); if (EDUKE32_PREDICT_FALSE((havepal & HAVE_PAL)==0)) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 082bfb570..0ac5ef87e 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -740,7 +740,7 @@ int32_t insertsprite(int16_t sectnum, int16_t statnum) if (newspritenum >= 0) { - Bassert((unsigned)sectnum < MAXSECTORS); + assert((unsigned)sectnum < MAXSECTORS); do_insertsprite_at_headofsect(newspritenum, sectnum); Numsprites++; @@ -760,7 +760,7 @@ int32_t deletesprite(int16_t spritenum) polymost_deletesprite(spritenum); if (deletesprite_replace) return deletesprite_replace(spritenum); - Bassert((sprite[spritenum].statnum == MAXSTATUS) + assert((sprite[spritenum].statnum == MAXSTATUS) == (sprite[spritenum].sectnum == MAXSECTORS)); if (sprite[spritenum].statnum == MAXSTATUS) @@ -988,7 +988,7 @@ int32_t rintersect(int32_t x1, int32_t y1, int32_t z1, t = (topu<<16) / bot; - Bassert((unsigned)t < 65536); + assert((unsigned)t < 65536); return t; } @@ -1304,7 +1304,7 @@ int32_t renderDrawRoomsQ16(int32_t daposx, int32_t daposy, int32_t daposz, auto owner = w.picnum + animateoffs(w.picnum, 16384); tile.newtile = TileFiles.tileCreateRotated(owner); - Bassert(tile.newtile != -1); + assert(tile.newtile != -1); RotTile(tile.newtile).owner = w.picnum+animateoffs(w.picnum,16384); @@ -2218,7 +2218,7 @@ static int32_t engineFinishLoadBoard(const vec3_t *dapos, int16_t *dacursectnum, numremoved = (numsprites-realnumsprites); numsprites = realnumsprites; - Bassert(numsprites == Numsprites); + assert(numsprites == Numsprites); //Must be after loading sectors, etc! updatesector(dapos->x, dapos->y, dacursectnum); @@ -2334,7 +2334,7 @@ int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t #ifdef NEW_MAP_FORMAT // Check for map-text first. - if (!Bmemcmp(&mapversion, "--ED", 4)) + if (!memcmp(&mapversion, "--ED", 4)) { mapversion = 10; ok = 1; @@ -2466,8 +2466,6 @@ int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t artSetupMapArt(filename); } - // Printf("Loaded map \"%s\" (md4sum: %08x%08x%08x%08x)\n", filename, B_BIG32(*((int32_t*)&md4out[0])), B_BIG32(*((int32_t*)&md4out[4])), B_BIG32(*((int32_t*)&md4out[8])), B_BIG32(*((int32_t*)&md4out[12]))); - return engineFinishLoadBoard(dapos, dacursectnum, numsprites, myflags); } @@ -2913,7 +2911,7 @@ int32_t inside(int32_t x, int32_t y, int16_t sectnum) return -1; } -int32_t __fastcall getangle(int32_t xvect, int32_t yvect) +int32_t getangle(int32_t xvect, int32_t yvect) { int32_t rv; @@ -2934,7 +2932,7 @@ int32_t __fastcall getangle(int32_t xvect, int32_t yvect) return rv; } -fix16_t __fastcall gethiq16angle(int32_t xvect, int32_t yvect) +fix16_t gethiq16angle(int32_t xvect, int32_t yvect) { fix16_t rv; diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 9e48ce9c8..ed569f028 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -990,7 +990,7 @@ static md3model_t *md3load(FileReader & fil) // NOTE: We assume that NULL is represented by all-zeros. // surfs[0].geometry is for POLYMER_MD_PROCESS_CHECK (else: crashes). // surfs[i].geometry is for FREE_SURFS_GEOMETRY. - Bassert(m->head.surfs[0].geometry == NULL); + assert(m->head.surfs[0].geometry == NULL); #if B_BIG_ENDIAN != 0 { diff --git a/source/build/src/mhk.cpp b/source/build/src/mhk.cpp index 4f54b9cff..2ae88bbb9 100644 --- a/source/build/src/mhk.cpp +++ b/source/build/src/mhk.cpp @@ -8,7 +8,7 @@ usermaphack_t g_loadedMapHack; // used only for the MD4 part int compare_usermaphacks(const void *a, const void *b) { - return Bmemcmp(((usermaphack_t const *) a)->md4, ((usermaphack_t const *) b)->md4, 16); + return memcmp(((usermaphack_t const *) a)->md4, ((usermaphack_t const *) b)->md4, 16); } usermaphack_t *usermaphacks; int32_t num_usermaphacks; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index cbbe944c5..f65220c0a 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -305,7 +305,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 setgotpic(globalpicnum); vec2_t tsiz = { tilesize.x, tilesize.y }; - Bassert(n <= MAX_DRAWPOLY_VERTS); + assert(n <= MAX_DRAWPOLY_VERTS); int j = 0; float px[8], py[8], dd[8], uu[8], vv[8]; @@ -2058,7 +2058,7 @@ static void polymost_drawalls(int32_t const bunch) float const ogux = xtex.u, oguy = ytex.u, oguo = otex.u; - Bassert(domostpolymethod == DAMETH_NOMASK); + assert(domostpolymethod == DAMETH_NOMASK); domostpolymethod = DAMETH_WALL; if (nextsectnum >= 0) @@ -2269,7 +2269,7 @@ void polymost_scansector(int32_t sectnum) int const nextsectnum = wal->nextsector; //Scan close sectors - if (nextsectnum >= 0 && !(wal->cstat&32) && sectorbordercnt < ARRAY_SSIZE(sectorborder)) + if (nextsectnum >= 0 && !(wal->cstat&32) && sectorbordercnt < countof(sectorborder)) if ((gotsector[nextsectnum>>3]&pow2char[nextsectnum&7]) == 0) { double const d = fp1.x*fp2.y - fp2.x*fp1.y; @@ -2584,7 +2584,7 @@ void polymost_drawrooms() maskwallcnt = 0; // NOTE: globalcursectnum has been already adjusted in ADJUST_GLOBALCURSECTNUM. - Bassert((unsigned)globalcursectnum < MAXSECTORS); + assert((unsigned)globalcursectnum < MAXSECTORS); polymost_scansector(globalcursectnum); grhalfxdown10x = grhalfxdown10; diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index bf63aa450..3c9b41f05 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -614,7 +614,7 @@ static void read_pal(FileReader &fil, int32_t pal[256]) char c[3]; fil.Read(c, 3); //#if B_BIG_ENDIAN != 0 - pal[i] = B_LITTLE32((c[0]<<18) + (c[1]<<10) + (c[2]<<2) + (i<<24)); + pal[i] = B_LITTLE32(unsigned((c[0]<<18) + (c[1]<<10) + (c[2]<<2) + (i<<24))); //#endif } } @@ -942,7 +942,7 @@ voxmodel_t *loadkvxfrombuf(const char *kvxbuffer, int32_t length) { const char *c = &paloff[i*3]; //#if B_BIG_ENDIAN != 0 - pal[i] = B_LITTLE32((c[0]<<18) + (c[1]<<10) + (c[2]<<2) + (i<<24)); + pal[i] = B_LITTLE32(int((c[0]<<18) + (c[1]<<10) + (c[2]<<2) + (i<<24))); //#endif } diff --git a/source/core/searchpaths.cpp b/source/core/searchpaths.cpp index 3df95fb39..45e37d276 100644 --- a/source/core/searchpaths.cpp +++ b/source/core/searchpaths.cpp @@ -955,7 +955,7 @@ bool AddINIFile(const char* pzFile, bool bForce = false) pINIIter->pNext = NULL; pINIIter->pDescription = NULL; Bstrncpy(pINIIter->zName, pzFile, BMAX_PATH); - for (int i = 0; i < ARRAY_SSIZE(gINIDescription); i++) + for (int i = 0; i < countof(gINIDescription); i++) { if (!Bstrncasecmp(pINIIter->zName, gINIDescription[i].pzFilename, BMAX_PATH)) { diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index 29c7e05dc..6f9deb888 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -71,7 +71,7 @@ int viewSetInterpolation(int32_t *const posptr) if (g_interpolationCnt >= MAXINTERPOLATIONS) return 1; - for (bssize_t i = 0; i < g_interpolationCnt; ++i) + for (int i = 0; i < g_interpolationCnt; ++i) if (curipos[i] == posptr) return 0; @@ -83,7 +83,7 @@ int viewSetInterpolation(int32_t *const posptr) void viewStopInterpolation(const int32_t * const posptr) { - for (bssize_t i = 0; i < g_interpolationCnt; ++i) + for (int i = 0; i < g_interpolationCnt; ++i) if (curipos[i] == posptr) { g_interpolationCnt--; @@ -97,7 +97,7 @@ void viewDoInterpolations(int smoothRatio) { int32_t ndelta = 0; - for (bssize_t i = 0, j = 0; i < g_interpolationCnt; ++i) + for (int i = 0, j = 0; i < g_interpolationCnt; ++i) { int32_t const odelta = ndelta; bakipos[i] = *curipos[i]; @@ -110,7 +110,7 @@ void viewDoInterpolations(int smoothRatio) void viewUpdateInterpolations(void) //Stick at beginning of G_DoMoveThings { - for (bssize_t i=g_interpolationCnt-1; i>=0; i--) oldipos[i] = *curipos[i]; + for (int i=g_interpolationCnt-1; i>=0; i--) oldipos[i] = *curipos[i]; } void viewRestoreInterpolations(void) //Stick at end of drawscreen diff --git a/source/games/duke/src/d_menu.cpp b/source/games/duke/src/d_menu.cpp index 172fdb4aa..78d5fdb4e 100644 --- a/source/games/duke/src/d_menu.cpp +++ b/source/games/duke/src/d_menu.cpp @@ -341,11 +341,6 @@ void GameInterface::DrawCenteredTextScreen(const DVector2 &origin, const char *t ::GameInterface::DrawCenteredTextScreen(origin, text, position, bg); } -static int GetPlayerColor(int color) -{ - return 0; -} - void GameInterface::DrawPlayerSprite(const DVector2& origin, bool onteam) { int mclock = I_GetBuildTime(); diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 0d350cedc..ebc20f54b 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -230,15 +230,11 @@ extern SWBOOL MenuInputMode; #define MK_FIXED(msw,lsw) (((int32_t)(msw)<<16)|(lsw)) #define FIXED(msw,lsw) MK_FIXED(msw,lsw) -#if B_LITTLE_ENDIAN != 0 -# define MSW_VAR(fixed) (*(((uint16_t*)&(fixed)) + 1)) -# define LSW_VAR(fixed) (*((uint16_t*)&(fixed))) - +// Ouch... +#if B_BIG_ENDIAN == 0 # define MSB_VAR(fixed) (*(((uint8_t*)&(fixed)) + 1)) # define LSB_VAR(fixed) (*((uint8_t*)&(fixed))) #else -# define LSW_VAR(fixed) (*(((uint16_t*)&(fixed)) + 1)) -# define MSW_VAR(fixed) (*((uint16_t*)&(fixed))) # define LSB_VAR(fixed) (*(((uint8_t*)&(fixed)) + 1)) # define MSB_VAR(fixed) (*((uint8_t*)&(fixed))) @@ -263,8 +259,8 @@ extern SWBOOL MenuInputMode; #define SP_TAG13(sp) B_LITTLE16(*((short*)&(sp)->xoffset)) #define SP_TAG14(sp) B_LITTLE16(*((short*)&(sp)->xrepeat)) #define SP_TAG15(sp) ((sp)->z) -#define SET_SP_TAG13(sp,val) (*((short*)&(sp)->xoffset)) = B_LITTLE16(val) -#define SET_SP_TAG14(sp,val) (*((short*)&(sp)->xrepeat)) = B_LITTLE16(val) +#define SET_SP_TAG13(sp,val) (*((short*)&(sp)->xoffset)) = B_LITTLE16((short)val) +#define SET_SP_TAG14(sp,val) (*((short*)&(sp)->xrepeat)) = B_LITTLE16((short)val) #define SPRITE_TAG1(sp) (sprite[sp].hitag) #define SPRITE_TAG2(sp) (sprite[sp].lotag) @@ -281,8 +277,8 @@ extern SWBOOL MenuInputMode; #define SPRITE_TAG13(sp) B_LITTLE16(*((short*)&sprite[sp].xoffset)) #define SPRITE_TAG14(sp) B_LITTLE16(*((short*)&sprite[sp].xrepeat)) #define SPRITE_TAG15(sp) (sprite[sp].z) -#define SET_SPRITE_TAG13(sp,val) (*((short*)&sprite[sp].xoffset)) = B_LITTLE16(val) -#define SET_SPRITE_TAG14(sp,val) (*((short*)&sprite[sp].xrepeat)) = B_LITTLE16(val) +#define SET_SPRITE_TAG13(sp,val) (*((short*)&sprite[sp].xoffset)) = B_LITTLE16((short)val) +#define SET_SPRITE_TAG14(sp,val) (*((short*)&sprite[sp].xrepeat)) = B_LITTLE16((short)val) // OVER and UNDER water macros #define SpriteInDiveArea(sp) (TEST(sector[(sp)->sectnum].extra, SECTFX_DIVE_AREA) ? TRUE : FALSE)