ソースを参照

Split modules into seperate crates

raster
Bergmann89 4年前
コミット
d05b3e3d0a
53個のファイルの変更399行の追加328行の削除
  1. +33
    -169
      Cargo.lock
  2. +7
    -3
      Cargo.toml
  3. +10
    -9
      space-crush-app/Cargo.toml
  4. +0
    -0
      space-crush-app/config.json
  5. +0
    -0
      space-crush-app/log4rs.yml
  6. +0
    -0
      space-crush-app/resources/fonts/DroidSansMono.ttf
  7. +0
    -0
      space-crush-app/resources/shader/noise.frag
  8. +0
    -0
      space-crush-app/resources/shader/noise.vert
  9. +0
    -0
      space-crush-app/resources/shader/quad.frag
  10. +0
    -0
      space-crush-app/resources/shader/quad.vert
  11. +0
    -0
      space-crush-app/resources/shader/text.frag
  12. +0
    -0
      space-crush-app/resources/shader/text.vert
  13. バイナリ
     
  14. +19
    -33
      space-crush-app/src/error.rs
  15. +2
    -1
      space-crush-app/src/lib.rs
  16. +11
    -6
      space-crush-app/src/main.rs
  17. +0
    -0
      space-crush-app/src/misc/events.rs
  18. +0
    -0
      space-crush-app/src/misc/mod.rs
  19. +2
    -3
      space-crush-app/src/misc/text.rs
  20. +0
    -0
      space-crush-app/src/misc/window.rs
  21. +5
    -40
      space-crush-app/src/misc/world.rs
  22. +3
    -3
      space-crush-app/src/render/debug.rs
  23. +3
    -3
      space-crush-app/src/render/init.rs
  24. +0
    -0
      space-crush-app/src/render/mod.rs
  25. +10
    -6
      space-crush-app/src/render/test.rs
  26. +0
    -0
      space-crush-app/src/resources/camera.rs
  27. +2
    -3
      space-crush-app/src/resources/config.rs
  28. +0
    -0
      space-crush-app/src/resources/geometry.rs
  29. +0
    -0
      space-crush-app/src/resources/mod.rs
  30. +0
    -0
      space-crush-app/src/resources/state.rs
  31. +0
    -0
      space-crush-app/src/systems/mod.rs
  32. +4
    -4
      space-crush-app/src/systems/state_update.rs
  33. +28
    -0
      space-crush-common/Cargo.toml
  34. +3
    -0
      space-crush-common/src/components/mod.rs
  35. +24
    -0
      space-crush-common/src/components/position.rs
  36. +24
    -0
      space-crush-common/src/components/velocity.rs
  37. +5
    -9
      space-crush-common/src/dispatcher.rs
  38. +51
    -0
      space-crush-common/src/error.rs
  39. +9
    -0
      space-crush-common/src/lib.rs
  40. +4
    -6
      space-crush-common/src/misc/log.rs
  41. +7
    -0
      space-crush-common/src/misc/mod.rs
  42. +28
    -16
      space-crush-common/src/misc/vfs.rs
  43. +46
    -0
      space-crush-common/src/misc/world.rs
  44. +0
    -0
      space-crush-common/src/resources/global.rs
  45. +0
    -0
      space-crush-common/src/resources/mod.rs
  46. +0
    -0
      space-crush-common/src/systems/mod.rs
  47. +0
    -0
      space-crush-common/src/systems/process.rs
  48. +28
    -0
      space-crush-server/Cargo.toml
  49. +28
    -0
      space-crush-server/log4rs.yml
  50. +3
    -0
      space-crush-server/src/main.rs
  51. バイナリ
     
  52. +0
    -7
      space-crush/src/lib.rs
  53. +0
    -7
      space-crush/src/misc/mod.rs

+ 33
- 169
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",


+ 7
- 3
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" }

space-crush/Cargo.toml → space-crush-app/Cargo.toml ファイルの表示

@@ -1,28 +1,29 @@
[package]
name = "space-crush"
name = "space-crush-app"
version = "0.1.0"
authors = ["Bergmann89 <info@bergmann89.de>"]
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"

space-crush/config.json → space-crush-app/config.json ファイルの表示


