rstnode: restructure project into workspace and sub-crates

wip/yesman
Katharina Fey 3 years ago
parent 56d96b2f22
commit cf9392a33b
Signed by: kookie
GPG Key ID: 90734A9E619C8A6C
  1. 115
      games/rstnode/Cargo.lock
  2. 34
      games/rstnode/Cargo.toml
  3. 5
      games/rstnode/assets/logo.svg
  4. 11
      games/rstnode/rst-client/Cargo.toml
  5. 3
      games/rstnode/rst-client/src/main.rs
  6. 29
      games/rstnode/rst-core/Cargo.toml
  7. 0
      games/rstnode/rst-core/src/_if.rs
  8. 7
      games/rstnode/rst-core/src/_loop.rs
  9. 5
      games/rstnode/rst-core/src/_match.rs
  10. 4
      games/rstnode/rst-core/src/bin/game.rs
  11. 5
      games/rstnode/rst-core/src/bin/server.rs
  12. 45
      games/rstnode/rst-core/src/config/io.rs
  13. 17
      games/rstnode/rst-core/src/config/mod.rs
  14. 0
      games/rstnode/rst-core/src/data.rs
  15. 2
      games/rstnode/rst-core/src/gens.rs
  16. 0
      games/rstnode/rst-core/src/io.rs
  17. 39
      games/rstnode/rst-core/src/lib.rs
  18. 0
      games/rstnode/rst-core/src/lobby.rs
  19. 0
      games/rstnode/rst-core/src/map.rs
  20. 0
      games/rstnode/rst-core/src/mapstore.rs
  21. 0
      games/rstnode/rst-core/src/runner.rs
  22. 0
      games/rstnode/rst-core/src/server.rs
  23. 0
      games/rstnode/rst-core/src/stats.rs
  24. 0
      games/rstnode/rst-core/src/users.rs
  25. 2
      games/rstnode/rst-core/src/wire/action.rs
  26. 2
      games/rstnode/rst-core/src/wire/mod.rs
  27. 5
      games/rstnode/rst-core/src/wire/req.rs
  28. 2
      games/rstnode/rst-core/src/wire/resp.rs
  29. 0
      games/rstnode/rst-core/src/wire/update.rs
  30. 9
      games/rstnode/rst-launcher/Cargo.toml
  31. 3
      games/rstnode/rst-launcher/src/main.rs
  32. 10
      games/rstnode/rst-server/Cargo.toml
  33. 3
      games/rstnode/rst-server/src/main.rs
  34. 4
      games/rstnode/shell.nix
  35. 24
      games/rstnode/src/lib.rs

@ -27,7 +27,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f823d037a7ec6ea2197046bafd4ae150e6bc36f9ca347404f46a46823fa84f2"
dependencies = [
"approx 0.3.2",
"approx",
"num-complex",
"num-traits 0.2.14",
]
@ -71,15 +71,6 @@ dependencies = [
"num-traits 0.2.14",
]
[[package]]
name = "approx"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
dependencies = [
"num-traits 0.2.14",
]
[[package]]
name = "arrayref"
version = "0.3.6"
@ -289,9 +280,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.5.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f07aa6688c702439a1be0307b6a94dffe1168569e45b9500c1372bc580740d59"
checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9"
[[package]]
name = "byte-tools"
@ -323,9 +314,9 @@ dependencies = [
[[package]]
name = "bzip2-sys"
version = "0.1.9+1.0.8"
version = "0.1.10+1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad3b39a260062fca31f7b0b12f207e8f2590a67d32ec7d59c20484b07ea7285e"
checksum = "17fa3d1ac1ca21c5c4e36a97f3c3eb25084576f6fc47bf0139c1123434216c6c"
dependencies = [
"cc",
"libc",
@ -381,17 +372,6 @@ dependencies = [
"libc",
]
[[package]]
name = "cgmath"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"
dependencies = [
"approx 0.4.0",
"mint",
"num-traits 0.2.14",
]
[[package]]
name = "chrono"
version = "0.4.19"
@ -648,9 +628,9 @@ dependencies = [
[[package]]
name = "ctor"
version = "0.1.18"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10bcb9d7dcbf7002aaffbb53eac22906b64cdcc127971dcc387d8eb7c95d5560"
checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19"
dependencies = [
"quote 1.0.8",
"syn 1.0.60",
@ -786,6 +766,12 @@ dependencies = [
"bitflags",
]
[[package]]
name = "dtoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e"
[[package]]
name = "error-chain"
version = "0.12.4"
@ -1069,7 +1055,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a76347431050a0b4e1a925124cdcde614b628260093bb52560d9c6b48435336"
dependencies = [
"approx 0.3.2",
"approx",
"bitflags",
"directories",
"gfx",
@ -1274,7 +1260,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b70adc570f1dc71b6b32e241cbcc2b42175f5aea71951fbf41e68b04aec24c7"
dependencies = [
"approx 0.3.2",
"approx",
"rusttype 0.8.3",
"xi-unicode",
]
@ -1380,9 +1366,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "jpeg-decoder"
version = "0.1.21"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6187dc218616c3a222bae7b78938f5af5e7c27d9cbef4c30ebca709cd680bf8"
checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
[[package]]
name = "kernel32-sys"
@ -1434,9 +1420,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.84"
version = "0.2.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff"
checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"
[[package]]
name = "libloading"
@ -1715,7 +1701,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaa9fddbc34c8c35dd2108515587b8ce0cab396f17977b8c738568e4edb521a2"
dependencies = [
"alga",
"approx 0.3.2",
"approx",
"generic-array 0.12.3",
"matrixmultiply",
"mint",
@ -2511,22 +2497,40 @@ dependencies = [
]
[[package]]
name = "rstnode"
name = "rst-core"
version = "0.0.0"
dependencies = [
"async-std",
"async-trait",
"cgmath",
"bincode",
"chrono",
"const_env",
"ggez",
"netmod-mem",
"quadtree_rs",
"rand 0.7.3",
"ratman",
"ratman-identity 0.4.0",
"serde",
"serde_json",
"serde_yaml",
]
[[package]]
name = "rst-launcher"
version = "0.1.0"
[[package]]
name = "rst-node-client"
version = "0.0.0"
dependencies = [
"ggez",
"rst-core",
]
[[package]]
name = "rst-node-server"
version = "0.0.0"
dependencies = [
"rst-core",
]
[[package]]
@ -2577,7 +2581,7 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f61411055101f7b60ecf1041d87fb74205fb20b0c7a723f07ef39174cf6b4c0"
dependencies = [
"approx 0.3.2",
"approx",
"crossbeam-deque",
"crossbeam-utils 0.7.2",
"linked-hash-map",
@ -2657,15 +2661,27 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.61"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a"
checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdd2af560da3c1fdc02cb80965289254fc35dff869810061e2d8290ee48848ae"
dependencies = [
"dtoa",
"linked-hash-map",
"serde",
"yaml-rust",
]
[[package]]
name = "sha1"
version = "0.6.0"
@ -2957,9 +2973,9 @@ dependencies = [
[[package]]
name = "tracing"
version = "0.1.22"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3"
checksum = "f7d40a22fd029e33300d8d89a5cc8ffce18bb7c587662f54629e94c9de5487f3"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite 0.2.4",
@ -2969,9 +2985,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.11"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada"
checksum = "43f080ea7e4107844ef4766459426fa2d5c1ada2e47edba05dc7fa99d9629f47"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.8",
@ -3303,6 +3319,15 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
[[package]]
name = "zip"
version = "0.5.9"

@ -1,27 +1,11 @@
[package]
name = "rstnode"
description = "A game about capturing computers on a network"
version = "0.0.0"
edition = "2018"
license = "AGPL-3.0-or-later"
authors = ["Bread Machine", "Katharina Fey <kookie@spacekookie.de>"]
[workspace]
members = [
"rst-core",
[dependencies]
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
async-std = { version = "1.0", features = ["unstable"] }
async-trait = "0.1"
"rst-launcher",
"rst-client",
"rst-server",
]
ratman = "0.1"
netmod-mem = "0.1.0"
identity = { version = "0.4", features = ["random"], package = "ratman-identity"}
ggez = "0.5"
cgmath = { version = "*", features = ["mint"] }
chrono = { version = "0.4", features = ["serde"] }
rand = "0.7"
quadtree_rs = "0.1"
const_env = "0.1"
[profile.release.overrides."*"]
opt-level = 3
# [profile.release.overrides."*"]
# opt-level = 3

@ -13,7 +13,10 @@
version="1.1"
id="svg8"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"
sodipodi:docname="logo.svg">
sodipodi:docname="logo.svg"
inkscape:export-filename="/home/Projects/kookienomicon/games/rstnode/assets/logo.png"
inkscape:export-xdpi="200.07384"
inkscape:export-ydpi="200.07384">
<defs
id="defs2" />
<sodipodi:namedview

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

@ -0,0 +1,11 @@
[package]
name = "rst-node-client"
description = "RST Node game client"
version = "0.0.0"
edition = "2018"
license = "AGPL-3.0-or-later"
authors = ["Bread Machine", "Katharina Fey <kookie@spacekookie.de>"]
[dependencies]
rst-core = { path = "../rst-core" }
ggez = "0.5"

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

@ -0,0 +1,29 @@
[package]
name = "rst-core"
description = "Shared logic and type state library for rstnode"
version = "0.0.0"
edition = "2018"
license = "AGPL-3.0-or-later"
authors = ["Bread Machine", "Katharina Fey <kookie@spacekookie.de>"]
[dependencies]
# Serialisation
bincode = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
serde_yaml = "0.8.15"
# Async utils
async-std = { version = "1.0", features = ["unstable"] }
async-trait = "0.1"
# Ratman networking utils
identity = { version = "0.4", features = ["random"], package = "ratman-identity"}
netmod-mem = "0.1.0"
ratman = "0.1"
# Other dependencies
chrono = { version = "0.4", features = ["serde"] }
const_env = "0.1"
quadtree_rs = "0.1"
rand = "0.7"

@ -1,4 +1,7 @@
//! A timed loop implementation
//!
//! This is a utility to be used in the server simulation to make sure
//! that a simulation step takes a certain amount of time to execute.
use async_std::{future::Future, task};
use chrono::{DateTime, Utc};
@ -16,7 +19,7 @@ const TICKS: u64 = 100;
const TICK_TIME: Duration = Duration::from_millis(1000 / TICKS);
/// Run a timed loop until you no longer want to
pub fn block_loop<F>(run: Arc<AtomicBool>, f: F)
pub(crate) fn block_loop<F>(run: Arc<AtomicBool>, f: F)
where
F: Future<Output = ()> + Send + Copy + 'static,
{
@ -30,7 +33,7 @@ where
}
/// Run a detached timed loop until you no longer want to
pub fn spawn_loop<F>(run: Arc<AtomicBool>, f: F)
pub(crate) fn spawn_loop<F>(run: Arc<AtomicBool>, f: F)
where
F: Future<Output = ()> + Send + Copy + 'static,
{

@ -10,6 +10,11 @@ use serde::{Deserialize, Serialize};
use std::collections::VecDeque;
/// Describes a match for the server
///
/// This type implements the partial [GameIf](crate::GameIf) API to
/// allow client to queue commands from players. The server
/// implementation runs a simulation for each match that is running on
/// it.
pub struct Match {
/// The match id
pub id: MatchId,

@ -1,5 +1,3 @@
//! The main game UI client
fn main() {
}
fn main() {}

@ -1,6 +1,3 @@
//! The dedicated server binary
fn main() {
}
fn main() {}

@ -0,0 +1,45 @@
//! I/O utilities to load configurations from disk
use super::MapCfg;
use serde_yaml::from_str;
use std::{
fs::File,
io::{self, Read},
path::Path,
};
/// Encode error state while loading a map configuration
pub enum Error {
Io(String),
Parsing(String),
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Self::Io(e.to_string())
}
}
impl From<serde_yaml::Error> for Error {
fn from(e: serde_yaml::Error) -> Self {
Self::Parsing(e.to_string())
}
}
/// Load a map YAML configuration from disk
///
/// This file format is structured according to the configuration
/// types in [config](crate::config). An example configuration is
/// provided below.
///
/// ```yaml
/// nodes:
/// -
/// ```
pub fn load_map<'p>(p: impl Into<&'p Path>) -> Result<MapCfg, Error> {
let mut f = File::open(p.into())?;
let mut s = String::new();
f.read_to_string(&mut s)?;
Ok(from_str(s.as_str())?)
}

@ -1,8 +1,14 @@
//! The file formats backing maps and other configs
//!
//! When creating maps to share with other clients, or to load into a
//! server, these types can be constructed with the YML description
//! format, outlined in [load_map](config::io::load_map)
use crate::data::{NodeId, LinkId};
use serde::{Serialize, Deserialize};
use std::path::Path;
mod io;
pub use io::*;
use crate::data::{LinkId, NodeId};
use serde::{Deserialize, Serialize};
/// A config tree that describes a map
#[derive(Serialize, Deserialize)]
@ -15,6 +21,7 @@ pub struct MapCfg {
pub spawns: Vec<SpawnCfg>,
}
/// A single node on a map, with an x and y coordinate
#[derive(Serialize, Deserialize)]
pub struct NodeCfg {
/// Node ID
@ -24,14 +31,16 @@ pub struct NodeCfg {
pub y: f64,
}
/// A link between two nodes
#[derive(Serialize, Deserialize)]
pub struct LinkCfg {
/// The link ID
id: LinkId,
/// List of connectioned nodes
con: Vec<NodeId>,
con: (NodeId, NodeId),
}
/// Special configuration for a node to act as a player spawn point
#[derive(Serialize, Deserialize)]
pub struct SpawnCfg {
/// The node of the spawn point

@ -84,7 +84,7 @@ pub mod send {
// Only level 3 guards can send takeovers
(None, Guard(Three), "takeover") => Pkt::TakeOver,
// Can't touch this
(_, _, _) => unreachable!(),
}

@ -0,0 +1,39 @@
//! # RST Node
//!
//! RST Node is a real-time strategy game about computers on a
//! network, fighting for dominance against a set of other network
//! operators. To operate a successful network you need to build
//! infrastructure, compute clusters, and defences on edge nodes.
//!
//! The game architecture is split between the game client and game
//! server. This library implements all required types and functions
//! to manage this state over a network connection.
//!
//! The main game interface is provided by [GameIf](crate::GameIf),
//! which is them implemented by [Server](crate::server::Server), and
//! [MatchClient](crate::client::MatchClient).
#[macro_use]
extern crate const_env;
pub(crate) mod _loop;
mod _if;
pub use _if::GameIf;
mod _match;
pub use _match::Match;
pub mod config;
pub mod data;
pub mod gens;
pub mod io;
pub mod lobby;
pub mod map;
pub mod mapstore;
pub mod server;
pub mod stats;
pub mod users;
pub mod wire;
pub use identity::Identity as Id;

@ -1,5 +1,5 @@
use crate::data::{NodeId, Upgrade};
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
/// All actions that a user can trigger via the UI
#[derive(Serialize, Deserialize)]

@ -66,5 +66,3 @@ pub struct Lobby {
/// An alias for a match ID
pub type MatchId = usize;

@ -1,5 +1,4 @@
use super::{action::Action, User, LobbyId, MatchId};
use super::{action::Action, LobbyId, MatchId, User};
use serde::{Deserialize, Serialize};
/// A message sent from the game client to the server
@ -18,7 +17,7 @@ pub enum Request {
/// Start an anonymous session
Anonymous(String),
/// A user joins a game lobby
Join(User, LobbyId),

@ -90,5 +90,5 @@ pub enum MatchErr {
/// The provided player wasn't in the match (anymore?)
NotInMatch,
/// The requested match had already ended
MatchAlreadyEnded
MatchAlreadyEnded,
}

@ -0,0 +1,9 @@
[package]
name = "rst-launcher"
version = "0.1.0"
authors = ["Katharina Fey <kookie@spacekookie.de>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

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

@ -0,0 +1,10 @@
[package]
name = "rst-node-server"
description = "Backend game server"
version = "0.0.0"
edition = "2018"
license = "AGPL-3.0-or-later"
authors = ["Bread Machine", "Katharina Fey <kookie@spacekookie.de>"]
[dependencies]
rst-core = { path = "../rst-core" }

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

@ -3,8 +3,8 @@ with import <nixpkgs> {};
stdenv.mkDerivation {
name = "rstnode";
buildInputs = with pkgs; [
rustc cargo clangStdenv stdenv rust-analyzer
alsaLib pkg-config libudev steam-run
rustc cargo clangStdenv rust-analyzer rustfmt
alsaLib pkg-config libudev
] ++ (with pkgs.xlibs; [
libGL
libGLU

@ -1,24 +0,0 @@
#![allow(warnings)]
#[macro_use]
extern crate const_env;
mod _if;
pub use _if::GameIf;
pub mod data;
pub mod gens;
pub mod _loop;
pub mod _match;
pub mod config;
pub mod io;
pub mod lobby;
pub mod map;
pub mod mapstore;
pub mod server;
pub mod stats;
pub mod users;
pub mod wire;
pub use identity::Identity as Id;
Loading…
Cancel
Save