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;
};
Logger(std::initializer_list<MessageReciever*> initial = {})
: recievers(initial) {
}
void addReciever(MessageReciever* out);
void removeReciever(MessageReciever* out);

View File

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

View File

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

View File

@ -2,9 +2,15 @@
#include "RWGame.hpp"
#include "SDL.h"
#include <core/Logger.hpp>
int main(int argc, char* argv[]) {
// Initialise Logging before anything else happens
StdOutReciever logstdout;
Logger logger({ &logstdout });
try {
RWGame game(argc, argv);
RWGame game(logger, argc, argv);
return game.run();
} catch (std::invalid_argument& ex) {
@ -20,7 +26,7 @@ int main(int argc, char* argv[]) {
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,
ex.what(), NULL) < 0) {