Skip to content

Commit

Permalink
More progress on MoviePlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed Dec 29, 2023
1 parent e27e2a6 commit ee5dd04
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 7 deletions.
59 changes: 59 additions & 0 deletions OpenJPOG/Source/ABINKMoviePlayer.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
#include "ABINKMoviePlayer.h"

TOSHI_NAMESPACE_USING

ABINKMoviePlayer::ABINKMoviePlayer()
{
m_bHasMovieStopped = TTRUE;
m_bIsBINKInitialized = TFALSE;
m_hBink = NULL;
m_iFrameBufferHeight = 0;
m_iFrameBufferWidth = 0;
m_pFrameBufferBits = TNULL;
RADSetMemory(RADMEMALLOC, RADMEMFREE);
SetFrameReady(TFALSE);
}

TBOOL ABINKMoviePlayer::RenderToFrameBuffer()
{
return TBOOL();
}

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)
{
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);
}
return TBOOL();
}

void ABINKMoviePlayer::BinkSleep(TINT a_iMicroseconds)
{
static S32 s_iTotalSleep = 0;
static S32 s_iSleepForward = 0;
static U64 s_iFrequency = 1000;
static S32 s_bFrequencyAquired = 0;

if (!s_bFrequencyAquired)
{
s_bFrequencyAquired = 1;
QueryPerformanceFrequency((LARGE_INTEGER*)&s_iFrequency);
}

s_iTotalSleep += a_iMicroseconds;

if ((s_iTotalSleep - s_iSleepForward) > 1000)
{
U64 start, end;
s_iTotalSleep -= s_iSleepForward;

QueryPerformanceCounter((LARGE_INTEGER*)&start);
Sleep(s_iTotalSleep / 1000);
QueryPerformanceCounter((LARGE_INTEGER*)&end);

end = ((end - start) * (U64)1000000) / s_iFrequency;

s_iSleepForward = (U32)end - s_iTotalSleep;
s_iTotalSleep %= 1000;
}
}
63 changes: 60 additions & 3 deletions OpenJPOG/Source/ABINKMoviePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
#include "AMoviePlayer.h"
#include <dsound.h>
#include "BINK.H"
#include "RAD.H"
#include <windows.h>
#include "TKernel/TMemory.h"

TOSHI_NAMESPACE_BEGIN

