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

@@ -46,6 +46,6 @@
//#define DEMO
// Enable Debug Mode
#define MC_DEBUG
//#define MC_DEBUG
#endif

View File

@@ -252,14 +252,14 @@ void xglGenBuffers(GLsizei num, GLuint* buffers)
g_GLBuffers[g_NextGLBufferID] = new GLBuffer(g_NextGLBufferID);
}
LogMsg("g_NextGLBufferID=%d", g_NextGLBufferID);
LOG_I("g_NextGLBufferID=%d", g_NextGLBufferID);
}
void xglAssert2(bool condition, const char* condstr, const char* file, int line)
{
if (condition) return;
LogMsg("Error: Assertion failed at %s:%d: %s", file, line, condstr);
LOG_E("Error: Assertion failed at %s:%d: %s", file, line, condstr);
#ifdef _MSC_VER
assert(false);

View File

@@ -28,6 +28,6 @@ Texture AppPlatform_emscripten::loadTexture(const std::string& path, bool b)
}
// I don't think this logic makes any sense
LogMsg("Couldn't find file: %s", realPath.c_str());
LOG_E("Couldn't find file: %s", realPath.c_str());
return out;
}

View File

@@ -352,6 +352,7 @@
849B93022A99C3D900CF0DE0 /* SoundEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 849B92B72A99C3D900CF0DE0 /* SoundEngine.cpp */; };
849B93032A99C3D900CF0DE0 /* SoundRepository.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 849B92B92A99C3D900CF0DE0 /* SoundRepository.cpp */; };
849B93042A99C3D900CF0DE0 /* SoundSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 849B92BB2A99C3D900CF0DE0 /* SoundSystem.cpp */; };
84A1072A2A9B183A00850A9C /* StandardOut.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84A107282A9B183A00850A9C /* StandardOut.cpp */; };
84C4D86F2A872C0100323E33 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84C4D86E2A872C0100323E33 /* OpenAL.framework */; };
/* End PBXBuildFile section */
@@ -1079,6 +1080,8 @@
849B92BB2A99C3D900CF0DE0 /* SoundSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SoundSystem.cpp; sourceTree = "<group>"; };
849B92BC2A99C3D900CF0DE0 /* SoundSystem.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SoundSystem.hpp; sourceTree = "<group>"; };
849B930F2A99C44A00CF0DE0 /* GameMods.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = GameMods.hpp; path = ../../../GameMods.hpp; sourceTree = SOURCE_ROOT; };
84A107282A9B183A00850A9C /* StandardOut.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StandardOut.cpp; sourceTree = "<group>"; };
84A107292A9B183A00850A9C /* StandardOut.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = StandardOut.hpp; sourceTree = "<group>"; };
84C4D86E2A872C0100323E33 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = /System/Library/Frameworks/OpenAL.framework; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
@@ -1442,6 +1445,8 @@
8443B6942A9865110086730C /* Options.hpp */,
8443B6952A9865110086730C /* Random.cpp */,
8443B6962A9865110086730C /* Random.hpp */,
84A107282A9B183A00850A9C /* StandardOut.cpp */,
84A107292A9B183A00850A9C /* StandardOut.hpp */,
8443B6972A9865110086730C /* Timer.cpp */,
8443B6982A9865110086730C /* Timer.hpp */,
8443B6992A9865110086730C /* Util.cpp */,
@@ -2523,6 +2528,7 @@
849B93022A99C3D900CF0DE0 /* SoundEngine.cpp in Sources */,
849B93032A99C3D900CF0DE0 /* SoundRepository.cpp in Sources */,
849B93042A99C3D900CF0DE0 /* SoundSystem.cpp in Sources */,
84A1072A2A9B183A00850A9C /* StandardOut.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -10,7 +10,7 @@ SoundSystemAL::SoundSystemAL()
device = alcOpenDevice(NULL);
if (!device)
{
LogMsg("Unable To Load Audio Engine");
LOG_E("Unable To Load Audio Engine");
return;
}
@@ -19,7 +19,7 @@ SoundSystemAL::SoundSystemAL()
ALCenum err = alcGetError(device);
if (err != ALC_NO_ERROR)
{
LogMsg("Unable To Open Audio Context: %s", alcGetString(device, err));
LOG_E("Unable To Open Audio Context: %s", alcGetString(device, err));
return;
}
@@ -28,7 +28,7 @@ SoundSystemAL::SoundSystemAL()
err = alcGetError(device);
if (err != ALC_NO_ERROR)
{
LogMsg("Unable To Select Audio Context: %s", alcGetString(device, err));
LOG_E("Unable To Select Audio Context: %s", alcGetString(device, err));
return;
}
@@ -57,7 +57,7 @@ SoundSystemAL::~SoundSystemAL()
ALCenum err = alcGetError(device);
if (err != ALC_NO_ERROR)
{
LogMsg("Unable To Deselect Audio Context: %s", alcGetString(device, err));
LOG_E("Unable To Deselect Audio Context: %s", alcGetString(device, err));
}
// Destroy Context
@@ -65,7 +65,7 @@ SoundSystemAL::~SoundSystemAL()
err = alcGetError(device);
if (err != ALC_NO_ERROR)
{
LogMsg("Unable To Destroy Audio Context: %s", alcGetString(device, err));
LOG_E("Unable To Destroy Audio Context: %s", alcGetString(device, err));
}
// Close Device
@@ -74,7 +74,7 @@ SoundSystemAL::~SoundSystemAL()
/*err = alcGetError(device);
if (err != ALC_NO_ERROR)
{
LogMsg("Unable To Close Audio Device: %s", alcGetString(device, err));
LOG_E("Unable To Close Audio Device: %s", alcGetString(device, err));
}*/
}
@@ -85,7 +85,7 @@ SoundSystemAL::~SoundSystemAL()
ALenum __err = val; \
if (__err != AL_NO_ERROR) \
{ \
LogMsg("(%s:%i) OpenAL Error: %s", __FILE__, __LINE__, alGetString(__err)); \
LOG_E("(%s:%i) OpenAL Error: %s", __FILE__, __LINE__, alGetString(__err)); \
exit(EXIT_FAILURE); \
} \
}

View File

@@ -107,7 +107,7 @@ void AppPlatform_sdl::ensureDirectoryExists(const char* path)
if (ret != 0)
{
// Unable To Create Folder
LogMsg("Error Creating Directory: %s: %s", path, strerror(errno));
LOG_E("Error Creating Directory: %s: %s", path, strerror(errno));
exit(EXIT_FAILURE);
}
}
@@ -177,11 +177,11 @@ void AppPlatform_sdl::saveScreenshot(const std::string& filename, int glWidth, i
// Save Image
if (fail || save_png(file.c_str(), pixels, line_size, width, height))
{
LogMsg("Screenshot Failed: %s", file.c_str());
LOG_E("Screenshot Failed: %s", file.c_str());
}
else
{
LogMsg("Screenshot Saved: %s", file.c_str());
LOG_I("Screenshot Saved: %s", file.c_str());
}
// Free
@@ -284,8 +284,8 @@ Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
SDL_RWclose(io);
}
// TODO: I don't think this logic makes any sense
LogMsg("Couldn't find file: %s", path.c_str());
// TODO: I don't think this logic makes any sense
LOG_E("Couldn't find file: %s", path.c_str());
return out;
}
@@ -299,12 +299,12 @@ std::vector<std::string> AppPlatform_sdl::getOptionStrings()
// TODO: This isn't specific to SDL2. Why isn't it in an AppPlatform base class?
std::vector<std::string> o;
LogMsg("Storage dir is %s", _storageDir.c_str());
LOG_I("Storage dir is %s", _storageDir.c_str());
std::ifstream ifs(getOptionsFilePath().c_str());
if (!ifs.is_open())
{
LogMsg("Warning, options.txt doesn't exist, resetting to defaults");
LOG_W("options.txt doesn't exist, resetting to defaults");
return o;
}
@@ -340,7 +340,7 @@ void AppPlatform_sdl::setOptionStrings(const std::vector<std::string>& str)
os.open(getOptionsFilePath().c_str());
if (!os.is_open())
{
LogMsg("Error, options.txt can't be opened");
LOG_E("Failed to read options.txt");
return;
}

View File

@@ -56,7 +56,7 @@ SDL_Surface* AppPlatform_sdlbase::getSurfaceForTexture(const Texture* const text
0xFF000000
);
if (!surface)
LogMsg("Error loading SDL_Surface from Texture: %s", SDL_GetError());
LOG_E("Failed loading SDL_Surface from Texture: %s", SDL_GetError());
return surface;
}

View File

