Move to legion ES

This commit is contained in:
Hamcha 2020-10-01 14:01:03 +02:00
parent 53215ba83c
commit 3f64620c3f
Signed by: hamcha
GPG key ID: 41467804B19A3315
11 changed files with 240 additions and 149 deletions

311
Cargo.lock generated
View file

@ -1,11 +1,5 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "ahash"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.13" version = "0.7.13"
@ -27,12 +21,6 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]]
name = "atom"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c86699c3f02778ec07158376991c8f783dd1f2f95c579ffaf0738dc984b2fe2"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.0.1" version = "1.0.1"
@ -45,6 +33,21 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "bit-set"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.2.1" version = "1.2.1"
@ -60,6 +63,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "bytemuck"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41aa2ec95ca3b5c54cf73c91acf06d24f4495d5f1b1c12506ae3483d646177ac"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
version = "1.3.4" version = "1.3.4"
@ -84,6 +93,15 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "config" name = "config"
version = "0.10.1" version = "0.10.1"
@ -158,17 +176,6 @@ dependencies = [
"scopeguard", "scopeguard",
] ]
[[package]]
name = "crossbeam-queue"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570"
dependencies = [
"cfg-if",
"crossbeam-utils",
"maybe-uninit",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.7.2" version = "0.7.2"
@ -180,6 +187,17 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "derivative"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.9.0" version = "0.9.0"
@ -189,12 +207,27 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "downcast-rs"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]] [[package]]
name = "either" name = "either"
version = "1.6.1" version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "erased-serde"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ca8b296792113e1500fd935ae487be6e00ce318952a6880555554824d6ebf38"
dependencies = [
"serde 1.0.116",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -288,16 +321,6 @@ dependencies = [
"wasi", "wasi",
] ]
[[package]]
name = "hashbrown"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf"
dependencies = [
"ahash",
"autocfg",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.16" version = "0.1.16"
@ -307,16 +330,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hibitset"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93a1bb8316a44459a7d14253c4d28dd7395cbd23cc04a68c46e851b8e46d64b1"
dependencies = [
"atom",
"rayon",
]
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.1" version = "0.2.1"
@ -354,6 +367,15 @@ dependencies = [
"bytes", "bytes",
] ]
[[package]]
name = "instant"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "iovec" name = "iovec"
version = "0.1.4" version = "0.1.4"
@ -363,6 +385,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.6" version = "0.4.6"
@ -385,6 +416,40 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "legion"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aa40f1a5f64dfdc1830657e0e7dd2c28087c4e32a2a85fcf63a286c429edefc"
dependencies = [
"bit-set",
"crossbeam-channel",
"derivative",
"downcast-rs",
"erased-serde",
"itertools",
"legion_codegen",
"parking_lot",
"paste",
"rayon",
"serde 1.0.116",
"smallvec",
"thiserror",
"uuid",
]
[[package]]
name = "legion_codegen"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c24e58060e656eae6b87f83f14f41080656a930fba7ef299122e40eb8ccd307f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"thiserror",
]
[[package]] [[package]]
name = "lexical-core" name = "lexical-core"
version = "0.7.4" version = "0.7.4"
@ -420,6 +485,15 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
[[package]]
name = "lock_api"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c"
dependencies = [
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.11" version = "0.4.11"
@ -520,12 +594,6 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "mopa"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a785740271256c230f57462d3b83e52f998433a7062fc18f96d5999474a9f915"
[[package]] [[package]]
name = "native-tls" name = "native-tls"
version = "0.2.4" version = "0.2.4"
@ -600,13 +668,14 @@ version = "0.1.0"
dependencies = [ dependencies = [
"config", "config",
"futures-util", "futures-util",
"legion",
"log", "log",
"serde 1.0.116", "serde 1.0.116",
"serde_derive", "serde_derive",
"specs",
"tokio", "tokio",
"tokio-tungstenite", "tokio-tungstenite",
"tungstenite", "tungstenite",
"ultraviolet",
] ]
[[package]] [[package]]
@ -654,6 +723,38 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "parking_lot"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
dependencies = [
"cfg-if",
"cloudabi",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi 0.3.9",
]
[[package]]
name = "paste"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0520af26d4cf99643dbbe093a61507922b57232d9978d8491fdc8f7b44573c8c"
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.1.0" version = "2.1.0"
@ -833,6 +934,15 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "safe_arch"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ff3d6d9696af502cc3110dacce942840fb06ff4514cad92236ecc455f2ce05"
dependencies = [
"bytemuck",
]
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.19" version = "0.1.19"
@ -944,26 +1054,6 @@ dependencies = [
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "shred"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5f08237e667ac94ad20f8878b5943d91a93ccb231428446c57c21c57779016d"
dependencies = [
"arrayvec",
"hashbrown",
"mopa",
"rayon",
"smallvec",
"tynm",
]
[[package]]
name = "shrev"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5752e017e03af9d735b4b069f53b7a7fd90fefafa04d8bd0c25581b0bff437f"
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.2.1" version = "1.2.1"
@ -998,22 +1088,6 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "specs"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fff28a29366aff703d5da8a7e2c8875dc8453ac1118f842cbc0fa70c7db51240"
dependencies = [
"crossbeam-queue",
"hashbrown",
"hibitset",
"log",
"rayon",
"shred",
"shrev",
"tuple_utils",
]
[[package]] [[package]]
name = "static_assertions" name = "static_assertions"
version = "1.1.0" version = "1.1.0"
@ -1045,6 +1119,26 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "thiserror"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.0.1" version = "1.0.1"
@ -1137,27 +1231,22 @@ dependencies = [
"utf-8", "utf-8",
] ]
[[package]]
name = "tuple_utils"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44834418e2c5b16f47bedf35c28e148db099187dd5feee6367fb2525863af4f1"
[[package]]
name = "tynm"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "367fb781963961b4a90a3362c54b1871caaecb081f011005778242230f39d34e"
dependencies = [
"nom",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.12.0" version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
name = "ultraviolet"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a6e176b3263890c808bb808f425ac1f6295fe2ae16425a9bf812be29b713d8e"
dependencies = [
"serde 1.0.116",
"wide",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.4" version = "0.3.4"
@ -1199,6 +1288,16 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
[[package]]
name = "uuid"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
dependencies = [
"rand",
"serde 1.0.116",
]
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.10" version = "0.2.10"
@ -1217,6 +1316,16 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wide"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80b27c76ecc22bd81fe681d9c9eac81e002d7b7048105ee4608f57c4e92e9211"
dependencies = [
"bytemuck",
"safe_arch",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.2.8" version = "0.2.8"

View file

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
tungstenite = "0.11" tungstenite = "0.11"
specs = "0.16" legion = "0.3"
config = "0.10" config = "0.10"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_derive = "1" serde_derive = "1"
@ -14,3 +14,4 @@ tokio = { version = "0.2", features = ["full"] }
tokio-tungstenite = "0.11" tokio-tungstenite = "0.11"
futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] } futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] }
log = "0.4" log = "0.4"
ultraviolet = { version = "0.7", features = [ "f64", "int", "serde" ] }

View file

@ -1,3 +1,2 @@
pub mod math;
pub mod transform; pub mod transform;
pub mod viewport;

View file

@ -0,0 +1,9 @@
use ultraviolet::Vec2;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Transform {
pub chunk_id: (u16, u16),
pub position: Vec2,
pub rotation: f32,
pub scale: Vec2,
}

View file

@ -0,0 +1,8 @@
use ultraviolet::Vec2;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Viewport {
pub chunk_id: (u16, u16),
pub position: Vec2,
pub size: Vec2,
}

View file

@ -1,2 +0,0 @@
#[derive(Debug)]
pub struct Point(f32, f32);

View file

@ -1,13 +0,0 @@
use super::math::Point;
use specs::{Component, VecStorage};
#[derive(Debug)]
pub struct Transform {
pub position: Point,
pub rotation: f32,
pub scale: Point,
}
impl Component for Transform {
type Storage = VecStorage<Self>;
}

View file

@ -1,3 +0,0 @@
pub mod world;
pub mod components;

View file

@ -1,20 +0,0 @@
use specs::prelude::*;
use super::components::transform::Transform;
pub struct GameWorld {
pub world: World,
}
impl GameWorld {
pub fn new() -> Self {
let mut world = World::new();
world.register::<Transform>();
GameWorld { world }
}
pub fn dispatcher(self) -> specs::AsyncDispatcher<'static, World> {
DispatcherBuilder::new().build_async(self.world)
}
}

View file

@ -1,20 +1,22 @@
mod components;
mod config; mod config;
mod game; mod systems;
use crate::config::Settings; use crate::config::Settings;
use crate::game::world::GameWorld;
use futures_util::StreamExt; use futures_util::StreamExt;
use legion::*;
use log::info; use log::info;
use std::io::Error; use std::io::Error;
use tokio::net::{TcpListener, TcpStream}; use tokio::net::{TcpListener, TcpStream};
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Error> { async fn main() -> Result<(), Error> {
let world = GameWorld::new();
let mut dispatcher = world.dispatcher();
dispatcher.dispatch();
let settings = Settings::new().unwrap(); let settings = Settings::new().unwrap();
let mut world = World::default();
let mut schedule = Schedule::builder().build();
let mut resources = legion::Resources::default();
// Create the event loop and TCP listener we'll accept connections on. // Create the event loop and TCP listener we'll accept connections on.
let try_socket = TcpListener::bind(&settings.bind).await; let try_socket = TcpListener::bind(&settings.bind).await;
let mut listener = try_socket.expect("Failed to bind"); let mut listener = try_socket.expect("Failed to bind");
@ -24,7 +26,7 @@ async fn main() -> Result<(), Error> {
tokio::spawn(accept_connection(stream)); tokio::spawn(accept_connection(stream));
} }
dispatcher.wait(); schedule.execute(&mut world, &mut resources);
Ok(()) Ok(())
} }

1
src/systems/mod.rs Normal file
View file

@ -0,0 +1 @@