diff --git a/Cargo.lock b/Cargo.lock index a5aeee7..c44ddb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,7 +188,7 @@ dependencies = [ "block", "cocoa-foundation", "core-foundation 0.9.1", - "core-graphics 0.22.1", + "core-graphics 0.22.2", "foreign-types", "libc", "objc", @@ -261,9 +261,9 @@ dependencies = [ [[package]] name = "core-graphics" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc239bba52bab96649441699533a68de294a101533b0270b2d65aa402b29a7f9" +checksum = "269f35f69b542b80e736a20a89a05215c0ce80c2c03c514abb2e318b78379d86" dependencies = [ "bitflags", "core-foundation 0.9.1", @@ -512,101 +512,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3b0c040a1fe6529d30b3c5944b280c7f0dcb2930d2c3062bca967b602583d0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748" - -[[package]] -name = "futures-executor" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4caa2b2b68b880003057c1dd49f1ed937e38f22fcf6c212188a121f08cf40a65" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" - -[[package]] -name = "futures-macro" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" - -[[package]] -name = "futures-task" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" -dependencies = [ - "once_cell", -] - -[[package]] -name = "futures-util" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", -] - [[package]] name = "getrandom" version = "0.1.15" @@ -964,13 +869,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] -name = "memmap" -version = "0.7.0" +name = "memmap2" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +checksum = "d9b70ca2a6103ac8b665dc150b142ef0e4e89df640c9e6cf295d189c3caebe5a" dependencies = [ "libc", - "winapi 0.3.9", ] [[package]] @@ -1280,38 +1184,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pin-project" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.19" @@ -1333,18 +1205,6 @@ dependencies = [ "toml", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" - [[package]] name = "proc-macro2" version = "1.0.24" @@ -1623,9 +1483,9 @@ dependencies = [ [[package]] name = "smithay-client-toolkit" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ec5c077def8af49f9b5aeeb5fcf8079c638c6615c3a8f9305e2dea601de57f7" +checksum = "86d1d080d3dc98d68251d073b231dfaa200fdc2ddebc435b313ad937d0ae9dfd" dependencies = [ "andrew", "bitflags", @@ -1634,7 +1494,7 @@ dependencies = [ "dlib", "lazy_static", "log", - "memmap", + "memmap2", "nix", "wayland-client", "wayland-cursor", @@ -1642,32 +1502,46 @@ dependencies = [ ] [[package]] -name = "space-crush" +name = "space-crush-app" version = "0.1.0" dependencies = [ - "futures", "gl", "glc", "glutin", "glyph_brush", "log", "log4rs", - "num_cpus", "ordered-float 2.0.1", - "rand", "serde", "serde_json", - "serde_yaml", "shred", "shrev", "smallvec", + "space-crush-common", + "specs", + "thiserror", +] + +[[package]] +name = "space-crush-common" +version = "0.1.0" +dependencies = [ + "glc", + "log", + "log4rs", + "serde_yaml", + "shred", + "shrev", "specs", "thiserror", - "tokio", "vfs", "vfs-zip", ] +[[package]] +name = "space-crush-server" +version = "0.1.0" + [[package]] name = "specs" version = "0.16.1" @@ -1758,16 +1632,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "tokio" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12a3eb39ee2c231be64487f1fcbe726c8f2514876a55480a5ab8559fc374252" -dependencies = [ - "autocfg", - "pin-project-lite", -] - [[package]] name = "toml" version = "0.5.7" @@ -1866,7 +1730,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d68a369614cd12ca384ca6e75ab0a5ac3a5acbfe8003622e20808a322b9bb652" dependencies = [ - "flate2 1.0.14", + "flate2 0.2.20", "vfs", "zip", ] @@ -2029,7 +1893,7 @@ dependencies = [ "bitflags", "cocoa", "core-foundation 0.9.1", - "core-graphics 0.22.1", + "core-graphics 0.22.2", "core-video-sys", "dispatch", "instant", @@ -2112,9 +1976,9 @@ dependencies = [ [[package]] name = "zip" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "543adf038106b64cfca4711c82c917d785e3540e04f7996554488f988ec43124" +checksum = "cc2896475a242c41366941faa27264df2cb935185a92e059a004d0048feb2ac5" dependencies = [ "byteorder", "bzip2", diff --git a/Cargo.toml b/Cargo.toml index 80b97b2..1733848 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,13 +2,17 @@ members = [ "gl", "glc", - "space-crush", + "space-crush-app", + "space-crush-common", + "space-crush-server", ] default-members = [ - "space-crush", + "space-crush-app", ] [patch.crates-io] gl = { path = "./gl" } glc = { path = "./glc" } -space-crush = { path = "./space-crush" } +space-crush-app = { path = "./space-crush-app" } +space-crush-common = { path = "./space-crush-common" } +space-crush-server = { path = "./space-crush-server" } diff --git a/space-crush/Cargo.toml b/space-crush-app/Cargo.toml similarity index 70% rename from space-crush/Cargo.toml rename to space-crush-app/Cargo.toml index 23287e9..405185c 100644 --- a/space-crush/Cargo.toml +++ b/space-crush-app/Cargo.toml @@ -1,28 +1,29 @@ [package] -name = "space-crush" +name = "space-crush-app" version = "0.1.0" authors = ["Bergmann89 "] edition = "2018" [dependencies] -futures = "0.3" +# futures = "0.3" gl = { version = "0.1", features = [ "use_log_crate" ] } glc = "0.1" glutin = { version = "0.25", features = [ "serde" ] } glyph_brush = "0.7" log = { version = "0.4", features = [ "max_level_trace", "release_max_level_warn" ] } log4rs = "0.13" -num_cpus = "1.13" +# num_cpus = "1.13" ordered-float = "2.0" -rand = "0.7" -serde = { version = "1.0", features = ["derive"] } +# rand = "0.7" +serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" -serde_yaml = "0.8" +# serde_yaml = "0.8" shred = { version = "0.10", features = [ "shred-derive" ] } shrev = "1.1" smallvec = { version = "1.5", features = [ "serde" ] } +space-crush-common = "0.1" specs = "0.16" thiserror = "1.0" -tokio = "0.3" -vfs = "0.4" -vfs-zip = "0.2" +# tokio = "0.3" +# vfs = "0.4" +# vfs-zip = "0.2" diff --git a/space-crush/config.json b/space-crush-app/config.json similarity index 100% rename from space-crush/config.json rename to space-crush-app/config.json diff --git a/space-crush/log4rs.yml b/space-crush-app/log4rs.yml similarity index 100% rename from space-crush/log4rs.yml rename to space-crush-app/log4rs.yml diff --git a/space-crush/resources/fonts/DroidSansMono.ttf b/space-crush-app/resources/fonts/DroidSansMono.ttf similarity index 100% rename from space-crush/resources/fonts/DroidSansMono.ttf rename to space-crush-app/resources/fonts/DroidSansMono.ttf diff --git a/space-crush/resources/shader/noise.frag b/space-crush-app/resources/shader/noise.frag similarity index 100% rename from space-crush/resources/shader/noise.frag rename to space-crush-app/resources/shader/noise.frag diff --git a/space-crush/resources/shader/noise.vert b/space-crush-app/resources/shader/noise.vert similarity index 100% rename from space-crush/resources/shader/noise.vert rename to space-crush-app/resources/shader/noise.vert diff --git a/space-crush/resources/shader/quad.frag b/space-crush-app/resources/shader/quad.frag similarity index 100% rename from space-crush/resources/shader/quad.frag rename to space-crush-app/resources/shader/quad.frag diff --git a/space-crush/resources/shader/quad.vert b/space-crush-app/resources/shader/quad.vert similarity index 100% rename from space-crush/resources/shader/quad.vert rename to space-crush-app/resources/shader/quad.vert diff --git a/space-crush/resources/shader/text.frag b/space-crush-app/resources/shader/text.frag similarity index 100% rename from space-crush/resources/shader/text.frag rename to space-crush-app/resources/shader/text.frag diff --git a/space-crush/resources/shader/text.vert b/space-crush-app/resources/shader/text.vert similarity index 100% rename from space-crush/resources/shader/text.vert rename to space-crush-app/resources/shader/text.vert diff --git a/space-crush-app/resources/textures/planet01.png b/space-crush-app/resources/textures/planet01.png new file mode 100644 index 0000000..2bf41e0 Binary files /dev/null and b/space-crush-app/resources/textures/planet01.png differ diff --git a/space-crush/src/misc/error.rs b/space-crush-app/src/error.rs similarity index 78% rename from space-crush/src/misc/error.rs rename to space-crush-app/src/error.rs index e335fce..e60a04d 100644 --- a/space-crush/src/misc/error.rs +++ b/space-crush-app/src/error.rs @@ -4,28 +4,17 @@ use glc::error::Error as GlcError; use glutin::{ContextError as GlutinContextError, CreationError as GlutinCreationError}; use glyph_brush::ab_glyph::InvalidFont; use serde_json::Error as JsonError; -use serde_yaml::Error as YamlError; +use space_crush_common::{misc::VfsError, Error as CommonError}; use thiserror::Error; -use vfs::VfsError; -use vfs_zip::Error as VfsZipError; #[derive(Debug, Error)] pub enum Error { #[error("IO Error: {0}")] IoError(IoError), - #[error("VFS Error: {0}")] - VfsError(VfsError), - - #[error("VFS ZIP Error: {0}")] - VfsZipError(VfsZipError), - #[error("JSON Error: {0}")] JsonError(JsonError), - #[error("YAML Error: {0}")] - YamlError(YamlError), - #[error("GLC Error: {0}")] GlcError(GlcError), @@ -38,15 +27,18 @@ pub enum Error { #[error("Invalid Font: {0}")] InvalidFont(InvalidFont), + #[error("VFS Error: {0}")] + VfsError(VfsError), + + #[error("{0}")] + CommonError(CommonError), + #[error("Resource is not registered: {0}!")] ResourceNotRegistered(&'static str), #[error("Unable to create OpenGL context!")] CreateContext, - #[error("Unable to initialize VFS!")] - InitVFS, - #[error("Font is not set!")] FontNotSet, } @@ -57,30 +49,12 @@ impl From for Error { } } -impl From for Error { - fn from(err: VfsError) -> Self { - Self::VfsError(err) - } -} - -impl From for Error { - fn from(err: VfsZipError) -> Self { - Self::VfsZipError(err) - } -} - impl From for Error { fn from(err: JsonError) -> Self { Self::JsonError(err) } } -impl From for Error { - fn from(err: YamlError) -> Self { - Self::YamlError(err) - } -} - impl From for Error { fn from(err: GlcError) -> Self { Self::GlcError(err) @@ -104,3 +78,15 @@ impl From for Error { Self::InvalidFont(err) } } + +impl From for Error { + fn from(err: VfsError) -> Self { + Self::VfsError(err) + } +} + +impl From for Error { + fn from(err: CommonError) -> Self { + Self::CommonError(err) + } +} diff --git a/space-crush/src/app/mod.rs b/space-crush-app/src/lib.rs similarity index 98% rename from space-crush/src/app/mod.rs rename to space-crush-app/src/lib.rs index 5f5c342..945fef3 100644 --- a/space-crush/src/app/mod.rs +++ b/space-crush-app/src/lib.rs @@ -1,3 +1,4 @@ +mod error; mod misc; mod render; mod resources; @@ -5,7 +6,7 @@ mod systems; use specs::{Dispatcher, DispatcherBuilder, World}; -use crate::Error; +pub use error::Error; use misc::{Events, TextManager, Window}; use render::{Debug, Init, Test}; diff --git a/space-crush/src/main.rs b/space-crush-app/src/main.rs similarity index 63% rename from space-crush/src/main.rs rename to space-crush-app/src/main.rs index 3a0ba70..e456b0c 100644 --- a/space-crush/src/main.rs +++ b/space-crush-app/src/main.rs @@ -1,12 +1,17 @@ use log::{error, info}; +use space_crush_app::{App, Error}; +use space_crush_common::{ + misc::{init_logger, Vfs}, + Dispatcher, +}; use specs::{World, WorldExt}; -use space_crush::{init_logger, misc::Vfs, App, Error, Server}; - fn main() -> Result<(), Error> { - let vfs = Vfs::new()?; + let vfs = Vfs::new(&["space-crush-app"])?; + + init_logger(&vfs, "log4rs.yml"); - init_logger(&vfs); + vfs.log_info(); info!("Application started"); @@ -25,11 +30,11 @@ fn run(vfs: Vfs) -> Result<(), Error> { let mut world = World::new(); world.insert(vfs); - let mut server = Server::new(&mut world); + let mut common = Dispatcher::new(&mut world); let mut app = App::new(&mut world)?; while app.is_running() { - server.process(&world); + common.process(&world); app.process(&world)?; } diff --git a/space-crush/src/app/misc/events.rs b/space-crush-app/src/misc/events.rs similarity index 100% rename from space-crush/src/app/misc/events.rs rename to space-crush-app/src/misc/events.rs diff --git a/space-crush/src/app/misc/mod.rs b/space-crush-app/src/misc/mod.rs similarity index 100% rename from space-crush/src/app/misc/mod.rs rename to space-crush-app/src/misc/mod.rs diff --git a/space-crush/src/app/misc/text.rs b/space-crush-app/src/misc/text.rs similarity index 99% rename from space-crush/src/app/misc/text.rs rename to space-crush-app/src/misc/text.rs index 8bc1a75..e6e0df4 100644 --- a/space-crush/src/app/misc/text.rs +++ b/space-crush-app/src/misc/text.rs @@ -26,11 +26,10 @@ use glyph_brush::{ }; use log::warn; use ordered_float::OrderedFloat; +use space_crush_common::misc::{Vfs, WorldHelper as _}; use specs::World; -use crate::{misc::Vfs, Error}; - -use super::super::misc::WorldHelper; +use crate::{misc::WorldHelper, Error}; /* TextManager */ diff --git a/space-crush/src/app/misc/window.rs b/space-crush-app/src/misc/window.rs similarity index 100% rename from space-crush/src/app/misc/window.rs rename to space-crush-app/src/misc/window.rs diff --git a/space-crush/src/app/misc/world.rs b/space-crush-app/src/misc/world.rs similarity index 52% rename from space-crush/src/app/misc/world.rs rename to space-crush-app/src/misc/world.rs index 5d7f931..bd17582 100644 --- a/space-crush/src/app/misc/world.rs +++ b/space-crush-app/src/misc/world.rs @@ -1,29 +1,15 @@ -use std::any::type_name; use std::iter::Iterator; use glc::{ shader::{Program, Shader, Type}, - texture::{Data, Target, Texture}, + texture::{Data, FilterMag, FilterMin, Target, Texture, Wrap}, }; -use shred::{Fetch, FetchMut, Resource}; -use shrev::{Event, EventChannel, ReaderId}; +use space_crush_common::misc::Vfs; use specs::World; -use crate::{misc::Vfs, Error}; +use crate::Error; pub trait WorldHelper { - fn resource(&self) -> Result, Error> - where - R: Resource; - - fn resource_mut(&self) -> Result, Error> - where - R: Resource; - - fn register_event_reader(&self) -> Result, Error> - where - E: Event; - fn load_program(&self, iter: I) -> Result where I: IntoIterator; @@ -32,29 +18,6 @@ pub trait WorldHelper { } impl WorldHelper for World { - fn resource(&self) -> Result, Error> - where - R: Resource, - { - self.try_fetch::() - .ok_or_else(|| Error::ResourceNotRegistered(type_name::())) - } - - fn resource_mut(&self) -> Result, Error> - where - R: Resource, - { - self.try_fetch_mut::() - .ok_or_else(|| Error::ResourceNotRegistered(type_name::())) - } - - fn register_event_reader(&self) -> Result, Error> - where - E: Event, - { - Ok(self.resource_mut::>()?.register_reader()) - } - fn load_program(&self, iter: I) -> Result where I: IntoIterator, @@ -78,6 +41,8 @@ impl WorldHelper for World { let mut texture = Texture::new(Target::Texture2D)?; texture.upload(&data, true)?; + texture.set_filter(FilterMin::LinearMipmapLinear, FilterMag::Linear)?; + texture.set_wrap(Wrap::ClampToEdge, Wrap::ClampToEdge, Wrap::ClampToEdge)?; Ok(texture) } diff --git a/space-crush/src/app/render/debug.rs b/space-crush-app/src/render/debug.rs similarity index 97% rename from space-crush/src/app/render/debug.rs rename to space-crush-app/src/render/debug.rs index 6f3c755..33ef6d5 100644 --- a/space-crush/src/app/render/debug.rs +++ b/space-crush-app/src/render/debug.rs @@ -1,13 +1,13 @@ use std::string::ToString; use log::warn; +use space_crush_common::resources::Global; use specs::{ReadExpect, System}; -use crate::{server::resources::Global, Error}; - -use super::super::{ +use crate::{ misc::{Text, TextCache, TextManager}, resources::State, + Error, }; /* Debug */ diff --git a/space-crush/src/app/render/init.rs b/space-crush-app/src/render/init.rs similarity index 97% rename from space-crush/src/app/render/init.rs rename to space-crush-app/src/render/init.rs index dd845c6..7e666dc 100644 --- a/space-crush/src/app/render/init.rs +++ b/space-crush-app/src/render/init.rs @@ -6,13 +6,13 @@ use glc::{ }; use log::error; use shrev::{EventChannel, ReaderId}; +use space_crush_common::misc::WorldHelper as _; use specs::{prelude::*, ReadExpect, System, World, WriteExpect}; -use crate::Error; - -use super::super::{ +use crate::{ misc::{MouseEvent, WorldHelper}, resources::{Camera, Config, Geometry, State}, + Error, }; pub struct Init { diff --git a/space-crush/src/app/render/mod.rs b/space-crush-app/src/render/mod.rs similarity index 100% rename from space-crush/src/app/render/mod.rs rename to space-crush-app/src/render/mod.rs diff --git a/space-crush/src/app/render/test.rs b/space-crush-app/src/render/test.rs similarity index 81% rename from space-crush/src/app/render/test.rs rename to space-crush-app/src/render/test.rs index 58fb3a1..9313375 100644 --- a/space-crush/src/app/render/test.rs +++ b/space-crush-app/src/render/test.rs @@ -2,16 +2,16 @@ use glc::{ matrix::{Angle, Matrix4f}, misc::Bindable, shader::{Program, Type, Uniform}, - texture::{FilterMag, FilterMin, Texture}, + texture::Texture, vector::Vector3f, }; +use space_crush_common::{misc::WorldHelper as _, resources::Global}; use specs::{ReadExpect, System, World}; -use crate::{server::resources::Global, Error}; - -use super::super::{ +use crate::{ misc::WorldHelper, resources::{Camera, Geometry}, + Error, }; pub struct Test { @@ -32,8 +32,7 @@ impl Test { world.resource::()?.bind(0)?; program.unbind(); - let mut texture = world.load_texture("resources/textures/test.png")?; - texture.set_filter(FilterMin::LinearMipmapLinear, FilterMag::Linear)?; + let texture = world.load_texture("resources/textures/planet01.png")?; Ok(Self { model, @@ -53,6 +52,9 @@ impl<'a> System<'a> for Test { Angle::Deg(10.0 * global.delta), ); + gl::enable(gl::BLEND); + gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); + self.texture.bind(); self.program.bind(); self.program.uniform(1, Uniform::Matrix4f(&self.model)); @@ -61,5 +63,7 @@ impl<'a> System<'a> for Test { self.program.unbind(); self.texture.unbind(); + + gl::disable(gl::BLEND); } } diff --git a/space-crush/src/app/resources/camera.rs b/space-crush-app/src/resources/camera.rs similarity index 100% rename from space-crush/src/app/resources/camera.rs rename to space-crush-app/src/resources/camera.rs diff --git a/space-crush/src/app/resources/config.rs b/space-crush-app/src/resources/config.rs similarity index 97% rename from space-crush/src/app/resources/config.rs rename to space-crush-app/src/resources/config.rs index d66d2ed..6d35453 100644 --- a/space-crush/src/app/resources/config.rs +++ b/space-crush-app/src/resources/config.rs @@ -2,11 +2,10 @@ use log::warn; use serde::{Deserialize, Serialize}; use serde_json::from_reader; use smallvec::{smallvec, SmallVec}; +use space_crush_common::misc::{Vfs, WorldHelper as _}; use specs::World; -use crate::{misc::Vfs, Error}; - -use super::super::misc::{VirtualKeyCode, WorldHelper}; +use crate::{misc::VirtualKeyCode, Error}; #[derive(Debug, Default, Serialize, Deserialize)] pub struct Config { diff --git a/space-crush/src/app/resources/geometry.rs b/space-crush-app/src/resources/geometry.rs similarity index 100% rename from space-crush/src/app/resources/geometry.rs rename to space-crush-app/src/resources/geometry.rs diff --git a/space-crush/src/app/resources/mod.rs b/space-crush-app/src/resources/mod.rs similarity index 100% rename from space-crush/src/app/resources/mod.rs rename to space-crush-app/src/resources/mod.rs diff --git a/space-crush/src/app/resources/state.rs b/space-crush-app/src/resources/state.rs similarity index 100% rename from space-crush/src/app/resources/state.rs rename to space-crush-app/src/resources/state.rs diff --git a/space-crush/src/app/systems/mod.rs b/space-crush-app/src/systems/mod.rs similarity index 100% rename from space-crush/src/app/systems/mod.rs rename to space-crush-app/src/systems/mod.rs diff --git a/space-crush/src/app/systems/state_update.rs b/space-crush-app/src/systems/state_update.rs similarity index 95% rename from space-crush/src/app/systems/state_update.rs rename to space-crush-app/src/systems/state_update.rs index 1648f13..fd52469 100644 --- a/space-crush/src/app/systems/state_update.rs +++ b/space-crush-app/src/systems/state_update.rs @@ -1,11 +1,11 @@ use shrev::{EventChannel, ReaderId}; +use space_crush_common::misc::WorldHelper; use specs::{prelude::*, ReadExpect, System, World, Write}; -use crate::Error; - -use super::super::{ - misc::{KeyboardEvent, MouseEvent, WindowEvent, WorldHelper}, +use crate::{ + misc::{KeyboardEvent, MouseEvent, WindowEvent}, resources::State, + Error, }; pub struct StateUpdate { diff --git a/space-crush-common/Cargo.toml b/space-crush-common/Cargo.toml new file mode 100644 index 0000000..102240d --- /dev/null +++ b/space-crush-common/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "space-crush-common" +version = "0.1.0" +authors = ["Bergmann89 "] +edition = "2018" + +[dependencies] +# futures = "0.3" +# gl = { version = "0.1", features = [ "use_log_crate" ] } +glc = "0.1" +# glutin = { version = "0.25", features = [ "serde" ] } +# glyph_brush = "0.7" +log = { version = "0.4", features = [ "max_level_trace", "release_max_level_warn" ] } +log4rs = "0.13" +# num_cpus = "1.13" +# ordered-float = "2.0" +# rand = "0.7" +# serde = { version = "1.0", features = ["derive"] } +# serde_json = "1.0" +serde_yaml = "0.8" +shred = { version = "0.10", features = [ "shred-derive" ] } +shrev = "1.1" +# smallvec = { version = "1.5", features = [ "serde" ] } +specs = "0.16" +thiserror = "1.0" +# tokio = "0.3" +vfs = "0.4" +vfs-zip = "0.2" diff --git a/space-crush-common/src/components/mod.rs b/space-crush-common/src/components/mod.rs new file mode 100644 index 0000000..2fa936e --- /dev/null +++ b/space-crush-common/src/components/mod.rs @@ -0,0 +1,3 @@ +mod position; + +pub use position::Position; diff --git a/space-crush-common/src/components/position.rs b/space-crush-common/src/components/position.rs new file mode 100644 index 0000000..58f2e25 --- /dev/null +++ b/space-crush-common/src/components/position.rs @@ -0,0 +1,24 @@ +use std::ops::{Deref, DerefMut}; + +use glc::vector::Vector2f; +use specs::{Component, VecStorage}; + +pub struct Position(pub Vector2f); + +impl Component for Position { + type Storage = VecStorage; +} + +impl Deref for Position { + type Target = Vector2f; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for Position { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} diff --git a/space-crush-common/src/components/velocity.rs b/space-crush-common/src/components/velocity.rs new file mode 100644 index 0000000..8109620 --- /dev/null +++ b/space-crush-common/src/components/velocity.rs @@ -0,0 +1,24 @@ +use std::ops::{Deref, DerefMut}; + +use glc::vector::Vector2f; +use specs::{Component, VecStorage}; + +pub struct Velocity(pub Vector2f); + +impl Component for Velocity { + type Storage = VecStorage; +} + +impl Deref for Velocity { + type Target = Vector2f; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for Velocity { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} diff --git a/space-crush/src/server/mod.rs b/space-crush-common/src/dispatcher.rs similarity index 62% rename from space-crush/src/server/mod.rs rename to space-crush-common/src/dispatcher.rs index 4b711e1..2db32b5 100644 --- a/space-crush/src/server/mod.rs +++ b/space-crush-common/src/dispatcher.rs @@ -1,16 +1,12 @@ -pub mod resources; -pub mod systems; +use specs::{Dispatcher as Inner, DispatcherBuilder, World}; -use specs::{Dispatcher, DispatcherBuilder, World}; +use crate::{resources::Global, systems::Process}; -use resources::Global; -use systems::Process; - -pub struct Server<'a, 'b> { - dispatcher: Dispatcher<'a, 'b>, +pub struct Dispatcher<'a, 'b> { + dispatcher: Inner<'a, 'b>, } -impl<'a, 'b> Server<'a, 'b> { +impl<'a, 'b> Dispatcher<'a, 'b> { pub fn new(world: &mut World) -> Self { world.insert(Global::default()); diff --git a/space-crush-common/src/error.rs b/space-crush-common/src/error.rs new file mode 100644 index 0000000..ecf26c1 --- /dev/null +++ b/space-crush-common/src/error.rs @@ -0,0 +1,51 @@ +use std::io::Error as IoError; + +use serde_yaml::Error as YamlError; +use thiserror::Error; +use vfs::VfsError; +use vfs_zip::Error as VfsZipError; + +#[derive(Debug, Error)] +pub enum Error { + #[error("IO Error: {0}")] + IoError(IoError), + + #[error("VFS Error: {0}")] + VfsError(VfsError), + + #[error("VFS ZIP Error: {0}")] + VfsZipError(VfsZipError), + + #[error("YAML Error: {0}")] + YamlError(YamlError), + + #[error("Resource is not registered: {0}!")] + ResourceNotRegistered(&'static str), + + #[error("Unable to initialize VFS!")] + InitVFS, +} + +impl From for Error { + fn from(err: IoError) -> Self { + Self::IoError(err) + } +} + +impl From for Error { + fn from(err: VfsError) -> Self { + Self::VfsError(err) + } +} + +impl From for Error { + fn from(err: VfsZipError) -> Self { + Self::VfsZipError(err) + } +} + +impl From for Error { + fn from(err: YamlError) -> Self { + Self::YamlError(err) + } +} diff --git a/space-crush-common/src/lib.rs b/space-crush-common/src/lib.rs new file mode 100644 index 0000000..ac3bbea --- /dev/null +++ b/space-crush-common/src/lib.rs @@ -0,0 +1,9 @@ +pub mod components; +pub mod dispatcher; +pub mod error; +pub mod misc; +pub mod resources; +pub mod systems; + +pub use dispatcher::Dispatcher; +pub use error::Error; diff --git a/space-crush/src/misc/log.rs b/space-crush-common/src/misc/log.rs similarity index 92% rename from space-crush/src/misc/log.rs rename to space-crush-common/src/misc/log.rs index 1fbeef2..5223d2a 100644 --- a/space-crush/src/misc/log.rs +++ b/space-crush-common/src/misc/log.rs @@ -20,8 +20,8 @@ use serde_yaml::from_str; use crate::{misc::Vfs, Error}; -pub fn init(vfs: &Vfs) { - let (config, err) = match load_from_file(vfs) { +pub fn init(vfs: &Vfs, path: &str) { + let (config, err) = match load_from_file(vfs, path) { Ok(config) => (config, None), Err(err) => (default_config(), Some(err)), }; @@ -33,11 +33,9 @@ pub fn init(vfs: &Vfs) { } } -fn load_from_file(vfs: &Vfs) -> Result { +fn load_from_file(vfs: &Vfs, path: &str) -> Result { let mut config = String::default(); - vfs.join("log4rs.yml")? - .open_file()? - .read_to_string(&mut config)?; + vfs.join(path)?.open_file()?.read_to_string(&mut config)?; let mut stderr = stderr(); let config = from_str::(&config)?; diff --git a/space-crush-common/src/misc/mod.rs b/space-crush-common/src/misc/mod.rs new file mode 100644 index 0000000..c06fb18 --- /dev/null +++ b/space-crush-common/src/misc/mod.rs @@ -0,0 +1,7 @@ +mod log; +mod vfs; +mod world; + +pub use self::log::init as init_logger; +pub use self::vfs::{Vfs, VfsError}; +pub use world::WorldHelper; diff --git a/space-crush/src/misc/vfs.rs b/space-crush-common/src/misc/vfs.rs similarity index 60% rename from space-crush/src/misc/vfs.rs rename to space-crush-common/src/misc/vfs.rs index 9bec47a..3b54732 100644 --- a/space-crush/src/misc/vfs.rs +++ b/space-crush-common/src/misc/vfs.rs @@ -1,10 +1,11 @@ use std::collections::HashSet; use std::env::{current_dir, current_exe}; use std::fs::File; +use std::iter::once; use std::ops::Deref; +use std::path::PathBuf; use log::info; - use vfs::{ impls::{overlay::OverlayFS, physical::PhysicalFS}, VfsPath, @@ -13,54 +14,65 @@ use vfs_zip::ZipReadOnly as ZipFS; use crate::Error; +pub use vfs::error::VfsError; + #[derive(Clone)] -pub struct Vfs(pub VfsPath); +pub struct Vfs { + pub root: VfsPath, + pub layers: Vec, +} impl Vfs { - pub fn new() -> Result { + pub fn new(dirs: &[&str]) -> Result { let dirs = vec![ current_exe() .ok() .as_ref() .and_then(|p| p.parent()) .map(|p| p.to_owned()), - current_exe() - .ok() - .as_ref() - .and_then(|p| p.parent()) - .map(|p| p.join("space-crush")), current_dir().ok(), - current_dir().ok().map(|p| p.join("space-crush")), ] .into_iter() - .filter_map(|d| d); + .filter_map(|d| d) + .map(|p| once(&"").chain(dirs).map(move |d| p.join(d))) + .flatten(); let mut paths = HashSet::new(); let mut layers = Vec::new(); + let mut overlays = Vec::new(); for dir in dirs.clone() { if paths.insert(dir.clone()) { - info!("Adding layer to VFS: {}", dir.display()); + layers.push(dir.to_owned()); let layer = VfsPath::new(PhysicalFS::new(dir)); - layers.push(layer); + overlays.push(layer); } } for dir in dirs { let path = dir.join("resources.bin"); if path.is_file() && paths.insert(path.to_owned()) { - info!("Adding layer to VFS: {}", dir.display()); + layers.push(dir.to_owned()); let zip = File::open(path)?; let layer = VfsPath::new(ZipFS::new_relaxed(zip)?); - layers.push(layer); + overlays.push(layer); } } - Ok(Self(VfsPath::new(OverlayFS::new(&layers)))) + Ok(Self { + root: VfsPath::new(OverlayFS::new(&overlays)), + layers, + }) + } + + pub fn log_info(&self) { + for layer in &self.layers { + info!("VFS Layer: {}", layer.display()); + } } } @@ -68,6 +80,6 @@ impl Deref for Vfs { type Target = VfsPath; fn deref(&self) -> &Self::Target { - &self.0 + &self.root } } diff --git a/space-crush-common/src/misc/world.rs b/space-crush-common/src/misc/world.rs new file mode 100644 index 0000000..bc2db0c --- /dev/null +++ b/space-crush-common/src/misc/world.rs @@ -0,0 +1,46 @@ +use std::any::type_name; + +use shred::{Fetch, FetchMut, Resource}; +use shrev::{Event, EventChannel, ReaderId}; +use specs::World; + +use crate::Error; + +pub trait WorldHelper { + fn resource(&self) -> Result, Error> + where + R: Resource; + + fn resource_mut(&self) -> Result, Error> + where + R: Resource; + + fn register_event_reader(&self) -> Result, Error> + where + E: Event; +} + +impl WorldHelper for World { + fn resource(&self) -> Result, Error> + where + R: Resource, + { + self.try_fetch::() + .ok_or_else(|| Error::ResourceNotRegistered(type_name::())) + } + + fn resource_mut(&self) -> Result, Error> + where + R: Resource, + { + self.try_fetch_mut::() + .ok_or_else(|| Error::ResourceNotRegistered(type_name::())) + } + + fn register_event_reader(&self) -> Result, Error> + where + E: Event, + { + Ok(self.resource_mut::>()?.register_reader()) + } +} diff --git a/space-crush/src/server/resources/global.rs b/space-crush-common/src/resources/global.rs similarity index 100% rename from space-crush/src/server/resources/global.rs rename to space-crush-common/src/resources/global.rs diff --git a/space-crush/src/server/resources/mod.rs b/space-crush-common/src/resources/mod.rs similarity index 100% rename from space-crush/src/server/resources/mod.rs rename to space-crush-common/src/resources/mod.rs diff --git a/space-crush/src/server/systems/mod.rs b/space-crush-common/src/systems/mod.rs similarity index 100% rename from space-crush/src/server/systems/mod.rs rename to space-crush-common/src/systems/mod.rs diff --git a/space-crush/src/server/systems/process.rs b/space-crush-common/src/systems/process.rs similarity index 100% rename from space-crush/src/server/systems/process.rs rename to space-crush-common/src/systems/process.rs diff --git a/space-crush-server/Cargo.toml b/space-crush-server/Cargo.toml new file mode 100644 index 0000000..51d6b36 --- /dev/null +++ b/space-crush-server/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "space-crush-server" +version = "0.1.0" +authors = ["Bergmann89 "] +edition = "2018" + +[dependencies] +# futures = "0.3" +# gl = { version = "0.1", features = [ "use_log_crate" ] } +# glc = "0.1" +# glutin = { version = "0.25", features = [ "serde" ] } +# glyph_brush = "0.7" +# log = { version = "0.4", features = [ "max_level_trace", "release_max_level_warn" ] } +# log4rs = "0.13" +# num_cpus = "1.13" +# ordered-float = "2.0" +# rand = "0.7" +# serde = { version = "1.0", features = ["derive"] } +# serde_json = "1.0" +# serde_yaml = "0.8" +# shred = { version = "0.10", features = [ "shred-derive" ] } +# shrev = "1.1" +# smallvec = { version = "1.5", features = [ "serde" ] } +# specs = "0.16" +# thiserror = "1.0" +# tokio = "0.3" +# vfs = "0.4" +# vfs-zip = "0.2" diff --git a/space-crush-server/log4rs.yml b/space-crush-server/log4rs.yml new file mode 100644 index 0000000..9b45cce --- /dev/null +++ b/space-crush-server/log4rs.yml @@ -0,0 +1,28 @@ +root: + level: debug + appenders: + - stdout + - file + +appenders: + stdout: + kind: console + encoder: + pattern: "[{d} {h({l:>5})}] {m}{n}" + + file: + kind: rolling_file + path: space-crush.log + append: true + encoder: + pattern: "{d} {h({l:<5})}{n} Module: {M}{n} File: {f}:{L}{n} Message: {m}{n}" + policy: + kind: compound + trigger: + kind: size + limit: 1 mb + roller: + kind: fixed_window + pattern: space-crush-{}.log + count: 5 + base: 1 diff --git a/space-crush-server/src/main.rs b/space-crush-server/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/space-crush-server/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/space-crush/resources/textures/test.png b/space-crush/resources/textures/test.png deleted file mode 100644 index 0f80e82..0000000 Binary files a/space-crush/resources/textures/test.png and /dev/null differ diff --git a/space-crush/src/lib.rs b/space-crush/src/lib.rs deleted file mode 100644 index 4e18ad9..0000000 --- a/space-crush/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub mod app; -pub mod misc; -pub mod server; - -pub use app::App; -pub use misc::{init_logger, Error}; -pub use server::Server; diff --git a/space-crush/src/misc/mod.rs b/space-crush/src/misc/mod.rs deleted file mode 100644 index 48aec74..0000000 --- a/space-crush/src/misc/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod error; -mod log; -mod vfs; - -pub use self::log::init as init_logger; -pub use self::vfs::Vfs; -pub use error::Error;