@@ -26,27 +26,6 @@ typedef AppPlatform_sdl UsedAppPlatform;
static float g_fPointToPixelScale = 1.0f;
void LogMsg(const char* fmt, ...)
{
va_list lst;
va_start(lst, fmt);
vprintf(fmt, lst);
printf("\n");
va_end(lst);
}
// I hate duplicating code, but yeah
void LogMsgNoCR(const char* fmt, ...)
{
va_list lst;
va_start(lst, fmt);
vprintf(fmt, lst);
va_end(lst);
}
UsedAppPlatform *g_pAppPlatform;
NinecraftApp *g_pApp;
@@ -262,7 +241,7 @@ int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
LOGE("Unable To Initialize SDL: %s\n", SDL_GetError());
LOG_E("Unable To Initialize SDL: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
@@ -290,7 +269,7 @@ int main(int argc, char *argv[])
window = SDL_CreateWindow("ReMinecraftPE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Minecraft::width, Minecraft::height, flags);
if (!window)
{
LOGE("Unable to create SDL window\n");
LOG_E("Unable to create SDL window\n");
exit(EXIT_FAILURE);
}
@@ -301,7 +280,7 @@ int main(int argc, char *argv[])
context = SDL_GL_CreateContext(window);
if (!context)
{
LOGE("Unable to create OpenGL context\n");
LOG_E("Unable to create OpenGL context\n");
exit(EXIT_FAILURE);
}

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">

View File

@@ -89,6 +89,8 @@ Minecraft::Minecraft() :
m_fLastUpdated = 0;
m_fDeltaTime = 0;
m_standardOut = new StandardOut();
#ifndef ORIGINAL_CODE
m_pTurnInput = new MouseTurnInput(this);
#else
@@ -797,6 +799,7 @@ Minecraft::~Minecraft()
SAFE_DELETE(m_pUser);
SAFE_DELETE(m_pLevelStorageSource);
SAFE_DELETE(m_pTurnInput);
SAFE_DELETE(m_standardOut);
//@BUG: potentially leaking a CThread instance if this is destroyed early?
}

View File

@@ -88,6 +88,9 @@ public:
static const bool DEADMAU5_CAMERA_CHEATS;
static int customDebugId;
private:
StandardOut *m_standardOut;
public:
bool field_18;
Options m_options;

View File

@@ -125,13 +125,13 @@ void NinecraftApp::updateStats()
if (m_pLocalPlayer)
{
Vec3 &pos = m_pLocalPlayer->m_pos;
printf("%d fps\t%3d chunk updates. (%.2f, %.2f, %.2f)\n", m_fps, Chunk::updates, pos.x, pos.y, pos.z);
printf("%s", m_pLevelRenderer->gatherStats1().c_str());
LOG_I("%d fps\t%3d chunk updates. (%.2f, %.2f, %.2f)", m_fps, Chunk::updates, pos.x, pos.y, pos.z);
LOG_I("%s", m_pLevelRenderer->gatherStats1().c_str());
Chunk::updates = 0;
}
else
{
printf("%d fps\n", m_fps);
LOG_I("%d fps", m_fps);
}
field_2B0 = timeMs;

View File

@@ -53,7 +53,7 @@ LevelRenderer::LevelRenderer(Minecraft* pMC, Textures* pTexs)
m_pBuffers = new GLuint[m_nBuffers];
xglGenBuffers(m_nBuffers, m_pBuffers);
printf("numBuffers: %d\n", m_nBuffers);
LOG_I("numBuffers: %d", m_nBuffers);
xglGenBuffers(1, &field_D8);
generateSky(); // inlined in the 0.1.0 demo
@@ -146,7 +146,7 @@ void LevelRenderer::allChanged()
field_A8 = 8;
m_chunksLength = field_A8 * field_A4 * field_AC;
printf("chunksLength: %d\n", m_chunksLength);
LOG_I("chunksLength: %d", m_chunksLength);
m_chunks = new Chunk* [m_chunksLength];
field_98 = new Chunk* [m_chunksLength];
@@ -1162,6 +1162,7 @@ void LevelRenderer::takePicture(TripodCamera* pCamera, Entity* pOwner)
void LevelRenderer::addParticle(const std::string& name, float x, float y, float z, float vx, float vy, float vz)
{
// TODO: Who's the genius who decided it'd be better to check a name string rather than an enum?
if (m_pMinecraft->m_pMobPersp->distanceToSqr_inline(x, y, z) > 256.0f)
return;
@@ -1202,13 +1203,12 @@ void LevelRenderer::addParticle(const std::string& name, float x, float y, float
return;
}
#ifndef ORIGINAL_CODE
//LogMsg("Unknown particle type: %s", name.c_str());
#endif
LOG_W("Unknown particle type: %s", name.c_str());
}
void LevelRenderer::playSound(const std::string& name, float x, float y, float z, float a, float b)
{
// TODO: Who's the genius who decided it'd be better to check a name string rather than an enum?
float mult = 1.0f, dist = 16.0f;
if (a > 1.0f)

View File

@@ -41,7 +41,7 @@ void PatchManager::LoadPatchData(const std::string& patchData)
if (command == "stop_now")
{
LogMsg("PatchManager: Found stop_now, quitting patch processing earlier, iProgramInCpp probably wanted to test something");
LOG_I("PatchManager: Found stop_now, quitting patch processing earlier, iProgramInCpp probably wanted to test something");
return;
}
@@ -116,7 +116,7 @@ void PatchManager::LoadPatchData(const std::string& patchData)
if (itemID == -1)
{
namefailure:
LogMsg("Unknown item/tile with the name %s", itemName.c_str());
LOG_W("Unknown item/tile with the name %s", itemName.c_str());
continue;
}
@@ -142,7 +142,7 @@ void PatchManager::LoadPatchData(const std::string& patchData)
continue;
}
LogMsg("Unknown command %s from patch data.", command.c_str());
LOG_W("Unknown command %s from patch data.", command.c_str());
}
}
@@ -158,7 +158,7 @@ void PatchManager::PatchTextures(AppPlatform* pAppPlatform, ePatchType patchType
Texture texture = pAppPlatform->loadTexture("patches/" + pd.m_filename, true);
if (texture.m_width == 0)
{
LogMsg("Image %s has width 0, not found?! Skipping", pd.m_filename.c_str());
LOG_W("Image %s has width 0, not found?! Skipping", pd.m_filename.c_str());
continue;
}
@@ -198,7 +198,7 @@ void PatchManager::PatchTiles()
continue;
}
LogMsg("PatchTiles: unknown item ID %d", pd.m_destID);
LOG_W("PatchTiles: unknown item ID %d", pd.m_destID);
}
}

View File

@@ -322,7 +322,7 @@ void Tesselator::vertex(float x, float y, float z)
if (!(field_4 & 3) && field_2C >= m_maxVertices - 1)
{
for (int i = 0; i < 3; i++)
puts("Overwriting the vertex buffer! This chunk/entity won't show up");
LOG_W("Overwriting the vertex buffer! This chunk/entity won't show up");
clear();
}

View File

@@ -21,6 +21,7 @@ SoundEngine::SoundEngine()
void SoundEngine::init(Options* options)
{
// TODO: Who's the genius who decided it'd be better to check a name string rather than an enum?
m_pOptions = options;
m_repository.add("step.cloth", SA_cloth1);

View File

@@ -27,10 +27,11 @@ void SoundRepository::add(const std::string& name, SoundDesc& sd)
bool SoundRepository::get(const std::string& name, SoundDesc& sd)
{
// TODO: Who's the genius who decided it'd be better to check a name string rather than an enum?
std::map<std::string, std::vector<SoundDesc> >::iterator iter = m_repo.find(name);
if (iter == m_repo.end())
{
printf("Couldn't find a sound with id: %s\n", name.c_str());
LOG_E("Couldn't find a sound with id: %s", name.c_str());
return false;
}

View File

@@ -0,0 +1,50 @@
#include <iostream>
#include <stdarg.h>
#include "StandardOut.hpp"
#include "Util.hpp"
StandardOut* StandardOut::m_singleton = nullptr;
StandardOut* const StandardOut::singleton()
{
return m_singleton;
}
StandardOut::StandardOut()
{
// Stick with the first output handle we get
if (!m_singleton)
m_singleton = this;
}
StandardOut::~StandardOut()
{
if (m_singleton == this)
m_singleton = nullptr;
}
void StandardOut::print(const char* const str)
{
std::cout << str << std::endl;
}
void StandardOut::print(std::string str)
{
print(str.c_str());
}
void StandardOut::vprintf(const char* const fmt, va_list argPtr)
{
print(Util::vformat(fmt, argPtr));
}
void StandardOut::printf(const char* const fmt, ...)
{
va_list argList;
va_start(argList, fmt);
vprintf(fmt, argList);
va_end(argList);
}

View File

@@ -0,0 +1,42 @@
#pragma once
#include <string>
class StandardOut
{
private:
static StandardOut* m_singleton;
public:
static StandardOut* const singleton();
StandardOut();
~StandardOut();
virtual void print(const char* const str);
virtual void print(std::string str);
virtual void vprintf(const char* const fmt, va_list argPtr);
virtual void printf(const char* const fmt, ...);
};
#ifdef _DEBUG
#define LOG(...) StandardOut::singleton()->printf(__VA_ARGS__)
#ifdef PLATFORM_ANDROID
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, "MinecraftPE", __VA_ARGS__)
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, "MinecraftPE", __VA_ARGS__)
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, "MinecraftPE", __VA_ARGS__)
#else
#define LOG_I(...) LOG("[Info]: " __VA_ARGS__)
#define LOG_W(...) LOG("[WARN]: " __VA_ARGS__)
#define LOG_E(...) LOG("[ERROR]: " __VA_ARGS__)
#endif
#else
#define LOG(...)
#define LOG_I(...)
#define LOG_W(...)
#define LOG_E(...)
#endif

View File

@@ -6,6 +6,7 @@
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include <stdarg.h>
#include "Util.hpp"
std::string Util::stringTrim(const std::string& str, const std::string& filter, bool a4, bool a5)
@@ -43,3 +44,23 @@ std::string Util::stringTrim(const std::string& str)
return stringTrim(str, " \t\n\r", true, true);
}
std::string Util::vformat(const char *fmt, va_list argPtr)
{
char str[1024];
vsnprintf(str, sizeof(str), fmt, argPtr);
return std::string(str);
}
std::string Util::format(const char *fmt, ...)
{
std::string str;
va_list argList;
va_start(argList, fmt);
str = vformat(fmt, argList);
va_end(argList);
return str;
}

View File

