game design and client work

This commit is contained in:
Able 2022-05-05 04:51:01 -05:00
parent ec5c27c260
commit ad3ccf2c26
11 changed files with 421 additions and 25 deletions

242
Cargo.lock generated
View file

@ -10,6 +10,7 @@ dependencies = [
"bevy-discord-presence", "bevy-discord-presence",
"bevy_egui", "bevy_egui",
"bevy_framepace", "bevy_framepace",
"bevy_rapier3d",
"bevy_rhai", "bevy_rhai",
"bevy_screen_diags", "bevy_screen_diags",
"discord-presence", "discord-presence",
@ -809,6 +810,19 @@ dependencies = [
"bytemuck", "bytemuck",
] ]
[[package]]
name = "bevy_rapier3d"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b4b8b9331b8dd730ea00acd211f927ea44ae85d40587f255d4095e0532cef8"
dependencies = [
"bevy",
"bitflags",
"log",
"nalgebra",
"rapier3d",
]
[[package]] [[package]]
name = "bevy_reflect" name = "bevy_reflect"
version = "0.7.0" version = "0.7.0"
@ -1536,6 +1550,20 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "crossbeam"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.4" version = "0.5.4"
@ -1546,6 +1574,41 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
] ]
[[package]]
name = "crossbeam-deque"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-queue"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.8" version = "0.8.8"
@ -1700,6 +1763,12 @@ dependencies = [
"nohash-hasher", "nohash-hasher",
] ]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "emath" name = "emath"
version = "0.18.0" version = "0.18.0"
@ -2223,7 +2292,7 @@ dependencies = [
"byteorder", "byteorder",
"color_quant", "color_quant",
"num-iter", "num-iter",
"num-rational", "num-rational 0.3.2",
"num-traits", "num-traits",
"png", "png",
"scoped_threadpool", "scoped_threadpool",
@ -2435,6 +2504,12 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a"
[[package]]
name = "libm"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db"
[[package]] [[package]]
name = "libspace" name = "libspace"
version = "0.1.0" version = "0.1.0"
@ -2534,6 +2609,15 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "matrixmultiply"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84"
dependencies = [
"rawpointer",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.4.1" version = "2.4.1"
@ -2725,6 +2809,34 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "nalgebra"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a89248335f688e4bd994e6d030fd7e185eb41769b8c435395075425e100ac6"
dependencies = [
"approx",
"glam",
"matrixmultiply",
"nalgebra-macros",
"num-complex",
"num-rational 0.4.0",
"num-traits",
"simba",
"typenum",
]
[[package]]
name = "nalgebra-macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01fcc0b8149b4632adc89ac3b7b31a12fb6099a0317a4eb2ebff574ef7de7218"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "named_pipe" name = "named_pipe"
version = "0.4.1" version = "0.4.1"
@ -2903,6 +3015,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "num-complex"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fbc387afefefd5e9e39493299f3069e14a140dd34dc19b4c1c1a8fddb6a790"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "num-derive" name = "num-derive"
version = "0.3.3" version = "0.3.3"
@ -2946,6 +3067,17 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-rational"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.14" version = "0.2.14"
@ -2953,6 +3085,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm 0.2.2",
] ]
[[package]] [[package]]
@ -3072,6 +3205,12 @@ version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "optional"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978aa494585d3ca4ad74929863093e87cac9790d81fe7aba2b3dc2890643a0fc"
[[package]] [[package]]
name = "owned_ttf_parser" name = "owned_ttf_parser"
version = "0.15.0" version = "0.15.0"
@ -3135,6 +3274,27 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "parry3d"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89cd07f0e1e9e207662f430a4e758c357fdf89450a548ef1ce59113822fd5fa7"
dependencies = [
"approx",
"arrayvec",
"bitflags",
"downcast-rs",
"either",
"nalgebra",
"num-derive",
"num-traits",
"rustc-hash",
"simba",
"slab",
"smallvec",
"spade",
]
[[package]] [[package]]
name = "paste" name = "paste"
version = "1.0.7" version = "1.0.7"
@ -3278,6 +3438,28 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6" checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6"
[[package]]
name = "rapier3d"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "652dc538f3b0b0c1ba75aa3f4bdcac8d5132630bce22efd54a7240bdac33108d"
dependencies = [
"approx",
"arrayvec",
"bit-vec",
"bitflags",
"crossbeam",
"downcast-rs",
"instant",
"nalgebra",
"num-derive",
"num-traits",
"parry3d",
"rustc-hash",
"simba",
"vec_map",
]
[[package]] [[package]]
name = "raw-window-handle" name = "raw-window-handle"
version = "0.4.3" version = "0.4.3"
@ -3287,6 +3469,12 @@ dependencies = [
"cty", "cty",
] ]
[[package]]
name = "rawpointer"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]] [[package]]
name = "rectangle-pack" name = "rectangle-pack"
version = "0.4.2" version = "0.4.2"
@ -3360,6 +3548,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "robust"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5864e7ef1a6b7bcf1d6ca3f655e65e724ed3b52546a0d0a663c991522f552ea"
[[package]] [[package]]
name = "rodio" name = "rodio"
version = "0.15.0" version = "0.15.0"
@ -3422,6 +3616,15 @@ version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "safe_arch"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "794821e4ccb0d9f979512f9c1973480123f9bd62a90d74ab0f9426fcf8f4a529"
dependencies = [
"bytemuck",
]
[[package]] [[package]]
name = "same-file" name = "same-file"
version = "1.0.6" version = "1.0.6"
@ -3566,6 +3769,19 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "simba"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13a2609e876d4f77f6ab7ff5254fc39b4f1927ba8e6db3d18be7c32534d3725e"
dependencies = [
"approx",
"num-complex",
"num-traits",
"paste",
"wide",
]
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.6" version = "0.4.6"
@ -3611,6 +3827,18 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "spade"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "333b8c21ebd9a45c5e955f3d7a1f0c4a2214847dd7e8e1abb69f34ec9b88882d"
dependencies = [
"num-traits",
"optional",
"robust",
"smallvec",
]
[[package]] [[package]]
name = "spin_sleep" name = "spin_sleep"
version = "1.1.1" version = "1.1.1"
@ -3707,7 +3935,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b0dc6d20ce137f302edf90f9cd3d278866fd7fb139efca6f246161222ad6d87" checksum = "7b0dc6d20ce137f302edf90f9cd3d278866fd7fb139efca6f246161222ad6d87"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"libm", "libm 0.1.4",
] ]
[[package]] [[package]]
@ -4241,6 +4469,16 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "wide"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3aba2d1dac31ac7cae82847ac5b8be822aee8f99a4e100f279605016b185c5f"
dependencies = [
"bytemuck",
"safe_arch",
]
[[package]] [[package]]
name = "widestring" name = "widestring"
version = "0.5.1" version = "0.5.1"

