diff options
| author | HampusM <hampus@hampusmat.com> | 2026-07-08 23:36:12 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-07-08 23:36:12 +0200 |
| commit | 5abf78013d3688d900deb6e1df5afd60954da4e7 (patch) | |
| tree | 38f5f972af2ba4584d2e89e1a29096c83a3ad71a /src | |
| parent | 0b78c7da4980c90c2feca1ef7e0ee898db084486 (diff) | |
feat: add names to entities
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 138 |
1 files changed, 76 insertions, 62 deletions
diff --git a/src/main.rs b/src/main.rs index 33d2486..aa8a91d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,69 +90,83 @@ impl engine::ecs::extension::Extension for Application fn init(mut assets: Single<Assets>, mut actions: Actions) -> Result<(), EngineError> { - actions.spawn(( - WindowCreationAttributes::default() - .with_title("Game") - .with_icon(Some(WindowIcon::Image( - Image::from_reader( - Cursor::new(include_bytes!("../res/icon.ico")), - ImageFormat::Ico, - ) - .with_context(|| "Invalid icon image")?, - ))) - .with_cursor_visible(false) - .with_cursor_grab_mode(WindowCursorGrabMode::Locked), - RenderingTargetWindow, - )); - - actions.spawn(( - Camera::default(), - WorldPosition { - position: Vec3 { x: 0.0, y: 0.0, z: 3.0 }, - }, - ActiveCamera, - FlyCamera::default(), - )); - - actions.spawn(( - PointLight::builder() - .diffuse(YELLOW) - .attenuation_params(AttenuationParams { - linear: 0.045, - quadratic: 0.0075, - ..Default::default() - }) - .build(), - WorldPosition::from(Vec3 { x: -6.0, y: 3.0, z: 3.0 }), - Model::new(assets.store_with_name_with("light_cube", |assets| { - ModelSpec::builder() - .mesh( - assets.store_with_name( - "light_cube_mesh", - cube_mesh_create( - CubeMeshCreationSpec::builder() - .dimens(Dimens3::from(2.0)) - .build(), + actions.spawn_named( + "Main window", + ( + WindowCreationAttributes::default() + .with_title("Game") + .with_icon(Some(WindowIcon::Image( + Image::from_reader( + Cursor::new(include_bytes!("../res/icon.ico")), + ImageFormat::Ico, + ) + .with_context(|| "Invalid icon image")?, + ))) + .with_cursor_visible(false) + .with_cursor_grab_mode(WindowCursorGrabMode::Locked), + RenderingTargetWindow, + ), + ); + + actions.spawn_named( + "Main camera", + ( + Camera::default(), + WorldPosition { + position: Vec3 { x: 0.0, y: 0.0, z: 3.0 }, + }, + ActiveCamera, + FlyCamera::default(), + ), + ); + + actions.spawn_named( + "Sun cube", + ( + PointLight::builder() + .diffuse(YELLOW) + .attenuation_params(AttenuationParams { + linear: 0.045, + quadratic: 0.0075, + ..Default::default() + }) + .build(), + WorldPosition::from(Vec3 { x: -6.0, y: 3.0, z: 3.0 }), + Model::new(assets.store_with_name_with("light_cube", |assets| { + ModelSpec::builder() + .mesh( + assets.store_with_name( + "light_cube_mesh", + cube_mesh_create( + CubeMeshCreationSpec::builder() + .dimens(Dimens3::from(2.0)) + .build(), + ), ), - ), - ) - .materials(ModelMaterials::direct([( - "surface", - assets.store_with_name( - "light_cube_surface_mat", - Material::builder().ambient(YELLOW * 5.0).build(), - ), - )])) - .material_name("surface") - .build() - })), - MaterialFlags::builder().use_ambient_color(true).build(), - )); - - actions.spawn(( - Model::new(assets.load::<ModelSpec>(Path::new(RESOURCE_DIR).join("teapot.obj"))), - WorldPosition::from(Vec3 { x: 1.6, y: 0.0, z: 0.0 }), - )); + ) + .materials(ModelMaterials::direct([( + "surface", + assets.store_with_name( + "light_cube_surface_mat", + Material::builder().ambient(YELLOW * 5.0).build(), + ), + )])) + .material_name("surface") + .build() + })), + MaterialFlags::builder().use_ambient_color(true).build(), + ), + ); + + actions.spawn_named( + "Big teapot", + ( + Model::new( + assets.load::<ModelSpec>(Path::new(RESOURCE_DIR).join("teapot.obj")), + ), + WorldPosition::from(Vec3 { x: 1.6, y: 0.0, z: 0.0 }), + ), + ); Ok(()) } |
