source: abuse/trunk/src/common.h @ 565

Last change on this file since 565 was 565, checked in by Sam Hocevar, 10 years ago

core: add more argument types to Min() and Max().

  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
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"
24using namespace lol;
25
26//
27// Custom utility functions
28//
29static inline int Min(int a, int b) { return a < b ? a : b; }
30static inline int Max(int a, int b) { return a > b ? a : b; }
31static inline long Min(long a, long b) { return a < b ? a : b; }
32static inline long Max(long a, long b) { return a > b ? a : b; }
33static inline unsigned long Min(unsigned long a, unsigned long b) { return a < b ? a : b; }
34static inline unsigned long Max(unsigned long a, unsigned long b) { return a > b ? a : b; }
35static inline float Min(float a, float b) { return a < b ? a : b; }
36static inline float Max(float a, float b) { return a > b ? a : b; }
37
38//
39// Byte swapping
40//
41static inline int BigEndian()
42{
43    union { uint32_t const x; uint8_t t[4]; } const u = { 0x01ffff00 };
44    return u.t[0];
45}
46
47static inline uint16_t lstl(uint16_t x)
48{
49    if (BigEndian())
50        return ((uint16_t)x << 8 ) | ((uint16_t)x >> 8);
51    return x;
52}
53
54static inline uint32_t lltl(uint32_t x)
55{
56    if (BigEndian())
57        return ((uint32_t)x >> 24) | (((uint32_t)x & 0x00ff0000) >> 8)
58             | (((uint32_t)x & 0x0000ff00) << 8) | ((uint32_t)x << 24);
59    return x;
60}
61
62#define ERROR(x,st) { if (!(x)) \
63   { printf("Error on line %d of %s : %s\n", \
64     __LINE__,__FILE__,st); exit(1); } }
65
66// These macros should be removed for the non-debugging version
67#ifdef NO_CHECK
68#   define CONDITION(x,st)
69#   define CHECK(x)
70#else
71#   define CONDITION(x,st) ERROR(x,st)
72#   define CHECK(x) CONDITION(x,"Check stop");
73#endif
74
75#endif // __COMMON_H__
76
Note: See TracBrowser for help on using the repository browser.