space-crush/log4rs.yml → space-crush-app/log4rs.yml ファイルの表示


space-crush/resources/fonts/DroidSansMono.ttf → space-crush-app/resources/fonts/DroidSansMono.ttf ファイルの表示


space-crush/resources/shader/noise.frag → space-crush-app/resources/shader/noise.frag ファイルの表示


space-crush/resources/shader/noise.vert → space-crush-app/resources/shader/noise.vert ファイルの表示


space-crush/resources/shader/quad.frag → space-crush-app/resources/shader/quad.frag ファイルの表示


space-crush/resources/shader/quad.vert → space-crush-app/resources/shader/quad.vert ファイルの表示


space-crush/resources/shader/text.frag → space-crush-app/resources/shader/text.frag ファイルの表示


space-crush/resources/shader/text.vert → space-crush-app/resources/shader/text.vert ファイルの表示


バイナリ
ファイルの表示


space-crush/src/misc/error.rs → 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<IoError> for Error {
}
}

impl From<VfsError> for Error {
fn from(err: VfsError) -> Self {
Self::VfsError(err)
}
}

impl From<VfsZipError> for Error {
fn from(err: VfsZipError) -> Self {
Self::VfsZipError(err)
}
}

impl From<JsonError> for Error {
fn from(err: JsonError) -> Self {
Self::JsonError(err)
}
}

impl From<YamlError> for Error {
fn from(err: YamlError) -> Self {
Self::YamlError(err)
}
}

impl From<GlcError> for Error {
fn from(err: GlcError) -> Self {
Self::GlcError(err)
@@ -104,3 +78,15 @@ impl From<InvalidFont> for Error {
Self::InvalidFont(err)
}
}

impl From<VfsError> for Error {
fn from(err: VfsError) -> Self {
Self::VfsError(err)
}
}

impl From<CommonError> for Error {
fn from(err: CommonError) -> Self {
Self::CommonError(err)
}
}

space-crush/src/app/mod.rs → 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};

space-crush/src/main.rs → 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)?;
}


space-crush/src/app/misc/events.rs → space-crush-app/src/misc/events.rs ファイルの表示


space-crush/src/app/misc/mod.rs → space-crush-app/src/misc/mod.rs ファイルの表示


space-crush/src/app/misc/text.rs → 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 */


space-crush/src/app/misc/window.rs → space-crush-app/src/misc/window.rs ファイルの表示


space-crush/src/app/misc/world.rs → 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<R>(&self) -> Result<Fetch<R>, Error>
where
R: Resource;

fn resource_mut<R>(&self) -> Result<FetchMut<R>, Error>
where
R: Resource;

fn register_event_reader<E>(&self) -> Result<ReaderId<E>, Error>
where
E: Event;

fn load_program<I>(&self, iter: I) -> Result<Program, Error>
where
I: IntoIterator<Item = (Type, &'static str)>;
@@ -32,29 +18,6 @@ pub trait WorldHelper {
}

impl WorldHelper for World {
fn resource<R>(&self) -> Result<Fetch<R>, Error>
where
R: Resource,
{
self.try_fetch::<R>()
.ok_or_else(|| Error::ResourceNotRegistered(type_name::<R>()))
}

fn resource_mut<R>(&self) -> Result<FetchMut<R>, Error>
where
R: Resource,
{
self.try_fetch_mut::<R>()
.ok_or_else(|| Error::ResourceNotRegistered(type_name::<R>()))
}

fn register_event_reader<E>(&self) -> Result<ReaderId<E>, Error>
where
E: Event,
{
Ok(self.resource_mut::<EventChannel<E>>()?.register_reader())
}

fn load_program<I>(&self, iter: I) -> Result<Program, Error>
where
I: IntoIterator<Item = (Type, &'static str)>,
@@ -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)
}

space-crush/src/app/render/debug.rs → 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 */

space-crush/src/app/render/init.rs → 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 {

space-crush/src/app/render/mod.rs → space-crush-app/src/render/mod.rs ファイルの表示


space-crush/src/app/render/test.rs → 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::<Camera>()?.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);
}
}

space-crush/src/app/resources/camera.rs → space-crush-app/src/resources/camera.rs ファイルの表示