View file

@ -5,6 +5,12 @@ edition = "2021"
resolver = "2" resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev.package.bevy_rapier3d]
opt-level = 3
[dependencies] [dependencies]
bevy = { version = "0.7.0", features = ["dynamic"] } bevy = { version = "0.7.0", features = ["dynamic"] }
serde = { version = "1.0.136", features = ["derive"] } serde = { version = "1.0.136", features = ["derive"] }
@ -19,4 +25,5 @@ bevy_egui = "0.14"
egui= "*" egui= "*"
discord-presence = "0.5.0" discord-presence = "0.5.0"
bevy_rapier3d = { version = "*", features = [ "simd-stable", "debug-render" ] }

View file

@ -1,2 +1,2 @@
counter.count += 105; counter.count += 15;
print("Hi"); print("Hi");

View file

@ -5,14 +5,28 @@ pub mod discord;
pub mod species; pub mod species;
pub mod ui; pub mod ui;
// use crate::{computer::ComputerPlugin, discord::DiscordPlugin}; use crate::ui::{diagnosis::diag_ui, UIPlugin};
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
use bevy::prelude::*; use bevy::prelude::*;
use bevy::winit::WinitSettings; use bevy::winit::WinitSettings;
use bevy_egui::EguiPlugin; use bevy_egui::EguiPlugin;
use bevy_framepace::FramepacePlugin; use bevy_framepace::FramepacePlugin;
use bevy_rapier3d::{
na::vector,
plugin::{NoUserData, RapierPhysicsPlugin},
prelude::{Collider, GenericJointBuilder, RapierDebugRenderPlugin, Restitution, RigidBody, *},
rapier::{
math::Point,
prelude::{
ColliderBuilder, ColliderSet, ImpulseJointSet, JointAxesMask, JointAxis,
MultibodyJointSet, RigidBodyBuilder, RigidBodySet,
},
},
};
use libspace::user::generate_user_id; use libspace::user::generate_user_id;
use ui::UIInfo;
use crate::ui::{ use crate::ui::{
client_settings::{client_settings, Settings}, client_settings::{client_settings, Settings},
@ -26,33 +40,82 @@ fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.insert_resource(WinitSettings::game()) .insert_resource(WinitSettings::game())
.insert_resource(Settings::default())
.add_plugin(FramepacePlugin::default().without_warnings()) .add_plugin(FramepacePlugin::default().without_warnings())
.add_plugin(UIPlugin)
// .add_plugin(ComputerPlugin) // Pending: Jordans acceptance // .add_plugin(ComputerPlugin) // Pending: Jordans acceptance
// .add_plugin(DiscordPlugin) // FIXME: Preformance increase, halts game while updating // .add_plugin(DiscordPlugin) // FIXME: Preformance increase, halts game while updating
.add_plugin(EguiPlugin) // .add_startup_system(setup)
.add_system(client_settings) .add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_system(settings_handler) .add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_system(wiki_ui) .add_plugin(RapierDebugRenderPlugin::default())
.add_system(stats_ui) .add_startup_system(setup_graphics)
.add_startup_system(setup_physics)
.add_system(print_ball_altitude)
.add_system(cursor_grab_system)
.run(); .run();
} }
#[derive(Component)] fn cursor_grab_system(
struct EnableText;
fn settings_handler(
mut plugin: ResMut<FramepacePlugin>,
mut windows: ResMut<Windows>, mut windows: ResMut<Windows>,
btn: Res<Input<MouseButton>>,
settings: Res<Settings>, key: Res<Input<KeyCode>>,
mut ui_info: ResMut<UIInfo>,
) { ) {
let window = windows.primary_mut(); let window = windows.get_primary_mut().unwrap();
let cursor_state = window.cursor_locked();
let visibility_state = window.cursor_visible();
plugin.framerate_limit = bevy_framepace::FramerateLimit::Manual(settings.target_fps); if key.just_pressed(KeyCode::Escape) {
use bevy::window::WindowMode::{BorderlessFullscreen, Windowed}; window.set_cursor_lock_mode(!cursor_state);
match settings.fullscreen { window.set_cursor_visibility(!visibility_state);
true => window.set_mode(BorderlessFullscreen), ui_info.mouse_grabbed = !ui_info.mouse_grabbed;
false => window.set_mode(Windowed),
} }
} }
fn setup_graphics(mut commands: Commands) {
// Add a camera so we can see the debug-render.
commands.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(-3.0, 3.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
fn setup_physics(mut commands: Commands) {
/* Create the ground. */
commands
.spawn()
.insert(Collider::cuboid(100.0, 0.1, 100.0))
.insert(Transform::from_xyz(0.0, -2.0, 0.0));
/* Create the bouncing ball. */
commands
.spawn()
.insert(RigidBody::Dynamic)
.insert(Collider::ball(0.5))
.insert(Restitution::coefficient(0.7))
.insert(Transform::from_xyz(0.0, 4.0, 0.0));
commands
.spawn()
.insert(RigidBody::Dynamic)
.insert(Collider::cuboid(1.0, 2.0, 1.0))
.insert(Restitution::coefficient(0.7))
.insert(Transform::from_xyz(0.0, 4.0, 0.0));
let joint = FixedJointBuilder::new().local_anchor1(Vec3::new(0.0, 0.0, -2.0));
/*
commands
.spawn()
.insert(RigidBody::Dynamic)
.insert(ImpulseJoint::new(abc, joint));
*/
}
fn print_ball_altitude(positions: Query<&Transform, With<RigidBody>>) {
for transform in positions.iter() {
// println!("Ball altitude: {}", transform.translation.y);
}
}
fn create_player() {}

View file

@ -0,0 +1,30 @@
pub const FPS: DiagnosticId = DiagnosticId::from_u128(288146834822086093791974408528866909483);
use bevy::{
diagnostic::{DiagnosticId, Diagnostics},
prelude::*,
};
use bevy_egui::EguiContext;
use super::UIInfo;
pub fn diag_ui(
mut egui_context: ResMut<EguiContext>,
ui_info: Res<UIInfo>,
diagnostics: Res<Diagnostics>,
) {
let mut fps_count = 0;
match diagnostics.get_measurement(FPS) {
Some(fps) => {
fps_count = fps.value as u32;
}
None => {}
}
egui::Window::new("Diagnosis").show(egui_context.ctx_mut(), |ui| {
ui.label(format!("FPS: {fps_count}"));
ui.label(format!("Cursor captured: {}", ui_info.mouse_grabbed))
});
}

View file

@ -1,3 +1,55 @@
use bevy::{
prelude::{Plugin, Res, ResMut},
window::Windows,
};
use bevy_egui::EguiPlugin;
use bevy_framepace::FramepacePlugin;
use self::{client_settings::Settings, diagnosis::diag_ui, stats::stats_ui, wiki::wiki_ui};
use crate::client_settings;
pub mod client_settings; pub mod client_settings;
pub mod diagnosis;
pub mod stats; pub mod stats;
pub mod wiki; pub mod wiki;
pub struct UIInfo {
pub mouse_grabbed: bool,
}
impl Default for UIInfo {
fn default() -> Self {
Self {
mouse_grabbed: true,
}
}
}
pub struct UIPlugin;
impl Plugin for UIPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app.insert_resource(Settings::default())
.insert_resource(UIInfo::default())
.add_plugin(EguiPlugin)
.add_system(client_settings)
.add_system(settings_handler)
.add_system(wiki_ui)
.add_system(stats_ui)
.add_system(diag_ui);
}
}
fn settings_handler(
mut plugin: ResMut<FramepacePlugin>,
mut windows: ResMut<Windows>,
settings: Res<Settings>,
) {
let window = windows.primary_mut();
plugin.framerate_limit = bevy_framepace::FramerateLimit::Manual(settings.target_fps);
use bevy::window::WindowMode::{BorderlessFullscreen, Windowed};
match settings.fullscreen {
true => window.set_mode(BorderlessFullscreen),
false => window.set_mode(Windowed),
}
}

