#pragma once #include "../../util/allocator.h" #include "../../util/vector.h" #include "../../util/color.h" #include "../../util/fnv.h" #include "../../editor/properties.h" enum MapPropId_t { MAPPROP_SKYBOX = -1, MAPPROP_CLIPBRUSH = -2, }; struct SURF_PROPS : public EOBJECT { EPROP( GL_TEX2D*, tex, {}, "texture" ); EPROP( CLR, clr, {}, "color" ); }; struct MAP_VERTEX : public EOBJECT { EPROP( VEC3, pos, {}, "position" ); EPROP_RANGED_STEP( VEC2, uv, {}, "uv", 0.f, 1.f, 0.025f ); EPROP( CLR, clr, {}, "color" ); EPROP_RO( VEC3, normal, {}, "normal" ); }; enum MapPolygonType_t { MPT_FLOOR, MPT_CEILING }; struct MAP_PROPREF { operator I32&() { return id; } operator I32() const { return id; } MAP_PROPREF() {} MAP_PROPREF( U32 id ) : id( id ) {} I32 id; }; struct MAP_POLYGON : public EOBJECT { EPROP( MAP_PROPREF, propid, {}, "prop id" ); EPROP( LIST, vertices, {}, "vertices" ); EPROP_RO( VEC3, mins, {}, "mins" ); EPROP_RO( VEC3, maxs, {}, "maxs" ); U8 type; }; struct MAP_WALL : public EOBJECT { EPROP( MAP_PROPREF, propid, {}, "prop id" ); EPROP( VEC3, start, {}, "start pos" ); EPROP( VEC3, end, {}, "end pos" ); EPROP_RANGED_STEP( VEC2, uvstart, {}, "uv start offset", 0.f, 1.f, 0.025f ); EPROP_RANGED_STEP( VEC2, uvend, {}, "uv end offset", 0.f, 1.f, 0.025f ); }; struct MAP_TEXTURE_ENTRY { char name[256]; struct GL_TEX2D* tex; FNV1A hash; }; struct MAP_SPRITE : public EOBJECT { EPROP( GL_TEX2D*, tex, {}, "texture" ); EPROP( VEC3, pos, {}, "position" ); EPROP_RANGED( VEC2, size, {}, "size", 0.25f, INFINITY ); EPROP( CLR, clr, {}, "color" ); }; struct MAP_ENTITY : public EOBJECT { EPROP( VEC3, pos, {}, "position" ); EPROP( U32, classid, {}, "entity class" ); EPROP( LIST, props, {}, "entity properties" ); }; struct MAP_SKYBOX : public EOBJECT { EPROP( SURF_PROPS, props, {}, "skybox surface properties" ); MAP_WALL walls[4]; MAP_POLYGON polygons[2]; }; struct WORLD_MAP : public EOBJECT { EPROP_RO( STR, name, {}, "name" ); EPROP( VEC3, startpos, {}, "spawn position" ); EPROP( F32, startang, {}, "spawn angle" ); EPROP( LIST , walls, {}, "walls" ); EPROP( LIST, polygons, {}, "polygons" ); EPROP( LIST , sprites, {}, "sprites" ); EPROP( LIST , entities, {}, "entities" ); EPROP( LIST , props, {}, "surface properties" ); EPROP( MAP_SKYBOX, skybox, {}, "skybox" ); F32 w; F32 h; EPROP_RO( VEC3, mins, {}, "mins" ); EPROP_RO( VEC3, maxs, {}, "maxs" ); struct BSP* bsp{}; EPROP( LIST, textures, {}, "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]; }