Skip to content

Commit

Permalink
content: Headquarter structure (#1261)
Browse files Browse the repository at this point in the history
* geo: Increase maximum blocker size

* asset: Support emissive in renderable trait

* assets: Add authorized asset origin

* readme: Update asset license info

* scene: Load location in edit mode

* asset: Generate prefab schema

* content: Add headquarter structure

* geo: Fix too high blocker count with overlapping shapes
  • Loading branch information
BastianBlokland authored Feb 3, 2025
1 parent 15bb95a commit 0c839bc
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ To run all the tests there's an overarching `test` target.
Assets under `assets/external/` are not distributed as part of this repository and thus not covered by the license.
Instead they are downloaded as part of the build process, all credits go to the original creators.

Licenses for the individual assets can be found at: [Asset License](https://www.bastian.tech/assets/license.txt).
License information:
[Asset Licenses 1](https://bastian.tech/assets/license.txt)
[Asset Licenses 2](https://bastian.tech/assets-auth/license.txt).
13 changes: 13 additions & 0 deletions assets/fetch.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@
"water_tower/water_tower_2_normal.tga",
"water_tower/water_tower.obj"
]
},
{
"host": "bastian.tech",
"license": "/assets-auth/license.txt",
"rootUri": "/assets-auth/",
"authUser": "volo",
"authPass": "kqT6YwEgxfN7rmSv",
"cacheTime": 86400,
"assets": [
"headquarter/headquarter.glb",
"headquarter/headquarter_color_rough.png",
"headquarter/headquarter_normal_emissive.png"
]
}
]
}
42 changes: 42 additions & 0 deletions assets/global/game.prefabs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,48 @@
{ "$type": "AssetPrefabTrait_Status", "supportedStatus": [ "Burning" ] }
]
},
{
"name": "StructureHeadquarter",
"traits": [
{ "$type": "AssetPrefabTrait_Name", "name": "Headquarter" },
{ "$type": "AssetPrefabTrait_SetMember", "sets": [ "destructible", "unit", "minimap", "structure" ] },
{
"$type": "AssetPrefabTrait_Renderable",
"graphic": "graphics/game/structure_headquarter.graphic",
"emissive": 0.2
},
{ "$type": "AssetPrefabTrait_Vision", "radius": 35 },
{
"$type": "AssetPrefabTrait_Health",
"amount": 10000,
"deathDestroyDelay": 0.8,
"deathEffectPrefab": "DeathStructure"
},
{
"$type": "AssetPrefabTrait_Collision",
"navBlocker": true,
"shapes": [
{
"$type": "AssetPrefabShape_Box",
"min": { "x": -4.0, "y": 0, "z": -3.3 },
"max": { "x": 4.0, "y": 11.5, "z": 5.0 }
},
{
"$type": "AssetPrefabShape_Box",
"min": { "x": -10.0, "y": 0, "z": -11 },
"max": { "x": 10.0, "y": 2, "z": 11.0 }
}
]
},
{
"$type": "AssetPrefabTrait_Location", "aimTarget": {
"min": { "x": -9, "y": 0.5, "z": -10 },
"max": { "x": 9, "y": 2, "z": 10 }
}
},
{ "$type": "AssetPrefabTrait_Status", "supportedStatus": [ "Burning" ] }
]
},
{
"name": "StructureHospital",
"traits": [
Expand Down
18 changes: 18 additions & 0 deletions assets/graphics/game/structure_headquarter.graphic
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"pass": "Geometry",
"shaders": [
{ "program": "shaders/standard.vert" },
{
"program": "shaders/standard.frag",
"overrides": [
{ "name": "normalMap", "binding": 0, "value": 1 },
{ "name": "emissiveMap", "binding": 2, "value": 1 }
]
}
],
"samplers": [
{ "texture": "external/headquarter/headquarter_color_rough.png", "anisotropy": "x2" },
{ "texture": "external/headquarter/headquarter_normal_emissive.png", "anisotropy": "x2" }
],
"mesh": "external/headquarter/headquarter.glb"
}
3 changes: 2 additions & 1 deletion assets/schemas/prefabs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
"additionalProperties": false,
"properties": {
"$type": { "const": "AssetPrefabTrait_Renderable" },
"graphic": { "title": "AssetRef", "description": "Asset reference", "$ref": "#/$defs/AssetRef" }
"graphic": { "title": "AssetRef", "description": "Asset reference", "$ref": "#/$defs/AssetRef" },
"emissive": { "title": "f32", "type": "number" }
},
"required": [ "$type", "graphic" ]
},
Expand Down
7 changes: 7 additions & 0 deletions assets/scripts/import/mesh/2_scale.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Mesh scale import rules.
*/