View file

@ -11,7 +11,7 @@ pub struct DateTime {
impl DateTime { impl DateTime {
pub fn format(&self) -> String { pub fn format(&self) -> String {
format!( format!(
"{:02}/{:02}/{:02}-{:02}:{:02}:{:02}", "{:04}/{:02}/{:02}-{:02}:{:02}:{:02}",
self.year, self.month, self.day, self.hour, self.minute, self.second self.year, self.month, self.day, self.hour, self.minute, self.second
) )
} }

View file

@ -6,3 +6,5 @@ pub mod protocol;
pub mod ship; pub mod ship;
pub mod user; pub mod user;
pub mod wiki; pub mod wiki;
pub const PORT: u16 = 22222;

View file

@ -0,0 +1,4 @@
pub struct SolarBody {
pub name: String,
pub size: usize,
}

View file

@ -3,7 +3,7 @@ use bevy::{app::ScheduleRunnerSettings, prelude::*, utils::Duration};
use libspace::datetime::DateTime; use libspace::datetime::DateTime;
// TODO: Workout a proper TPS for the server. // TODO: Workout a proper TPS for the server.
pub const TICKS_PER_SECOND: u32 = 20; pub const TICKS_PER_SECOND: u32 = 1;
fn main() { fn main() {
App::new() App::new()