space-crush/src/app/resources/config.rs → 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 {

space-crush/src/app/resources/geometry.rs → space-crush-app/src/resources/geometry.rs ファイルの表示


space-crush/src/app/resources/mod.rs → space-crush-app/src/resources/mod.rs ファイルの表示


space-crush/src/app/resources/state.rs → space-crush-app/src/resources/state.rs ファイルの表示


space-crush/src/app/systems/mod.rs → space-crush-app/src/systems/mod.rs ファイルの表示


space-crush/src/app/systems/state_update.rs → 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 {

+ 28
- 0
space-crush-common/Cargo.toml ファイルの表示

@@ -0,0 +1,28 @@
[package]
name = "space-crush-common"
version = "0.1.0"
authors = ["Bergmann89 <info@bergmann89.de>"]
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"

+ 3
- 0
space-crush-common/src/components/mod.rs ファイルの表示

@@ -0,0 +1,3 @@
mod position;

pub use position::Position;

+ 24
- 0
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<Self>;
}

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
}
}

+ 24
- 0
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<Self>;
}

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
}
}

space-crush/src/server/mod.rs → 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());


+ 51
- 0
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<IoError> for Error {
fn from(err: IoError) -> Self {
Self::IoError(err)
}
}

impl From<VfsError> for Error {
fn from(err: VfsError) -> Self {
Self::VfsError(err)
}
}

impl From<VfsZipError> for Error {
fn from(err: VfsZipError) -> Self {
Self::VfsZipError(err)
}
}

impl From<YamlError> for Error {
fn from(err: YamlError) -> Self {
Self::YamlError(err)
}
}

+ 9
- 0
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;

space-crush/src/misc/log.rs → 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<Config, Error> {
fn load_from_file(vfs: &Vfs, path: &str) -> Result<Config, Error> {
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::<RawConfig>(&config)?;

+ 7
- 0
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;

space-crush/src/misc/vfs.rs → 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<PathBuf>,
}

impl Vfs {
pub fn new() -> Result<Self, Error> {
pub fn new(dirs: &[&str]) -> Result<Self, Error> {
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
}
}

+ 46
- 0
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<R>(&self) -> Result<Fetch<R>, Error>
where
R: Resource;

fn resource_mut<R>(&self) -> Result<FetchMut<R>, Error>
where
R: Resource;

fn register_event_reader<E>(&self) -> Result<ReaderId<E>, Error>
where
E: Event;
}

impl WorldHelper for World {
fn resource<R>(&self) -> Result<Fetch<R>, Error>
where
R: Resource,
{
self.try_fetch::<R>()
.ok_or_else(|| Error::ResourceNotRegistered(type_name::<R>()))
}

fn resource_mut<R>(&self) -> Result<FetchMut<R>, Error>
where
R: Resource,
{
self.try_fetch_mut::<R>()
.ok_or_else(|| Error::ResourceNotRegistered(type_name::<R>()))
}

fn register_event_reader<E>(&self) -> Result<ReaderId<E>, Error>
where
E: Event,
{
Ok(self.resource_mut::<EventChannel<E>>()?.register_reader())
}
}

space-crush/src/server/resources/global.rs → space-crush-common/src/resources/global.rs ファイルの表示


space-crush/src/server/resources/mod.rs → space-crush-common/src/resources/mod.rs ファイルの表示


space-crush/src/server/systems/mod.rs → space-crush-common/src/systems/mod.rs ファイルの表示


space-crush/src/server/systems/process.rs → space-crush-common/src/systems/process.rs ファイルの表示


+ 28
- 0
space-crush-server/Cargo.toml ファイルの表示

@@ -0,0 +1,28 @@
[package]
name = "space-crush-server"
version = "0.1.0"
authors = ["Bergmann89 <info@bergmann89.de>"]
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"

+ 28
- 0
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

+ 3
- 0
space-crush-server/src/main.rs ファイルの表示

@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

バイナリ
ファイルの表示


+ 0
- 7
space-crush/src/lib.rs ファイルの表示

@@ -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;

+ 0
- 7
space-crush/src/misc/mod.rs ファイルの表示

@@ -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;

読み込み中…
キャンセル
保存