rename ObjID to OptShort

png-branch
an 2019-02-21 14:35:16 -05:00
parent b87ce92d22
commit e2b29195dd
4 changed files with 54 additions and 53 deletions

View File

@ -446,8 +446,8 @@ is 6.9s, but the integral part is ignored. "No angle" is represented by 65510
The type "`unit`" refers to a 16-bit fixed point number with the format 5.10s. The type "`unit`" refers to a 16-bit fixed point number with the format 5.10s.
This is used for all world coordinates. This is used for all world coordinates.
An "Object ID" is a 16-bit integer which references something by index. If all An "Optional Short" is a 16-bit integer which references something by index. If
bits are set, it is to be interpreted as "none." Traditionally, these are all bits are set, it is to be interpreted as "none." Traditionally, these are
signed integers, but they can be treated as unsigned with no repercussions. signed integers, but they can be treated as unsigned with no repercussions.
## Wad ## ## Wad ##
@ -580,7 +580,7 @@ Side Texture is 6 bytes. Just stores a texture and an offset.
| `OffsetY` | `unit` | `2` | | `OffsetY` | `unit` | `2` |
| `TextureId` | `u16` | `4` | | `TextureId` | `u16` | `4` |
- `TextureId` is an Object ID referencing a Shapes bitmap. - `TextureId` is an Optional Short referencing a Shapes bitmap.
### Point ### ### Point ###
@ -631,9 +631,10 @@ Line is 32 bytes. A geometric line segment.
- `Flags` is a Line Flags bit field. - `Flags` is a Line Flags bit field.
- `HeightHi` and `HeightLo` are the highest adjacent ceiling and lowest - `HeightHi` and `HeightLo` are the highest adjacent ceiling and lowest
adjacent floor heights, respectively. adjacent floor heights, respectively.
- `SideFrnt` and `SideBack` are Object ID indices of the Sides in the front and - `SideFrnt` and `SideBack` are Optional Short indices of the Sides in the
back. front and back.
- `PolyFrnt` and `PolyBack` are Object ID indices of the connected Polygons. - `PolyFrnt` and `PolyBack` are Optional Short indices of the connected
Polygons.
### Side ### ### Side ###
@ -718,9 +719,9 @@ shape and automatically split them.)
- `Center` is a Point structure. - `Center` is a Point structure.
- `OrigFlr` is a Point structure for the texture offset of the floor. - `OrigFlr` is a Point structure for the texture offset of the floor.
- `OrigCei` is a Point structure for the texture offset of the ceiling. - `OrigCei` is a Point structure for the texture offset of the ceiling.
- `Media` is an Object ID. - `Media` is an Optional Short.
- `SoundAmbient` is an Object ID. - `SoundAmbient` is an Optional Short.
- `SoundRandom` is an Object ID. - `SoundRandom` is an Optional Short.
### Light ### ### Light ###
@ -853,7 +854,7 @@ part of the map in the middle of a wall.
- `Flags` is a Media Flags bit field. - `Flags` is a Media Flags bit field.
- `Control` is the index of a light which is used to control the height of this - `Control` is the index of a light which is used to control the height of this
media. media.
- `Texture` is an Object ID representing the texture index. - `Texture` is an Optional Short representing the texture index.
- `XferMode` is a Transfer Mode enumeration. - `XferMode` is a Transfer Mode enumeration.
### Static Map Info ### ### Static Map Info ###
@ -1184,7 +1185,7 @@ Frame is 36 bytes. TODO: document how world transform works.
- `Flags` is a Frame Flags bit field. - `Flags` is a Frame Flags bit field.
- `MinLight` is the minimum light intensity (0-1.) - `MinLight` is the minimum light intensity (0-1.)
- `BmpIndex` is an Object ID for the bitmap index. - `BmpIndex` is an Optional Short for the bitmap index.
### Sequence ### ### Sequence ###
@ -1287,7 +1288,7 @@ Sound Definition is 64 bytes.
| `GroupSize` | `u32` | `28` | | `GroupSize` | `u32` | `28` |
| `AddOffset` | `u32[5]` | `32` | | `AddOffset` | `u32[5]` | `32` |
- `Code` is an Object ID referencing something (TODO.) - `Code` is an Optional Short referencing something (TODO.)
- `Volume` is a Sound Behaviour enumeration. - `Volume` is a Sound Behaviour enumeration.
- `Flags` is a Sound Definition Flags bit field. - `Flags` is a Sound Definition Flags bit field.
- `Chance` is the chance out of `65535` that the sound will not play. - `Chance` is the chance out of `65535` that the sound will not play.

