add polygons

png-branch
an 2019-02-18 19:27:55 -05:00
parent f190206fa2
commit b08c370530
3 changed files with 110 additions and 8 deletions

View File

@ -683,8 +683,8 @@ shape and automatically split them.)
| `LinArray` | `u16[8]` | `24` |
| `TexFlr` | `u16` | `40` |
| `TexCei` | `u16` | `42` |
| `HeightFlr` | `u16` | `44` |
| `HeightCei` | `u16` | `46` |
| `HeightFlr` | `unit` | `44` |
| `HeightCei` | `unit` | `46` |
| `LightFlr` | `u16` | `48` |
| `LightCei` | `u16` | `50` |
| `Area` | `i32` | `52` |
@ -697,19 +697,26 @@ shape and automatically split them.)
| `Adjacent` | `u16[8]` | `68` |
| `NeighborFst` | `u16` | `84` |
| `NeighborNum` | `u16` | `86` |
| `CenterX` | `unit` | `88` |
| `CenterY` | `unit` | `90` |
| `Center` | `struct` | `88` |
| `SideArray` | `u16[8]` | `92` |
| `OrigFlrX` | `unit` | `108` |
| `OrigFlrY` | `unit` | `110` |
| `OrigCeiX` | `unit` | `112` |
| `OrigCeiY` | `unit` | `114` |
| `OrigFlr` | `struct` | `108` |
| `OrigCei` | `struct` | `112` |
| `Media` | `u16` | `116` |
| `MediaLight` | `u16` | `118` |
| `Sound` | `u16` | `120` |
| `SoundAmbient` | `u16` | `122` |
| `SoundRandom` | `u16` | `124` |
- `Type` is a Polygon Type enumeration.
- `Flags` is a Polygon Flags bit field.
- `Area` is the power-of-two area of the polygon.
- `ObjectFst` must be `65535`.
- `Center` is a Point structure.
- `OrigFlr` is a Point structure.
- `OrigCei` is a Point structure.
- `SoundAmbient` is an Object ID.
- `SoundRandom` is an Object ID.
### Light ###
Light is 100 bytes.

View File

@ -55,6 +55,7 @@ fn dump_chunk(opt: &Options, cid: Ident, cnk: &[u8], eid: u16) -> ResultS<()>
b"PNTS" => make_yaml(opt, &c_array(cnk, map::read_pnts)?)?,
b"LINS" => make_yaml(opt, &c_array(cnk, map::read_lins)?)?,
b"SIDS" => make_yaml(opt, &c_array(cnk, map::read_sids)?)?,
b"POLY" => make_yaml(opt, &c_array(cnk, map::read_poly)?)?,
b"term" => make_yaml(opt, &c_array(cnk, trm::read_term)?)?,
_ => (),
}

View File

@ -88,6 +88,43 @@ pub fn read_sids(b: &[u8]) -> ResultS<(Side, usize)>
xfer_pri, xfer_sec, xfer_tra, shade}, 64))
}
pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
{
let ptype = c_u16b(b, 0)?;
let flags = c_u16b(b, 2)?;
let pdata = c_i16b(b, 4)?;
let tex_flr = c_u16b(b, 40)?;
let tex_cei = c_u16b(b, 42)?;
let hei_flr = c_u16b(b, 44)?;
let hei_cei = c_u16b(b, 46)?;
let lit_flr = c_u16b(b, 48)?;
let lit_cei = c_u16b(b, 50)?;
let xfr_flr = c_u16b(b, 64)?;
let xfr_cei = c_u16b(b, 66)?;
let ori_flr = read_point(c_data(b, 108..112)?)?;
let ori_cei = read_point(c_data(b, 112..116)?)?;
let media = c_u16b(b, 116)?;
let media_l = c_u16b(b, 118)?;
let sound = c_u16b(b, 120)?;
let snd_amb = c_u16b(b, 122)?;
let snd_rnd = c_u16b(b, 124)?;
let ptype = PolyType::from_repr(ptype)?;
let flags = ok!(PolyFlags::from_bits(flags), "bad PolyFlags")?;
let tex_flr = ObjID::from_repr(tex_flr);
let tex_cei = ObjID::from_repr(tex_cei);
let hei_flr = Unit::from_bits(hei_flr);
let hei_cei = Unit::from_bits(hei_cei);
let xfr_flr = TransferMode::from_repr(xfr_flr)?;
let xfr_cei = TransferMode::from_repr(xfr_cei)?;
let snd_amb = ObjID::from_repr(snd_amb);
let snd_rnd = ObjID::from_repr(snd_rnd);
Ok((Polygon{ptype, flags, pdata, tex_flr, tex_cei, hei_flr, hei_cei,
lit_flr, lit_cei, xfr_flr, xfr_cei, ori_flr, ori_cei, media,
media_l, sound, snd_amb, snd_rnd},
128))
}
#[derive(Serialize)]
pub struct Point
{
@ -130,6 +167,29 @@ pub struct Side
shade: Fixed,
}
#[derive(Debug, Serialize)]
pub struct Polygon
{
ptype: PolyType,
flags: PolyFlags,
pdata: i16,
tex_flr: ObjID,
tex_cei: ObjID,
hei_flr: Unit,
hei_cei: Unit,
lit_flr: u16,
lit_cei: u16,
xfr_flr: TransferMode,
xfr_cei: TransferMode,
ori_flr: Point,
ori_cei: Point,
media: u16,
media_l: u16,
sound: u16,
snd_amb: ObjID,
snd_rnd: ObjID,
}
#[derive(Debug, Serialize)]
pub struct Minf
{
@ -217,6 +277,14 @@ bitflags! {
}
}
bitflags! {
#[derive(Serialize)]
pub struct PolyFlags: u16
{
const Detached = 1 << 14;
}
}
c_enum! {
#[derive(Debug, Serialize)]
pub enum SideType: u16
@ -229,6 +297,32 @@ c_enum! {
}
}
c_enum! {
#[derive(Debug, Serialize)]
pub enum PolyType: u16
{
0 => Normal,
1 => ImpassItem,
2 => ImpassMons,
3 => Hill,
4 => Base,
5 => Platform,
6 => TrigLightOn,
7 => TrigPlatOn,
8 => TrigLightOff,
9 => TrigPlatOff,
10 => Teleporter,
11 => ZoneBorder,
12 => Goal,
13 => TrigMonsVis,
14 => TrigMonsInv,
15 => TrigMonsDual,
16 => TrigItems,
17 => MustExplore,
18 => AutoExit,
}
}
impl fmt::Debug for Point
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result