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
|
#pragma once
#include "../../util/allocator.h"
#include "../../util/vector.h"
#include "../../util/color.h"
#include "../../util/fnv.h"
#include <string.h>
enum MapPropId_t {
MAPPROP_SKYBOX = -1,
};
struct SURF_PROPS {
struct GL_TEX2D* tex;
CLR clr;
};
struct MAP_VERTEX {
VEC3 pos;
VEC3 normal;
VEC2 uv;
CLR clr;
};
enum MapPolygonType_t {
MPT_FLOOR,
MPT_CEILING
};
struct MAP_POLYGON {
MAP_POLYGON& operator=( const MAP_POLYGON& other ) {
memcpy( this, &other, sizeof(*this) );
vertices = other.vertices;
return *this;
}
LIST<MAP_VERTEX> vertices;
VEC3 mins;
VEC3 maxs;
U8 type;
I32 propid;
};
struct MAP_WALL {
VEC3 start;
VEC3 end;
VEC2 uvstart;
VEC2 uvend;
I32 propid;
};
struct MAP_TEXTURE_ENTRY {
char name[256];
struct GL_TEX2D* tex;
FNV1A hash;
};
struct MAP_SPRITE {
VEC3 pos;
VEC2 size;
CLR clr;
GL_TEX2D* tex;
};
struct MAP_ENTITY {
VEC3 pos;
U32 classid;
LIST<struct OBJECT_PROP*> props;
};
struct MAP_SKYBOX {
SURF_PROPS props;
MAP_WALL walls[4];
MAP_POLYGON polygons[2];
};
struct WORLD_MAP {
LIST<MAP_WALL> walls;
LIST<MAP_POLYGON> polygons;
LIST<MAP_SPRITE> sprites;
LIST<MAP_ENTITY> entities;
LIST<SURF_PROPS> props;
MAP_SKYBOX skybox;
F32 w;
F32 h;
VEC3 mins;
VEC3 maxs;
char name[256];
VEC3 startpos;
F32 startang;
struct BSP* bsp{};
LIST<MAP_TEXTURE_ENTRY*> textures;
};
extern WORLD_MAP* map_from_file( struct GAME_DATA* game, const char* filename );
extern struct CFG_SECTION* map_serialize( WORLD_MAP* map );
extern STAT map_add_texture_ref( WORLD_MAP* map, GL_TEX2D* tex );
extern GL_TEX2D* map_find_texture( WORLD_MAP* map, const char* name );
extern void map_free( struct GAME_DATA* game, WORLD_MAP* map );
// checks mins/maxs and recreates skybox if needed
extern void map_check_bounds( WORLD_MAP* map );
extern void map_calc_bounds( WORLD_MAP* map );
extern void map_polygon_calc_bounds( MAP_POLYGON* p );
inline SURF_PROPS* map_props_get_special( WORLD_MAP* w, I32 prop ) {
switch( prop ) {
case MAPPROP_SKYBOX: return &w->skybox.props;
};
dlog( "map_props_get_special(): unknown special prop %d\n", prop );
return 0;
}
inline SURF_PROPS* map_get_props( WORLD_MAP* m, I32 idx ) {
return idx < 0 ?
map_props_get_special( m, idx ) :
&m->props[idx];
}
inline SURF_PROPS* wall_get_props( WORLD_MAP* w, MAP_WALL* s ) {
return s->propid < 0 ?
map_props_get_special( w, s->propid ) :
&w->props[s->propid];
}
inline SURF_PROPS* polygon_get_props( WORLD_MAP* w, MAP_POLYGON* s ) {
return s->propid < 0 ?
map_props_get_special( w, s->propid ) :
&w->props[s->propid];
}
|