View File

@ -39,9 +39,9 @@ macro_rules! rd_1 {
rd_1!($b u16::from_be_bytes, $nam 2 $n); rd_1!($b u16::from_be_bytes, $nam 2 $n);
let $nam = Unit::from_bits($nam); let $nam = Unit::from_bits($nam);
}; };
(BE $b:ident $nam:ident ObjID $n:expr) => { (BE $b:ident $nam:ident OptShort $n:expr) => {
rd_1!($b u16::from_be_bytes, $nam 2 $n); rd_1!($b u16::from_be_bytes, $nam 2 $n);
let $nam = ObjID::from_repr($nam); let $nam = OptShort::from_repr($nam);
}; };
// little endian // little endian
@ -154,19 +154,19 @@ pub fn rd_ofstable<T, F>(b: &[u8],
Ok(v) Ok(v)
} }
impl ObjID impl OptShort
{ {
/// Creates an `ObjID` from a `u16`. /// Creates an `OptShort` from a `u16`.
pub fn from_repr(n: u16) -> ObjID pub fn from_repr(n: u16) -> OptShort
{ {
if n == u16::max_value() { if n == u16::max_value() {
ObjID(None) OptShort(None)
} else { } else {
ObjID(NonZeroU16::new(n + 1)) OptShort(NonZeroU16::new(n + 1))
} }
} }
/// Returns the `u16` representation of an `ObjID`. /// Returns the `u16` representation of an `OptShort`.
pub fn get_repr(&self) -> u16 pub fn get_repr(&self) -> u16
{ {
match self.0 { match self.0 {
@ -175,7 +175,7 @@ impl ObjID
} }
} }
/// Returns the `Option` representation of an `ObjID`. /// Returns the `Option` representation of an `OptShort`.
pub fn get(&self) -> Option<u16> pub fn get(&self) -> Option<u16>
{ {
match self.0 { match self.0 {
@ -185,13 +185,13 @@ impl ObjID
} }
} }
impl fmt::Debug for ObjID impl fmt::Debug for OptShort
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{ {
match self.get() { match self.get() {
None => write!(f, "ObjID(None)"), None => write!(f, "None"),
Some(n) => write!(f, "ObjID({})", n), Some(n) => write!(f, "Some({})", n),
} }
} }
} }
@ -202,6 +202,6 @@ pub type Ident = [u8; 4];
/// An object identified by a `u16` which may be `u16::max_value()` to /// An object identified by a `u16` which may be `u16::max_value()` to
/// represent None. /// represent None.
#[derive(Serialize)] #[derive(Serialize)]
pub struct ObjID(Option<NonZeroU16>); pub struct OptShort(Option<NonZeroU16>);
// EOF // EOF

View File