if (asset_id_match("external/headquarter/*")) {
vertex_scale(0.05)
}
1 change: 1 addition & 0 deletions libs/asset/include/asset_prefab.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef struct {

typedef struct {
AssetRef graphic;
f32 emissive; // Normalized.
} AssetPrefabTraitRenderable;

typedef struct {
Expand Down
1 change: 1 addition & 0 deletions libs/asset/src/loader_prefab.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ void asset_data_init_prefab(void) {

data_reg_struct_t(g_dataReg, AssetPrefabTraitRenderable);
data_reg_field_t(g_dataReg, AssetPrefabTraitRenderable, graphic, g_assetRefType);
data_reg_field_t(g_dataReg, AssetPrefabTraitRenderable, emissive, data_prim_t(f32), .flags = DataFlags_Opt);

data_reg_struct_t(g_dataReg, AssetPrefabTraitVfx);
data_reg_field_t(g_dataReg, AssetPrefabTraitVfx, asset, g_assetRefType);
Expand Down
20 changes: 13 additions & 7 deletions libs/geo/src/nav.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define geo_nav_occupants_max 4096
#define geo_nav_occupants_per_cell 3
#define geo_nav_blockers_max 2048
#define geo_nav_blocker_max_cells 256
#define geo_nav_blocker_max_cells 512
#define geo_nav_island_max (u8_max - 1)
#define geo_nav_island_blocked u8_max
#define geo_nav_island_itr_per_tick 10000
Expand Down Expand Up @@ -1400,8 +1400,10 @@ static void geo_nav_block_box(
for (u16 x = region.min.x; x != region.max.x; ++x, ++cellIndex) {
const f32 cellY = grid->cellY[cellIndex];
if (box->max.y > cellY && box->min.y < (cellY + grid->cellHeight)) {
nav_cell_block(grid, cellIndex);
nav_bit_set(regionBits, indexInRegion);
if (!nav_bit_test(regionBits, indexInRegion)) {
nav_cell_block(grid, cellIndex);
nav_bit_set(regionBits, indexInRegion);
}
}
++indexInRegion;
}
Expand All @@ -1417,8 +1419,10 @@ static void geo_nav_block_box_rotated(
const GeoNavCell cell = {.x = x, .y = y};
const GeoBox cellBox = nav_cell_box(grid, cell);
if (geo_box_rotated_overlap_box(box, &cellBox)) {
nav_cell_block(grid, cellIndex);
nav_bit_set(regionBits, indexInRegion);
if (!nav_bit_test(regionBits, indexInRegion)) {
nav_cell_block(grid, cellIndex);
nav_bit_set(regionBits, indexInRegion);
}
}
++indexInRegion;
}
Expand All @@ -1434,8 +1438,10 @@ static void geo_nav_block_sphere(
const GeoNavCell cell = {.x = x, .y = y};
const GeoBox cellBox = nav_cell_box(grid, cell);
if (geo_sphere_overlap_box(sphere, &cellBox)) {
nav_cell_block(grid, cellIndex);
nav_bit_set(regionBits, indexInRegion);
if (!nav_bit_test(regionBits, indexInRegion)) {
nav_cell_block(grid, cellIndex);
nav_bit_set(regionBits, indexInRegion);
}
}
++indexInRegion;
}
Expand Down
8 changes: 7 additions & 1 deletion libs/scene/src/prefab.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static const u64 g_prefabVariantTraitMask[ScenePrefabVariant_Count] = {
(u64_lit(1) << AssetPrefabTrait_Property) |
(u64_lit(1) << AssetPrefabTrait_Decal) |
(u64_lit(1) << AssetPrefabTrait_LightPoint) |
(u64_lit(1) << AssetPrefabTrait_Location) |
(u64_lit(1) << AssetPrefabTrait_LightDir) |
(u64_lit(1) << AssetPrefabTrait_LightAmbient) |
(u64_lit(1) << AssetPrefabTrait_Collision) |
Expand Down Expand Up @@ -418,7 +419,12 @@ static void setup_renderable(PrefabSetupContext* ctx, const AssetPrefabTraitRend
color = geo_color_white;
}
ecs_world_add_t(
ctx->world, ctx->entity, SceneRenderableComp, .graphic = t->graphic.entity, .color = color);
ctx->world,
ctx->entity,
SceneRenderableComp,
.graphic = t->graphic.entity,
.emissive = t->emissive,
.color = color);
}

static void setup_vfx_system(PrefabSetupContext* ctx, const AssetPrefabTraitVfx* t) {
Expand Down

0 comments on commit 0c839bc

Please sign in to comment.