Convert the engine into a lib package

This commit is contained in:
SeanOMik 2023-09-08 00:30:22 -04:00
parent 2e225ccd09
commit 32689e77ce
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
8 changed files with 14 additions and 163 deletions

2
Cargo.lock generated
View File

@ -1091,7 +1091,7 @@ dependencies = [
[[package]]
name = "lyra-engine"
version = "0.1.0"
version = "0.0.1"
dependencies = [
"aligned-vec",
"anyhow",

View File

@ -1,6 +1,6 @@
[package]
name = "lyra-engine"
version = "0.1.0"
version = "0.0.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# Lyra Engine
This is a very WIP custom game engine written in Rust.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

8
src/lib.rs Normal file
View File

@ -0,0 +1,8 @@
mod game;
mod render;
mod input_event;
mod resources;
mod ecs;
mod math;
mod input;
mod castable_any;

View File

@ -1,159 +0,0 @@
mod game;
mod render;
mod input_event;
mod resources;
mod ecs;
mod math;
mod input;
mod castable_any;
use atomicell::Ref;
use ecs::components::mesh::MeshComponent;
use ecs::components::transform::TransformComponent;
use edict::QueryIter;
use game::Game;
use input_event::InputEvent;
use tracing::debug;
use crate::input::{InputSystem, KeyCode, MouseMotion, MouseExact, CursorEnteredWindow, MouseScroll, CursorLeftWindow, MouseButton, InputButtons};
use crate::render::material::Material;
use crate::render::texture::Texture;
use crate::ecs::components::camera::CameraComponent;
use crate::math::{Angle, Transform};
#[derive(Debug, Default)]
struct Point2d {
x: i32,
y: i32,
}
impl std::fmt::Display for Point2d {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "(x={}, y={})", self.x, self.y)
}
}
impl Point2d {
pub fn new(x: i32, y: i32) -> Self {
Self {
x,
y,
}
}
}
#[derive(Debug, Default)]
struct Point3d {
x: i32,
y: i32,
z: i32,
}
impl std::fmt::Display for Point3d {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "(x={}, y={}, z={})", self.x, self.y, self.z)
}
}
impl Point3d {
pub fn new(x: i32, y: i32, z: i32) -> Self {
Self {
x,
y,
z,
}
}
}
#[async_std::main]
async fn main() {
let mut world = edict::World::new();
//world.spawn((Point2d::new(10, 10), Point3d::new(50, 50, 50)));
let diffuse_bytes = include_bytes!("../res/happy-tree.png");
let diffuse_texture = Texture::from_bytes(diffuse_bytes).unwrap();
world.spawn((MeshComponent::new(
render::mesh::Mesh {
vertices: crate::render::vertex::VERTICES.to_vec(),
indices: Some(crate::render::vertex::INDICES.to_vec())
}, Material {
shader_id: 0,
texture: diffuse_texture.clone()
}),
TransformComponent::from(Transform::from_xyz(0.005, 0.0, -2.0)),
));
world.spawn((MeshComponent::new(
render::mesh::Mesh {
vertices: crate::render::vertex::VERTICES.to_vec(),
indices: Some(crate::render::vertex::INDICES.to_vec())
}, Material {
shader_id: 0,
texture: diffuse_texture
}),
TransformComponent::from(Transform::from_xyz(0.005, 0.7, -0.5)),
));
let mut camera = CameraComponent::new();
camera.transform.translation += glam::Vec3::new(0.0, 0.0, 2.0);
//camera.transform.rotate_y(Angle::Degrees(-25.0));
camera.transform.rotate_z(Angle::Degrees(-90.0));
world.spawn((camera,));
let jiggle_system = |world: &mut edict::World| -> anyhow::Result<()> {
let keys = world.get_resource();
if keys.is_none() {
return Ok(());
}
let keys: Ref<InputButtons<KeyCode>> = keys.unwrap();
let speed = 0.001;
let mut dir_x = 0.0;
let mut dir_y = 0.0;
if keys.is_pressed(KeyCode::A) {
dir_x += speed;
}
if keys.is_pressed(KeyCode::D) {
dir_x -= speed;
}
if keys.is_pressed(KeyCode::S) {
dir_y += speed;
}
if keys.is_pressed(KeyCode::W) {
dir_y -= speed;
}
drop(keys);
for transform in world.query_mut::<(&mut TransformComponent,)>().iter_mut() {
let t = &mut transform.transform;
//debug!("Translation: {}", t.translation);
/* t.translation += glam::Vec3::new(0.0, 0.001, 0.0);
t.translation.x *= -1.0; */
t.translation.x += dir_x;
t.translation.y += dir_y;
}
/* for mesh in world.query_mut::<(&mut MeshComponent,)>().iter_mut() {
for vertex in mesh.mesh.vertices.iter_mut() {
vertex.position[0] += 0.0001;
}
} */
Ok(())
};
Game::initialize().await
.with_world(world)
.with_system("jiggle", jiggle_system, &["input"])
.run().await;
}

View File

@ -251,7 +251,7 @@ impl BasicRenderer {
label: Some("texture_bind_group_layout"),
});
let shader_src = resources::load_string("shader/base.wgsl").await.expect("Failed to load shader!");
let shader_src = include_str!("shaders/base.wgsl");
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(&shader_src)),
@ -463,7 +463,7 @@ impl BasicRenderer {
let (vertex_buffer, buffer_indices) = self.create_vertex_index_buffers(mesh);
let texture_img = &model.material.texture;
let diffuse_texture = RenderTexture::from_image(&self.device, &self.queue, &texture_img.img, 0, Some("happy-tree.png")).unwrap();
let diffuse_texture = RenderTexture::from_image(&self.device, &self.queue, &texture_img.img, 0, None).unwrap();
let texture_bind_group_layout =
self.device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {