mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add basic singleplayer support
Former-commit-id: 929b05faca5d2b95a96349dfc17a62b3165289a1
This commit is contained in:
parent
786dc16092
commit
7ec6e09332
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1960,6 +1960,7 @@ dependencies = [
|
|||||||
"vek 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"vek 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"veloren-client 0.2.0",
|
"veloren-client 0.2.0",
|
||||||
"veloren-common 0.2.0",
|
"veloren-common 0.2.0",
|
||||||
|
"veloren-server 0.2.0",
|
||||||
"winit 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winit 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
1
voxygen/.gitignore
vendored
1
voxygen/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
settings.toml
|
||||||
|
@ -12,6 +12,7 @@ default = ["gl"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
common = { package = "veloren-common", path = "../common" }
|
common = { package = "veloren-common", path = "../common" }
|
||||||
client = { package = "veloren-client", path = "../client" }
|
client = { package = "veloren-client", path = "../client" }
|
||||||
|
server = { package = "veloren-server", path = "../server" }
|
||||||
|
|
||||||
# Graphics
|
# Graphics
|
||||||
gfx = "0.17"
|
gfx = "0.17"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
mod client_init;
|
mod client_init;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
mod singleplayer;
|
||||||
|
|
||||||
use super::char_selection::CharSelectionState;
|
use super::char_selection::CharSelectionState;
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -9,6 +10,7 @@ use crate::{
|
|||||||
use client_init::{ClientInit, Error as InitError};
|
use client_init::{ClientInit, Error as InitError};
|
||||||
use common::{clock::Clock, comp};
|
use common::{clock::Clock, comp};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::thread;
|
||||||
use ui::{Event as MainMenuEvent, MainMenuUi};
|
use ui::{Event as MainMenuEvent, MainMenuUi};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -100,6 +102,11 @@ impl PlayState for MainMenuState {
|
|||||||
),
|
),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
MainMenuEvent::StartSingleplayer => {
|
||||||
|
thread::spawn(move || {
|
||||||
|
singleplayer::run_server();
|
||||||
|
});
|
||||||
|
}
|
||||||
MainMenuEvent::Quit => return PlayStateResult::Shutdown,
|
MainMenuEvent::Quit => return PlayStateResult::Shutdown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
voxygen/src/menu/main/singleplayer.rs
Normal file
36
voxygen/src/menu/main/singleplayer.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
use log::info;
|
||||||
|
use server::{Input, Event, Server};
|
||||||
|
use common::clock::Clock;
|
||||||
|
|
||||||
|
const TPS: u64 = 30;
|
||||||
|
|
||||||
|
pub fn run_server() {
|
||||||
|
info!("Starting server-cli...");
|
||||||
|
|
||||||
|
// Set up an fps clock
|
||||||
|
let mut clock = Clock::new();
|
||||||
|
|
||||||
|
// Create server
|
||||||
|
let mut server = Server::new()
|
||||||
|
.expect("Failed to create server instance");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let events = server.tick(Input::default(), clock.get_last_delta())
|
||||||
|
.expect("Failed to tick server");
|
||||||
|
|
||||||
|
for event in events {
|
||||||
|
match event {
|
||||||
|
Event::ClientConnected { entity } => info!("Client connected!"),
|
||||||
|
Event::ClientDisconnected { entity } => info!("Client disconnected!"),
|
||||||
|
Event::Chat { entity, msg } => info!("[Client] {}", msg),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up the server after a tick
|
||||||
|
server.cleanup();
|
||||||
|
|
||||||
|
// Wait for the next tick
|
||||||
|
clock.tick(Duration::from_millis(1000 / TPS));
|
||||||
|
}
|
||||||
|
}
|
@ -91,6 +91,7 @@ pub enum Event {
|
|||||||
username: String,
|
username: String,
|
||||||
server_address: String,
|
server_address: String,
|
||||||
},
|
},
|
||||||
|
StartSingleplayer,
|
||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +173,18 @@ impl MainMenuUi {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! singleplayer {
|
||||||
|
() => {
|
||||||
|
self.login_error = None;
|
||||||
|
events.push(Event::StartSingleplayer);
|
||||||
|
events.push(Event::LoginAttempt {
|
||||||
|
username: "singleplayer".to_string(),
|
||||||
|
server_address: "localhost".to_string(),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
|
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
|
||||||
// Username
|
// Username
|
||||||
// TODO: get a lower resolution and cleaner input_bg.png
|
// TODO: get a lower resolution and cleaner input_bg.png
|
||||||
@ -296,7 +309,7 @@ impl MainMenuUi {
|
|||||||
.set(self.ids.singleplayer_button, ui_widgets)
|
.set(self.ids.singleplayer_button, ui_widgets)
|
||||||
.was_clicked()
|
.was_clicked()
|
||||||
{
|
{
|
||||||
login!();
|
singleplayer!();
|
||||||
}
|
}
|
||||||
// Quit
|
// Quit
|
||||||
if Button::image(self.imgs.button)
|
if Button::image(self.imgs.button)
|
||||||
|
Loading…
Reference in New Issue
Block a user