From ce3348883350d21821aed720a098b8515077564d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 16:32:40 +0400 Subject: fix(render): reveal buildings when scripted construction ends Publish completed constructions with the same fresh world snapshot that the render tick consumes. Activate their prepared render roots and collision bindings through the existing spawn path. An unmodified Third Part start shows the actual factory appearing on the site between two Vulkan frames. Terrain rebuilding for a new basement remains open. --- apps/fparkan-game/src/main.rs | 6 ++++++ crates/fparkan-runtime/src/clan_ai_events.rs | 11 +++++++---- crates/fparkan-runtime/src/construction.rs | 28 ++++++++++++++++++++-------- crates/fparkan-runtime/src/lib.rs | 8 +++++++- docs/tomes/06-behavior.md | 5 +++-- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 8c2e12f9..4a76f016 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -11201,6 +11201,12 @@ impl StaticVulkanApp { .iter() .map(|unit| (unit, "factory_robot_completed")), ) + .chain( + frame + .constructed_buildings + .iter() + .map(|building| (building, "building_constructed")), + ) .chain(deployed_mine.iter().map(|unit| (unit, "mine_deployed"))) { let index = reinforcement.object_index; diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs index 0ccebdcb..e544a9d9 100644 --- a/crates/fparkan-runtime/src/clan_ai_events.rs +++ b/crates/fparkan-runtime/src/clan_ai_events.rs @@ -88,10 +88,13 @@ pub(super) fn resolve_captures( Ok(captured) } -pub(super) fn tick(engine: &mut crate::Engine, now_ms: u32) -> Vec { +pub(super) fn tick( + engine: &mut crate::Engine, + now_ms: u32, +) -> (Vec, Vec) { let mut notices = Vec::new(); let Some(loaded) = &mut engine.loaded else { - return notices; + return (notices, Vec::new()); }; crate::laboratory::tick( loaded, @@ -99,7 +102,7 @@ pub(super) fn tick(engine: &mut crate::Engine, now_ms: u32) -> Vec Vec, now_ms: u32, -) { +) -> Vec { + let mut constructed = Vec::new(); let mut index = 0; while let Some(task) = mission.construction.tasks.get_mut(index) { let owned = @@ -286,14 +287,16 @@ pub(super) fn tick( patrol.clear_move(task.builder); } if finish { - if let Err(error) = complete(mission, world, &task, production.as_deref_mut()) { - eprintln!( + match complete(mission, world, &task, production.as_deref_mut()) { + Ok(building) => constructed.push(building), + Err(error) => eprintln!( "script_building_construction_failed clan={} builder={} reason={error}", task.owner.0, task.builder.slot - ); + ), } } } + constructed } fn complete( @@ -301,7 +304,7 @@ fn complete( world: &mut World, task: &Task, production: Option<&mut crate::production::Production>, -) -> Result<(), crate::EngineError> { +) -> Result { let index = crate::behavior_ore_index_for_handle(&mission.behavior_ore_states, task.builder) .map_err(crate::EngineError::Production)?; let stock = f32::from_bits(mission.behavior_ore_states[index].current_ore_bits); @@ -382,7 +385,11 @@ fn complete( "script_building_constructed clan={} builder={} building={} class={class:#010x}", task.owner.0, task.builder.slot, handle.slot ); - Ok(()) + Ok(SpawnedUnit { + object_index: task.slot, + handle, + clan: task.owner.0, + }) } fn destination( @@ -514,13 +521,18 @@ mod tests { } } for now in (0..=900_000).step_by(100) { - crate::frame(&mut engine, now).unwrap(); + let frame = crate::frame(&mut engine, now).unwrap(); let loaded = engine.loaded.as_ref().unwrap(); if let Some(handle) = loaded.object_drafts[start..end].iter().find_map(|draft| { (draft.unit_dat_header_flags == Some(0x8000_0010)) .then(|| handle_by_original_id(&engine.world, draft.original_id.unwrap())) .flatten() }) { + assert!(frame + .constructed_buildings + .iter() + .any(|building| building.handle == handle)); + assert!(frame.snapshot.objects.contains(&handle)); assert_eq!( identity_metadata(&engine.world, handle).unwrap().owner_id, Some(OwnerId(1)) diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 3b177b0a..312774ff 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -1411,6 +1411,8 @@ pub struct FrameResult { pub autodemo_reinforcement_unavailable: usize, /// Robot completed by a player factory order on this tick. pub produced_unit: Option, + /// Buildings completed by scripted construction on this tick. + pub constructed_buildings: Vec, /// Diagnostic for a production order whose unit could not be created. pub production_failure: Option, /// Technology completed by a player laboratory order on this tick. @@ -2949,7 +2951,10 @@ pub fn step_headless( .loaded .as_mut() .and_then(|state| state.tick_mission_event(&engine.world, queue_time_ms)); - let clan_notices = clan_ai_events::tick(engine, queue_time_ms); + let (clan_notices, constructed_buildings) = clan_ai_events::tick(engine, queue_time_ms); + if !constructed_buildings.is_empty() { + snapshot = fparkan_world::world_snapshot(&engine.world, snapshot.events); + } let researched_component = engine .loaded .as_mut() @@ -2963,6 +2968,7 @@ pub fn step_headless( autodemo_reinforcements, autodemo_reinforcement_unavailable, produced_unit, + constructed_buildings, production_failure, researched_component, player_footstep: None, diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md index 59620fd4..61490626 100644 --- a/docs/tomes/06-behavior.md +++ b/docs/tomes/06-behavior.md @@ -777,8 +777,9 @@ RVA `0x28800` проверяет детали и считает цену. Ког В FParkan сценарий этой миссии со штатного старта уже ставит завод и лабораторию. Готовое здание получает контроллер, запас руды и логический ID, а завод входит в список производства и принимает заказ транспортника. -Резервные модели будущих зданий не вырезают фундаменты в стартовом рельефе. -Перестройка рельефа при их появлении ещё открыта. +В кадре завершения стройки подготовленная модель занимает площадку, и её +коллизия становится доступна игроку. Вырезание подземной части фундамента +при завершении стройки ещё открыто. ### Первый запуск сценария -- cgit v1.2.3