Compare commits

7 Commits

Author SHA1 Message Date
Wesley Irvin
39ebbe5ca3 WIP of doom renderer 5-12-23
WIP Implementation so far of doom renderer on 5-12-23
2023-05-12 21:44:37 -04:00
Wesley Irvin
fed4e520f5 Merge pull request 'Logging' (#24) from logging into master
Reviewed-on: https://git.batesirvintech.net/wesley/doom-oxidized/pulls/24
2023-05-04 20:30:27 -04:00
Wesley Irvin
f9a089839b Logging
Added in the dependencies for logging and proved that logging
functionality is working. Should be able to close issue #23.
2023-05-04 20:29:22 -04:00
Wesley Irvin
8720085e96 Merge pull request 'Licensing' (#22) from license into master
Reviewed-on: https://git.batesirvintech.net/wesley/doom-oxidized/pulls/22
2023-05-02 22:01:19 -04:00
Wesley Irvin
b1924a0c63 Licensing
Added the MIT License to the project.
2023-05-02 21:59:54 -04:00
Wesley Irvin
5684c8081f Merge pull request 'WADFile Documentation' (#21) from wadfile-doc into master
Reviewed-on: https://git.batesirvintech.net/wesley/doom-oxidized/pulls/21
2023-05-02 21:52:25 -04:00
Wesley Irvin
7e7740b0c5 WADFile Documentation
First run of documentation for current state of wadfile.rs. Should
satisfy requirements for open issue #20.
2023-05-02 21:50:39 -04:00
5 changed files with 149 additions and 48 deletions

View File

@@ -4,4 +4,6 @@ version = "0.1.0"
edition = "2021"
[dependencies]
env_logger = "0.10.0"
log = "0.4.17"
sdl2 = "0.35.2"

9
LICENSE Normal file
View File

@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright © 2023 Wesley Irvin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

75
src/application.rs Normal file
View File

@@ -0,0 +1,75 @@
use sdl2::{
event::Event, keyboard::Keycode, pixels::Color, render::WindowCanvas, EventPump, Sdl,
VideoSubsystem,
};
use std::time::Duration;
pub struct Application {
sdl_context: Sdl,
video_subsystem: VideoSubsystem,
event_pump: EventPump,
main_window: WindowCanvas,
}
impl Application {
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
let new_sdl_context = sdl2::init()?;
let new_video_subsystem = new_sdl_context.video()?;
let new_event_subsystem = new_sdl_context.event_pump()?;
let new_window = new_video_subsystem
.window("Doom - Oxidized", 320, 240)
.position_centered()
.build()?;
let window_surface = new_window.into_canvas().build()?;
Ok(Self {
sdl_context: new_sdl_context,
video_subsystem: new_video_subsystem,
event_pump: new_event_subsystem,
main_window: window_surface,
})
}
pub fn video_subsystem(&self) -> &VideoSubsystem {
&self.video_subsystem
}
pub fn event_subsystem(&mut self) -> &mut EventPump {
&mut self.event_pump
}
pub fn sdl_context(&self) -> &Sdl {
&self.sdl_context
}
pub fn run(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.main_window.set_draw_color(Color::RGB(0, 255, 255));
self.main_window.clear();
self.main_window.present();
let mut i = 0;
'running: loop {
i = (i + 1) % 255;
self.main_window.set_draw_color(Color::RGB(i, 64, 255 - i));
self.main_window.clear();
for event in self.event_pump.poll_iter() {
match event {
Event::Quit { .. }
| Event::KeyDown {
keycode: Some(Keycode::Escape),
..
} => break 'running,
_ => {}
}
}
self.main_window.present();
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 30));
}
Ok(())
}
}

View File

