From e70e120c0f1d859d6768f3d1692755bf680ddeed Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 20 Dec 2024 01:54:59 +0100 Subject: [PATCH] Implement LegoVideoManager::DrawFPS --- .../legoomni/src/video/legovideomanager.cpp | 103 +++++++++++++++++- LEGO1/omni/include/mxdisplaysurface.h | 2 + LEGO1/omni/src/video/mxdisplaysurface.cpp | 6 + 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp index 70fae9aa..e4c2a662 100644 --- a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp +++ b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp @@ -19,6 +19,8 @@ #include "tgl/d3drm/impl.h" #include "viewmanager/viewroi.h" +#include + DECOMP_SIZE_ASSERT(LegoVideoManager, 0x590) DECOMP_SIZE_ASSERT(MxStopWatch, 0x18) DECOMP_SIZE_ASSERT(MxFrequencyMeter, 0x20) @@ -390,10 +392,107 @@ inline void LegoVideoManager::DrawCursor() ->BltFast(m_cursorXCopy, m_cursorYCopy, m_cursorSurface, &m_cursorRect, DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY); } -// STUB: LEGO1 0x1007bbc0 +// FUNCTION: LEGO1 0x1007bbc0 void LegoVideoManager::DrawFPS() { - // TODO + char zeros[8] = "0000.00"; + if (m_unk0x528 == NULL) { + m_arialFont = CreateFontA( + 12, + 0, + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + ANSI_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | VARIABLE_PITCH, + "Arial" + ); + HDC dc = GetDC(NULL); + SelectObject(dc, m_arialFont); + GetTextExtentPointA(dc, zeros, strlen(zeros), &m_fpsSize); + ReleaseDC(NULL, dc); + m_unk0x528 = m_displaySurface->FUN_100bc8b0(); + SetRect(&this->m_fpsRect, 0, 0, m_fpsSize.cx, m_fpsSize.cy); + if (m_unk0x528 == NULL) { + DeleteObject(m_arialFont); + m_arialFont = NULL; + return; + } + DDCOLORKEY color_key; + color_key.dwColorSpaceHighValue = 0; + color_key.dwColorSpaceLowValue = 0; + m_unk0x528->SetColorKey(DDCKEY_SRCBLT, &color_key); + DDSURFACEDESC surfaceDesc = {0}; + surfaceDesc.dwSize = sizeof(surfaceDesc); + if (m_unk0x528->Lock(NULL, &surfaceDesc, DDLOCK_WAIT, NULL) != DD_OK) { + m_unk0x528->Release(); + DeleteObject(m_arialFont); + m_unk0x528 = NULL; + m_arialFont = NULL; + } + else { + DWORD i; + char* ptr = (char*) surfaceDesc.lpSurface; + for (i = 0; i < surfaceDesc.dwHeight; i++) { + memset(ptr, 0, surfaceDesc.dwWidth * surfaceDesc.ddpfPixelFormat.dwRGBBitCount / 8); + ptr += surfaceDesc.lPitch; + } + m_unk0x528->Unlock(surfaceDesc.lpSurface); + m_unk0x54c = Timer()->GetTime(); + m_unk0x550 = 1.f; + } + } + else { + MxTimer* timer = Timer(); + if (timer->GetTime() <= m_unk0x54c + 5000.f) { + m_unk0x550 += 1.f; + } + else { + char buffer[32]; + int nb = sprintf(buffer, "%.02f", m_unk0x550 / (Timer()->GetTime() - m_unk0x54c) / 1000.f); + m_unk0x54c = Timer()->GetTime(); + DDSURFACEDESC surfaceDesc = {0}; + surfaceDesc.dwSize = sizeof(surfaceDesc); + if (m_unk0x528->Lock(NULL, &surfaceDesc, DDLOCK_WAIT, NULL) == DD_OK) { + DWORD i; + char* ptr = (char*) surfaceDesc.lpSurface; + for (i = 0; i < surfaceDesc.dwHeight; i++) { + memset(ptr, 0, surfaceDesc.dwWidth * surfaceDesc.ddpfPixelFormat.dwRGBBitCount / 8); + ptr += surfaceDesc.lPitch; + } + m_unk0x528->Unlock(surfaceDesc.lpSurface); + } + HDC dc; + if (m_unk0x528->GetDC(&dc) != DD_OK) { + m_unk0x528->Release(); + m_unk0x528 = NULL; + DeleteObject(m_arialFont); + m_arialFont = NULL; + return; + } + SelectObject(dc, m_arialFont); + SetTextColor(dc, RGB(0xff, 0xff, 0x00)); + SetBkColor(dc, RGB(0x00, 0x00, 0x00)); + SetBkMode(dc, OPAQUE); + GetTextExtentPoint32A(dc, buffer, nb, &m_fpsSize); + RECT rect; + SetRect(&rect, 0, 0, m_fpsSize.cx, m_fpsSize.cy); + ExtTextOutA(dc, 0, 0, ETO_OPAQUE, &rect, buffer, nb, NULL); + m_unk0x528->ReleaseDC(dc); + m_unk0x550 = 1.f; + } + if (m_unk0x528 != NULL) { + m_displaySurface->GetDirectDrawSurface2() + ->BltFast(20, 20, m_unk0x528, &m_fpsRect, DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY); + m_3dManager->GetLego3DView()->GetView()->ForceUpdate(20, 20, m_fpsRect.right, m_fpsRect.bottom); + } + } } // FUNCTION: LEGO1 0x1007c080 diff --git a/LEGO1/omni/include/mxdisplaysurface.h b/LEGO1/omni/include/mxdisplaysurface.h index 3c2c83a7..ba458d28 100644 --- a/LEGO1/omni/include/mxdisplaysurface.h +++ b/LEGO1/omni/include/mxdisplaysurface.h @@ -109,6 +109,8 @@ class MxDisplaySurface : public MxCore { MxU8 p_bpp ); + IDirectDrawSurface* FUN_100bc8b0(void); + private: MxU8 CountTotalBitsSetTo1(MxU32 p_param); MxU8 CountContiguousBitsSetTo1(MxU32 p_param); diff --git a/LEGO1/omni/src/video/mxdisplaysurface.cpp b/LEGO1/omni/src/video/mxdisplaysurface.cpp index 3a301af1..4ff4f382 100644 --- a/LEGO1/omni/src/video/mxdisplaysurface.cpp +++ b/LEGO1/omni/src/video/mxdisplaysurface.cpp @@ -1092,3 +1092,9 @@ MxBool MxDisplaySurface::VTable0x2c( { return 0; } + +// STUB: LEGO1 0x100bc8b0 +IDirectDrawSurface* MxDisplaySurface::FUN_100bc8b0(void) +{ + return NULL; +}