Browse Source

Move code in debug folder into new debug namespace

master
C. J. Howard 3 years ago
parent
commit
692d0f71ee
21 changed files with 116 additions and 52 deletions
  1. +2
    -2
      src/application.cpp
  2. +10
    -6
      src/application.hpp
  3. +7
    -3
      src/debug/ansi-codes.hpp
  4. +4
    -0
      src/debug/cli.cpp
  5. +7
    -3
      src/debug/cli.hpp
  6. +31
    -0
      src/debug/debug.hpp
  7. +4
    -0
      src/debug/logger.cpp
  8. +7
    -3
      src/debug/logger.hpp
  9. +4
    -0
      src/debug/performance-sampler.cpp
  10. +6
    -3
      src/debug/performance-sampler.hpp
  11. +9
    -9
      src/game/bootloader.cpp
  12. +3
    -4
      src/game/console-commands.cpp
  13. +1
    -2
      src/game/console-commands.hpp
  14. +8
    -4
      src/game/game-context.hpp
  15. +2
    -2
      src/game/states/loading-state.cpp
  16. +2
    -2
      src/game/states/map-state.cpp
  17. +2
    -2
      src/game/states/play-state.cpp
  18. +2
    -2
      src/game/states/splash-state.cpp
  19. +2
    -2
      src/game/states/title-state.cpp
  20. +1
    -1
      src/resources/resource-manager.cpp
  21. +2
    -2
      src/resources/resource-manager.hpp

+ 2
- 2
src/application.cpp View File

@ -59,7 +59,7 @@ application::application():
sdl_gl_context(nullptr) sdl_gl_context(nullptr)
{ {
// Setup logging // Setup logging
logger = new ::logger();
logger = new debug::logger();
// Get SDL compiled version // Get SDL compiled version
SDL_version sdl_compiled_version; SDL_version sdl_compiled_version;
@ -222,7 +222,7 @@ application::application():
frame_scheduler->set_max_frame_duration(0.25); frame_scheduler->set_max_frame_duration(0.25);
// Setup performance sampling // Setup performance sampling
performance_sampler = new ::performance_sampler();
performance_sampler = new debug::performance_sampler();
performance_sampler->set_sample_size(15); performance_sampler->set_sample_size(15);
} }

+ 10
- 6
src/application.hpp View File

@ -33,12 +33,16 @@ class event_dispatcher;
class frame_scheduler; class frame_scheduler;
class game_controller; class game_controller;
class keyboard; class keyboard;
class logger;
class mouse; class mouse;
class performance_sampler;
class rasterizer; class rasterizer;
class image; class image;
namespace debug
{
class logger;
class performance_sampler;
}
/** /**
* *
*/ */
@ -179,7 +183,7 @@ public:
::rasterizer* get_rasterizer(); ::rasterizer* get_rasterizer();
/// Returns the application logger. /// Returns the application logger.
::logger* get_logger();
debug::logger* get_logger();
/// Returns the virtual keyboard. /// Returns the virtual keyboard.
::keyboard* get_keyboard(); ::keyboard* get_keyboard();
@ -213,7 +217,7 @@ private:
std::array<int, 2> viewport_dimensions; std::array<int, 2> viewport_dimensions;
std::array<int, 2> mouse_position; std::array<int, 2> mouse_position;
double update_rate; double update_rate;
logger* logger;
debug::logger* logger;
SDL_Window* sdl_window; SDL_Window* sdl_window;
SDL_GLContext sdl_gl_context; SDL_GLContext sdl_gl_context;
@ -222,7 +226,7 @@ private:
// Frame timing // Frame timing
frame_scheduler* frame_scheduler; frame_scheduler* frame_scheduler;
performance_sampler* performance_sampler;
debug::performance_sampler* performance_sampler;
// Events // Events
event_dispatcher* event_dispatcher; event_dispatcher* event_dispatcher;
@ -234,7 +238,7 @@ private:
std::unordered_map<int, game_controller*> game_controller_map; std::unordered_map<int, game_controller*> game_controller_map;
}; };
inline logger* application::get_logger()
inline debug::logger* application::get_logger()
{ {
return logger; return logger;
} }

+ 7
- 3
src/debug/ansi-codes.hpp View File

