### DEATHMATCH_START Source: https://docs.rs/neurodoom/0.6.7/neurodoom/map/doomednum/constant.DEATHMATCH_START.html The DEATHMATCH_START constant is an i16 value representing the starting point for deathmatch mode. ```APIDOC ## Constant DEATHMATCH_START neurodoom::map::doomednum ### Summary ```rust pub const DEATHMATCH_START: i16 = 11; ``` This constant defines the initial spawn point or identifier for deathmatch games within the `doomednum` module of the `neurodoom` crate. ``` -------------------------------- ### Line of Sight BSP Traversal Setup Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/physics.rs.html Sets up parameters for BSP traversal to check line-of-sight, calculating slopes based on start and end points and entity heights. ```rust let dx = x2 - x1; let dy = y2 - y1; let eye_z = z1; let mut top_slope = (z2 + h2) - eye_z; let mut bottom_slope = z2 - eye_z; // Traverse BSP cross_bsp_node( map, map.root_node(), x1, y1, dx, dy, x2, y2, eye_z, &mut top_slope, &mut bottom_slope, ) ``` -------------------------------- ### Renderer::init_planes Source: https://docs.rs/neurodoom/0.6.7/neurodoom/render/struct.Renderer.html Initializes lookup tables used for rendering planes. This is a setup function called once or as needed. ```APIDOC ## Renderer::init_planes ### Description Lookup tables for plane rendering. ### Method `init_planes` ``` -------------------------------- ### Initialize Visplane Lookup Tables Source: https://docs.rs/neurodoom/latest/neurodoom/render/struct.Renderer.html Initializes lookup tables used for rendering planes. This is a setup step for plane rendering. ```rust pub fn init_planes(&mut self) Source ``` -------------------------------- ### MobjInfo Configuration Example Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/game_data.rs.html Configuration for a MobjInfo entry, specifying properties like health, states, sounds, and flags. Used to define game entities. ```rust MobjInfo { doomednum: 30, spawnstate: StateNum(907), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, painstate: StateNum(0), painchance: 0, painsound: 0, meleestate: StateNum(0), missilestate: StateNum(0), deathstate: StateNum(0), xdeathstate: StateNum(0), deathsound: 0, speed: 0, radius: 1048576, height: 1048576, mass: 100, damage: 0, activesound: 0, raw_flags: 2, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 31, spawnstate: StateNum(908), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, painstate: StateNum(0), painchance: 0, painsound: 0, meleestate: StateNum(0), missilestate: StateNum(0), deathstate: StateNum(0), xdeathstate: StateNum(0), deathsound: 0, speed: 0, radius: 1048576, height: 1048576, mass: 100, damage: 0, activesound: 0, raw_flags: 2, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 32, spawnstate: StateNum(909), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, painstate: StateNum(0), painchance: 0, painsound: 0, meleestate: StateNum(0), missilestate: StateNum(0), deathstate: StateNum(0), xdeathstate: StateNum(0), deathsound: 0, speed: 0, radius: 1048576, height: 1048576, mass: 100, damage: 0, activesound: 0, raw_flags: 2, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 33, spawnstate: StateNum(910), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, painstate: StateNum(0), painchance: 0, painsound: 0, meleestate: StateNum(0), missilestate: StateNum(0), deathstate: StateNum(0), xdeathstate: StateNum(0), deathsound: 0, speed: 0, radius: 1048576, height: 1048576, mass: 100, damage: 0, activesound: 0, raw_flags: 2, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 37, spawnstate: StateNum(913), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, painstate: StateNum(0), painchance: 0, painsound: 0, meleestate: StateNum(0), missilestate: StateNum(0), deathstate: StateNum(0), xdeathstate: StateNum(0), deathsound: 0, speed: 0, radius: 1048576, height: 1048576, mass: 100, damage: 0, activesound: 0, raw_flags: 2, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 36, spawnstate: StateNum(924), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, painstate: StateNum(0), painchance: 0, painsound: 0, meleestate: StateNum(0), missilestate: StateNum(0), deathstate: StateNum(0), xdeathstate: StateNum(0), deathsound: 0, speed: 0, radius: 1048576, height: 1048576, mass: 100, damage: 0, activesound: 0, raw_flags: 2, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 41, spawnstate: StateNum(917), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, painstate: StateNum(0), painchance: 0, painsound: 0, meleestate: StateNum(0), missilestate: StateNum(0), deathstate: StateNum(0), xdeathstate: StateNum(0), deathsound: 0, speed: 0, radius: 1048576, height: 1048576, mass: 100, damage: 0, activesound: 0, raw_flags: 2, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 42, spawnstate: StateNum(921), spawnhealth: 1000, seestate: StateNum(0), seesound: 0, reactiontime: 8, attacksound: 0, } ``` -------------------------------- ### Setup Renderer for a Frame Source: https://docs.rs/neurodoom/latest/neurodoom/render/struct.Renderer.html Sets up the renderer's view parameters for a new frame. This includes position (x, y, z) and viewing angle. ```rust pub fn setup_frame(&mut self, x: Fixed, y: Fixed, z: Fixed, angle: Angle) Source ``` -------------------------------- ### Initialize Z-Light Tables Source: https://docs.rs/neurodoom/latest/neurodoom/render/struct.Renderer.html Initializes zlight tables, which are used for distance-based lighting calculations for planes. This is part of the lighting setup. ```rust pub fn init_zlight(&mut self) Source ``` -------------------------------- ### MobjInfo Structure Example Source: https://docs.rs/neurodoom/latest/src/neurodoom/game_data.rs.html This snippet illustrates the `MobjInfo` structure, which defines properties for game monsters (mobjects). It includes fields for health, states, sounds, and combat parameters. ```rust MobjInfo { doomednum: -1, spawnstate: StateNum(149), spawnhealth: 100, seestate: StateNum(150), seesound: 0, reactiontime: 0, attacksound: 0, painstate: StateNum(156), painchance: 255, painsound: 25, meleestate: StateNum(0), missilestate: StateNum(154), deathstate: StateNum(158), xdeathstate: StateNum(165), deathsound: 57, speed: 0, radius: 1048576, height: 3670016, mass: 100, damage: 0, activesound: 0, raw_flags: 33557510, raisestate: StateNum(0), } ``` ```rust MobjInfo { doomednum: 3004, spawnstate: StateNum(174), spawnhealth: 20, seestate: StateNum(176), seesound: 36, reactiontime: 8, attacksound: 1, painstate: StateNum(187), painchance: 200, painsound: 27, meleestate: StateNum(0), ``` -------------------------------- ### Quick Start: Initialize and Tick Classic Doom Engine Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/lib.rs.html Demonstrates how to initialize the ClassicEngine with a WAD file and run a single tick for a player. Shows how to retrieve the framebuffer, semantic buffer, and depth buffer. ```rust #![no_std] // Surface every direct panic site as a warning so they cannot drift in // unnoticed. `clippy::indexing_slicing` is enabled globally; the renderer // and physics hot loops carry module-level `#![allow]` with documented // rationale (see src/render/mod.rs). We deliberately do NOT enable // `clippy::arithmetic_side_effects` — Doom's fixed-point math uses // wrapping arithmetic pervasively, and every site would need an // `#[allow]`, drowning out actionable cases. #![warn( clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unreachable, clippy::unimplemented, clippy::todo, clippy::indexing_slicing )] //! Deterministic pure-Rust Doom simulator with semantic + depth perception //! buffers alongside the classic 320x200 indexed framebuffer. //! //! The engine is `#![no_std]` (uses `alloc`), headless by default, and //! generic over a `GameRules` implementation — the built-in //! [`ClassicDoomRules`] reproduces classic single-player; user code can //! substitute its own rules for bespoke multiplayer or AI training setups. //! //! # Layout //! //! - [`DoomEngine`] / [`ClassicEngine`] — top-level orchestrator. Owns the //! [`World`], [`map::MapData`], [`texture::TextureData`], and a //! [`render::Renderer`]. See [`DoomEngine::tick`] (single-player) or //! [`DoomEngine::simulate`] + [`DoomEngine::render_for`] (multi-peer). //! - [`World`] — entities, controllers, per-player state, sector state. //! Deterministic, serializable. //! - [`rules::GameRules`] — the transition function; one `tick` per //! simulation step. //! - [`render`] — BSP / wall / plane / sprite rasterizer, HUD overlay, //! and the `SemanticClass` / depth buffers exposed to AI code. //! - [`perception::PerceptionFrame`] — a snapshot of `(semantic, depth)` //! ready for downsampling or feature extraction. //! - [`combat`] / [`physics`] / [`specials`] — reusable gameplay helpers //! used by `ClassicDoomRules`; available to custom rule impls. //! //! # Quick start //! //! ```no_run //! use neurodoom::{ClassicEngine, PeerId, PlayerAction}; //! //! # fn demo() -> Result<(), Box> { //! let wad = std::fs::read("doom1.wad")?; //! let mut engine = ClassicEngine::new(&wad, "E1M1")?; //! engine.tick_single(PeerId(0), PlayerAction::default()); //! let rgba = engine.framebuffer(); // 320 * 200 * 4 bytes //! let _semantic = engine.semantic_buffer(); // one SemanticClass per pixel //! let _depth = engine.depth_buffer(); // fixed-point distance per pixel //! # let _ = rgba; //! # Ok(()) //! # } //! ``` ``` -------------------------------- ### Quick Start: Initialize and Tick Classic Doom Engine Source: https://docs.rs/neurodoom/latest/src/neurodoom/lib.rs.html Demonstrates how to initialize the ClassicEngine with a WAD file and a map, then advance a single game tick for a player. Shows how to retrieve the rendered framebuffer and auxiliary buffers. ```rust #![no_std] // Surface every direct panic site as a warning so they cannot drift in // unnoticed. `clippy::indexing_slicing` is enabled globally; the renderer // and physics hot loops carry module-level `#![allow]` with documented // rationale (see src/render/mod.rs). We deliberately do NOT enable // `clippy::arithmetic_side_effects` — Doom's fixed-point math uses // wrapping arithmetic pervasively, and every site would need an // `#[allow]`, drowning out actionable cases. #![warn( clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unreachable, clippy::unimplemented, clippy::todo, clippy::indexing_slicing )] //! Deterministic pure-Rust Doom simulator with semantic + depth perception //! buffers alongside the classic 320x200 indexed framebuffer. //! //! The engine is `#![no_std]` (uses `alloc`), headless by default, and //! generic over a `GameRules` implementation — the built-in //! [`ClassicDoomRules`] reproduces classic single-player; user code can //! substitute its own rules for bespoke multiplayer or AI training setups. //! //! # Layout //! //! - [`DoomEngine`] / [`ClassicEngine`] — top-level orchestrator. Owns the //! [`World`], [`map::MapData`], [`texture::TextureData`], and a //! [`render::Renderer`]. See [`DoomEngine::tick`] (single-player) or //! [`DoomEngine::simulate`] + [`DoomEngine::render_for`] (multi-peer). //! - [`World`] — entities, controllers, per-player state, sector state. //! Deterministic, serializable. //! - [`rules::GameRules`] — the transition function; one `tick` per //! simulation step. //! - [`render`] — BSP / wall / plane / sprite rasterizer, HUD overlay, //! and the `SemanticClass` / depth buffers exposed to AI code. //! - [`perception::PerceptionFrame`] — a snapshot of `(semantic, depth)` //! ready for downsampling or feature extraction. //! - [`combat`] / [`physics`] / [`specials`] — reusable gameplay helpers //! used by `ClassicDoomRules`; available to custom rule impls. //! //! # Quick start //! //! ```no_run //! use neurodoom::{ClassicEngine, PeerId, PlayerAction}; //! //! # fn demo() -> Result<(), Box> { //! let wad = std::fs::read("doom1.wad")?; //! let mut engine = ClassicEngine::new(&wad, "E1M1")?; //! engine.tick_single(PeerId(0), PlayerAction::default()); //! let rgba = engine.framebuffer(); // 320 * 200 * 4 bytes //! let _semantic = engine.semantic_buffer(); // one SemanticClass per pixel //! let _depth = engine.depth_buffer(); // fixed-point distance per pixel //! # let _ = rgba; //! # Ok(()) //! # } //! ``` ``` -------------------------------- ### Define Player 2 Start Position Source: https://docs.rs/neurodoom/0.6.7/neurodoom/map/doomednum/constant.PLAYER2_START.html This constant specifies the integer value representing the starting coordinate for the second player. ```rust pub const PLAYER2_START: i16 = 2; ``` -------------------------------- ### ClassicEngine Initialization and Tick Source: https://docs.rs/neurodoom/latest/neurodoom/index.html Demonstrates how to initialize the ClassicEngine with a WAD file and a map, and how to perform a single simulation tick for a player. ```APIDOC ## `ClassicEngine::new` and `ClassicEngine::tick_single` ### Description Initializes a `ClassicEngine` with game data from a WAD file and a specified map. It then simulates a single game tick for a given player, processing their actions. ### Method - `ClassicEngine::new(wad_data: &[u8], map_name: &str) -> Result` - `ClassicEngine::tick_single(&mut self, player_id: PeerId, action: PlayerAction)` ### Parameters #### `ClassicEngine::new` Parameters - `wad_data` (*&[u8]*) - Required - The byte slice containing the WAD file data. - `map_name` (*&str*) - Required - The name of the map to load (e.g., "E1M1"). #### `ClassicEngine::tick_single` Parameters - `player_id` (*PeerId*) - Required - The identifier for the player performing the action. - `action` (*PlayerAction*) - Required - The set of actions the player is taking in this tick. ### Response #### `ClassicEngine::new` Success Response - `ClassicEngine` - An initialized engine instance. #### `ClassicEngine::tick_single` Success Response This method does not return a value directly but updates the engine's internal state. ### Request Example ```rust use neurodoom::{ClassicEngine, PeerId, PlayerAction}; let wad = std::fs::read("doom1.wad")?; let mut engine = ClassicEngine::new(&wad, "E1M1")?; engine.tick_single(PeerId(0), PlayerAction::default()); ``` ### Accessing Framebuffer and Buffers After ticking the engine, you can access various rendering and perception buffers. #### Methods - `ClassicEngine::framebuffer() -> &[u8]` - `ClassicEngine::semantic_buffer() -> &[SemanticClass]` - `ClassicEngine::depth_buffer() -> &[u16]` #### Response - `framebuffer` (*&[u8]*) - Returns a slice representing the RGBA framebuffer (320x200x4 bytes). - `semantic_buffer` (*&[SemanticClass]*) - Returns a slice representing the semantic class buffer, with one `SemanticClass` per pixel. - `depth_buffer` (*&[u16]*) - Returns a slice representing the depth buffer, with fixed-point distance per pixel. ``` -------------------------------- ### get Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/world.rs.html Retrieves an immutable reference to an entity by its ID. ```APIDOC ## get ### Description Retrieves an immutable reference to an entity from the world using its `EntityId`. Returns `None` if the entity does not exist. ### Method GET ### Endpoint /world/entities/{id} ### Parameters #### Path Parameters - **id** (EntityId) - Required - The ID of the entity to retrieve. ### Returns - **Option<&Entity>**: An optional immutable reference to the entity. ``` -------------------------------- ### Any::type_id Implementation Source: https://docs.rs/neurodoom/0.6.7/neurodoom/classic/struct.ClassicDoomRules.html Gets the TypeId of an entity. This is a blanket implementation for all types. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Quick Start: Initialize and Tick Doom Engine Source: https://docs.rs/neurodoom/0.6.7/index.html This snippet demonstrates how to initialize the ClassicEngine with a WAD file and a map, and then perform a single simulation tick for a player. It also shows how to access the rendered framebuffer, semantic buffer, and depth buffer. ```rust use neurodoom::{ClassicEngine, PeerId, PlayerAction}; let wad = std::fs::read("doom1.wad")?; let mut engine = ClassicEngine::new(&wad, "E1M1")?; engine.tick_single(PeerId(0), PlayerAction::default()); let rgba = engine.framebuffer(); // 320 * 200 * 4 bytes let _semantic = engine.semantic_buffer(); // one SemanticClass per pixel let _depth = engine.depth_buffer(); // fixed-point distance per pixel ``` -------------------------------- ### setup_frame Source: https://docs.rs/neurodoom/latest/neurodoom/render/struct.Renderer.html Set up the renderer for a frame. ```APIDOC ## setup_frame ### Description Set up the renderer for a frame. ### Method `setup_frame` ### Parameters - `x`: Fixed - `y`: Fixed - `z`: Fixed - `angle`: Angle ``` -------------------------------- ### Get Buffer Size Source: https://docs.rs/neurodoom/latest/src/neurodoom/engine.rs.html Returns the dimensions (width, height) of the rendering buffers. ```rust pub fn buffer_size(&self) -> (usize, usize) { (SCREENWIDTH, SCREENHEIGHT) } ``` -------------------------------- ### Engine Initialization and Tick Source: https://docs.rs/neurodoom/latest/neurodoom Demonstrates how to initialize the ClassicEngine with a WAD file and a map, and how to perform a single simulation tick for a player. It also shows how to retrieve the framebuffer, semantic buffer, and depth buffer. ```APIDOC ## `ClassicEngine::new` and `tick_single` ### Description Initializes a `ClassicEngine` with game data from a WAD file and a specified map. It then advances the simulation by one step for a given `PeerId` and `PlayerAction`, and provides methods to access the rendered frame and perception buffers. ### Methods - `ClassicEngine::new(wad_data: &[u8], map_name: &str) -> Result` - `engine.tick_single(peer_id: PeerId, action: PlayerAction)` - `engine.framebuffer() -> &[u8]` - `engine.semantic_buffer() -> &[SemanticClass]` - `engine.depth_buffer() -> &[u16]` ### Parameters #### `ClassicEngine::new` - **wad_data** (`&[u8]`) - Required - The raw byte data of the Doom WAD file. - **map_name** (`&str`) - Required - The name of the map to load from the WAD. #### `tick_single` - **peer_id** (`PeerId`) - Required - The identifier for the player performing the action. - **action** (`PlayerAction`) - Required - The action the player is taking. ### Response #### Success Response (`ClassicEngine::new`) Returns a `ClassicEngine` instance. #### Success Response (`tick_single`) Advances the simulation state. #### Success Response (`framebuffer`, `semantic_buffer`, `depth_buffer`) Returns a slice representing the requested buffer. ### Request Example ```rust use neurodoom::{ClassicEngine, PeerId, PlayerAction}; let wad = std::fs::read("doom1.wad")?; let mut engine = ClassicEngine::new(&wad, "E1M1")?; engine.tick_single(PeerId(0), PlayerAction::default()); let rgba = engine.framebuffer(); // 320 * 200 * 4 bytes let _semantic = engine.semantic_buffer(); // one SemanticClass per pixel let _depth = engine.depth_buffer(); // fixed-point distance per pixel ``` ``` -------------------------------- ### Any::type_id() Blanket Implementation Source: https://docs.rs/neurodoom/0.6.7/neurodoom/world/struct.PlayerState.html Gets the TypeId of the PlayerState, part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Instantiate ClassicEngine Source: https://docs.rs/neurodoom/0.6.7/neurodoom/engine/type.ClassicEngine.html Creates a new ClassicEngine instance, loading game data from a WAD file and setting up a specified map. This is the entry point for starting a classic single-player game. ```rust pub fn new(wad_data: &[u8], map_name: &str) -> Result ``` -------------------------------- ### ClassicEngine::new Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/lib.rs.html Constructs a new `ClassicEngine` instance from a WAD file and a map name. This is the entry point for initializing the Doom simulation with classic game rules. ```APIDOC ## `ClassicEngine::new` ### Description Constructs a new `ClassicEngine` instance from a WAD file and a map name. This is the entry point for initializing the Doom simulation with classic game rules. ### Method Associated function (constructor) ### Parameters - **wad**: `&[u8]` - A byte slice representing the contents of a Doom WAD file. - **map_name**: `&str` - The name of the map to load from the WAD file. ### Returns A `Result` containing a `ClassicEngine` on success, or a `DoomError` on failure. ``` -------------------------------- ### Entity Type ID Source: https://docs.rs/neurodoom/latest/neurodoom/world/struct.Entity.html Gets the `TypeId` of an entity, used for runtime type identification. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Setup Frame Parameters Source: https://docs.rs/neurodoom/latest/src/neurodoom/render/mod.rs.html Sets up the renderer's state for a new frame, including camera position, orientation, and pre-calculating trigonometric values for the current view angle. This should be called at the beginning of each frame. ```rust pub fn setup_frame(&mut self, x: Fixed, y: Fixed, z: Fixed, angle: Angle) { self.view_x = x; self.view_y = y; self.view_z = z; self.view_angle = angle; self.view_sin = crate::tables::FINESINE[(angle >> ANGLETOFINESHIFT) as usize]; self.view_cos = finecosine((angle >> ANGLETOFINESHIFT) as usize); self.valid_count += 1; } ``` -------------------------------- ### Define PLAYER4_START Constant Source: https://docs.rs/neurodoom/0.6.7/neurodoom/map/doomednum/constant.PLAYER4_START.html This constant defines the starting position for player 4. It is an i16 type. ```rust pub const PLAYER4_START: i16 = 4; ``` -------------------------------- ### Renderer::setup_frame Source: https://docs.rs/neurodoom/0.6.7/neurodoom/render/struct.Renderer.html Sets up the renderer's state for a new frame, including view position and angle. ```APIDOC ## Renderer::setup_frame ### Description Set up the renderer for a frame. ### Method `setup_frame` ### Parameters * `x`: Fixed - The view's X coordinate. * `y`: Fixed - The view's Y coordinate. * `z`: Fixed - The view's Z coordinate. * `angle`: Angle - The view's angle. ``` -------------------------------- ### Get Controlled Entity by Peer Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/world.rs.html Returns the EntityId controlled by a given PeerId, if such a mapping exists. ```rust /// Which entity does this peer control? pub fn controlled_by(&self, peer: PeerId) -> Option { self.controllers.get(&peer).copied() } ``` -------------------------------- ### ClassicEngine::new Source: https://docs.rs/neurodoom/0.6.7/neurodoom/engine/type.ClassicEngine.html Creates a new ClassicEngine instance. This involves loading the WAD file, spawning map entities, and preparing the engine for gameplay. ```APIDOC ## ClassicEngine::new ### Description Creates a classic Doom engine — loads WAD, spawns map things, ready to play. ### Method Rust function ### Signature `pub fn new(wad_data: &[u8], map_name: &str) -> Result` ### Parameters #### Path Parameters - **wad_data** (&[u8]) - Required - The WAD data to load. - **map_name** (&str) - Required - The name of the map to spawn. ### Response #### Success Response - **Self** (ClassicEngine) - A new instance of the ClassicEngine. #### Error Response - **DoomError** - An error occurred during engine creation. ``` -------------------------------- ### Get Player State Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/world.rs.html Retrieves an immutable reference to the player state for a given entity, if it is player-controlled. ```rust /// Get player state for an entity (if it's player-controlled). pub fn player_state(&self, entity: EntityId) -> Option<&PlayerState> { self.player_states.get(&entity) } ``` -------------------------------- ### Error::cause Method (Deprecated) Source: https://docs.rs/neurodoom/0.6.7/neurodoom/map/enum.MapError.html Deprecated method for getting the error cause. Replaced by Error::source. ```rust fn cause(&self) -> Option<&dyn Error> ``` -------------------------------- ### DoomEngine::new Source: https://docs.rs/neurodoom/0.6.7/neurodoom/engine/struct.DoomEngine.html Creates a new `DoomEngine` instance specifically configured with `ClassicDoomRules`. This constructor loads the WAD, spawns map entities, and prepares the engine for immediate gameplay in a classic Doom style. ```APIDOC ## DoomEngine::new ### Description Creates a new `DoomEngine` instance specifically configured with `ClassicDoomRules`. This constructor loads the WAD, spawns map entities, and prepares the engine for immediate gameplay in a classic Doom style. ### Method `new(wad_data: &[u8], map_name: &str) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * `wad_data` (&[u8]): The WAD data containing map and entity information. * `map_name` (&str): The name of the map to load. ### Response * Returns `Result`: Ok containing the new `DoomEngine` instance on success, or a `DoomError` on failure. ``` -------------------------------- ### StateDef Structure Example Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/game_data.rs.html Defines a single game state with sprite, frame, tics, action, and next_state. ```rust StateDef { sprite: SpriteNum(51), frame: 19, tics: 5, action: ActionId(0), next_state: StateNum(756), } ``` ```rust StateDef { sprite: SpriteNum(51), frame: 21, tics: -1, action: ActionId(0), next_state: StateNum(0), } ``` ```rust StateDef { sprite: SpriteNum(52), frame: 0, tics: -1, action: ActionId(0), next_state: StateNum(763), } ``` ```rust StateDef { sprite: SpriteNum(52), frame: 2, tics: 6, action: ActionId(58), next_state: StateNum(767), } ``` ```rust StateDef { sprite: SpriteNum(52), frame: 10, tics: 6, action: ActionId(38), next_state: StateNum(775), } ``` ```rust StateDef { sprite: SpriteNum(52), frame: 11, tics: -1, action: ActionId(0), next_state: StateNum(0), } ``` ```rust StateDef { sprite: SpriteNum(52), frame: 12, tics: 4, action: ActionId(0), next_state: StateNum(777), } ``` ```rust StateDef { sprite: SpriteNum(52), frame: 12, tics: 8, action: ActionId(47), next_state: StateNum(763), } ``` ```rust StateDef { sprite: SpriteNum(53), frame: 0, tics: -1, action: ActionId(0), next_state: StateNum(0), } ``` ```rust StateDef { sprite: SpriteNum(53), frame: 1, tics: 36, action: ActionId(8), next_state: StateNum(778), } ``` ```rust StateDef { sprite: SpriteNum(53), frame: 0, tics: 100, action: ActionId(9), next_state: StateNum(781), } ``` ```rust StateDef { sprite: SpriteNum(53), frame: 0, tics: 10, action: ActionId(0), next_state: StateNum(782), } ``` -------------------------------- ### new Source: https://docs.rs/neurodoom/latest/neurodoom/render/struct.Renderer.html Creates a new Renderer instance. ```APIDOC ## new ### Description Creates a new Renderer instance. ### Method `new` ### Returns `Self` ``` -------------------------------- ### Initialize Light Scale Tables Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/render/mod.rs.html Sets up the `scalelight` table, which maps light levels and horizontal distances to color map indices. This is used for applying lighting effects based on distance and brightness. ```rust fn init_light_tables(&mut self) { const DISTMAP: usize = 2; for i in 0..LIGHTLEVELS { let startmap = ((LIGHTLEVELS - 1 - i) * 2 * NUMCOLORMAPS / LIGHTLEVELS) as i32; for j in 0..MAXLIGHTSCALE { // j * SCREENWIDTH / viewwidth / DISTMAP (viewwidth=SCREENWIDTH, detailshift=0) let level = (startmap - (j as i32) / DISTMAP as i32) .clamp(0, NUMCOLORMAPS as i32 - 1); self.scalelight[i][j] = level as usize; } } } ``` -------------------------------- ### Get Sector Light Level Source: https://docs.rs/neurodoom/latest/src/neurodoom/engine.rs.html Calculates and returns the light level at a specific X, Y coordinate within the map. ```rust fn sector_light_at(map: &MapData, x: Fixed, y: Fixed) -> i16 { ``` -------------------------------- ### init_zlight Source: https://docs.rs/neurodoom/latest/neurodoom/render/struct.Renderer.html Initialize zlight tables (distance-based lighting for planes). ```APIDOC ## init_zlight ### Description Initialize zlight tables (distance-based lighting for planes). ### Method `init_zlight` ``` -------------------------------- ### Get Depth Buffer Data Source: https://docs.rs/neurodoom/latest/src/neurodoom/engine.rs.html Returns a slice of the depth buffer data, containing depth information for each pixel. ```rust pub fn depth_buffer(&self) -> &[Fixed] { &self.renderer.depth } ``` -------------------------------- ### Get Framebuffer Data Source: https://docs.rs/neurodoom/latest/src/neurodoom/engine.rs.html Returns a slice of the raw framebuffer data, typically used for displaying the rendered image. ```rust pub fn framebuffer(&self) -> &[u8] { &self.renderer.rgba } ``` -------------------------------- ### Get Mutable Player State Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/world.rs.html Retrieves a mutable reference to the player state for a given entity, allowing modifications. ```rust /// Get mutable player state for an entity. pub fn player_state_mut(&mut self, entity: EntityId) -> Option<&mut PlayerState> { self.player_states.get_mut(&entity) } ``` -------------------------------- ### init_texture_mapping Source: https://docs.rs/neurodoom/latest/neurodoom/render/struct.Renderer.html Build the viewangletox and xtoviewangle lookup tables. ```APIDOC ## init_texture_mapping ### Description Build the viewangletox and xtoviewangle lookup tables. ### Method `init_texture_mapping` ``` -------------------------------- ### Creating a BitFlags Instance with All Flags Set Source: https://docs.rs/neurodoom/0.6.7/neurodoom/types/type.Buttons.html Shows how to create a BitFlags instance where all possible flags are set. This is useful for representing a state where all options are enabled. ```rust #[bitflags] #[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] enum MyFlag { One = 1 << 0, Two = 1 << 1, Three = 1 << 2, } let empty: BitFlags = BitFlags::all(); assert!(empty.is_all()); assert_eq!(empty.contains(MyFlag::One), true); assert_eq!(empty.contains(MyFlag::Two), true); assert_eq!(empty.contains(MyFlag::Three), true); ``` -------------------------------- ### Get Demo Length Source: https://docs.rs/neurodoom/latest/neurodoom/demo/struct.Demo.html Returns the number of recorded tics in the demo. A tic represents approximately 1/35th of a second. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Get Entity by ID Source: https://docs.rs/neurodoom/0.6.7/neurodoom/world/struct.World.html Retrieves an immutable reference to an entity using its ID. Returns None if the entity does not exist. ```rust pub fn get(&self, id: EntityId) -> Option<&Entity> ``` -------------------------------- ### Renderer::new Source: https://docs.rs/neurodoom/0.6.7/neurodoom/render/struct.Renderer.html Creates a new instance of the Renderer. ```APIDOC ## Renderer::new ### Description Creates a new instance of the Renderer. ### Method `new` ### Returns `Self` - A new Renderer instance. ``` -------------------------------- ### Initialize Texture Mapping Tables Source: https://docs.rs/neurodoom/latest/src/neurodoom/render/tables.rs.html Builds the `viewangletox` and `xtoviewangle` lookup tables used for perspective projection. This function calculates focal length and then populates the tables by iterating through fine tangents and screen coordinates. ```rust use crate::math::*; use crate::tables::FINETANGENT; use super::Renderer; /// Field of view in fine angles (2048 fine angles = 90 degrees). pub const FIELDOFVIEW: usize = 2048; impl Renderer { /// Build the viewangletox and xtoviewangle lookup tables. pub fn init_texture_mapping(&mut self) { let width = SCREENWIDTH as i32; let center_x_frac = self.center_x_frac; // Focal length for perspective projection let focal_length = fixed_div( center_x_frac, FINETANGENT[FINEANGLES / 4 + FIELDOFVIEW / 2], ); // Build viewangletox: fine angle → screen x for (i, &tan) in FINETANGENT.iter().enumerate().take(FINEANGLES / 2) { let t; if tan > 2 * FRACUNIT { t = -1; } else if tan < -2 * FRACUNIT { t = width + 1; } else { let x = fixed_mul(tan, focal_length); let raw = (center_x_frac - x + FRACUNIT - 1) >> FRACBITS; t = raw.clamp(-1, width + 1); }; self.viewangletox[i] = t; } // Build xtoviewangle: screen x → angle for x in 0..=SCREENWIDTH { let mut i = 0; while i < FINEANGLES / 2 && self.viewangletox[i] > x as i32 { i += 1; } self.xtoviewangle[x] = ((i as u32) << ANGLETOFINESHIFT).wrapping_sub(ANG90); } // Clip angle = half FOV self.clip_angle = self.xtoviewangle[0]; } } ``` -------------------------------- ### Get Player State Source: https://docs.rs/neurodoom/0.6.7/neurodoom/world/struct.World.html Retrieves the player state for a given entity ID. Returns None if the entity is not player-controlled. ```rust pub fn player_state(&self, entity: EntityId) -> Option<&PlayerState> ``` -------------------------------- ### Get Semantic Buffer Data Source: https://docs.rs/neurodoom/latest/src/neurodoom/engine.rs.html Returns a slice of the semantic buffer data, which might contain information for post-processing or analysis. ```rust pub fn semantic_buffer(&self) -> &[u8] { &self.renderer.semantic } ``` -------------------------------- ### Get Entity Count Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/world.rs.html Returns the number of active entities currently in the world. This count is derived from the size of the ID-to-slot mapping. ```rust pub fn entity_count(&self) -> usize { self.id_to_slot.len() } ``` -------------------------------- ### Initialize Z-Light Tables for Planes Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/render/planes.rs.html Precomputes distance-based lighting levels for planes. This table helps to dim planes based on their distance from the viewer. ```rust /// Initialize zlight tables (distance-based lighting for planes). pub fn init_zlight(&mut self) { const DISTMAP: i32 = 2; for i in 0..LIGHTLEVELS { let startmap = ((LIGHTLEVELS - 1 - i) * 2 * NUMCOLORMAPS / LIGHTLEVELS) as i32; for j in 0..MAXLIGHTZ { let scale = fixed_div( (SCREENWIDTH as i32 / 2) * FRACUNIT, (j as i32 + 1) << LIGHTZSHIFT, ); let scale = scale >> LIGHTSCALESHIFT; let level = (startmap - scale / DISTMAP).clamp(0, NUMCOLORMAPS as i32 - 1); self.zlight[i][j] = level as usize; } } } ``` -------------------------------- ### Get Entity by ID Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/world.rs.html Retrieves an immutable reference to an entity using its ID. Returns `None` if the entity does not exist or has been removed. ```rust pub fn get(&self, id: EntityId) -> Option<&Entity> { let &slot = self.id_to_slot.get(&id)?; self.entities.get(slot)?.as_ref() } ``` -------------------------------- ### Initialize Texture Mapping Tables Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/render/tables.rs.html Builds the viewangletox and xtoviewangle lookup tables. These tables are essential for converting between screen coordinates and view angles, using a fixed-point arithmetic approach. Requires `FINETANGENT` lookup table and constants like `SCREENWIDTH`, `FRACUNIT`, `FRACBITS`, `FINEANGLES`, and `ANGLETOFINESHIFT`. ```rust use crate::math::*; use crate::tables::FINETANGENT; use super::Renderer; /// Field of view in fine angles (2048 fine angles = 90 degrees). pub const FIELDOFVIEW: usize = 2048; impl Renderer { /// Build the viewangletox and xtoviewangle lookup tables. pub fn init_texture_mapping(&mut self) { let width = SCREENWIDTH as i32; let center_x_frac = self.center_x_frac; // Focal length for perspective projection let focal_length = fixed_div( center_x_frac, FINETANGENT[FINEANGLES / 4 + FIELDOFVIEW / 2], ); // Build viewangletox: fine angle → screen x for (i, &tan) in FINETANGENT.iter().enumerate().take(FINEANGLES / 2) { let t; if tan > 2 * FRACUNIT { t = -1; } else if tan < -2 * FRACUNIT { t = width + 1; } else { let x = fixed_mul(tan, focal_length); let raw = (center_x_frac - x + FRACUNIT - 1) >> FRACBITS; t = raw.clamp(-1, width + 1); }; self.viewangletox[i] = t; } // Build xtoviewangle: screen x → angle for x in 0..=SCREENWIDTH { let mut i = 0; while i < FINEANGLES / 2 && self.viewangletox[i] > x as i32 { i += 1; } self.xtoviewangle[x] = ((i as u32) << ANGLETOFINESHIFT).wrapping_sub(ANG90); } // Clip angle = half FOV self.clip_angle = self.xtoviewangle[0]; } } ``` -------------------------------- ### Get Mutable Entity by ID Source: https://docs.rs/neurodoom/0.6.7/neurodoom/world/struct.World.html Retrieves a mutable reference to an entity using its ID. Returns None if the entity does not exist. ```rust pub fn get_mut(&mut self, id: EntityId) -> Option<&mut Entity> ``` -------------------------------- ### Error::description Method (Deprecated) Source: https://docs.rs/neurodoom/0.6.7/neurodoom/map/enum.MapError.html Deprecated method for getting an error description. Use the Display impl or to_string() instead. ```rust fn description(&self) -> &str ``` -------------------------------- ### Create Classic Doom Engine Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/engine.rs.html Constructs a new classic Doom engine instance. It loads the specified WAD data, initializes the map, spawns map entities, and prepares the engine for gameplay. Requires WAD data and a map name as input. ```rust impl ClassicEngine { /// Create a classic Doom engine — loads WAD, spawns map things, ready to play. pub fn new(wad_data: &[u8], map_name: &str) -> Result { let mut engine = Self::new_with_rules(wad_data, map_name, crate::classic::ClassicDoomRules)?; engine.spawn_map_things(PeerId(0)); Ok(engine) } } ``` -------------------------------- ### Initialize Doom Engine with Custom Rules Source: https://docs.rs/neurodoom/0.6.7/src/neurodoom/engine.rs.html Creates a new Doom engine instance with custom game rules. Loads map geometry and textures from a WAD. Does not spawn entities by default. ```rust pub fn new_with_rules(wad_data: &[u8], map_name: &str, rules: R) -> Result { let wad = Wad::parse(wad_data).map_err(DoomError::WadError)?; let mut map = MapData::load(&wad, map_name).map_err(DoomError::MapError)?; let textures = TextureData::load(&wad).map_err(DoomError::TextureError)?; map.resolve_textures(&textures); let mut renderer = Renderer::new(); let sky_name = *b"F_SKY1\0\0"; renderer.sky_flat_num = textures.flat_num_for_name(&sky_name); let sky_tex_name = *b"SKY1\0\0\0\0"; renderer.sky_texture_num = textures.texture_num_for_name(&sky_tex_name); let world = world_from_map(&map); Ok(Self { rules, world, map, textures, renderer, thing_refs: Vec::new(), }) } ``` -------------------------------- ### BLAZE_OPEN Constant Definition Source: https://docs.rs/neurodoom/0.6.7/neurodoom/map/line_special/constant.BLAZE_OPEN.html Defines the BLAZE_OPEN constant with a specific i16 value. This is a direct definition and does not require complex setup. ```rust pub const BLAZE_OPEN: i16 = 118; ```