Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging and make some refactorings. #195

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/osre/Common/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class OSRE_EXPORT Logger {
StdLogStream();

/// @brief The class destructor.
~StdLogStream();
~StdLogStream() override = default;

/// @brief Will write a message into the stream.
/// @param msg [in] The message to write.
Expand Down
32 changes: 21 additions & 11 deletions src/Engine/Common/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ static void appendDomain(const String &domain, String &logMsg) {
}
}

static String stripFilename(const String &filename) {
if (filename.empty()) {
return filename;
}

String::size_type pos = filename.find_last_of("/");
if (pos == String::npos) {
return filename;
}
const String strippedName = filename.substr(pos + 1, filename.size() - pos - 1);

return strippedName;
}

AbstractLogStream::AbstractLogStream() :
m_IsActive(true) {
// empty
Expand Down Expand Up @@ -264,10 +278,6 @@ Logger::StdLogStream::StdLogStream() {
// empty
}

Logger::StdLogStream::~StdLogStream() {
// empty
}

void Logger::StdLogStream::write(const String &msg) {
std::cout << msg;
}
Expand All @@ -276,7 +286,7 @@ void tracePrint(const String &domain, const String &file, int line, const String
String message;
message += msg;
message += " (";
message += file;
message += stripFilename(file);
message += ", ";
std::stringstream ss;
ss << line;
Expand All @@ -289,7 +299,7 @@ void debugPrint(const String &domain, const String &file, int line, const String
String message;
message += msg;
message += " (";
message += file;
message += stripFilename(file);
message += ", ";
std::stringstream ss;
ss << line;
Expand All @@ -302,7 +312,7 @@ void infoPrint(const String &domain, const String &file, int line, const String
String message;
message += msg;
message += " (";
message += file;
message += stripFilename(file);
message += ", ";
std::stringstream ss;
ss << line;
Expand All @@ -313,7 +323,7 @@ void infoPrint(const String &domain, const String &file, int line, const String

void logPrint(const String &domain, const String &file, int line, const String &message) {
String msg;
msg += file;
msg += stripFilename(file);
msg += ", ";
std::stringstream ss;
ss << line;
Expand All @@ -330,7 +340,7 @@ void warnPrint(const String &domain, const String &file, int line, const String
String msg;
msg += message;
msg += " (";
msg += file;
msg += stripFilename(file);
msg += ", ";
std::stringstream ss;
ss << line;
Expand All @@ -343,7 +353,7 @@ void errorPrint(const String &domain, const String &file, int line, const String
String msg;
msg += message;
msg += " (";
msg += file;
msg += stripFilename(file);
msg += ", ";
std::stringstream ss;
ss << line;
Expand All @@ -356,7 +366,7 @@ void fatalPrint(const String &domain, const String &file, int line, const String
String msg;
msg += message;
msg += " (";
msg += file;
msg += stripFilename(file);
msg += ", ";
std::stringstream ss;
ss << line;
Expand Down
19 changes: 5 additions & 14 deletions src/Engine/Platform/sdl2/SDL2EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <osre/RenderBackend/RenderBackendService.h>
#include <src/Engine/Platform/sdl2/SDL2EventQueue.h>

#include "SDL2Initializer.h"
#include "SDL2Window.h"

#include <SDL.h>
Expand Down Expand Up @@ -86,7 +87,7 @@ struct SDL2PeekInputUpdate final : public AbstractSDL2InputUpdate {
// Update implemented as a poll operation, will check for a new event.
bool update(SDL_Event *ev) override {
const i32 ret = ::SDL_PollEvent(ev);
if (0 == ret) {
if (ret == 0) {
return false;
}

Expand Down Expand Up @@ -118,22 +119,12 @@ SDL2EventHandler::SDL2EventHandler(AbstractWindow *window) :
m_eventTriggerer->addTriggerableEvent(QuitEvent);
m_eventTriggerer->addTriggerableEvent(AppFocusEvent);

if (0 == SDL_WasInit(SDL_INIT_EVERYTHING)) {
SDL_Init(SDL_INIT_EVERYTHING);
}

if (0 == SDL_WasInit(SDL_INIT_EVENTS)) {
SDL_InitSubSystem(SDL_INIT_EVENTS);
}

if (0 == SDL_WasInit(SDL_INIT_JOYSTICK)) {
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
}

SDL_JoystickEventState(SDL_ENABLE);
SDL2Initializer::init();
}

SDL2EventHandler::~SDL2EventHandler() {
SDL2Initializer::release();

unregisterAllMenuCommands();

delete m_eventTriggerer;
Expand Down
6 changes: 6 additions & 0 deletions src/Engine/Platform/sdl2/SDL2Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ bool SDL2Initializer::init() {
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS) < 0 ) {
return false;
}

if (0 == SDL_WasInit(SDL_INIT_JOYSTICK)) {
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
}
SDL_JoystickEventState(SDL_ENABLE);

s_inited = true;

return true;
Expand Down
Loading