diff options
38 files changed, 199 insertions, 169 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 64810fa..ec62e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 0.C.0 +*0.C.0-10* + +* Update readme +* Add dependencies subsection to readme +* Add function for logging + *0.C.0-F* * Fix and update readme @@ -1,4 +1,4 @@ -BOWSHOCK 0.C.0-F +**BOWSHOCK 0.C.0-F** ![](https://mandelbrot.dk/logo/bowshock.svg) @@ -12,7 +12,7 @@ Bowshock uses CMake as its build system. The standard option `CMAKE_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 from a web instance. I use the one on `dav1d.de`, with the following settings: +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> @@ -28,6 +28,28 @@ Before running – however – the data directory must be installed. This can be ./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, it's either `glfw-wayland` (Arch) nor `glfw-x11` (Arch) can be used. + +### GLAD + +The GLAD loader must be downloaded from a web instance. I use the one on `dav1d.de`, with the following settings: + +<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: diff --git a/bowshock/CMakeLists.txt b/bowshock/CMakeLists.txt index 6553dc3..e52da7f 100644 --- a/bowshock/CMakeLists.txt +++ b/bowshock/CMakeLists.txt @@ -49,6 +49,7 @@ add_executable( "source/client/ShaderProgram/destructor.cxx" "source/base/base_directory.cxx" + "source/base/log.cxx" "source/base/terminate.cxx" "source/logic/Canister/constructor.cxx" diff --git a/bowshock/include/bow/application.hxx b/bowshock/include/bow/application.hxx index 0965730..f7a4146 100644 --- a/bowshock/include/bow/application.hxx +++ b/bowshock/include/bow/application.hxx @@ -22,7 +22,7 @@ namespace bow { .patch = 0x0u, }; - class Application { + class Application final { public: explicit Application(int argc, char const* const* argv) noexcept; diff --git a/bowshock/include/bow/base.hxx b/bowshock/include/bow/base.hxx index 3691019..448f255 100644 --- a/bowshock/include/bow/base.hxx +++ b/bowshock/include/bow/base.hxx @@ -43,4 +43,6 @@ namespace bow { // 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 index cc71528..fcbe222 100644 --- a/bowshock/include/bow/client.hxx +++ b/bowshock/include/bow/client.hxx @@ -42,7 +42,7 @@ namespace bow { 0x7F ship_rotational_velocity_z 8 binary64 */ - struct ClientConfiguration { + struct ClientConfiguration final { ::std::string directory; ::std::string save_name; ::std::uint_least16_t network_port; @@ -50,7 +50,7 @@ namespace bow { bool skip_start_sequence: 0x1; }; - class PlayerData { + class PlayerData final { public: ::std::string name; ::std::uint64_t time; @@ -100,7 +100,7 @@ namespace bow { Vertex, }; - class ShaderProgram { + class ShaderProgram final { public: ::GLuint handle; @@ -114,7 +114,7 @@ namespace bow { static auto compile_shader(::std::string const& name, ::bow::ShaderType type) -> ::GLuint; }; - class Renderer { + class Renderer final { public: ::GLFWwindow* window; ::bow::ShaderProgram* shader_program; @@ -128,7 +128,7 @@ namespace bow { auto render(::GLfloat const vertices[], ::std::size_t size) -> void; }; - class Client { + class Client final { public: explicit Client(::bow::ClientConfiguration const& configuration); diff --git a/bowshock/include/bow/server.hxx b/bowshock/include/bow/server.hxx index 71136a4..2fb0583 100644 --- a/bowshock/include/bow/server.hxx +++ b/bowshock/include/bow/server.hxx @@ -10,18 +10,18 @@ #include <thread> namespace bow { - struct ServerConfiguration { + struct ServerConfiguration final { ::std::uint_least16_t network_port; }; - struct ObjectElement { + struct ObjectElement final { ::bow::Object* object; ::bow::ObjectElement* next; }; class ObjectRoot; - class ObjectIterator { + class ObjectIterator final { public: ObjectIterator(::bow::ObjectRoot const& root) noexcept; @@ -39,7 +39,7 @@ namespace bow { ::bow::ObjectElement* element; }; - class ObjectRoot { + class ObjectRoot final { public: ObjectRoot() noexcept; @@ -59,7 +59,7 @@ namespace bow { ::bow::ObjectElement* elements; }; - class ServerInstance { + class ServerInstance final { public: explicit ServerInstance(::bow::ServerConfiguration const& configuration, ::std::atomic_flag* stop_flag) noexcept; @@ -82,7 +82,7 @@ namespace bow { auto loop() -> void; }; - class Server { + class Server final { public: static auto start(::bow::ServerConfiguration const& configuration) -> ::bow::Server*; diff --git a/bowshock/source/application/Application/constructor.cxx b/bowshock/source/application/Application/constructor.cxx index 7644720..7f1f31b 100644 --- a/bowshock/source/application/Application/constructor.cxx +++ b/bowshock/source/application/Application/constructor.cxx @@ -4,20 +4,19 @@ #include <bow/client.hxx> #include <bow/network.hxx> -#include <cstdio> #include <cstdlib> -#include <fmt/core.h> +#include <format> #include <string> #include <vector> using namespace ::std::literals::string_literals; bow::Application::Application(int const argc, char const* const* const argv) noexcept { - ::fmt::print(stderr, "[app] configuring application\n"); + ::bow::log("app"s, "configuring application"s); auto const program_name = [&argc, argv]() -> ::std::string { if (argc < 0x1) [[unlikely]] { - ::bow::terminate("app", "program not provided"); + ::bow::terminate("app"s, "program not provided"s); } else { return ::std::string(*argv); } @@ -35,8 +34,8 @@ bow::Application::Application(int const argc, char const* const* const argv) noe .network_port = ::bow::DEFAULT_NETWORK_PORT, }; - this->client =nullptr; - this->server =nullptr; + this->client = nullptr; + this->server = nullptr; ::std::vector<char const*> parameters(argv + 0x1u, argv + static_cast<::std::size_t>(argc)); diff --git a/bowshock/source/application/Application/destructor.cxx b/bowshock/source/application/Application/destructor.cxx index 51fdec5..daef5c1 100644 --- a/bowshock/source/application/Application/destructor.cxx +++ b/bowshock/source/application/Application/destructor.cxx @@ -2,14 +2,16 @@ #include <bow/application.hxx> -#include <cstdio> #include <fmt/core.h> +#include <string> + +using namespace ::std::literals::string_literals; bow::Application::~Application() noexcept { - ::fmt::print(stderr, "[app] quitting\n"); + ::bow::log("app"s, "quitting"s); delete this->client; delete this->server; - ::fmt::print(stderr, "\nGoodbye! \u2764\n"); + ::fmt::print("\nGoodbye! \u2764\n"); } diff --git a/bowshock/source/application/Application/initialise_signal.cxx b/bowshock/source/application/Application/initialise_signal.cxx index c2ebd4a..1e8196e 100644 --- a/bowshock/source/application/Application/initialise_signal.cxx +++ b/bowshock/source/application/Application/initialise_signal.cxx @@ -4,11 +4,12 @@ #include <atomic> #include <csignal> -#include <cstdio> #include <cstdlib> -#include <fmt/core.h> #include <format> #include <stdexcept> +#include <string> + +using namespace ::std::literals::string_literals; // 31.10.4. // constexpr atomic_flag::atomic_flag() noexcept; @@ -27,7 +28,7 @@ static auto bow::interrupt_handler(int const signal) -> void { }; auto bow::Application::initialise_signal() -> void { - ::fmt::print(stderr, "[app] initialising signal handlers\n"); + ::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]] { diff --git a/bowshock/source/application/Application/parse_parameters.cxx b/bowshock/source/application/Application/parse_parameters.cxx index 26b353f..96540d6 100644 --- a/bowshock/source/application/Application/parse_parameters.cxx +++ b/bowshock/source/application/Application/parse_parameters.cxx @@ -5,8 +5,6 @@ #include <bow/network.hxx> #include <charconv> -#include <cstdio> -#include <fmt/core.h> #include <format> #include <stdexcept> #include <string> @@ -17,7 +15,7 @@ using namespace ::std::literals::string_literals; auto bow::Application::parse_parameters(::std::string const& program_name, ::std::vector<char const*> const& parameters) -> void { - ::fmt::print(stderr, "[app] parsing parameters\n"); + ::bow::log("app"s, "parsing parameters"s); if (parameters.size() >= 0x1u) [[unlikely]] { auto const parse = [&program_name, this](::std::string const& parameter) -> void { @@ -25,10 +23,10 @@ auto bow::Application::parse_parameters(::std::string const& program_name, ::std 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") { - ::fmt::print(stderr, "[app] setting directory to \"{}\"\n", value); + if (field == "directory"s) { + ::bow::log("app"s, ::std::format("setting directory to \"{}\"", value)); this->client_configuration.directory = value; - } else if (field == "port") { + } else if (field == "port"s) { auto const numeric_value = [&field, &value]() -> ::std::uint16_t { ::std::uint_least16_t numeric_value = UINT16_C(0x0); @@ -40,43 +38,42 @@ auto bow::Application::parse_parameters(::std::string const& program_name, ::std || numeric_value > ::bow::MAXIMUM_NETWORK_PORT; if (out_of_range) [[unlikely]] { - ::fmt::print(stderr, "[app] value ({}) for {} is out of range (min. is {}, max. is {})\n", value, field, ::bow::MINIMUM_NETWORK_PORT, ::bow::MAXIMUM_NETWORK_PORT); - throw ::std::invalid_argument("value out of range"); + ::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]] { - ::fmt::print(stderr, "[app] invalid value ({}) for {}\n", value, field); - throw ::std::invalid_argument("invalid value"); + ::bow::log("app"s, ::std::format("invalid value ({}) for {}", value, field)); + throw ::std::invalid_argument("invalid value"s); } return numeric_value; }(); - ::fmt::print(stderr, "[app] setting the port number to {}\n", 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") { - ::fmt::print(stderr, "[app] setting save name to \"{}\"\n", 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 setting = ::std::string_view(parameter.begin(), parameter.end()); + auto const flag = ::std::string_view(parameter.begin(), parameter.end()); - if (setting == "credits") { + if (flag == "credits"s) { ::bow::Application::print_credits(); - } else if (setting == "help") { + } else if (flag == "help") { ::bow::Application::print_help(program_name); - } else if (setting == "new") { - ::fmt::print(stderr, "[app] using default save file\n"); + } else if (flag == "new") { + ::bow::log("app"s, "using default save file"s); this->client_configuration.new_save = true; - } else if (setting == "skip") { - ::fmt::print(stderr, "[app] skipping start sequence\n"); + } else if (flag == "skip") { + ::bow::log("app"s, "skipping start sequence"s); this->client_configuration.skip_start_sequence = true; } else { - ::fmt::print(stderr, "[app] invalid setting\"{}\"\n", setting); - throw ::std::invalid_argument("invalid setting"); + throw ::std::invalid_argument(::std::format("invalid flag \"{}\"", flag)); } } }; diff --git a/bowshock/source/application/Application/print_credits.cxx b/bowshock/source/application/Application/print_credits.cxx index 1136e05..6a6f695 100644 --- a/bowshock/source/application/Application/print_credits.cxx +++ b/bowshock/source/application/Application/print_credits.cxx @@ -5,20 +5,21 @@ #include <cstdio> #include <cstdlib> #include <filesystem> -#include <fmt/core.h> #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"; + ::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]] { - ::fmt::print(stderr, "[app] unable to open credits file\n"); - + ::bow::log("app"s, "unable to open credits file"s); ::std::exit(EXIT_FAILURE); } @@ -26,13 +27,13 @@ auto bow::Application::print_credits() noexcept -> void { try { return ::std::vector<char>(file_size + 0x2u); } catch (...) { - ::fmt::print(stderr, "[app] unable to allocate memory for credits\n"); + ::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]] { - ::fmt::print(stderr, "[app] unable to read credits file\n"); + ::bow::log("app"s, "unable to read credits file"s); ::std::exit(EXIT_FAILURE); } diff --git a/bowshock/source/application/Application/run.cxx b/bowshock/source/application/Application/run.cxx index ddbfed8..c09ce75 100644 --- a/bowshock/source/application/Application/run.cxx +++ b/bowshock/source/application/Application/run.cxx @@ -4,17 +4,16 @@ #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> -#include <tuple> -#include <format> +using namespace ::std::literals::string_literals; auto bow::Application::run() -> int { ::std::srand(static_cast<int unsigned>(::std::time(nullptr))); @@ -38,10 +37,10 @@ auto bow::Application::run() -> int { ); if constexpr (::bow::DEBUG) { - ::fmt::print("[app] debug mode is enabled\n"); + ::bow::log("app"s, "debug mode is enabled"s); } - ::fmt::print(stderr, "[app] data directory at \"{}\"\n", ::bow::DATA_DIRECTORY); + ::bow::log("app"s, ::std::format("data directory at \"{}\"", ::bow::DATA_DIRECTORY)); this->initialise_signal(); diff --git a/bowshock/source/base/base_directory.cxx b/bowshock/source/base/base_directory.cxx index 4d86ce4..b6b884a 100644 --- a/bowshock/source/base/base_directory.cxx +++ b/bowshock/source/base/base_directory.cxx @@ -2,9 +2,7 @@ #include <bow/logic.hxx> -#include <cstdio> #include <cstdlib> -#include <fmt/core.h> #include <string> using namespace ::std::literals::string_literals; @@ -12,10 +10,7 @@ using namespace ::std::literals::string_literals; auto bow::base_directory() noexcept -> ::std::string { auto const pointer = ::std::getenv("HOME"); - if (pointer == nullptr) [[unlikely]] { - ::fmt::print(stderr, "unable to get home directory - using current directory\n"); - return "."s; - } + if (pointer == nullptr) [[unlikely]] { return "."s; } return ::std::string(pointer); } diff --git a/bowshock/source/base/log.cxx b/bowshock/source/base/log.cxx new file mode 100644 index 0000000..ecf7e09 --- /dev/null +++ b/bowshock/source/base/log.cxx @@ -0,0 +1,11 @@ +// 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/client/Client/constructor.cxx b/bowshock/source/client/Client/constructor.cxx index 64407ea..3d8fd5b 100644 --- a/bowshock/source/client/Client/constructor.cxx +++ b/bowshock/source/client/Client/constructor.cxx @@ -3,27 +3,26 @@ #include <bow/client.hxx> #include <bow/logic.hxx> -#include <cstdio> #include <filesystem> -#include <fmt/core.h> +#include <format> #include <string> using namespace ::std::literals::string_literals; bow::Client::Client(::bow::ClientConfiguration const& configuration) { - ::fmt::print(stderr, "[client] initialising\n"); + ::bow::log("client"s, "initialising"s); this->configuration = configuration; - ::fmt::print(stderr, "[client] creating configuration directory at {}\n", this->configuration.directory); + ::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) { - ::fmt::print(stderr, "[client] using default save\n"); + ::bow::log("client"s, "using default save"s); } else { this->player_data.load(::bow::Client::save_path(this->configuration.directory, this->configuration.save_name));; } - ::fmt::print(stderr, "[client] welcome, CMDR {}\n", this->player_data.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 index a4224bc..3e5d12e 100644 --- a/bowshock/source/client/Client/destructor.cxx +++ b/bowshock/source/client/Client/destructor.cxx @@ -2,10 +2,5 @@ #include <bow/client.hxx> -#include <cstdio> -#include <cstdlib> -#include <fmt/core.h> -#include <GLFW/glfw3.h> - ::bow::Client::~Client() noexcept { } diff --git a/bowshock/source/client/Client/loop.cxx b/bowshock/source/client/Client/loop.cxx index 04df684..9dd618d 100644 --- a/bowshock/source/client/Client/loop.cxx +++ b/bowshock/source/client/Client/loop.cxx @@ -4,13 +4,14 @@ #include <bow/logic.hxx> #include <cmath> -#include <cstdio> -#include <fmt/core.h> #include <glad/glad.h> #include <GLFW/glfw3.h> +#include <string> + +using namespace ::std::literals::string_literals; auto bow::Client::loop() -> void { - ::fmt::print(stderr, "[client] entering main loop\n"); + ::bow::log("client"s, "entering main loop"s); ::GLfloat vertices[] = { -0x1.0000p0f, +0x1.0000p0f, 0x0p0f, diff --git a/bowshock/source/client/Client/poll_events.cxx b/bowshock/source/client/Client/poll_events.cxx index 8d3aac0..50ad818 100644 --- a/bowshock/source/client/Client/poll_events.cxx +++ b/bowshock/source/client/Client/poll_events.cxx @@ -2,15 +2,16 @@ #include <bow/client.hxx> -#include <cstdio> -#include <fmt/core.h> #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]] { - ::fmt::print(stderr, "got interrupt\n"); + ::bow::log("client"s, "got interrupt"s); ::glfwSetWindowShouldClose(renderer.window, GLFW_TRUE); } diff --git a/bowshock/source/client/Client/run.cxx b/bowshock/source/client/Client/run.cxx index f5327c2..4f80cc7 100644 --- a/bowshock/source/client/Client/run.cxx +++ b/bowshock/source/client/Client/run.cxx @@ -4,15 +4,16 @@ #include <bow/logic.hxx> #include <cmath> -#include <cstdio> #include <exception> -#include <fmt/core.h> #include <format> #include <glad/glad.h> #include <GLFW/glfw3.h> +#include <string> + +using namespace ::std::literals::string_literals; auto bow::Client::run() noexcept -> void { - ::fmt::print(stderr, "[client] running\n"); + ::bow::log("client"s, "running"s); if (!this->configuration.skip_start_sequence) [[likely]] { auto stop = false; @@ -21,7 +22,7 @@ auto bow::Client::run() noexcept -> void { try { stop = this->start_sequence(); } catch (::std::exception const& exception) { - ::bow::terminate("client", ::std::format("got uncaught exception: {}", exception.what())); + ::bow::terminate("client"s, ::std::format("got uncaught exception: {}", exception.what())); } } else { stop = this->start_sequence(); @@ -34,7 +35,7 @@ auto bow::Client::run() noexcept -> void { try { this->loop(); } catch (::std::exception const& exception) { - ::bow::terminate("client", ::std::format("got uncaught exception: {}", exception.what())); + ::bow::terminate("client"s, ::std::format("got uncaught exception: {}", exception.what())); } } else { this->loop(); diff --git a/bowshock/source/client/Client/start_sequence.cxx b/bowshock/source/client/Client/start_sequence.cxx index c1007a5..e1baf23 100644 --- a/bowshock/source/client/Client/start_sequence.cxx +++ b/bowshock/source/client/Client/start_sequence.cxx @@ -2,12 +2,13 @@ #include <bow/client.hxx> -#include <cstdio> -#include <fmt/core.h> #include <GLFW/glfw3.h> +#include <string> + +using namespace ::std::literals::string_literals; auto bow::Client::start_sequence() -> bool { - ::fmt::print(stderr, "[client] starting start sequence\n"); + ::bow::log("client"s, "starting start sequence"s); auto exit = false; diff --git a/bowshock/source/client/PlayerData/constructor.cxx b/bowshock/source/client/PlayerData/constructor.cxx index 695799a..c1ffb03 100644 --- a/bowshock/source/client/PlayerData/constructor.cxx +++ b/bowshock/source/client/PlayerData/constructor.cxx @@ -3,18 +3,13 @@ #include <bow/client.hxx> #include <bow/logic.hxx> -#include <array> #include <cstdint> -#include <cstdio> -#include <cstring> -#include <fmt/core.h> -#include <stdexcept> #include <string> using namespace ::std::literals::string_literals; -bow::PlayerData::PlayerData() noexcept { - ::fmt::print(stderr, "[client] generating player data\n"); +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. diff --git a/bowshock/source/client/PlayerData/encode_save.cxx b/bowshock/source/client/PlayerData/encode_save.cxx index 9b0f121..bdd7946 100644 --- a/bowshock/source/client/PlayerData/encode_save.cxx +++ b/bowshock/source/client/PlayerData/encode_save.cxx @@ -6,8 +6,6 @@ #include <cstdint> #include <cstring> -#include <fmt/core.h> - 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, diff --git a/bowshock/source/client/PlayerData/load.cxx b/bowshock/source/client/PlayerData/load.cxx index f120ffc..5a94f39 100644 --- a/bowshock/source/client/PlayerData/load.cxx +++ b/bowshock/source/client/PlayerData/load.cxx @@ -5,16 +5,13 @@ #include <array> #include <cstdint> -#include <cstdio> -#include <cstring> -#include <fmt/core.h> -#include <stdexcept> +#include <format> #include <string> using namespace ::std::literals::string_literals; auto bow::PlayerData::load(::std::string const& path) -> void { - ::fmt::print(stderr, "[client] loading save file at \"{}\"\n", path); + ::bow::log("client"s, ::std::format("loading save file at \"{}\"", path)); ::std::array<::std::uint8_t, ::bow::SAVE_LENGTH> raw; diff --git a/bowshock/source/client/PlayerData/read_file.cxx b/bowshock/source/client/PlayerData/read_file.cxx index c076d85..caf3f63 100644 --- a/bowshock/source/client/PlayerData/read_file.cxx +++ b/bowshock/source/client/PlayerData/read_file.cxx @@ -6,23 +6,23 @@ #include <array> #include <cstdint> #include <cstdio> -#include <fmt/core.h> #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]] { - ::fmt::print(stderr, "[client] unable to open save file, using default\n"); - + ::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"); + throw ::std::runtime_error("unable to read save file"s); } ::std::fclose(file); diff --git a/bowshock/source/client/PlayerData/save.cxx b/bowshock/source/client/PlayerData/save.cxx index b18313a..b9c5c0c 100644 --- a/bowshock/source/client/PlayerData/save.cxx +++ b/bowshock/source/client/PlayerData/save.cxx @@ -5,12 +5,15 @@ #include <array> #include <cstdint> #include <cstdio> -#include <fmt/core.h> +#include <format> +#include <string> + +using namespace ::std::literals::string_literals; auto bow::PlayerData::save(::std::string const& path) -> void { using ::bow::SAVE_LENGTH; - ::fmt::print(stderr, "[client] saving CMDR {} at \"{}\"\n", this->name.data(), path); + ::bow::log("client"s, ::std::format("saving CMDR {} at \"{}\"", this->name.data(), path)); ::std::array<::std::uint8_t, SAVE_LENGTH> data; diff --git a/bowshock/source/client/Renderer/constructor.cxx b/bowshock/source/client/Renderer/constructor.cxx index 287dd3c..355bbd5 100644 --- a/bowshock/source/client/Renderer/constructor.cxx +++ b/bowshock/source/client/Renderer/constructor.cxx @@ -2,23 +2,24 @@ #include <bow/client.hxx> -#include <cstdio> #include <cstdlib> -#include <fmt/core.h> #include <glad/glad.h> #include <GLFW/glfw3.h> #include <stdexcept> +#include <string> + +using namespace ::std::literals::string_literals; bow::Renderer::Renderer() { - ::fmt::print(stderr, "[client] initialising graphics\n"); + ::bow::log("client"s, "initialising graphics"s); - ::fmt::print(stderr, "[client] initialising glfw\n"); + ::bow::log("client"s, "initialising glfw"s); if (!::glfwInit()) [[unlikely]] { - throw ::std::runtime_error("unable to initialise glfw"); + throw ::std::runtime_error("unable to initialise glfw"s); } - ::fmt::print(stderr, "[client] initialising window\n"); + ::bow::log("client"s, "initialising window"s); ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 0x4); ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0x1); @@ -27,13 +28,13 @@ bow::Renderer::Renderer() { ::glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); ::glfwWindowHint(GLFW_SAMPLES, 0x8); - this->window = ::glfwCreateWindow(0x400, 0x240, "Bowshock", ::glfwGetPrimaryMonitor(), nullptr); + this->window = ::glfwCreateWindow(0x400, 0x240, "Bowshock \u2011 Procyon", ::glfwGetPrimaryMonitor(), nullptr); if (this->window == nullptr) [[unlikely]] { - throw ::std::runtime_error("unable to open window"); + throw ::std::runtime_error("unable to open window"s); } - ::fmt::print(stderr, "[client] initialising context\n"); + ::bow::log("client"s, "initialising context"s); ::glfwMakeContextCurrent(this->window); ::gladLoadGL(); @@ -49,7 +50,7 @@ bow::Renderer::Renderer() { ::glfwSwapBuffers(this->window); ::glfwSwapInterval(0x1); - this->shader_program = new ::bow::ShaderProgram("main"); + this->shader_program = new ::bow::ShaderProgram("main"s); glGenVertexArrays(0x1, &this->vao); glGenBuffers(0x1, &this->vbo); diff --git a/bowshock/source/client/ShaderProgram/compile_shader.cxx b/bowshock/source/client/ShaderProgram/compile_shader.cxx index f736868..40515e7 100644 --- a/bowshock/source/client/ShaderProgram/compile_shader.cxx +++ b/bowshock/source/client/ShaderProgram/compile_shader.cxx @@ -2,9 +2,8 @@ #include <bow/client.hxx> -#include <cstdio> #include <filesystem> -#include <fmt/core.h> +#include <format> #include <glad/glad.h> #include <stdexcept> #include <string> @@ -63,9 +62,9 @@ auto bow::ShaderProgram::compile_shader(::std::string const& name, ::bow::Shader using ::bow::DATA_DIRECTORY; - auto const path = DATA_DIRECTORY + "/shaders/" + name + "." + type_suffix + "." + ::bow::SHADER_FILE_SUFFIX; + auto const path = DATA_DIRECTORY + "/shaders/"s + name + "." + type_suffix + "."s + ::bow::SHADER_FILE_SUFFIX; - ::fmt::print(stderr, "[client] compiling {} shader at \"{}\"\n", type_string, path); + ::bow::log("client"s, ::std::format("compiling {} shader at \"{}\"", type_string, path)); ::std::FILE* file = ::std::fopen(path.c_str(), "r"); @@ -75,7 +74,7 @@ auto bow::ShaderProgram::compile_shader(::std::string const& name, ::bow::Shader 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"); + throw ::std::runtime_error("unable to read shader source"s); } source.push_back('\x00'); @@ -98,13 +97,13 @@ auto bow::ShaderProgram::compile_shader(::std::string const& name, ::bow::Shader glGetShaderInfoLog(shader, log_length, nullptr, log); - ::fmt::print(stderr, "[client] unable to compiler shader:\n"); + ::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"); + 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 index 043d017..95ad0af 100644 --- a/bowshock/source/client/ShaderProgram/constructor.cxx +++ b/bowshock/source/client/ShaderProgram/constructor.cxx @@ -2,21 +2,14 @@ #include <bow/client.hxx> -#include <cstdio> -#include <cstdlib> -#include <cstring> -#include <filesystem> -#include <fmt/core.h> +#include <format> #include <glad/glad.h> -#include <stdexcept> #include <string> -#include <type_traits> -#include <vector> using namespace ::std::literals::string_literals; bow::ShaderProgram::ShaderProgram(::std::string const& name) { - ::fmt::print(stderr, "[client] compiling shader program \"{}\"\n", name); + ::bow::log("client"s, ::std::format("compiling shader program \"{}\"", name)); // Ignore exceptions: auto const vertex_shader = ::bow::ShaderProgram::compile_shader(name, ::bow::ShaderType::Vertex); diff --git a/bowshock/source/logic/hull_mass.cxx b/bowshock/source/logic/hull_mass.cxx index 56938f4..11479a5 100644 --- a/bowshock/source/logic/hull_mass.cxx +++ b/bowshock/source/logic/hull_mass.cxx @@ -10,6 +10,8 @@ auto bow::hull_mass(::bow::ShipType const ship) noexcept -> double { switch (ship) { default: mass = 0x1p0; + break; + case ShipType::Aquila: mass = 0x100p0; } diff --git a/bowshock/source/server/ObjectRoot/add.cxx b/bowshock/source/server/ObjectRoot/add.cxx index 15778bf..6c835d6 100644 --- a/bowshock/source/server/ObjectRoot/add.cxx +++ b/bowshock/source/server/ObjectRoot/add.cxx @@ -2,14 +2,16 @@ #include <bow/server.hxx> -#include <cstdio> #include <cstdlib> #include <cstring> -#include <fmt/core.h> +#include <format> +#include <string> + +using namespace ::std::literals::string_literals; template<::bow::ObjectLike T> auto bow::ObjectRoot::add(T const& object_value) -> T* { - ::fmt::print(stderr, "[server] adding object of type {}\n", object_value.object_type_string()); + ::bow::log("server"s, ::std::format("adding object of type {}", object_value.object_type_string())); // Ignore exceptions: auto const element = new ::bow::ObjectElement; diff --git a/bowshock/source/server/ObjectRoot/destructor.cxx b/bowshock/source/server/ObjectRoot/destructor.cxx index dd1b4d3..8cda2ce 100644 --- a/bowshock/source/server/ObjectRoot/destructor.cxx +++ b/bowshock/source/server/ObjectRoot/destructor.cxx @@ -2,18 +2,19 @@ #include <bow/server.hxx> -#include <cstdio> -#include <fmt/core.h> -#include <type_traits> +#include <format> +#include <string> + +using namespace ::std::literals::string_literals; bow::ObjectRoot::~ObjectRoot() noexcept { - ::fmt::print(stderr, "[server] deleting objects\n"); + ::bow::log("server"s, "deleting objects"s); ::bow::ObjectElement* element; ::bow::ObjectElement* next; for (element = this->elements; element != nullptr; element = next) { - ::fmt::print(stderr, "[server] deleting object of type {}\n", element->object->object_type_string()); + ::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/Server/destructor.cxx b/bowshock/source/server/Server/destructor.cxx index 30b34b3..21c753e 100644 --- a/bowshock/source/server/Server/destructor.cxx +++ b/bowshock/source/server/Server/destructor.cxx @@ -2,11 +2,10 @@ #include <bow/server.hxx> -#include <cstdio> -#include <fmt/core.h> +using namespace ::std::literals::string_literals; ::bow::Server::~Server() noexcept { - ::fmt::print(stderr, "[app] stopping server\n"); + ::bow::log("app"s, "stopping server"s); this->stop_flag->test_and_set(); diff --git a/bowshock/source/server/Server/start.cxx b/bowshock/source/server/Server/start.cxx index 7647261..ca9b3db 100644 --- a/bowshock/source/server/Server/start.cxx +++ b/bowshock/source/server/Server/start.cxx @@ -4,13 +4,13 @@ #include <bow/server.hxx> #include <atomic> -#include <cstdio> -#include <fmt/core.h> #include <thread> #include <utility> +using namespace ::std::literals::string_literals; + auto bow::Server::start(::bow::ServerConfiguration const& configuration) -> ::bow::Server* { - ::fmt::print(stderr, "[app] starting server\n"); + ::bow::log("app"s, "starting server"s); auto stop_flag = new ::std::atomic_flag(); diff --git a/bowshock/source/server/ServerInstance/generate_system.cxx b/bowshock/source/server/ServerInstance/generate_system.cxx index b8ca6cf..8372161 100644 --- a/bowshock/source/server/ServerInstance/generate_system.cxx +++ b/bowshock/source/server/ServerInstance/generate_system.cxx @@ -4,11 +4,13 @@ #include <bow/server.hxx> #include <cstdint> -#include <cstdio> -#include <fmt/core.h> +#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 { - ::fmt::print(stderr, "[server] generating system ({:x})\n", identifier); + ::bow::log("server"s, ::std::format("generating system ({:x})", identifier)); if (system.has_objects()) [[likely]] { system.~ObjectRoot(); diff --git a/bowshock/source/server/ServerInstance/loop.cxx b/bowshock/source/server/ServerInstance/loop.cxx index 06fc267..d4e9c46 100644 --- a/bowshock/source/server/ServerInstance/loop.cxx +++ b/bowshock/source/server/ServerInstance/loop.cxx @@ -4,12 +4,13 @@ #include <bow/logic.hxx> #include <cmath> -#include <cstdio> -#include <fmt/core.h> #include <stdexcept> +#include <string> + +using namespace ::std::literals::string_literals; auto bow::ServerInstance::loop() -> void { - ::fmt::print(stderr, "[server] entering main loop\n"); + ::bow::log("server"s, "entering main loop"s); // For stellar bodies: auto system_root = ::bow::ObjectRoot(); @@ -36,5 +37,5 @@ auto bow::ServerInstance::loop() -> void { this->move(objects_root); } - ::fmt::print(stderr, "[server] submitting\n"); + ::bow::log("server"s, "submitting"s); } diff --git a/bowshock/source/server/ServerInstance/run.cxx b/bowshock/source/server/ServerInstance/run.cxx index 0460ddb..37613c8 100644 --- a/bowshock/source/server/ServerInstance/run.cxx +++ b/bowshock/source/server/ServerInstance/run.cxx @@ -2,25 +2,26 @@ #include <bow/server.hxx> -#include <cstdio> #include <exception> -#include <fmt/core.h> #include <format> +#include <string> + +using namespace ::std::literals::string_literals; auto bow::ServerInstance::run(::bow::ServerInstance* server) noexcept -> void { - ::fmt::print(stderr, "[server] angle unit: {:.3f} rad\n", 0x1p0); - ::fmt::print(stderr, "[server] distance unit: {:.3f} m\n", ::bow::DISTANCE_MODIFIER); - ::fmt::print(stderr, "[server] mass unit: {:.3f} kg\n", ::bow::MASS_MODIFIER); - ::fmt::print(stderr, "[server] time unit: {:.3f} s\n", ::bow::TIME_MODIFIER); - ::fmt::print(stderr, "[server] gravitational constant: {:.9f} (factor: {:.3f}))\n", ::bow::GRAVITY_VALUE, ::bow::GRAVITY_FACTOR); + ::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", ::std::format("got uncaught exception: {}", exception.what())); + ::bow::terminate("server"s, ::std::format("got uncaught exception: {}", exception.what())); } catch (...) { - ::bow::terminate("server", "got uncaught exception"); + ::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 index 2dcf85c..176aeb2 100644 --- a/bowshock/source/server/ServerInstance/simulate.cxx +++ b/bowshock/source/server/ServerInstance/simulate.cxx @@ -4,11 +4,13 @@ #include <bow/server.hxx> #include <cstdint> -#include <cstdio> -#include <fmt/core.h> +#include <format> +#include <string> + +using namespace ::std::literals::string_literals; auto bow::ServerInstance::simulate(::bow::ObjectRoot& system, ::std::uint64_t const duration) noexcept -> void { - ::fmt::print(stderr, "[server] simulating for ({}) time units\n", duration); + ::bow::log("server"s, ::std::format("simulating for ({}) time units", duration)); for (auto i = UINT64_C(0x0); i <= duration; ++i) { this->gravitate(system); |