Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/photo/gta6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub(super) fn photograph(
};
let (models, kits) = super::timing::time("04 gta6: models", || {
crate::state::gta6_models_and_kits(
&state.gta6.install,
&state.gta6,
&root,
under,
only.as_ref(),
Expand All @@ -204,15 +204,15 @@ pub(super) fn photograph(
root.display()
);
if ctx.wheels.is_some() {
let found = crate::state::gta6_models(&state.gta6.install, &root, WHEELS_UNDER, None)?;
let found = crate::state::gta6_models(&state.gta6, &root, WHEELS_UNDER, None)?;
println!("{} wheel models", found.len());
ctx.wheel_models = Some(found.into_iter().map(|m| (m.name.clone(), m)).collect());
}
if ctx.shaded {
// A part's layers come from the build's layered materials, which a worker reads once: a
// picture drawn before it ends shows every part with no material.
let until = Instant::now() + FIRST_SETTLE;
while crate::state::gta6_shaders::layer_index::under(&root).is_none()
while crate::state::gta6_shaders::layer_index::under(&state.gta6.drawable, &root).is_none()
&& Instant::now() < until
{
std::thread::sleep(Duration::from_millis(50));
Expand Down Expand Up @@ -319,7 +319,7 @@ pub(super) fn photograph(
let file = std::fs::File::open(&model.archive).ok()?;
Some(crate::state::gta6_weapon_parts::read_part(&file, model.offset)?.1)
};
crate::render::gta6_drawable::wheel_parts(doc, wheels, &read)
crate::render::gta6_drawable::wheel_parts(&state.gta6.rpf9, doc, wheels, &read)
});
bridge.gta6_overrides_mut().set_beside(beside);
if ctx.shaded {
Expand Down Expand Up @@ -600,15 +600,15 @@ fn photograph_kits(
// A part's maps are the ones its state names in the build's asset lists, which a worker reads.
let until = Instant::now() + FIRST_SETTLE;
let lists = loop {
match index::under(root) {
match index::under(&state.gta6.drawable, root) {
Some(read) => break read,
None if Instant::now() < until => std::thread::sleep(Duration::from_millis(50)),
None => return Err("the build's ped asset lists were not read in time".into()),
}
};
println!("the build's ped asset lists are read");
let poses = crate::render::gta6_ped_pose::load_human_poses(root);
let hair_lib = crate::render::gta6_hair::HairLibrary::load(root);
let poses = crate::render::gta6_ped_pose::load_human_poses(&state.gta6.rpf9, root);
let hair_lib = crate::render::gta6_hair::HairLibrary::load(&state.gta6.rpf9, root);
let mut settle = FIRST_SETTLE;
for (name, kit) in kits {
let target = options
Expand Down Expand Up @@ -722,11 +722,14 @@ fn photograph_kits(
overrides.ped_pose = pose;
overrides.set_beside(Some(beside));
}
index::dress(Some(
(parts.iter())
.map(|(model, textures)| (drawable_word(&model.name), textures.clone()))
.collect(),
));
index::dress(
&state.gta6.drawable,
Some(
(parts.iter())
.map(|(model, textures)| (drawable_word(&model.name), textures.clone()))
.collect(),
),
);
let look = Some(kit_look(dressing.kind));
let made = state.hold_gta6_model(parts[0].0, root).and_then(|id| {
state.active_document = Some(id);
Expand All @@ -735,7 +738,7 @@ fn photograph_kits(
state.let_go(&[id]);
drawn.and_then(|image| save(&image, &target))
});
index::dress(None);
index::dress(&state.gta6.drawable, None);
tally.record(name, made);
}
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions src/render/gta6_drawable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) fn meshes(req: &GeometryRequest<'_>) -> Vec<MeshUpload> {
let posed = crate::state::gta6_anim_play::gta6_posed(req.state);
let own = posed
.as_ref()
.and_then(|_| own_skeleton(&req.state.gta6.anim, req.doc, req.selection));
.and_then(|_| own_skeleton(&req.state.gta6, req.doc, req.selection));
let posing = (posed.as_ref()).map(|p| (p.skeleton, own.as_ref()));
let (lod, channel) = (
req.state.preview_scene.lod,
Expand Down Expand Up @@ -221,7 +221,7 @@ pub(crate) fn parts_drawn(
doc: &crate::state::Document,
) -> Option<Arc<Vec<Part>>> {
(state.preview_scene.assemble_parts)
.then(|| crate::state::gta6_weapon_parts::of(doc.path.as_deref()?))
.then(|| crate::state::gta6_weapon_parts::of(&state.gta6.drawable, doc.path.as_deref()?))
.flatten()
}

Expand Down Expand Up @@ -385,11 +385,11 @@ pub(crate) fn drawn_geometries(
/// The skeleton of a scanned drawable or fragment, or of the dictionary entry `selection` is in,
/// read when it opened.
fn own_skeleton(
anim: &crate::state::gta6::anim::AnimSession,
gta6: &crate::state::gta6::session::Gta6Session,
doc: &crate::state::Document,
selection: Option<crate::state::SelectionKey>,
) -> Option<Skeleton> {
crate::state::gta6_entry_skeletons::shown(anim, doc, selection)
crate::state::gta6_entry_skeletons::shown(gta6, doc, selection)
}

/// The level of detail `lod`, or the first where that one has no models.
Expand Down Expand Up @@ -449,7 +449,7 @@ pub(crate) fn meshes_at(

/// Each geometry of the drawn level of `doc` that does not join `skeleton`: its model, its index and why.
pub(crate) fn unjoined(
anim: &crate::state::gta6::anim::AnimSession,
gta6: &crate::state::gta6::session::Gta6Session,
doc: &crate::state::Document,
selection: Option<crate::state::SelectionKey>,
lod: usize,
Expand All @@ -461,7 +461,7 @@ pub(crate) fn unjoined(
let Some(drawable) = drawable_of(resource, selection) else {
return Vec::new();
};
let own = own_skeleton(anim, doc, selection);
let own = own_skeleton(gta6, doc, selection);
let mut out = Vec::new();
for (m, model) in drawn_level(drawable, lod).enumerate() {
for (g, geometry) in model.geometries.iter().enumerate() {
Expand Down
27 changes: 18 additions & 9 deletions src/render/gta6_drawable/wheels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ pub(crate) type Wheel = (String, u32, [f32; 4], f32, [u8; 3]);
/// Each of `wheels` as a part on its bone of `doc`'s skeleton at bind, its model read by `read`;
/// a wheel whose bone the skeleton lacks, or whose model does not read, is left out.
pub(crate) fn wheel_parts(
rpf9: &crate::state::rpf::Rpf9Session,
doc: &crate::state::Document,
wheels: &[Wheel],
read: &dyn Fn(&str) -> Option<Resource>,
) -> Vec<Part> {
let skeleton =
(doc.path.as_deref()).and_then(|path| crate::state::rpf9_scan::scanned_skeleton(path).ok());
let skeleton = (doc.path.as_deref())
.and_then(|path| crate::state::rpf9_scan::scanned_skeleton(rpf9, path).ok());
let Some(skeleton) = skeleton else {
return Vec::new();
};
let world = or_anim::gta6::skeleton(&skeleton).bind_world;
let sizes = wheel_sizes(doc);
let sizes = wheel_sizes(rpf9, doc);
let read: Vec<Option<Resource>> = wheels.iter().map(|(model, ..)| read(model)).collect();
// A wheel's models are made one across and are sized by their tyre: its radius to the
// radius the vehicle states for the bone, its width along the axle, which is the models' x,
Expand Down Expand Up @@ -60,7 +61,10 @@ pub(crate) fn wheel_parts(
/// The radius and the width the bound of each wheel of `doc` states, by its bone's hash: a
/// disc's radius and twice its margin, a cylinder's radius and height, a frustum's wider radius
/// and height. A bone with several keeps the widest across.
fn wheel_sizes(doc: &crate::state::Document) -> std::collections::HashMap<u32, (f32, f32)> {
fn wheel_sizes(
rpf9: &crate::state::rpf::Rpf9Session,
doc: &crate::state::Document,
) -> std::collections::HashMap<u32, (f32, f32)> {
use or_io::gta6::headerless::ChildBound;
let mut sizes = std::collections::HashMap::new();
let DocPayload::Gta6Drawable(resource) = &doc.payload else {
Expand Down Expand Up @@ -96,7 +100,8 @@ fn wheel_sizes(doc: &crate::state::Document) -> std::collections::HashMap<u32, (
Some((bone, size(bound)?))
});
for (bone, (radius, width)) in of_bones.chain(of_children) {
let wheel = (fragment_bone_name(doc, bone)).is_some_and(|name| name.starts_with("wheel"));
let wheel =
(fragment_bone_name(rpf9, doc, bone)).is_some_and(|name| name.starts_with("wheel"));
let kept: &mut (f32, f32) = sizes.entry(bone).or_insert((0.0, 0.0));
if wheel && radius > kept.0 && width > 0.0 {
*kept = (radius, width);
Expand All @@ -107,8 +112,12 @@ fn wheel_sizes(doc: &crate::state::Document) -> std::collections::HashMap<u32, (
}

/// The name of the bone of `doc`'s skeleton whose hash is `hash`.
fn fragment_bone_name(doc: &crate::state::Document, hash: u32) -> Option<String> {
let skeleton = crate::state::rpf9_scan::scanned_skeleton(doc.path.as_deref()?).ok()?;
fn fragment_bone_name(
rpf9: &crate::state::rpf::Rpf9Session,
doc: &crate::state::Document,
hash: u32,
) -> Option<String> {
let skeleton = crate::state::rpf9_scan::scanned_skeleton(rpf9, doc.path.as_deref()?).ok()?;
let bone = skeleton.bones.iter().find(|bone| bone.hash == hash)?;
Some(bone.name.to_ascii_lowercase())
}
Expand Down Expand Up @@ -136,8 +145,8 @@ pub(crate) fn wheels(
wheels: &[Wheel],
read: &dyn Fn(&str) -> Option<Resource>,
) -> Vec<MeshUpload> {
let skeleton =
(doc.path.as_deref()).and_then(|path| crate::state::rpf9_scan::scanned_skeleton(path).ok());
let skeleton = (doc.path.as_deref())
.and_then(|path| crate::state::rpf9_scan::scanned_skeleton(&state.gta6.rpf9, path).ok());
let Some(skeleton) = skeleton else {
return Vec::new();
};
Expand Down
4 changes: 2 additions & 2 deletions src/render/gta6_hair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ pub(crate) struct HairLibrary {

impl HairLibrary {
/// Load the secondary-motion asset map, cloth entry index, and hair colour database from `root`.
pub(crate) fn load(root: &Path) -> Option<Self> {
let Ok(keys) = crate::state::rpf9_scan::rpf9_table::keys() else {
pub(crate) fn load(rpf9: &crate::state::rpf::Rpf9Session, root: &Path) -> Option<Self> {
let Ok(keys) = crate::state::rpf9_scan::rpf9_table::keys(rpf9) else {
tracing::warn!("could not load GTA VI keys to build hair library");
return None;
};
Expand Down
2 changes: 1 addition & 1 deletion src/render/gta6_meshlets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ pub(crate) fn meshlets(
&mut |drawable, models, placement| {
let name = drawable.name.as_str();
let sources = Sources {
shading: &gta6_shaders::shading,
shading: &|hash, data| gta6_shaders::shading(&state.gta6.drawable, hash, data),
effect_name: &|hash| effect_name(&state.gta6.bodies, hash),
map: &|key| session.decoded(key, || stored(key)),
layered: &|| gta6_layer_index::worn_as(state, name, true),
Expand Down
4 changes: 2 additions & 2 deletions src/render/gta6_ped_pose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ pub(crate) struct HumanPoses {
}

/// Load the canonical male and female standing neutral idle poses from `root`.
pub(crate) fn load_human_poses(root: &Path) -> HumanPoses {
let Ok(keys) = crate::state::rpf9_scan::rpf9_table::keys() else {
pub(crate) fn load_human_poses(rpf9: &crate::state::rpf::Rpf9Session, root: &Path) -> HumanPoses {
let Ok(keys) = crate::state::rpf9_scan::rpf9_table::keys(rpf9) else {
tracing::warn!("could not load GTA VI keys to build human standing poses");
return HumanPoses::default();
};
Expand Down
2 changes: 1 addition & 1 deletion src/render/viewport/bones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn gta6_rest(state: &AppState) -> Option<(DocumentId, Named, Arc<Skeleton>)> {
let named = entry.map_or(Named::Drawable, Named::Entry);
let data = entry.map_or(usize::MAX, |code| code as usize);
let skeleton = kept((doc.id, doc.payload_epoch(), data), || {
let read = shown(&state.gta6.anim, doc, selection)?;
let read = shown(&state.gta6, doc, selection)?;
(!read.bones.is_empty()).then(|| or_anim::gta6::skeleton(&read))
})?;
Some((doc.id, named, skeleton))
Expand Down
7 changes: 4 additions & 3 deletions src/render/viewport/game_shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ impl RenderBridge {
})
};
gta6_shaders::request(
&state.gta6.drawable,
&crate::render::gta6_meshlets::worn(state, self.gta6.overrides.beside()),
install,
self.gta6.hardware_adapter,
Expand All @@ -458,8 +459,8 @@ impl RenderBridge {
self.gta6.maps = Default::default();
self.start_decoding_gta6(state);
}
let running = gta6_shaders::running();
let pack = gta6_shaders::pack();
let running = gta6_shaders::running(&state.gta6.drawable);
let pack = gta6_shaders::pack(&state.gta6.drawable);
let key = MeshCacheKey::of(state, doc, pack.as_ref().map_or(0, |(number, _)| *number));
// A map learnt or decoded since the scene was bound is bound where it is read
self.take_on_gta6_maps(state, key);
Expand Down Expand Up @@ -561,7 +562,7 @@ impl RenderBridge {
);
}
let said = crate::render::gta6_shaded::said(
&gta6_shaders::status(hashes),
&gta6_shaders::status(&state.gta6.drawable, hashes),
drawn,
drawn + left_out.len(),
);
Expand Down
4 changes: 3 additions & 1 deletion src/render/viewport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ impl MeshCacheKey {
gta6_posed_on: crate::state::gta6_anim_play::gta6_model_drawn(state).or_else(|| {
crate::state::gta6_anim_play::gta6_posed(state).map(|p| (p.model, true))
}),
terrain_tiles: crate::state::gta6_shaders::terrain_tile::reads_ended(),
terrain_tiles: crate::state::gta6_shaders::terrain_tile::reads_ended(
&state.gta6.drawable,
),
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/render/viewport/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,22 +355,22 @@ impl RenderBridge {

/// Draw the GTA VI world this frame in the plain pass: put the models and textures that
/// arrived on the device, and lay out the instances of the last selection the camera sees.
pub fn refresh_world(&mut self) {
pub fn refresh_world(&mut self, world_session: &crate::state::gta6::world::WorldSession) {
let started = Instant::now();
(self.world.cost.laid, self.world.cost.uploaded) = (false, (0, 0));
self.lay_world();
self.lay_world(world_session);
self.world.cost.refresh = started.elapsed();
}

fn lay_world(&mut self) {
fn lay_world(&mut self, world_session: &crate::state::gta6::world::WorldSession) {
self.world.shown = true;
self.world.frame += 1;
// No program of GTA VI draws its world yet.
self.frame_world_shaded(false);
self.frame.mode = self.world_plain_mode();
let bc = (self.device.features()).contains(wgpu::Features::TEXTURE_COMPRESSION_BC);
let budgets = self.world_budgets();
let mut viewer = crate::state::gta6_world::worldview::viewer();
let mut viewer = crate::state::gta6_world::worldview::viewer(world_session);
let eye = viewer.camera.position;
let now = Instant::now();
let lead = self.world.was.map_or(eye, |(then, was)| {
Expand Down Expand Up @@ -451,6 +451,7 @@ impl RenderBridge {
(per_metre, budgets.most_side),
);
self.schedule_world_textures(
world_session,
&selected,
touched,
(view_proj, eye, lod_scale),
Expand Down Expand Up @@ -531,6 +532,7 @@ impl RenderBridge {
/// Rebuild touched materials with their current colour maps and report wanted models and textures to the viewer.
fn schedule_world_textures(
&mut self,
world_session: &crate::state::gta6::world::WorldSession,
selected: &Selected,
touched: Vec<u32>,
(view_proj, eye, lod_scale): (glam::Mat4, Vec3, f32),
Expand Down Expand Up @@ -605,7 +607,7 @@ impl RenderBridge {
.collect();
let mut wanted = merged(wanted);
world.textures.hold(&mut wanted);
let mut viewer = crate::state::gta6_world::worldview::viewer();
let mut viewer = crate::state::gta6_world::worldview::viewer(world_session);
viewer.see_models(in_view);
viewer.want_textures(wanted);
}
Expand Down
8 changes: 4 additions & 4 deletions src/self_check/shots/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Shell {
.find(|(s, _)| *s == name)
.map(|s| s.1)
};
let viewer = viewer();
let viewer = viewer(&state.gta6.world);
Ok(json!({
"frame_ms": ms(frame),
"refresh_ms": ms(cost.refresh),
Expand Down Expand Up @@ -127,7 +127,7 @@ impl Shell {
self.bridge.relay_world();
relaid.push(self.measured(state)?);
}
let pose = Pose::of(&viewer().camera);
let pose = Pose::of(&viewer(&state.gta6.world).camera);
let unix = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH);
let json = json!({
"camera": pose.line(),
Expand All @@ -149,12 +149,12 @@ impl Shell {
over: Duration,
path: &Path,
) -> Result<(), String> {
let from = Pose::of(&viewer().camera);
let from = Pose::of(&viewer(&state.gta6.world).camera);
let started = Instant::now();
let mut frames = Vec::new();
loop {
let t = (started.elapsed().as_secs_f32() / over.as_secs_f32()).min(1.0);
between(&from, to, t).put(&mut viewer().camera);
between(&from, to, t).put(&mut viewer(&state.gta6.world).camera);
let mut frame = self.measured(state)?;
frame["t"] = json!(t);
frames.push(frame);
Expand Down
Loading
Loading