diff options
93 files changed, 311 insertions, 3067 deletions
@@ -1,9 +1,2 @@ -/assets -/bindir -/build -/datdir -/glad -*.star -*.zip -*.zst -vgcore.* +/Cargo.lock +/target diff --git a/CHANGELOG.md b/CHANGELOG.md index 078fa6c..eb21dfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,27 +1,49 @@ -# 0.C.0 +# Changelog -*0.C.0-12* +This is the changelog of Bowshock. +See `"README.md"` for more information. + +## 0.13.0-0 + +* Rewrite in Rust +* Update copyright years +* Update gitignore +* Use decimal versioning +* Add core library +* Add client and server executables +* Reformat changelog +* Reformat credits + +### Core + +* Depend on `bzipper` + +### Client + +### Server + +## 0.12.0-18 * Update readme * Improve commenting -*0.C.0-11* +## 0.12.0-17 * Fix readme -*0.C.0-10* +## 0.12.0-16 * Update readme * Add dependencies subsection to readme * Add function for logging -*0.C.0-F* +## 0.12.0-15 * Fix and update readme * Update and fix installation script * Put version number in readme -*0.C.0-E* +## 0.12.0-14 * Update readme * Add function for getting the hull mass of a ship type @@ -30,24 +52,24 @@ * Rename ware_mass to ware_density * Add ship type 'canis' -*0.C.0-D* +## 0.12.0-13 * Update readme -*0.C.0-C* +## 0.12.0-12 * Update readme (add logo) -*0.C.0-B* +## 0.12.0-11 * Update readme * Update changelog style -*0.C.0-A* +## 0.12.0-10 * Update readme (eg. use non-ASCII characters) -*0.C.0-9* +## 0.12.0-9 * Fix CMake not complaining about data directory not being specified * Find packages in CMake @@ -69,12 +91,12 @@ * Make changelog Markdown * Rename home_directory to base_directory -*0.C.0-8* +## 0.12.0-8 * Fix shader validation script * Fix shader -*0.C.0-7* +## 0.12.0-7 * Update readme * Split program into client-side and server-side @@ -94,7 +116,7 @@ * Add copyright symbol to startup notice * Bump version specified in CMake -*0.C.0-6* +## 0.12.0-6 * Check I/O results * Fix credits print @@ -106,12 +128,12 @@ * Fix logs * Fix save loader -*0.C.0-5* +## 0.12.0-5 * Update readme * Fix version constant -*0.C.0-4* +## 0.12.0-4 * Drop zp in favour of the standard library * Drop ly in favour of the standard library @@ -125,11 +147,11 @@ * Update help screen * Fix objects not being deleted -*0.C.0-3* +## 0.12.0-3 * Enable more warnings -*0.C.0-2* +## 0.12.0-2 * Enforce new naming convention * Use fixed-width floating-point types @@ -139,7 +161,7 @@ * Make cmpshd static * Rename crd to prcrd -*0.C.0-1* +## 0.12.0-1 * Update naming convention * Use trailing return types @@ -148,23 +170,23 @@ * Update some typings * Rename intro to start sequence -*0.C.0-0* +## 0.12.0-0 * Migrate from Zap to zp * Migrate from Flux to ly * Tag development versions * Use minimum-width types -# 0.B.2 +## 0.11.2 * Fix data directory not being set correctly by CMake -# 0.B.1 +## 0.11.1 * Fortify sources * Use Flux more -# 0.B.0 +## 0.11.0 * Use generator expressions in CMake * Use OpenGL 4.1 @@ -176,7 +198,7 @@ * Add more quotes * Fix launch options not being listed on the help print -# 0.A.0 +## 0.10.0 * Remove satellite object type * Fix viewport size being too small on some devices @@ -207,7 +229,7 @@ * Add assumption macro * Improve precision of gravitational constant -# 0.9.0 +## 0.9.0 * Fix compilation warning * Optimise mechanical functions @@ -221,13 +243,13 @@ * Update gitignore * Make code more modular -# 0.8.1 +## 0.8.1 * Update renderer * Add canister to simulation * Update mechanical functions -# 0.8.0 +## 0.8.0 * Make code more modular * Don't use global variables @@ -239,7 +261,7 @@ * Enable more warnings * Draw simulation in window -# 0.7 +## 0.7 * Make window fullscreen * Update object data (store both positional and rotational velocity) @@ -253,7 +275,7 @@ * (Temporarily) define some constants as macros instead of as compile-time variables * Create object system -# 0.6 +## 0.6 * Update versioning: Use major.minor * Update save format @@ -261,7 +283,7 @@ * Add quotes * Save simulation result to image -# 5 +## 5 * Update save data format * Add continue routine @@ -272,24 +294,24 @@ * Update flux usage * Optimise grav -# 4 +## 4 * Add simple save routine * Add logo * Add clean and purge targets to makefile -# 3 +## 3 * Fix incorrect symbol names * Add basic graphics instancing -# 2 +## 2 * Rename project to Bowshock (from Procyon) * Rewrite project * Add gravity engine -# 1 +## 1 * Move save handlers into their own module 'sav' * Add new module 'evt' @@ -303,6 +325,6 @@ * Add function for determining the jump range of a ship * Add desktop entry -# 0 +## 0 * Initial diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index d90ad33..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.21) - -project( - bowshock - - VERSION 0.12.0 - HOMEPAGE_URL "https://mandelbrot.dk/bowshock" - LANGUAGES C CXX -) - -add_subdirectory(bowshock) -add_subdirectory(glad) diff --git a/CREDITS.md b/CREDITS.md new file mode 100644 index 0000000..0e9a046 --- /dev/null +++ b/CREDITS.md @@ -0,0 +1,7 @@ +# Credits + +Bowshock is copyright © 2022-2024 Gabriel Bjørnager Jensen. + +## Director + +**Bjørnager Jensen**, Gabriel diff --git a/CREDITS.txt b/CREDITS.txt deleted file mode 100644 index fcd91ea..0000000 --- a/CREDITS.txt +++ /dev/null @@ -1,13 +0,0 @@ -BOWSHOCK - -COPYRIGHT: -2022-2023 Gabriel Bjørnager Jensen - -DESIGN - Gabriel Bjørnager Jensen - -ARTWORK - Gabriel Bjørnager Jensen - -SOFTWARE DEVELOPMENT - Gabriel Bjørnager Jensen diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..dd788c4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,153 @@ +[workspace] +members = ["client", "core", "server"] +resolver = "2" + +[workspace.package] +version = "3.0.0" +authors = ["Gabriel Bjørnager Jensen"] +homepage = "https://achernar.dk/index.php?p=bowshock" +repository = "https://mandelbrot.dk/bowshock/" + +[workspace.lints.clippy] +as_ptr_cast_mut = "forbid" +as_underscore = "warn" +assertions_on_result_states = "warn" +bool_to_int_with_if = "warn" +borrow_as_ptr = "forbid" +branches_sharing_code = "warn" +cast_lossless = "warn" +cast_ptr_alignment = "forbid" +checked_conversions = "warn" +clear_with_drain = "warn" +cloned_instead_of_copied = "warn" +collection_is_never_read = "warn" +dbg_macro = "warn" +debug_assert_with_mut_call = "warn" +deref_by_slicing = "warn" +derive_partial_eq_without_eq = "deny" +empty_enum = "warn" +empty_enum_variants_with_brackets = "warn" +empty_line_after_doc_comments = "warn" +empty_line_after_outer_attr = "warn" +empty_structs_with_brackets = "warn" +enum_variant_names = "allow" +equatable_if_let = "warn" +excessive_precision = "allow" +exit = "warn" +expl_impl_clone_on_copy = "warn" +explicit_deref_methods = "warn" +explicit_into_iter_loop = "warn" +explicit_iter_loop = "warn" +fallible_impl_from = "deny" +flat_map_option = "warn" +float_cmp = "deny" # Fortran, is that you? +float_cmp_const = "deny" +format_push_string = "warn" +from_iter_instead_of_collect = "warn" +future_not_send = "deny" +if_not_else = "warn" +if_then_some_else_none = "warn" +ignored_unit_patterns = "warn" +impl_trait_in_params = "warn" +implicit_clone = "warn" +imprecise_flops = "deny" +inconsistent_struct_constructor = "deny" +index_refutable_slice = "warn" +inefficient_to_string = "warn" +infinite_loop = "deny" +into_iter_without_iter = "deny" +invalid_upcast_comparisons = "warn" +iter_filter_is_ok = "warn" +iter_filter_is_some = "warn" +iter_not_returning_iterator = "deny" +iter_on_empty_collections = "warn" +iter_on_single_items = "warn" +iter_with_drain = "warn" +iter_without_into_iter = "deny" +macro_use_imports = "warn" +manual_assert = "warn" +manual_c_str_literals = "warn" +manual_instant_elapsed = "warn" +manual_is_variant_and = "warn" +manual_let_else = "warn" +manual_ok_or = "warn" +manual_string_new = "warn" +map_unwrap_or = "warn" +match_bool = "warn" +match_on_vec_items = "warn" +match_same_arms = "warn" +mismatching_type_param_order = "warn" +mixed_read_write_in_expression = "deny" +must_use_candidate = "deny" +mut_mut = "deny" +mutex_atomic = "deny" +mutex_integer = "deny" +needless_bitwise_bool = "deny" +needless_collect = "warn" +needless_continue = "warn" +needless_pass_by_ref_mut = "warn" +needless_pass_by_value = "deny" +needless_raw_string_hashes = "warn" +needless_raw_strings = "warn" +no_effect_underscore_binding = "deny" +no_mangle_with_rust_abi = "deny" +non_ascii_literal = "forbid" +nonstandard_macro_braces = "warn" +option_as_ref_cloned = "warn" +option_if_let_else = "warn" +option_option = "deny" +or_fun_call = "deny" +path_buf_push_overwrite = "deny" +pattern_type_mismatch = "deny" +ptr_as_ptr = "forbid" +ptr_cast_constness = "forbid" +pub_underscore_fields = "deny" +pub_with_shorthand = "deny" +read_zero_byte_vec = "deny" +redundant_clone = "deny" +redundant_closure_for_method_calls = "warn" +redundant_else = "warn" +redundant_pub_crate = "warn" +redundant_type_annotations = "warn" +ref_as_ptr = "deny" +ref_binding_to_reference = "warn" +ref_option_ref = "deny" +rest_pat_in_fully_bound_structs = "warn" +return_self_not_must_use = "deny" +same_functions_in_if_condition = "deny" +same_name_method = "deny" +self_named_module_files = "deny" +semicolon_outside_block = "warn" +single_char_pattern = "warn" +str_split_at_newline = "warn" +string_lit_as_bytes = "deny" +string_lit_chars_any = "deny" +string_to_string = "deny" +suboptimal_flops = "deny" +trait_duplication_in_bounds = "deny" +transmute_ptr_to_ptr = "deny" +type_repetition_in_bounds = "deny" +uninhabited_references = "deny" +uninlined_format_args = "deny" +unnecessary_box_returns = "deny" +unnecessary_join = "deny" +unnecessary_self_imports = "deny" +unneeded_field_pattern = "warn" +unnested_or_patterns = "warn" +unseparated_literal_suffix = "warn" +unused_async = "warn" +unused_peekable = "warn" +unused_rounding = "warn" +use_self = "deny" +used_underscore_binding = "deny" +useless_let_if_seq = "warn" +verbose_bit_mask = "warn" +verbose_file_reads = "warn" +wildcard_dependencies = "deny" +zero_sized_map_values = "deny" + +[profile.release] +codegen-units = 1 + +lto = "fat" +opt-level = 3 @@ -1,97 +1,18 @@ -*BOWSHOCK 0.C.0-11* +# Bowshock -![](https://mandelbrot.dk/logo/bowshock.svg) +*Bowshock* is an upcoming project developed at [Achernar](https://achernar.dk/) by Gabriel Bjørnager Jensen. -# CHANGELOG +This project is currently early in development. +This readme will be elaborated upon gradually. -Read: `CHANGELOG.md` - -# COMPILATION - -Bowshock uses CMake as its build system. The standard option `CMAKE_BUILD_TYPE` may be set to either `Release` or `Debug`, depending on the build type. - -The main program is written in C++20, and a conforming compiler is therefore required. OpenGL 3.2 is used for rendering, and the shaders are therefore written in GLSL 1.5. - -Before compilation, an appropriate *GLAD* loader must be downloaded. For more information, read: *COMPILATION > DEPENDENCIES > GLAD* - -<https://glad.dav1d.de/#language=c&specification=gl&api=gl%3D3.2&api=gles1%3Dnone&api=gles2%3Dnone&api=glsc2%3Dnone&profile=core&loader=on> - -The script `extractGlad.sh` will extract `glad.zip` (or any other archive – if specified) to `glad`. It also copies a CMake lists file to the directory. - -``` -./extractGlad.sh <archive> -``` - -Before running – however – the data directory must be installed. This can be done via the installation script `install.sh`: - -``` -./install.sh data [data directory] -``` - -## DEPENDENCIES - -Bowshock makes use of the following libraries: - -* {fmt} -* GLAD (see below) -* GLFW3 - -For {fmt}, the appropriate package is `fmt` (Arch). For GLFW, both `glfw-wayland` and `glfw-x11` (both Arch) may be used. - -### GLAD - -The GLAD loader must be downloaded from a web instance. I use the one on `dav1d.de`, with the following settings: +## CHANGELOG -<https://glad.dav1d.de/#language=c&specification=gl&api=gl%3D3.2&api=gles1%3Dnone&api=gles2%3Dnone&api=glsc2%3Dnone&profile=core&loader=on> - -The script `extractGlad.sh` will extract `glad.zip` (or any other archive – if specified) to `glad`. It also copies a CMake lists file to the directory. - -``` -./extractGlad.sh <archive> -``` - -# DEVELOPMENT - -To initialise the environment, I use the following commands: - -``` -rm -fr build && \ -rm -fr bindir && \ -rm -fr datdir && \ -./extractGlad.sh && \ -cmake -Bbuild -DBOW_DATA_DIRECTORY="${PWD}/datdir" -DCMAKE_BUILD_TYPE=Debug . && \ -./install.sh data "${PWD}/datdir" -``` - -… and from there just use the following to build the project: - -``` -clear && \ -./validateShaders.py && \ -cmake --build build && \ -build/bowshock/bowshock --skip -``` - -## SHADER VALIDATION - -The shaders at `bowshock/shader` may be validated using the Python script `validateShaders.py`. If the shaders contain errors, and these are not fixed before installation, the program will fail to compile them during run‐time. - -# INSTALLATION - -The script `install.sh` will install the executable, the assets, the shaders, etc. to the specified directories: - -``` -./install.sh all [build directory] [binary directory] [data directory] -``` - -# MIRRORS - -mandelbrot.dk (main): <https://mandelbrot.dk/bowshock> +Read: `CHANGELOG.md` -GitLab: <https://gitlab.com/bjoernager/bowshock.git> +## MIRRORS -GitHub: <https://github.com/bjoernager/bowshock.git> +Bowshock is officially hosted on [`mandelbrot.dk`](https://mandelbrot.dk/bowshock/). -# CREDITS +## CREDITS Read: `CREDITS.txt` diff --git a/bowshock.desktop b/bowshock.desktop deleted file mode 100755 index 1d8dc3d..0000000 --- a/bowshock.desktop +++ /dev/null @@ -1,5 +0,0 @@ -[Desktop Entry] -Type=Application -Name=Bowshock -Exec=/usr/bin/bowshock -Icon=bowshock diff --git a/bowshock/CMakeLists.txt b/bowshock/CMakeLists.txt deleted file mode 100644 index e52da7f..0000000 --- a/bowshock/CMakeLists.txt +++ /dev/null @@ -1,155 +0,0 @@ -cmake_minimum_required(VERSION 3.21) - -option(BOW_DATA_DIRECTORY "Directory for storing run-time data (assets, shaders...)." "") - -if(NOT DEFINED BOW_DATA_DIRECTORY) - message(FATAL_ERROR "Data directory (BOW_DATA_DIRECTORY) not specified") -endif() - -find_package( - glfw3 REQUIRED -) - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_EXTENSIONS OFF) - -add_executable( - bowshock - - "source/main.cxx" - - "source/application/Application/constructor.cxx" - "source/application/Application/destructor.cxx" - "source/application/Application/get_quote.cxx" - "source/application/Application/initialise_signal.cxx" - "source/application/Application/parse_parameters.cxx" - "source/application/Application/print_credits.cxx" - "source/application/Application/print_help.cxx" - "source/application/Application/run.cxx" - - "source/client/Client/constructor.cxx" - "source/client/Client/destructor.cxx" - "source/client/Client/loop.cxx" - "source/client/Client/poll_events.cxx" - "source/client/Client/run.cxx" - "source/client/Client/save_path.cxx" - "source/client/Client/start_sequence.cxx" - "source/client/PlayerData/constructor.cxx" - "source/client/PlayerData/decode_save.cxx" - "source/client/PlayerData/encode_save.cxx" - "source/client/PlayerData/load.cxx" - "source/client/PlayerData/read_file.cxx" - "source/client/PlayerData/save.cxx" - "source/client/PlayerData/write_file.cxx" - "source/client/Renderer/constructor.cxx" - "source/client/Renderer/destructor.cxx" - "source/client/Renderer/render.cxx" - "source/client/ShaderProgram/compile_shader.cxx" - "source/client/ShaderProgram/constructor.cxx" - "source/client/ShaderProgram/destructor.cxx" - - "source/base/base_directory.cxx" - "source/base/log.cxx" - "source/base/terminate.cxx" - - "source/logic/Canister/constructor.cxx" - "source/logic/Canister/object_type_string.cxx" - "source/logic/hull_mass.cxx" - "source/logic/Object/object_type_string.cxx" - "source/logic/Ship/constructor.cxx" - "source/logic/Ship/net_mass.cxx" - "source/logic/Ship/object_type_string.cxx" - "source/logic/Star/constructor.cxx" - "source/logic/Star/object_type_string.cxx" - "source/logic/Station/constructor.cxx" - "source/logic/Station/object_type_string.cxx" - "source/logic/ware_density.cxx" - "source/logic/World/constructor.cxx" - "source/logic/World/object_type_string.cxx" - - "source/server/ObjectIterator/constructor.cxx" - "source/server/ObjectIterator/operator_equality.cxx" - "source/server/ObjectIterator/operator_increment.cxx" - "source/server/ObjectRoot/add.cxx" - "source/server/ObjectRoot/begin.cxx" - "source/server/ObjectRoot/constructor.cxx" - "source/server/ObjectRoot/destructor.cxx" - "source/server/ObjectRoot/end.cxx" - "source/server/Server/destructor.cxx" - "source/server/Server/start.cxx" - "source/server/ServerInstance/constructor.cxx" - "source/server/ServerInstance/generate_system.cxx" - "source/server/ServerInstance/gravitate.cxx" - "source/server/ServerInstance/loop.cxx" - "source/server/ServerInstance/move.cxx" - "source/server/ServerInstance/run.cxx" - "source/server/ServerInstance/simulate.cxx" -) - -add_dependencies( - bowshock - - glad - glfw -) - -target_include_directories( - bowshock PRIVATE - - "include" -) - -target_link_libraries( - bowshock PRIVATE - - fmt - glad - glfw - m -) - -target_compile_definitions( - bowshock PRIVATE - - GLFW_INCLUDE_NONE - bow_DATA_DIRECTORY="${BOW_DATA_DIRECTORY}" - bow_DEBUG=$<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,true,false> -) - -if(UNIX) - target_compile_definitions( - bowshock PRIVATE - - _FORTIFY_SOURCE=$<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,0x0,0x2> - _POSIX_C_SOURCE=200112l - ) -endif() - -if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|GNU") - target_compile_options( - bowshock PRIVATE - - $<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,-Og,-Ofast> - -Wall - -Wdouble-promotion - -Wextra - -Wformat=2 - -Winvalid-utf8 - -Wmissing-declarations - -Wmissing-include-dirs - -Wnull-dereference - -Wpedantic - -Wpointer-arith - -Wstrict-overflow=5 - -fdiagnostics-color=always - -g - ) -elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - target_compile_options( - bowshock PRIVATE - - /O2 - /W4 - $<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,/Zo> - ) -endif() diff --git a/bowshock/include/bow/application.hxx b/bowshock/include/bow/application.hxx deleted file mode 100644 index f7a4146..0000000 --- a/bowshock/include/bow/application.hxx +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#pragma once - -#include <bow/client.hxx> -#include <bow/server.hxx> - -#include <string> -#include <tuple> -#include <vector> - -namespace bow { - template<typename T> struct VersionType { - T major; - T minor; - T patch; - }; - - constexpr ::bow::VersionType<::std::uint64_t> VERSION = { - .major = 0x0u, - .minor = 0xCu, - .patch = 0x0u, - }; - - class Application final { - public: - explicit Application(int argc, char const* const* argv) noexcept; - - ~Application() noexcept; - - auto run() -> int; - - private: - ::bow::ClientConfiguration client_configuration; - ::bow::ServerConfiguration server_configuration; - - ::bow::Client* client; - ::bow::Server* server; - - [[noreturn]] static auto print_credits() noexcept -> void; - - [[noreturn]] static auto print_help(::std::string const& program_name) noexcept -> void; - - [[nodiscard]] static auto get_quote(::std::uint8_t identifier) -> ::std::tuple<::std::string, ::std::string>; - - auto parse_parameters(::std::string const& program_name, ::std::vector<char const*> const& parameters) -> void; - - auto initialise_signal() -> void; - }; -} diff --git a/bowshock/include/bow/base.hxx b/bowshock/include/bow/base.hxx deleted file mode 100644 index 448f255..0000000 --- a/bowshock/include/bow/base.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#pragma once - -#ifndef bow_DATA_DIRECTORY -#error data directory not specified -#endif - -#include <atomic> -#include <climits> -#include <cstdint> -#include <exception> -#include <source_location> -#include <string> - -static_assert(CHAR_BIT == 0x8, "bytes must contain exactly eight bits"); - -namespace bow { - inline ::std::string DATA_DIRECTORY(bow_DATA_DIRECTORY); - - constexpr bool DEBUG = bow_DEBUG; - - constexpr ::std::size_t COMMANDER_NAME_LENGTH = 0x10u; - - constexpr ::std::uint_least8_t NUMBER_OF_QUOTE_IDENTIFIERS = UINT8_C(0x24); - - template<typename T> struct Xyz { - T x; - T y; - T z; - }; - - // UB to use this from an asynchronous signal - // handler? ISO requires ::std::atomic or - // ::std::sig_atomic_t, but the former is not - // lock-free, and the latter is not even truly - // atomic. - extern ::std::atomic_flag GOT_INTERRUPT; - - [[noreturn]] auto terminate(::std::string const& location, ::std::string const& message) noexcept -> void; - - // Returns the path to the user's home directory. - // If we are unable to determine its path, we - // instead use the current directory ".". - auto base_directory() noexcept -> ::std::string; - - auto log(::std::string const& location, ::std::string const& message) noexcept -> void; -} diff --git a/bowshock/include/bow/client.hxx b/bowshock/include/bow/client.hxx deleted file mode 100644 index fcbe222..0000000 --- a/bowshock/include/bow/client.hxx +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#pragma once - -#include <bow/logic.hxx> - -#include <array> -#include <csignal> -#include <cstdint> -#include <glad/glad.h> -#include <GLFW/glfw3.h> -#include <string> - -namespace bow { - constexpr ::std::uint64_t SAVE_FORMAT_VERSION = 0x7u; - - constexpr ::std::size_t SAVE_LENGTH = 0x79u + ::bow::COMMANDER_NAME_LENGTH; - - constexpr ::std::string SHADER_FILE_SUFFIX("glsl"); - - /* - Save format: - - offset: identifier: size: format: - - 0x00 format_version 8 unsigned - 0x08 commander_name E UTF-8 - 0x16 time 8 unsigned - 0x1E system_identifier 8 unsigned - 0x1F ship_type 1 unsigned - 0x27 ship_position_x 8 binary64 - 0x2F ship_position_y 8 binary64 - 0x37 ship_position_z 8 binary64 - 0x3F ship_rotation_x 8 binary64 - 0x47 ship_rotation_y 8 binary64 - 0x4F ship_rotation_z 8 binary64 - 0x57 ship_positional_velocity_x 8 binary64 - 0x5F ship_positional_velocity_y 8 binary64 - 0x67 ship_positional_velocity_z 8 binary64 - 0x6F ship_rotational_velocity_x 8 binary64 - 0x77 ship_rotational_velocity_y 8 binary64 - 0x7F ship_rotational_velocity_z 8 binary64 - */ - - struct ClientConfiguration final { - ::std::string directory; - ::std::string save_name; - ::std::uint_least16_t network_port; - bool new_save: 0x1; - bool skip_start_sequence: 0x1; - }; - - class PlayerData final { - public: - ::std::string name; - ::std::uint64_t time; - ::std::uint64_t system_identifier; - ::bow::Ship ship; - float zoom; - - PlayerData() noexcept; - PlayerData(::std::string const& path); - - auto save(::std::string const& path) -> void; - auto load(::std::string const& path) -> void; - - private: - struct SaveData { - ::std::uint64_t format_version; - char8_t commander_name[::bow::COMMANDER_NAME_LENGTH]; - ::std::uint64_t time; - ::std::uint64_t system_identifier; - ::std::uint8_t ship_type; - double ship_position_x; - double ship_position_y; - double ship_position_z; - double ship_rotation_x; - double ship_rotation_y; - double ship_rotation_z; - double ship_positional_velocity_x; - double ship_positional_velocity_y; - double ship_positional_velocity_z; - double ship_rotational_velocity_x; - double ship_rotational_velocity_y; - double ship_rotational_velocity_z; - }; - - auto encode_save(::std::array<::std::uint8_t, ::bow::SAVE_LENGTH>& buffer, ::bow::PlayerData const& source) noexcept -> void; - - auto decode_save(::bow::PlayerData & buffer, ::std::array<::std::uint8_t, ::bow::SAVE_LENGTH> const& source) -> void; - - auto write_file(::std::string const& path, ::std::array<::std::uint8_t, ::bow::SAVE_LENGTH> const& buffer) -> void; - - auto read_file(::std::array<::std::uint8_t, ::bow::SAVE_LENGTH>& buffer, ::std::string const& path) -> bool; - }; - - enum struct ShaderType { - Fragment, - Geometry, - Vertex, - }; - - class ShaderProgram final { - public: - ::GLuint handle; - - ShaderProgram() noexcept = default; - - explicit ShaderProgram(::std::string const& name); - - ~ShaderProgram() noexcept; - - private: - static auto compile_shader(::std::string const& name, ::bow::ShaderType type) -> ::GLuint; - }; - - class Renderer final { - public: - ::GLFWwindow* window; - ::bow::ShaderProgram* shader_program; - ::GLuint vao; - ::GLuint vbo; - - Renderer(); - - ~Renderer() noexcept; - - auto render(::GLfloat const vertices[], ::std::size_t size) -> void; - }; - - class Client final { - public: - explicit Client(::bow::ClientConfiguration const& configuration); - - ~Client() noexcept; - - static auto save_path(::std::string const& directory, ::std::string const& name) noexcept -> ::std::string; - - auto run() noexcept -> void; - - private: - ::bow::ClientConfiguration configuration; - - ::bow::PlayerData player_data; - - ::bow::Renderer renderer; - - auto poll_events() noexcept -> bool; - - auto start_sequence() -> bool; - - auto loop() -> void; - }; -} diff --git a/bowshock/include/bow/logic.hxx b/bowshock/include/bow/logic.hxx deleted file mode 100644 index bd6a36c..0000000 --- a/bowshock/include/bow/logic.hxx +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#pragma once - -#include <bow/base.hxx> - -#include <cstdint> -#include <string> -#include <type_traits> - -namespace bow { - // Each of the three main measures (distance, mass, - // and time) have their own modifier. These - // modifiers are used to change the "fundamental" - // units used. - - constexpr double DISTANCE_MODIFIER = 0x1.16A5D2D360000000p037; // 1 astronomical unit - constexpr double MASS_MODIFIER = 0x1.91930A5E75F0C192p100; // 1 solar mass - constexpr double TIME_MODIFIER = 0x1.0000000000000000p012; // 1 second - - constexpr double GRAVITY_FACTOR = (::bow::MASS_MODIFIER * (::bow::TIME_MODIFIER * ::bow::TIME_MODIFIER)) / ((::bow::DISTANCE_MODIFIER * ::bow::DISTANCE_MODIFIER * ::bow::DISTANCE_MODIFIER)); // Inverse. - - constexpr double GRAVITY_VALUE = 0x1.258688101B4BB16Dp-34 * ::bow::GRAVITY_FACTOR; // gravitational constant (s^2*m*t^2) - - enum struct Ware: ::std::uint8_t { - AcidsAndBases, - Air, - AlcoholicBeverages, - AncientArtefacts, - AnimalMeats, - Atomics, - Batteries, - BattleWeapons, - Beer, - Biowaste, - Cameras, - Cannabis, - ChemicalWaste, - Clothing, - CoffeeAndTea, - ComputerParts, - Computers, - ComputerSoftware, - Cuttlery, - Dairy, - Drones, - ElectronicComponents, - EncryptedData, - EnergyGenerators, - Explosives, - Films, - FruitsAndVegetables, - Gemstones, - HandWeapons, - HullParts, - Hypnotics, - Ivory, - Jewellry, - Lasers, - LiveAnimals, - LuxuryGoods, - Machinery, - Magnets, - Medicine, - Minerals, - Money, - Monitors, - Music, - Narcotics, - NerveAgents, - NobleGases, - NobleMetals, - OrganicDyes, - Paper, - Pearls, - Pesticides, - Petroleums, - Pharmaceuticals, - Pornography, - Probes, - ProtiumFuel, - Radioactives, - Recyclables, - Robots, - Rockets, - Rubbish, - ScientificInstruments, - SkinsAndFurs, - Slaves, - Soils, - Spirits, - StorageDevices, - Superconductors, - SyntheticDyes, - SyntheticMeat, - Tobacco, - TritiumFuel, - VirtualIntelligences, - Water, - Wine, - XenoRelics, - }; - - enum struct ObjectType: ::std::uint8_t { - Canister, - Ship, - Star, - Station, - World, - }; - - class Object { - public: - ::bow::ObjectType object_type; - - ::bow::Xyz<double> position; // astronomical units - ::bow::Xyz<double> rotation; // radians - ::bow::Xyz<double> positional_velocity; // astronomical units per second - ::bow::Xyz<double> rotational_velocity; // radians per second - double mass; // kilograms - - virtual ~Object() noexcept = default; - - [[nodiscard]] virtual auto object_type_string() const noexcept -> ::std::string; - - protected: - Object() noexcept = default; - }; - - template<typename T> - concept ObjectLike = ::std::is_base_of_v<::bow::Object, T>; - - class Canister final: public ::bow::Object { - public: - ::bow::Ware content; - - Canister() noexcept; - - [[nodiscard]] virtual auto object_type_string() const noexcept -> ::std::string; - }; - - enum struct ShipType: ::std::uint8_t { - Aquila, - Canis, - Cassiopeia, - Centaurus, - Corvus, - Cursor, - Eridanus, - Falco, - Lyra, - Taurus, - Ursa, - Vipera, - }; - constexpr ::std::uint8_t MAXIMUM_SHIP_IDENTIFIER = static_cast<::std::uint8_t>(bow::ShipType::Vipera); - - class Ship final: public ::bow::Object { - public: - ::bow::ShipType type; - - Ship() noexcept; - - [[nodiscard]] virtual auto object_type_string() const noexcept -> ::std::string; - - [[nodiscard]] auto net_mass() noexcept -> double; - }; - - enum struct StarType: ::std::uint8_t { - A, // Main sequence - B, // Main sequence - C, // Carbon - F, // Main sequence - G, // Main sequence - K, // Main sequence - L, // Brown dwarf - M, // Main sequence - N, // Neutron star - O, // Main sequence - S, // Carbon - T, // Brown dwarf - W, // Worm hole - X, // Black hole - Y, // Brown dwarf - Z, // White hole - }; - - class Star final: public ::bow::Object { - public: - ::bow::StarType type; - - Star() noexcept; - - [[nodiscard]] virtual auto object_type_string() const noexcept -> ::std::string; - }; - - enum struct StationType: ::std::uint8_t { - Globus, - Orbis, - }; - - class Station final: public ::bow::Object { - public: - ::bow::StationType type; - - Station() noexcept; - - [[nodiscard]] virtual auto object_type_string() const noexcept -> ::std::string; - }; - - enum struct WorldType: ::std::uint8_t { - AmmoniumWorld, - GasGiant, - IceWorld, - LavaWorld, - RockyWorld, - WaterWorld, - }; - - class World final: public ::bow::Object { - public: - ::bow::WorldType type; - - World() noexcept; - - [[nodiscard]] virtual auto object_type_string() const noexcept -> ::std::string; - }; - - [[nodiscard]] auto hull_mass( ::bow::ShipType ship) noexcept -> double; - [[nodiscard]] auto ware_density(::bow::Ware ware) noexcept -> double; -} diff --git a/bowshock/include/bow/network.hxx b/bowshock/include/bow/network.hxx deleted file mode 100644 index 0cad935..0000000 --- a/bowshock/include/bow/network.hxx +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#pragma once - -#include <bow/logic.hxx> - -namespace bow { - // I chose the default port number (37279) as it's - // the index number of Proycon in the Hipparcos - // Catalogue. - constexpr ::std::uint_least16_t DEFAULT_NETWORK_PORT = UINT16_C(0x919F); - constexpr ::std::uint_least16_t MINIMUM_NETWORK_PORT = UINT16_C(0x0001); - constexpr ::std::uint_least16_t MAXIMUM_NETWORK_PORT = UINT16_C(0xFFFF); -} diff --git a/bowshock/include/bow/server.hxx b/bowshock/include/bow/server.hxx deleted file mode 100644 index 2fb0583..0000000 --- a/bowshock/include/bow/server.hxx +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#pragma once - -#include <bow/logic.hxx> - -#include <atomic> -#include <cstddef> -#include <cstdint> -#include <thread> - -namespace bow { - struct ServerConfiguration final { - ::std::uint_least16_t network_port; - }; - - struct ObjectElement final { - ::bow::Object* object; - ::bow::ObjectElement* next; - }; - - class ObjectRoot; - - class ObjectIterator final { - public: - ObjectIterator(::bow::ObjectRoot const& root) noexcept; - - ~ObjectIterator() noexcept = default; - - inline auto operator *() noexcept -> ::bow::Object& { return *this->element->object; } - inline auto operator *() const noexcept -> ::bow::Object const& { return *this->element->object; } - - auto operator ==(::bow::ObjectIterator const& other) const noexcept -> bool; - auto operator ==(::std::nullptr_t) const noexcept -> bool; - - auto operator ++() noexcept -> ::bow::ObjectIterator&; - - private: - ::bow::ObjectElement* element; - }; - - class ObjectRoot final { - public: - ObjectRoot() noexcept; - - ~ObjectRoot() noexcept; - - auto begin() const noexcept -> ::bow::ObjectIterator; - auto end() const noexcept -> ::bow::ObjectIterator; - - inline auto has_objects() const noexcept -> bool { return this->elements != nullptr; } - - template<::bow::ObjectLike T> - auto add(T const& value) -> T*; - - private: - friend ::bow::ObjectIterator; - - ::bow::ObjectElement* elements; - }; - - class ServerInstance final { - public: - explicit ServerInstance(::bow::ServerConfiguration const& configuration, ::std::atomic_flag* stop_flag) noexcept; - - static auto run(::bow::ServerInstance* server) noexcept -> void; - - private: - ::bow::ServerConfiguration configuration; - - ::std::atomic_flag* stop_flag; - - auto generate_system(::bow::ObjectRoot& system, ::std::uint64_t identifier, ::std::uint64_t time) -> void; - - auto gravitate(::bow::ObjectRoot& system) noexcept -> void; - auto gravitate(::bow::ObjectRoot& objects, ::bow::ObjectRoot const& system) noexcept -> void; - - auto move(::bow::ObjectRoot& root) noexcept -> void; - - auto simulate(::bow::ObjectRoot& system, ::std::uint64_t duration) noexcept -> void; - - auto loop() -> void; - }; - - class Server final { - public: - static auto start(::bow::ServerConfiguration const& configuration) -> ::bow::Server*; - - ~Server() noexcept; - - private: - Server() noexcept = default; - - ::std::thread* thread; - - ::bow::ServerInstance* instance; - - ::std::atomic_flag* stop_flag; - }; - - auto start_server() -> ::bow::Server; - - auto stop_server(::bow::ServerInstance& server) -> void; -} - -template<> -auto bow::ObjectRoot::add<::bow::Object>(::bow::Object const& object_value) -> ::bow::Object* = delete; diff --git a/bowshock/shader/main.frag.glsl b/bowshock/shader/main.frag.glsl deleted file mode 100644 index e539ab5..0000000 --- a/bowshock/shader/main.frag.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#version 150 core - -out vec4 colour; - -void main() { - colour = vec4(0.7137f, 0.0941f, 0.2000f, 1.0f); -} diff --git a/bowshock/shader/main.vert.glsl b/bowshock/shader/main.vert.glsl deleted file mode 100644 index 3737735..0000000 --- a/bowshock/shader/main.vert.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#version 150 core - -in vec3 position; - -void main() { - gl_Position = vec4(position.x, position.y, position.z, 1.0f); -} diff --git a/bowshock/source/application/Application/constructor.cxx b/bowshock/source/application/Application/constructor.cxx deleted file mode 100644 index 7f1f31b..0000000 --- a/bowshock/source/application/Application/constructor.cxx +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> -#include <bow/client.hxx> -#include <bow/network.hxx> - -#include <cstdlib> -#include <format> -#include <string> -#include <vector> - -using namespace ::std::literals::string_literals; - -bow::Application::Application(int const argc, char const* const* const argv) noexcept { - ::bow::log("app"s, "configuring application"s); - - auto const program_name = [&argc, argv]() -> ::std::string { - if (argc < 0x1) [[unlikely]] { - ::bow::terminate("app"s, "program not provided"s); - } else { - return ::std::string(*argv); - } - }(); - - this->client_configuration = ::bow::ClientConfiguration { - .directory = ""s, - .save_name = "save"s, - .network_port = ::bow::DEFAULT_NETWORK_PORT, - .new_save = false, - .skip_start_sequence = false, - }; - - this->server_configuration = ::bow::ServerConfiguration { - .network_port = ::bow::DEFAULT_NETWORK_PORT, - }; - - this->client = nullptr; - this->server = nullptr; - - ::std::vector<char const*> parameters(argv + 0x1u, argv + static_cast<::std::size_t>(argc)); - - this->parse_parameters(program_name, parameters); - - if (this->client_configuration.directory.empty()) [[likely]] { - auto const base_directory = ::bow::base_directory(); - - this->client_configuration.directory = base_directory + "/.bowshock"s; - } -} diff --git a/bowshock/source/application/Application/destructor.cxx b/bowshock/source/application/Application/destructor.cxx deleted file mode 100644 index daef5c1..0000000 --- a/bowshock/source/application/Application/destructor.cxx +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> - -#include <fmt/core.h> -#include <string> - -using namespace ::std::literals::string_literals; - -bow::Application::~Application() noexcept { - ::bow::log("app"s, "quitting"s); - - delete this->client; - delete this->server; - - ::fmt::print("\nGoodbye! \u2764\n"); -} diff --git a/bowshock/source/application/Application/get_quote.cxx b/bowshock/source/application/Application/get_quote.cxx deleted file mode 100644 index ac4494c..0000000 --- a/bowshock/source/application/Application/get_quote.cxx +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> - -#include <cstdint> -#include <format> -#include <stdexcept> -#include <string> -#include <tuple> - -using namespace ::std::literals::string_literals; - -auto bow::Application::get_quote(::std::uint8_t const identifier) -> ::std::tuple<::std::string, ::std::string> { - ::std::string quote = ""s; - ::std::string source = ""s; - - switch (identifier) { - default: - throw ::std::invalid_argument(::std::format("invalid quote identifier ({})", identifier)); - - case 0x0u: - quote = "You gotta be heaven to see heaven."; - source = "Jim Carrey"; - break; - - case 0x1u: - quote = "Though it's the end of the world, don't blame yourself, now."; - source = "Porter Robinson"; - break; - - case 0x2u: - quote = "The future will be better tomorrow."; - source = "Dan Quayle"; - break; - - case 0x3u: - quote = "Sir, an equation has no meaning for me unless it expresses a thought of god."; - source = "Srinivasa Ramanujan Aiyangar"; - break; - - case 0x4u: - quote = "Amīcus Platō amīcus Aristotelēs magis amīca vēritās."; - source = "Isaac Newton"; - break; - - case 0x5u: - quote = "I have studied these things \u2013 you have not."; - source = "Isaac Newton"; - break; - - case 0x6u: - quote = "La construction d'une machine propre à exprimer tous les sons de nos paroles,\n avec toutes les articulations, serait sans doute une décourverte bien\n importante.\n\u2026 La chose ne me paraît pas impossible."; - source = "Leonhard Euler"; - break; - - case 0x7u: - quote = "In mathematics, you don't understand things, you just get used to them."; - source = "John von Neumann"; - break; - - case 0x8u: - quote = "Being a language, mathematics may be used not only to inform, but also \u2013 among\n other things \u2013 to seduce."; - source = "Benoît B. Mandelbrot"; - break; - - case 0x9u: - quote = "The real question is not whether machines think, but whether men do."; - source = "Burrhus Frederic Skinner"; - break; - - case 0xAu: - quote = "Those who are not shocked when they first come across quantum theory cannot\n possibly have understood it."; - source = "Niels Henrik David Bohr"; - break; - - case 0xBu: - quote = "Every sentence I utter must be understood not as an affirmation, but as a\n question."; - source = "Niels Henrik David Bohr"; - break; - - case 0xCu: - quote = "We will now discuss in a little more detail the struggle for existence."; - source = "Charles Robert Darwin"; - break; - - case 0xDu: - quote = "Nam et ipsa scientia potestas est."; - source = "Francis Bacon"; - break; - - case 0xEu: - quote = "We don't know a millionth of one percent about anything."; - source = "Thomas Alva Edison"; - break; - - case 0xFu: - quote = "My goal is simple. It is a complete understanding of the universe, why it is as\n it is, and why it exists at all."; - source = "Stephen William Hawking"; - break; - - case 0x10u: - quote = "Equipped with his five senses, man explores the universe around him and calls\n the adventure Science."; - source = "Edwin Powell Hubble"; - break; - - case 0x11u: - quote = "I can say this: I believe that the human mind, or even the mind of a cat, is\n more interesting in its complexity than an entire galaxy if it is devoid of\n life."; - source = "Martin Gardner"; - break; - - case 0x12u: - quote = "I'm always right. This time I'm just more right than usual."; - source = "Linus Benedict Torvalds"; - break; - - case 0x13u: - quote = "I'm an instant star. Just add water and stir."; - source = "David Robert Jones"; - break; - - case 0x14u: - quote = "Don't waste the Earth \u2013 it is our jewel!"; - source = "Buzz Eugene Aldrin"; - break; - - case 0x15u: - quote = "I think we're going to the moon because it's in the nature of the human being to\n face challenges."; - source = "Neil Alden Armstrong"; - break; - - case 0x16u: - quote = "A hacker is someone who enjoys playful cleverness \u2013 not necessarily with\n computers."; - source = "Richard Matthew Stallman"; - break; - - case 0x17u: - quote = "So Einstein was wrong when he said \"God does not play dice.\". Consideration of\n black holes suggests, not only that God does play dice, but that he sometimes\n confuses us by throwing them where they can't be seen."; - source = "Stephen William Hawking"; - break; - - case 0x18u: - quote = "I'm a blackstar."; - source = "David Robert Jones"; - break; - - case 0x19u: - quote = "Sooner or later, we must expand life beyond our little blue mud ball\u2014or go\n extinct."; - source = "Elon Reeve Musk"; - break; - - case 0x1Au: - quote = "I would like to die on Mars \u2013 just not on impact."; - source = "Elon Reeve Musk"; - break; - - case 0x1Bu: - quote = "The web does not just connect computers; it connects people."; - source = "Timothy John Berners-Lee"; - break; - - case 0x1Cu: - quote = "Can digital computers think?"; - source = "Alan Mathison Turing"; - break; - - case 0x1Du: - quote = "That's one small step for a man, one giant leap for mankind."; - source = "Neil Alden Armstrong"; - break; - - case 0x1Eu: - quote = "If you think it's simple, then you have misunderstood the problem."; - source = "Bjarne Stroustrup"; - break; - - case 0x1Fu: - quote = "Controlling complexity is the essence of computer programming."; - source = "Brian Wilson Kerningham"; - break; - - case 0x20u: - quote = "I have always wished for my computer to be as easy to use as my telephone.\n My wish has come true because I can no longer figure out how to use my\n telephone."; - source = "Bjarne Stroustrup"; - break; - - case 0x21u: - quote = "There is no mathematical substitute for philosophy."; - source = "Saul Aaron Kripke"; - break; - - case 0x22u: - quote = "Biology is engineering."; - source = "Daniel Clement Dennett III"; - break; - - case 0x23u: - quote = "The universe is under no obligation to make sense to you."; - source = "Neil deGrasse Tyson"; - break; - } - - return ::std::make_tuple(quote, source); -} diff --git a/bowshock/source/application/Application/initialise_signal.cxx b/bowshock/source/application/Application/initialise_signal.cxx deleted file mode 100644 index 1e8196e..0000000 --- a/bowshock/source/application/Application/initialise_signal.cxx +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> - -#include <atomic> -#include <csignal> -#include <cstdlib> -#include <format> -#include <stdexcept> -#include <string> - -using namespace ::std::literals::string_literals; - -// 31.10.4. -// constexpr atomic_flag::atomic_flag() noexcept; -// Effects: Initializes *this to the clear state. -::std::atomic_flag bow::GOT_INTERRUPT; - -namespace bow { - static auto interrupt_handler(int const signal) -> void; -} - -static auto bow::interrupt_handler(int const signal) -> void { - // Ignore the return value: We canister't do anything (meaningful) about it anyways. - ::std::signal(signal, ::bow::interrupt_handler); - - ::bow::GOT_INTERRUPT.test_and_set(); -}; - -auto bow::Application::initialise_signal() -> void { - ::bow::log("app"s, "initialising signal handlers"s); - - auto const set_handler = []<typename Handler>(int const signal, Handler const& handler) -> void { - if (::std::signal(signal, static_cast<auto (*)(int) -> void>(handler)) == SIG_ERR) [[unlikely]] { - throw ::std::runtime_error(::std::format("unable to set signal handler for {}", signal)); - } - }; - - set_handler(SIGINT, ::bow::interrupt_handler); - set_handler(SIGTERM, ::bow::interrupt_handler); -} diff --git a/bowshock/source/application/Application/parse_parameters.cxx b/bowshock/source/application/Application/parse_parameters.cxx deleted file mode 100644 index 96540d6..0000000 --- a/bowshock/source/application/Application/parse_parameters.cxx +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> -#include <bow/client.hxx> -#include <bow/network.hxx> - -#include <charconv> -#include <format> -#include <stdexcept> -#include <string> -#include <string_view> -#include <system_error> -#include <vector> - -using namespace ::std::literals::string_literals; - -auto bow::Application::parse_parameters(::std::string const& program_name, ::std::vector<char const*> const& parameters) -> void { - ::bow::log("app"s, "parsing parameters"s); - - if (parameters.size() >= 0x1u) [[unlikely]] { - auto const parse = [&program_name, this](::std::string const& parameter) -> void { - if (auto const offset = parameter.find("="); offset != ::std::string::npos) { - auto const field = ::std::string_view(parameter.begin(), parameter.begin() + offset); - auto const value = ::std::string_view(parameter.begin() + offset + 0x1u, parameter.end()); - - if (field == "directory"s) { - ::bow::log("app"s, ::std::format("setting directory to \"{}\"", value)); - this->client_configuration.directory = value; - } else if (field == "port"s) { - auto const numeric_value = [&field, &value]() -> ::std::uint16_t { - ::std::uint_least16_t numeric_value = UINT16_C(0x0); - - auto const result = ::std::from_chars(value.begin(), value.end(), numeric_value); - - bool const out_of_range = - result.ec == ::std::errc::result_out_of_range - || numeric_value < ::bow::MINIMUM_NETWORK_PORT - || numeric_value > ::bow::MAXIMUM_NETWORK_PORT; - - if (out_of_range) [[unlikely]] { - ::bow::log("app"s, ::std::format("value ({}) for {} is out of range (min. is {}, max. is {})", value, field, ::bow::MINIMUM_NETWORK_PORT, ::bow::MAXIMUM_NETWORK_PORT)); - throw ::std::invalid_argument("value out of range"s); - } - - if (result.ec != ::std::errc()) [[unlikely]] { - ::bow::log("app"s, ::std::format("invalid value ({}) for {}", value, field)); - throw ::std::invalid_argument("invalid value"s); - } - - return numeric_value; - }(); - - ::bow::log("app"s, ::std::format("setting the port number to {}", numeric_value)); - this->client_configuration.network_port = numeric_value; - this->server_configuration.network_port = numeric_value; - } else if (field == "save"s) { - ::bow::log("app"s, ::std::format("setting save name to \"{}\"", value)); - this->client_configuration.save_name = value; - } else { - throw ::std::invalid_argument(::std::format("invalid field name \"{}\"", field)); - } - } else { - auto const flag = ::std::string_view(parameter.begin(), parameter.end()); - - if (flag == "credits"s) { - ::bow::Application::print_credits(); - } else if (flag == "help") { - ::bow::Application::print_help(program_name); - } else if (flag == "new") { - ::bow::log("app"s, "using default save file"s); - this->client_configuration.new_save = true; - } else if (flag == "skip") { - ::bow::log("app"s, "skipping start sequence"s); - this->client_configuration.skip_start_sequence = true; - } else { - throw ::std::invalid_argument(::std::format("invalid flag \"{}\"", flag)); - } - } - }; - - for (auto const parameter: parameters) { - parse(parameter); - } - } -} diff --git a/bowshock/source/application/Application/print_credits.cxx b/bowshock/source/application/Application/print_credits.cxx deleted file mode 100644 index 6a6f695..0000000 --- a/bowshock/source/application/Application/print_credits.cxx +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> - -#include <cstdio> -#include <cstdlib> -#include <filesystem> -#include <stdexcept> -#include <string> -#include <vector> - -using namespace ::std::literals::string_literals; - -auto bow::Application::print_credits() noexcept -> void { - ::std::string path = ::bow::DATA_DIRECTORY + "/CREDITS.txt"s; - - ::std::size_t const file_size = ::std::filesystem::file_size(path); - - ::std::FILE* file = ::std::fopen(path.c_str(), "r"); - - if (file == nullptr) [[unlikely]] { - ::bow::log("app"s, "unable to open credits file"s); - ::std::exit(EXIT_FAILURE); - } - - auto credits = [file_size]() noexcept -> ::std::vector<char> { - try { - return ::std::vector<char>(file_size + 0x2u); - } catch (...) { - ::bow::log("app"s, "unable to allocate memory for credits"s); - ::std::exit(EXIT_FAILURE); - } - }(); - - if (::std::fread(&credits.data()[0x1], sizeof (char), file_size, file) < file_size) [[unlikely]] { - ::bow::log("app"s, "unable to read credits file"s); - ::std::exit(EXIT_FAILURE); - } - - ::std::fclose(file); - - credits.front() = '\n'; - credits.back() = '\n'; - - ::std::fwrite(credits.data(), sizeof (char), file_size + 0x2u, stdout); - - credits.~vector(); - - ::std::exit(EXIT_SUCCESS); -} diff --git a/bowshock/source/application/Application/print_help.cxx b/bowshock/source/application/Application/print_help.cxx deleted file mode 100644 index 9b4f68f..0000000 --- a/bowshock/source/application/Application/print_help.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> - -#include <cstdlib> -#include <fmt/core.h> - -auto bow::Application::print_help(::std::string const& program_name) noexcept -> void { - ::fmt::print( - "\n" - "\x1B[1mBowshock\x1B[0m {:X}.{:X}.{:X}\n" - "Copyright \u00A9 2022\u20102023 \x1B[1mGabriel Bj\u00F8rnager Jensen\x1B[0m.\n" - "\n" - "Usage: \"{}\" <parameters> <flags>\n" - "\n" - "Parameters:\n" - " directory Set the application \x1B[1mdirectory\x1B[0m to be used\n" - " port Set the (decimal) \x1B[1mport\x1B[0m number used to connect to the server\n" - " save Set the \x1B[1mname\x1B[0m of the save file\n" - "\n" - "Flags:\n" - " credits Print the game \x1B[1mcredits\x1B[0m\n" - " help Print the \x1B[1mhelp\x1B[0m screen\n" - " new Start a \x1B[1mnew\x1B[0m save file\n" - " skip \x1B[1mskip\x1B[0m the intro\n" - "\n", - ::bow::VERSION.major, ::bow::VERSION.minor, ::bow::VERSION.patch, program_name - ); - - ::std::exit(EXIT_SUCCESS); -} diff --git a/bowshock/source/application/Application/run.cxx b/bowshock/source/application/Application/run.cxx deleted file mode 100644 index c09ce75..0000000 --- a/bowshock/source/application/Application/run.cxx +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> -#include <bow/client.hxx> -#include <bow/server.hxx> - -#include <cstdint> -#include <cstdio> -#include <cstdlib> -#include <ctime> -#include <fmt/core.h> -#include <format> -#include <stdexcept> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Application::run() -> int { - ::std::srand(static_cast<int unsigned>(::std::time(nullptr))); - - auto const quote_identifier = static_cast<::std::uint8_t>(::std::rand()) % ::bow::NUMBER_OF_QUOTE_IDENTIFIERS; - - // Print quote: - { - auto const quote_source = this->get_quote(quote_identifier); - - auto const quote = ::std::get<0x0>(quote_source); - auto const source = ::std::get<0x1>(quote_source); - - ::fmt::print("\n{}\n\u2014{}\n\n", quote, source); - } - - ::fmt::print( - stderr, - "\x1B[0m\x1B[1mBowshock\x1B[0m {:X}.{:X}.{:X} \u2013 Copyright \u00A9 2022\u20102023 \x1B[1mGabriel Bj\u00F8rnager Jensen\x1B[0m.\n\n", - ::bow::VERSION.major, ::bow::VERSION.minor, ::bow::VERSION.patch - ); - - if constexpr (::bow::DEBUG) { - ::bow::log("app"s, "debug mode is enabled"s); - } - - ::bow::log("app"s, ::std::format("data directory at \"{}\"", ::bow::DATA_DIRECTORY)); - - this->initialise_signal(); - - // The server handles all of its exceptions. - this->server = ::bow::Server::start(this->server_configuration); - - this->client = new ::bow::Client(this->client_configuration); - - // The client handles all of its exceptions. - this->client->run(); - - return 0x0; -} diff --git a/bowshock/source/base/base_directory.cxx b/bowshock/source/base/base_directory.cxx deleted file mode 100644 index b6b884a..0000000 --- a/bowshock/source/base/base_directory.cxx +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -#include <cstdlib> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::base_directory() noexcept -> ::std::string { - auto const pointer = ::std::getenv("HOME"); - - if (pointer == nullptr) [[unlikely]] { return "."s; } - - return ::std::string(pointer); -} diff --git a/bowshock/source/base/log.cxx b/bowshock/source/base/log.cxx deleted file mode 100644 index ecf7e09..0000000 --- a/bowshock/source/base/log.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/base.hxx> - -#include <cstdio> -#include <fmt/core.h> -#include <string> - -auto bow::log(::std::string const& location, ::std::string const& message) noexcept -> void { - ::fmt::print(stderr, "[{}] {}\n", location, message); -} diff --git a/bowshock/source/base/terminate.cxx b/bowshock/source/base/terminate.cxx deleted file mode 100644 index 94e1ed6..0000000 --- a/bowshock/source/base/terminate.cxx +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/base.hxx> - -#include <cstdlib> -#include <cstdio> -#include <fmt/core.h> -#include <string> - -auto bow::terminate(::std::string const& location, ::std::string const& message) noexcept -> void { - ::fmt::print(stderr, "[{}] terminate due to: {}\n", location, message); - - ::std::abort(); -} diff --git a/bowshock/source/client/Client/constructor.cxx b/bowshock/source/client/Client/constructor.cxx deleted file mode 100644 index 3d8fd5b..0000000 --- a/bowshock/source/client/Client/constructor.cxx +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> -#include <bow/logic.hxx> - -#include <filesystem> -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -bow::Client::Client(::bow::ClientConfiguration const& configuration) { - ::bow::log("client"s, "initialising"s); - - this->configuration = configuration; - - ::bow::log("client"s, ::std::format("creating configuration directory at {}", this->configuration.directory)); - ::std::filesystem::create_directory(this->configuration.directory); - ::std::filesystem::create_directory(this->configuration.directory + "/save"s); - - if (this->configuration.new_save) { - ::bow::log("client"s, "using default save"s); - } else { - this->player_data.load(::bow::Client::save_path(this->configuration.directory, this->configuration.save_name));; - } - - ::bow::log("client"s, ::std::format("welcome, CMDR {}", this->player_data.name)); -} diff --git a/bowshock/source/client/Client/destructor.cxx b/bowshock/source/client/Client/destructor.cxx deleted file mode 100644 index 3e5d12e..0000000 --- a/bowshock/source/client/Client/destructor.cxx +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -::bow::Client::~Client() noexcept { -} diff --git a/bowshock/source/client/Client/loop.cxx b/bowshock/source/client/Client/loop.cxx deleted file mode 100644 index 9dd618d..0000000 --- a/bowshock/source/client/Client/loop.cxx +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> -#include <bow/logic.hxx> - -#include <cmath> -#include <glad/glad.h> -#include <GLFW/glfw3.h> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Client::loop() -> void { - ::bow::log("client"s, "entering main loop"s); - - ::GLfloat vertices[] = { - -0x1.0000p0f, +0x1.0000p0f, 0x0p0f, - +0x1.0000p0f, +0x1.0000p0f, 0x0p0f, - +0x0.0000p0f, +0x0.0000p0f, 0x0p0f, - }; - - glBufferData(GL_ARRAY_BUFFER, sizeof (vertices), vertices, GL_STREAM_DRAW); - - glVertexAttribPointer(0x0, 0x3, GL_FLOAT, GL_FALSE, 0x3* sizeof (::GLfloat), nullptr); - glEnableVertexAttribArray(0x0); - - auto const scroll_handler = [](::GLFWwindow* const window, [[maybe_unused]] double const horizontal_offset, double const vertical_offset) -> void { - auto const data = static_cast<::bow::PlayerData*>(::glfwGetWindowUserPointer(window)); - - data->zoom *= ::std::pow(0x1.04p0f, -static_cast<float>(vertical_offset)); - }; - - ::glfwSetWindowUserPointer(this->renderer.window, &player_data); - ::glfwSetScrollCallback(this->renderer.window, scroll_handler); - - for (;;) { - if (this->poll_events()) [[unlikely]] { break; } - - ::GLfloat const frame = 0x1p0f * player_data.zoom; - - // Currently, we don't recieve any information from - // the server. - - //vertices[0x0] = static_cast<::GLfloat>(system_root.objects->next->position.x) / frame; - //vertices[0x1] = static_cast<::GLfloat>(system_root.objects->next->position.y) / frame; - //vertices[0x3] = static_cast<::GLfloat>(system_root.objects->position.x) / frame; - //vertices[0x4] = static_cast<::GLfloat>(system_root.objects->position.y) / frame; - //vertices[0x6] = static_cast<::GLfloat>(objects_root.objects->position.x) / frame; - //vertices[0x7] = static_cast<::GLfloat>(objects_root.objects->position.y) / frame; - - this->renderer.render(vertices, sizeof (vertices)); - } - - ::glfwSetScrollCallback(this->renderer.window, nullptr); - - glDeleteVertexArrays(0x1, &this->renderer.vao); - glDeleteBuffers(0x1, &this->renderer.vbo); - - this->player_data.save(::bow::Client::save_path(this->configuration.directory, this->configuration.save_name)); - -} diff --git a/bowshock/source/client/Client/poll_events.cxx b/bowshock/source/client/Client/poll_events.cxx deleted file mode 100644 index 50ad818..0000000 --- a/bowshock/source/client/Client/poll_events.cxx +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <GLFW/glfw3.h> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Client::poll_events() noexcept -> bool { - ::glfwPollEvents(); - - if (::bow::GOT_INTERRUPT.test()) [[unlikely]] { - ::bow::log("client"s, "got interrupt"s); - ::glfwSetWindowShouldClose(renderer.window, GLFW_TRUE); - } - - if (::glfwWindowShouldClose(renderer.window)) [[unlikely]] { return true; } - - return false; -} diff --git a/bowshock/source/client/Client/run.cxx b/bowshock/source/client/Client/run.cxx deleted file mode 100644 index 4f80cc7..0000000 --- a/bowshock/source/client/Client/run.cxx +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> -#include <bow/logic.hxx> - -#include <cmath> -#include <exception> -#include <format> -#include <glad/glad.h> -#include <GLFW/glfw3.h> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Client::run() noexcept -> void { - ::bow::log("client"s, "running"s); - - if (!this->configuration.skip_start_sequence) [[likely]] { - auto stop = false; - - if constexpr (!::bow::DEBUG) { - try { - stop = this->start_sequence(); - } catch (::std::exception const& exception) { - ::bow::terminate("client"s, ::std::format("got uncaught exception: {}", exception.what())); - } - } else { - stop = this->start_sequence(); - } - - if (stop) [[unlikely]] { return; } - } - - if constexpr (!::bow::DEBUG) { - try { - this->loop(); - } catch (::std::exception const& exception) { - ::bow::terminate("client"s, ::std::format("got uncaught exception: {}", exception.what())); - } - } else { - this->loop(); - } -} diff --git a/bowshock/source/client/Client/save_path.cxx b/bowshock/source/client/Client/save_path.cxx deleted file mode 100644 index bf5f8b2..0000000 --- a/bowshock/source/client/Client/save_path.cxx +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Client::save_path(::std::string const& directory, ::std::string const& name) noexcept -> ::std::string { - auto const path = directory + "/save/"s + name + ".bowshock"s; - - return path; -} diff --git a/bowshock/source/client/Client/start_sequence.cxx b/bowshock/source/client/Client/start_sequence.cxx deleted file mode 100644 index e1baf23..0000000 --- a/bowshock/source/client/Client/start_sequence.cxx +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <GLFW/glfw3.h> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Client::start_sequence() -> bool { - ::bow::log("client"s, "starting start sequence"s); - - auto exit = false; - - constexpr ::GLfloat bowshock_red = 0x1.6D6D6D6Ep-1f; - constexpr ::GLfloat bowshock_green = 0x1.81818182p-4f; - constexpr ::GLfloat bowshock_blue = 0x1.9999999Ap-3f; - - ::glfwSetTime(0x0p0); - for (double duration = 0x0p0; duration <= 0x3p0; duration = ::glfwGetTime()) { - if (poll_events()) [[unlikely]] break; - - glClearColor(bowshock_red, bowshock_green, bowshock_blue, 0x1p0); - glClear(GL_COLOR_BUFFER_BIT); - ::glfwSwapBuffers(renderer.window); - } - - double const fade_duration = 0x1p0; - ::glfwSetTime(0x0p0); - for (double factor = 0x0p0; factor <= fade_duration; factor = ::glfwGetTime()) { - if (poll_events()) [[unlikely]] { break; } - - ::GLfloat const red = bowshock_red * (0x1p0f - static_cast<::GLfloat>(factor) / static_cast<::GLfloat>(fade_duration)); - ::GLfloat const green = bowshock_green * (0x1p0f - static_cast<::GLfloat>(factor) / static_cast<::GLfloat>(fade_duration)); - ::GLfloat const blue = bowshock_blue * (0x1p0f - static_cast<::GLfloat>(factor) / static_cast<::GLfloat>(fade_duration)); - - glClearColor(red, green, blue, 0x1p0); - glClear(GL_COLOR_BUFFER_BIT); - ::glfwSwapBuffers(renderer.window); - } - - glClearColor(0x0p0f, 0x0p0f, 0x0p0f, 0x1p0f); - glClear(GL_COLOR_BUFFER_BIT); - ::glfwSwapBuffers(renderer.window); - - if (::glfwWindowShouldClose(renderer.window)) [[unlikely]] { exit = true; } - - return exit; -} diff --git a/bowshock/source/client/PlayerData/constructor.cxx b/bowshock/source/client/PlayerData/constructor.cxx deleted file mode 100644 index c1ffb03..0000000 --- a/bowshock/source/client/PlayerData/constructor.cxx +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> -#include <bow/logic.hxx> - -#include <cstdint> -#include <string> - -using namespace ::std::literals::string_literals; - -bow::PlayerData::PlayerData() noexcept { - ::bow::log("client"s, "generating player data"s); - - this->name = "Corneille"s; - this->time = UINT64_C(0x0); // 256 julian years after the Unix Epoch. - this->system_identifier = UINT64_C(0x0); - this->ship = ::bow::Ship(); - this->zoom = 0x4p0; -} diff --git a/bowshock/source/client/PlayerData/decode_save.cxx b/bowshock/source/client/PlayerData/decode_save.cxx deleted file mode 100644 index a4f57ef..0000000 --- a/bowshock/source/client/PlayerData/decode_save.cxx +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <array> -#include <cstdint> -#include <cstring> -#include <format> -#include <stdexcept> - -auto bow::PlayerData::decode_save(::bow::PlayerData & buffer, ::std::array<::std::uint8_t, ::bow::SAVE_LENGTH> const& source) -> void { - auto data = ::bow::PlayerData::SaveData { - .format_version = UINT64_C(0x0), - .commander_name = u8"\000\000\000\000\000\000\000\000\000\000\000\000\000\000", - .time = UINT64_C(0x0), - .system_identifier = UINT64_C(0x0), - .ship_type = UINT8_C(0x0), - .ship_position_x = 0x0p0, - .ship_position_y = 0x0p0, - .ship_position_z = 0x0p0, - .ship_rotation_x = 0x0p0, - .ship_rotation_y = 0x0p0, - .ship_rotation_z = 0x0p0, - .ship_positional_velocity_x = 0x0p0, - .ship_positional_velocity_y = 0x0p0, - .ship_positional_velocity_z = 0x0p0, - .ship_rotational_velocity_x = 0x0p0, - .ship_rotational_velocity_y = 0x0p0, - .ship_rotational_velocity_z = 0x0p0, - }; - - ::std::size_t index = 0x0u; - - auto const decode_value = [&index, &source]<typename T>(T& buffer) { - constexpr auto size = sizeof (T); - - ::std::memcpy(&buffer, &source[index], size); - index += size; - }; - - decode_value(data.format_version); - decode_value(data.commander_name); - decode_value(data.time); - decode_value(data.system_identifier); - decode_value(data.ship_type); - decode_value(data.ship_position_x); - decode_value(data.ship_position_y); - decode_value(data.ship_position_z); - decode_value(data.ship_rotation_x); - decode_value(data.ship_rotation_y); - decode_value(data.ship_rotation_z); - decode_value(data.ship_positional_velocity_x); - decode_value(data.ship_positional_velocity_y); - decode_value(data.ship_positional_velocity_z); - decode_value(data.ship_rotational_velocity_x); - decode_value(data.ship_rotational_velocity_y); - decode_value(data.ship_rotational_velocity_z); - - if (data.format_version != ::bow::SAVE_FORMAT_VERSION) [[unlikely]] { - throw ::std::invalid_argument(::std::format("invalid format ({:#04x}) of save file", data.format_version)); - } - - if (data.ship_type > ::bow::MAXIMUM_SHIP_IDENTIFIER) [[unlikely]] { - throw ::std::invalid_argument(::std::format("invalid ship type ({:#04x})\n", data.ship_type)); - } - - buffer.time = data.time, - buffer.system_identifier = data.system_identifier, - buffer.ship.type = static_cast<::bow::ShipType>(data.ship_type), - buffer.ship.position.x = data.ship_position_x, - buffer.ship.position.y = data.ship_position_y, - buffer.ship.position.z = data.ship_position_z, - buffer.ship.rotation.x = data.ship_rotation_x, - buffer.ship.rotation.y = data.ship_rotation_y, - buffer.ship.rotation.z = data.ship_rotation_z, - buffer.ship.positional_velocity.x = data.ship_positional_velocity_x, - buffer.ship.positional_velocity.y = data.ship_positional_velocity_y, - buffer.ship.positional_velocity.z = data.ship_positional_velocity_z, - buffer.ship.rotational_velocity.x = data.ship_rotational_velocity_x, - buffer.ship.rotational_velocity.y = data.ship_rotational_velocity_y, - buffer.ship.rotational_velocity.z = data.ship_rotational_velocity_z, - - buffer.name = ::std::string(reinterpret_cast<char *>(data.commander_name), ::bow::COMMANDER_NAME_LENGTH); -} diff --git a/bowshock/source/client/PlayerData/encode_save.cxx b/bowshock/source/client/PlayerData/encode_save.cxx deleted file mode 100644 index bdd7946..0000000 --- a/bowshock/source/client/PlayerData/encode_save.cxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <array> -#include <cstdint> -#include <cstring> - -auto bow::PlayerData::encode_save(::std::array<::std::uint8_t, ::bow::SAVE_LENGTH>& buffer, ::bow::PlayerData const& source) noexcept -> void { - auto data = ::bow::PlayerData::SaveData { - .format_version = ::bow::SAVE_FORMAT_VERSION, - .commander_name = u8"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", - .time = source.time, - .system_identifier = source.system_identifier, - .ship_type = static_cast<::std::uint8_t>(source.ship.type), - .ship_position_x = source.ship.position.x, - .ship_position_y = source.ship.position.y, - .ship_position_z = source.ship.position.z, - .ship_rotation_x = source.ship.rotation.x, - .ship_rotation_y = source.ship.rotation.y, - .ship_rotation_z = source.ship.rotation.z, - .ship_positional_velocity_x = source.ship.positional_velocity.x, - .ship_positional_velocity_y = source.ship.positional_velocity.y, - .ship_positional_velocity_z = source.ship.positional_velocity.z, - .ship_rotational_velocity_x = source.ship.rotational_velocity.x, - .ship_rotational_velocity_y = source.ship.rotational_velocity.y, - .ship_rotational_velocity_z = source.ship.rotational_velocity.z, - }; - - ::std::memcpy(&data.commander_name, source.name.data(), ::bow::COMMANDER_NAME_LENGTH); - - ::std::size_t index = 0x0u; - - auto const encode_value = [&buffer, &index]<typename T>(T const& value) { - constexpr auto size = sizeof (T); - - ::std::memcpy(&buffer[index], &value, size); - index += size; - }; - - encode_value(data.format_version); - encode_value(data.commander_name); - encode_value(data.time); - encode_value(data.system_identifier); - encode_value(data.ship_type); - encode_value(data.ship_position_x); - encode_value(data.ship_position_y); - encode_value(data.ship_position_z); - encode_value(data.ship_rotation_x); - encode_value(data.ship_rotation_y); - encode_value(data.ship_rotation_z); - encode_value(data.ship_positional_velocity_x); - encode_value(data.ship_positional_velocity_y); - encode_value(data.ship_positional_velocity_z); - encode_value(data.ship_rotational_velocity_x); - encode_value(data.ship_rotational_velocity_y); - encode_value(data.ship_rotational_velocity_z); -} diff --git a/bowshock/source/client/PlayerData/load.cxx b/bowshock/source/client/PlayerData/load.cxx deleted file mode 100644 index 5a94f39..0000000 --- a/bowshock/source/client/PlayerData/load.cxx +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> -#include <bow/logic.hxx> - -#include <array> -#include <cstdint> -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::PlayerData::load(::std::string const& path) -> void { - ::bow::log("client"s, ::std::format("loading save file at \"{}\"", path)); - - ::std::array<::std::uint8_t, ::bow::SAVE_LENGTH> raw; - - if (!this->read_file(raw, path)) [[likely]] { - this->decode_save(*this, raw); - - this->ship.mass = this->ship.net_mass(); - } -} diff --git a/bowshock/source/client/PlayerData/read_file.cxx b/bowshock/source/client/PlayerData/read_file.cxx deleted file mode 100644 index caf3f63..0000000 --- a/bowshock/source/client/PlayerData/read_file.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> -#include <bow/logic.hxx> - -#include <array> -#include <cstdint> -#include <cstdio> -#include <stdexcept> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::PlayerData::read_file(::std::array<::std::uint8_t, ::bow::SAVE_LENGTH>& buffer, ::std::string const& path) -> bool { - using ::bow::SAVE_LENGTH; - - auto const file = ::std::fopen(path.c_str(), "rb"); - - if (file == nullptr) [[unlikely]] { - ::bow::log("client"s, "unable to open save file, using default"s); - return true; - } - - if (::std::fread(buffer.data(), sizeof (::std::uint8_t), SAVE_LENGTH, file) < SAVE_LENGTH) [[unlikely]] { - throw ::std::runtime_error("unable to read save file"s); - } - - ::std::fclose(file); - - return false; -} diff --git a/bowshock/source/client/PlayerData/save.cxx b/bowshock/source/client/PlayerData/save.cxx deleted file mode 100644 index b9c5c0c..0000000 --- a/bowshock/source/client/PlayerData/save.cxx +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <array> -#include <cstdint> -#include <cstdio> -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::PlayerData::save(::std::string const& path) -> void { - using ::bow::SAVE_LENGTH; - - ::bow::log("client"s, ::std::format("saving CMDR {} at \"{}\"", this->name.data(), path)); - - ::std::array<::std::uint8_t, SAVE_LENGTH> data; - - ::bow::PlayerData::encode_save(data, *this); - - this->write_file(path, data); -} diff --git a/bowshock/source/client/PlayerData/write_file.cxx b/bowshock/source/client/PlayerData/write_file.cxx deleted file mode 100644 index 2a01e60..0000000 --- a/bowshock/source/client/PlayerData/write_file.cxx +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <array> -#include <cstdint> -#include <cstdio> -#include <stdexcept> - -auto bow::PlayerData::write_file(::std::string const& path, ::std::array<::std::uint8_t, ::bow::SAVE_LENGTH> const& data) -> void { - using ::bow::SAVE_LENGTH; - - auto const file = ::std::fopen(path.c_str(), "wb"); - if (file == nullptr) [[unlikely]] { - throw ::std::runtime_error("unable to create save file"); - } - - if (::std::fwrite(data.data(), 0x1u, SAVE_LENGTH, file) < SAVE_LENGTH) [[unlikely]] { - throw ::std::runtime_error("unable to write save file"); - } - - ::std::fclose(file); -} diff --git a/bowshock/source/client/Renderer/constructor.cxx b/bowshock/source/client/Renderer/constructor.cxx deleted file mode 100644 index 355bbd5..0000000 --- a/bowshock/source/client/Renderer/constructor.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <cstdlib> -#include <glad/glad.h> -#include <GLFW/glfw3.h> -#include <stdexcept> -#include <string> - -using namespace ::std::literals::string_literals; - -bow::Renderer::Renderer() { - ::bow::log("client"s, "initialising graphics"s); - - ::bow::log("client"s, "initialising glfw"s); - - if (!::glfwInit()) [[unlikely]] { - throw ::std::runtime_error("unable to initialise glfw"s); - } - - ::bow::log("client"s, "initialising window"s); - - ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 0x4); - ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0x1); - ::glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); - ::glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - ::glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); - ::glfwWindowHint(GLFW_SAMPLES, 0x8); - - this->window = ::glfwCreateWindow(0x400, 0x240, "Bowshock \u2011 Procyon", ::glfwGetPrimaryMonitor(), nullptr); - - if (this->window == nullptr) [[unlikely]] { - throw ::std::runtime_error("unable to open window"s); - } - - ::bow::log("client"s, "initialising context"s); - - ::glfwMakeContextCurrent(this->window); - ::gladLoadGL(); - - glEnable(GL_MULTISAMPLE); - - auto const video_mode = ::glfwGetVideoMode(::glfwGetPrimaryMonitor()); - - glViewport(0x0, 0x0, video_mode->width, video_mode->height); - glClearColor(0x0p0, 0x0p0, 0x0p0, 0x1p0); - glClear(GL_COLOR_BUFFER_BIT); - - ::glfwSwapBuffers(this->window); - ::glfwSwapInterval(0x1); - - this->shader_program = new ::bow::ShaderProgram("main"s); - - glGenVertexArrays(0x1, &this->vao); - glGenBuffers(0x1, &this->vbo); - - glBindVertexArray(this->vao); - glBindBuffer(GL_ARRAY_BUFFER, vbo); -} diff --git a/bowshock/source/client/Renderer/destructor.cxx b/bowshock/source/client/Renderer/destructor.cxx deleted file mode 100644 index 5d3aa8e..0000000 --- a/bowshock/source/client/Renderer/destructor.cxx +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <glad/glad.h> -#include <GLFW/glfw3.h> - -bow::Renderer::~Renderer() noexcept { - delete this->shader_program; - - ::glfwDestroyWindow(this->window); - ::glfwTerminate(); -} diff --git a/bowshock/source/client/Renderer/render.cxx b/bowshock/source/client/Renderer/render.cxx deleted file mode 100644 index 16ff4d4..0000000 --- a/bowshock/source/client/Renderer/render.cxx +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> -#include <bow/logic.hxx> - -#include <glad/glad.h> -#include <GLFW/glfw3.h> -#include <stdexcept> - -auto bow::Renderer::render(::GLfloat const vertices[], ::std::size_t const size) -> void { - glClearColor(0x0p0f, 0x0p0f, 0x0p0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - glBindBuffer(GL_ARRAY_BUFFER, this->vbo); - glBufferSubData(GL_ARRAY_BUFFER, 0x0, size, vertices); - - glUseProgram(this->shader_program->handle); - - glBindVertexArray(this->vao); - glDrawArrays(GL_TRIANGLES, 0x0, 0x3 * 0x1); - - ::glfwSwapBuffers(this->window); -} diff --git a/bowshock/source/client/ShaderProgram/compile_shader.cxx b/bowshock/source/client/ShaderProgram/compile_shader.cxx deleted file mode 100644 index 5f78e9f..0000000 --- a/bowshock/source/client/ShaderProgram/compile_shader.cxx +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <filesystem> -#include <format> -#include <glad/glad.h> -#include <stdexcept> -#include <string> -#include <vector> - -using namespace ::std::literals::string_literals; - -auto bow::ShaderProgram::compile_shader(::std::string const& name, ::bow::ShaderType const pretty_type) -> ::GLuint { - // Compile a shader according to the provided - // shader type. The path of the shader is - // calculated from the data directory path. - - auto const type = [pretty_type]() -> ::GLuint { - using ::bow::ShaderType; - - switch (pretty_type) { - case ShaderType::Fragment: - return GL_FRAGMENT_SHADER; - - case ShaderType::Geometry: - return GL_GEOMETRY_SHADER; - - case ShaderType::Vertex: - return GL_VERTEX_SHADER; - } - }(); - - auto const type_suffix = [type]() -> ::std::string { - switch (type) { - default: - // Until C++23: - ::__builtin_unreachable(); - - case GL_FRAGMENT_SHADER: - return "frag"s; - - case GL_GEOMETRY_SHADER: - return "geom"s; - - case GL_VERTEX_SHADER: - return "vert"s; - } - }(); - - auto const type_string = [type]() -> ::std::string { - switch (type) { - default: - ::__builtin_unreachable(); - - case GL_FRAGMENT_SHADER: - return "fragment"s; - - case GL_GEOMETRY_SHADER: - return "geometry"s; - - case GL_VERTEX_SHADER: - return "vertex"s; - } - }(); - - using ::bow::DATA_DIRECTORY; - - auto const path = DATA_DIRECTORY + "/shaders/"s + name + "." + type_suffix + "."s + ::bow::SHADER_FILE_SUFFIX; - - ::bow::log("client"s, ::std::format("compiling {} shader at \"{}\"", type_string, path)); - - ::std::FILE* file = ::std::fopen(path.c_str(), "r"); - - auto const file_size = ::std::filesystem::file_size(path); - - static_assert(sizeof (::GLchar) == sizeof (char)); - auto source = ::std::vector<::GLchar>(file_size + 0x1u); - - if (::std::fread(source.data(), sizeof (::GLchar), file_size, file) < file_size) [[unlikely]] { - throw ::std::runtime_error("unable to read shader source"s); - } - - source.push_back('\x00'); - - auto const source_pointer = source.data(); - - auto shader = glCreateShader(type); - glShaderSource(shader, 0x1, const_cast<::GLchar const* const*>(&source_pointer), nullptr); - - glCompileShader(shader); - - ::GLint compilation_status = 0x0; - glGetShaderiv(shader, GL_COMPILE_STATUS, &compilation_status); - - if (compilation_status == GL_FALSE) [[unlikely]] { - ::GLint log_length = 0x0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length); - - auto log = new ::GLchar[static_cast<::std::size_t>(log_length)]; - - glGetShaderInfoLog(shader, log_length, nullptr, log); - - ::bow::log("client"s, "unable to compiler shader:"s); - - ::std::fwrite(log, 0x1u, static_cast<::std::size_t>(log_length), stderr); - - delete[] log; - - throw ::std::runtime_error("unable to compile shader"s); - } - - return shader; -} diff --git a/bowshock/source/client/ShaderProgram/constructor.cxx b/bowshock/source/client/ShaderProgram/constructor.cxx deleted file mode 100644 index 4292ef1..0000000 --- a/bowshock/source/client/ShaderProgram/constructor.cxx +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <format> -#include <glad/glad.h> -#include <string> - -using namespace ::std::literals::string_literals; - -bow::ShaderProgram::ShaderProgram(::std::string const& name) { - // Compile a shader program. Currently, this means - // compiling a vertex shader and an equivalent - // fragment shader, both with the name "name". Cf. - // compile_shader for more information. - - ::bow::log("client"s, ::std::format("compiling shader program \"{}\"", name)); - - // Ignore exceptions: - auto const vertex_shader = ::bow::ShaderProgram::compile_shader(name, ::bow::ShaderType::Vertex); - auto const fragment_shader = ::bow::ShaderProgram::compile_shader(name, ::bow::ShaderType::Fragment); - - this->handle = glCreateProgram(); - glAttachShader(handle, vertex_shader); - glAttachShader(handle, fragment_shader); - glLinkProgram(handle); - - glDeleteShader(vertex_shader); - glDeleteShader(fragment_shader); -} diff --git a/bowshock/source/client/ShaderProgram/destructor.cxx b/bowshock/source/client/ShaderProgram/destructor.cxx deleted file mode 100644 index f1356fa..0000000 --- a/bowshock/source/client/ShaderProgram/destructor.cxx +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/client.hxx> - -#include <glad/glad.h> - -::bow::ShaderProgram::~ShaderProgram() noexcept { - glDeleteProgram(this->handle); -} diff --git a/bowshock/source/logic/Canister/constructor.cxx b/bowshock/source/logic/Canister/constructor.cxx deleted file mode 100644 index cc40917..0000000 --- a/bowshock/source/logic/Canister/constructor.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -bow::Canister::Canister() noexcept { - this->object_type = ::bow::ObjectType::Canister; - - this->position.x = 0x0p0; - this->position.y = 0x0p0; - this->position.z = 0x0p0; - this->rotation.x = 0x0p0; - this->rotation.y = 0x0p0; - this->rotation.z = 0x0p0; - this->positional_velocity.x = 0x0p0; - this->positional_velocity.y = 0x0p0; - this->positional_velocity.z = 0x0p0; - this->rotational_velocity.x = 0x0p0; - this->rotational_velocity.y = 0x0p0; - this->rotational_velocity.z = 0x0p0; - this->mass = 0x0p0; - this->content = ::bow::Ware::Biowaste; - - this->mass = ::bow::ware_density(this->content) * 0x1p0; -} diff --git a/bowshock/source/logic/Canister/object_type_string.cxx b/bowshock/source/logic/Canister/object_type_string.cxx deleted file mode 100644 index ef8b8b4..0000000 --- a/bowshock/source/logic/Canister/object_type_string.cxx +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -#include <cstddef> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Canister::object_type_string() const noexcept -> ::std::string { - return "canister"s; -} diff --git a/bowshock/source/logic/Object/object_type_string.cxx b/bowshock/source/logic/Object/object_type_string.cxx deleted file mode 100644 index 8318f25..0000000 --- a/bowshock/source/logic/Object/object_type_string.cxx +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -#include <cstddef> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Object::object_type_string() const noexcept -> ::std::string { - return "object"s; -} diff --git a/bowshock/source/logic/Ship/constructor.cxx b/bowshock/source/logic/Ship/constructor.cxx deleted file mode 100644 index 8c1532e..0000000 --- a/bowshock/source/logic/Ship/constructor.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -bow::Ship::Ship() noexcept { - this->object_type = ::bow::ObjectType::Ship; - - this->position.x = 0x0p0; - this->position.y = 0x0p0; - this->position.z = 0x0p0; - this->rotation.x = 0x0p0; - this->rotation.y = 0x0p0; - this->rotation.z = 0x0p0; - this->positional_velocity.x = 0x0p0; - this->positional_velocity.y = 0x0p0; - this->positional_velocity.z = 0x0p0; - this->rotational_velocity.x = 0x0p0; - this->rotational_velocity.y = 0x0p0; - this->rotational_velocity.z = 0x0p0; - this->mass = 0x0p0; - this->type = ::bow::ShipType::Aquila; - - this->mass = this->net_mass(); -} diff --git a/bowshock/source/logic/Ship/net_mass.cxx b/bowshock/source/logic/Ship/net_mass.cxx deleted file mode 100644 index 352117c..0000000 --- a/bowshock/source/logic/Ship/net_mass.cxx +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -auto bow::Ship::net_mass() noexcept -> double { - double mass = ::bow::hull_mass(this->type); - - return mass; -} diff --git a/bowshock/source/logic/Ship/object_type_string.cxx b/bowshock/source/logic/Ship/object_type_string.cxx deleted file mode 100644 index c38f9fd..0000000 --- a/bowshock/source/logic/Ship/object_type_string.cxx +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -#include <cstddef> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Ship::object_type_string() const noexcept -> ::std::string { - return "ship"s; -} diff --git a/bowshock/source/logic/Star/constructor.cxx b/bowshock/source/logic/Star/constructor.cxx deleted file mode 100644 index 799fb38..0000000 --- a/bowshock/source/logic/Star/constructor.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -bow::Star::Star() noexcept { - this->object_type = ::bow::ObjectType::Star; - - this->position.x = 0x0p0; - this->position.y = 0x0p0; - this->position.z = 0x0p0; - this->rotation.x = 0x0p0; - this->rotation.y = 0x0p0; - this->rotation.z = 0x0p0; - this->positional_velocity.x = 0x0p0; - this->positional_velocity.y = 0x0p0; - this->positional_velocity.z = 0x0p0; - this->rotational_velocity.x = 0x0p0; - this->rotational_velocity.y = 0x0p0; - this->rotational_velocity.z = 0x0p0; - this->mass = 0x1p0; - this->type = ::bow::StarType::G; -} diff --git a/bowshock/source/logic/Star/object_type_string.cxx b/bowshock/source/logic/Star/object_type_string.cxx deleted file mode 100644 index 167a9ed..0000000 --- a/bowshock/source/logic/Star/object_type_string.cxx +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -#include <cstddef> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Star::object_type_string() const noexcept -> ::std::string { - return "star"s; -} diff --git a/bowshock/source/logic/Station/constructor.cxx b/bowshock/source/logic/Station/constructor.cxx deleted file mode 100644 index e2fd4a4..0000000 --- a/bowshock/source/logic/Station/constructor.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -bow::Station::Station() noexcept { - this->object_type = ::bow::ObjectType::Station; - - this->position.x = 0x0p0; - this->position.y = 0x0p0; - this->position.z = 0x0p0; - this->rotation.x = 0x0p0; - this->rotation.y = 0x0p0; - this->rotation.z = 0x0p0; - this->positional_velocity.x = 0x0p0; - this->positional_velocity.y = 0x0p0; - this->positional_velocity.z = 0x0p0; - this->rotational_velocity.x = 0x0p0; - this->rotational_velocity.y = 0x0p0; - this->rotational_velocity.z = 0x0p0; - this->mass = 0x0p0; - this->type = ::bow::StationType::Orbis; -} diff --git a/bowshock/source/logic/Station/object_type_string.cxx b/bowshock/source/logic/Station/object_type_string.cxx deleted file mode 100644 index 9991b41..0000000 --- a/bowshock/source/logic/Station/object_type_string.cxx +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -#include <cstddef> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::Station::object_type_string() const noexcept -> ::std::string { - return "station"s; -} diff --git a/bowshock/source/logic/World/constructor.cxx b/bowshock/source/logic/World/constructor.cxx deleted file mode 100644 index e7ec793..0000000 --- a/bowshock/source/logic/World/constructor.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -bow::World::World() noexcept { - this->object_type = ::bow::ObjectType::World; - - this->position.x = 0x0p0; - this->position.y = 0x0p0; - this->position.z = 0x0p0; - this->rotation.x = 0x0p0; - this->rotation.y = 0x0p0; - this->rotation.z = 0x0p0; - this->positional_velocity.x = 0x0p0; - this->positional_velocity.y = 0x0p0; - this->positional_velocity.z = 0x0p0; - this->rotational_velocity.x = 0x0p0; - this->rotational_velocity.y = 0x0p0; - this->rotational_velocity.z = 0x0p0; - this->mass = 0x1p0; - this->type = ::bow::WorldType::RockyWorld; -} diff --git a/bowshock/source/logic/World/object_type_string.cxx b/bowshock/source/logic/World/object_type_string.cxx deleted file mode 100644 index db05042..0000000 --- a/bowshock/source/logic/World/object_type_string.cxx +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -#include <cstddef> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::World::object_type_string() const noexcept -> ::std::string { - return "world"s; -} diff --git a/bowshock/source/logic/hull_mass.cxx b/bowshock/source/logic/hull_mass.cxx deleted file mode 100644 index 00b7c54..0000000 --- a/bowshock/source/logic/hull_mass.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -auto bow::hull_mass(::bow::ShipType const ship) noexcept -> double { - // Calculate the default hull mass of a ship type. - // This is negated by the ammount of damages hull, - // whose mass is ignored. - - using ::bow::ShipType; - - double mass = 0x0p0; - - switch (ship) { - default: - mass = 0x1p0; - break; - - case ShipType::Aquila: - mass = 0x100p0; - } - - return mass / ::bow::MASS_MODIFIER; -} diff --git a/bowshock/source/logic/ware_density.cxx b/bowshock/source/logic/ware_density.cxx deleted file mode 100644 index 97690a0..0000000 --- a/bowshock/source/logic/ware_density.cxx +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> - -auto bow::ware_density([[maybe_unused]] ::bow::Ware const ware) noexcept -> double { - double mass = 0x1p0; - - return mass / ::bow::MASS_MODIFIER; -} diff --git a/bowshock/source/main.cxx b/bowshock/source/main.cxx deleted file mode 100644 index 3105864..0000000 --- a/bowshock/source/main.cxx +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/application.hxx> - -int main(int const argc, char const* const* argv) { - auto application = ::bow::Application(argc, argv); - - return application.run(); -} diff --git a/bowshock/source/server/ObjectIterator/constructor.cxx b/bowshock/source/server/ObjectIterator/constructor.cxx deleted file mode 100644 index 0a9a88c..0000000 --- a/bowshock/source/server/ObjectIterator/constructor.cxx +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -bow::ObjectIterator::ObjectIterator(::bow::ObjectRoot const& root) noexcept { - this->element = root.elements; -} diff --git a/bowshock/source/server/ObjectIterator/operator_equality.cxx b/bowshock/source/server/ObjectIterator/operator_equality.cxx deleted file mode 100644 index ca86aca..0000000 --- a/bowshock/source/server/ObjectIterator/operator_equality.cxx +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -#include <cstddef> - -auto bow::ObjectIterator::operator ==(::bow::ObjectIterator const& other) const noexcept -> bool { - return this->element == other.element; -} - -auto bow::ObjectIterator::operator ==(::std::nullptr_t) const noexcept -> bool { - return this->element == nullptr; -} diff --git a/bowshock/source/server/ObjectIterator/operator_increment.cxx b/bowshock/source/server/ObjectIterator/operator_increment.cxx deleted file mode 100644 index deab4ff..0000000 --- a/bowshock/source/server/ObjectIterator/operator_increment.cxx +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -auto bow::ObjectIterator::operator ++() noexcept -> ::bow::ObjectIterator& { - this->element = this->element->next; - - return *this; -} diff --git a/bowshock/source/server/ObjectRoot/add.cxx b/bowshock/source/server/ObjectRoot/add.cxx deleted file mode 100644 index 6c835d6..0000000 --- a/bowshock/source/server/ObjectRoot/add.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -#include <cstdlib> -#include <cstring> -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -template<::bow::ObjectLike T> -auto bow::ObjectRoot::add(T const& object_value) -> T* { - ::bow::log("server"s, ::std::format("adding object of type {}", object_value.object_type_string())); - - // Ignore exceptions: - auto const element = new ::bow::ObjectElement; - element->object = new T; - *element->object = object_value; - - element->next = this->elements; - this->elements = element; - - return static_cast<T*>(element->object); -} - -template auto ::bow::ObjectRoot::add<::bow::Canister>(::bow::Canister const& object_value) -> ::bow::Canister*; -template auto ::bow::ObjectRoot::add<::bow::Ship>( ::bow::Ship const& object_value) -> ::bow::Ship*; -template auto ::bow::ObjectRoot::add<::bow::Star>( ::bow::Star const& object_value) -> ::bow::Star*; -template auto ::bow::ObjectRoot::add<::bow::Station>( ::bow::Station const& object_value) -> ::bow::Station*; -template auto ::bow::ObjectRoot::add<::bow::World>( ::bow::World const& object_value) -> ::bow::World*; diff --git a/bowshock/source/server/ObjectRoot/begin.cxx b/bowshock/source/server/ObjectRoot/begin.cxx deleted file mode 100644 index 3810f5d..0000000 --- a/bowshock/source/server/ObjectRoot/begin.cxx +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -auto bow::ObjectRoot::begin() const noexcept -> ::bow::ObjectIterator { - return ::bow::ObjectIterator(*this); -} diff --git a/bowshock/source/server/ObjectRoot/constructor.cxx b/bowshock/source/server/ObjectRoot/constructor.cxx deleted file mode 100644 index 50755c3..0000000 --- a/bowshock/source/server/ObjectRoot/constructor.cxx +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -bow::ObjectRoot::ObjectRoot() noexcept { - this->elements = nullptr; -} diff --git a/bowshock/source/server/ObjectRoot/destructor.cxx b/bowshock/source/server/ObjectRoot/destructor.cxx deleted file mode 100644 index 8cda2ce..0000000 --- a/bowshock/source/server/ObjectRoot/destructor.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -bow::ObjectRoot::~ObjectRoot() noexcept { - ::bow::log("server"s, "deleting objects"s); - - ::bow::ObjectElement* element; - ::bow::ObjectElement* next; - - for (element = this->elements; element != nullptr; element = next) { - ::bow::log("server"s, ::std::format("deleting object of type {}", element->object->object_type_string())); - - next = element->next; - delete element; - } -} diff --git a/bowshock/source/server/ObjectRoot/end.cxx b/bowshock/source/server/ObjectRoot/end.cxx deleted file mode 100644 index b461626..0000000 --- a/bowshock/source/server/ObjectRoot/end.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -auto bow::ObjectRoot::end() const noexcept -> ::bow::ObjectIterator { - auto iterator = ::bow::ObjectIterator(*this); - - while (++iterator != nullptr) {} - - return iterator; -} diff --git a/bowshock/source/server/ObjectRoot/operator_increment.cxx b/bowshock/source/server/ObjectRoot/operator_increment.cxx deleted file mode 100644 index a9ab381..0000000 --- a/bowshock/source/server/ObjectRoot/operator_increment.cxx +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -auto bow::ObjectIterator::operator ++() noexcept -> T& { - this->object = this->object->next; - - return *this; -} diff --git a/bowshock/source/server/Server/destructor.cxx b/bowshock/source/server/Server/destructor.cxx deleted file mode 100644 index ebf3e03..0000000 --- a/bowshock/source/server/Server/destructor.cxx +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -using namespace ::std::literals::string_literals; - -::bow::Server::~Server() noexcept { - ::bow::log("app"s, "stopping server"s); - - this->stop_flag->test_and_set(); - - // Wait for the server to submit. - this->thread->join(); - - delete this->stop_flag; - delete this->instance; - delete this->thread; -} diff --git a/bowshock/source/server/Server/start.cxx b/bowshock/source/server/Server/start.cxx deleted file mode 100644 index ca9b3db..0000000 --- a/bowshock/source/server/Server/start.cxx +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> -#include <bow/server.hxx> - -#include <atomic> -#include <thread> -#include <utility> - -using namespace ::std::literals::string_literals; - -auto bow::Server::start(::bow::ServerConfiguration const& configuration) -> ::bow::Server* { - ::bow::log("app"s, "starting server"s); - - auto stop_flag = new ::std::atomic_flag(); - - auto server = new ::bow::ServerInstance(configuration, stop_flag); - - auto thread = new ::std::thread(::bow::ServerInstance::run, server); - - auto const instance = new ::bow::Server; - - instance->thread = ::std::move(thread); - instance->instance = ::std::move(server); - instance->stop_flag = ::std::move(stop_flag); - - return instance; -} diff --git a/bowshock/source/server/ServerInstance/constructor.cxx b/bowshock/source/server/ServerInstance/constructor.cxx deleted file mode 100644 index 0ca263f..0000000 --- a/bowshock/source/server/ServerInstance/constructor.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -#include <atomic> - -::bow::ServerInstance::ServerInstance(::bow::ServerConfiguration const& configuration, ::std::atomic_flag* stop_flag) noexcept { - this->configuration = configuration; - - this->stop_flag = stop_flag; -} diff --git a/bowshock/source/server/ServerInstance/generate_system.cxx b/bowshock/source/server/ServerInstance/generate_system.cxx deleted file mode 100644 index 4b60867..0000000 --- a/bowshock/source/server/ServerInstance/generate_system.cxx +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> -#include <bow/server.hxx> - -#include <cstdint> -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::ServerInstance::generate_system(::bow::ObjectRoot& system, ::std::uint64_t const identifier, ::std::uint64_t const time) -> void { - ::bow::log("server"s, ::std::format("generating system ({:x})", identifier)); - - if (system.has_objects()) [[likely]] { - system.~ObjectRoot(); - } - - // Nb.: The following code is only temporary. - // Currently, every system has only an Earth-Sol - // orbit. - - system.add([]() -> ::bow::Star { - auto star = ::bow::Star(); - - star.mass = 0x1p0, - star.type = ::bow::StarType::G; - - return star; - }()); - - system.add([]() -> ::bow::World { - auto world = ::bow::World(); - - world.position.y = 0x1.F76F144Dp-1; - world.positional_velocity.x = 0x1.B2D06FF3p-23 * ::bow::TIME_MODIFIER; - world.rotational_velocity.z = 0x1.31DB66BBp-15; - world.mass = 0x1.931AFC649369998Fp-19, - world.type = ::bow::WorldType::RockyWorld; - - return world; - }()); - - this->simulate(system, time); -} diff --git a/bowshock/source/server/ServerInstance/gravitate.cxx b/bowshock/source/server/ServerInstance/gravitate.cxx deleted file mode 100644 index b3cdd0a..0000000 --- a/bowshock/source/server/ServerInstance/gravitate.cxx +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> -#include <bow/logic.hxx> - -#include <cmath> - -namespace bow { - static auto gravitate_single(::bow::Object& object, ::bow::Object const& parent) noexcept -> void { - // Gravitate a single object to its parent (the - // force is unilateral). - - // Calculate the distance between the two objects - // using the Pythagorean theorem: - // d = sqrt(a^2+b^2+c^2) - auto const distance_x = parent.position.x - object.position.x; - auto const distance_y = parent.position.y - object.position.y; - auto const distance_z = parent.position.z - object.position.z; - auto const distance = ::std::sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z); - - // Calculate the angle between the X and Y - // dimensions and the X and Z dimensions. - auto const angle_y = ::std::atan2(distance_y, distance_x); - auto const angle_z = ::std::atan2(distance_z, distance_x); - - // If two objects overlap - that is, they have a - // absolute spacing of zero, then we discard the - // accelerations. We use a value as it makes these - // function branchless. - auto const no_overlap = ::std::abs(distance) != 0x0p0; - - // Calculate the acceleration towards the parent - // object using Newtonian physics: - // a = (m/(s^2))G - auto const acceleration = parent.mass / (distance * distance) * ::bow::GRAVITY_VALUE * static_cast<double>(no_overlap); - - // Calculate the gained velocity on the three - // dimensions using trigonometry: - // x = cos(theta_y)*a - // y = sin(theta_y)*a - // z = sin(theta_z)*a - auto const velocity_x = ::std::cos(angle_y) * acceleration; - auto const velocity_y = ::std::sin(angle_y) * acceleration; - auto const velocity_z = ::std::sin(angle_z) * acceleration; - - // Append the gained velocities to the existing - // velocities. - object.positional_velocity.x += velocity_x; - object.positional_velocity.y += velocity_y; - object.positional_velocity.z += velocity_z; - } - - static void gravitate_pair(::bow::Object& object0, ::bow::Object& object1) noexcept { - // Gravitate a pair of objects to each other (the - // force is mutual). Cf. gravitate_single. - - auto const distance_x = object1.position.x - object0.position.x; - auto const distance_y = object1.position.y - object0.position.y; - auto const distance_z = object1.position.z - object0.position.z; - auto const distance = ::std::sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z); - - auto const angle_y = ::std::atan2(distance_y, distance_x); - auto const angle_z = ::std::atan2(distance_z, distance_x); - - auto const no_overlap = ::std::abs(distance) != 0x0p0; - - auto acceleration0 = ::bow::GRAVITY_VALUE / (distance * distance); - auto const acceleration1 = acceleration0 * object0.mass * static_cast<double>(no_overlap); // This is negative. - acceleration0 *= object1.mass * static_cast<double>(no_overlap); - - auto velocity_x0 = ::std::cos(angle_y); - auto velocity_y0 = ::std::sin(angle_y); - auto velocity_z0 = ::std::sin(angle_z); - auto const velocity_x1 = velocity_x0 * acceleration1; - auto const velocity_y1 = velocity_y0 * acceleration1; - auto const velocity_z1 = velocity_z0 * acceleration1; - velocity_x0 *= acceleration0; - velocity_y0 *= acceleration0; - velocity_z0 *= acceleration0; - - object0.positional_velocity.x += velocity_x0; - object0.positional_velocity.y += velocity_y0; - object0.positional_velocity.z += velocity_z0; - - object1.positional_velocity.x -= velocity_x1; - object1.positional_velocity.y -= velocity_y1; - object1.positional_velocity.z -= velocity_z1; - } -} - -auto bow::ServerInstance::gravitate(::bow::ObjectRoot& system) noexcept -> void { - for (auto& object0: system) { - for (auto& object1: system) { - ::bow::gravitate_pair(object0, object1); - } - } -} - -auto bow::ServerInstance::gravitate(::bow::ObjectRoot& objects, ::bow::ObjectRoot const& system) noexcept -> void { - for (auto& object0: objects) { - for (auto const& object1: system) { - ::bow::gravitate_single(object0, object1); - } - } -} diff --git a/bowshock/source/server/ServerInstance/loop.cxx b/bowshock/source/server/ServerInstance/loop.cxx deleted file mode 100644 index d4e9c46..0000000 --- a/bowshock/source/server/ServerInstance/loop.cxx +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> -#include <bow/logic.hxx> - -#include <cmath> -#include <stdexcept> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::ServerInstance::loop() -> void { - ::bow::log("server"s, "entering main loop"s); - - // For stellar bodies: - auto system_root = ::bow::ObjectRoot(); - - // For miscellaneous objects (canisters, ships, etc.): - auto objects_root = ::bow::ObjectRoot(); - - this->generate_system(system_root, 0x0u, 0x0u); - - objects_root.add([]() -> ::bow::Canister { - auto canister = ::bow::Canister(); - - canister.position.y = -0x2p0; - canister.positional_velocity.x = -0x1p-12; - - return canister; - }()); - - while (!this->stop_flag->test() && !::bow::GOT_INTERRUPT.test()) { - this->gravitate(system_root); - this->gravitate(objects_root, system_root); - - this->move(system_root); - this->move(objects_root); - } - - ::bow::log("server"s, "submitting"s); -} diff --git a/bowshock/source/server/ServerInstance/move.cxx b/bowshock/source/server/ServerInstance/move.cxx deleted file mode 100644 index 232523e..0000000 --- a/bowshock/source/server/ServerInstance/move.cxx +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> -#include <bow/logic.hxx> - -auto bow::ServerInstance::move(::bow::ObjectRoot& root) noexcept -> void { - for (auto& object: root) { - // Apply the velocities of each object to their - // position: - // x = x+v_x - // y = y+v_x - // z = z+v_x - object.position.x += object.positional_velocity.x; - object.position.y += object.positional_velocity.y; - object.position.z += object.positional_velocity.z; - object.rotation.x += object.rotational_velocity.x; - object.rotation.y += object.rotational_velocity.y; - object.rotation.z += object.rotational_velocity.z; - } -} diff --git a/bowshock/source/server/ServerInstance/run.cxx b/bowshock/source/server/ServerInstance/run.cxx deleted file mode 100644 index 37613c8..0000000 --- a/bowshock/source/server/ServerInstance/run.cxx +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/server.hxx> - -#include <exception> -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::ServerInstance::run(::bow::ServerInstance* server) noexcept -> void { - ::bow::log("server"s, ::std::format("angle unit: {:.3f} rad", 0x1p0)); - ::bow::log("server"s, ::std::format("distance unit: {:.3f} m", ::bow::DISTANCE_MODIFIER)); - ::bow::log("server"s, ::std::format("mass unit: {:.3f} kg", ::bow::MASS_MODIFIER)); - ::bow::log("server"s, ::std::format("time unit: {:.3f} s", ::bow::TIME_MODIFIER)); - ::bow::log("server"s, ::std::format("gravitational constant: {:.9f} (factor: {:.3f}s))", ::bow::GRAVITY_VALUE, ::bow::GRAVITY_FACTOR)); - - if constexpr (!::bow::DEBUG) { - try { - server->loop(); - } catch (::std::exception const& exception) { - ::bow::terminate("server"s, ::std::format("got uncaught exception: {}", exception.what())); - } catch (...) { - ::bow::terminate("server"s, "got uncaught exception"s); - } - } else { - server->loop(); - } -} diff --git a/bowshock/source/server/ServerInstance/simulate.cxx b/bowshock/source/server/ServerInstance/simulate.cxx deleted file mode 100644 index 9e2f44f..0000000 --- a/bowshock/source/server/ServerInstance/simulate.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2022-2023 Gabriel Bjørnager Jensen. - -#include <bow/logic.hxx> -#include <bow/server.hxx> - -#include <cstdint> -#include <format> -#include <string> - -using namespace ::std::literals::string_literals; - -auto bow::ServerInstance::simulate(::bow::ObjectRoot& system, ::std::uint64_t const duration) noexcept -> void { - ::bow::log("server"s, ::std::format("simulating for ({}) time units", duration)); - - for (auto i = UINT64_C(0x0); i <= duration; ++i) { - // Do a minimal simulation of the target system for - // n-units of time. This is for consistency when - // loading a system at the same in-game time. - this->gravitate(system); - this->move(system); - } -} diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000..1c8e411 --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "bowshock-client" +edition = "2021" + +version.workspace = true +authors.workspace = true +readme.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +bowshock = { path = "../core" } + +[lints] +workspace = true diff --git a/client/src/main.rs b/client/src/main.rs new file mode 100644 index 0000000..2235f75 --- /dev/null +++ b/client/src/main.rs @@ -0,0 +1,3 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +fn main() { } diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 0000000..c55e42b --- /dev/null +++ b/core/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "bowshock" +edition = "2021" + +version.workspace = true +authors.workspace = true +readme.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +bzipper = "0.5.2" + +[lints] +workspace = true diff --git a/core/src/lib.rs b/core/src/lib.rs new file mode 100644 index 0000000..343623c --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,9 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +#[macro_export] +macro_rules! use_mod { + ($vis:vis $name:ident) => { + mod $name; + use $name::*; + }; +} diff --git a/extractGlad.sh b/extractGlad.sh deleted file mode 100755 index 4a3aa79..0000000 --- a/extractGlad.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -echo extracting GLAD... - -if ! [ -z "${1}" ] -then - archive="${1}" -else - archive="glad.zip" -fi - -if ! [ -e "${archive}" ] -then - echo "failure: unable to access file \"${archive}\"" - exit 1 -fi - -unzip -od"glad" "${archive}" -cp -v "glad.CMakeLists.txt" "glad/CMakeLists.txt" - -echo success diff --git a/glad.CMakeLists.txt b/glad.CMakeLists.txt deleted file mode 100644 index 0ec0384..0000000 --- a/glad.CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -cmake_minimum_required(VERSION 3.21) - -set(CMAKE_C_STANDARD 99) - -add_library( - glad STATIC - - "src/glad.c" -) - -target_include_directories( - glad PUBLIC - - "include" -) - -if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang|GNU") - target_compile_options( - glad PRIVATE - - $<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,-Og,-Ofast> - -fdiagnostics-color=always - -g - ) -elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - target_compile_options( - glad PRIVATE - - /O2 - $<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,/Zo> - ) -endif() diff --git a/install.sh b/install.sh deleted file mode 100755 index 1e8dd22..0000000 --- a/install.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/sh - -installBinary() { - buildDirectory="${1}" - binaryDirectory="${2}" - - mkdir -pvm755 "${binaryDirectory}" - - install -vm755 "${buildDirectory}/bowshock/bowshock" "${binaryDirectory}"/bowshock -} - -installData() { - sourceDirectory="${1}" - dataDirectory="${2}" - - mkdir -pvm755 "${dataDirectory}/shaders" - - install -vm644 "${sourceDirectory}/CHANGELOG.md" "${dataDirectory}" - install -vm644 "${sourceDirectory}/CREDITS.txt" "${dataDirectory}" - install -vm644 "${sourceDirectory}/bowshock/shader/"*".glsl" "${dataDirectory}/shaders" -} - -echo installing "${1}" - -if [ "${1}" == "data" ] -then - if [ -z "${2}" ] - then - echo failure: data directory is not set - exit 2 - fi - - sourceDirectory="${PWD}" - dataDirectory="${2}" - - installData "${sourceDirectory}" "${dataDirectory}" - - echo done - - exit 0 -elif [ "${1}" == "all" ] -then - if [ -z "${2}" ] - then - echo failure: build directory is not set - exit 3 - fi - - if [ -z "${3}" ] - then - echo failure: binary directory is not set - exit 2 - fi - - if [ -z "${4}" ] - then - echo failure: data directory is not set - exit 1 - fi - - sourceDirectory="${PWD}" - buildDirectory="${2}" - binaryDirectory="${3}" - dataDirectory="${4}" - - installBinary "${buildDirectory}" "${binaryDirectory}" - installData "${sourceDirectory}" "${dataDirectory}" -fi - -echo done diff --git a/server/Cargo.toml b/server/Cargo.toml new file mode 100644 index 0000000..8ff78a2 --- /dev/null +++ b/server/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "bowshock-server" +edition = "2021" + +version.workspace = true +authors.workspace = true +readme.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +bowshock = { path = "../core" } + +[lints] +workspace = true diff --git a/server/src/app/mod.rs b/server/src/app/mod.rs new file mode 100644 index 0000000..0ec083c --- /dev/null +++ b/server/src/app/mod.rs @@ -0,0 +1,10 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +mod run; + +pub struct App; + +impl App { + #[must_use] + pub fn new() -> Self { Self } +} diff --git a/server/src/app/run.rs b/server/src/app/run.rs new file mode 100644 index 0000000..f04e42f --- /dev/null +++ b/server/src/app/run.rs @@ -0,0 +1,9 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use crate::App; + +impl App { + pub fn run(self) -> Result<(), i32> { + Ok(()) + } +} diff --git a/server/src/main.rs b/server/src/main.rs new file mode 100644 index 0000000..33f011d --- /dev/null +++ b/server/src/main.rs @@ -0,0 +1,7 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use bowshock::use_mod; + +use_mod!(pub app); + +fn main() -> Result<(), i32> { App::new().run() } diff --git a/validateShaders.py b/validateShaders.py deleted file mode 100755 index d71a3e1..0000000 --- a/validateShaders.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python - -from subprocess import PIPE, run - -def validate(path: str): - print("validating \"", path, "\"... ", end='', sep='') - - path = "bowshock/shader/" + path + ".glsl" - program = "glslangValidator" - - status = run([program, path], stdout=PIPE) - - result = status.returncode - if result != 0x0: - print("\x1B[38;5;161merror\x1B[0m") - print() - print(status.stdout.decode("utf-8")) - quit(0x1) - - print("\x1B[38;5;77mokay\x1B[0m") - -if __name__ == "__main__": - print("validating shaders...") - - shaders = [ - "main.frag", - "main.vert", - ] - - for shader in shaders: - validate(shader) - - print("success") |