rename Optional Short again
parent
baf86e80d2
commit
fe2f830f3e
|
@ -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.
|
||||
This is used for all world coordinates.
|
||||
|
||||
An "Optional Short" is a 16-bit integer which references something by index. If
|
||||
all bits are set, it is to be interpreted as "none." Traditionally, these are
|
||||
A "`u16opt`" is a 16-bit integer which references something by index. If 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.
|
||||
|
||||
## Wad ##
|
||||
|
@ -578,9 +578,9 @@ Side Texture is 6 bytes. Just stores a texture and an offset.
|
|||
| ---- | ---- | ------ |
|
||||
| `OffsetX` | `unit` | `0` |
|
||||
| `OffsetY` | `unit` | `2` |
|
||||
| `TextureId` | `u16` | `4` |
|
||||
| `TextureId` | `u16opt` | `4` |
|
||||
|
||||
- `TextureId` is an Optional Short referencing a Shapes bitmap.
|
||||
- `TextureId` references a Shapes bitmap.
|
||||
|
||||
### Point ###
|
||||
|
||||
|
@ -622,19 +622,17 @@ Line is 32 bytes. A geometric line segment.
|
|||
| `Length` | `unit` | `6` |
|
||||
| `HeightHi` | `unit` | `8` |
|
||||
| `HeightLo` | `unit` | `10` |
|
||||
| `SideFrnt` | `u16` | `12` |
|
||||
| `SideBack` | `u16` | `14` |
|
||||
| `PolyFrnt` | `u16` | `16` |
|
||||
| `PolyBack` | `u16` | `18` |
|
||||
| `SideFrnt` | `u16opt` | `12` |
|
||||
| `SideBack` | `u16opt` | `14` |
|
||||
| `PolyFrnt` | `u16opt` | `16` |
|
||||
| `PolyBack` | `u16opt` | `18` |
|
||||
|
||||
- `PointBeg` and `PointEnd` are the beginning and terminating endpoints.
|
||||
- `Flags` is a Line Flags bit field.
|
||||
- `HeightHi` and `HeightLo` are the highest adjacent ceiling and lowest
|
||||
adjacent floor heights, respectively.
|
||||
- `SideFrnt` and `SideBack` are Optional Short indices of the Sides in the
|
||||
front and back.
|
||||
- `PolyFrnt` and `PolyBack` are Optional Short indices of the connected
|
||||
Polygons.
|
||||
- `SideFrnt` and `SideBack` are indices of the Sides in the front and back.
|
||||
- `PolyFrnt` and `PolyBack` are indices of the connected Polygons.
|
||||
|
||||
### Side ###
|
||||
|
||||
|
@ -706,11 +704,11 @@ shape and automatically split them.)
|
|||
| `SideArray` | `u16[8]` | `92` |
|
||||
| `OrigFlr` | `struct` | `108` |
|
||||
| `OrigCei` | `struct` | `112` |
|
||||
| `Media` | `u16` | `116` |
|
||||
| `Media` | `u16opt` | `116` |
|
||||
| `MediaLight` | `u16` | `118` |
|
||||
| `SoundIndices` | `u16` | `120` |
|
||||
| `SoundAmbient` | `u16` | `122` |
|
||||
| `SoundRandom` | `u16` | `124` |
|
||||
| `SoundAmbient` | `u16opt` | `122` |
|
||||
| `SoundRandom` | `u16opt` | `124` |
|
||||
|
||||
- `Type` is a Polygon Type enumeration.
|
||||
- `Flags` is a Polygon Flags bit field.
|
||||
|
@ -719,9 +717,6 @@ shape and automatically split them.)
|
|||
- `Center` is a Point structure.
|
||||
- `OrigFlr` is a Point structure for the texture offset of the floor.
|
||||
- `OrigCei` is a Point structure for the texture offset of the ceiling.
|
||||
- `Media` is an Optional Short.
|
||||
- `SoundAmbient` is an Optional Short.
|
||||
- `SoundRandom` is an Optional Short.
|
||||
|
||||
### Light ###
|
||||
|
||||
|
@ -847,14 +842,13 @@ part of the map in the middle of a wall.
|
|||
| `Origin` | `struct` | `14` |
|
||||
| `Height` | `unit` | `18` |
|
||||
| `Minimum` | `fixed` | `20` |
|
||||
| `Texture` | `u16` | `24` |
|
||||
| `Texture` | `u16opt` | `24` |
|
||||
| `XferMode` | `u16` | `26` |
|
||||
|
||||
- `Type` is a Media Type enumeration.
|
||||
- `Flags` is a Media Flags bit field.
|
||||
- `Control` is the index of a light which is used to control the height of this
|
||||
media.
|
||||
- `Texture` is an Optional Short representing the texture index.
|
||||
- `XferMode` is a Transfer Mode enumeration.
|
||||
|
||||
### Static Map Info ###
|
||||
|
@ -1190,7 +1184,7 @@ Frame is 36 bytes. TODO: document how world transform works.
|
|||
| ---- | ---- | ------ |
|
||||
| `Flags` | `u16` | `0` |
|
||||
| `MinLight` | `fixed` | `2` |
|
||||
| `BmpIndex` | `u16` | `6` |
|
||||
| `BmpIndex` | `u16opt` | `6` |
|
||||
| `WldLeft` | `unit` | `14` |
|
||||
| `WldRight` | `unit` | `16` |
|
||||
| `WldTop` | `unit` | `18` |
|
||||
|
@ -1200,7 +1194,6 @@ Frame is 36 bytes. TODO: document how world transform works.
|
|||
|
||||
- `Flags` is a Frame Flags bit field.
|
||||
- `MinLight` is the minimum light intensity (0-1.)
|
||||
- `BmpIndex` is an Optional Short for the bitmap index.
|
||||
|
||||
### Sequence ###
|
||||
|
||||
|
@ -1291,7 +1284,7 @@ Sound Definition is 64 bytes.
|
|||
|
||||
| Name | Type | Offset |
|
||||
| ---- | ---- | ------ |
|
||||
| `Code` | `u16` | `0` |
|
||||
| `Code` | `u16opt` | `0` |
|
||||
| `Volume` | `u16` | `2` |
|
||||
| `Flags` | `u16` | `4` |
|
||||
| `Chance` | `u16` | `6` |
|
||||
|
@ -1303,7 +1296,6 @@ Sound Definition is 64 bytes.
|
|||
| `GroupSize` | `u32` | `28` |
|
||||
| `AddOffset` | `u32[5]` | `32` |
|
||||
|
||||
- `Code` is an Optional Short referencing something (TODO.)
|
||||
- `Volume` is a Sound Behaviour enumeration.
|
||||
- `Flags` is a Sound Definition Flags bit field.
|
||||
- `Chance` is the chance out of `65535` that the sound will not play.
|
||||
|
|
|
@ -39,9 +39,9 @@ macro_rules! rd_1 {
|
|||
rd_1!($b u16::from_be_bytes, $nam 2 $n);
|
||||
let $nam = Unit::from_bits($nam);
|
||||
};
|
||||
(BE $b:ident $nam:ident OptShort $n:expr) => {
|
||||
(BE $b:ident $nam:ident OptU16 $n:expr) => {
|
||||
rd_1!($b u16::from_be_bytes, $nam 2 $n);
|
||||
let $nam = OptShort::from_repr($nam);
|
||||
let $nam = OptU16::from_repr($nam);
|
||||
};
|
||||
|
||||
// little endian
|
||||
|
@ -154,19 +154,19 @@ pub fn rd_ofstable<T, F>(b: &[u8],
|
|||
Ok(v)
|
||||
}
|
||||
|
||||
impl OptShort
|
||||
impl OptU16
|
||||
{
|
||||
/// Creates an `OptShort` from a `u16`.
|
||||
pub fn from_repr(n: u16) -> OptShort
|
||||
/// Creates an `OptU16` from a `u16`.
|
||||
pub fn from_repr(n: u16) -> OptU16
|
||||
{
|
||||
if n == u16::max_value() {
|
||||
OptShort(None)
|
||||
OptU16(None)
|
||||
} else {
|
||||
OptShort(NonZeroU16::new(n + 1))
|
||||
OptU16(NonZeroU16::new(n + 1))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `u16` representation of an `OptShort`.
|
||||
/// Returns the `u16` representation of an `OptU16`.
|
||||
pub fn get_repr(&self) -> u16
|
||||
{
|
||||
match self.0 {
|
||||
|
@ -175,7 +175,7 @@ impl OptShort
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the `Option` representation of an `OptShort`.
|
||||
/// Returns the `Option` representation of an `OptU16`.
|
||||
pub fn get(&self) -> Option<u16>
|
||||
{
|
||||
match self.0 {
|
||||
|
@ -185,7 +185,7 @@ impl OptShort
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for OptShort
|
||||
impl fmt::Debug for OptU16
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
||||
{
|
||||
|
@ -202,6 +202,6 @@ pub type Ident = [u8; 4];
|
|||
/// An object identified by a `u16` which may be `u16::max_value()` to
|
||||
/// represent None.
|
||||
#[derive(Serialize)]
|
||||
pub struct OptShort(Option<NonZeroU16>);
|
||||
pub struct OptU16(Option<NonZeroU16>);
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn read_sidetex(b: &[u8]) -> ResultS<SideTex>
|
|||
read_data! {
|
||||
6, BE in b =>
|
||||
offs = read_point[0..4];
|
||||
tex_id = OptShort[4];
|
||||
tex_id = OptU16[4];
|
||||
}
|
||||
|
||||
Ok(SideTex{offs, tex_id})
|
||||
|
@ -83,10 +83,10 @@ pub fn read_lins(b: &[u8]) -> ResultS<(Line, usize)>
|
|||
pnt_beg = u16[0];
|
||||
pnt_end = u16[2];
|
||||
flags = u16[4];
|
||||
side_fr = OptShort[12];
|
||||
side_bk = OptShort[14];
|
||||
poly_fr = OptShort[16];
|
||||
poly_bk = OptShort[18];
|
||||
side_fr = OptU16[12];
|
||||
side_bk = OptU16[14];
|
||||
poly_fr = OptU16[16];
|
||||
poly_bk = OptU16[18];
|
||||
}
|
||||
|
||||
let flags = flag_ok!(LineFlags, flags)?;
|
||||
|
@ -127,8 +127,8 @@ pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
|
|||
128, BE in b =>
|
||||
ptype = u16[0];
|
||||
pdata = i16[4];
|
||||
tex_flr = OptShort[40];
|
||||
tex_cei = OptShort[42];
|
||||
tex_flr = OptU16[40];
|
||||
tex_cei = OptU16[42];
|
||||
hei_flr = Unit[44];
|
||||
hei_cei = Unit[46];
|
||||
lit_flr = u16[48];
|
||||
|
@ -137,11 +137,11 @@ pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
|
|||
xfr_cei = u16[66];
|
||||
ori_flr = read_point[108..112];
|
||||
ori_cei = read_point[112..116];
|
||||
med_ind = OptShort[116];
|
||||
med_ind = OptU16[116];
|
||||
med_ctl = u16[118];
|
||||
snd_ind = u16[120];
|
||||
snd_amb = OptShort[122];
|
||||
snd_rnd = OptShort[124];
|
||||
snd_amb = OptU16[122];
|
||||
snd_rnd = OptU16[124];
|
||||
}
|
||||
|
||||
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];
|
||||
hei_nrm = Unit[18];
|
||||
min_lt = Fixed[20];
|
||||
texture = OptShort[24];
|
||||
texture = OptU16[24];
|
||||
xfer = u16[26];
|
||||
}
|
||||
|
||||
|
@ -304,17 +304,17 @@ pub struct Line
|
|||
pub flags: LineFlags,
|
||||
pub pnt_beg: u16,
|
||||
pub pnt_end: u16,
|
||||
pub side_fr: OptShort,
|
||||
pub side_bk: OptShort,
|
||||
pub poly_fr: OptShort,
|
||||
pub poly_bk: OptShort,
|
||||
pub side_fr: OptU16,
|
||||
pub side_bk: OptU16,
|
||||
pub poly_fr: OptU16,
|
||||
pub poly_bk: OptU16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct SideTex
|
||||
{
|
||||
pub offs: Point,
|
||||
pub tex_id: OptShort,
|
||||
pub tex_id: OptU16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
@ -338,8 +338,8 @@ pub struct Polygon
|
|||
{
|
||||
pub ptype: PolyType,
|
||||
pub pdata: i16,
|
||||
pub tex_flr: OptShort,
|
||||
pub tex_cei: OptShort,
|
||||
pub tex_flr: OptU16,
|
||||
pub tex_cei: OptU16,
|
||||
pub hei_flr: Unit,
|
||||
pub hei_cei: Unit,
|
||||
pub lit_flr: u16,
|
||||
|
@ -348,11 +348,11 @@ pub struct Polygon
|
|||
pub xfr_cei: TransferMode,
|
||||
pub ori_flr: Point,
|
||||
pub ori_cei: Point,
|
||||
pub med_ind: OptShort,
|
||||
pub med_ind: OptU16,
|
||||
pub med_ctl: u16,
|
||||
pub snd_ind: u16,
|
||||
pub snd_amb: OptShort,
|
||||
pub snd_rnd: OptShort,
|
||||
pub snd_amb: OptU16,
|
||||
pub snd_rnd: OptU16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
@ -440,7 +440,7 @@ pub struct Media
|
|||
pub orig: Point,
|
||||
pub hei_nrm: Unit,
|
||||
pub min_lt: Fixed,
|
||||
pub texture: OptShort,
|
||||
pub texture: OptU16,
|
||||
pub xfer: TransferMode,
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ pub fn read_fxpx(b: &[u8]) -> ResultS<(Effect, usize)>
|
|||
shape = u16[2];
|
||||
pitch = Fixed[4];
|
||||
flags = u16[8];
|
||||
delay = OptShort[10];
|
||||
delay_snd = OptShort[12];
|
||||
delay = OptU16[10];
|
||||
delay_snd = OptU16[12];
|
||||
}
|
||||
|
||||
let flags = flag_ok!(EffectFlags, flags)?;
|
||||
|
@ -95,8 +95,8 @@ pub struct Effect
|
|||
pub shape: u16,
|
||||
pub pitch: Fixed,
|
||||
pub flags: EffectFlags,
|
||||
pub delay: OptShort,
|
||||
pub delay_snd: OptShort,
|
||||
pub delay: OptU16,
|
||||
pub delay_snd: OptU16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
|
|
@ -147,9 +147,9 @@ fn sequence(b: &[u8]) -> ResultS<Sequence>
|
|||
key = u16[44];
|
||||
xfer = u16[46];
|
||||
xfer_pd = u16[48];
|
||||
snd_beg = OptShort[50];
|
||||
snd_key = OptShort[52];
|
||||
snd_end = OptShort[54];
|
||||
snd_beg = OptU16[50];
|
||||
snd_key = OptU16[52];
|
||||
snd_end = OptU16[54];
|
||||
loop_f = u16[58];
|
||||
}
|
||||
|
||||
|
@ -355,9 +355,9 @@ pub struct Sequence
|
|||
key: u16,
|
||||
xfer: TransferMode,
|
||||
xfer_pd: u16,
|
||||
snd_beg: OptShort,
|
||||
snd_key: OptShort,
|
||||
snd_end: OptShort,
|
||||
snd_beg: OptU16,
|
||||
snd_key: OptU16,
|
||||
snd_end: OptU16,
|
||||
loop_f: u16,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue