2006-04-13 20:47:06 +00:00
|
|
|
// Compatibility declarations for things which might not be present in
|
|
|
|
// certain build environments. It also levels the playing field caused
|
|
|
|
// by different platforms.
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#ifndef compat_h_
|
|
|
|
#define compat_h_
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-02-25 08:15:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-01-25 10:56:13 +00:00
|
|
|
#include "xs_Float.h"
|
2020-04-11 21:46:42 +00:00
|
|
|
#include "m_alloc.h"
|
2020-06-20 16:17:49 +00:00
|
|
|
#include "intvec.h"
|
2020-08-30 21:34:40 +00:00
|
|
|
#include "m_swap.h"
|
2020-01-25 10:56:13 +00:00
|
|
|
|
2017-02-25 08:15:16 +00:00
|
|
|
////////// Language and compiler feature polyfills //////////
|
|
|
|
|
|
|
|
# define EXTERNC
|
|
|
|
|
2017-02-25 08:15:13 +00:00
|
|
|
#ifndef UNREFERENCED_PARAMETER
|
|
|
|
# define UNREFERENCED_PARAMETER(x) (x) = (x)
|
2014-11-30 23:18:57 +00:00
|
|
|
#endif
|
2014-10-29 17:05:15 +00:00
|
|
|
|
2010-12-20 16:55:37 +00:00
|
|
|
#if defined __GNUC__ || defined __clang__
|
|
|
|
# define ATTRIBUTE(attrlist) __attribute__(attrlist)
|
|
|
|
#else
|
|
|
|
# define ATTRIBUTE(attrlist)
|
|
|
|
#endif
|
|
|
|
|
2014-11-24 08:19:50 +00:00
|
|
|
|
2018-12-23 23:23:50 +00:00
|
|
|
#ifndef MAY_ALIAS
|
|
|
|
# ifdef _MSC_VER
|
|
|
|
# define MAY_ALIAS
|
|
|
|
# else
|
|
|
|
# define MAY_ALIAS __attribute__((may_alias))
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2017-02-25 08:15:16 +00:00
|
|
|
#ifndef FORCE_INLINE
|
2017-02-25 08:15:53 +00:00
|
|
|
# ifdef _MSC_VER
|
|
|
|
# define FORCE_INLINE __forceinline
|
2015-01-25 12:16:10 +00:00
|
|
|
# else
|
2017-02-25 08:15:16 +00:00
|
|
|
# ifdef __GNUC__
|
2017-02-25 08:15:53 +00:00
|
|
|
# define FORCE_INLINE inline __attribute__((always_inline))
|
2017-02-25 08:15:16 +00:00
|
|
|
# else
|
2017-02-25 08:15:53 +00:00
|
|
|
# define FORCE_INLINE inline
|
2014-11-24 08:19:50 +00:00
|
|
|
# endif
|
2014-10-30 04:59:23 +00:00
|
|
|
# endif
|
2008-02-16 22:27:08 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-23 03:17:29 +00:00
|
|
|
# define fallthrough__ [[fallthrough]]
|
2012-03-18 08:50:41 +00:00
|
|
|
|
2017-02-25 08:15:16 +00:00
|
|
|
////////// Architecture detection //////////
|
|
|
|
|
2020-08-30 21:34:40 +00:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2006-04-13 20:47:06 +00:00
|
|
|
# define B_BIG_ENDIAN 1
|
2020-08-30 21:34:40 +00:00
|
|
|
#else
|
2006-04-13 20:47:06 +00:00
|
|
|
# define B_BIG_ENDIAN 0
|
|
|
|
#endif
|
|
|
|
|
2019-04-18 17:24:22 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdint.h>
|
2006-08-31 01:54:23 +00:00
|
|
|
|
2017-02-25 08:15:36 +00:00
|
|
|
#include <limits.h>
|
2017-02-25 08:15:16 +00:00
|
|
|
#include <stdarg.h>
|
2018-11-18 18:09:48 +00:00
|
|
|
#include <stddef.h>
|
2017-02-25 08:15:16 +00:00
|
|
|
#include <stdio.h>
|
2018-11-18 18:09:48 +00:00
|
|
|
#include <stdlib.h>
|
2017-02-25 08:15:16 +00:00
|
|
|
#include <string.h>
|
2006-08-31 01:54:23 +00:00
|
|
|
|
2019-07-16 09:35:09 +00:00
|
|
|
#if !(defined _WIN32 && defined __clang__)
|
2017-02-25 08:15:36 +00:00
|
|
|
#include <float.h>
|
2019-07-16 09:35:09 +00:00
|
|
|
#endif
|
2018-11-18 18:09:48 +00:00
|
|
|
#include <math.h>
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-02-25 08:15:16 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2018-11-18 18:09:48 +00:00
|
|
|
#include <time.h>
|
2015-05-03 07:03:12 +00:00
|
|
|
|
2017-02-25 08:15:16 +00:00
|
|
|
#include <assert.h>
|
2015-05-03 07:03:48 +00:00
|
|
|
|
2019-07-16 09:35:09 +00:00
|
|
|
# include <limits>
|
2018-10-16 06:09:54 +00:00
|
|
|
# include <algorithm>
|
|
|
|
# include <functional>
|
2017-04-12 08:30:29 +00:00
|
|
|
# include <type_traits>
|
2017-02-25 08:15:16 +00:00
|
|
|
|
|
|
|
////////// Platform headers //////////
|
|
|
|
|
|
|
|
#if !defined __APPLE__ && (!defined EDUKE32_BSD || !__STDC__)
|
|
|
|
# include <malloc.h>
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2020-04-11 21:50:43 +00:00
|
|
|
#include "engineerrors.h"
|
2017-02-25 08:15:16 +00:00
|
|
|
|
2021-03-24 20:13:36 +00:00
|
|
|
typedef intptr_t bssize_t;
|
2017-02-25 08:15:16 +00:00
|
|
|
|
|
|
|
#define BMAX_PATH 256
|
|
|
|
|
2017-04-12 08:30:29 +00:00
|
|
|
////////// Metaprogramming structs //////////
|
|
|
|
|
2020-08-30 21:34:40 +00:00
|
|
|
using native_t = intptr_t;
|
2017-04-12 08:30:32 +00:00
|
|
|
|
2014-12-27 18:36:43 +00:00
|
|
|
typedef struct {
|
|
|
|
float x, y;
|
|
|
|
} vec2f_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-07-24 01:38:05 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
union { float x, d; };
|
|
|
|
union { float y, u; };
|
|
|
|
union { float z, v; };
|
|
|
|
};
|
|
|
|
vec2f_t vec2;
|
|
|
|
};
|
2014-12-27 18:36:43 +00:00
|
|
|
} vec3f_t;
|
|
|
|
|
2020-09-04 19:24:48 +00:00
|
|
|
static_assert(sizeof(vec3f_t) == sizeof(float) * 3);
|
2015-03-24 00:40:33 +00:00
|
|
|
|
2017-02-25 08:16:01 +00:00
|
|
|
////////// Language tricks that depend on size_t //////////
|
|
|
|
|
2019-12-29 15:35:51 +00:00
|
|
|
#include "basics.h"
|
|
|
|
|
2019-05-19 03:52:54 +00:00
|
|
|
////////// Bitfield manipulation //////////
|
|
|
|
|
2020-09-08 16:48:18 +00:00
|
|
|
static FORCE_INLINE void bitmap_set(uint8_t *const ptr, int const n) { ptr[n>>3] |= 1 << (n&7); }
|
|
|
|
static FORCE_INLINE char bitmap_test(uint8_t const *const ptr, int const n) { return ptr[n>>3] & (1 << (n&7)); }
|
2017-04-12 08:30:35 +00:00
|
|
|
|
2017-02-25 08:15:16 +00:00
|
|
|
////////// Utility functions //////////
|
|
|
|
|
2019-05-19 03:52:54 +00:00
|
|
|
// breadth-first search helpers
|
|
|
|
template <typename T>
|
|
|
|
void bfirst_search_init(T *const list, uint8_t *const bitmap, T *const eltnumptr, int const maxelts, int const firstelt)
|
|
|
|
{
|
2020-09-08 16:48:18 +00:00
|
|
|
memset(bitmap, 0, (maxelts+7)>>3);
|
2019-05-19 03:52:54 +00:00
|
|
|
|
|
|
|
list[0] = firstelt;
|
|
|
|
bitmap_set(bitmap, firstelt);
|
|
|
|
*eltnumptr = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void bfirst_search_try(T *const list, uint8_t *const bitmap, T *const eltnumptr, int const elt)
|
|
|
|
{
|
|
|
|
if (!bitmap_test(bitmap, elt))
|
|
|
|
{
|
|
|
|
bitmap_set(bitmap, elt);
|
|
|
|
list[(*eltnumptr)++] = elt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#endif // compat_h_
|