@ -44,7 +44,7 @@ pub fn read_sidetex(b: &[u8]) -> ResultS<SideTex>
read_data! { read_data! {
6, BE in b => 6, BE in b =>
offs = read_point[0..4]; offs = read_point[0..4];
tex_id = ObjID[4]; tex_id = OptShort[4];
} }
Ok(SideTex{offs, tex_id}) Ok(SideTex{offs, tex_id})
@ -83,10 +83,10 @@ pub fn read_lins(b: &[u8]) -> ResultS<(Line, usize)>
pnt_beg = u16[0]; pnt_beg = u16[0];
pnt_end = u16[2]; pnt_end = u16[2];
flags = u16[4]; flags = u16[4];
side_fr = ObjID[12]; side_fr = OptShort[12];
side_bk = ObjID[14]; side_bk = OptShort[14];
poly_fr = ObjID[16]; poly_fr = OptShort[16];
poly_bk = ObjID[18]; poly_bk = OptShort[18];
} }
let flags = ok!(LineFlags::from_bits(flags), "bad LineFlags")?; let flags = ok!(LineFlags::from_bits(flags), "bad LineFlags")?;
@ -127,8 +127,8 @@ pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
128, BE in b => 128, BE in b =>
ptype = u16[0]; ptype = u16[0];
pdata = i16[4]; pdata = i16[4];
tex_flr = ObjID[40]; tex_flr = OptShort[40];
tex_cei = ObjID[42]; tex_cei = OptShort[42];
hei_flr = Unit[44]; hei_flr = Unit[44];
hei_cei = Unit[46]; hei_cei = Unit[46];
lit_flr = u16[48]; lit_flr = u16[48];
@ -137,11 +137,11 @@ pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
xfr_cei = u16[66]; xfr_cei = u16[66];
ori_flr = read_point[108..112]; ori_flr = read_point[108..112];
ori_cei = read_point[112..116]; ori_cei = read_point[112..116];
med_ind = ObjID[116]; med_ind = OptShort[116];
med_ctl = u16[118]; med_ctl = u16[118];
snd_ind = u16[120]; snd_ind = u16[120];
snd_amb = ObjID[122]; snd_amb = OptShort[122];
snd_rnd = ObjID[124]; snd_rnd = OptShort[124];
} }
let xfr_flr = TransferMode::from_repr(xfr_flr)?; let xfr_flr = TransferMode::from_repr(xfr_flr)?;
@ -262,7 +262,7 @@ pub fn read_medi(b: &[u8]) -> ResultS<(Media, usize)>
orig = read_point[14..18]; orig = read_point[14..18];
hei_nrm = Unit[18]; hei_nrm = Unit[18];
min_lt = Fixed[20]; min_lt = Fixed[20];
texture = ObjID[24]; texture = OptShort[24];
xfer = u16[26]; xfer = u16[26];
} }
@ -304,17 +304,17 @@ pub struct Line
pub flags: LineFlags, pub flags: LineFlags,
pub pnt_beg: u16, pub pnt_beg: u16,
pub pnt_end: u16, pub pnt_end: u16,
pub side_fr: ObjID, pub side_fr: OptShort,
pub side_bk: ObjID, pub side_bk: OptShort,
pub poly_fr: ObjID, pub poly_fr: OptShort,
pub poly_bk: ObjID, pub poly_bk: OptShort,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct SideTex pub struct SideTex
{ {
pub offs: Point, pub offs: Point,
pub tex_id: ObjID, pub tex_id: OptShort,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -338,8 +338,8 @@ pub struct Polygon
{ {
pub ptype: PolyType, pub ptype: PolyType,
pub pdata: i16, pub pdata: i16,
pub tex_flr: ObjID, pub tex_flr: OptShort,
pub tex_cei: ObjID, pub tex_cei: OptShort,
pub hei_flr: Unit, pub hei_flr: Unit,
pub hei_cei: Unit, pub hei_cei: Unit,
pub lit_flr: u16, pub lit_flr: u16,
@ -348,11 +348,11 @@ pub struct Polygon
pub xfr_cei: TransferMode, pub xfr_cei: TransferMode,
pub ori_flr: Point, pub ori_flr: Point,
pub ori_cei: Point, pub ori_cei: Point,
pub med_ind: ObjID, pub med_ind: OptShort,
pub med_ctl: u16, pub med_ctl: u16,
pub snd_ind: u16, pub snd_ind: u16,
pub snd_amb: ObjID, pub snd_amb: OptShort,
pub snd_rnd: ObjID, pub snd_rnd: OptShort,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -440,7 +440,7 @@ pub struct Media
pub orig: Point, pub orig: Point,
pub hei_nrm: Unit, pub hei_nrm: Unit,
pub min_lt: Fixed, pub min_lt: Fixed,
pub texture: ObjID, pub texture: OptShort,
pub xfer: TransferMode, pub xfer: TransferMode,
} }

View File

@ -147,9 +147,9 @@ fn sequence(b: &[u8]) -> ResultS<Sequence>
key = u16[44]; key = u16[44];
xfer = u16[46]; xfer = u16[46];
xfer_pd = u16[48]; xfer_pd = u16[48];
snd_beg = ObjID[50]; snd_beg = OptShort[50];
snd_key = ObjID[52]; snd_key = OptShort[52];
snd_end = ObjID[54]; snd_end = OptShort[54];
loop_f = u16[58]; loop_f = u16[58];
} }
@ -355,9 +355,9 @@ pub struct Sequence
key: u16, key: u16,
xfer: TransferMode, xfer: TransferMode,
xfer_pd: u16, xfer_pd: u16,
snd_beg: ObjID, snd_beg: OptShort,
snd_key: ObjID, snd_key: OptShort,
snd_end: ObjID, snd_end: OptShort,
loop_f: u16, loop_f: u16,
} }