2023-06-24 13:09:46 -04:00
|
|
|
#include "mxvideomanager.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
|
|
|
|
#include "legoomni.h"
|
2023-09-19 23:00:34 -04:00
|
|
|
#include "mxautolocker.h"
|
|
|
|
#include "mxpresenter.h"
|
2023-10-14 14:46:00 -04:00
|
|
|
#include "mxticklemanager.h"
|
2023-09-19 23:00:34 -04:00
|
|
|
|
2023-10-17 09:16:37 -04:00
|
|
|
DECOMP_SIZE_ASSERT(MxVideoManager, 0x64)
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be1f0
|
2023-09-19 23:00:34 -04:00
|
|
|
MxVideoManager::MxVideoManager()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
Init();
|
2023-09-19 23:00:34 -04:00
|
|
|
}
|
2023-06-24 13:09:46 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be270
|
2023-12-13 05:48:14 -05:00
|
|
|
void MxVideoManager::VTable0x34(MxU32 p_x, MxU32 p_y, MxU32 p_width, MxU32 p_height)
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be2a0
|
2023-10-17 09:16:37 -04:00
|
|
|
MxVideoManager::~MxVideoManager()
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
Destroy(TRUE);
|
2023-06-24 13:09:46 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be320
|
2023-09-19 23:00:34 -04:00
|
|
|
MxResult MxVideoManager::Init()
|
2023-06-24 13:09:46 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_pDirectDraw = NULL;
|
|
|
|
this->m_pDDSurface = NULL;
|
|
|
|
this->m_displaySurface = NULL;
|
|
|
|
this->m_region = NULL;
|
|
|
|
this->m_videoParam.SetPalette(NULL);
|
2023-12-13 05:48:14 -05:00
|
|
|
this->m_unk0x60 = FALSE;
|
2023-10-24 19:38:27 -04:00
|
|
|
return SUCCESS;
|
2023-09-19 23:00:34 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be340
|
2023-10-14 14:46:00 -04:00
|
|
|
void MxVideoManager::Destroy(MxBool p_fromDestructor)
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_thread) {
|
|
|
|
m_thread->Terminate();
|
|
|
|
delete m_thread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TickleManager()->UnregisterClient(this);
|
2023-10-14 14:46:00 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_criticalSection.Enter();
|
2023-10-14 14:46:00 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_displaySurface)
|
|
|
|
delete m_displaySurface;
|
2023-10-14 14:46:00 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_region)
|
|
|
|
delete m_region;
|
2023-10-14 14:46:00 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_videoParam.GetPalette())
|
|
|
|
delete m_videoParam.GetPalette();
|
2023-10-14 14:46:00 -04:00
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0x60) {
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_pDirectDraw)
|
|
|
|
m_pDirectDraw->Release();
|
|
|
|
if (m_pDDSurface)
|
|
|
|
m_pDDSurface->Release();
|
|
|
|
}
|
2023-10-14 14:46:00 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
Init();
|
|
|
|
m_criticalSection.Leave();
|
2023-10-14 14:46:00 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!p_fromDestructor)
|
|
|
|
MxMediaManager::Destroy();
|
2023-10-14 14:46:00 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be3e0
|
2023-09-19 23:00:34 -04:00
|
|
|
void MxVideoManager::UpdateRegion()
|
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_region->VTable0x20() == FALSE) {
|
2023-11-06 18:12:09 -05:00
|
|
|
MxRect32 rect(m_region->GetRect(), m_videoParam.GetRect());
|
|
|
|
m_displaySurface
|
|
|
|
->Display(rect.GetLeft(), rect.GetTop(), rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
|
2023-10-24 19:38:27 -04:00
|
|
|
}
|
2023-06-24 13:09:46 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be440
|
2023-10-17 09:16:37 -04:00
|
|
|
void MxVideoManager::SortPresenterList()
|
2023-06-30 14:34:39 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (this->m_presenters->GetCount() <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MxPresenterListCursor a(this->m_presenters);
|
|
|
|
MxPresenterListCursor b(this->m_presenters);
|
|
|
|
MxU32 count = this->m_presenters->GetCount() - 1;
|
|
|
|
MxBool finished;
|
|
|
|
|
|
|
|
if (count != 0) {
|
|
|
|
do {
|
|
|
|
a.Reset();
|
|
|
|
b.Head();
|
|
|
|
|
|
|
|
finished = TRUE;
|
|
|
|
for (MxU32 i = count; i != 0; i--) {
|
2023-12-13 05:48:14 -05:00
|
|
|
MxPresenter *presenterA, *presenterB;
|
2023-10-24 19:38:27 -04:00
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
a.Next(presenterA);
|
|
|
|
b.Next(presenterB);
|
2023-10-24 19:38:27 -04:00
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
if (presenterA->GetDisplayZ() < presenterB->GetDisplayZ()) {
|
|
|
|
a.SetValue(presenterB);
|
|
|
|
b.SetValue(presenterA);
|
2023-10-24 19:38:27 -04:00
|
|
|
finished = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!finished && --count != 0);
|
|
|
|
}
|
2023-06-27 22:04:07 -04:00
|
|
|
}
|
2023-10-07 14:05:45 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be600
|
2023-12-13 05:48:14 -05:00
|
|
|
MxResult MxVideoManager::VTable0x28(
|
2023-10-24 19:38:27 -04:00
|
|
|
MxVideoParam& p_videoParam,
|
|
|
|
LPDIRECTDRAW p_pDirectDraw,
|
|
|
|
LPDIRECTDRAWSURFACE p_pDDSurface,
|
|
|
|
LPDIRECTDRAWSURFACE p_ddSurface1,
|
|
|
|
LPDIRECTDRAWSURFACE p_ddSurface2,
|
|
|
|
LPDIRECTDRAWCLIPPER p_ddClipper,
|
|
|
|
MxU32 p_frequencyMS,
|
|
|
|
MxBool p_createThread
|
|
|
|
)
|
2023-10-07 14:05:45 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxBool locked = FALSE;
|
|
|
|
MxResult status = FAILURE;
|
2023-10-07 14:05:45 -04:00
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x60 = FALSE;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (MxMediaManager::InitPresenters() != SUCCESS)
|
|
|
|
goto done;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_criticalSection.Enter();
|
|
|
|
locked = TRUE;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_videoParam = p_videoParam;
|
|
|
|
m_region = new MxRegion();
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!m_region)
|
|
|
|
goto done;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_pDirectDraw = p_pDirectDraw;
|
|
|
|
m_pDDSurface = p_pDDSurface;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
MxPalette* palette;
|
|
|
|
if (p_videoParam.GetPalette() == NULL) {
|
|
|
|
palette = new MxPalette();
|
|
|
|
m_videoParam.SetPalette(palette);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!palette)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
palette = p_videoParam.GetPalette()->Clone();
|
|
|
|
m_videoParam.SetPalette(palette);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!palette)
|
|
|
|
goto done;
|
|
|
|
}
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_displaySurface = new MxDisplaySurface();
|
|
|
|
if (m_displaySurface && m_displaySurface->Init(m_videoParam, p_ddSurface1, p_ddSurface2, p_ddClipper) == SUCCESS) {
|
|
|
|
m_displaySurface->SetPalette(m_videoParam.GetPalette());
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (p_createThread) {
|
|
|
|
m_thread = new MxTickleThread(this, p_frequencyMS);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!m_thread || m_thread->Start(0, 0) != SUCCESS)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TickleManager()->RegisterClient(this, p_frequencyMS);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
status = SUCCESS;
|
|
|
|
}
|
2023-10-14 15:33:11 -04:00
|
|
|
|
|
|
|
done:
|
2023-10-24 19:38:27 -04:00
|
|
|
if (status != SUCCESS)
|
|
|
|
Destroy();
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (locked)
|
|
|
|
m_criticalSection.Leave();
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return status;
|
2023-10-07 14:05:45 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be820
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult MxVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyMS, MxBool p_createThread)
|
2023-10-07 14:05:45 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxBool locked = FALSE;
|
|
|
|
MxResult status = FAILURE;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x60 = TRUE;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (MxMediaManager::InitPresenters() != SUCCESS)
|
|
|
|
goto done;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_criticalSection.Enter();
|
|
|
|
locked = TRUE;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_videoParam = p_videoParam;
|
|
|
|
m_region = new MxRegion();
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!m_region)
|
|
|
|
goto done;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (DirectDrawCreate(NULL, &m_pDirectDraw, NULL) != DD_OK)
|
|
|
|
goto done;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_pDirectDraw->SetCooperativeLevel(MxOmni::GetInstance()->GetWindowHandle(), DDSCL_NORMAL) != DD_OK)
|
|
|
|
goto done;
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
MxPalette* palette;
|
|
|
|
if (p_videoParam.GetPalette() == NULL) {
|
|
|
|
palette = new MxPalette();
|
|
|
|
m_videoParam.SetPalette(palette);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!palette)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
palette = p_videoParam.GetPalette()->Clone();
|
|
|
|
m_videoParam.SetPalette(palette);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!palette)
|
|
|
|
goto done;
|
|
|
|
}
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_displaySurface = new MxDisplaySurface();
|
|
|
|
if (m_displaySurface && m_displaySurface->Create(m_videoParam) == SUCCESS) {
|
|
|
|
m_displaySurface->SetPalette(m_videoParam.GetPalette());
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (p_createThread) {
|
|
|
|
m_thread = new MxTickleThread(this, p_frequencyMS);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!m_thread || m_thread->Start(0, 0) != SUCCESS)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TickleManager()->RegisterClient(this, p_frequencyMS);
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
status = SUCCESS;
|
|
|
|
}
|
2023-10-14 15:33:11 -04:00
|
|
|
|
|
|
|
done:
|
2023-10-24 19:38:27 -04:00
|
|
|
if (status != SUCCESS)
|
|
|
|
Destroy();
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (locked)
|
|
|
|
m_criticalSection.Leave();
|
2023-10-14 15:33:11 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return status;
|
2023-10-07 14:05:45 -04:00
|
|
|
}
|
2023-10-16 16:09:08 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bea50
|
2023-10-17 09:16:37 -04:00
|
|
|
void MxVideoManager::Destroy()
|
2023-10-16 16:09:08 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
Destroy(FALSE);
|
2023-10-17 09:16:37 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bea60
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxVideoManager::InvalidateRect(MxRect32& p_rect)
|
2023-10-17 09:16:37 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_criticalSection.Enter();
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_region)
|
2023-12-13 05:48:14 -05:00
|
|
|
m_region->VTable0x18(p_rect);
|
2023-10-16 16:09:08 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
m_criticalSection.Leave();
|
2023-10-17 09:16:37 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bea90
|
2023-10-17 09:16:37 -04:00
|
|
|
MxResult MxVideoManager::Tickle()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxAutoLocker lock(&this->m_criticalSection);
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
SortPresenterList();
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
MxPresenter* presenter;
|
|
|
|
MxPresenterListCursor cursor(this->m_presenters);
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
while (cursor.Next(presenter))
|
|
|
|
presenter->Tickle();
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
cursor.Reset();
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
while (cursor.Next(presenter))
|
|
|
|
presenter->PutData();
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
UpdateRegion();
|
|
|
|
m_region->Reset();
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return SUCCESS;
|
2023-10-17 09:16:37 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bebe0
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult MxVideoManager::RealizePalette(MxPalette* p_palette)
|
2023-10-17 09:16:37 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
PALETTEENTRY paletteEntries[256];
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_criticalSection.Enter();
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (p_palette && this->m_videoParam.GetPalette()) {
|
|
|
|
p_palette->GetEntries(paletteEntries);
|
|
|
|
this->m_videoParam.GetPalette()->SetEntries(paletteEntries);
|
|
|
|
this->m_displaySurface->SetPalette(this->m_videoParam.GetPalette());
|
|
|
|
}
|
2023-10-17 09:16:37 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_criticalSection.Leave();
|
|
|
|
return SUCCESS;
|
2023-10-16 16:09:08 -04:00
|
|
|
}
|