@ -17,9 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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 { namespace ansi {
constexpr char* reset = "\u004b[0m"; constexpr char* reset = "\u004b[0m";
@ -65,6 +68,7 @@ constexpr char* underline = "\u003b[4m";
constexpr char* reversed = "\u001b[7m"; constexpr char* reversed = "\u001b[7m";
} // namespace ansi } // namespace ansi
} // namespace debug
#endif // ANTKEEPER_ANSI_CODES_HPP
#endif // ANTKEEPER_DEBUG_ANSI_CODES_HPP

+ 4
- 0
src/debug/cli.cpp View File

@ -19,6 +19,8 @@
#include "cli.hpp" #include "cli.hpp"
namespace debug {
std::string cli::interpret(const std::string& line) const std::string cli::interpret(const std::string& line) const
{ {
std::istringstream stream(line); 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()) if (auto it = commands.find(name); it != commands.end())
commands.erase(it); commands.erase(it);
} }
} // namespace debug

+ 7
- 3
src/debug/cli.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_CLI_HPP
#define ANTKEEPER_CLI_HPP
#ifndef ANTKEEPER_DEBUG_CLI_HPP
#define ANTKEEPER_DEBUG_CLI_HPP
#include <functional> #include <functional>
#include <map> #include <map>
@ -26,6 +26,8 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
namespace debug {
/** /**
* Minimal command-line interpreter. * Minimal command-line interpreter.
*/ */
@ -129,4 +131,6 @@ typename cli::command_type cli::wrap(const std::function& function)
std::placeholders::_1); std::placeholders::_1);
} }
#endif // ANTKEEPER_CLI_HPP
} // namespace debug
#endif // ANTKEEPER_DEBUG_CLI_HPP

+ 31
- 0
src/debug/debug.hpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

+ 4
- 0
src/debug/logger.cpp View File

@ -21,6 +21,8 @@
#include "utility/timestamp.hpp" #include "utility/timestamp.hpp"
#include <iostream> #include <iostream>
namespace debug {
logger::logger(): logger::logger():
os(&std::cout), os(&std::cout),
auto_newline(true), auto_newline(true),
@ -188,3 +190,5 @@ void logger::pop_task(int status)
error(message); error(message);
} }
} }
} // namespace debug

+ 7
- 3
src/debug/logger.hpp View File

@ -17,14 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_LOGGER_HPP
#define ANTKEEPER_LOGGER_HPP
#ifndef ANTKEEPER_DEBUG_LOGGER_HPP
#define ANTKEEPER_DEBUG_LOGGER_HPP
#include <list> #include <list>
#include <ostream> #include <ostream>
#include <stack> #include <stack>
#include <string> #include <string>
namespace debug {
/** /**
* Logs formatted debug messages to an output stream. * Logs formatted debug messages to an output stream.
*/ */
@ -120,5 +122,7 @@ inline const std::string& logger::get_history() const
return history; return history;
} }
#endif // ANTKEEPER_LOGGER_HPP
} // namespace debug
#endif // ANTKEEPER_DEBUG_LOGGER_HPP

+ 4
- 0
src/debug/performance-sampler.cpp View File

@ -21,6 +21,8 @@
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
namespace debug {
performance_sampler::performance_sampler(): performance_sampler::performance_sampler():
sample_size(1), sample_size(1),
sample_index(0) 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<double>(samples.size()); return std::accumulate(samples.begin(), samples.end(), 0.0) / static_cast<double>(samples.size());
} }
} // namespace debug

+ 6
- 3
src/debug/performance-sampler.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_PERFORMANCE_SAMPLER_HPP
#define ANTKEEPER_PERFORMANCE_SAMPLER_HPP
#ifndef ANTKEEPER_DEBUG_PERFORMANCE_SAMPLER_HPP
#define ANTKEEPER_DEBUG_PERFORMANCE_SAMPLER_HPP
#include <cstdlib> #include <cstdlib>
#include <vector> #include <vector>
namespace debug {
/** /**
* Measures a rolling mean frame duration. * Measures a rolling mean frame duration.
*/ */
@ -62,5 +64,6 @@ private:
std::size_t sample_index; std::size_t sample_index;
}; };
#endif // ANTKEEPER_PERFORMANCE_SAMPLER_HPP
} // namespace debug
#endif // ANTKEEPER_DEBUG_PERFORMANCE_SAMPLER_HPP

