diff --git a/src/application.cpp b/src/application.cpp index ffa567f..5e2d55a 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -59,7 +59,7 @@ application::application(): sdl_gl_context(nullptr) { // Setup logging - logger = new ::logger(); + logger = new debug::logger(); // Get SDL compiled version SDL_version sdl_compiled_version; @@ -222,7 +222,7 @@ application::application(): frame_scheduler->set_max_frame_duration(0.25); // Setup performance sampling - performance_sampler = new ::performance_sampler(); + performance_sampler = new debug::performance_sampler(); performance_sampler->set_sample_size(15); } diff --git a/src/application.hpp b/src/application.hpp index 8bc08bb..cff6175 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -33,12 +33,16 @@ class event_dispatcher; class frame_scheduler; class game_controller; class keyboard; -class logger; class mouse; -class performance_sampler; class rasterizer; class image; +namespace debug +{ + class logger; + class performance_sampler; +} + /** * */ @@ -179,7 +183,7 @@ public: ::rasterizer* get_rasterizer(); /// Returns the application logger. - ::logger* get_logger(); + debug::logger* get_logger(); /// Returns the virtual keyboard. ::keyboard* get_keyboard(); @@ -213,7 +217,7 @@ private: std::array viewport_dimensions; std::array mouse_position; double update_rate; - logger* logger; + debug::logger* logger; SDL_Window* sdl_window; SDL_GLContext sdl_gl_context; @@ -222,7 +226,7 @@ private: // Frame timing frame_scheduler* frame_scheduler; - performance_sampler* performance_sampler; + debug::performance_sampler* performance_sampler; // Events event_dispatcher* event_dispatcher; @@ -234,7 +238,7 @@ private: std::unordered_map game_controller_map; }; -inline logger* application::get_logger() +inline debug::logger* application::get_logger() { return logger; } diff --git a/src/debug/ansi-codes.hpp b/src/debug/ansi-codes.hpp index a2295f5..ec0e004 100644 --- a/src/debug/ansi-codes.hpp +++ b/src/debug/ansi-codes.hpp @@ -17,9 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_ANSI_CODES_HPP -#define ANTKEEPER_ANSI_CODES_HPP +#ifndef ANTKEEPER_DEBUG_ANSI_CODES_HPP +#define ANTKEEPER_DEBUG_ANSI_CODES_HPP +namespace debug { + +/// ANSI escape codes. namespace ansi { constexpr char* reset = "\u004b[0m"; @@ -65,6 +68,7 @@ constexpr char* underline = "\u003b[4m"; constexpr char* reversed = "\u001b[7m"; } // namespace ansi +} // namespace debug -#endif // ANTKEEPER_ANSI_CODES_HPP +#endif // ANTKEEPER_DEBUG_ANSI_CODES_HPP diff --git a/src/debug/cli.cpp b/src/debug/cli.cpp index f2cf52f..8f12025 100644 --- a/src/debug/cli.cpp +++ b/src/debug/cli.cpp @@ -19,6 +19,8 @@ #include "cli.hpp" +namespace debug { + std::string cli::interpret(const std::string& line) const { std::istringstream stream(line); @@ -38,3 +40,5 @@ void cli::unregister_command(const std::string& name) if (auto it = commands.find(name); it != commands.end()) commands.erase(it); } + +} // namespace debug diff --git a/src/debug/cli.hpp b/src/debug/cli.hpp index d326c31..4f7f6f6 100644 --- a/src/debug/cli.hpp +++ b/src/debug/cli.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CLI_HPP -#define ANTKEEPER_CLI_HPP +#ifndef ANTKEEPER_DEBUG_CLI_HPP +#define ANTKEEPER_DEBUG_CLI_HPP #include #include @@ -26,6 +26,8 @@ #include #include +namespace debug { + /** * Minimal command-line interpreter. */ @@ -129,4 +131,6 @@ typename cli::command_type cli::wrap(const std::function& function) std::placeholders::_1); } -#endif // ANTKEEPER_CLI_HPP +} // namespace debug + +#endif // ANTKEEPER_DEBUG_CLI_HPP diff --git a/src/debug/debug.hpp b/src/debug/debug.hpp new file mode 100644 index 0000000..6850d97 --- /dev/null +++ b/src/debug/debug.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_DEBUG_HPP +#define ANTKEEPER_DEBUG_HPP + +/// Debugging functions and classes +namespace debug {} + +#include "ansi-codes.hpp" +#include "cli.hpp" +#include "logger.hpp" +#include "performance-sampler.hpp" + +#endif // ANTKEEPER_DEBUG_HPP diff --git a/src/debug/logger.cpp b/src/debug/logger.cpp index 0213f62..602a7c3 100644 --- a/src/debug/logger.cpp +++ b/src/debug/logger.cpp @@ -21,6 +21,8 @@ #include "utility/timestamp.hpp" #include +namespace debug { + logger::logger(): os(&std::cout), auto_newline(true), @@ -188,3 +190,5 @@ void logger::pop_task(int status) error(message); } } + +} // namespace debug diff --git a/src/debug/logger.hpp b/src/debug/logger.hpp index 26a5ce3..3aed487 100644 --- a/src/debug/logger.hpp +++ b/src/debug/logger.hpp @@ -17,14 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_LOGGER_HPP -#define ANTKEEPER_LOGGER_HPP +#ifndef ANTKEEPER_DEBUG_LOGGER_HPP +#define ANTKEEPER_DEBUG_LOGGER_HPP #include #include #include #include +namespace debug { + /** * Logs formatted debug messages to an output stream. */ @@ -120,5 +122,7 @@ inline const std::string& logger::get_history() const return history; } -#endif // ANTKEEPER_LOGGER_HPP +} // namespace debug + +#endif // ANTKEEPER_DEBUG_LOGGER_HPP diff --git a/src/debug/performance-sampler.cpp b/src/debug/performance-sampler.cpp index bba246b..9732028 100644 --- a/src/debug/performance-sampler.cpp +++ b/src/debug/performance-sampler.cpp @@ -21,6 +21,8 @@ #include #include +namespace debug { + performance_sampler::performance_sampler(): sample_size(1), sample_index(0) @@ -60,3 +62,5 @@ double performance_sampler::mean_frame_duration() const return std::accumulate(samples.begin(), samples.end(), 0.0) / static_cast(samples.size()); } +} // namespace debug + diff --git a/src/debug/performance-sampler.hpp b/src/debug/performance-sampler.hpp index f4eed06..8d50708 100644 --- a/src/debug/performance-sampler.hpp +++ b/src/debug/performance-sampler.hpp @@ -17,12 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_PERFORMANCE_SAMPLER_HPP -#define ANTKEEPER_PERFORMANCE_SAMPLER_HPP +#ifndef ANTKEEPER_DEBUG_PERFORMANCE_SAMPLER_HPP +#define ANTKEEPER_DEBUG_PERFORMANCE_SAMPLER_HPP #include #include +namespace debug { + /** * Measures a rolling mean frame duration. */ @@ -62,5 +64,6 @@ private: std::size_t sample_index; }; -#endif // ANTKEEPER_PERFORMANCE_SAMPLER_HPP +} // namespace debug +#endif // ANTKEEPER_DEBUG_PERFORMANCE_SAMPLER_HPP diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 847399a..715481d 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -120,7 +120,7 @@ static void setup_callbacks(game_context* ctx); int bootloader(application* app, int argc, char** argv) { // Get application logger - logger* logger = app->get_logger(); + debug::logger* logger = app->get_logger(); logger->push_task("Running application bootloader"); @@ -166,7 +166,7 @@ int bootloader(application* app, int argc, char** argv) void parse_options(game_context* ctx, int argc, char** argv) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Parsing command line options"); try @@ -232,7 +232,7 @@ void parse_options(game_context* ctx, int argc, char** argv) void setup_resources(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; // Setup resource manager ctx->resource_manager = new resource_manager(logger); @@ -354,7 +354,7 @@ void setup_resources(game_context* ctx) void load_config(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Loading config"); // Load config file @@ -370,7 +370,7 @@ void load_config(game_context* ctx) void load_strings(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Loading strings"); ctx->string_table = ctx->resource_manager->load("strings.csv"); @@ -394,7 +394,7 @@ void load_strings(game_context* ctx) void setup_window(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Setting up window"); application* app = ctx->app; @@ -441,7 +441,7 @@ void setup_window(game_context* ctx) void setup_rendering(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Setting up rendering"); // Get rasterizer from application @@ -613,7 +613,7 @@ void setup_rendering(game_context* ctx) void setup_scenes(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Setting up rendering"); // Get default framebuffer @@ -1242,7 +1242,7 @@ void setup_controls(game_context* ctx) void setup_cli(game_context* ctx) { - ctx->cli = new cli(); + ctx->cli = new debug::cli(); ctx->cli->register_command("echo", cc::echo); ctx->cli->register_command("exit", std::function(std::bind(&cc::exit, ctx))); ctx->cli->register_command("scrot", std::function(std::bind(&cc::scrot, ctx))); diff --git a/src/game/console-commands.cpp b/src/game/console-commands.cpp index 5acfb16..5ce363e 100644 --- a/src/game/console-commands.cpp +++ b/src/game/console-commands.cpp @@ -23,8 +23,7 @@ #include "game/game-context.hpp" #include "debug/cli.hpp" -namespace cc -{ +namespace cc { std::string echo(std::string text) { @@ -46,9 +45,9 @@ std::string scrot(game_context* ctx) std::string cue(game_context* ctx, float t, std::string command) { ::timeline* timeline = ctx->timeline; - ::cli* cli = ctx->cli; + debug::cli* cli = ctx->cli; - timeline->add_cue({timeline->get_position() + t, std::function(std::bind(&::cli::interpret, cli, command))}); + timeline->add_cue({timeline->get_position() + t, std::function(std::bind(&debug::cli::interpret, cli, command))}); return std::string("command \"" + command + "\" will execute in " + std::to_string(t) + " seconds"); } diff --git a/src/game/console-commands.hpp b/src/game/console-commands.hpp index aabb827..d31767e 100644 --- a/src/game/console-commands.hpp +++ b/src/game/console-commands.hpp @@ -24,8 +24,7 @@ struct game_context; -namespace cc -{ +namespace cc { std::string echo(std::string text); diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index 8e7a765..ac88f55 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -49,7 +49,6 @@ class directional_light; class final_pass; class framebuffer; class locomotion_system; -class logger; class material; class input_listener; class material_pass; @@ -82,7 +81,6 @@ class renderer; class model_instance; class input_event_router; class input_mapper; -class cli; class outline_pass; class tracking_system; class painting_system; @@ -94,13 +92,19 @@ template class animation; template class material_property; template class tween; +namespace debug +{ + class cli; + class logger; +} + /** * */ struct game_context { application* app; - logger* logger; + debug::logger* logger; std::ofstream log_filestream; // Command-line options @@ -253,7 +257,7 @@ struct game_context biome* biome; // Debug - cli* cli; + debug::cli* cli; // Misc pheromone_matrix* pheromones; diff --git a/src/game/states/loading-state.cpp b/src/game/states/loading-state.cpp index 1953728..c26aff1 100644 --- a/src/game/states/loading-state.cpp +++ b/src/game/states/loading-state.cpp @@ -24,7 +24,7 @@ void loading_state_enter(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Entering loading state"); logger->pop_task(EXIT_SUCCESS); @@ -34,7 +34,7 @@ void loading_state_enter(game_context* ctx) void loading_state_exit(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Exiting loading state"); logger->pop_task(EXIT_SUCCESS); diff --git a/src/game/states/map-state.cpp b/src/game/states/map-state.cpp index acc7f9b..c3e690d 100644 --- a/src/game/states/map-state.cpp +++ b/src/game/states/map-state.cpp @@ -34,7 +34,7 @@ void map_state_enter(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Entering map state"); // Disable sky pass @@ -48,7 +48,7 @@ void map_state_enter(game_context* ctx) void map_state_exit(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Exiting map state"); logger->pop_task(EXIT_SUCCESS); diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index a91f8e7..457692e 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -71,7 +71,7 @@ void play_state_enter(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Entering play state"); // Load biome @@ -462,7 +462,7 @@ void play_state_enter(game_context* ctx) void play_state_exit(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Exiting play state"); logger->pop_task(EXIT_SUCCESS); diff --git a/src/game/states/splash-state.cpp b/src/game/states/splash-state.cpp index 5c923d6..80410a3 100644 --- a/src/game/states/splash-state.cpp +++ b/src/game/states/splash-state.cpp @@ -34,7 +34,7 @@ void splash_state_enter(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Entering splash state"); //ctx->app->set_window_opacity(0.5f); @@ -99,7 +99,7 @@ void splash_state_enter(game_context* ctx) void splash_state_exit(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Exiting splash state"); // Disable splash skipper diff --git a/src/game/states/title-state.cpp b/src/game/states/title-state.cpp index 1c90dd1..7561df7 100644 --- a/src/game/states/title-state.cpp +++ b/src/game/states/title-state.cpp @@ -24,7 +24,7 @@ void title_state_enter(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Entering title state"); // Get timeline @@ -48,7 +48,7 @@ void title_state_enter(game_context* ctx) void title_state_exit(game_context* ctx) { - logger* logger = ctx->logger; + debug::logger* logger = ctx->logger; logger->push_task("Exiting title state"); logger->pop_task(EXIT_SUCCESS); diff --git a/src/resources/resource-manager.cpp b/src/resources/resource-manager.cpp index a7f2a2e..ccd5db4 100644 --- a/src/resources/resource-manager.cpp +++ b/src/resources/resource-manager.cpp @@ -19,7 +19,7 @@ #include "resources/resource-manager.hpp" -resource_manager::resource_manager(::logger* logger): +resource_manager::resource_manager(debug::logger* logger): logger(logger) { // Init PhysicsFS diff --git a/src/resources/resource-manager.hpp b/src/resources/resource-manager.hpp index b225afe..cbb6d36 100644 --- a/src/resources/resource-manager.hpp +++ b/src/resources/resource-manager.hpp @@ -40,7 +40,7 @@ public: /** * Creates a resource manager. */ - resource_manager(::logger* logger); + resource_manager(debug::logger* logger); /** * Destroys a resource manager and frees all of its resources. @@ -89,7 +89,7 @@ private: std::map resource_cache; std::list search_paths; entt::registry archetype_registry; - logger* logger; + debug::logger* logger; }; template