-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chunk.h
87 lines (62 loc) · 1.27 KB
/
Chunk.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
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
#ifndef _CHUNK_H
#define _CHUNK_H
#include "Math3d.h"
#include "sgtypes.h"
#include <octree.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_opengl.h>
#include <vector>
#include <tuple>
#include <map>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
class Chunk;
typedef std::tuple<int, int> ChunkLocation;
typedef std::map<ChunkLocation, Chunk *> ChunkMap;
typedef std::map<ChunkLocation, Chunk *>::iterator ChunkMapIterator;
struct RenderedFaces {
std::vector<GLfloat> px;
std::vector<GLfloat> nx;
std::vector<GLfloat> py;
std::vector<GLfloat> ny;
std::vector<GLfloat> pz;
std::vector<GLfloat> nz;
RenderedFaces();
};
class Chunk {
protected:
Octree<Uint8, 4> data;
RenderedFaces rendered_faces;
public:
Chunk();
enum {
PX=0,
NX,
PY,
NY,
PZ,
NZ
};
GLuint vboFaces[6];
int vertex_count;
bool isAir(Uint8 x, Uint8 y, Uint8 z);
void renderFaces(bool firstCall=false);
void addFace(Uint8 x, Uint8 y, Uint8 z, Uint8 face);
void render();
void serialize(std::ostream &out) const;
void read(std::istream &in);
~Chunk();
};
class ChunkManager {
protected:
ChunkMap chunks;
public:
ChunkManager();
int vertex_count;
void add(int x, int y, Chunk * c);
Chunk * get(int x, int y);
void render();
~ChunkManager();
};
#endif