mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Initial structure
This commit is contained in:
parent
7d17f8b67a
commit
819af1594f
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"common",
|
||||
"client",
|
||||
"server",
|
||||
]
|
||||
|
||||
[profile.dev]
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
3
client/.gitignore
vendored
Normal file
3
client/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
10
client/Cargo.toml
Normal file
10
client/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "veloren-client"
|
||||
version = "0.1.0"
|
||||
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
|
||||
specs = "0.14"
|
49
client/src/lib.rs
Normal file
49
client/src/lib.rs
Normal file
@ -0,0 +1,49 @@
|
||||
// Standard
|
||||
use std::time::Duration;
|
||||
|
||||
// Internal
|
||||
use common::LocalState;
|
||||
|
||||
pub enum ClientErr {
|
||||
ServerShutdown,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
pub struct Input {
|
||||
// TODO: Use this type to manage client input
|
||||
}
|
||||
|
||||
pub struct Client {
|
||||
state: LocalState,
|
||||
|
||||
// TODO: Add "meta" state here
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state: LocalState::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a single client tick, handle input and update the game state by the given duration
|
||||
pub fn tick(&mut self, input: Input, dt: Duration) -> Result<(), ClientErr> {
|
||||
// This tick function is the centre of the Veloren universe. Most client-side things are
|
||||
// managed from here, and as such it's important that it stays organised. Please consult
|
||||
// the core developers before making significant changes to this code. Here is the
|
||||
// approximate order of things. Please update it as this code changes.
|
||||
//
|
||||
// 1) Collect input from the frontend, apply input effects to the state of the game
|
||||
// 2) Go through any events (timer-driven or otherwise) that need handling and apply them
|
||||
// to the state of the game
|
||||
// 3) Perform a single LocalState tick (i.e: update the world and entities in the world)
|
||||
// 4) Go through the terrain update queue and apply all changes to the terrain
|
||||
// 5) Finish the tick, passing control of the main thread back to the frontend
|
||||
|
||||
// Tick the client's LocalState (step 3)
|
||||
self.state.tick(dt);
|
||||
|
||||
// Finish the tick, pass control back to the frontend (step 6)
|
||||
Ok(())
|
||||
}
|
||||
}
|
3
common/.gitignore
vendored
Normal file
3
common/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
8
common/Cargo.toml
Normal file
8
common/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
specs = "0.14"
|
6
common/src/comp/mod.rs
Normal file
6
common/src/comp/mod.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// External
|
||||
use specs::{World as EcsWorld, Builder};
|
||||
|
||||
pub fn register_local_components(ecs_world: &mut EcsWorld) {
|
||||
// TODO: Register local components here
|
||||
}
|
30
common/src/lib.rs
Normal file
30
common/src/lib.rs
Normal file
@ -0,0 +1,30 @@
|
||||
pub mod comp;
|
||||
|
||||
// Standard
|
||||
use std::time::Duration;
|
||||
|
||||
// External
|
||||
use specs::{World as EcsWorld, Builder};
|
||||
|
||||
// A type used to represent game state stored on both the client and the server. This includes
|
||||
// things like entity components, terrain data, and global state like weather, time of day, etc.
|
||||
pub struct LocalState {
|
||||
ecs_world: EcsWorld
|
||||
}
|
||||
|
||||
impl LocalState {
|
||||
pub fn new() -> Self {
|
||||
let mut ecs_world = EcsWorld::new();
|
||||
|
||||
comp::register_local_components(&mut ecs_world);
|
||||
|
||||
Self {
|
||||
ecs_world,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute a single tick, simulating the game state by the given duration
|
||||
pub fn tick(&mut self, dt: Duration) {
|
||||
println!("Ticked!");
|
||||
}
|
||||
}
|
3
server/.gitignore
vendored
Normal file
3
server/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
10
server/Cargo.toml
Normal file
10
server/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "server"
|
||||
version = "0.1.0"
|
||||
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
|
||||
specs = "0.14"
|
51
server/src/lib.rs
Normal file
51
server/src/lib.rs
Normal file
@ -0,0 +1,51 @@
|
||||
// Standard
|
||||
use std::time::Duration;
|
||||
|
||||
// Internal
|
||||
use common::LocalState;
|
||||
|
||||
pub enum ClientErr {
|
||||
ServerShutdown,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
pub struct Input {
|
||||
// TODO: Use this type to manage server input
|
||||
}
|
||||
|
||||
pub struct Server {
|
||||
state: LocalState,
|
||||
|
||||
// TODO: Add "meta" state here
|
||||
}
|
||||
|
||||
impl Server {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state: LocalState::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a single server tick, handle input and update the game state by the given duration
|
||||
pub fn tick(&mut self, input: Input, dt: Duration) -> Result<(), ClientErr> {
|
||||
// This tick function is the centre of the Veloren universe. Most server-side things are
|
||||
// managed from here, and as such it's important that it stays organised. Please consult
|
||||
// the core developers before making significant changes to this code. Here is the
|
||||
// approximate order of things. Please update it as this code changes.
|
||||
//
|
||||
// 1) Collect input from the frontend, apply input effects to the state of the game
|
||||
// 2) Go through any events (timer-driven or otherwise) that need handling and apply them
|
||||
// to the state of the game
|
||||
// 3) Go through all incoming client network communications, apply them to the game state
|
||||
// 4) Perform a single LocalState tick (i.e: update the world and entities in the world)
|
||||
// 5) Go through the terrain update queue and apply all changes to the terrain
|
||||
// 6) Send relevant state updates to all clients
|
||||
// 7) Finish the tick, passing control of the main thread back to the frontend
|
||||
|
||||
// Tick the client's LocalState (step 3)
|
||||
self.state.tick(dt);
|
||||
|
||||
// Finish the tick, pass control back to the frontend (step 6)
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user