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