@@ -1,20 +1,17 @@
extern crate log;
extern crate sdl2;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::pixels::Color;
use std::time::Duration;
use env_logger::Builder;
use log::{debug, error, info, warn, LevelFilter};
mod application;
mod doomlevel;
mod wadfile;
use application::Application;
use doomlevel::DoomLevel;
use wadfile::WADFile;
static WIDTH: u32 = 320;
static HEIGHT: u32 = 200;
static SCALING: u32 = 4;
fn find_sdl_gl_driver() -> Option<u32> {
for (index, item) in sdl2::render::drivers().enumerate() {
if item.name == "opengl" {
@@ -24,7 +21,7 @@ fn find_sdl_gl_driver() -> Option<u32> {
None
}
fn main() -> Result<(), &'static str> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let wad_file = WADFile::from_path("WADs/doom1.wad")?;
let level = DoomLevel::load_level(&wad_file, wad_file.get_index_from_name("e1m1").unwrap());
@@ -105,48 +102,16 @@ Flags:
level.linedefs[test_linedef].always_automap()
);
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();
Builder::new().filter_level(LevelFilter::Debug).init();
let window = video_subsystem
.window("Doom - Oxidized", WIDTH * SCALING, HEIGHT * SCALING)
.position_centered()
.opengl()
.build()
.unwrap();
debug!("Test of the DEBUG log!");
info!("Test of INFO log!");
warn!("Test of WARN log!");
error!("Test of ERROR log!");
let mut canvas = window
.into_canvas()
.index(find_sdl_gl_driver().unwrap())
.build()
.unwrap();
let mut app = Application::new()?;
canvas.set_draw_color(Color::RGB(0, 255, 255));
canvas.clear();
canvas.present();
let mut event_pump = sdl_context.event_pump().unwrap();
let mut i = 0;
'running: loop {
i = (i + 1) % 255;
canvas.set_draw_color(Color::RGB(i, 64, 255 - i));
canvas.clear();
for event in event_pump.poll_iter() {
match event {
Event::Quit { .. }
| Event::KeyDown {
keycode: Some(Keycode::Escape),
..
} => break 'running,
_ => {}
}
}
canvas.present();
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 30));
}
app.run()?;
Ok(())
}

View File

@@ -7,15 +7,33 @@ use std::{
path::Path,
};
/// Representation of a WAD file in memory.
///
/// Struct is created by
/// ```
/// let wad_file = WADFile::from_path("WADs/doom1.wad").unwrap();
/// ```
pub struct WADFile {
/// Holds the path to the WAD file
pub wad_path: String,
/// Type of WAD file (either 'IWAD' or 'PWAD')
pub identifier: String,
/// Number of lumps in the WAD
pub num_lumps: u32,
/// Offset to the lump directory
pub init_offset: u32,
/// List of each directory entry in WAD directory
lump_directory: Vec<Directory>,
}
impl WADFile {
/// Constructs a WADFile from a given path.
///
/// Takes in a path as a string slice, then opens the file at this path.
/// after this it will read and parse the header file, and load the lump
/// directory into memory.
///
/// TODO: Add example code here
pub fn from_path(path: &str) -> Result<Self, &str> {
let wad_file = Path::new(path);
@@ -38,22 +56,48 @@ impl WADFile {
})
}
/// Get a lumps name
///
/// Gets the name of a lump given an index. Will return a
/// string with the lumps name.
///
/// TODO: Add example code here
pub fn get_lump_name(&self, index: u32) -> String {
self.lump_directory[index as usize].lump_name.to_owned()
}
/// Get a lumps offset
///
/// Returns the offset where lump begins that is
/// identified by index.
///
/// TODO: Add example code here
pub fn get_lump_offset(&self, index: u32) -> u32 {
self.lump_directory[index as usize].lump_pos.to_owned()
}
/// Get size of a lump
///
/// Returns the size of lump at position index.
///
/// TODO: Add example code here
pub fn get_lump_size(&self, index: u32) -> u32 {
self.lump_directory[index as usize].lump_size.to_owned()
}
/// Get length of directory list
///
/// Returns the length of the directory list.
pub fn get_directory_len(&self) -> usize {
self.lump_directory.len()
}
// Get index of a lump with given name.
//
// Will return the index of a lump that has name specified
// in lump_name. If not found will return None.
//
// TODO: Add example code here
pub fn get_index_from_name(&self, lump_name: &str) -> Option<u32> {
let mut search_lump = lump_name.to_ascii_uppercase();
@@ -71,6 +115,9 @@ impl WADFile {
}
}
/// Loads lump directory into memory
///
/// Reads the directory in the WAD file and loads into memory.
fn get_lump_dir(path: &str, dir_offset: &u32, num_lumps: &u32, lump_buffer: &mut Vec<Directory>) {
let mut wad_data = File::open(&path).unwrap();
wad_data
@@ -94,6 +141,9 @@ fn get_lump_dir(path: &str, dir_offset: &u32, num_lumps: &u32, lump_buffer: &mut
}
}
/// Reads header data
///
/// Reads and returns the data from the WAD header.
fn get_header_data(path: &str) -> (String, u32, u32) {
let mut wad_data = File::open(&path).unwrap();