Skip to content

Commit

Permalink
Make more func const, fix some movement
Browse files Browse the repository at this point in the history
  • Loading branch information
flukejones committed Nov 14, 2024
1 parent a48a342 commit 0b0054f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;
use std::path::PathBuf;

fn main() {
println!("cargo::rustc-check-cfg=cfg(Debug)");
// #[cfg(all(target_os = "macos", feature = "sdl2-bundled"))]
// println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path");

Expand Down
4 changes: 2 additions & 2 deletions game-exe/src/d_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use gamestate::Game;
use gamestate_traits::sdl2::keyboard::Scancode;
use gamestate_traits::sdl2::pixels::PixelFormatEnum;
use gamestate_traits::sdl2::render::Canvas;
use gamestate_traits::sdl2::video::{Window, WindowPos};
use gamestate_traits::sdl2::video::Window;
use gamestate_traits::{sdl2, GameState, SubsystemTrait};
use hud_doom::Messages;
use input::Input;
Expand Down Expand Up @@ -453,7 +453,7 @@ fn process_events(
let event_callback = |event: sdl2::event::Event| match event {
sdl2::event::Event::Window {
timestamp: _,
window_id,
window_id: _,
win_event,
} => {
match win_event {
Expand Down
1 change: 0 additions & 1 deletion game-exe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ fn main() -> Result<(), Box<dyn Error>> {
for n in 0..num_disp {
info!("Found display {:?}", video_ctx.display_name(n)?);
}
let b = video_ctx.display_bounds(1)?;
let mut window = video_ctx
.window("ROOM4DOOM", 0, 0)
.opengl()
Expand Down
11 changes: 5 additions & 6 deletions gameplay/src/thing/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ use crate::level::flags::LineDefFlags;
use crate::level::map_data::BSPTrace;
use crate::level::map_defs::{BBox, LineDef, SlopeType};
use crate::utilities::{
box_on_line_side, circle_circle_intersect, p_random, path_traverse, BestSlide, Intercept, PortalZ, FRACUNIT_DIV4
box_on_line_side, circle_circle_intersect, fixed_to_float, p_random, path_traverse, BestSlide, Intercept, PortalZ, FRACUNIT_DIV4
};
use crate::{MapObjKind, MapObject, MapPtr};

use super::MapObjFlag;

pub const GRAVITY: f32 = 1.0;
pub const MAXMOVE: f32 = 30.0;
pub const STOPSPEED: f32 = 0.06250095; // 0x1000
pub const FRICTION: f32 = 0.9062638; // 0xE800
pub const STOPSPEED: f32 = fixed_to_float(0x1000);
pub const FRICTION: f32 = fixed_to_float(0xE800);

//const MAXSPECIALCROSS: i32 = 8;
pub const PT_ADDLINES: i32 = 1;
Expand Down Expand Up @@ -235,11 +235,10 @@ impl MapObject {
if let Some(player) = self.player_mut() {
if player.cmd.forwardmove == 0 && player.cmd.sidemove == 0 {
self.set_state(StateNum::PLAY);
self.momxyz = Vec3::default();
}
} else {
self.momxyz = Vec3::default();
}
self.momxyz.x = 0.0;
self.momxyz.y = 0.0;
} else {
self.momxyz.x *= FRICTION;
self.momxyz.y *= FRICTION;
Expand Down
14 changes: 7 additions & 7 deletions gameplay/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const FRACUNIT: f32 = (1 << FRACBITS) as f32;
pub const FRACUNIT_DIV4: f32 = FRACUNIT / 4.0;

/// Convert a Doom `fixed_t` fixed-point float to `f32`
pub fn fixed_to_float(value: i32) -> f32 {
pub const fn fixed_to_float(value: i32) -> f32 {
value as f32 / FRACUNIT
}

const DEG_TO_RAD: f32 = PI / 180.0;

/// Convert a BAM (Binary Angle Measure) to radians
pub fn bam_to_radian(value: u32) -> f32 {
pub const fn bam_to_radian(value: u32) -> f32 {
(value as f32 * 8.381_903e-8) * DEG_TO_RAD
}

Expand All @@ -47,29 +47,29 @@ pub const RNDTABLE: [i32; 256] = [
84, 118, 222, 187, 136, 120, 163, 236, 249,
];

pub fn p_random() -> i32 {
pub const fn p_random() -> i32 {
unsafe {
PRNDINDEX = (PRNDINDEX + 1) & 0xFF;
RNDTABLE[PRNDINDEX]
}
}

pub fn m_random() -> i32 {
pub const fn m_random() -> i32 {
unsafe {
RNDINDEX = (RNDINDEX + 1) & 0xFF;
RNDTABLE[RNDINDEX]
}
}

pub fn m_clear_random() {
pub const fn m_clear_random() {
unsafe {
// Not clearing this random as it's used only by screen wipe so far
//RNDINDEX = 0;
PRNDINDEX = 0;
}
}

pub fn p_subrandom() -> i32 {
pub const fn p_subrandom() -> i32 {
let r = p_random();
r - p_random()
}
Expand All @@ -83,7 +83,7 @@ pub struct Trace {
}

impl Trace {
pub fn new(xyz: Vec3, dxyz: Vec3) -> Self {
pub const fn new(xyz: Vec3, dxyz: Vec3) -> Self {
Self { xyz, dxyz }
}
}
Expand Down
52 changes: 26 additions & 26 deletions intermission/doom/src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ pub(crate) struct Patches {
// pub minus: WadPatch,
pub percent: WadPatch,
pub kills: WadPatch,
pub secret: WadPatch,
pub sp_secret: WadPatch,
pub items: WadPatch,
pub frags: WadPatch,
pub colon: WadPatch,
pub time: WadPatch,
pub sucks: WadPatch,
pub par: WadPatch,
pub killers: WadPatch,
pub victims: WadPatch,
pub total: WadPatch,
pub star: WadPatch,
pub bstar: WadPatch,
pub enter: WadPatch,
pub finish: WadPatch,
pub players: [WadPatch; MAXPLAYERS],
pub bplayers: [WadPatch; MAXPLAYERS],
// secret: WadPatch,
// frags: WadPatch,
// killers: WadPatch,
// victims: WadPatch,
// total: WadPatch,
// sucks: WadPatch,
// star: WadPatch,
// bstar: WadPatch,
// players: [WadPatch; MAXPLAYERS],
// bplayers: [WadPatch; MAXPLAYERS],
}

impl Patches {
Expand Down Expand Up @@ -58,23 +58,23 @@ impl Patches {
nums: get_num_sprites("WINUM", 0, wad),
percent: WadPatch::from_lump(wad.get_lump("WIPCNT").unwrap()),
kills: WadPatch::from_lump(wad.get_lump("WIOSTK").unwrap()),
secret: WadPatch::from_lump(wad.get_lump("WIOSTS").unwrap()),
sp_secret: WadPatch::from_lump(wad.get_lump("WISCRT2").unwrap()),
items: WadPatch::from_lump(wad.get_lump("WIOSTI").unwrap()),
frags: WadPatch::from_lump(wad.get_lump("WIFRGS").unwrap()),
colon: WadPatch::from_lump(wad.get_lump("WICOLON").unwrap()),
time: WadPatch::from_lump(wad.get_lump("WITIME").unwrap()),
sucks: WadPatch::from_lump(wad.get_lump("WISUCKS").unwrap()),
par: WadPatch::from_lump(wad.get_lump("WIPAR").unwrap()),
killers: WadPatch::from_lump(wad.get_lump("WIKILRS").unwrap()),
victims: WadPatch::from_lump(wad.get_lump("WIVCTMS").unwrap()),
total: WadPatch::from_lump(wad.get_lump("WIMSTT").unwrap()),
star: WadPatch::from_lump(wad.get_lump("STFST01").unwrap()),
bstar: WadPatch::from_lump(wad.get_lump("STFDEAD0").unwrap()),
enter: WadPatch::from_lump(wad.get_lump("WIENTER").unwrap()),
finish: WadPatch::from_lump(wad.get_lump("WIF").unwrap()),
players: unsafe { players.map(|n| n.assume_init()) },
bplayers: unsafe { bplayers.map(|n| n.assume_init()) },
// secret: WadPatch::from_lump(wad.get_lump("WIOSTS").unwrap()),
// frags: WadPatch::from_lump(wad.get_lump("WIFRGS").unwrap()),
// sucks: WadPatch::from_lump(wad.get_lump("WISUCKS").unwrap()),
// killers: WadPatch::from_lump(wad.get_lump("WIKILRS").unwrap()),
// victims: WadPatch::from_lump(wad.get_lump("WIVCTMS").unwrap()),
// total: WadPatch::from_lump(wad.get_lump("WIMSTT").unwrap()),
// star: WadPatch::from_lump(wad.get_lump("STFST01").unwrap()),
// bstar: WadPatch::from_lump(wad.get_lump("STFDEAD0").unwrap()),
// players: unsafe { players.map(|n| n.assume_init()) },
// bplayers: unsafe { bplayers.map(|n| n.assume_init()) },
}
}
}
Expand Down Expand Up @@ -149,12 +149,12 @@ pub(crate) struct Animation {
// following must be initialized to zero before use!
// next value of bcnt (used in conjunction with period)
pub next_tic: i32,
// last drawn animation frame (Doom II)
pub last_drawn: i32,
// next frame number to animate
pub counter: i32,
// used by RANDOM and LEVEL when animating (Doom II)
pub state: i32,
// // used by RANDOM and LEVEL when animating (Doom II)
// pub state: i32,
// // last drawn animation frame (Doom II)
// pub last_drawn: i32,
}

impl Animation {
Expand All @@ -174,9 +174,9 @@ impl Animation {
data2: 0,
patches: Vec::new(),
next_tic: 0,
last_drawn: 0,
counter: 0,
state: 0,
// state: 0,
// last_drawn: 0,
}
}
}
Expand Down

0 comments on commit 0b0054f

Please sign in to comment.