-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsp.h
158 lines (135 loc) · 4.24 KB
/
bsp.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "include/GL/glew.h"
#include "include/glm/glm.hpp"
#define HEADER_LUMPS 64
#define VBSP_HEADER (('P'<<24) + ('S' << 16) + ('B' << 8) + 'V')
class bsp
{
public:
bsp (const char* fp);
void LoadMapDetails(glm::vec3 pos);
enum lumpTypes {LUMP_ENTITIES = 0, LUMP_PLANES, LUMP_TEXDATA, LUMP_VERTICES, LUMP_VISIBILITY, LUMP_NODES, LUMP_TEXINFO, LUMP_FACES, LUMP_LIGHTING, LUMP_OCCLUSION, LUMP_LEAFS, LUMP_FACEIDS, LUMP_EDGES, LUMP_SURFEDGES, LUMP_MODELS, LUMP_WORLDLIGHTS,
LUMP_LEAFFACES, LUMP_LEAFBRUSHES, LUMP_BRUSHES, LUMP_BRUSHSIDES, LUMP_AREAS, LUMP_AREAPORTALS, LUMP_PORTALS, LUMP_UNUSED0, LUMP_PROPCOLLISION, LUMP_CLUSTERS, LUMP_UNUSED1, LUMP_PROPHULLS, LUMP_PORTALVERTS, LUMP_UNUSED2,
LUMP_PROPTRIS, LUMP_DISPINFO, LUMP_ORIGINALFACES, LUMP_PHYSDISP, LUMP_PHYSCOLLIDE, LUMP_VERTNORMALS, LUMP_VERTNORMALINDICES, LUMP_DISP_LIGHTMAP_ALPHAS, LUMP_DISP_VERTS, LUMP_DISP_LIGHTMAP_SAMPLE_POSITIONS,
LUMP_GAME_LUMP, LUMP_LEAFWATERDATA, LUMP_PRIMITIVES, LUMP_PRIMVERTS, LUMP_PRIMINDICES, LUMP_PAKFILE, LUMP_CLIPPORTALVERTS, LUMP_CUBEMAPS, LUMP_TEXDATA_STRING_DATA, LUMP_TEXDATA_STRING_TABLE, LUMP_OVERLAYS, LUMP_LEAFMINDISTTOWATER,
LUMP_FACE_MACRO_TEXTURE_INFO, LUMP_DISP_TRIS, LUMP_PHYSCOLLIDESURFACE, LUMP_PROP_BLOB, LUMP_WATEROVERLAYS, LUMP_LIGHTMAPPAGES, LUMP_LEAF_AMBIENT_INDEX_HDR, LUMP_LIGHTMAPPAGEINFOS, LUMP_LEAF_AMBIENT_INDEX, LUMP_LIGHTING_HDR,
LUMP_WORLDLIGHTS_HDR, LUMP_LEAF_AMBIENT_LIGHTING_HDR, LUMP_LEAF_AMBIENT_LIGHTING, LUMP_XZIPPAKFILE, LUMP_FACES_HDR, LUMP_MAP_FLAGS, LUMP_OVERLAY_FADES, LUMP_OVERLAY_SYSTEM_LEVELS, LUMP_PHYSLEVEL, LUMP_DISP_MULTIBLEND};
// TODO: Major cleanup
///////////////////////////
// TODO ASAP: Make naming more consistent, everything is all over the place right now
///////////////////////////
// Contains the info of every lump (offset from beginning of file, length of lump, version (usually 0), and identification (usually 0)
struct lumpInfo
{
int offset;
int length;
int version;
char ident[4];
};
// Main header struct
struct Header
{
int magic;
int version;
lumpInfo lumps[HEADER_LUMPS];
int revision;
};
// Vertex struct
struct Vertex
{
float x, y, z;
// cleaner usage of verts
Vertex pos()
{
return Vertex (x, y, z);
};
Vertex (float a, float b, float c)
{
x = a;
y = b;
z = c;
};
Vertex (){};
};
std::vector <Vertex> vertices; // map verts
struct Plane
{
Vertex normal;
float distance;
int type;
};
std::vector <Vertex> mapNormals; // map normals
struct Node
{
int planeIndex;
int children[2];
short mins[3];
short maxs[3];
unsigned short faceIndex;
unsigned short numFaces;
short area;
short padding;
};
std::vector <Node> nodes;
struct Leaf
{
int contents;
short cluster;
short area:9; // use only 9 bits
short flags:7;
short mins[3];
short maxs[3];
unsigned short firstLeafFace;
unsigned short numLeafFaces;
unsigned short firstLeafBrush;
unsigned short numLeafBrushes;
short leafWaterDataID;
};
std::vector <Leaf> leafs;
std::vector <unsigned short> leafFaces;
struct Face
{
unsigned short planeIndex;
unsigned __int8 side; // visual c++ stuffs, change it later
unsigned __int8 onNode;
int firstEdge;
short numEdges;
short texInfo;
short dispInfo;
short surfaceFogVolumeID;
unsigned __int8 styles[4];
int lightOfs;
float area;
int lightmapTextureMinsInLuxels[2];
int lightmapTextureSizeInLuxels[2];
int origFace;
unsigned short numPrims;
unsigned short firstPrimID;
unsigned int smoothingGroups;
};
std::vector <Face> faces;
struct Edge
{
unsigned short vert[2];
};
std::vector <Edge> edges;
std::vector <int> SurfEdges;
std::vector <Plane> planes;
std::vector <GLuint> indices; // Final index vector
private:
std::ifstream map;
Header header;
int WalkBSPTree (glm::vec3 pos, int node);
bool PointIsInside (glm::vec3 pos, short min[3], short max[3]);
void ComputeBSP (int node, int leaf, glm::vec3 pos);
void RenderLeaf (int leaf);
void RenderFace (int face);
float dotProduct (Vertex normal, glm::vec3 b);
bool loadHeader();
template <typename T>
void readLump (std::ifstream& fp, std::vector<T>& elements, unsigned int index);
// ^^^ thank you layla for showing this ^^^
};