+ 9
- 9
src/game/bootloader.cpp View File

@ -120,7 +120,7 @@ static void setup_callbacks(game_context* ctx);
int bootloader(application* app, int argc, char** argv) int bootloader(application* app, int argc, char** argv)
{ {
// Get application logger // Get application logger
logger* logger = app->get_logger();
debug::logger* logger = app->get_logger();
logger->push_task("Running application bootloader"); 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) 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"); logger->push_task("Parsing command line options");
try try
@ -232,7 +232,7 @@ void parse_options(game_context* ctx, int argc, char** argv)
void setup_resources(game_context* ctx) void setup_resources(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
// Setup resource manager // Setup resource manager
ctx->resource_manager = new resource_manager(logger); ctx->resource_manager = new resource_manager(logger);
@ -354,7 +354,7 @@ void setup_resources(game_context* ctx)
void load_config(game_context* ctx) void load_config(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Loading config"); logger->push_task("Loading config");
// Load config file // Load config file
@ -370,7 +370,7 @@ void load_config(game_context* ctx)
void load_strings(game_context* ctx) void load_strings(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Loading strings"); logger->push_task("Loading strings");
ctx->string_table = ctx->resource_manager->load<string_table>("strings.csv"); ctx->string_table = ctx->resource_manager->load<string_table>("strings.csv");
@ -394,7 +394,7 @@ void load_strings(game_context* ctx)
void setup_window(game_context* ctx) void setup_window(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Setting up window"); logger->push_task("Setting up window");
application* app = ctx->app; application* app = ctx->app;
@ -441,7 +441,7 @@ void setup_window(game_context* ctx)
void setup_rendering(game_context* ctx) void setup_rendering(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Setting up rendering"); logger->push_task("Setting up rendering");
// Get rasterizer from application // Get rasterizer from application
@ -613,7 +613,7 @@ void setup_rendering(game_context* ctx)
void setup_scenes(game_context* ctx) void setup_scenes(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Setting up rendering"); logger->push_task("Setting up rendering");
// Get default framebuffer // Get default framebuffer
@ -1242,7 +1242,7 @@ void setup_controls(game_context* ctx)
void setup_cli(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("echo", cc::echo);
ctx->cli->register_command("exit", std::function<std::string()>(std::bind(&cc::exit, ctx))); ctx->cli->register_command("exit", std::function<std::string()>(std::bind(&cc::exit, ctx)));
ctx->cli->register_command("scrot", std::function<std::string()>(std::bind(&cc::scrot, ctx))); ctx->cli->register_command("scrot", std::function<std::string()>(std::bind(&cc::scrot, ctx)));

+ 3
- 4
src/game/console-commands.cpp View File

@ -23,8 +23,7 @@
#include "game/game-context.hpp" #include "game/game-context.hpp"
#include "debug/cli.hpp" #include "debug/cli.hpp"
namespace cc
{
namespace cc {
std::string echo(std::string text) 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) std::string cue(game_context* ctx, float t, std::string command)
{ {
::timeline* timeline = ctx->timeline; ::timeline* timeline = ctx->timeline;
::cli* cli = ctx->cli;
debug::cli* cli = ctx->cli;
timeline->add_cue({timeline->get_position() + t, std::function<void()>(std::bind(&::cli::interpret, cli, command))});
timeline->add_cue({timeline->get_position() + t, std::function<void()>(std::bind(&debug::cli::interpret, cli, command))});
return std::string("command \"" + command + "\" will execute in " + std::to_string(t) + " seconds"); return std::string("command \"" + command + "\" will execute in " + std::to_string(t) + " seconds");
} }

+ 1
- 2
src/game/console-commands.hpp View File

@ -24,8 +24,7 @@
struct game_context; struct game_context;
namespace cc
{
namespace cc {
std::string echo(std::string text); std::string echo(std::string text);

+ 8
- 4
src/game/game-context.hpp View File

@ -49,7 +49,6 @@ class directional_light;
class final_pass; class final_pass;
class framebuffer; class framebuffer;
class locomotion_system; class locomotion_system;
class logger;
class material; class material;
class input_listener; class input_listener;
class material_pass; class material_pass;
@ -82,7 +81,6 @@ class renderer;
class model_instance; class model_instance;
class input_event_router; class input_event_router;
class input_mapper; class input_mapper;
class cli;
class outline_pass; class outline_pass;
class tracking_system; class tracking_system;
class painting_system; class painting_system;
@ -94,13 +92,19 @@ template class animation;
template <typename T> class material_property; template <typename T> class material_property;
template <typename T> class tween; template <typename T> class tween;
namespace debug
{
class cli;
class logger;
}
/** /**
* *
*/ */
struct game_context struct game_context
{ {
application* app; application* app;
logger* logger;
debug::logger* logger;
std::ofstream log_filestream; std::ofstream log_filestream;
// Command-line options // Command-line options
@ -253,7 +257,7 @@ struct game_context
biome* biome; biome* biome;
// Debug // Debug
cli* cli;
debug::cli* cli;
// Misc // Misc
pheromone_matrix* pheromones; pheromone_matrix* pheromones;

+ 2
- 2
src/game/states/loading-state.cpp View File

@ -24,7 +24,7 @@
void loading_state_enter(game_context* ctx) void loading_state_enter(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Entering loading state"); logger->push_task("Entering loading state");
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);
@ -34,7 +34,7 @@ void loading_state_enter(game_context* ctx)
void loading_state_exit(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->push_task("Exiting loading state");
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);

+ 2
- 2
src/game/states/map-state.cpp View File

@ -34,7 +34,7 @@
void map_state_enter(game_context* ctx) void map_state_enter(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Entering map state"); logger->push_task("Entering map state");
// Disable sky pass // Disable sky pass
@ -48,7 +48,7 @@ void map_state_enter(game_context* ctx)
void map_state_exit(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->push_task("Exiting map state");
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);

+ 2
- 2
src/game/states/play-state.cpp View File

@ -71,7 +71,7 @@
void play_state_enter(game_context* ctx) void play_state_enter(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Entering play state"); logger->push_task("Entering play state");
// Load biome // Load biome
@ -462,7 +462,7 @@ void play_state_enter(game_context* ctx)
void play_state_exit(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->push_task("Exiting play state");
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);

+ 2
- 2
src/game/states/splash-state.cpp View File

@ -34,7 +34,7 @@
void splash_state_enter(game_context* ctx) void splash_state_enter(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Entering splash state"); logger->push_task("Entering splash state");
//ctx->app->set_window_opacity(0.5f); //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) void splash_state_exit(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Exiting splash state"); logger->push_task("Exiting splash state");
// Disable splash skipper // Disable splash skipper

+ 2
- 2
src/game/states/title-state.cpp View File

@ -24,7 +24,7 @@
void title_state_enter(game_context* ctx) void title_state_enter(game_context* ctx)
{ {
logger* logger = ctx->logger;
debug::logger* logger = ctx->logger;
logger->push_task("Entering title state"); logger->push_task("Entering title state");
// Get timeline // Get timeline
@ -48,7 +48,7 @@ void title_state_enter(game_context* ctx)
void title_state_exit(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->push_task("Exiting title state");
logger->pop_task(EXIT_SUCCESS); logger->pop_task(EXIT_SUCCESS);

+ 1
- 1
src/resources/resource-manager.cpp View File

@ -19,7 +19,7 @@
#include "resources/resource-manager.hpp" #include "resources/resource-manager.hpp"
resource_manager::resource_manager(::logger* logger):
resource_manager::resource_manager(debug::logger* logger):
logger(logger) logger(logger)
{ {
// Init PhysicsFS // Init PhysicsFS

+ 2
- 2
src/resources/resource-manager.hpp View File

@ -40,7 +40,7 @@ public:
/** /**
* Creates a resource manager. * Creates a resource manager.
*/ */
resource_manager(::logger* logger);
resource_manager(debug::logger* logger);
/** /**
* Destroys a resource manager and frees all of its resources. * Destroys a resource manager and frees all of its resources.
@ -89,7 +89,7 @@ private:
std::map<std::string, resource_handle_base*> resource_cache; std::map<std::string, resource_handle_base*> resource_cache;
std::list<std::string> search_paths; std::list<std::string> search_paths;
entt::registry archetype_registry; entt::registry archetype_registry;
logger* logger;
debug::logger* logger;
}; };
template <typename T> template <typename T>

Loading…
Cancel
Save