From 738033a8c306a852bc405db5023cf0e69e0e0c8f Mon Sep 17 00:00:00 2001 From: AdventureT Date: Fri, 29 Dec 2023 13:19:46 +0100 Subject: [PATCH] Some more BINK progress --- OpenJPOG/Source/ABINKMoviePlayer.cpp | 100 +++++++++++++++++++++++++-- OpenJPOG/Source/ABINKMoviePlayer.h | 47 ++++--------- OpenJPOG/Source/AMoviePlayer.h | 1 - 3 files changed, 106 insertions(+), 42 deletions(-) diff --git a/OpenJPOG/Source/ABINKMoviePlayer.cpp b/OpenJPOG/Source/ABINKMoviePlayer.cpp index 28b888b..bdf88ca 100644 --- a/OpenJPOG/Source/ABINKMoviePlayer.cpp +++ b/OpenJPOG/Source/ABINKMoviePlayer.cpp @@ -2,6 +2,8 @@ TOSHI_NAMESPACE_USING +static U32 s_iPlayForegroundFast = 0; + ABINKMoviePlayer::ABINKMoviePlayer() { m_bHasMovieStopped = TTRUE; @@ -14,20 +16,101 @@ ABINKMoviePlayer::ABINKMoviePlayer() SetFrameReady(TFALSE); } -TBOOL ABINKMoviePlayer::RenderToFrameBuffer() +TBOOL ABINKMoviePlayer::InitializeMoviePlayer() { - return TBOOL(); + HRESULT hResult = DirectSoundCreate(NULL, &m_pDirectSound, NULL); + if (FAILED(hResult)) { + m_pDirectSound = NULL; + } + else { + BinkSoundUseDirectSound(m_pDirectSound); + } + return TTRUE; } -TBOOL ABINKMoviePlayer::RenderToFrameBuffer(TPBYTE a_pDest, TINT a_iUnk, TINT a_iDestHeigth, TINT a_iDestPitch, TINT a_iDestX, INT a_iDestY, INT a_iSrcX, INT a_iSrcY) +TBOOL ABINKMoviePlayer::ShutdownMoviePlayer() { - if (a_iDestHeigth == a_iUnk) { - BinkCopyToBufferRect(m_hBink, a_pDest, a_iDestPitch, a_iDestHeigth, - a_iDestX, a_iDestY, a_iSrcX, a_iSrcY, m_hBink->Width, m_hBink->Height, BINKCOPYALL | BINKNOSKIP | BINKSURFACE32A); + if (m_bIsBINKInitialized) { + FreeAudioResource(); + FreeVideoResource(); + m_bIsBINKInitialized = TFALSE; + SetFrameReady(TFALSE); + } + return TFALSE; +} + +TBOOL ABINKMoviePlayer::Update(TFLOAT a_fDeltaTime) +{ + if (!m_bHasMovieStopped && m_hBink) { + BinkService(m_hBink); + if (BinkWait(m_hBink)) { + BinkSleep(500); + return TFALSE; + } + RenderToFrameBuffer(); + } + return TFALSE; +} + +TBOOL ABINKMoviePlayer::RenderToTexture(TTextureResource* a_pTexture) +{ + if (m_hBink) { + m_iWidth = m_hBink->Width; + m_iHeight = m_hBink->Height; + if (a_pTexture && !m_bHasMovieStopped) { + if (s_iPlayForegroundFast) { + BinkDoFrame(m_hBink); + BinkNextFrame(m_hBink); + return FALSE; + } + m_iFrameCount++; + // TODO: Do some Texture stuff + BinkDoFrame(m_hBink); + if (m_iFrameCount == m_hBink->Frames) { + + } + } } return TBOOL(); } +TBOOL ABINKMoviePlayer::RenderToFrameBuffer() +{ + if (!m_bHasMovieStopped && !m_bRenderingTiles) { + RenderToTiles(); + m_bRenderingTiles = TTRUE; + } + return TFALSE; +} + +TBOOL ABINKMoviePlayer::RenderToFrameBuffer(TPBYTE a_pDest, TINT a_iDestWidth, TINT a_iDestHeigth, TINT a_iDestPitch, TINT a_iDestX, INT a_iDestY, INT a_iSrcX, INT a_iSrcY) +{ + BinkCopyToBufferRect(m_hBink, a_pDest, a_iDestPitch, a_iDestHeigth, + a_iDestX, a_iDestY, a_iSrcX, a_iSrcY, m_hBink->Width, m_hBink->Height, BINKCOPYALL | BINKNOSKIP | BINKSURFACE32A); + TPBYTE pBuf = a_pDest + a_iDestX + a_iDestY * a_iDestWidth; + + if (a_iDestHeigth == a_iDestWidth) { + // I think this ignores alpha? + for (TINT i = 0; i < a_iDestHeigth; i++) { + for (TINT j = 0; j < a_iDestWidth; j++) { + *pBuf = *pBuf | 0xFF000000; + } + pBuf += a_iDestPitch * 4; + } + } + else if (a_iDestHeigth != a_iDestWidth && a_iDestHeigth - a_iDestWidth >= 0) { + // I think this ignores alpha? + for (TINT i = 0; i < a_iDestWidth; i++) { + for (TINT j = 0; j < a_iDestWidth; j++) { + *pBuf = *pBuf | 0xFF000000; + } + pBuf += a_iDestPitch * 4; + } + } + + return TFALSE; +} + void ABINKMoviePlayer::BinkSleep(TINT a_iMicroseconds) { static S32 s_iTotalSleep = 0; @@ -58,3 +141,8 @@ void ABINKMoviePlayer::BinkSleep(TINT a_iMicroseconds) s_iTotalSleep %= 1000; } } + +TBOOL ABINKMoviePlayer::RenderToTiles() +{ + return TBOOL(); +} diff --git a/OpenJPOG/Source/ABINKMoviePlayer.h b/OpenJPOG/Source/ABINKMoviePlayer.h index 613becd..1580ad1 100644 --- a/OpenJPOG/Source/ABINKMoviePlayer.h +++ b/OpenJPOG/Source/ABINKMoviePlayer.h @@ -14,45 +14,16 @@ class ABINKMoviePlayer : public AMoviePlayer public: ABINKMoviePlayer(); - virtual TBOOL InitializeMoviePlayer() - { - HRESULT hResult = DirectSoundCreate(NULL, &m_pDirectSound, NULL); - if (FAILED(hResult)) { - m_pDirectSound = NULL; - } - else { - BinkSoundUseDirectSound(m_pDirectSound); - } - return TTRUE; - } + virtual TBOOL InitializeMoviePlayer(); - virtual TBOOL ShutdownMoviePlayer() - { - if (m_bIsBINKInitialized) { - FreeAudioResource(); - FreeVideoResource(); - m_bIsBINKInitialized = TFALSE; - SetFrameReady(TFALSE); - } - return TFALSE; - } + virtual TBOOL ShutdownMoviePlayer(); - virtual TBOOL Update(TFLOAT a_fDeltaTime) - { - - if (m_bIsBINKInitialized && m_hBink) { - BinkService(m_hBink); - if (BinkWait(m_hBink) != 0) { - BinkSleep(500); - return TFALSE; - } - RenderToFrameBuffer(); - } - return TFALSE; - } + virtual TBOOL Update(TFLOAT a_fDeltaTime); + + virtual TBOOL RenderToTexture(TTextureResource *a_pTexture); virtual TBOOL RenderToFrameBuffer(); - virtual TBOOL RenderToFrameBuffer(TPBYTE a_pDest, TINT a_iUnk, TINT a_iDestHeigth, TINT a_iDestPitch, TINT a_iDestX, INT a_iDestY, INT a_iSrcX, INT a_iSrcY); + virtual TBOOL RenderToFrameBuffer(TPBYTE a_pDest, TINT a_iSourceHeigth, TINT a_iDestHeigth, TINT a_iDestPitch, TINT a_iDestX, INT a_iDestY, INT a_iSrcX, INT a_iSrcY); virtual TBOOL FreeVideoResource() { @@ -66,6 +37,7 @@ class ABINKMoviePlayer : public AMoviePlayer } void BinkSleep(TINT a_iMicroseconds); + TBOOL RenderToTiles(); private: @@ -82,9 +54,14 @@ class ABINKMoviePlayer : public AMoviePlayer private: TBOOL m_bHasMovieStopped; // 0x210 TBOOL m_bIsBINKInitialized; // 0x211 + TBOOL m_bDrawingFrame; // 0x213 + TBOOL m_bRenderingTiles; // 0x214 HBINK m_hBink; // 0x218 + TINT m_iFrameCount; // 0x220 TINT m_iFrameBufferWidth; // 0x224 TINT m_iFrameBufferHeight; // 0x228 + TINT m_iWidth; // 0x22C + TINT m_iHeight; // 0x230 TPBYTE m_pFrameBufferBits; // 0x234 LPDIRECTSOUND m_pDirectSound; // 0x278 }; diff --git a/OpenJPOG/Source/AMoviePlayer.h b/OpenJPOG/Source/AMoviePlayer.h index d49a0a2..b87aaca 100644 --- a/OpenJPOG/Source/AMoviePlayer.h +++ b/OpenJPOG/Source/AMoviePlayer.h @@ -103,7 +103,6 @@ class AMoviePlayer return TFALSE; } - // Probably a spelling mistake from the devs (Bit) virtual TBOOL Render_BackBufferBlit() { return TFALSE;