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.
|
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 "Optional Short" is a 16-bit integer which references something by index. If
|
A "`u16opt`" is a 16-bit integer which references something by index. If all
|
||||||
all bits are set, it is to be interpreted as "none." Traditionally, these are
|
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 ##
|
||||||
|
@ -578,9 +578,9 @@ Side Texture is 6 bytes. Just stores a texture and an offset.
|
||||||
| ---- | ---- | ------ |
|
| ---- | ---- | ------ |
|
||||||
| `OffsetX` | `unit` | `0` |
|
| `OffsetX` | `unit` | `0` |
|
||||||
| `OffsetY` | `unit` | `2` |
|
| `OffsetY` | `unit` | `2` |
|
||||||
| `TextureId` | `u16` | `4` |
|
| `TextureId` | `u16opt` | `4` |
|
||||||
|
|
||||||
- `TextureId` is an Optional Short referencing a Shapes bitmap.
|
- `TextureId` references a Shapes bitmap.
|
||||||
|
|
||||||
### Point ###
|
### Point ###
|
||||||
|
|
||||||
|
@ -622,19 +622,17 @@ Line is 32 bytes. A geometric line segment.
|
||||||
| `Length` | `unit` | `6` |
|
| `Length` | `unit` | `6` |
|
||||||
| `HeightHi` | `unit` | `8` |
|
| `HeightHi` | `unit` | `8` |
|
||||||
| `HeightLo` | `unit` | `10` |
|
| `HeightLo` | `unit` | `10` |
|
||||||
| `SideFrnt` | `u16` | `12` |
|
| `SideFrnt` | `u16opt` | `12` |
|
||||||
| `SideBack` | `u16` | `14` |
|
| `SideBack` | `u16opt` | `14` |
|
||||||
| `PolyFrnt` | `u16` | `16` |
|
| `PolyFrnt` | `u16opt` | `16` |
|
||||||
| `PolyBack` | `u16` | `18` |
|
| `PolyBack` | `u16opt` | `18` |
|
||||||
|
|
||||||
- `PointBeg` and `PointEnd` are the beginning and terminating endpoints.
|
- `PointBeg` and `PointEnd` are the beginning and terminating endpoints.
|
||||||
- `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 Optional Short indices of the Sides in the
|
- `SideFrnt` and `SideBack` are indices of the Sides in the front and back.
|
||||||
front and back.
|
- `PolyFrnt` and `PolyBack` are indices of the connected Polygons.
|
||||||
- `PolyFrnt` and `PolyBack` are Optional Short indices of the connected
|
|
||||||
Polygons.
|
|
||||||
|
|
||||||
### Side ###
|
### Side ###
|
||||||
|
|
||||||
|
@ -706,11 +704,11 @@ shape and automatically split them.)
|
||||||
| `SideArray` | `u16[8]` | `92` |
|
| `SideArray` | `u16[8]` | `92` |
|
||||||
| `OrigFlr` | `struct` | `108` |
|
| `OrigFlr` | `struct` | `108` |
|
||||||
| `OrigCei` | `struct` | `112` |
|
| `OrigCei` | `struct` | `112` |
|
||||||
| `Media` | `u16` | `116` |
|
| `Media` | `u16opt` | `116` |
|
||||||
| `MediaLight` | `u16` | `118` |
|
| `MediaLight` | `u16` | `118` |
|
||||||
| `SoundIndices` | `u16` | `120` |
|
| `SoundIndices` | `u16` | `120` |
|
||||||
| `SoundAmbient` | `u16` | `122` |
|
| `SoundAmbient` | `u16opt` | `122` |
|
||||||
| `SoundRandom` | `u16` | `124` |
|
| `SoundRandom` | `u16opt` | `124` |
|
||||||
|
|
||||||
- `Type` is a Polygon Type enumeration.
|
- `Type` is a Polygon Type enumeration.
|
||||||
- `Flags` is a Polygon Flags bit field.
|
- `Flags` is a Polygon Flags bit field.
|
||||||
|
@ -719,9 +717,6 @@ 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 Optional Short.
|
|
||||||
- `SoundAmbient` is an Optional Short.
|
|
||||||
- `SoundRandom` is an Optional Short.
|
|
||||||
|
|
||||||
### Light ###
|
### Light ###
|
||||||
|
|
||||||
|
@ -847,14 +842,13 @@ part of the map in the middle of a wall.
|
||||||
| `Origin` | `struct` | `14` |
|
| `Origin` | `struct` | `14` |
|
||||||
| `Height` | `unit` | `18` |
|
| `Height` | `unit` | `18` |
|
||||||
| `Minimum` | `fixed` | `20` |
|
| `Minimum` | `fixed` | `20` |
|
||||||
| `Texture` | `u16` | `24` |
|
| `Texture` | `u16opt` | `24` |
|
||||||
| `XferMode` | `u16` | `26` |
|
| `XferMode` | `u16` | `26` |
|
||||||
|
|
||||||
- `Type` is a Media Type enumeration.
|
- `Type` is a Media Type enumeration.
|
||||||
- `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 Optional Short representing the texture index.
|
|
||||||
- `XferMode` is a Transfer Mode enumeration.
|
- `XferMode` is a Transfer Mode enumeration.
|
||||||
|
|
||||||
### Static Map Info ###
|
### Static Map Info ###
|
||||||
|
@ -1190,7 +1184,7 @@ Frame is 36 bytes. TODO: document how world transform works.
|
||||||
| ---- | ---- | ------ |
|
| ---- | ---- | ------ |
|
||||||
| `Flags` | `u16` | `0` |
|
| `Flags` | `u16` | `0` |
|
||||||
| `MinLight` | `fixed` | `2` |
|
| `MinLight` | `fixed` | `2` |
|
||||||
| `BmpIndex` | `u16` | `6` |
|
| `BmpIndex` | `u16opt` | `6` |
|
||||||
| `WldLeft` | `unit` | `14` |
|
| `WldLeft` | `unit` | `14` |
|
||||||
| `WldRight` | `unit` | `16` |
|
| `WldRight` | `unit` | `16` |
|
||||||
| `WldTop` | `unit` | `18` |
|
| `WldTop` | `unit` | `18` |
|
||||||
|
@ -1200,7 +1194,6 @@ 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 Optional Short for the bitmap index.
|
|
||||||
|
|
||||||
### Sequence ###
|
### Sequence ###
|
||||||
|
|
||||||
|
@ -1291,7 +1284,7 @@ Sound Definition is 64 bytes.
|
||||||
|
|
||||||
| Name | Type | Offset |
|
| Name | Type | Offset |
|
||||||
| ---- | ---- | ------ |
|
| ---- | ---- | ------ |
|
||||||
| `Code` | `u16` | `0` |
|
| `Code` | `u16opt` | `0` |
|
||||||
| `Volume` | `u16` | `2` |
|
| `Volume` | `u16` | `2` |
|
||||||
| `Flags` | `u16` | `4` |
|
| `Flags` | `u16` | `4` |
|
||||||
| `Chance` | `u16` | `6` |
|
| `Chance` | `u16` | `6` |
|
||||||
|
@ -1303,7 +1296,6 @@ Sound Definition is 64 bytes.
|
||||||
| `GroupSize` | `u32` | `28` |
|
| `GroupSize` | `u32` | `28` |
|
||||||
| `AddOffset` | `u32[5]` | `32` |
|
| `AddOffset` | `u32[5]` | `32` |
|
||||||
|
|
||||||
- `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.
|
||||||
|
|
|
@ -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 OptShort $n:expr) => {
|
(BE $b:ident $nam:ident OptU16 $n:expr) => {
|
||||||
rd_1!($b u16::from_be_bytes, $nam 2 $n);
|
rd_1!($b u16::from_be_bytes, $nam 2 $n);
|
||||||
let $nam = OptShort::from_repr($nam);
|
let $nam = OptU16::from_repr($nam);
|
||||||
};
|
};
|
||||||
|
|
||||||
// little endian
|
// little endian
|
||||||
|
@ -154,19 +154,19 @@ pub fn rd_ofstable<T, F>(b: &[u8],
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OptShort
|
impl OptU16
|
||||||
{
|
{
|
||||||
/// Creates an `OptShort` from a `u16`.
|
/// Creates an `OptU16` from a `u16`.
|
||||||
pub fn from_repr(n: u16) -> OptShort
|
pub fn from_repr(n: u16) -> OptU16
|
||||||
{
|
{
|
||||||
if n == u16::max_value() {
|
if n == u16::max_value() {
|
||||||
OptShort(None)
|
OptU16(None)
|
||||||
} else {
|
} 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
|
pub fn get_repr(&self) -> u16
|
||||||
{
|
{
|
||||||
match self.0 {
|
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>
|
pub fn get(&self) -> Option<u16>
|
||||||
{
|
{
|
||||||
match self.0 {
|
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
|
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
|
/// An object identified by a `u16` which may be `u16::max_value()` to
|
||||||
/// represent None.
|
/// represent None.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct OptShort(Option<NonZeroU16>);
|
pub struct OptU16(Option<NonZeroU16>);
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -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 = OptShort[4];
|
tex_id = OptU16[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 = OptShort[12];
|
side_fr = OptU16[12];
|
||||||
side_bk = OptShort[14];
|
side_bk = OptU16[14];
|
||||||
poly_fr = OptShort[16];
|
poly_fr = OptU16[16];
|
||||||
poly_bk = OptShort[18];
|
poly_bk = OptU16[18];
|
||||||
}
|
}
|
||||||
|
|
||||||
let flags = flag_ok!(LineFlags, flags)?;
|
let flags = flag_ok!(LineFlags, flags)?;
|
||||||
|
@ -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 = OptShort[40];
|
tex_flr = OptU16[40];
|
||||||
tex_cei = OptShort[42];
|
tex_cei = OptU16[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 = OptShort[116];
|
med_ind = OptU16[116];
|
||||||
med_ctl = u16[118];
|
med_ctl = u16[118];
|
||||||
snd_ind = u16[120];
|
snd_ind = u16[120];
|
||||||
snd_amb = OptShort[122];
|
snd_amb = OptU16[122];
|
||||||
snd_rnd = OptShort[124];
|
snd_rnd = OptU16[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 = OptShort[24];
|
texture = OptU16[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: OptShort,
|
pub side_fr: OptU16,
|
||||||
pub side_bk: OptShort,
|
pub side_bk: OptU16,
|
||||||
pub poly_fr: OptShort,
|
pub poly_fr: OptU16,
|
||||||
pub poly_bk: OptShort,
|
pub poly_bk: OptU16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct SideTex
|
pub struct SideTex
|
||||||
{
|
{
|
||||||
pub offs: Point,
|
pub offs: Point,
|
||||||
pub tex_id: OptShort,
|
pub tex_id: OptU16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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: OptShort,
|
pub tex_flr: OptU16,
|
||||||
pub tex_cei: OptShort,
|
pub tex_cei: OptU16,
|
||||||
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: OptShort,
|
pub med_ind: OptU16,
|
||||||
pub med_ctl: u16,
|
pub med_ctl: u16,
|
||||||
pub snd_ind: u16,
|
pub snd_ind: u16,
|
||||||
pub snd_amb: OptShort,
|
pub snd_amb: OptU16,
|
||||||
pub snd_rnd: OptShort,
|
pub snd_rnd: OptU16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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: OptShort,
|
pub texture: OptU16,
|
||||||
pub xfer: TransferMode,
|
pub xfer: TransferMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ pub fn read_fxpx(b: &[u8]) -> ResultS<(Effect, usize)>
|
||||||
shape = u16[2];
|
shape = u16[2];
|
||||||
pitch = Fixed[4];
|
pitch = Fixed[4];
|
||||||
flags = u16[8];
|
flags = u16[8];
|
||||||
delay = OptShort[10];
|
delay = OptU16[10];
|
||||||
delay_snd = OptShort[12];
|
delay_snd = OptU16[12];
|
||||||
}
|
}
|
||||||
|
|
||||||
let flags = flag_ok!(EffectFlags, flags)?;
|
let flags = flag_ok!(EffectFlags, flags)?;
|
||||||
|
@ -95,8 +95,8 @@ pub struct Effect
|
||||||
pub shape: u16,
|
pub shape: u16,
|
||||||
pub pitch: Fixed,
|
pub pitch: Fixed,
|
||||||
pub flags: EffectFlags,
|
pub flags: EffectFlags,
|
||||||
pub delay: OptShort,
|
pub delay: OptU16,
|
||||||
pub delay_snd: OptShort,
|
pub delay_snd: OptU16,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
|
|
@ -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 = OptShort[50];
|
snd_beg = OptU16[50];
|
||||||
snd_key = OptShort[52];
|
snd_key = OptU16[52];
|
||||||
snd_end = OptShort[54];
|
snd_end = OptU16[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: OptShort,
|
snd_beg: OptU16,
|
||||||
snd_key: OptShort,
|
snd_key: OptU16,
|
||||||
snd_end: OptShort,
|
snd_end: OptU16,
|
||||||
loop_f: u16,
|
loop_f: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue