1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | * |
---|
6 | * This software was released into the Public Domain. As with most public |
---|
7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
8 | * Jonathan Clark, or by Sam Hocevar. |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef __COMMON_H__ |
---|
12 | #define __COMMON_H__ |
---|
13 | |
---|
14 | // |
---|
15 | // Globally required headers |
---|
16 | // |
---|
17 | #include <stdint.h> |
---|
18 | #include <stdio.h> |
---|
19 | |
---|
20 | // |
---|
21 | // Lol Engine |
---|
22 | // |
---|
23 | #include "lol/matrix.h" |
---|
24 | #include "lol/timer.h" |
---|
25 | using namespace lol; |
---|
26 | |
---|
27 | // |
---|
28 | // Custom utility functions |
---|
29 | // |
---|
30 | static inline int Min(int a, int b) { return a < b ? a : b; } |
---|
31 | static inline int Max(int a, int b) { return a > b ? a : b; } |
---|
32 | static inline unsigned int Min(unsigned int a, unsigned int b) { return a < b ? a : b; } |
---|
33 | static inline unsigned int Max(unsigned int a, unsigned int b) { return a > b ? a : b; } |
---|
34 | static inline long Min(long a, long b) { return a < b ? a : b; } |
---|
35 | static inline long Max(long a, long b) { return a > b ? a : b; } |
---|
36 | static inline unsigned long Min(unsigned long a, unsigned long b) { return a < b ? a : b; } |
---|
37 | static inline unsigned long Max(unsigned long a, unsigned long b) { return a > b ? a : b; } |
---|
38 | static inline float Min(float a, float b) { return a < b ? a : b; } |
---|
39 | static inline float Max(float a, float b) { return a > b ? a : b; } |
---|
40 | |
---|
41 | static inline vec2i Min(vec2i a, vec2i b) { return vec2i(Min(a.x, b.x), Min(a.y, b.y)); } |
---|
42 | static inline vec2i Max(vec2i a, vec2i b) { return vec2i(Max(a.x, b.x), Max(a.y, b.y)); } |
---|
43 | |
---|
44 | // |
---|
45 | // Byte swapping |
---|
46 | // |
---|
47 | static inline int BigEndian() |
---|
48 | { |
---|
49 | union { uint32_t const x; uint8_t t[4]; } const u = { 0x01ffff00 }; |
---|
50 | return u.t[0]; |
---|
51 | } |
---|
52 | |
---|
53 | static inline uint16_t lstl(uint16_t x) |
---|
54 | { |
---|
55 | if (BigEndian()) |
---|
56 | return ((uint16_t)x << 8 ) | ((uint16_t)x >> 8); |
---|
57 | return x; |
---|
58 | } |
---|
59 | |
---|
60 | static inline uint32_t lltl(uint32_t x) |
---|
61 | { |
---|
62 | if (BigEndian()) |
---|
63 | return ((uint32_t)x >> 24) | (((uint32_t)x & 0x00ff0000) >> 8) |
---|
64 | | (((uint32_t)x & 0x0000ff00) << 8) | ((uint32_t)x << 24); |
---|
65 | return x; |
---|
66 | } |
---|
67 | |
---|
68 | #define ERROR(x,st) { if (!(x)) \ |
---|
69 | { printf("Error on line %d of %s : %s\n", \ |
---|
70 | __LINE__,__FILE__,st); exit(1); } } |
---|
71 | |
---|
72 | // These macros should be removed for the non-debugging version |
---|
73 | #ifdef NO_CHECK |
---|
74 | # define CONDITION(x,st) |
---|
75 | # define CHECK(x) |
---|
76 | #else |
---|
77 | # define CONDITION(x,st) ERROR(x,st) |
---|
78 | # define CHECK(x) CONDITION(x,"Check stop"); |
---|
79 | #endif |
---|
80 | |
---|
81 | #endif // __COMMON_H__ |
---|
82 | |
---|