moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / felib / felibdef.h
blob663037ee0a1dfd5426868bc78bfc00383575ec68
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __FELIB_FELIBDEF_H__
13 #define __FELIB_FELIBDEF_H__
15 static_assert(sizeof(void*) == 4, "64 bit is NOT SUPPORTED and WILL NOT WORK!");
18 * Global defines for the project FeLib.
19 * This file is created to decrease the need of including headers in
20 * other headers just for the sake of some silly macros, because it
21 * decreases compilation efficiency and may cause cross-including
23 * List of macros that should be gathered here:
24 * 1. all numeric defines used in multiple .cpp or .h files
25 * 2. all inline functions used in multiple .cpp or .h files
26 * and independent enough (do not require other headers)
27 * 3. class construction macros used in multiple .h files
30 #include "typedef.h"
32 cint MapMoveX[9] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
33 cint MapMoveY[9] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
35 culong SquarePartTickMask[4] = { 0xFF, 0xFF00, 0xFF0000, 0xFF000000 };
37 #define FPI 3.1415926535897932384626433832795
39 /* Btw, both __attribute__ ((regparm(3))) and __fastcall SUCK! */
41 #define NO_ALIGNMENT __attribute__ ((packed))
42 #define NO_RETURN __attribute__((noreturn))
43 #define LIKE_PRINTF(p1, p2) __attribute__((format(printf, p1, p2)))
45 template <class type> constexpr inline type Max (type X, type Y) { return (X >= Y ? X : Y); }
46 template <class type> constexpr inline type Max (type X, type Y, type Z) { return (X >= Y ? (X >= Z ? X : Z) : (Y >= Z ? Y : Z)); }
47 template <class type> constexpr inline type Min (type X, type Y) { return (X <= Y ? X : Y); }
48 template <class type> constexpr inline type Min (type X, type Y, type Z) { return (X <= Y ? (X <= Z ? X : Z) : (Y <= Z ? Y : Z)); }
49 template <class type> constexpr inline type HypotSquare (type X, type Y) { return X*X+Y*Y; }
50 template <class type> constexpr inline type Limit (type Value, type Minimum, type Maximum) { return (Value >= Minimum ? (Value <= Maximum ? Value : Maximum) : Minimum); }
52 template <class type> inline void LimitRef (type &Value, type Minimum, type Maximum) {
53 if (Value <= Minimum) Value = Minimum;
54 else if (Value >= Maximum) Value = Maximum;
57 template <class type> inline void Swap(type &X, type &Y) {
58 const type T = X;
59 X = Y;
60 Y = T;
63 constexpr inline col16 GetRed16 (col16 Color) { return (Color>>8)&0xF8; }
64 constexpr inline col16 GetGreen16 (col16 Color) { return (Color>>3)&0xFC; }
65 constexpr inline col16 GetBlue16 (col16 Color) { return (Color<<3)&0xF8; }
67 //constexpr inline unsigned int MakeColor16 (int c) { return (c < 0 ? 0 : (c > 255 ? 63 : 63*c/255)); }
68 constexpr inline col16 MakeRGB16 (int Red, int Green, int Blue) { return ((Red<<8)&0xF800)|((Green<<3)&0x7E0)|((Blue>>3)&0x1F); }
70 constexpr inline col16 MakeShadeColor (col16 Color) {
71 return
72 MakeRGB16(
73 GetRed16(Color)/3,
74 GetGreen16(Color)/3,
75 GetBlue16(Color)/3);
78 constexpr inline col24 GetRed24 (col24 Color) { return Color >> 16 & 0xFF; }
79 constexpr inline col24 GetGreen24 (col24 Color) { return Color >> 8 & 0xFF; }
80 constexpr inline col24 GetBlue24 (col24 Color) { return Color & 0xFF; }
82 constexpr inline col24 MakeRGB24 (int Red, int Green, int Blue) { return (Red << 16 & 0xFF0000) | (Green << 8 & 0xFF00) | (Blue & 0xFF); }
84 constexpr inline int GetMaxColor24 (col24 Color) { return Max(GetRed24(Color), GetGreen24(Color), GetBlue24(Color)); }
85 constexpr inline int GetMinColor24 (col24 Color) { return Min(GetRed24(Color), GetGreen24(Color), GetBlue24(Color)); }
88 #define NONE 0
89 #define MIRROR 1
90 #define FLIP 2
91 #define ROTATE 4
93 #define TRANSPARENT_COLOR 0xF81F
95 #define RED 0xF800
96 #define GREEN 0x07E0
97 #define BLUE 0x2ABF
98 #define YELLOW 0xFFE0
99 #define PINK 0xF01E
100 #define WHITE 0xFFFF
101 #define LIGHT_GRAY 0x94B2
102 #define DARK_GRAY 0x528A
103 #define BLACK 0x0000
104 #define CYAN 0x07FF
105 #define ORANGE (MakeRGB16(255, 127, 0))
107 #define SEL_BLUE 0x2AAF
109 #define NORMAL_LUMINANCE 0x808080
111 #define KEY_BACK_SPACE 0x08
112 #define KEY_ESC 0x1B
113 #define KEY_ENTER 0x0D
114 #define KEY_UP 0x148
115 #define KEY_DOWN 0x150
116 #define KEY_RIGHT 0x14D
117 #define KEY_LEFT 0x14B
118 #define KEY_HOME 0x147
119 #define KEY_END 0x14F
120 #define KEY_PAGE_DOWN 0x151
121 #define KEY_PAGE_UP 0x149
122 #define KEY_INS 0x152
123 #define KEY_DEL 0x153
124 #define KEY_PLUS 0x14E
125 #define KEY_SPACE 0x20
126 #define KEY_NUMPAD_5 2
128 #define NO_FLAME 0xFFFF
130 #define SELECTABLE 1
131 #define INVERSE_MODE 2
132 #define BLIT_AFTERWARDS 4
133 #define DRAW_BACKGROUND_AFTERWARDS 8
134 #define FADE 16
136 /* special list flag */
137 #define FELIST_NO_BADKEY_EXIT 0x80
139 /* felist errors */
140 #define FELIST_ERROR_BIT 0x8000
141 #define LIST_WAS_EMPTY 0xFFFF
142 #define ESCAPED 0xFFFE
143 #define NOTHING_SELECTED 0xFFFD
145 #define NO_LIMIT 0xFFFF
147 #define MAX_CONTROLS 0x10
149 #define HIGHEST 0xFF
151 #define NORMAL_EXIT 0
152 #define ABORTED 1
154 #define MAX_CONFIG_OPTIONS 0x100
156 #define FLY_PRIORITY ((10 << 4) + 10)
157 #define SPARKLE_PRIORITY ((12 << 4) + 12)
158 #define LIGHTNING_PRIORITY ((14 << 4) + 14)
159 #define AVERAGE_PRIORITY ((8 << 4) + 8)
161 #define NO_IMAGE 0xFFFF
163 #define ZERO_POOLS 1
164 #define RAND_ALLOC 2
166 using rcint = int;
167 #define REFS(ptr) (reinterpret_cast<rcint*>(ptr)[-1])
168 #define REFSA(ptr) &(reinterpret_cast<rcint*>(ptr)[-1])
170 #define SKIP_FIRST 1
171 #define ALLOW_END_FAILURE 2
173 #define MAX_RAND 0x7FFFFFFF
175 #define TRANSPARENT_PALETTE_INDEX 191
177 #define MAX_HIGHSCORES 100
179 /* sparkling flags */
181 #define SPARKLING_A 1
182 #define SPARKLING_B 2
183 #define SPARKLING_C 4
184 #define SPARKLING_D 8
187 #endif