From f8b92ce3aa08b1445c9f956d8166830946562d12 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 3 Sep 2025 20:10:09 +0200 Subject: a --- src/game/world/map.h | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 src/game/world/map.h (limited to 'src/game/world/map.h') 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 + +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 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 props; +}; + +struct MAP_SKYBOX { + SURF_PROPS props; + MAP_WALL walls[4]; + MAP_POLYGON polygons[2]; +}; + +struct WORLD_MAP { + LIST walls; + LIST polygons; + LIST sprites; + LIST props; + MAP_SKYBOX skybox; + F32 w; + F32 h; + + VEC3 mins; + VEC3 maxs; + char name[256]; + + VEC3 startpos; + F32 startang; + + struct BSP* bsp{}; + + LIST 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]; +} -- cgit v1.2.3