cargo fmt options

shader120
Luke D. Jones 2022-02-21 20:40:31 +13:00
parent 07cd90f70e
commit c2b5407d3a
35 changed files with 166 additions and 147 deletions

7
.rustfmt.toml Normal file
View File

@ -0,0 +1,7 @@
max_width = 100
imports_granularity = "Crate"
reorder_imports = true
reorder_modules = true
use_field_init_shorthand = true
remove_nested_parens = true
edition = "2021"

View File

@ -6,7 +6,7 @@
[ ] - Implement texture read and prep for use
[X] - FIXED: they work I guess: E3M4 crushers
Split the gameplay out in to a crate. The gameplay requires:
- `p_` files, these are things like thinkers, objects (mobj, lights, sector movers).
- the level data
- the info (state, sprite etc)
Game and doom-lib are now separate crates with these criteria:
- "game" controls input and ticcmd, rendering, and menu display
- "game" will also check state and show appropriate screens (like demo, intermission, menus)
- "doom-lib" is pure gamestate - things like level control, map objects, thinkers etc.

View File

@ -1,5 +1,4 @@
use std::env;
use std::path::PathBuf;
use std::{env, path::PathBuf};
fn main() {
let target = env::var("TARGET").unwrap();

View File

@ -1,6 +1,6 @@
use std::error::Error;
use doom_lib::game::Game;
use doom_lib::Game;
use golem::Context;
use sdl2::{
keyboard::Scancode,

View File

@ -1,11 +1,7 @@
use std::collections::hash_set::HashSet;
use doom_lib::doom_def::WeaponType;
use doom_lib::tic_cmd::*;
use sdl2::event::Event;
use sdl2::keyboard::Scancode as Sc;
use sdl2::mouse::MouseButton as Mb;
use sdl2::EventPump;
use doom_lib::{tic_cmd::*, WeaponType};
use sdl2::{event::Event, keyboard::Scancode as Sc, mouse::MouseButton as Mb, EventPump};
#[derive(Default, Clone)]
pub struct InputEvents {

View File

@ -9,9 +9,9 @@ use std::error::Error;
use d_main::d_doom_loop;
use golem::*;
use gumdrop::Options;
use doom_lib::{d_main::GameOptions, game::Game};
use doom_lib::{Game, GameOptions};
use gumdrop::Options;
use input::Input;
/// The main `game` crate should take care of initialising a few things

View File

@ -1,11 +1,5 @@
use crate::renderer::defs::ClipRange;
use crate::renderer::segs::SegRender;
use crate::renderer::RenderData;
use doom_lib::angle::Angle;
use doom_lib::level_data::map_data::{MapData, IS_SSECTOR_MASK};
use doom_lib::level_data::map_defs::{Segment, SubSector};
use doom_lib::play::map_object::MapObject;
use doom_lib::play::player::Player;
use crate::renderer::{defs::ClipRange, segs::SegRender, RenderData};
use doom_lib::{Angle, MapData, MapObject, Player, Segment, SubSector, IS_SSECTOR_MASK};
use glam::Vec2;
use sdl2::{render::Canvas, surface::Surface};
use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, PI};
@ -397,7 +391,7 @@ pub fn point_to_angle_2(point1: &Vec2, point2: &Vec2) -> Angle {
#[cfg(test)]
mod tests {
use doom_lib::level_data::map_data::{MapData, IS_SSECTOR_MASK};
use doom_lib::{MapData, IS_SSECTOR_MASK};
use wad::WadData;
#[test]

View File

@ -1,6 +1,6 @@
use std::ptr::NonNull;
use doom_lib::level_data::map_defs::Segment;
use doom_lib::Segment;
pub const SIL_NONE: i32 = 0;
pub const SIL_BOTTOM: i32 = 1;

View File

@ -1,7 +1,6 @@
use doom_lib::angle::Angle;
use doom_lib::Angle;
use crate::renderer::defs::DrawSeg;
use crate::renderer::portals::PortalClip;
use crate::renderer::{defs::DrawSeg, portals::PortalClip};
pub mod bsp;
pub mod defs;

View File

@ -1,18 +1,15 @@
use doom_lib::{
angle::Angle,
doom_def::{ML_DONTPEGBOTTOM, ML_MAPPED},
level_data::map_defs::Segment,
play::player::Player,
};
use doom_lib::{Angle, Player, Segment, ML_DONTPEGBOTTOM, ML_MAPPED};
use sdl2::{render::Canvas, surface::Surface};
use std::{
f32::consts::{FRAC_PI_2, PI},
ptr::NonNull,
};
use crate::renderer::RenderData;
use crate::{
renderer::defs::{DrawSeg, MAXDRAWSEGS, SCREENHEIGHT, SIL_BOTH, SIL_BOTTOM, SIL_NONE, SIL_TOP},
renderer::{
defs::{DrawSeg, MAXDRAWSEGS, SCREENHEIGHT, SIL_BOTH, SIL_BOTTOM, SIL_NONE, SIL_TOP},
RenderData,
},
utilities::{point_to_dist, scale_from_view_angle, CLASSIC_SCREEN_X_TO_VIEW},
};

View File

@ -1,8 +1,7 @@
use std::f32::consts::FRAC_PI_4;
use glam::{Mat4, Vec3};
use golem::Dimension::*;
use golem::*;
use golem::{Dimension::*, *};
use super::{Drawer, GL_QUAD, GL_QUAD_INDICES};

View File

@ -1,8 +1,7 @@
use std::f32::consts::FRAC_PI_4;
use glam::{Mat4, Vec3};
use golem::Dimension::*;
use golem::*;
use golem::{Dimension::*, *};
use super::{Drawer, GL_QUAD, GL_QUAD_INDICES};

View File

@ -1,8 +1,7 @@
use std::f32::consts::FRAC_PI_4;
use glam::{Mat4, Vec3};
use golem::Dimension::*;
use golem::*;
use golem::{Dimension::*, *};
use super::{Drawer, GL_QUAD, GL_QUAD_INDICES};

View File

@ -1,5 +1,4 @@
use std::fmt;
use std::time::Instant;
use std::{fmt, time::Instant};
const MS_PER_UPDATE: f32 = 28.57;

View File

@ -1,6 +1,6 @@
use std::f32::consts::{FRAC_PI_2, FRAC_PI_4};
use doom_lib::angle::Angle;
use doom_lib::Angle;
use glam::Vec2;
// pub fn player_dist_to_screen() -> f32 {

View File

@ -3,9 +3,8 @@ use std::ptr::null_mut;
use criterion::*;
use doom_lib::{
d_main, doom_def,
level_data::{map_data::MapData, Level},
play::d_thinker::{ObjectType, TestObject, Think, ThinkerAlloc},
MapData,
};
use wad::WadData;

View File

@ -2,7 +2,7 @@ use std::{path::PathBuf, str::FromStr};
use criterion::*;
use doom_lib::level_data::map_data::MapData;
use doom_lib::MapData;
use wad::wad::WadData;
fn bench_load_e1m1(b: &mut Bencher) {

View File

@ -1,7 +1,7 @@
use gumdrop::Options;
use std::{error::Error, fmt, str::FromStr};
use crate::{doom_def::GameMission, doom_def::GameMode};
use crate::doom_def::{GameMission, GameMode};
#[derive(Debug)]
pub enum DoomArgError {

View File

@ -1,14 +1,16 @@
use crate::d_main;
use crate::d_main::{GameOptions, Skill};
use crate::level_data::{p_ticker, Level};
use crate::play::{
map_object::MapObject,
player::{Player, PlayerState, WBStartStruct},
specials::spawn_specials,
utilities::m_clear_random,
use crate::{
d_main,
d_main::{GameOptions, Skill},
doom_def::*,
level_data::{p_ticker, Level},
play::{
map_object::MapObject,
player::{Player, PlayerState, WBStartStruct},
specials::spawn_specials,
utilities::m_clear_random,
},
tic_cmd::{TicCmd, TIC_CMD_BUTTONS},
};
use crate::tic_cmd::TicCmd;
use crate::{doom_def::*, tic_cmd::TIC_CMD_BUTTONS};
use d_main::identify_version;
use log::{debug, info, trace, warn};
use std::io::Write;

View File

@ -1,6 +1,8 @@
use crate::info::{MapObjectInfo, MapObjectType, StateNum};
use crate::play::map_object::MobjFlag;
use crate::sounds::SfxEnum;
use crate::{
info::{MapObjectInfo, MapObjectType, StateNum},
play::map_object::MobjFlag,
sounds::SfxEnum,
};
/// This variable exists only to help create the mobs array
const NUM_CATEGORIES: usize = MapObjectType::NUMMOBJTYPES as usize;

View File

@ -1,12 +1,12 @@
use log::debug;
use wad::{lumps::WadThing, WadData};
use crate::doom_def::GameAction;
use crate::level_data::map_data::MapData;
use crate::play::d_thinker::ThinkerAlloc;
use crate::{
d_main::Skill, doom_def::GameMode, doom_def::MAXPLAYERS, doom_def::MAX_DEATHMATCH_STARTS,
d_main::Skill,
doom_def::{GameAction, GameMode, MAXPLAYERS, MAX_DEATHMATCH_STARTS},
game::Game,
level_data::map_data::MapData,
play::d_thinker::ThinkerAlloc,
};
/// The level is considered a `World` or sorts. One that exists only

View File

@ -1,11 +1,11 @@
use std::ptr::null_mut;
use crate::angle::Angle;
use crate::level_data::map_defs::{
BBox, LineDef, Node, Sector, Segment, SideDef, SlopeType, SubSector,
use crate::{
angle::Angle,
level_data::map_defs::{BBox, LineDef, Node, Sector, Segment, SideDef, SlopeType, SubSector},
play::utilities::bam_to_radian,
DPtr,
};
use crate::play::utilities::bam_to_radian;
use crate::DPtr;
use glam::Vec2;
use wad::{lumps::*, WadData};
@ -441,8 +441,10 @@ impl BSPTrace {
#[cfg(test)]
mod tests {
use crate::level_data::map_data::MapData;
use crate::{angle::Angle, level_data::map_data::BSPTrace};
use crate::{
angle::Angle,
level_data::map_data::{BSPTrace, MapData},
};
use glam::Vec2;
use std::f32::consts::{FRAC_PI_2, PI};
use wad::WadData;

View File

@ -1,7 +1,8 @@
use crate::angle::Angle;
use crate::play::d_thinker::Thinker;
use crate::play::map_object::MapObject;
use crate::DPtr;
use crate::{
angle::Angle,
play::{d_thinker::Thinker, map_object::MapObject},
DPtr,
};
use glam::Vec2;
#[derive(Debug)]

View File

@ -2,8 +2,7 @@ use std::f32::consts::PI;
use crate::level_data::map_defs::Node;
use crate::play::utilities::ray_to_line_intersect;
use crate::radian_range;
use crate::{play::utilities::ray_to_line_intersect, radian_range};
use glam::Vec2;
impl Node {

View File

@ -1,21 +1,33 @@
// #![feature(const_fn_floating_point_arithmetic)]
use std::f32::consts::PI;
use std::fmt;
use std::ops::{Deref, DerefMut};
use std::{
f32::consts::PI,
fmt,
ops::{Deref, DerefMut},
};
pub mod angle;
pub mod d_main;
pub mod doom_def;
pub mod errors;
pub mod flags;
pub mod game;
pub mod info;
pub mod level_data;
pub mod play;
pub mod sounds;
mod angle;
mod d_main;
mod doom_def;
mod errors;
mod flags;
mod game;
mod info;
mod level_data;
mod play;
mod sounds;
pub mod tic_cmd;
pub use angle::Angle;
pub use d_main::GameOptions;
pub use doom_def::{WeaponType, ML_DONTPEGBOTTOM, ML_MAPPED};
pub use game::Game;
pub use level_data::{
map_data::{MapData, IS_SSECTOR_MASK},
map_defs::{Segment, SubSector},
};
pub use play::{map_object::MapObject, player::Player};
/// Functions purely as a safe fn wrapper around a `NonNull` because we know that
/// the Map structure is not going to change under us
pub struct DPtr<T> {

View File

@ -1,7 +1,9 @@
use std::alloc::{alloc, dealloc, Layout};
use std::fmt::{self, Debug};
use std::mem::{align_of, size_of};
use std::ptr::{self, null_mut};
use std::{
alloc::{alloc, dealloc, Layout},
fmt::{self, Debug},
mem::{align_of, size_of},
ptr::{self, null_mut},
};
use log::debug;

View File

@ -3,18 +3,26 @@
//! Doom source name `p_doors`
use log::{debug, error, warn};
use std::fmt::{self, Formatter};
use std::ptr::null_mut;
use std::{
fmt::{self, Formatter},
ptr::null_mut,
};
use crate::doom_def::TICRATE;
use crate::level_data::map_defs::Sector;
use crate::level_data::Level;
use crate::play::specials::{move_plane, PlaneResult};
use crate::{doom_def::Card, level_data::map_defs::LineDef, DPtr};
use crate::{
doom_def::{Card, TICRATE},
level_data::{
map_defs::{LineDef, Sector},
Level,
},
play::specials::{move_plane, PlaneResult},
DPtr,
};
use super::d_thinker::{ObjectType, Think, Thinker};
use super::map_object::MapObject;
use super::specials::find_lowest_ceiling_surrounding;
use super::{
d_thinker::{ObjectType, Think, Thinker},
map_object::MapObject,
specials::find_lowest_ceiling_surrounding,
};
const VDOOR: f32 = 2.0;
const VDOORWAIT: i32 = 150;

View File

@ -2,9 +2,13 @@
use std::ptr::null_mut;
use crate::level_data::map_defs::{LineDef, Sector};
use crate::level_data::Level;
use crate::DPtr;
use crate::{
level_data::{
map_defs::{LineDef, Sector},
Level,
},
DPtr,
};
use super::{
d_thinker::{ObjectType, Think, Thinker},

View File

@ -18,15 +18,13 @@ use crate::level_data::Level;
use glam::Vec2;
use wad::lumps::WadThing;
use crate::info::MOBJINFO;
use crate::info::{ActionF, MapObjectType, SpriteNum, State, StateNum, STATES};
use crate::level_data::map_defs::SubSector;
use crate::sounds::SfxEnum;
use crate::{
angle::Angle,
d_main::Skill,
doom_def::{MAXPLAYERS, MTF_AMBUSH, TICRATE},
info::MapObjectInfo,
info::{ActionF, MapObjectInfo, MapObjectType, SpriteNum, State, StateNum, MOBJINFO, STATES},
level_data::map_defs::SubSector,
sounds::SfxEnum,
};
use std::f32::consts::PI;

View File

@ -7,15 +7,20 @@ use super::{
map_object::{MapObject, MobjFlag},
specials::cross_special_line,
switch::p_use_special_line,
utilities::{box_on_line_side, path_traverse, PortalZ},
utilities::{BestSlide, Intercept, MAXRADIUS, USERANGE},
utilities::{
box_on_line_side, path_traverse, BestSlide, Intercept, PortalZ, MAXRADIUS, USERANGE,
},
};
use crate::angle::Angle;
use crate::flags::LineDefFlags;
use crate::level_data::map_data::BSPTrace;
use crate::level_data::map_defs::{BBox, LineDef, SlopeType};
use crate::DPtr;
use crate::{
angle::Angle,
flags::LineDefFlags,
level_data::{
map_data::BSPTrace,
map_defs::{BBox, LineDef, SlopeType},
},
DPtr,
};
//const MAXSPECIALCROSS: i32 = 8;
pub const PT_ADDLINES: i32 = 1;

View File

@ -1,5 +1,4 @@
use std::f32::consts::FRAC_PI_2;
use std::ptr::NonNull;
use std::{f32::consts::FRAC_PI_2, ptr::NonNull};
use glam::Vec2;
@ -9,15 +8,13 @@ use super::{
utilities::{bam_to_radian, fixed_to_float, MAXHEALTH, VIEWHEIGHT},
};
use crate::info::StateNum;
use crate::level_data::Level;
use crate::tic_cmd::TIC_CMD_BUTTONS;
use crate::{
angle::Angle,
doom_def::MAX_AMMO,
doom_def::{AmmoType, Card, PowerType, WeaponType, MAXPLAYERS},
doom_def::{AmmoType, Card, PowerType, WeaponType, MAXPLAYERS, MAX_AMMO},
info::{SpriteNum, StateNum},
level_data::Level,
tic_cmd::{TicCmd, TIC_CMD_BUTTONS},
};
use crate::{info::SpriteNum, tic_cmd::TicCmd};
/// 16 pixels of bob
const MAXBOB: f32 = 16.0; // 0x100000;

View File

@ -16,11 +16,15 @@ use super::{
platforms::{ev_do_platform, PlatKind},
};
use crate::flags::LineDefFlags;
use crate::info::MapObjectType;
use crate::level_data::map_defs::{LineDef, Sector};
use crate::level_data::Level;
use crate::DPtr;
use crate::{
flags::LineDefFlags,
info::MapObjectType,
level_data::{
map_defs::{LineDef, Sector},
Level,
},
DPtr,
};
use log::{debug, error, trace, warn};
pub fn get_next_sector(line: DPtr<LineDef>, sector: DPtr<Sector>) -> Option<DPtr<Sector>> {

View File

@ -1,10 +1,12 @@
//! Many helper functions related to traversing the map, crossing or finding lines.
use super::map_object::MapObject;
use super::movement::{PT_ADDLINES, PT_EARLYOUT};
use super::{
map_object::MapObject,
movement::{PT_ADDLINES, PT_EARLYOUT},
};
use crate::angle::Angle;
use crate::{
angle::Angle,
level_data::{
map_data::BSPTrace,
map_defs::{BBox, LineDef, SlopeType},

View File

@ -1,5 +1,4 @@
use crate::lumps::*;
use crate::{Lumps, WadData};
use crate::{lumps::*, Lumps, WadData};
use std::marker::PhantomData;
pub struct LumpIter<T, F: Fn(usize) -> T> {
@ -261,8 +260,7 @@ impl WadData {
#[cfg(test)]
mod tests {
use crate::lumps::WadThing;
use crate::wad::WadData;
use crate::{lumps::WadThing, wad::WadData};
#[test]
fn things_iter() {

View File

@ -1,7 +1,4 @@
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
use std::{fmt, str};
use std::{fmt, fs::File, io::prelude::*, path::PathBuf, str};
use crate::lumps::WadBlockMap;
@ -307,8 +304,7 @@ impl WadData {
#[cfg(test)]
mod tests {
use crate::wad::WadData;
use crate::Lumps;
use crate::{wad::WadData, Lumps};
#[test]
fn load_wad() {