diff options
| author | day <day@national.shitposting.agency> | 2026-03-16 16:25:49 +0100 |
|---|---|---|
| committer | day <day@national.shitposting.agency> | 2026-03-16 16:25:49 +0100 |
| commit | 7f85c9fc75bd62ac09ea4457d3b17f85988fca66 (patch) | |
| tree | 15248e42bfafc6bd19e50c9010b701057958ff3a /src/game | |
| parent | 872c39b24ecf4063f785ff3e8b2f940acd8c2d59 (diff) | |
| parent | 991352b0d2767e6bd1a46f554db4ac9d208c13ad (diff) | |
Merge remote-tracking branch 'origin/master' into obj
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/world/map.cpp | 52 | ||||
| -rw-r--r-- | src/game/world/map.h | 87 |
2 files changed, 75 insertions, 64 deletions
diff --git a/src/game/world/map.cpp b/src/game/world/map.cpp index a44f191..7b8060b 100644 --- a/src/game/world/map.cpp +++ b/src/game/world/map.cpp @@ -1,4 +1,4 @@ -#include <cfloat> +#include <float.h> #include "map.h" #include "../../game.h" @@ -83,7 +83,7 @@ STAT map_polygon_verts_from_section( WORLD_MAP* m, MAP_POLYGON* p, CFG_SECTION* sprintf( vertsec, "%d", i ); CFG_SECTION* v = cfg_section( vertices, vertsec ); if( !v ) { - dlog( "map_polygon_verts_from_section() : missing vertex %d in polygon with propid %d in map %s\n", i, p->propid, m->name ); + dlog( "map_polygon_verts_from_section() : missing vertex %d in polygon with propid %d in map %s\n", i, p->propid.id, m->name.data ); continue; } @@ -92,7 +92,7 @@ STAT map_polygon_verts_from_section( WORLD_MAP* m, MAP_POLYGON* p, CFG_SECTION* CFG_CLR* clr = cfg_clr( v, "clr" ); if( !pos ) { - dlog( "map_polygon_verts_from_section() : missing pos for vertex %d in polygon with propid %d in map %s\n", i, p->propid, m->name ); + dlog( "map_polygon_verts_from_section() : missing pos for vertex %d in polygon with propid %d in map %s\n", i, p->propid.id, m->name.data ); return STAT_ERR; } @@ -104,7 +104,7 @@ STAT map_polygon_verts_from_section( WORLD_MAP* m, MAP_POLYGON* p, CFG_SECTION* } if( !p->vertices.size ) { - dlog( "map_polygon_verts_from_section() : invalid vertex count for polygon with propid %d in map %s\n", p->propid, m->name ); + dlog( "map_polygon_verts_from_section() : invalid vertex count for polygon with propid %d in map %s\n", p->propid.id, m->name.data ); return STAT_ERR; } @@ -126,7 +126,7 @@ void map_polygon_calc_bounds( MAP_POLYGON* p ) { STAT map_polygons_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* polygons, U32 polyc ) { if( !polyc ) { - dlog( "map_polygons_from_section() : no polygons in %s\n", m->name ); + dlog( "map_polygons_from_section() : no polygons in %s\n", m->name.data ); return STAT_OK; } @@ -138,20 +138,20 @@ STAT map_polygons_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* polygon sprintf( polysec, "%d", i ); CFG_SECTION* p = cfg_section( polygons, polysec ); if( !p ) { - dlog( "map_polygons_from_section() : missing polygon %d in %s\n", i, m->name ); + dlog( "map_polygons_from_section() : missing polygon %d in %s\n", i, m->name.data ); continue; } CFG_INT* propid = cfg_int( p, "propid" ); if( !propid ) { - dlog( "map_polygons_from_section() : missing propid for polygon %d in map %s\n", i, m->name ); + dlog( "map_polygons_from_section() : missing propid for polygon %d in map %s\n", i, m->name.data ); continue; } poly.propid = propid->value; CFG_INT* polytype = cfg_int( p, "type" ); if( !polytype ) { - dlog( "map_polygons_from_section() : missing polygon type for polygon %d in %s\n", i, m->name ); + dlog( "map_polygons_from_section() : missing polygon type for polygon %d in %s\n", i, m->name.data ); continue; } @@ -159,13 +159,13 @@ STAT map_polygons_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* polygon CFG_INT* vertc = cfg_int( p, "vertcount" ); if( !vertc || !vertc->value ) { - dlog( "map_polygons_from_section() : missing vertex count for polygon %d in %s\n", i, m->name ); + dlog( "map_polygons_from_section() : missing vertex count for polygon %d in %s\n", i, m->name.data ); continue; } CFG_SECTION* vertices = cfg_section( p, "vertices" ); if( !vertices ) { - dlog( "map_polygons_from_section() : missing vertices for polygon %d in %s", i, m->name ); + dlog( "map_polygons_from_section() : missing vertices for polygon %d in %s", i, m->name.data ); continue; } @@ -182,7 +182,7 @@ STAT map_polygons_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* polygon STAT map_walls_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* walls, U32 wallc ) { if( !wallc ) { - dlog( "map_walls_from_section() : no walls in %s\n", m->name ); + dlog( "map_walls_from_section() : no walls in %s\n", m->name.data ); return STAT_OK; } @@ -194,7 +194,7 @@ STAT map_walls_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* walls, U32 sprintf( wallsec, "%d", i ); CFG_SECTION* w = cfg_section( walls, wallsec ); if( !w ) { - dlog( "map_walls_from_section() : missing wall %d in %s\n", i, m->name ); + dlog( "map_walls_from_section() : missing wall %d in %s\n", i, m->name.data ); continue; } @@ -203,7 +203,7 @@ STAT map_walls_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* walls, U32 CFG_INT* prop = cfg_int( w, "propid" ); if( !start || !end || !prop ) { - dlog( "map_walls_from_section() : bad wall definition in %s idx %d [%p %p %p]\n", m->name, i, start, end, prop ); + dlog( "map_walls_from_section() : bad wall definition in %s idx %d [%p %p %p]\n", m->name.data, i, start, end, prop ); continue; } @@ -221,7 +221,7 @@ STAT map_walls_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* walls, U32 STAT map_props_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* props, U32 propc ) { if( !propc ) { - dlog( "map_props_from_section() : no props in %s\n", m->name ); + dlog( "map_props_from_section() : no props in %s\n", m->name.data ); return STAT_ERR; } @@ -233,7 +233,7 @@ STAT map_props_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* props, U32 sprintf( propsec, "%d", i ); CFG_SECTION* p = cfg_section( props, propsec ); if( !p ) { - dlog( "map_props_from_section() : missing prop %d in %s\n", i, m->name ); + dlog( "map_props_from_section() : missing prop %d in %s\n", i, m->name.data ); continue; } @@ -261,7 +261,7 @@ STAT map_props_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* props, U32 STAT map_sprites_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* sprites, U32 spritec ) { if( !spritec ) { - dlog( "map_sprites_from_section() : no sprites in %s\n", m->name ); + dlog( "map_sprites_from_section() : no sprites in %s\n", m->name.data ); return STAT_OK; } @@ -273,7 +273,7 @@ STAT map_sprites_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* sprites, sprintf( spritesec, "%d", i ); CFG_SECTION* s = cfg_section( sprites, spritesec ); if( !s ) { - dlog( "map_sprites_from_section() : missing sprite %d in %s\n", i, m->name ); + dlog( "map_sprites_from_section() : missing sprite %d in %s\n", i, m->name.data ); continue; } @@ -283,7 +283,7 @@ STAT map_sprites_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* sprites, CFG_VEC2* size = cfg_vec2( s, "size" ); if( !tex || !pos || !size ) { - dlog( "map_sprites_from_section() : invalid sprite %d in %s\n", i, m->name ); + dlog( "map_sprites_from_section() : invalid sprite %d in %s\n", i, m->name.data ); continue; } @@ -305,7 +305,7 @@ STAT map_sprites_from_section( WORLD_MAP* m, GAME_DATA* g, CFG_SECTION* sprites, STAT map_entities_from_section( WORLD_MAP* m, GAME_DATA*, CFG_SECTION* entities, U32 entityc ) { if( !entityc ) { - dlog( "map_entities_from_section() : no entities in %s\n", m->name ); + dlog( "map_entities_from_section() : no entities in %s\n", m->name.data ); return STAT_OK; } @@ -317,14 +317,14 @@ STAT map_entities_from_section( WORLD_MAP* m, GAME_DATA*, CFG_SECTION* entities, sprintf( entitysec, "%d", i ); CFG_SECTION* s = cfg_section( entities, entitysec ); if( !s ) { - dlog( "map_entities_from_section() : missing entity %d in %s\n", i, m->name ); + dlog( "map_entities_from_section() : missing entity %d in %s\n", i, m->name.data ); continue; } CFG_INT* classid = cfg_int( s, "classid" ); CFG_VEC3* pos = cfg_vec3( s, "pos" ); if( !classid || !pos ) { - dlog( "map_entities_from_section() : invalid entity %d in %s\n", i, m->name ); + dlog( "map_entities_from_section() : invalid entity %d in %s\n", i, m->name.data ); continue; } @@ -380,24 +380,24 @@ void map_gen_skybox( WORLD_MAP* m ) { VEC3 maxs = m->maxs + VEC3( SKYBOX_OFFSET, SKYBOX_OFFSET, SKYBOX_OFFSET ); m->skybox.walls[0] = { + .propid = MAPPROP_SKYBOX, .start = { mins.x, mins.y, mins.z }, .end = { maxs.x, mins.y, maxs.z - mins.z }, - .propid = MAPPROP_SKYBOX }; m->skybox.walls[1] = { + .propid = MAPPROP_SKYBOX, .start = { maxs.x, mins.y, mins.z }, .end = { maxs.x, maxs.y, maxs.z - mins.z }, - .propid = MAPPROP_SKYBOX }; m->skybox.walls[2] = { + .propid = MAPPROP_SKYBOX, .start = { maxs.x, maxs.y, mins.z }, .end = { mins.x, maxs.y, maxs.z - mins.z }, - .propid = MAPPROP_SKYBOX }; m->skybox.walls[3] = { + .propid = MAPPROP_SKYBOX, .start = { mins.x, maxs.y, mins.z }, .end = { mins.x, mins.y, maxs.z - mins.z }, - .propid = MAPPROP_SKYBOX }; VEC2 floor[] = { @@ -496,7 +496,7 @@ WORLD_MAP* map_from_file( GAME_DATA* game, const char* path ) { WORLD_MAP* m = new WORLD_MAP; const char* name = file_path_last_of( path ); - strcpy( m->name, name ); + m->name = name; CFG_SECTION* s = cfg_section( root, "map" ); if( !s ) { dlog( errstr, "map", path ); delete m; return 0; } diff --git a/src/game/world/map.h b/src/game/world/map.h index 2b8a7a5..21bfa1f 100644 --- a/src/game/world/map.h +++ b/src/game/world/map.h @@ -6,23 +6,22 @@ #include "../../util/fnv.h" #include "../../editor/properties.h" -#include <string.h> - enum MapPropId_t { MAPPROP_SKYBOX = -1, MAPPROP_CLIPBRUSH = -2, }; struct SURF_PROPS : public EOBJECT { - struct GL_TEX2D* tex; - CLR clr; + EPROP( GL_TEX2D*, tex, {}, "texture" ); + EPROP( CLR, clr, {}, "color" ); }; struct MAP_VERTEX : public EOBJECT { - VEC3 pos; - VEC3 normal; - VEC2 uv; - CLR clr; + 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 { @@ -30,23 +29,33 @@ enum MapPolygonType_t { 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 { - LIST<MAP_VERTEX> vertices; + EPROP( MAP_PROPREF, propid, {}, "prop id" ); + EPROP( LIST<MAP_VERTEX>, vertices, {}, "vertices" ); - VEC3 mins; - VEC3 maxs; + EPROP_RO( VEC3, mins, {}, "mins" ); + EPROP_RO( VEC3, maxs, {}, "maxs" ); U8 type; - I32 propid; }; struct MAP_WALL : public EOBJECT { - VEC3 start; - VEC3 end; + EPROP( MAP_PROPREF, propid, {}, "prop id" ); - VEC2 uvstart; - VEC2 uvend; + EPROP( VEC3, start, {}, "start pos" ); + EPROP( VEC3, end, {}, "end pos" ); - I32 propid; + 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 { @@ -56,40 +65,42 @@ struct MAP_TEXTURE_ENTRY { }; struct MAP_SPRITE : public EOBJECT { - VEC3 pos; - VEC2 size; - CLR clr; - GL_TEX2D* tex; + EPROP( GL_TEX2D*, tex, {}, "texture" ); + EPROP( VEC3, pos, {}, "position" ); + EPROP_RANGED( VEC2, size, {}, "size", 0.25f, INFINITY ); + EPROP( CLR, clr, {}, "color" ); }; -struct MAP_ENTITY { - VEC3 pos; - U32 classid; - LIST<struct OBJECT_PROP*> props; +struct MAP_ENTITY : public EOBJECT { + EPROP( VEC3, pos, {}, "position" ); + EPROP( U32, classid, {}, "entity class" ); + + EPROP( LIST<struct OBJECT_PROP*>, props, {}, "entity properties" ); }; struct MAP_SKYBOX : public EOBJECT { - SURF_PROPS props; + EPROP( SURF_PROPS, props, {}, "skybox surface properties" ); MAP_WALL walls[4]; MAP_POLYGON polygons[2]; }; struct WORLD_MAP : public EOBJECT { - LIST<MAP_WALL> walls; - LIST<MAP_POLYGON> polygons; - LIST<MAP_SPRITE> sprites; - LIST<MAP_ENTITY> entities; - LIST<SURF_PROPS> props; - MAP_SKYBOX skybox; + EPROP_RO( STR, name, {}, "name" ); + EPROP( VEC3, startpos, {}, "spawn position" ); + EPROP( F32, startang, {}, "spawn angle" ); + + EPROP( LIST<MAP_WALL> , walls, {}, "walls" ); + EPROP( LIST<MAP_POLYGON>, polygons, {}, "polygons" ); + EPROP( LIST<MAP_SPRITE> , sprites, {}, "sprites" ); + EPROP( LIST<MAP_ENTITY> , entities, {}, "entities" ); + EPROP( LIST<SURF_PROPS> , props, {}, "surface properties" ); + + EPROP( MAP_SKYBOX, skybox, {}, "skybox" ); F32 w; F32 h; - VEC3 mins; - VEC3 maxs; - char name[256]; - - VEC3 startpos; - F32 startang; + EPROP_RO( VEC3, mins, {}, "mins" ); + EPROP_RO( VEC3, maxs, {}, "maxs" ); struct BSP* bsp{}; |