class ABINKMoviePlayer : public AMoviePlayer
{
public:
ABINKMoviePlayer();

virtual TBOOL InitializeMoviePlayer()
{
HRESULT hResult = DirectSoundCreate(NULL, &m_pDirectSound, NULL);
Expand All @@ -22,14 +28,65 @@ class ABINKMoviePlayer : public AMoviePlayer

virtual TBOOL ShutdownMoviePlayer()
{
if (m_bIsInitialized) {
m_bIsInitialized = TFALSE;
if (m_bIsBINKInitialized) {
FreeAudioResource();
FreeVideoResource();
m_bIsBINKInitialized = TFALSE;
SetFrameReady(TFALSE);
}
return TFALSE;
}

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 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 FreeVideoResource()
{
return TTRUE;
}

virtual TBOOL FreeAudioResource()
{
delete m_pDirectSound;
return TTRUE;
}

void BinkSleep(TINT a_iMicroseconds);

private:

static void PTR4* RADLINK RADMEMALLOC(U32 bytes)
{
return tmalloc(bytes, TNULL, -1);
}

static void RADLINK RADMEMFREE(void PTR4* ptr)
{
tfree(ptr);
}

private:
LPDIRECTSOUND m_pDirectSound;
TBOOL m_bHasMovieStopped; // 0x210
TBOOL m_bIsBINKInitialized; // 0x211
HBINK m_hBink; // 0x218
TINT m_iFrameBufferWidth; // 0x224
TINT m_iFrameBufferHeight; // 0x228
TPBYTE m_pFrameBufferBits; // 0x234
LPDIRECTSOUND m_pDirectSound; // 0x278
};

TOSHI_NAMESPACE_END
2 changes: 1 addition & 1 deletion OpenJPOG/Source/AMoviePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class AMoviePlayer
m_bIsFullscreen = a_bFullscreen;
}

virtual TBOOL SetFrameReady(TBOOL a_bFreameReady)
virtual void SetFrameReady(TBOOL a_bFreameReady)
{
m_bIsFrameReady = a_bFreameReady;
}
Expand Down
11 changes: 11 additions & 0 deletions OpenJPOG/Source/ARootTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ TOSHI_NAMESPACE_USING

IMPLEMENT_DYNCREATE(ARootTask, TTask);

ARootTask::ARootTask()
{
m_pMoviePlayer = TNULL;
}

TBOOL ARootTask::OnCreate()
{
m_pMoviePlayer = new ABINKMoviePlayer();
return TTask::OnCreate();
}

void ARootTask::AllocateInputSystem()
{
TScheduler* pScheduler = g_oTheApp.GetKernel()->GetScheduler();
Expand Down
7 changes: 6 additions & 1 deletion OpenJPOG/Source/ARootTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
#include "TKernel/TTask.h"
#include "TKernel/TCString.h"
#include "AVibrationManager.h"
#include "ABINKMoviePlayer.h"

class ARootTask : public Toshi::TTask
{
DECLARE_DYNAMIC(ARootTask);
public:
ARootTask() = default;
ARootTask();
virtual ~ARootTask() = default;

virtual TBOOL OnCreate() override;
virtual TBOOL OnUpdate(TFLOAT a_fDeltaTime) override { return TTRUE; }

void SetName(TPCHAR a_szName)
{
m_szName = a_szName;
Expand All @@ -23,4 +27,5 @@ class ARootTask : public Toshi::TTask
Toshi::TCString m_szName;
TTask* m_pInputTask; // 0x38
AVibrationManager* m_pVibrationTask; // 0xE8
Toshi::ABINKMoviePlayer* m_pMoviePlayer; // 0xF0
};
21 changes: 21 additions & 0 deletions OpenJPOG/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,30 @@ TBOOL AApplication::OnCreate(TINT argc, TPCHAR* const argv)
m_pInputTask->Activate(TTRUE);
m_pInputTask->SetName((TPCHAR)"InputTask");

m_pUpdate2Task = (ADummyTask*)g_oTheApp.GetKernel()->GetScheduler()->CreateTask(TGetClass(ADummyTask), TNULL);
m_pUpdate2Task->Create();
m_pUpdate2Task->Activate(TTRUE);
m_pUpdate2Task->SetName((TPCHAR)"Update2");

m_pRootTask = (ARootTask*)g_oTheApp.GetKernel()->GetScheduler()->CreateTask(TGetClass(ARootTask), m_pUpdate2Task);
if (m_pRootTask) {
if (!m_pRootTask->Create()) {
return TFALSE;
}
m_pRootTask->Activate(TTRUE);
}

return TApplication::OnCreate(argc, argv);
}

TBOOL AApplication::OnDestroy()
{
m_pRootTask->DestroyTask();
m_pInputTask->DestroyTask();
m_pRenderTask->DestroyTask();
return TTRUE;
}

int main(int argc, char** argv)
{
if (g_oTheApp.Create("Jurassic Park: Operation Genesis - (c) Blue Tongue Software", argc, argv)) {
Expand Down
16 changes: 14 additions & 2 deletions OpenJPOG/Source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "TApplication/TApplication.h"
#include "TKernel/TMemory.h"
#include "ADummyTask.h"
#include "ARootTask.h"

class AApplication : public Toshi::TApplication
{
Expand All @@ -13,12 +14,23 @@ class AApplication : public Toshi::TApplication
}

virtual TBOOL OnCreate(TINT argc, TPCHAR* const argv) override;
virtual TBOOL OnDestroy() override;
public:
ARootTask* GetRootTask() const { return m_pRootTask; }
ADummyTask* GetInputRootTask() const { return m_pInputTask; }
ADummyTask* GetUpdate1RootTask() const { return m_pUpdate1Task; }
ADummyTask* GetUpdate2RootTask() const { return m_pUpdate2Task; }
ADummyTask* GetUpdate3RootTask() const { return m_pUpdate3Task; }
ADummyTask* GetRenderRootTask() const { return m_pRenderTask; }

private:
// TApplication 0x0 -> 0x1C
ADummyTask* m_pInputTask; // 0x1C
// 0x0 -> 0x1C TApplication
ARootTask* m_pRootTask; // 0x1C
ADummyTask* m_pInputTask; // 0x20
ADummyTask* m_pUpdate1Task; // 0x24
ADummyTask* m_pUpdate2Task; // 0x28
ADummyTask* m_pUpdate3Task; // 0x2C
ADummyTask* m_pRenderTask; // 0x24
};

extern AApplication g_oTheApp;
1 change: 1 addition & 0 deletions OpenJPOG/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project ("OpenJPOG")
"TKernelInterface",
"TApplication",
"TRenderInterface",
"dsound.lib",
"fmodvc.lib",
"binkw32.lib"
}
Expand Down
6 changes: 6 additions & 0 deletions Toshi/Include/TKernel/TTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

TOSHI_NAMESPACE_BEGIN

class TScheduler;

class TOSHI_EXPORT TTask : public TObject, public TNodeTree<TTask>::TNode
{
DECLARE_DYNAMIC(TTask);
Expand Down Expand Up @@ -36,13 +38,17 @@ class TOSHI_EXPORT TTask : public TObject, public TNodeTree<TTask>::TNode
virtual void OnDeactivate() {}

void Activate(TBOOL a_bActivate);
void DestroyTask();

TBOOL IsCreated() const { return HASFLAG(m_iState & State_Created); }
TBOOL IsActive() const { return HASFLAG(m_iState & State_Active); }
TBOOL IsDying() const { return HASFLAG(m_iState & State_Dying); }

TScheduler* GetScheduler();

private:
TINT m_iState;
TScheduler* m_pScheduler; // 0x20
};

TOSHI_NAMESPACE_END
11 changes: 11 additions & 0 deletions Toshi/Source/TKernel/TTask.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "TTask.h"
#include "TScheduler.h"

TOSHI_NAMESPACE_USING

Expand Down Expand Up @@ -50,3 +51,13 @@ void TTask::Activate(TBOOL a_bActivate)
}
}
}

void TTask::DestroyTask()
{
m_pScheduler->DestroyTask(*this);
}

TScheduler* TTask::GetScheduler()
{
return m_pScheduler;
}

0 comments on commit ee5dd04

Please sign in to comment.