-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkamkar.h
61 lines (51 loc) · 1.3 KB
/
kamkar.h
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
#pragma once
#include <GLFW/glfw3.h>
#include <noise.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
template <typename T>
T *emalloc(unsigned int count) {
T *const result = static_cast<T *>(malloc(count * sizeof(T)));
if (result == nullptr) {
perror("Allocation with malloc failed");
exit(1);
}
return result;
}
template <typename T>
T *ecalloc(unsigned int count) {
T *const result = static_cast<T *>(calloc(count, sizeof(T)));
if (result == nullptr) {
perror("Allocation with calloc failed");
exit(1);
}
return result;
}
constexpr float sqrt3 = 1.73205080757f;
constexpr float minZoom = 0.005f;
constexpr float maxZoom = 1.0f;
constexpr float maxScroll = 100.0f;
constexpr float hexHeight = 1.5f;
struct Tilemap;
enum Terrain : uchar {
None,
Ocean,
Beach,
Grass,
Mountain
};
struct Tile {
Terrain terrain : 7;
bool isVisible : 1;
};
Tilemap *createTilemap();
Tile *getTile(Tilemap *map, vec2<int> position);
namespace graphics {
GLFWwindow *init(const char *title);
void render(GLFWwindow *window, Tilemap *map, const vec2<int> *entities, int entityCount, float zoom);
void moveCamera(Direction direction, float distance);
vec2<float> getCamera();
vec2<int> getCameraHex();
}