diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
commit | 95708732572431dc057a9fd71fa8bd8571a336a2 (patch) | |
tree | 3255e3407eb069c8124d41e1d6f60163b7c5091d /stockton-types/src | |
parent | 9bceddef62c48b56e7b93a2ca19636e1ff6486cb (diff) |
feat(all): start using an ECS
Diffstat (limited to 'stockton-types/src')
-rw-r--r-- | stockton-types/src/components/mod.rs | 23 | ||||
-rw-r--r-- | stockton-types/src/lib.rs | 5 | ||||
-rw-r--r-- | stockton-types/src/session.rs (renamed from stockton-types/src/world.rs) | 35 |
3 files changed, 55 insertions, 8 deletions
diff --git a/stockton-types/src/components/mod.rs b/stockton-types/src/components/mod.rs index c96417e..0dd9fe9 100644 --- a/stockton-types/src/components/mod.rs +++ b/stockton-types/src/components/mod.rs @@ -14,3 +14,26 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see <http://www.gnu.org/licenses/>. */ + +use crate::Vector3; + +#[derive(Clone, Copy, Debug, PartialEq)] +struct Transform { + /// Position of the object + pub position: Vector3, + + /// Rotation of the object (euler angles in radians) + pub rotation: Vector3, +} + +#[derive(Clone, Copy, Debug, PartialEq)] +struct CameraSettings { + /// FOV (radians) + pub fov: f32, + + /// Near clipping plane (world units) + pub near: f32, + + /// Far clipping plane (world units) + pub far: f32, +} diff --git a/stockton-types/src/lib.rs b/stockton-types/src/lib.rs index a53d4fa..1fda444 100644 --- a/stockton-types/src/lib.rs +++ b/stockton-types/src/lib.rs @@ -17,13 +17,14 @@ //! Common types for all stockton crates. +extern crate legion; extern crate nalgebra_glm as na; extern crate stockton_levels; pub mod components; -pub mod world; +pub mod session; -pub use world::World; +pub use session::Session; /// Alias for convenience pub type Vector2 = na::Vec2; diff --git a/stockton-types/src/world.rs b/stockton-types/src/session.rs index 3db567a..8e48b59 100644 --- a/stockton-types/src/world.rs +++ b/stockton-types/src/session.rs @@ -17,17 +17,40 @@ //! The thing you play on and all the associated state. -use stockton_levels::prelude::*; +use legion::systems::Builder; +use legion::*; /// A loaded world. -pub struct World<T: MinBSPFeatures<VulkanSystem>> { - pub map: T, +pub struct Session { + world: World, + resources: Resources, + schedule: Schedule, } -impl<T: MinBSPFeatures<VulkanSystem>> World<T> { +impl Session { /// Create a new world from a level. /// The level can be any format, as long as it has the required features of a bsp. - pub fn new(map: T) -> World<T> { - World { map } + pub fn new<R: FnOnce(&mut Resources), S: FnOnce(&mut Builder)>( + add_resources: R, + add_systems: S, + ) -> Session { + let world = World::default(); + + let mut resources = Resources::default(); + add_resources(&mut resources); + + let mut schedule = Schedule::builder(); + add_systems(&mut schedule); + let schedule = schedule.build(); + + Session { + world, + resources, + schedule, + } + } + + pub fn do_update(&mut self) { + self.schedule.execute(&mut self.world, &mut self.resources); } } |