Logging cleanup (#69)

* Mac OS X 10.6 & More C++03 Support

* Fix SDL2 options.txt loading for C++03

* Output/Logging Overhaul
* Added StandardOut class
* Renamed LOGX macros to LOG_X
* Removed LogMsg macros in favor of LOG_X
* Added console window for debug Windows builds

* Updated Xcode Project
+ StandardOut.hpp
+ StandardOut.cpp

* StandardOut_windows
* Replaced the Windows #ifdefs in StandardOut with StandardOut_windows

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
This commit is contained in:
Brent
2023-08-28 02:55:41 -05:00
committed by GitHub
parent f7915a1dab
commit 5c1ea03747
43 changed files with 326 additions and 207 deletions

View File

@@ -12,6 +12,7 @@
#include <shlobj.h>
#include "AppPlatform_windows.hpp"
#include "StandardOut_windows.hpp"
#include "thirdparty/stb_image.h"
#include "thirdparty/stb_image_write.h"
@@ -31,6 +32,15 @@ AppPlatform_windows::AppPlatform_windows()
m_bShiftPressed = false;
m_MouseDiffX = 0, m_MouseDiffY = 0;
// This initializes the StandardOut singleton to use the Windows-specific variant
// If we didn't initialize it here, the Minecraft class would have our back
m_standardOut = new StandardOut_windows();
}
AppPlatform_windows::~AppPlatform_windows()
{
SAFE_DELETE(m_standardOut);
}
int AppPlatform_windows::checkLicense()
@@ -137,7 +147,7 @@ Texture AppPlatform_windows::loadTexture(const std::string& str, bool b)
FILE* f = fopen(realPath.c_str(), "rb");
if (!f)
{
LogMsg("File %s couldn't be opened", realPath.c_str());
LOG_E("File %s couldn't be opened", realPath.c_str());
_error:
const std::string msg = "Error loading " + realPath + ". Did you unzip the Minecraft assets?";
@@ -153,7 +163,7 @@ Texture AppPlatform_windows::loadTexture(const std::string& str, bool b)
stbi_uc* img = stbi_load_from_file(f, &width, &height, &channels, STBI_rgb_alpha);
if (!img)
{
LogMsg("File %s couldn't be loaded via stb_image", realPath.c_str());
LOG_E("File %s couldn't be loaded via stb_image", realPath.c_str());
goto _error;
}

View File

@@ -16,11 +16,13 @@
#include "client/player/input/Mouse.hpp"
#include "client/player/input/Keyboard.hpp"
#include "common/Utils.hpp"
#include "StandardOut_windows.hpp"
class AppPlatform_windows : public AppPlatform
{
public:
AppPlatform_windows();
~AppPlatform_windows();
void buyGame() override;
void saveScreenshot(const std::string& fileName, int width, int height) override;
int checkLicense() override;
@@ -75,5 +77,7 @@ private:
bool m_bShiftPressed;
int m_MouseDiffX, m_MouseDiffY;
StandardOut_windows *m_standardOut;
};

View File

@@ -14,7 +14,7 @@
SoundSystemWindows::SoundSystemWindows()
{
printf("Init SoundSystemWindows\n");
LOG_I("Init SoundSystemWindows");
HRESULT result;
DSBUFFERDESC bufferDesc;
@@ -24,14 +24,14 @@ SoundSystemWindows::SoundSystemWindows()
result = DirectSoundCreate8(NULL, &m_directsound, NULL);
if (FAILED(result))
{
printf("SoundSystemWindows failed to create directsound8 handle\n");
LOG_E("SoundSystemWindows failed to create directsound8 handle");
return;
}
result = m_directsound->SetCooperativeLevel(GetHWND(), DSSCL_NORMAL);
if (FAILED(result))
{
printf("SoundSystemWindows failed set cooperation level\n");
LOG_E("SoundSystemWindows failed set cooperation level");
return;
}
@@ -47,7 +47,7 @@ SoundSystemWindows::SoundSystemWindows()
result = m_directsound->CreateSoundBuffer(&bufferDesc, &primaryBuffer, NULL);
if (FAILED(result))
{
printf("SoundSystemWindows failed to create primary sound buffer\n");
LOG_E("SoundSystemWindows failed to create primary sound buffer");
return;
}
@@ -57,7 +57,7 @@ SoundSystemWindows::SoundSystemWindows()
if (FAILED(result))
{
printf("SoundSystemWindows failed to create 3D listener\n");
LOG_E("SoundSystemWindows failed to create 3D listener\n");
}
m_available = true;
@@ -67,7 +67,7 @@ SoundSystemWindows::SoundSystemWindows()
SoundSystemWindows::~SoundSystemWindows()
{
printf("Destroying SoundSystemWindows\n");
LOG_I("Destroying SoundSystemWindows");
if (!isAvailable())
{
@@ -203,7 +203,7 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float
result = m_directsound->CreateSoundBuffer(&bufferDesc, &tempBuffer, NULL);
if (FAILED(result))
{
printf("SoundSystemWindows CreateSoundBuffer failed\n");
LOG_E("SoundSystemWindows CreateSoundBuffer failed");
return;
}
@@ -211,7 +211,7 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float
result = tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&soundbuffer);
if (FAILED(result))
{
printf("SoundSystemWindows tempBuffer QueryInterface failed\n");
LOG_E("SoundSystemWindows tempBuffer QueryInterface failed");
return;
}
@@ -224,7 +224,7 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float
result = soundbuffer->Lock(0, length, (void**)&bufferPtr, (DWORD*)&bufferSize, NULL, 0, 0);
if (FAILED(result))
{
printf("SoundSystemWindows lock failed\n");
LOG_E("SoundSystemWindows lock failed");
return;
//return false;
}
@@ -236,7 +236,7 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float
result = soundbuffer->Unlock((void*)bufferPtr, bufferSize, NULL, 0);
if (FAILED(result))
{
printf("SoundSystemWindows unlock failed\n");
LOG_E("SoundSystemWindows unlock failed");
return;
}
@@ -275,7 +275,7 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float
HRESULT hr = soundbuffer->QueryInterface(IID_IDirectSound3DBuffer8,
(LPVOID*)&object3d);
if (FAILED(hr)) {
printf("SoundSystemWindows QueryInterface failed for 3D Object\n");
LOG_E("SoundSystemWindows QueryInterface failed for 3D Object");
return;
}

View File

@@ -0,0 +1,34 @@
#include <iostream>
#include <stdarg.h>
#include <windows.h>
#include "StandardOut_windows.hpp"
#include "common/Util.hpp"
void StandardOut_windows::print(const char* const str)
{
StandardOut::print(str);
OutputDebugStringA(str);
OutputDebugStringA("\n");
}
void StandardOut_windows::print(std::string str)
{
print(str.c_str());
}
void StandardOut_windows::vprintf(const char* const fmt, va_list argPtr)
{
print(Util::vformat(fmt, argPtr));
}
void StandardOut_windows::printf(const char* const fmt, ...)
{
va_list argList;
va_start(argList, fmt);
vprintf(fmt, argList);
va_end(argList);
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include <string>
#include "common/StandardOut.hpp"
class StandardOut_windows : StandardOut
{
void print(const char* const str) override;
void print(std::string str) override;
void vprintf(const char* const fmt, va_list argPtr) override;
void printf(const char* const fmt, ...) override;
};

View File

@@ -21,45 +21,6 @@ LPCTSTR g_WindowClassName = TEXT("MCPEClass");
AppPlatform_windows g_AppPlatform;
NinecraftApp* g_pApp;
void LogMsg(const char* fmt, ...)
{
va_list lst;
va_start(lst, fmt);
#ifdef _WIN32
char buf[10240];
vsnprintf(buf, sizeof buf, fmt, lst);
buf[sizeof buf - 1] = 0;
OutputDebugStringA(buf);
OutputDebugStringA("\n");
#else
vfprintf(stderr, fmt, lst);
fprintf(stderr, "\n");
#endif
va_end(lst);
}
// I hate duplicating code, but yeah
void LogMsgNoCR(const char* fmt, ...)
{
va_list lst;
va_start(lst, fmt);
#ifdef _WIN32
char buf[10240];
vsnprintf(buf, sizeof buf, fmt, lst);
buf[sizeof buf - 1] = 0;
OutputDebugStringA(buf);
#else
vfprintf(stderr, fmt, lst);
#endif
va_end(lst);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
@@ -162,6 +123,15 @@ void CheckOptionalTextureAvailability()
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
#ifdef _DEBUG
AllocConsole();
FILE* ostream;
FILE* istream;
freopen_s(&ostream, "CONOUT$", "w", stdout);
freopen_s(&istream, "CONIN$", "r", stdin);
SetConsoleTitle("Minecraft C++ Debug Console");
#endif
SetInstance(hInstance);
// register the window class:

View File

@@ -381,8 +381,9 @@
<ClInclude Include="$(MC_ROOT)\thirdparty\zlib\zconf.h" />
<ClInclude Include="$(MC_ROOT)\thirdparty\zlib\zlib.h" />
<ClInclude Include="$(MC_ROOT)\thirdparty\zlib\zutil.h" />
<ClInclude Include="..\..\..\compat\KeyCodes.hpp" />
<ClInclude Include="..\..\..\compat\SDLKeyCodes.h" />
<ClInclude Include="$(MC_ROOT)\compat\KeyCodes.hpp" />
<ClInclude Include="$(MC_ROOT)\compat\SDLKeyCodes.h" />
<ClInclude Include="$(MC_ROOT)\source\common\StandardOut.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MC_ROOT)\compat\GLExt.cpp" />
@@ -390,6 +391,7 @@
<ClCompile Include="$(MC_ROOT)\platforms\windows\AppPlatform_windows.cpp" />
<ClCompile Include="$(MC_ROOT)\platforms\windows\main.cpp" />
<ClCompile Include="$(MC_ROOT)\platforms\windows\SoundSystemWindows.cpp" />
<ClInclude Include="$(MC_ROOT)\platforms\windows\StandardOut_windows.hpp" />
<ClCompile Include="$(MC_ROOT)\source\App.cpp" />
<ClCompile Include="$(MC_ROOT)\source\AppPlatform.cpp" />
<ClCompile Include="$(MC_ROOT)\source\client\gui\components\AvailableGamesList.cpp" />
@@ -727,6 +729,8 @@
<ClCompile Include="$(MC_ROOT)\thirdparty\zlib\trees.c" />
<ClCompile Include="$(MC_ROOT)\thirdparty\zlib\uncompr.c" />
<ClCompile Include="$(MC_ROOT)\thirdparty\zlib\zutil.c" />
<ClCompile Include="..\..\..\source\common\StandardOut.cpp" />
<ClCompile Include="..\StandardOut_windows.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="$(MC_ROOT)\thirdparty\raknet\CMakeLists.txt" />

View File

@@ -103,6 +103,9 @@
<Filter Include="source\platforms\windows">
<UniqueIdentifier>{27e531b5-8c5e-4fcc-aa64-b1f364da0746}</UniqueIdentifier>
</Filter>
<Filter Include="source\platforms\base">
<UniqueIdentifier>{43e2c12c-cafd-47ac-be4b-3689b4c53d30}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\thirdparty\raknet\ThreadsafePacketLogger.h">
@@ -1173,6 +1176,12 @@
<ClInclude Include="..\..\..\compat\SDLKeyCodes.h">
<Filter>thirdparty</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\common\StandardOut.hpp">
<Filter>source\common</Filter>
</ClInclude>
<ClInclude Include="..\StandardOut_windows.hpp">
<Filter>source\platforms\windows</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MC_ROOT)\thirdparty\raknet\TwoWayAuthentication.cpp">
@@ -2201,6 +2210,12 @@
<ClCompile Include="$(MC_ROOT)\platforms\windows\SoundSystemWindows.cpp">
<Filter>source\platforms\windows</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\common\StandardOut.cpp">
<Filter>source\common</Filter>
</ClCompile>
<ClCompile Include="..\StandardOut_windows.cpp">
<Filter>source\platforms\windows</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="$(MC_ROOT)\thirdparty\raknet\CMakeLists.txt">