-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.h
More file actions
89 lines (79 loc) · 1.93 KB
/
Map.h
File metadata and controls
89 lines (79 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <stdint.h>
namespace MapLayout {
inline constexpr char E1M1[] =
#include "../../../maps/e1m1.txt"
;
constexpr int computeWidth(const char* text) {
int width = 0;
int current = 0;
for (int i = 0; text[i] != '\0'; i++) {
char symbol = text[i];
if (symbol == '\r') {
continue;
}
if (symbol == '\n') {
if (current > width) {
width = current;
}
current = 0;
continue;
}
current++;
}
if (current > width) {
width = current;
}
return width;
}
constexpr int computeHeight(const char* text) {
int height = 0;
int current = 0;
for (int i = 0; text[i] != '\0'; i++) {
char symbol = text[i];
if (symbol == '\r') {
continue;
}
if (symbol == '\n') {
if (current > 0) {
height++;
}
current = 0;
continue;
}
current++;
}
if (current > 0) {
height++;
}
return height;
}
} // namespace MapLayout
class Map {
public:
static constexpr int MAX_WIDTH = 64;
static constexpr int MAX_HEIGHT = 64;
static constexpr int CELL_COUNT = MAX_WIDTH * MAX_HEIGHT;
static constexpr int DOOR_OPEN_BYTES = (CELL_COUNT + 7) / 8;
static constexpr int WIDTH = MapLayout::computeWidth(MapLayout::E1M1);
static constexpr int HEIGHT = MapLayout::computeHeight(MapLayout::E1M1);
static_assert(WIDTH > 0, "Map width must be greater than zero");
static_assert(HEIGHT > 0, "Map height must be greater than zero");
static_assert(WIDTH <= MAX_WIDTH, "Map width exceeds maximum");
static_assert(HEIGHT <= MAX_HEIGHT, "Map height exceeds maximum");
struct Spawn {
float x = 3.5f;
float y = 3.5f;
float dirX = 1.0f;
float dirY = 0.0f;
};
static void load(
uint8_t (*tiles)[MAX_WIDTH],
uint8_t* doorOpenBits,
int& width,
int& height,
Spawn& spawn);
private:
static uint8_t decodeTile(char symbol);
static bool decodeSpawn(char symbol, Spawn& spawn, int x, int y);
};