Skip to content
Snippets Groups Projects
Commit 09e0e578 authored by Tomas Vybiral's avatar Tomas Vybiral
Browse files

removed logging lib - problems in compilation on some systems

parent 71f0d3df
No related branches found
No related tags found
No related merge requests found
......@@ -80,14 +80,14 @@ endif()
include(cmake/Conan.cmake)
run_conan()
 
add_subdirectory(src)
if(ENABLE_TESTING)
enable_testing()
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
add_subdirectory(test)
endif()
 
add_subdirectory(src)
option(ENABLE_UNITY "Enable Unity builds of projects" OFF)
if(ENABLE_UNITY)
# Add for any project you want to apply unity builds for
......
[requires]
catch2/2.11.0
spdlog/1.5.0
\ No newline at end of file
catch2/2.11.0
\ No newline at end of file
......@@ -8,5 +8,4 @@ target_link_libraries(
shooter
PRIVATE project_options
project_warnings
CONAN_PKG::spdlog
game)
......@@ -8,11 +8,12 @@ add_library(game
single_shot.h single_shot.cpp
multi_shot.h multi_shot.cpp)
 
target_include_directories(game PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_link_libraries(game
PRIVATE
project_options
project_warnings
CONAN_PKG::spdlog
state
input
renderer
......
#include "game.h"
 
#include "spdlog/spdlog.h"
#include "input/sdl_input.h"
#include "renderer/sdl_renderer.h"
#include "single_shot.h"
......@@ -27,8 +26,6 @@ game::game(uint32_t fps):current_state(),
input_processor = new sdl_input();
renderer = new sdl_renderer();
shoot_control = new single_shot();
spdlog::get("game")->debug("Fps set to: {} and delta_time set to: {}", fps, delta_time);
spdlog::get("game")->info("Finished game component initialization.");
 
load_levels();
 
......@@ -38,13 +35,11 @@ game::game(uint32_t fps):current_state(),
}
 
void game::load_levels() {
spdlog::get("game")->info("Loading levels");
level::create().from_file("levels/01.txt");
level::create().with_enemy_at({320, 120}).with_enemy_at({160, 240}).with_enemy_at({480, 360}).save_as("level_01");
}
 
game::~game() {
spdlog::get("game")->debug("Deleting allocated resources");
if (!input_processor)
delete input_processor;
if (!renderer) {
......@@ -57,7 +52,6 @@ game::~game() {
 
void game::run_loop() {
is_running = true;
spdlog::get("game")->info("Starting game loop.");
while (is_running) {
auto start = std::chrono::system_clock::now();
process_events();
......@@ -69,7 +63,6 @@ void game::run_loop() {
std::chrono::duration<double> diff = end - start;
SDL_Delay(static_cast<uint32_t>((delta_time - diff.count())*1000));
}
spdlog::get("game")->info("Game loop ended");
}
 
bool game::try_to_switch_level() {
......
......@@ -7,5 +7,4 @@ target_link_libraries(input
PUBLIC
project_options
project_warnings
CONAN_PKG::spdlog
${SDL2_LIBRARY})
\ No newline at end of file
......@@ -7,7 +7,6 @@ target_link_libraries(renderer
PUBLIC
project_options
project_warnings
CONAN_PKG::spdlog
${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARY}
${SDL2_TTF_LIBRARY}
......
......@@ -4,10 +4,9 @@ add_library(state
entities.h entities.cpp
level.h level.cpp)
 
target_include_directories(state PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(state PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
 
target_link_libraries(state
PRIVATE
project_options
project_warnings
CONAN_PKG::spdlog)
\ No newline at end of file
project_warnings)
\ No newline at end of file
#include "state.h"
 
#include <exception>
#include <stdexcept>
#include <cstring>
 
#include "spdlog/spdlog.h"
state::state():player(), enemies(), projectiles(), score(0), next_level_id("") { }
 
void state::push() const {
spdlog::get("state")->debug("Pushing current state.");
history.emplace_back(*this);
}
 
state state::pop() {
state top;
if (!history.empty()) {
auto first = history.front();
history.pop_front();
return first;
top = history.back();
history.pop_back();
} else {
throw std::length_error("History is empty. So nothing can be poped.");
throw std::runtime_error("History is empty. So nothing can be poped.");
}
return top;
}
 
state& state::operator=(const state& other) {
......
......@@ -15,7 +15,7 @@
class state {
public:
/// Default constructor
state() = default;
state();
/// Copy constructor to store states in history
state(const state& other) = default;
 
......
#include "fmt/core.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/basic_file_sink.h"
#include <memory>
#include <string>
#include <stdexcept>
#include <iostream>
 
#include "game/game.h"
 
......@@ -29,47 +24,15 @@
* * Abstract factory
*/
 
/**
* This function creates spdlog logger and registers it.
*
* @param logger_name name of the logger.
* @param file_sink file to save logs to.
*/
void create_logger(const std::string& logger_name, const std::shared_ptr<spdlog::sinks::basic_file_sink_mt>& file_sink) {
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::warn);
std::vector<spdlog::sink_ptr> sinks{console_sink, file_sink};
auto logger = std::make_shared<spdlog::logger>(logger_name, sinks.begin(), sinks.end());
spdlog::register_logger(logger);
}
/**
* This function creates all needed loggers.
*/
void create_loggers() {
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("shooter.log", true);
file_sink->set_level(spdlog::level::trace);
create_logger("main", file_sink);
create_logger("game", file_sink);
create_logger("state", file_sink);
}
/*
* Main function that intializes logggers, initializes and starts the game.
* Main function that initializes and starts the game.
*/
int main() {
create_loggers();
try {
spdlog::get("main")->info("Initialzing main game component.");
game game(30);
spdlog::get("main")->info("Starting main game loop.");
game.run_loop();
spdlog::get("main")->info("Game loop ended.");
} catch (const std::exception& exp) {
spdlog::get("main")->error(fmt::format("Unhadled exception caught: {}", exp.what()));
std::cerr << "Unhadled exception caught: " << exp.what() << std::endl;
return 1;
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment