| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file types.h |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created OpenJazz.h |
| 10 | * - 1st November 2023: Created types.h from parts of OpenJazz.h |
| 11 | * |
| 12 | * @par Licence: |
| 13 | * Copyright (c) 2005-2017 AJ Thomson |
| 14 | * Copyright (c) 2015-2026 Carsten Teibes |
| 15 | * |
| 16 | * OpenJazz is distributed under the terms of |
| 17 | * the GNU General Public License, version 2.0 |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #ifndef OJ_TYPES_H |
| 23 | #define OJ_TYPES_H |
| 24 | |
| 25 | // Constants |
| 26 | |
| 27 | // Numbers in -10 exponent fixed point |
| 28 | #define FE 128 |
| 29 | #define FQ 256 |
| 30 | #define FH 512 |
| 31 | #define F1 1024 |
| 32 | #define F2 2048 |
| 33 | #define F4 4096 |
| 34 | #define F8 8192 |
| 35 | #define F10 10240 |
| 36 | #define F12 12288 |
| 37 | #define F16 16384 |
| 38 | #define F20 20480 |
| 39 | #define F24 24576 |
| 40 | #define F32 32768 |
| 41 | #define F36 36864 |
| 42 | #define F40 40960 |
| 43 | #define F80 81920 |
| 44 | #define F64 65536 |
| 45 | #define F100 102400 |
| 46 | #define F160 163840 |
| 47 | #define F192 196608 |
| 48 | |
| 49 | // Macros |
| 50 | |
| 51 | // For fixed-point operations |
| 52 | #define FTOI(x) ((x) >> 10) ///< Fixed to Int |
| 53 | #define ITOF(x) ((x) << 10) ///< Int to Fixed |
| 54 | #define MUL(x, y) (((x) * (y)) >> 10) ///< multiplication |
| 55 | #define DIV(x, y) (((x) << 10) / (y)) ///< division |
| 56 | |
| 57 | // For boundary checking, TODO: use std::clamp with c++17 |
| 58 | #define CLAMP(v, l, h) (((v) < (l)) ? (l) : (((v) > (h)) ? (h) : (v))) |
| 59 | |
| 60 | // For easier conversion of strongly typed enums |
| 61 | #define MAKE_ENUM_CLASS(name, ...) \ |
| 62 | enum class name : unsigned { __VA_ARGS__ }; \ |
| 63 | inline constexpr unsigned operator+ (name const val) noexcept { \ |
| 64 | return static_cast<unsigned>(val); \ |
| 65 | } |
| 66 | |
| 67 | #define OJ_UNUSED(v) (void)(v) |
| 68 | |
| 69 | // Datatypes |
| 70 | |
| 71 | typedef int fixed; ///< Custom fixed-point data type |
| 72 | |
| 73 | namespace SE { |
| 74 | enum Type : int; ///< Sound Index type |
| 75 | } |
| 76 | |
| 77 | MAKE_ENUM_CLASS(scalerType, |
| 78 | None, |
| 79 | Bilinear, |
| 80 | Scale2x, |
| 81 | hqx |
| 82 | ); |
| 83 | |
| 84 | MAKE_ENUM_CLASS(hudType, |
| 85 | Classic, |
| 86 | FPS, |
| 87 | Modern |
| 88 | ); |
| 89 | |
| 90 | MAKE_ENUM_CLASS(difficultyType, |
| 91 | Easy, |
| 92 | Normal, |
| 93 | Hard, |
| 94 | Turbo |
| 95 | ); |
| 96 | |
| 97 | MAKE_ENUM_CLASS(alignX, |
| 98 | Left, |
| 99 | Center, |
| 100 | Right |
| 101 | ); |
| 102 | |
| 103 | MAKE_ENUM_CLASS(alignY, |
| 104 | Top, |
| 105 | Center, |
| 106 | Bottom |
| 107 | ); |
| 108 | |
| 109 | struct Point { |
| 110 | Point() : x(0), y(0) {} |
| 111 | Point(int x, int y) : x(x), y(y) {} |
| 112 | |
| 113 | bool operator==(const Point& other) const { |
| 114 | return (x == other.x) && (y == other.y); |
| 115 | } |
| 116 | |
| 117 | int x, y; |
| 118 | }; |
| 119 | |
| 120 | #endif |