use neurodoom::game_data::EntityType;
use neurodoom::map::MapData;
use neurodoom::math::*;
use neurodoom::physics;
use neurodoom::texture::TextureData;
use neurodoom::wad::Wad;
fn load_wad() -> Vec<u8> {
let path = std::env::var("DOOM_WAD")
.unwrap_or_else(|_| "doom1.wad".to_string());
std::fs::read(&path).unwrap_or_else(|e| panic!("failed to read WAD at {path}: {e}"))
}
fn setup() -> (MapData, TextureData) {
let data = load_wad();
let wad = Wad::parse(&data).unwrap();
let mut map = MapData::load(&wad, "E1M1").unwrap();
let textures = TextureData::load(&wad).unwrap();
map.resolve_textures(&textures);
(map, textures)
}
#[test]
fn check_position_at_player_start() {
let (map, _textures) = setup();
let p1 = map.things.iter().find(|t| t.type_num == 1).unwrap();
let x = (p1.x as Fixed) << FRACBITS;
let y = (p1.y as Fixed) << FRACBITS;
let info = EntityType(0).info().unwrap(); let result = physics::check_position(&map, info.radius, x, y);
assert!(result.ok, "player start should be a valid position");
}
#[test]
fn find_sector_heights_at_player_start() {
let (map, _textures) = setup();
let p1 = map.things.iter().find(|t| t.type_num == 1).unwrap();
let x = (p1.x as Fixed) << FRACBITS;
let y = (p1.y as Fixed) << FRACBITS;
let (floor, ceiling) = physics::find_sector_heights(&map, x, y);
assert!(ceiling > floor, "ceiling should be above floor at player start");
}