diff options
| author | navewindre <boneyaard@gmail.com> | 2025-09-03 20:10:09 +0200 |
|---|---|---|
| committer | navewindre <boneyaard@gmail.com> | 2025-09-03 20:10:09 +0200 |
| commit | f8b92ce3aa08b1445c9f956d8166830946562d12 (patch) | |
| tree | 94e63a5aec9f8f52b577f56799e0c9201fd976a5 /src/game/world/map.h | |
a
Diffstat (limited to 'src/game/world/map.h')
| -rw-r--r-- | src/game/world/map.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/game/world/map.h b/src/game/world/map.h new file mode 100644 index 0000000..29022db --- /dev/null +++ b/src/game/world/map.h @@ -0,0 +1,137 @@ +#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 { + 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<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]; +} |
