Skip to content

Commit

Permalink
Merge pull request #1 from ihatecompvir/master
Browse files Browse the repository at this point in the history
Add support for CubeTex version 2
  • Loading branch information
PikminGuts92 authored May 15, 2023
2 parents a619a06 + eee586f commit 068c479
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
34 changes: 28 additions & 6 deletions core/grim/src/scene/cube_tex/io.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::io::{BinaryStream, SeekFrom, Stream};
use crate::scene::*;
use crate::SystemInfo;
use crate::texture::Bitmap;
use crate::SystemInfo;
use grim_traits::scene::*;
use std::error::Error;

fn is_version_supported(version: u32) -> bool {
match version {
1 => true, // GH2 360
_ => false
2 => true, // TBRB/RB3/DC1
_ => false,
}
}

Expand All @@ -24,8 +25,12 @@ impl ObjectReadWrite for CubeTexObject {

load_object(self, &mut stream, info)?;

self.some_num_1 = stream.read_uint32()?;
self.some_num_2 = stream.read_uint32()?;
if version < 2 {
self.some_num_1 = stream.read_uint32()?;
self.some_num_2 = stream.read_uint32()?;
} else {
self.properties = load_cubetex_properties(&mut stream)?;
}

self.right_ext_path = stream.read_prefixed_string()?;
self.left_ext_path = stream.read_prefixed_string()?;
Expand All @@ -34,7 +39,9 @@ impl ObjectReadWrite for CubeTexObject {
self.front_ext_path = stream.read_prefixed_string()?;
self.back_ext_path = stream.read_prefixed_string()?;

self.some_bool = stream.read_boolean()?;
if version < 2 {
self.some_bool = stream.read_boolean()?; // only seems to exist on version 1
}

if stream.pos() == stream.len()? as u64 {
return Ok(());
Expand Down Expand Up @@ -108,4 +115,19 @@ impl ObjectReadWrite for CubeTexObject {

Ok(())
}
}
}

fn load_cubetex_properties(reader: &mut Box<BinaryStream>,) -> Result<Vec<CubeTexProperties>, Box<dyn Error>> {
let mut properties = Vec::new();
for _ in 0..7 {
let bpp = reader.read_uint32()?;
let width = reader.read_uint32()?;
let height = reader.read_uint32()?;
let num_mip_maps = reader.read_uint32()?;
let bitmap_encoding = reader.read_uint32()?;

properties.push(CubeTexProperties {bpp,width,height,num_mip_maps,bitmap_encoding,})
}

Ok(properties)
}
14 changes: 13 additions & 1 deletion core/grim/src/scene/cube_tex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ use grim_macros::*;
use grim_traits::scene::*;
pub use io::*;

pub struct CubeTexProperties {
pub bpp: u32,
pub width: u32,
pub height: u32,
pub num_mip_maps: u32,
pub bitmap_encoding: u32, // DXT5, RGBA, etc.
}

#[milo]
pub struct CubeTexObject {
pub some_num_1: u32,
pub some_num_2: u32,

pub properties: Vec<CubeTexProperties>,

pub right_ext_path: String,
pub left_ext_path: String,
pub top_ext_path: String,
Expand Down Expand Up @@ -39,6 +49,8 @@ impl Default for CubeTexObject {
some_num_1: 64,
some_num_2: 4,

properties: Vec::new(),

right_ext_path: String::default(),
left_ext_path: String::default(),
top_ext_path: String::default(),
Expand All @@ -56,4 +68,4 @@ impl Default for CubeTexObject {
back: None,
}
}
}
}

0 comments on commit 068c479

Please sign in to comment.