From c60a6d07efb120724b308e29e8e70f27c87c952d Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Sun, 17 Jan 2021 14:42:56 +0100 Subject: Update dependencies and rename client and server main files --- Cargo.lock | 20 +++---- Cargo.toml | 21 ++++---- src/client.rs | 156 ----------------------------------------------------- src/client_main.rs | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/server.rs | 0 src/server_main.rs | 0 6 files changed, 174 insertions(+), 178 deletions(-) delete mode 100644 src/client.rs create mode 100644 src/client_main.rs delete mode 100644 src/server.rs create mode 100644 src/server_main.rs diff --git a/Cargo.lock b/Cargo.lock index d36d039..9edec6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,9 +69,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cc" -version = "1.0.61" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" +checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" [[package]] name = "cfg-if" @@ -81,9 +81,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cmake" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" +checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855" dependencies = [ "cc", ] @@ -388,9 +388,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "raylib" -version = "3.0.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b222dc0fecd87b6a4272b2ebd80ca8c5435f5c0360c38ed2a2b2b3f6bd2c1f13" +checksum = "7d3df0dcf9b202552b74c715028224a04ca89443a1e4706382798aa6b13c85a0" dependencies = [ "lazy_static", "libc", @@ -399,9 +399,9 @@ dependencies = [ [[package]] name = "raylib-sys" -version = "3.0.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6909eb526b5f7a3f6f8b3904dc7acc4f433f4f8bd071a342b5139bab913fe7" +checksum = "0e2a71751cbdfb2beaa9ca806ec223525c182778e6ef123378898f99f1b1b30c" dependencies = [ "cc", "cmake", @@ -597,9 +597,9 @@ checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" [[package]] name = "xmltree" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76badaccb0313f1f0cb6582c2973f2dd0620f9652eb7a5ff6ced0cc3ac922b3" +checksum = "d046fd42d4137234742eae0d05b4fb6fbdda9aed7c78e523ae890fd87c7e11dd" dependencies = [ "xml-rs", ] diff --git a/Cargo.toml b/Cargo.toml index 6627b77..c4fe883 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,27 +5,24 @@ authors = ["Arne Dußin "] edition = "2018" default-run = "client" -[build] -target = "client" - [[bin]] name = "client" -path = "src/client.rs" +path = "src/client_main.rs" [[bin]] name = "server" -path = "src/server.rs" +path = "src/server_main.rs" [dependencies] +alga = "*" +float-cmp = "*" +log = "*" +nalgebra = "*" +num-traits = "*" +pretty_env_logger = "*" raylib = "3.0.0" ron = "*" serde = "*" -nalgebra = "*" -alga = "*" -num-traits = "*" svgtypes = "*" -xmltree = "*" -pretty_env_logger = "*" -log = "*" thiserror = "*" -float-cmp = "*" +xmltree = "*" diff --git a/src/client.rs b/src/client.rs deleted file mode 100644 index 4ed5581..0000000 --- a/src/client.rs +++ /dev/null @@ -1,156 +0,0 @@ -//! # Graf Karto cartographer -//! -//! ### What is it exactly -//! Graf Karto is a table top role playing game (TTRPG) map creation tool that is optimised for real -//! time map interaction. -//! -//! ### Motivation -//! While there are certainly many TTRPG map creation tools for single user and multi user available -//! online and on the market, we felt that most of them lack features or are to unwieldy to seriously -//! consider for real time dungeon drawing, say for instance when drawing a map for an old school -//! revival style game. This is why Graf Karto is optimised for speed above pretty graphical features. -//! The aim is for the user not to have to think much about how they are going to achieve what they are -//! doing and how they are going to make it pretty, but should just be able to *do* it, to have time to -//! worry about other things. This does not mean that all maps created should visually be equivalent to -//! a steaming pile of hot garbage, but if the visuals should try to get in the way, usability and speed -//! takes precedence. - -#![allow(dead_code)] -#![warn(missing_docs)] - -#[macro_use] -extern crate log; - -pub mod cli; -pub mod colours; -pub mod config; -pub mod editor; -pub mod grid; -pub mod gui; -pub mod input; -pub mod map; -pub mod math; -pub mod server; -pub mod snapping; -pub mod stable_vec; -pub mod svg; -pub mod tool; -pub mod transform; -pub mod transformable; - -use cli::CLI; -use config::Config; -use editor::Editor; -use float_cmp::F64Margin; -use gui::{DimensionIndicator, ToolSidebar}; -use input::Input; -use raylib::prelude::*; -use snapping::Snapper; -use std::ffi::CString; -use std::io; -use transform::Transform; - -/// Location of the file containing the style used for the raylib user interface. -pub const GUI_STYLE: &str = "assets/style/cyber.rgs"; -/// Location of the graf karto configuration options file. -pub const CONFIG_FILE: &str = "config.ron"; - -/// The acceptable error that is used throughout the project for two floats to be considered equal. -/// If it is set too low, the editor might not work properly, if set too high, the granularity may -/// become too low for certain purposes. -pub const FLOAT_MARGIN: F64Margin = F64Margin { - epsilon: 10000. * f64::EPSILON, - ulps: 0, -}; - -fn main() { - pretty_env_logger::init(); - - let (mut rl, thread) = raylib::init().resizable().title("Hello there!").build(); - rl.set_target_fps(120); - rl.set_exit_key(None); - - // Load the configuration file, if available. - let config = match Config::from_file(CONFIG_FILE) { - Ok(config) => config, - Err(err) => { - /* Create a default config file if it doesn't exist, otherwise leave the incorrectly - * formatted/corrupted or otherwise unreadable file alone. - */ - let config = Config::default(); - if err.kind() == io::ErrorKind::NotFound { - warn!("Could not find a configuration file. Creating default."); - config - .write_file(CONFIG_FILE) - .expect("Could not write config file."); - } else { - error!( - "Could not read configuration file: {}\nUsing defaults for this run.", - err - ); - } - - config - } - }; - - // Load the preferred gui style - rl.gui_load_style(Some( - &CString::new(GUI_STYLE).expect("Could not create C string from style file name"), - )); - - let mut input = Input::new(&rl); - config::register_bindings(&config, &mut input); - let mut editor = Editor::new(&mut rl, &thread, config); - let mut dimension_indicator = DimensionIndicator::new(); - let mut tool_sidebar = ToolSidebar::new(&mut rl, &thread, &mut input); - let mut snapper = Snapper::default(); - let mut cli = CLI::new(&mut input); - - let mut transform = Transform::new(); - let mut last_mouse_pos = rl.get_mouse_position(); - while !rl.window_should_close() { - let screen_width = rl.get_screen_width(); - let screen_height = rl.get_screen_height(); - - input.update(&mut rl); - - // Move the canvas together with the mouse - if rl.is_mouse_button_down(MouseButton::MOUSE_MIDDLE_BUTTON) { - transform.move_by_px(&(rl.get_mouse_position() - last_mouse_pos).into()); - } - // Update the last mouse position - last_mouse_pos = rl.get_mouse_position(); - - let mouse_wheel_move = rl.get_mouse_wheel_move(); - if mouse_wheel_move != 0 { - // Zoom in for positive and zoom out for negative mouse wheel rotations. - let scale_factor = if mouse_wheel_move > 0 { 1.2 } else { 1. / 1.2 }; - transform.try_zoom( - &rl.get_mouse_position().into(), - mouse_wheel_move.abs() as f64 * scale_factor, - ); - } - - cli.update(&mut editor, &mut input); - dimension_indicator.update(editor.map_mut(), &mut rl); - snapper.update(&mut rl, cli.active()); - editor.update(&mut rl, &transform, &snapper, &mut input); - tool_sidebar.update(screen_height as u16, &mut input); - - // Drawing section - { - let mut d = rl.begin_drawing(&thread); - d.clear_background(Color::BLACK); - grid::draw_grid(&mut d, screen_width, screen_height, &transform); - editor.map().draw(&mut d, &transform); - - editor.draw_tools(&mut d, &transform); - tool_sidebar.draw(&mut d, &mut editor); - snapper.draw(&mut d); - gui::position_indicator_draw(&mut d, last_mouse_pos.into(), &transform, &snapper); - dimension_indicator.draw(&mut d, &transform); - cli.draw(&mut d); - } - } -} diff --git a/src/client_main.rs b/src/client_main.rs new file mode 100644 index 0000000..22251c3 --- /dev/null +++ b/src/client_main.rs @@ -0,0 +1,155 @@ +//! # Graf Karto cartographer +//! +//! ### What is it exactly +//! Graf Karto is a table top role playing game (TTRPG) map creation tool that is optimised for real +//! time map interaction. +//! +//! ### Motivation +//! While there are certainly many TTRPG map creation tools for single user and multi user available +//! online and on the market, we felt that most of them lack features or are to unwieldy to seriously +//! consider for real time dungeon drawing, say for instance when drawing a map for an old school +//! revival style game. This is why Graf Karto is optimised for speed above pretty graphical features. +//! The aim is for the user not to have to think much about how they are going to achieve what they are +//! doing and how they are going to make it pretty, but should just be able to *do* it, to have time to +//! worry about other things. This does not mean that all maps created should visually be equivalent to +//! a steaming pile of hot garbage, but if the visuals should try to get in the way, usability and speed +//! takes precedence. + +#![allow(dead_code)] +#![warn(missing_docs)] + +#[macro_use] +extern crate log; + +pub mod cli; +pub mod colours; +pub mod config; +pub mod editor; +pub mod grid; +pub mod gui; +pub mod input; +pub mod map; +pub mod math; +pub mod snapping; +pub mod stable_vec; +pub mod svg; +pub mod tool; +pub mod transform; +pub mod transformable; + +use cli::CLI; +use config::Config; +use editor::Editor; +use float_cmp::F64Margin; +use gui::{DimensionIndicator, ToolSidebar}; +use input::Input; +use raylib::prelude::*; +use snapping::Snapper; +use std::ffi::CString; +use std::io; +use transform::Transform; + +/// Location of the file containing the style used for the raylib user interface. +pub const GUI_STYLE: &str = "assets/style/cyber.rgs"; +/// Location of the graf karto configuration options file. +pub const CONFIG_FILE: &str = "config.ron"; + +/// The acceptable error that is used throughout the project for two floats to be considered equal. +/// If it is set too low, the editor might not work properly, if set too high, the granularity may +/// become too low for certain purposes. +pub const FLOAT_MARGIN: F64Margin = F64Margin { + epsilon: 10000. * f64::EPSILON, + ulps: 0, +}; + +fn main() { + pretty_env_logger::init(); + + let (mut rl, thread) = raylib::init().resizable().title("Hello there!").build(); + rl.set_target_fps(120); + rl.set_exit_key(None); + + // Load the configuration file, if available. + let config = match Config::from_file(CONFIG_FILE) { + Ok(config) => config, + Err(err) => { + /* Create a default config file if it doesn't exist, otherwise leave the incorrectly + * formatted/corrupted or otherwise unreadable file alone. + */ + let config = Config::default(); + if err.kind() == io::ErrorKind::NotFound { + warn!("Could not find a configuration file. Creating default."); + config + .write_file(CONFIG_FILE) + .expect("Could not write config file."); + } else { + error!( + "Could not read configuration file: {}\nUsing defaults for this run.", + err + ); + } + + config + } + }; + + // Load the preferred gui style + rl.gui_load_style(Some( + &CString::new(GUI_STYLE).expect("Could not create C string from style file name"), + )); + + let mut input = Input::new(&rl); + config::register_bindings(&config, &mut input); + let mut editor = Editor::new(&mut rl, &thread, config); + let mut dimension_indicator = DimensionIndicator::new(); + let mut tool_sidebar = ToolSidebar::new(&mut rl, &thread, &mut input); + let mut snapper = Snapper::default(); + let mut cli = CLI::new(&mut input); + + let mut transform = Transform::new(); + let mut last_mouse_pos = rl.get_mouse_position(); + while !rl.window_should_close() { + let screen_width = rl.get_screen_width(); + let screen_height = rl.get_screen_height(); + + input.update(&mut rl); + + // Move the canvas together with the mouse + if rl.is_mouse_button_down(MouseButton::MOUSE_MIDDLE_BUTTON) { + transform.move_by_px(&(rl.get_mouse_position() - last_mouse_pos).into()); + } + // Update the last mouse position + last_mouse_pos = rl.get_mouse_position(); + + let mouse_wheel_move = rl.get_mouse_wheel_move(); + if mouse_wheel_move != 0. { + // Zoom in for positive and zoom out for negative mouse wheel rotations. + let scale_factor = if mouse_wheel_move > 0. { 1.2 } else { 1. / 1.2 }; + transform.try_zoom( + &rl.get_mouse_position().into(), + mouse_wheel_move.abs() as f64 * scale_factor, + ); + } + + cli.update(&mut editor, &mut input); + dimension_indicator.update(editor.map_mut(), &mut rl); + snapper.update(&mut rl, cli.active()); + editor.update(&mut rl, &transform, &snapper, &mut input); + tool_sidebar.update(screen_height as u16, &mut input); + + // Drawing section + { + let mut d = rl.begin_drawing(&thread); + d.clear_background(Color::BLACK); + grid::draw_grid(&mut d, screen_width, screen_height, &transform); + editor.map().draw(&mut d, &transform); + + editor.draw_tools(&mut d, &transform); + tool_sidebar.draw(&mut d, &mut editor); + snapper.draw(&mut d); + gui::position_indicator_draw(&mut d, last_mouse_pos.into(), &transform, &snapper); + dimension_indicator.draw(&mut d, &transform); + cli.draw(&mut d); + } + } +} diff --git a/src/server.rs b/src/server.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/server_main.rs b/src/server_main.rs new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-70-g09d2