summaryrefslogtreecommitdiff
path: root/engine/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/lib.rs')
-rw-r--r--engine/src/lib.rs108
1 files changed, 40 insertions, 68 deletions
diff --git a/engine/src/lib.rs b/engine/src/lib.rs
index abf26f5..36affff 100644
--- a/engine/src/lib.rs
+++ b/engine/src/lib.rs
@@ -1,61 +1,45 @@
#![deny(clippy::all, clippy::pedantic)]
#![allow(clippy::needless_pass_by_value)]
-use ecs::component::Sequence as ComponentSequence;
-use ecs::event::component::TypeTransformComponentsToAddedEvents;
-use ecs::event::{Event, Sequence as EventSequence};
-use ecs::extension::Extension;
-use ecs::sole::Sole;
-use ecs::system::{Into, System};
-use ecs::tuple::Reduce as TupleReduce;
-use ecs::uid::Uid;
-use ecs::{SoleAlreadyExistsError, World};
-
-use crate::delta_time::{update as update_delta_time, DeltaTime, LastUpdate};
-use crate::event::{
- Conclude as ConcludeEvent,
- PostPresent as PostPresentEvent,
- PreUpdate as PreUpdateEvent,
- Present as PresentEvent,
- Update as UpdateEvent,
-};
-
-mod opengl;
-mod shader_preprocessor;
+use crate::asset::{Assets, Extension as AssetExtension};
+use crate::ecs::error::HandlerFn as ErrorHandlerFn;
+use crate::ecs::extension::Extension;
+use crate::ecs::World;
+
mod util;
+mod work_queue;
+pub mod asset;
pub mod camera;
+pub mod collision;
pub mod data_types;
-pub mod delta_time;
pub mod draw_flags;
-pub mod event;
pub mod file_format;
+pub mod image;
pub mod input;
pub mod lighting;
pub mod material;
pub mod math;
pub mod mesh;
-pub mod performance;
+pub mod model;
pub mod projection;
-pub mod renderer;
-pub mod shader;
+pub mod reflection;
+pub mod rendering;
+pub mod scene;
+pub mod sky_box;
pub mod texture;
pub mod transform;
-pub mod vertex;
-pub mod window;
+pub mod ui;
+pub mod windowing;
+
+pub extern crate engine_ecs as ecs;
-pub extern crate ecs;
+pub use ecs::error::Error;
pub(crate) use crate::data_types::matrix;
pub use crate::data_types::{color, vector};
-type EventOrder = (
- PreUpdateEvent,
- UpdateEvent,
- PresentEvent,
- PostPresentEvent,
- ConcludeEvent,
-);
+const INITIAL_ASSET_CAPACITY: usize = 128;
#[derive(Debug)]
pub struct Engine
@@ -71,53 +55,34 @@ impl Engine
{
let mut world = World::new();
- world.add_sole(DeltaTime::default()).ok();
+ let mut assets = Assets::with_capacity(INITIAL_ASSET_CAPACITY);
- world.register_system(
- PreUpdateEvent,
- update_delta_time
- .into_system()
- .initialize((LastUpdate::default(),)),
- );
+ crate::model::asset::add_importers(&mut assets);
+ crate::material::asset::add_importers(&mut assets);
- Self { world }
- }
+ crate::texture::initialize(&mut assets);
- pub fn spawn<Comps>(&mut self, components: Comps) -> Uid
- where
- Comps: ComponentSequence + TupleReduce<TypeTransformComponentsToAddedEvents>,
- Comps::Out: EventSequence,
- {
- self.world.create_entity(components)
- }
+ world.add_extension(AssetExtension { assets });
- pub fn register_system<'this, SystemImpl>(
- &'this mut self,
- event: impl Event,
- system: impl System<'this, SystemImpl>,
- )
- {
- self.world.register_system(event, system);
+ Self { world }
}
- /// Adds a globally shared singleton value.
- ///
- /// # Errors
- /// Returns `Err` if this [`Sole`] has already been added.
- pub fn add_sole(&mut self, sole: impl Sole) -> Result<(), SoleAlreadyExistsError>
+ pub fn with_error_handler(mut self, error_handler: ErrorHandlerFn) -> Self
{
- self.world.add_sole(sole)
+ self.world.set_err_handler(error_handler);
+ self
}
- pub fn add_extension(&mut self, extension: impl Extension)
+ pub fn with_extension(mut self, extension: impl Extension) -> Self
{
self.world.add_extension(extension);
+ self
}
/// Runs the event loop.
- pub fn start(&self)
+ pub fn start(&mut self)
{
- self.world.event_loop::<EventOrder>();
+ self.world.start_loop();
}
}
@@ -128,3 +93,10 @@ impl Default for Engine
Self::new()
}
}
+
+#[macro_export]
+macro_rules! error {
+ ($($tt: tt)*) => {
+ $crate::ecs::error!($($tt)*)
+ };
+}