use std::error::Error; use std::path::Path; use engine::camera::fly::{Extension as FlyCameraExtension, Options as FlyCameraOptions}; use engine::camera::Camera; use engine::data_types::dimens::Dimens; use engine::ecs::sole::Single; use engine::event::Start as StartEvent; use engine::input::Extension as InputExtension; use engine::lighting::LightSourceBuilder; use engine::material::Builder as MaterialBuilder; use engine::renderer::Extension as RendererExtension; use engine::shader::Program as ShaderProgram; use engine::texture::{List as TextureList, Texture}; use engine::transform::Transform; use engine::vector::{Vec2, Vec3}; use engine::vertex::Builder as VertexBuilder; use engine::window::{CursorMode, Extension as WindowExtension, Window}; use engine::Engine; use tracing::Level; use tracing_subscriber::FmtSubscriber; use crate::cube::{create_cube_mesh, Corner as CubeCorner, Side as CubeSide}; mod cube; const WINDOW_SIZE: Dimens = Dimens { width: 1920, height: 1080 }; fn main() -> Result<(), Box> { let subscriber = FmtSubscriber::builder() .with_max_level(Level::TRACE) .finish(); tracing::subscriber::set_global_default(subscriber)?; let mut engine = Engine::new(); let mut transform = Transform::new(); transform.set_position(Vec3 { x: 1.6, y: 0.0, z: 0.0 }); let texture = Texture::open(Path::new("vent.png"))?; let texture_id = texture.id(); engine.spawn(( create_cube_mesh(cube_vertex_builder_cb), TextureList::from_iter([texture]), MaterialBuilder::new() .ambient_map(texture_id) .diffuse_map(texture_id) .specular_map(texture_id) .build(), transform, ShaderProgram::new()?, )); let light_source = LightSourceBuilder::new() .position(Vec3 { x: 1.2, y: 1.0, z: 1.5 }) .build(); engine.spawn((light_source,)); engine.spawn((Camera { current: true, ..Default::default() },)); engine.register_system(StartEvent, prepare_window); engine.add_extension(RendererExtension::default()); engine.add_extension( WindowExtension::default() .window_title("Game") .window_size(WINDOW_SIZE), ); engine.add_extension(FlyCameraExtension(FlyCameraOptions { camera_speed: 3.0, mouse_sensitivity: 0.2, })); engine.add_extension(InputExtension::default()); engine.start(); Ok(()) } fn prepare_window(window: Single) { window.set_cursor_mode(CursorMode::Disabled).unwrap(); } fn cube_vertex_builder_cb( vertex_builder: VertexBuilder, _side: CubeSide, corner: CubeCorner, ) -> VertexBuilder { vertex_builder.texture_coords(match corner { CubeCorner::TopRight => Vec2 { x: 1.0, y: 1.0 }, CubeCorner::TopLeft => Vec2 { x: 0.0, y: 1.0 }, CubeCorner::BottomRight => Vec2 { x: 1.0, y: 0.0 }, CubeCorner::BottomLeft => Vec2 { x: 0.0, y: 0.0 }, }) }