wgtk/space/section/
bwsg.rs

1use std::collections::HashMap;
2use std::io::{Read, Seek};
3
4use super::{Section, SectionId, BWST};
5use crate::util::io::WgReadExt;
6
7
8/// StaticGeometry section, defines models and positions.
9#[derive(Debug)]
10pub struct BWSG {
11    pub strings: HashMap<u32, String>,
12    pub models: Vec<ModelInfo>,
13    pub positions: Vec<PositionInfo>,
14}
15
16impl Section for BWSG {
17
18    const ID: &'static SectionId = b"BWSG";
19
20    fn decode<R: Read + Seek>(read: &mut R) -> std::io::Result<Self> {
21
22        // Reuse BWST decoding for strings stored in BWSG.
23        let strings = BWST::decode(read)?.strings;
24
25        let models = read.read_vector(|buf| {
26            Ok(ModelInfo {
27                vertices_fnv: buf.read_u32()?,
28                id_from: buf.read_u32()?,
29                id_to: buf.read_u32()?,
30                vertices_count: buf.read_u32()?,
31                vertices_type_fnv: buf.read_u32()?
32            })
33        })?;
34
35        let positions = read.read_vector(|buf| {
36            Ok(PositionInfo {
37                typ: buf.read_u64()?,
38                size: buf.read_u32()?,
39                data_sizes_id: buf.read_u32()?,
40                position: buf.read_u32()?
41            })
42        })?;
43
44        Ok(BWSG {
45            strings,
46            models,
47            positions
48        })
49
50    }
51
52}
53
54
55/// A model information with its resources.
56/// Decoded by [BWSG] section.
57#[derive(Debug)]
58pub struct ModelInfo {
59    pub vertices_fnv: u32,
60    pub id_from: u32,
61    pub id_to: u32,
62    pub vertices_count: u32,
63    pub vertices_type_fnv: u32
64}
65
66
67/// A position information.
68/// Decoded by [BWSG] section.
69#[derive(Debug)]
70pub struct PositionInfo {
71    pub typ: u64,
72    /// Size of vertices block from .primitives
73    pub size: u32,
74    /// Index data_sizes
75    pub data_sizes_id: u32,
76    /// Start position in `BSGD`
77    pub position: u32
78}