Subversion Repositories eduke32

Rev

Rev 5038 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5038 Rev 5075
Line 557... Line 557...
557
// Clamp <in> to [<min>..<max>]. The case in >= max is handled first.
557
// Clamp <in> to [<min>..<max>]. The case in >= max is handled first.
558
CLAMP_DECL float fclamp2(float in, float min, float max) { return in >= max ? max : (in <= min ? min : in); }
558
CLAMP_DECL float fclamp2(float in, float min, float max) { return in >= max ? max : (in <= min ? min : in); }
559
559
560
#define BMAX_PATH 256
560
#define BMAX_PATH 256
561
561
-
 
562
/* Static assertions, based on source found in LuaJIT's src/lj_def.h. */
-
 
563
#define EDUKE32_ASSERT_NAME2(name, line) name ## line
-
 
564
#define EDUKE32_ASSERT_NAME(line) EDUKE32_ASSERT_NAME2(eduke32_assert_, line)
-
 
565
#ifdef __COUNTER__
-
 
566
# define EDUKE32_STATIC_ASSERT(cond) \
-
 
567
    extern void EDUKE32_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
-
 
568
#else
-
 
569
# define EDUKE32_STATIC_ASSERT(cond) \
-
 
570
    extern void EDUKE32_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
-
 
571
#endif
562
572
563
struct Bdirent
573
struct Bdirent
564
{
574
{
565
    uint16_t namlen;
575
    uint16_t namlen;
566
    char *name;
576
    char *name;
Line 600... Line 610...
600
typedef struct {
610
typedef struct {
601
    float x, y;
611
    float x, y;
602
} vec2f_t;
612
} vec2f_t;
603
613
604
typedef struct {
614
typedef struct {
605
    float x, y, z;
615
    union { float x; float d; };
-
 
616
    union { float y; float u; };
-
 
617
    union { float z; float v; };
606
} vec3f_t;
618
} vec3f_t;
607
619
-
 
620
EDUKE32_STATIC_ASSERT(sizeof(vec3f_t) == sizeof(float) * 3);
-
 
621
-
 
622
typedef struct {
-
 
623
    union { double x; double d; };
-
 
624
    union { double y; double u; };
-
 
625
    union { double z; double v; };
-
 
626
} vec3d_t;
-
 
627
-
 
628
EDUKE32_STATIC_ASSERT(sizeof(vec3d_t) == sizeof(double) * 3);
608
629
609
#if RAND_MAX == 32767
630
#if RAND_MAX == 32767
610
FORCE_INLINE uint16_t system_15bit_rand(void) { return (uint16_t)rand(); }
631
FORCE_INLINE uint16_t system_15bit_rand(void) { return (uint16_t)rand(); }
611
#else  // RAND_MAX > 32767, assumed to be of the form 2^k - 1
632
#else  // RAND_MAX > 32767, assumed to be of the form 2^k - 1
612
FORCE_INLINE uint16_t system_15bit_rand(void) { return ((uint16_t)rand())&0x7fff; }
633
FORCE_INLINE uint16_t system_15bit_rand(void) { return ((uint16_t)rand())&0x7fff; }
Line 890... Line 911...
890
911
891
#define MAYBE_FCLOSE_AND_NULL(fileptr) do { \
912
#define MAYBE_FCLOSE_AND_NULL(fileptr) do { \
892
    if (fileptr) { Bfclose(fileptr); fileptr=NULL; } \
913
    if (fileptr) { Bfclose(fileptr); fileptr=NULL; } \
893
} while (0)
914
} while (0)
894
915
895
/* Static assertions, based on source found in LuaJIT's src/lj_def.h. */
-
 
896
#define EDUKE32_ASSERT_NAME2(name, line) name ## line
-
 
897
#define EDUKE32_ASSERT_NAME(line) EDUKE32_ASSERT_NAME2(eduke32_assert_, line)
-
 
898
#ifdef __COUNTER__
-
 
899
# define EDUKE32_STATIC_ASSERT(cond) \
-
 
900
    extern void EDUKE32_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
-
 
901
#else
-
 
902
# define EDUKE32_STATIC_ASSERT(cond) \
-
 
903
    extern void EDUKE32_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
-
 
904
#endif
-
 
905
-
 
906
#define ARRAY_SIZE(Ar) (sizeof(Ar)/sizeof((Ar)[0]))
916
#define ARRAY_SIZE(Ar) (sizeof(Ar)/sizeof((Ar)[0]))
907
#define ARRAY_SSIZE(Ar) (bssize_t)ARRAY_SIZE(Ar)
917
#define ARRAY_SSIZE(Ar) (bssize_t)ARRAY_SIZE(Ar)
908
918
909
////////// PANICKING ALLOCATION MACROS (wrapping the functions) //////////
919
////////// PANICKING ALLOCATION MACROS (wrapping the functions) //////////
910
#ifdef DEBUGGINGAIDS
920
#ifdef DEBUGGINGAIDS