1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Initialise logging outside of RWGame

This commit is contained in:
Daniel Evans 2016-10-15 01:39:15 +01:00
parent 6da5dc6dae
commit 657a726a9b
4 changed files with 17 additions and 9 deletions

View File

@ -35,6 +35,10 @@ public:
virtual void messageRecieved(const LogMessage&) = 0; virtual void messageRecieved(const LogMessage&) = 0;
}; };
Logger(std::initializer_list<MessageReciever*> initial = {})
: recievers(initial) {
}
void addReciever(MessageReciever* out); void addReciever(MessageReciever* out);
void removeReciever(MessageReciever* out); void removeReciever(MessageReciever* out);

View File

@ -7,6 +7,7 @@
#include "states/MenuState.hpp" #include "states/MenuState.hpp"
#include <core/Profiler.hpp> #include <core/Profiler.hpp>
#include <core/Logger.hpp>
#include <engine/GameState.hpp> #include <engine/GameState.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
@ -42,9 +43,7 @@ std::map<GameRenderer::SpecialModel, std::string> kSpecialModels = {
DebugDraw* debug = nullptr; DebugDraw* debug = nullptr;
StdOutReciever logPrinter; RWGame::RWGame(Logger& log, int argc, char* argv[]) : log(log) {
RWGame::RWGame(int argc, char* argv[]) {
if (!config.isValid()) { if (!config.isValid()) {
throw std::runtime_error("Invalid configuration file at: " + throw std::runtime_error("Invalid configuration file at: " +
config.getConfigFile()); config.getConfigFile());
@ -113,7 +112,6 @@ RWGame::RWGame(int argc, char* argv[]) {
work = new WorkContext(); work = new WorkContext();
log.addReciever(&logPrinter);
log.info("Game", "Game directory: " + config.getGameDataPath()); log.info("Game", "Game directory: " + config.getGameDataPath());
log.info("Game", "Build: " + kBuildStr); log.info("Game", "Build: " + kBuildStr);

View File

@ -2,7 +2,6 @@
#define _RWGAME_HPP_ #define _RWGAME_HPP_
#include <chrono> #include <chrono>
#include <core/Logger.hpp>
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <render/GameRenderer.hpp> #include <render/GameRenderer.hpp>
@ -15,9 +14,10 @@
#include "SDL.h" #include "SDL.h"
class PlayerController; class PlayerController;
class Logger;
class RWGame { class RWGame {
Logger log; Logger& log;
GameConfig config{"openrw.ini"}; GameConfig config{"openrw.ini"};
GameState* state = nullptr; GameState* state = nullptr;
GameData* data = nullptr; GameData* data = nullptr;
@ -51,7 +51,7 @@ class RWGame {
float timescale = 1.f; float timescale = 1.f;
public: public:
RWGame(int argc, char* argv[]); RWGame(Logger& log, int argc, char* argv[]);
~RWGame(); ~RWGame();
int run(); int run();

View File

@ -2,9 +2,15 @@
#include "RWGame.hpp" #include "RWGame.hpp"
#include "SDL.h" #include "SDL.h"
#include <core/Logger.hpp>
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Initialise Logging before anything else happens
StdOutReciever logstdout;
Logger logger({ &logstdout });
try { try {
RWGame game(argc, argv); RWGame game(logger, argc, argv);
return game.run(); return game.run();
} catch (std::invalid_argument& ex) { } catch (std::invalid_argument& ex) {
@ -20,7 +26,7 @@ int main(int argc, char* argv[]) {
const char* kErrorTitle = "Fatal Error"; const char* kErrorTitle = "Fatal Error";
std::cerr << kErrorTitle << "\n" << ex.what() << std::endl; logger.error("exception", ex.what());
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, kErrorTitle, if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, kErrorTitle,
ex.what(), NULL) < 0) { ex.what(), NULL) < 0) {