@@ -20,6 +20,9 @@ public:
static std::string stringTrim(const std::string &, const std::string &, bool, bool);
static std::string stringTrim(const std::string &);
static std::string vformat(const char* fmt, va_list argPtr);
static std::string format(const char* fmt, ...);
template<typename T>
static bool remove(std::vector<T>& vec, const T& t)
{

View File

@@ -83,10 +83,11 @@ void closedir(DIR* dir);
#endif
#include "compat/KeyCodes.hpp"
#include "../../compat/KeyCodes.hpp"
#include "StandardOut.hpp"
// options:
#include "GameMods.hpp"
#include "../../GameMods.hpp"
// don't know where to declare these:
@@ -612,17 +613,6 @@ uint8_t* ZlibDeflateToMemory(uint8_t* pInput, size_t sizeBytes, size_t *compress
uint8_t* ZlibDeflateToMemoryLvl(uint8_t* pInput, size_t sizeBytes, size_t* compressedSizeOut, int level);
// things that we added:
#ifndef ORIGINAL_CODE
void LogMsg(const char* fmt, ...); // not part of actual Minecraft (they use printf), but useful
void LogMsgNoCR(const char* fmt, ...); // not part of actual Minecraft (they use printf), but useful
#ifdef printf
#error "printf is defined. Why?"
#endif
#define printf LogMsgNoCR
#define puts(str) LogMsg("%s", str);
#ifdef _WIN32
@@ -636,30 +626,3 @@ void SetInstance(HINSTANCE hinst);
void SetHWND(HWND hwnd);
#endif
#else
#define LogMsg(...)
#define LogMsgNoCR(...)
#endif
#ifdef MC_DEBUG
#ifdef PLATFORM_ANDROID
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "MinecraftPE", __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, "MinecraftPE", __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "MinecraftPE", __VA_ARGS__)
#else
#define LOGI(...) printf("Info: " __VA_ARGS__)
#define LOGW(...) printf("WARN: " __VA_ARGS__)
#define LOGE(...) printf("ERROR: " __VA_ARGS__)
#endif
#else
#define LOGI(...) printf(__VA_ARGS__)
#define LOGW(...) printf(__VA_ARGS__)
#define LOGE(...) printf(__VA_ARGS__)
#endif

View File

@@ -8,14 +8,15 @@
#include <RakPeer.h>
#include "ClientSideNetworkHandler.hpp"
#include "common/Utils.hpp"
#include "client/gui/screens/StartMenuScreen.hpp"
// This lets you make the client shut up and not log events in the debug console.
#define VERBOSE_CLIENT
#if defined(ORIGINAL_CODE) || defined(VERBOSE_CLIENT)
#define puts_ignorable(str) puts(str)
#define printf_ignorable(str, ...) printf(str, __VA_ARGS__)
#define puts_ignorable(str) LOG_I(str)
#define printf_ignorable(str, ...) LOG_I(str, __VA_ARGS__)
#else
#define puts_ignorable(str)
#define printf_ignorable(str, ...)
@@ -42,7 +43,7 @@ void ClientSideNetworkHandler::levelGenerated(Level* level)
void ClientSideNetworkHandler::onConnect(const RakNet::RakNetGUID& rakGuid) // server guid
{
RakNet::RakNetGUID localGuid = ((RakNet::RakPeer*)m_pServerPeer)->GetMyGUID();
printf_ignorable("onConnect, server guid: %s, local guid: %s\n", rakGuid.ToString(), localGuid.ToString());
printf_ignorable("onConnect, server guid: %s, local guid: %s", rakGuid.ToString(), localGuid.ToString());
m_serverGUID = rakGuid;
@@ -167,7 +168,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, MovePla
Entity* pEntity = m_pLevel->getEntity(packet->m_id);
if (!pEntity)
{
LogMsg("No player with id %d", packet->m_id);
LOG_E("No player with id %d", packet->m_id);
return;
}
@@ -181,7 +182,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, PlaceBl
Player* pPlayer = (Player*)m_pLevel->getEntity(pPlaceBlockPkt->m_playerID);
if (!pPlayer)
{
LogMsg("No player with id %d", pPlaceBlockPkt->m_playerID);
LOG_E("No player with id %d", pPlaceBlockPkt->m_playerID);
return;
}
@@ -218,7 +219,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, RemoveB
Player* pPlayer = (Player*)m_pLevel->getEntity(pRemoveBlockPkt->m_playerID);
if (!pPlayer)
{
LogMsg("No player with id %d", pRemoveBlockPkt->m_playerID);
LOG_E("No player with id %d", pRemoveBlockPkt->m_playerID);
return;
}
@@ -260,14 +261,14 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, ChunkDa
{
if (!m_pLevel)
{
puts("Level @ handle ChunkDataPacket is 0");
LOG_E("Level @ handle ChunkDataPacket is 0");
return;
}
LevelChunk* pChunk = m_pLevel->getChunkSource()->create(pChunkDataPkt->m_x, pChunkDataPkt->m_z);
if (!pChunk || pChunk->isEmpty())
{
puts("Failed to find write-able chunk");
LOG_E("Failed to find write-able chunk");
// @BUG: Not trying again.
return;
}
@@ -348,17 +349,15 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, PlayerE
if (!pPlayer)
return;
#ifndef ORIGINAL_CODE
if (!Item::items[pPlayerEquipmentPkt->m_itemID])
{
LogMsg("That item %d doesn't actually exist!", pPlayerEquipmentPkt->m_itemID);
LOG_W("That item %d doesn't actually exist!", pPlayerEquipmentPkt->m_itemID);
return;
}
#endif
if (pPlayer->m_guid == m_pServerPeer->GetMyGUID())
{
puts("Attempted to modify local player's inventory");
LOG_W("Attempted to modify local player's inventory");
return;
}
@@ -374,7 +373,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
bs->Read(magicNum);
if (magicNum != compMagic && magicNum != uncompMagic)
{
LogMsg("Error, invalid level data packet with magic %d", magicNum);
LOG_E("Invalid level data packet with magic %d", magicNum);
return;
}
@@ -386,7 +385,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
bs->Read(uncompSize);
bs->Read(compSize);
LogMsg("Decompressing level data. Compressed: %d bytes, uncompressed: %d bytes", compSize, uncompSize);
LOG_I("Decompressing level data. Compressed: %d bytes, uncompressed: %d bytes", compSize, uncompSize);
// Read the compressed data.
uint8_t* pCompData = new uint8_t[compSize];
@@ -399,7 +398,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
// If we couldn't, bail
if (!pUncompData)
{
LogMsg("Error, can't decompress level data");
LOG_E("Failed to decompress level data!");
return;
}
@@ -421,7 +420,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
if (chunksX != C_MAX_CHUNKS_X || chunksZ != C_MAX_CHUNKS_Z)
{
LogMsg("Error, we don't yet support a level of size %d x %d chunks. Some chunks may disappear or be regenerated.", chunksX, chunksZ);
LOG_E("We don't yet support a level of size %d x %d chunks. Some chunks may disappear or be regenerated.", chunksX, chunksZ);
}
for (int x = 0; x < chunksX; x++)
@@ -433,7 +432,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
if (magicNum != chunkSepMagic)
{
_FAIL_BECAUSE_INVALID:
LogMsg("Error, aborting because level data is invalid, reading chunk %d, %d. Magic: %d", x, z, magicNum);
LOG_E("Aborting because level data is invalid, reading chunk %d, %d. Magic: %d", x, z, magicNum);
return;
}
@@ -445,7 +444,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LevelDataP
LevelChunk* pChunk = m_pLevel->getChunk(x, z);
if (!pChunk || pChunk->isEmpty())
LogMsg("Error, no chunk at %d, %d", x, z);
LOG_E("No chunk at %d, %d", x, z);
// continue reading anyway to skip over the offending chunk

View File

@@ -7,13 +7,14 @@
********************************************************************/
#include "ServerSideNetworkHandler.hpp"
#include "common/Utils.hpp"
// This lets you make the server shut up and not log events in the debug console.
#define VERBOSE_SERVER
#if defined(ORIGINAL_CODE) || defined(VERBOSE_SERVER)
#define puts_ignorable(str) puts(str)
#define printf_ignorable(str, ...) printf(str, __VA_ARGS__)
#define puts_ignorable(str) LOG_I(str)
#define printf_ignorable(str, ...) LOG_I(str, __VA_ARGS__)
#else
#define puts_ignorable(str)
#define printf_ignorable(str, ...)
@@ -60,7 +61,7 @@ void ServerSideNetworkHandler::levelGenerated(Level* level)
void ServerSideNetworkHandler::onNewClient(const RakNet::RakNetGUID& guid)
{
printf_ignorable("onNewClient, client guid: %s\n", guid.ToString());
printf_ignorable("onNewClient, client guid: %s", guid.ToString());
}
void ServerSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid)
@@ -98,7 +99,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LoginPacke
// if they're already online, fail
if (getPlayerByGUID(guid))
{
printf("That player is already in the world!\n");
LOG_E("That player is already in the world!");
return;
}
@@ -152,7 +153,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, MessagePac
OnlinePlayer* pOP = getPlayerByGUID(guid);
if (!pOP)
{
printf("MessagePacket: That jerk %s doesn't actually exist\n", guid.ToString());
LOG_W("MessagePacket: That jerk %s doesn't actually exist", guid.ToString());
return;
}
@@ -163,7 +164,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, MessagePac
if (msg[0] == '/')
{
printf("CMD: %s: %s\n", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
LOG_I("CMD: %s: %s", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
std::stringstream ss(msg);
ss.get(); // skip the /
@@ -190,7 +191,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, MessagePac
return;
}
printf("MSG: <%s> %s\n", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
LOG_I("MSG: <%s> %s", pOP->m_pPlayer->m_name.c_str(), msg.c_str());
// send everyone the message
std::string gameMessage = "<" + pOP->m_pPlayer->m_name + "> " + msg;
@@ -268,21 +269,21 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, PlayerEqui
Player* pPlayer = (Player*)m_pLevel->getEntity(packet->m_playerID);
if (!pPlayer)
{
LogMsg("No player with id %d", packet->m_playerID);
LOG_W("No player with id %d", packet->m_playerID);
return;
}
#ifndef ORIGINAL_CODE
if (!Item::items[packet->m_itemID])
{
LogMsg("That item %d doesn't actually exist!", packet->m_itemID);
LOG_W("That item %d doesn't actually exist!", packet->m_itemID);
return;
}
#endif
if (pPlayer->m_guid == m_pRakNetPeer->GetMyGUID())
{
puts("Attempted to modify local player's inventory");
LOG_W("Attempted to modify local player's inventory");
return;
}
@@ -304,7 +305,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, RequestChu
LevelChunk* pChunk = m_pLevel->getChunk(packet->m_x, packet->m_z);
if (!pChunk)
{
LogMsg("No chunk at %d, %d", packet->m_x, packet->m_z);
LOG_E("No chunk at %d, %d", packet->m_x, packet->m_z);
return;
}

View File

@@ -61,7 +61,7 @@ void LevelDataPacket::write(RakNet::BitStream* pbs)
if (pCompressedData)
{
float ratio = 100.0f * float(compSize) / float(uncompSize);
//LogMsg("Compression ratio: %.2f (%d comp, %d uncomp)", ratio, int(compSize), int(uncompSize));
//LOG_I("Compression ratio: %.2f (%d comp, %d uncomp)", ratio, int(compSize), int(uncompSize));
int cs2 = int(compSize), us2 = int(uncompSize);
bs.Reset();
@@ -73,7 +73,7 @@ void LevelDataPacket::write(RakNet::BitStream* pbs)
}
else
{
//LogMsg("Level not compressed.");
//LOG_I("Level not compressed.");
}
pbs->Write(bs);

View File

@@ -183,7 +183,7 @@ void Inventory::addTestItem(int itemID, int amount, int auxValue)
if (inst.m_amount != 0)
{
LogMsg("AddTestItem: Couldn't add all %d of %s, only gave %d",
LOG_I("AddTestItem: Couldn't add all %d of %s, only gave %d",
amount, Item::items[itemID]->m_DescriptionID.c_str(), amount - inst.m_amount);
}
}
@@ -291,5 +291,5 @@ void Inventory::selectItemById(int itemID)
return;
}
LogMsg("selectItemById: %d doesn't exist", itemID);
LOG_W("selectItemById: %d doesn't exist", itemID);
}

View File

@@ -40,7 +40,7 @@ Item::Item(int itemID)
if (Item::items[m_itemID])
{
printf("Item conflict id @ %d! Id already used\n", m_itemID);
LOG_W("Item conflict id @ %d! Id already used\n", m_itemID);
}
Item::items[m_itemID] = this;
@@ -66,7 +66,7 @@ Item* Item::setMaxStackSize(int mss)
Item* Item::setCraftingRemainingItem(Item* pItem)
{
if (m_maxStackSize > 1)
puts("Max stack size must be 1 for items with crafting results");
LOG_W("Max stack size must be 1 for items with crafting results");
m_pCraftingRemainingItem = pItem;

View File

@@ -83,7 +83,7 @@ ChunkSource* Level::createChunkSource()
}
#endif
puts("no level data, calling dimension->createRandomLevelSource");
LOG_I("No level data, calling dimension->createRandomLevelSource");
return m_pDimension->createRandomLevelSource();
}
@@ -1029,7 +1029,7 @@ _failure:
m_levelData.m_spawnPos.y = 32;
m_levelData.m_spawnPos.z = 0;
printf("Failed to validate spawn point, using (%d, %d, %d)\n", m_levelData.m_spawnPos.x, m_levelData.m_spawnPos.y, m_levelData.m_spawnPos.z);
LOG_W("Failed to validate spawn point, using (%d, %d, %d)", m_levelData.m_spawnPos.x, m_levelData.m_spawnPos.y, m_levelData.m_spawnPos.z);
return;
#endif
@@ -1075,13 +1075,13 @@ bool Level::addEntity(Entity* pEnt)
Entity* pOldEnt = getEntity(pEnt->hashCode());
if (pOldEnt)
{
LogMsg("Warning: entity %d already exists.", pEnt->hashCode());
LOG_W("Entity %d already exists.", pEnt->hashCode());
//removeEntity(pOldEnt);
}
if (!pEnt->isPlayer() && m_bIsMultiplayer)
{
LogMsg("Hey, why are you trying to add an non-player entity in a multiplayer world?");
LOG_W("Hey, why are you trying to add an non-player entity in a multiplayer world?");
}
//@NOTE: useless Mth::floor() calls
@@ -1194,7 +1194,7 @@ _failure:
m_levelData.m_spawnPos.y = 32;
m_levelData.m_spawnPos.z = 0;
printf("Failed to validate spawn point, using (%d, %d, %d)\n", m_levelData.m_spawnPos.x, m_levelData.m_spawnPos.y, m_levelData.m_spawnPos.z);
LOG_W("Failed to validate spawn point, using (%d, %d, %d)", m_levelData.m_spawnPos.x, m_levelData.m_spawnPos.y, m_levelData.m_spawnPos.z);
return;
#endif
@@ -1406,9 +1406,7 @@ void Level::tick(Entity* pEnt, bool b)
{
if (!hasChunksAt(tileX - 32, 0, tileZ - 32, tileX + 32, 128, tileZ + 32))
{
#ifndef ORIGINAL_CODE
LogMsg("Not updating entity %d because we don't have chunks around it loaded", pEnt->m_EntityID);
#endif
LOG_W("Not updating entity %d because we don't have chunks around it loaded", pEnt->m_EntityID);
return;
}

View File

@@ -745,7 +745,7 @@ void LevelChunk::setData(int x, int y, int z, int data)
// seems to set block data in 8192 block (4*16*128) chunks for some reason ?
void LevelChunk::setBlocks(uint8_t* pData, int y)
{
puts("LevelChunk::setBlocks");
LOG_I("LevelChunk::setBlocks");
for (int i = 0; i < 8192; i++)
{
m_pBlockData[8192 * y + i] = pData[i];
@@ -774,7 +774,7 @@ void LevelChunk::setBlocks(uint8_t* pData, int y)
int LevelChunk::setBlocksAndData(uint8_t* pData, int a3, int a4, int a5, int a6, int a7, int a8, int a9)
{
puts("LevelChunk::setBlocksAndData");
LOG_I("LevelChunk::setBlocksAndData");
if (a3 >= a6)
{

View File

@@ -38,7 +38,7 @@ RandomLevelSource::RandomLevelSource(Level* level, TLong seed, int x) :
field_7E90 = nullptr;
field_7E94 = nullptr;
LogMsg("Generating world with seed: %d", seed);
LOG_I("Generating world with seed: %d", seed);
for (int a = 0; a < 32; a++)
{
@@ -51,7 +51,7 @@ RandomLevelSource::RandomLevelSource(Level* level, TLong seed, int x) :
field_7280 = new float[1024];
Random random = m_random;
printf("random.get : %d\n", random.genrand_int32() >> 1);
LOG_I("random.get : %d", random.genrand_int32() >> 1);
}
// @BUG: Potential collisions.

View File

@@ -21,7 +21,7 @@ PerlinNoise::PerlinNoise(Random* pRandom, int nOctaves)
if (nOctaves == 10)
{
LogMsg("Ok");
LOG_I("PerlinNoise octaves are 10");
}
init(nOctaves);

View File

@@ -75,7 +75,7 @@ void ExternalFileLevelStorage::savePlayerData(LevelData* levelData, std::vector<
FILE* pFile = fopen((m_levelDirPath + "/" + "player.dat").c_str(), "wb");
if (!pFile)
{
LogMsg("Not saving player data");
LOG_W("Not saving player data");
return;
}
@@ -214,7 +214,7 @@ void ExternalFileLevelStorage::save(Level* level, LevelChunk* chunk)
SAFE_DELETE(m_pRegionFile);
m_pRegionFile = nullptr;
LogMsg("Not saving :( (x: %d z: %d)", chunk->m_chunkX, chunk->m_chunkZ);
LOG_W("Not saving :( (x: %d z: %d)", chunk->m_chunkX, chunk->m_chunkZ);
return;
}

View File

@@ -56,7 +56,7 @@ void ExternalFileLevelStorageSource::getLevelList(std::vector<LevelSummary>& vls
if (!de)
break;
LogMsg("Entry: %s", de->d_name);
LOG_I("Entry: %s", de->d_name);
if (de->d_type == DT_DIR)
{

View File

@@ -37,7 +37,7 @@ bool MemoryLevelStorageSource::isNewLevelIdAcceptable(const std::string& x)
void MemoryLevelStorageSource::deleteLevel(const std::string& x)
{
LogMsg("Delete level: %s", x.c_str());
LOG_I("Delete level: %s", x.c_str());
}
void MemoryLevelStorageSource::renameLevel(const std::string& x, const std::string& y)

View File

@@ -83,7 +83,7 @@ void Tile::_init(int ID, Material* pMaterial, int texture)
if (tiles[m_ID])
// @BUG: Printing &tiles[m_ID], but probably supposed to print tiles[m_ID]
printf("Slot %d is already occupied by %p when adding %p\n", m_ID, &tiles[m_ID], this);
LOG_W("Slot %d is already occupied by %p when adding %p", m_ID, &tiles[m_ID], this);
}
Tile::~Tile()

View File

@@ -10,4 +10,4 @@
// USER EDITABLE FILE
#include "common/Utils.hpp"
#include "../../source/common/Utils.hpp"