Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more vpinball 10.8 changes #30

Merged
merged 3 commits into from
Nov 29, 2023
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
208 changes: 123 additions & 85 deletions src/vpx/gamedata.rs

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions src/vpx/gameitem/hittarget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ pub struct HitTarget {
pub friction: f32,
pub scatter: f32,
pub is_collidable: bool,
pub disable_lighting_top: f32, // DILI
pub disable_lighting_below: Option<f32>, // DILB (added in 10.?)
pub disable_lighting_top_old: Option<f32>, // DILI (removed in 10.8)
pub disable_lighting_top: Option<f32>, // DILT (added in 10.8)
pub disable_lighting_below: Option<f32>, // DILB (added in 10.?)
pub depth_bias: f32,
pub is_reflection_enabled: bool,
pub is_dropped: bool,
Expand Down Expand Up @@ -69,7 +70,8 @@ impl BiffRead for HitTarget {
let mut friction: f32 = 0.0;
let mut scatter: f32 = 0.0;
let mut is_collidable: bool = true;
let mut disable_lighting_top: f32 = 0.0;
let mut disable_lighting_top_old: Option<f32> = None; //0.0;
let mut disable_lighting_top: Option<f32> = None; //0.0;
let mut disable_lighting_below: Option<f32> = None; //0.0;
let mut depth_bias: f32 = 0.0;
let mut is_reflection_enabled: bool = true;
Expand Down Expand Up @@ -144,7 +146,10 @@ impl BiffRead for HitTarget {
is_collidable = reader.get_bool();
}
"DILI" => {
disable_lighting_top = reader.get_f32();
disable_lighting_top_old = Some(reader.get_f32());
}
"DILT" => {
disable_lighting_top = Some(reader.get_f32());
}
"DILB" => {
disable_lighting_below = Some(reader.get_f32());
Expand Down Expand Up @@ -209,6 +214,7 @@ impl BiffRead for HitTarget {
friction,
scatter,
is_collidable,
disable_lighting_top_old,
disable_lighting_top,
disable_lighting_below,
is_reflection_enabled,
Expand Down Expand Up @@ -246,7 +252,12 @@ impl BiffWrite for HitTarget {
writer.write_tagged_f32("RFCT", self.friction);
writer.write_tagged_f32("RSCT", self.scatter);
writer.write_tagged_bool("CLDR", self.is_collidable);
writer.write_tagged_f32("DILI", self.disable_lighting_top);
if let Some(dili) = self.disable_lighting_top_old {
writer.write_tagged_f32("DILI", dili);
}
if let Some(disable_lighting_top) = self.disable_lighting_top {
writer.write_tagged_f32("DILT", disable_lighting_top);
}
if let Some(disable_lighting_below) = self.disable_lighting_below {
writer.write_tagged_f32("DILB", disable_lighting_below);
}
Expand Down Expand Up @@ -308,7 +319,8 @@ mod tests {
friction: rng.gen(),
scatter: rng.gen(),
is_collidable: rng.gen(),
disable_lighting_top: rng.gen(),
disable_lighting_top_old: Some(rng.gen()),
disable_lighting_top: Some(rng.gen()),
disable_lighting_below: rng.gen(),
is_reflection_enabled: rng.gen(),
depth_bias: rng.gen(),
Expand Down
22 changes: 17 additions & 5 deletions src/vpx/gameitem/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub struct Primitive {
pub is_toy: bool, // 29
pub use_3d_mesh: bool, // 30
pub static_rendering: bool, // 31
pub disable_lighting_top: f32, // 32
pub disable_lighting_top_old: Option<f32>, // DILI (removed in 10.8)
pub disable_lighting_top: Option<f32>, // DILT (added in 10.8)
pub disable_lighting_below: Option<f32>, // 33 DILB (added in 10.?)
pub is_reflection_enabled: bool, // 34
pub backfaces_enabled: Option<bool>, // 35 EBFC (added in 10.?)
Expand Down Expand Up @@ -92,7 +93,8 @@ impl BiffRead for Primitive {
let mut is_toy: bool = false;
let mut use_3d_mesh: bool = false;
let mut static_rendering: bool = false;
let mut disable_lighting_top: f32 = 0.0;
let mut disable_lighting_top_old: Option<f32> = None; //0.0;
let mut disable_lighting_top: Option<f32> = None; //0.0;
let mut disable_lighting_below: Option<f32> = None; //0.0;
let mut is_reflection_enabled: bool = true;
let mut backfaces_enabled: Option<bool> = None; //false;
Expand Down Expand Up @@ -240,7 +242,10 @@ impl BiffRead for Primitive {
//[BiffFloat("DILI", QuantizedUnsignedBits = 8, Pos = 32)]
//public float DisableLightingTop; // m_d.m_fDisableLightingTop = (tmp == 1) ? 1.f : dequantizeUnsigned<8>(tmp); // backwards compatible hacky loading!
"DILI" => {
disable_lighting_top = reader.get_f32();
disable_lighting_top_old = Some(reader.get_f32());
}
"DILT" => {
disable_lighting_top = Some(reader.get_f32());
}
"DILB" => {
disable_lighting_below = Some(reader.get_f32());
Expand Down Expand Up @@ -393,6 +398,7 @@ impl BiffRead for Primitive {
is_toy,
use_3d_mesh,
static_rendering,
disable_lighting_top_old,
disable_lighting_top,
disable_lighting_below,
is_reflection_enabled,
Expand Down Expand Up @@ -465,7 +471,12 @@ impl BiffWrite for Primitive {
writer.write_tagged_bool("ISTO", self.is_toy);
writer.write_tagged_bool("U3DM", self.use_3d_mesh);
writer.write_tagged_bool("STRE", self.static_rendering);
writer.write_tagged_f32("DILI", self.disable_lighting_top);
if let Some(disable_lighting_top_old) = self.disable_lighting_top_old {
writer.write_tagged_f32("DILI", disable_lighting_top_old);
}
if let Some(disable_lighting_top) = self.disable_lighting_top {
writer.write_tagged_f32("DILT", disable_lighting_top);
}
if let Some(disable_lighting_below) = self.disable_lighting_below {
writer.write_tagged_f32("DILB", disable_lighting_below);
}
Expand Down Expand Up @@ -604,7 +615,8 @@ mod tests {
is_toy: rng.gen(),
use_3d_mesh: rng.gen(),
static_rendering: rng.gen(),
disable_lighting_top: rng.gen(),
disable_lighting_top_old: Some(rng.gen()),
disable_lighting_top: Some(rng.gen()),
disable_lighting_below: rng.gen(),
is_reflection_enabled: rng.gen(),
backfaces_enabled: rng.gen(),
Expand Down
29 changes: 20 additions & 9 deletions src/vpx/gameitem/wall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ pub struct Wall {
pub is_top_bottom_visible: bool,
pub slingshot_animation: bool,
pub is_side_visible: bool,
pub disable_lighting_top: f32,
pub disable_lighting_below: Option<f32>, // DILB (added in 10.?)
pub disable_lighting_top_old: Option<f32>, // DILI (removed in 10.8)
pub disable_lighting_top: Option<f32>, // DILT (added in 10.8)
pub disable_lighting_below: Option<f32>, // DILB (added in 10.?)
pub is_reflection_enabled: bool,
pub physics_material: Option<String>, // MAPH (added in 10.?)
pub overwrite_physics: Option<bool>, // OVPH (added in 10.?)
Expand Down Expand Up @@ -74,7 +75,8 @@ impl BiffRead for Wall {
let mut scatter: f32 = Default::default();
let mut is_top_bottom_visible: bool = true;
let mut overwrite_physics: Option<bool> = None; //true;
let mut disable_lighting_top: f32 = Default::default();
let mut disable_lighting_top_old: Option<f32> = None; //0.0;
let mut disable_lighting_top: Option<f32> = None; //0.0;
let mut disable_lighting_below: Option<f32> = None;
let mut is_side_visible: bool = true;
let mut is_reflection_enabled: bool = true;
Expand Down Expand Up @@ -167,9 +169,6 @@ impl BiffRead for Wall {
"OVPH" => {
overwrite_physics = Some(reader.get_bool());
}
"DLTO" => {
disable_lighting_top = reader.get_f32();
}
"DLBE" => {
disable_lighting_below = Some(reader.get_f32());
}
Expand Down Expand Up @@ -207,7 +206,10 @@ impl BiffRead for Wall {
is_side_visible = reader.get_bool();
}
"DILI" => {
disable_lighting_top = reader.get_f32();
disable_lighting_top_old = Some(reader.get_f32());
}
"DILT" => {
disable_lighting_top = Some(reader.get_f32());
}
"DILB" => {
disable_lighting_below = Some(reader.get_f32());
Expand Down Expand Up @@ -307,6 +309,7 @@ impl BiffRead for Wall {
is_top_bottom_visible,
slingshot_animation,
is_side_visible,
disable_lighting_top_old,
disable_lighting_top,
disable_lighting_below,
is_reflection_enabled,
Expand Down Expand Up @@ -351,7 +354,12 @@ impl BiffWrite for Wall {
writer.write_tagged_bool("VSBL", self.is_top_bottom_visible);
writer.write_tagged_bool("SLGA", self.slingshot_animation);
writer.write_tagged_bool("SVBL", self.is_side_visible);
writer.write_tagged_f32("DILI", self.disable_lighting_top);
if let Some(disable_lighting_top_old) = self.disable_lighting_top_old {
writer.write_tagged_f32("DILI", disable_lighting_top_old);
}
if let Some(disable_lighting_top) = self.disable_lighting_top {
writer.write_tagged_f32("DILT", disable_lighting_top);
}
if let Some(disable_lighting_below) = self.disable_lighting_below {
writer.write_tagged_f32("DILB", disable_lighting_below);
}
Expand Down Expand Up @@ -386,9 +394,11 @@ impl BiffWrite for Wall {
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use rand::Rng;

#[test]
fn test_write_read() {
let mut rng = rand::thread_rng();
let wall = Wall {
hit_event: true,
is_droppable: true,
Expand Down Expand Up @@ -416,7 +426,8 @@ mod tests {
is_top_bottom_visible: true,
slingshot_animation: true,
is_side_visible: true,
disable_lighting_top: 11.0,
disable_lighting_top_old: Some(rng.gen()),
disable_lighting_top: Some(rng.gen()),
disable_lighting_below: Some(12.0),
is_reflection_enabled: true,
physics_material: Some("physics_material".to_string()),
Expand Down
24 changes: 22 additions & 2 deletions src/vpx/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ pub struct ImageData {
// TODO seems to be 1 for some kind of link type img, related to screenshots.
// we only see this where a screenshot is set on the table info.
// https://github.com/vpinball/vpinball/blob/1a70aa35eb57ec7b5fbbb9727f6735e8ef3183e0/Texture.cpp#L588
pub link: Option<u32>, // LINK
pub alpha_test_value: f32, // ALTV
pub link: Option<u32>, // LINK
pub alpha_test_value: f32, // ALTV
pub is_opaque: Option<bool>, // OPAQ (added in 10.8)
pub is_signed: Option<bool>, // SIGN (added in 10.8)
// TODO we can probably only have one of these so we can make an enum
pub jpeg: Option<ImageDataJpeg>,
pub bits: Option<ImageDataBits>,
Expand Down Expand Up @@ -92,6 +94,8 @@ fn read(reader: &mut BiffReader) -> ImageData {
let mut width: u32 = 0;
let mut path: String = "".to_string();
let mut alpha_test_value: f32 = 0.0;
let mut is_opaque: Option<bool> = None;
let mut is_signed: Option<bool> = None;
let mut jpeg: Option<ImageDataJpeg> = None;
let mut bits: Option<ImageDataBits> = None;
let mut link: Option<u32> = None;
Expand Down Expand Up @@ -121,6 +125,12 @@ fn read(reader: &mut BiffReader) -> ImageData {
"ALTV" => {
alpha_test_value = reader.get_f32();
}
"OPAQ" => {
is_opaque = Some(reader.get_bool());
}
"SIGN" => {
is_signed = Some(reader.get_bool());
}
"BITS" => {
// these have zero as length
// read all the data until the next expected tag
Expand Down Expand Up @@ -160,6 +170,8 @@ fn read(reader: &mut BiffReader) -> ImageData {
height,
link,
alpha_test_value,
is_opaque,
is_signed,
jpeg,
bits,
}
Expand All @@ -184,6 +196,12 @@ fn write(data: &ImageData, writer: &mut BiffWriter) {
writer.write_tagged_data("JPEG", &bits);
}
writer.write_tagged_f32("ALTV", data.alpha_test_value);
if let Some(is_opaque) = data.is_opaque {
writer.write_tagged_bool("OPAQ", is_opaque);
}
if let Some(is_signed) = data.is_signed {
writer.write_tagged_bool("SIGN", is_signed);
}
writer.close(true);
}

Expand Down Expand Up @@ -280,6 +298,8 @@ mod test {
height: 2,
link: None,
alpha_test_value: 1.0,
is_opaque: Some(true),
is_signed: Some(false),
jpeg: Some(ImageDataJpeg {
path: "path_value".to_string(),
name: "name_value".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/vpx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ mod tests {

let mac = read_mac(&mut comp)?;
let expected = [
26, 207, 96, 222, 89, 140, 131, 117, 185, 116, 6, 2, 113, 119, 49, 153,
217, 73, 194, 14, 110, 210, 8, 223, 228, 57, 31, 13, 74, 148, 216, 40,
];
assert_eq!(mac, expected);
Ok(())
Expand Down
32 changes: 25 additions & 7 deletions tests/vpx_read_write_compare_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ fn read_and_write_all() -> io::Result<()> {
// testdir can not be used in non-main threads
let dir: PathBuf = testdir!();
// TODO why is par_iter() not faster but just consuming all cpu cores?
paths.iter().try_for_each(|path| {
println!("testing: {:?}", path);
let test_vpx_path = read_and_write_vpx(&dir, &path)?;

assert_equal_vpx(path, test_vpx_path);
Ok(())
})
paths
.iter()
// .filter(|p| {
// p.file_name()
// .unwrap()
// .to_string_lossy()
// .to_ascii_lowercase()
// .contains("diehard")
// })
.try_for_each(|path| {
println!("testing: {:?}", path);
let test_vpx_path = read_and_write_vpx(&dir, &path)?;

assert_equal_vpx(path, test_vpx_path);
Ok(())
})
}

fn read_and_write_vpx(dir: &PathBuf, path: &Path) -> io::Result<PathBuf> {
Expand Down Expand Up @@ -182,6 +191,15 @@ fn biff_tags_and_hashes(reader: &mut BiffReader) -> Vec<(String, usize, u64)> {
let hash = hasher.finish();
tags.push(("BITS".to_string(), data.len(), hash));
}
"CODE" => {
let len = reader.get_u32_no_remaining_update();
// at least a the time of 1060, some code was still encoded in latin1
let data = reader.get_str_with_encoding_no_remaining_update(len as usize);
let mut hasher = DefaultHasher::new();
Hash::hash_slice(&data.string.as_bytes(), &mut hasher);
let hash = hasher.finish();
tags.push(("CODE".to_string(), len as usize, hash));
}
other => {
let data = reader.get_record_data(false);
let mut hasher = DefaultHasher::new();
Expand Down