* Add F3 debug text.

This commit is contained in:
iProgramInCpp 2023-08-11 20:04:07 +03:00
parent b1786eba1f
commit 35a63582df
9 changed files with 70 additions and 2 deletions

View file

@ -58,6 +58,9 @@ enum
AKEYCODE_APOSTROPHE = VK_OEM_7, // ''"'
AKEYCODE_SPACE = VK_SPACE,
AKEYCODE_F3 = VK_F3,
AKEYCODE_F4 = VK_F4,
AKEYCODE_0 = '0',
AKEYCODE_1 = '1',
//...
@ -72,7 +75,6 @@ enum
AKEYCODE_T = 'T',
AKEYCODE_Z = 'Z',
AKEYCODE_F4 = VK_F4,
};
// this sucks
@ -128,6 +130,7 @@ enum
AKEYCODE_Q,
AKEYCODE_T,
AKEYCODE_Z,
AKEYCODE_F3,
AKEYCODE_F4,
AKEYCODE_ARROW_LEFT,
AKEYCODE_ARROW_RIGHT,
@ -137,6 +140,8 @@ enum
static inline int translate_sdl_key_to_mcpe(int key) {
switch (key) {
case SDLK_ESCAPE: return AKEYCODE_MENU;
case SDLK_F3: return AKEYCODE_F3;
case SDLK_F4: return AKEYCODE_F4;
case SDLK_F5: return AKEYCODE_SEARCH;
case SDLK_y: return AKEYCODE_BACK;
case SDLK_u: return AKEYCODE_BUTTON_X;
@ -176,7 +181,6 @@ static inline int translate_sdl_key_to_mcpe(int key) {
case SDLK_q: return AKEYCODE_Q;
case SDLK_t: return AKEYCODE_T;
case SDLK_z: return AKEYCODE_Z;
case SDLK_F4: return AKEYCODE_F4;
case SDLK_LEFT: return AKEYCODE_ARROW_LEFT;
case SDLK_RIGHT: return AKEYCODE_ARROW_RIGHT;
case SDLK_RETURN: return AKEYCODE_ENTER;

View file

@ -466,6 +466,10 @@ void Minecraft::tickInput()
m_pLocalPlayer->drop(&inst);
}
}
else if (keyCode == AKEYCODE_F3)
{
m_options.m_bDebugText = !m_options.m_bDebugText;
}
#ifdef ENH_ALLOW_AO
else if (keyCode == AKEYCODE_F4)
{
@ -555,6 +559,11 @@ void Minecraft::sendMessage(const std::string& message)
}
}
std::string Minecraft::getVersionString()
{
return "v0.1.0 alpha";
}
void Minecraft::_levelGenerated()
{
if (m_pNetEventCallback)
@ -987,6 +996,11 @@ ItemInstance* Minecraft::getSelectedItem()
return &m_CurrItemInstance;
}
int Minecraft::getFpsIntlCounter()
{
return 0;
}
void Minecraft::leaveGame(bool bCopyMap)
{
m_bPreparingLevel = false;

View file

@ -56,6 +56,7 @@ public:
void tickMouse();
void handleCharInput(char chr);
void sendMessage(const std::string& message);
std::string getVersionString();
virtual void onGraphicsReset();
virtual void update() override;
@ -75,6 +76,8 @@ public:
ItemInstance* getSelectedItem();
virtual int getFpsIntlCounter();
public:
static int width, height;
static bool useAmbientOcclusion;

View file

@ -55,6 +55,13 @@ void NinecraftApp::initGLStates()
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
}
int NinecraftApp::getFpsIntlCounter()
{
int ofps = m_fps;
m_fps = 0;
return ofps;
}
void NinecraftApp::init()
{
Mth::initMth();
@ -110,6 +117,7 @@ void NinecraftApp::update()
void NinecraftApp::updateStats()
{
/*
int timeMs = getTimeMs();
if (timeMs > field_2B0 + 999)
{
@ -128,6 +136,7 @@ void NinecraftApp::updateStats()
field_2B0 = timeMs;
m_fps = 0;
}
*/
}
NinecraftApp::NinecraftApp()

View file

@ -28,6 +28,8 @@ public:
void updateStats();
void initGLStates();
int getFpsIntlCounter() override;
private:
int field_DBC;
bool field_DC0;

View file

@ -52,6 +52,8 @@ void Options::initDefaultValues()
field_1C = "Default";
m_playerName = "Steve";
m_bServerVisibleDefault = true;
m_bDebugText = false;
m_keyBinds[0] = { "key.forward", 'W' };
m_keyBinds[1] = { "key.left", 'A' };
m_keyBinds[2] = { "key.back", 'S' };

View file

@ -110,5 +110,6 @@ public:
std::string m_playerName;
bool m_bServerVisibleDefault;
bool m_bAutoJump;
bool m_bDebugText;
};

View file

@ -49,6 +49,9 @@ void GameRenderer::_init()
field_7C = 0.0f;
field_80 = 0.0f;
field_84 = 0.0f;
m_lastUpdatedMS = 0;
m_shownFPS = 0;
m_shownChunkUpdates = 0;
}
GameRenderer::GameRenderer(Minecraft* pMinecraft) :
@ -622,6 +625,34 @@ void GameRenderer::render(float f)
#endif
}
}
std::stringstream debugText;
debugText << "ReMinecraftPE " << m_pMinecraft->getVersionString();
debugText << "\n" << m_shownFPS << " fps, " << m_shownChunkUpdates << " chunk updates";
if (m_pMinecraft->m_options.m_bDebugText)
{
if (m_pMinecraft->m_pLocalPlayer)
{
char posStr[64];
Vec3 pos = m_pMinecraft->m_pLocalPlayer->getPos(f);
snprintf(posStr, sizeof posStr, "%.2f, %.2f, %.2f", pos.x, pos.y, pos.z);
debugText << "\npos: " << posStr;
debugText << "\n" << m_pMinecraft->m_pLevelRenderer->gatherStats1();
}
m_pMinecraft->m_pFont->drawShadow(debugText.str(), 2, 2, 0xFFFFFF);
}
int timeMs = getTimeMs();
if (timeMs - m_lastUpdatedMS >= 1000)
{
m_lastUpdatedMS = timeMs;
m_shownFPS = m_pMinecraft->getFpsIntlCounter();
m_shownChunkUpdates = Chunk::updates;
Chunk::updates = 0;
}
}
void GameRenderer::tick()

View file

@ -84,5 +84,7 @@ public:
float m_matrix_projection[16];
float m_matrix_model_view[16];
int m_shownFPS, m_shownChunkUpdates, m_lastUpdatedMS;
};