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

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

core: Get rid of mostly useless headers, move endianness handling to
common.h (and rewrite functions so that they do not need the SDL headers)
and move a few functions out of sdlport's video.cpp. These functions
were in the original video.cpp (which reappears) and shouldn't be part
of the SDL port.

  • Property svn:keywords set to Id
File size: 2.1 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 or
8 *  Jonathan Clark.
9 */
10
11#ifndef __COMMON_H__
12#define __COMMON_H__
13
14//
15// Globally required headers
16//
17#include <stdint.h>
18
19//
20// Lol Engine
21//
22#include "lol/matrix.h"
23using namespace lol;
24
25//
26// Custom utility functions
27//
28static inline int Min(int a, int b) { return a < b ? a : b; }
29static inline int Max(int a, int b) { return a > b ? a : b; }
30static inline float Min(float a, float b) { return a < b ? a : b; }
31static inline float Max(float a, float b) { return a > b ? a : b; }
32
33//
34// Byte swapping
35//
36static inline int BigEndian()
37{
38    union { uint32_t const x; uint8_t t[4]; } const u = { 0x01ffff00 };
39    return u.t[0];
40}
41
42static inline uint16_t Swap16(uint16_t x)
43{
44    return ((uint16_t)x << 8 ) | ((uint16_t)x >> 8);
45}
46
47static 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
79#endif // __COMMON_H__
80
Note: See TracBrowser for help on using the repository browser.