[509] | 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 |
---|
[555] | 7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
| 8 | * Jonathan Clark, or by Sam Hocevar. |
---|
[509] | 9 | */ |
---|
| 10 | |
---|
| 11 | #ifndef __COMMON_H__ |
---|
| 12 | #define __COMMON_H__ |
---|
| 13 | |
---|
[518] | 14 | // |
---|
[524] | 15 | // Globally required headers |
---|
| 16 | // |
---|
| 17 | #include <stdint.h> |
---|
[525] | 18 | #include <stdio.h> |
---|
[524] | 19 | |
---|
| 20 | // |
---|
[518] | 21 | // Lol Engine |
---|
| 22 | // |
---|
[509] | 23 | #include "lol/matrix.h" |
---|
| 24 | using namespace lol; |
---|
| 25 | |
---|
[518] | 26 | // |
---|
| 27 | // Custom utility functions |
---|
| 28 | // |
---|
| 29 | static inline int Min(int a, int b) { return a < b ? a : b; } |
---|
| 30 | static inline int Max(int a, int b) { return a > b ? a : b; } |
---|
| 31 | static inline float Min(float a, float b) { return a < b ? a : b; } |
---|
| 32 | static inline float Max(float a, float b) { return a > b ? a : b; } |
---|
| 33 | |
---|
[524] | 34 | // |
---|
| 35 | // Byte swapping |
---|
| 36 | // |
---|
| 37 | static inline int BigEndian() |
---|
| 38 | { |
---|
| 39 | union { uint32_t const x; uint8_t t[4]; } const u = { 0x01ffff00 }; |
---|
| 40 | return u.t[0]; |
---|
| 41 | } |
---|
| 42 | |
---|
[525] | 43 | static inline uint16_t lstl(uint16_t x) |
---|
[524] | 44 | { |
---|
[525] | 45 | if (BigEndian()) |
---|
| 46 | return ((uint16_t)x << 8 ) | ((uint16_t)x >> 8); |
---|
| 47 | return x; |
---|
[524] | 48 | } |
---|
| 49 | |
---|
[525] | 50 | static inline uint32_t lltl(uint32_t x) |
---|
[524] | 51 | { |
---|
[525] | 52 | if (BigEndian()) |
---|
| 53 | return ((uint32_t)x >> 24) | (((uint32_t)x & 0x00ff0000) >> 8) |
---|
| 54 | | (((uint32_t)x & 0x0000ff00) << 8) | ((uint32_t)x << 24); |
---|
| 55 | return x; |
---|
[524] | 56 | } |
---|
| 57 | |
---|
| 58 | #define ERROR(x,st) { if (!(x)) \ |
---|
| 59 | { printf("Error on line %d of %s : %s\n", \ |
---|
| 60 | __LINE__,__FILE__,st); exit(1); } } |
---|
| 61 | |
---|
| 62 | // These macros should be removed for the non-debugging version |
---|
| 63 | #ifdef NO_CHECK |
---|
| 64 | # define CONDITION(x,st) |
---|
| 65 | # define CHECK(x) |
---|
| 66 | #else |
---|
| 67 | # define CONDITION(x,st) ERROR(x,st) |
---|
| 68 | # define CHECK(x) CONDITION(x,"Check stop"); |
---|
| 69 | #endif |
---|
| 70 | |
---|
[509] | 71 | #endif // __COMMON_H__ |
---|
| 72 | |
---|