Skip to content

Commit

Permalink
Some Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBrokenRail committed Jun 18, 2024
1 parent 7e1940a commit 8ee49a8
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mkdir -p build
cd build

# Configure Build
emcmake cmake -GNinja "$@" ../../platforms/sdl
emcmake cmake -GNinja "$@" ../../

# Build
cmake --build .
Expand Down
9 changes: 4 additions & 5 deletions platforms/sdl/base/AppPlatform_sdl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "SoundSystemAL.hpp"
#define SOUND_SYSTEM SoundSystemAL
#endif
// Macros are cursed
#define _STR(x) #x
#define STR(x) _STR(x)

void AppPlatform_sdl_base::_init(std::string storageDir, SDL_Window *window)
{
Expand All @@ -36,7 +39,6 @@ void AppPlatform_sdl_base::_init(std::string storageDir, SDL_Window *window)

ensureDirectoryExists(_storageDir.c_str());

m_pLogger = new Logger;
m_pSoundSystem = nullptr;

// Default Touchscreen Mode
Expand Down Expand Up @@ -64,7 +66,7 @@ void AppPlatform_sdl_base::initSoundSystem()
{
if (!m_pSoundSystem)
{
LOG_I("Initializing OpenAL SoundSystem...");
LOG_I("Initializing " STR(SOUND_SYSTEM) "...");
m_pSoundSystem = new SOUND_SYSTEM();
}
else
Expand Down Expand Up @@ -112,9 +114,6 @@ AppPlatform_sdl_base::~AppPlatform_sdl_base()
SAFE_DELETE(_iconTexture);

SAFE_DELETE(m_pSoundSystem);

// DELETE THIS LAST
SAFE_DELETE(m_pLogger);
}

SDL_Surface* AppPlatform_sdl_base::getSurfaceForTexture(const Texture* const texture)
Expand Down
1 change: 0 additions & 1 deletion platforms/sdl/base/AppPlatform_sdl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class AppPlatform_sdl_base : public AppPlatform

bool _mousegrabbed;

Logger* m_pLogger;
SoundSystem* m_pSoundSystem;

bool m_bIsTouchscreen;
Expand Down
4 changes: 4 additions & 0 deletions platforms/sdl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ void CheckOptionalTextureAvailability()
// Main
int main(int argc, char *argv[])
{
// Setup Logging
new Logger;

// Setup SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
LOG_E("Unable To Initialize SDL: %s", SDL_GetError());
Expand Down
7 changes: 0 additions & 7 deletions platforms/windows/AppPlatform_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "GameMods.hpp"

#include "AppPlatform_win32.hpp"
#include "LoggerWin32.hpp"

#include "thirdparty/GL/GL.hpp"

Expand All @@ -37,18 +36,12 @@ AppPlatform_win32::AppPlatform_win32()

m_MouseDiffX = 0, m_MouseDiffY = 0;

// This initializes the Logger singleton to use the Windows-specific variant
// If we didn't initialize it here, the Minecraft class would have our back
m_pLogger = new LoggerWin32();
m_pSoundSystem = nullptr;
}

AppPlatform_win32::~AppPlatform_win32()
{
SAFE_DELETE(m_pSoundSystem);

// DELETE THIS LAST
SAFE_DELETE(m_pLogger);
}

void AppPlatform_win32::initSoundSystem()
Expand Down
1 change: 0 additions & 1 deletion platforms/windows/AppPlatform_win32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class AppPlatform_win32 : public AppPlatform

int m_MouseDiffX, m_MouseDiffY;

LoggerWin32 *m_pLogger;
SoundSystemDS* m_pSoundSystem;
};

5 changes: 5 additions & 0 deletions platforms/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "client/player/input/Multitouch.hpp"

#include "AppPlatform_win32.hpp"
#include "LoggerWin32.hpp"

LPCTSTR g_WindowClassName = TEXT("MCPEClass");

Expand Down Expand Up @@ -142,6 +143,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine

SetInstance(hInstance);

// This initializes the Logger singleton to use the Windows-specific variant
// If we didn't initialize it here, the Minecraft class would have our back
new LoggerWin32;

// register the window class:
WNDCLASS wc;
wc.style = CS_OWNDC;
Expand Down
3 changes: 0 additions & 3 deletions source/client/app/Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ Minecraft::Minecraft() :
m_licenseID = -2;
m_fLastUpdated = 0;
m_fDeltaTime = 0;

m_Logger = new Logger();
}

int Minecraft::getLicenseId()
Expand Down Expand Up @@ -869,7 +867,6 @@ Minecraft::~Minecraft()
SAFE_DELETE(m_pUser);
SAFE_DELETE(m_pLevelStorageSource);
SAFE_DELETE(m_pInputHolder);
SAFE_DELETE(m_Logger);

//@BUG: potentially leaking a CThread instance if this is destroyed early?
}
Expand Down
1 change: 0 additions & 1 deletion source/client/app/Minecraft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class Minecraft : public App
static int customDebugId;

private:
Logger *m_Logger;
Options *m_options;

public:
Expand Down
5 changes: 4 additions & 1 deletion source/common/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ Logger* const Logger::singleton()
Logger::Logger()
{
// Stick with the first output handle we get
if (!m_singleton)
if (!m_singleton) {
m_singleton = this;
} else {
m_singleton->print(LOG_ERR, "Logging already setup!");
}
}

Logger::~Logger()
Expand Down

0 comments on commit 8ee49a8

Please sign in to comment.