wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <array>
11#include <cstdint>
12
13#include <welder/vocabulary.hpp>
14
21#if defined(_MSC_VER)
22# define WOWLIB_EMPTY_BASES __declspec(empty_bases)
23#else
24# define WOWLIB_EMPTY_BASES
25#endif
26
28 struct [[
29 =welder::weld,
30 =welder::doc(
31 "A 2D float vector: texture coordinates, UV animation speeds.")
32 ]] C2Vector {
33 [[=welder::doc("The x component.")]]
34 float x = 0;
35 [[=welder::doc("The y component.")]]
36 float y = 0;
37
38 bool operator==(const C2Vector&) const = default;
39 };
40
41 struct [[
42 =welder::weld,
43 =welder::doc("A 2D integer vector.")
44 ]] C2IVector {
45 [[=welder::doc("The x component.")]]
46 std::int32_t x = 0;
47 [[=welder::doc("The y component.")]]
48 std::int32_t y = 0;
50 bool operator==(const C2IVector&) const = default;
51 };
52
53 struct [[
54 =welder::weld,
55 =welder::doc("A 3D float vector — the workhorse: positions, normals, "
56 "rotations-as-Euler-degrees in placements.")
58 [[=welder::doc("The x component.")]]
59 float x = 0;
60 [[=welder::doc("The y component.")]]
61 float y = 0;
62 [[=welder::doc("The z component.")]]
63 float z = 0;
64
65 bool operator==(const C3Vector&) const = default;
66 };
68 struct [[
69 =welder::weld,
70 =welder::doc("A 3D integer vector.")
71 ]] C3IVector {
72 [[=welder::doc("The x component.")]]
73 std::int32_t x = 0;
74 [[=welder::doc("The y component.")]]
75 std::int32_t y = 0;
76 [[=welder::doc("The z component.")]]
77 std::int32_t z = 0;
78
79 bool operator==(const C3IVector&) const = default;
80 };
82 struct [[
83 =welder::weld,
84 =welder::doc("A 4D float vector.")
85 ]] C4Vector {
86 [[=welder::doc("The x component.")]]
87 float x = 0;
88 [[=welder::doc("The y component.")]]
89 float y = 0;
90 [[=welder::doc("The z component.")]]
91 float z = 0;
92 [[=welder::doc("The w component.")]]
93 float w = 0;
95 bool operator==(const C4Vector&) const = default;
96 };
97
98 struct [[
99 =welder::weld,
100 =welder::doc(R"(
101 A quaternion with the scalar part LAST on disk (x, y, z, w) — note the
102 difference from math libraries that lead with w.)")
103 ]] C4Quaternion {
104 [[=welder::doc("The x component.")]]
105 float x = 0;
106 [[=welder::doc("The y component.")]]
107 float y = 0;
108 [[=welder::doc("The z component.")]]
109 float z = 0;
110 [[=welder::doc("The w (scalar) component.")]]
111 float w = 1;
113 bool operator==(const C4Quaternion&) const = default;
114 };
115
116 struct [[
117 =welder::weld,
118 =welder::doc("A 3x3 matrix as three column C3Vectors.")
119 ]] C33Matrix {
120 [[=welder::doc("The three columns.")]]
121 std::array<C3Vector, 3> columns{};
122
123 bool operator==(const C33Matrix&) const = default;
124 };
125
126 struct [[
127 =welder::weld,
128 =welder::doc("A 3x4 matrix as four column C3Vectors.")
129 ]] C34Matrix {
130 [[=welder::doc("The four columns.")]]
131 std::array<C3Vector, 4> columns{};
132
133 bool operator==(const C34Matrix&) const = default;
134 };
135
136 struct [[
137 =welder::weld,
138 =welder::doc("A 4x4 matrix as four column C4Vectors.")
139 ]] C44Matrix {
140 [[=welder::doc("The four columns.")]]
141 std::array<C4Vector, 4> columns{};
142
143 bool operator==(const C44Matrix&) const = default;
144 };
145
146 struct [[
147 =welder::weld,
148 =welder::doc(
149 "A plane as a normal and its signed distance from the origin.")
151 [[=welder::doc("The plane normal.")]]
152 C3Vector normal{};
153 [[=welder::doc("The signed distance from the origin.")]]
154 float distance = 0;
155
156 bool operator==(const C4Plane&) const = default;
157 };
159 struct [[
160 =welder::weld,
161 =welder::doc("An axis-aligned bounding box: minimum and maximum corners.")
162 ]] CAaBox {
163 [[=welder::doc("The minimum corner.")]]
164 C3Vector min{};
165 [[=welder::doc("The maximum corner.")]]
166 C3Vector max{};
167
168 bool operator==(const CAaBox&) const = default;
169 };
171 struct [[
172 =welder::weld,
173 =welder::doc("An axis-aligned sphere: position and radius.")
175 [[=welder::doc("The center position.")]]
176 C3Vector position{};
177 [[=welder::doc("The radius.")]]
178 float radius = 0;
179
180 bool operator==(const CAaSphere&) const = default;
181 };
183 struct [[
184 =welder::weld,
185 =welder::doc("A float range: minimum and maximum.")
187 [[=welder::doc("The minimum.")]]
188 float min = 0;
189 [[=welder::doc("The maximum.")]]
190 float max = 0;
191
192 bool operator==(const CRange&) const = default;
193 };
194
195 struct [[
196 =welder::weld,
197 =welder::doc("A color stored as r, g, b, a bytes.")
198 ]] CArgb {
199 [[=welder::doc("The red component.")]]
200 std::uint8_t r = 0;
201 [[=welder::doc("The green component.")]]
202 std::uint8_t g = 0;
203 [[=welder::doc("The blue component.")]]
204 std::uint8_t b = 0;
205 [[=welder::doc("The alpha component.")]]
206 std::uint8_t a = 0;
207
208 bool operator==(const CArgb&) const = default;
209 };
210
211 struct [[
212 =welder::weld,
213 =welder::doc(
214 "A color stored as b, g, r, a bytes — the client's immediate-mode "
215 "vertex color layout (WMO MOCV, doodad colors).")
216 ]] CImVector {
217 [[=welder::doc("The blue component.")]]
218 std::uint8_t b = 0;
219 [[=welder::doc("The green component.")]]
220 std::uint8_t g = 0;
221 [[=welder::doc("The red component.")]]
222 std::uint8_t r = 0;
223 [[=welder::doc("The alpha component.")]]
224 std::uint8_t a = 0;
225
226 bool operator==(const CImVector&) const = default;
227 };
228
229 struct [[
230 =welder::weld,
231 =welder::doc(
232 "A signed 16-bit fixed-point value with an implicit 0x7FFF scale.")
233 ]] fixed16 {
234 [[=welder::doc("The raw fixed-point integer; value / 0x7FFF is the float.")]
235 ]
236 std::int16_t value = 0;
237
238 [[=welder::getter,
239 =welder::doc("The value as a float in [-1, 1].")]]
240 constexpr float asFloat() const {
241 return static_cast<float>(value) / 0x7FFF;
242 }
243
244 bool operator==(const fixed16&) const = default;
245 };
246
247 static_assert(sizeof(C2Vector) == 8);
248 static_assert(sizeof(C2IVector) == 8);
249 static_assert(sizeof(C3Vector) == 12);
250 static_assert(sizeof(C3IVector) == 12);
251 static_assert(sizeof(C4Vector) == 16);
252 static_assert(sizeof(C4Quaternion) == 16);
253 static_assert(sizeof(C33Matrix) == 36);
254 static_assert(sizeof(C34Matrix) == 48);
255 static_assert(sizeof(C44Matrix) == 64);
256 static_assert(sizeof(C4Plane) == 16);
257 static_assert(sizeof(CAaBox) == 24);
258 static_assert(sizeof(CAaSphere) == 16);
259 static_assert(sizeof(CRange) == 8);
260 static_assert(sizeof(CArgb) == 4);
261 static_assert(sizeof(CImVector) == 4);
262 static_assert(sizeof(fixed16) == 2);
263}
264
265// The primitives live in wowlib::formats::common (welded as the wowlib.formats.common
266// submodule), but the format code refers to them by their bare client names. This
267// directive keeps both bare (C3Vector) and wowlib::formats::C3Vector lookups working —
268// qualified name lookup follows using-directives — WITHOUT re-declaring them as members
269// of wowlib::formats (so welder still binds them under `common`, not twice).
270namespace wowlib::formats {
271 using namespace common;
272}
A 2D integer vector.
Definition types.hpp:39
std::int32_t x
The x component.
Definition types.hpp:41
std::int32_t y
The y component.
Definition types.hpp:43
bool operator==(const C2IVector &) const =default
A 2D float vector: texture coordinates, UV animation speeds.
Definition types.hpp:29
float y
The y component.
Definition types.hpp:33
bool operator==(const C2Vector &) const =default
float x
The x component.
Definition types.hpp:31
A 3x3 matrix as three column C3Vectors.
Definition types.hpp:100
bool operator==(const C33Matrix &) const =default
std::array< C3Vector, 3 > columns
The three columns.
Definition types.hpp:102
A 3x4 matrix as four column C3Vectors.
Definition types.hpp:108
std::array< C3Vector, 4 > columns
The four columns.
Definition types.hpp:110
bool operator==(const C34Matrix &) const =default
A 3D integer vector.
Definition types.hpp:61
std::int32_t x
The x component.
Definition types.hpp:63
std::int32_t y
The y component.
Definition types.hpp:65
bool operator==(const C3IVector &) const =default
std::int32_t z
The z component.
Definition types.hpp:67
A 3D float vector — the workhorse: positions, normals, rotations-as-Euler-degrees in placements.
Definition types.hpp:49
float y
The y component.
Definition types.hpp:53
float x
The x component.
Definition types.hpp:51
bool operator==(const C3Vector &) const =default
float z
The z component.
Definition types.hpp:55
A 4x4 matrix as four column C4Vectors.
Definition types.hpp:116
bool operator==(const C44Matrix &) const =default
std::array< C4Vector, 4 > columns
The four columns.
Definition types.hpp:118
A plane as a normal and its signed distance from the origin.
Definition types.hpp:124
bool operator==(const C4Plane &) const =default
C3Vector normal
The plane normal.
Definition types.hpp:126
float distance
The signed distance from the origin.
Definition types.hpp:128
bool operator==(const C4Quaternion &) const =default
float w
The w (scalar) component.
Definition types.hpp:94
float w
The w component.
Definition types.hpp:81
float x
The x component.
Definition types.hpp:75
float y
The y component.
Definition types.hpp:77
float z
The z component.
Definition types.hpp:79
bool operator==(const C4Vector &) const =default
An axis-aligned bounding box: minimum and maximum corners.
Definition types.hpp:134
C3Vector min
The minimum corner.
Definition types.hpp:136
C3Vector max
The maximum corner.
Definition types.hpp:138
bool operator==(const CAaBox &) const =default
An axis-aligned sphere: position and radius.
Definition types.hpp:144
C3Vector position
The center position.
Definition types.hpp:146
bool operator==(const CAaSphere &) const =default
A color stored as r, g, b, a bytes.
Definition types.hpp:164
bool operator==(const CArgb &) const =default
std::uint8_t g
The green component.
Definition types.hpp:168
std::uint8_t r
The red component.
Definition types.hpp:166
std::uint8_t a
The alpha component.
Definition types.hpp:172
std::uint8_t b
The blue component.
Definition types.hpp:170
A color stored as b, g, r, a bytes — the client's immediate-mode vertex color layout (WMO MOCV,...
Definition types.hpp:178
std::uint8_t g
The green component.
Definition types.hpp:182
bool operator==(const CImVector &) const =default
std::uint8_t b
The blue component.
Definition types.hpp:180
std::uint8_t r
The red component.
Definition types.hpp:184
std::uint8_t a
The alpha component.
Definition types.hpp:186
A float range: minimum and maximum.
Definition types.hpp:154
bool operator==(const CRange &) const =default
A signed 16-bit fixed-point value with an implicit 0x7FFF scale.
Definition types.hpp:192