isle/LEGO1/mxtransitionmanager.cpp

238 lines
5.9 KiB
C++
Raw Normal View History

#include "mxtransitionmanager.h"
#include "legoutil.h"
#include "legovideomanager.h"
DECOMP_SIZE_ASSERT(MxTransitionManager, 0x900);
// 0x100f4378
RECT g_fullScreenRect = {0, 0, 640, 480};
// OFFSET: LEGO1 0x1004b8d0
MxTransitionManager::MxTransitionManager()
{
m_animationTimer = 0;
m_transitionType = NOT_TRANSITIONING;
m_ddSurface = NULL;
m_waitIndicator = NULL;
m_copyBuffer = NULL;
m_copyFlags.bit0 = FALSE;
m_unk28.bit0 = FALSE;
m_unk24 = 0;
}
// OFFSET: LEGO1 0x1004ba00
MxTransitionManager::~MxTransitionManager()
{
free(m_copyBuffer);
if (m_waitIndicator != NULL) {
delete m_waitIndicator->GetAction();
delete m_waitIndicator;
}
TickleManager()->UnregisterClient(this);
}
// OFFSET: LEGO1 0x1004bac0 STUB
MxResult MxTransitionManager::Tickle()
{
// TODO
return 0;
}
// OFFSET: LEGO1 0x1004bc30
void MxTransitionManager::EndTransition(MxBool p_notifyWorld)
{
if (m_transitionType != NOT_TRANSITIONING) {
m_transitionType = NOT_TRANSITIONING;
m_copyFlags.bit0 = FALSE;
TickleManager()->UnregisterClient(this);
if (p_notifyWorld) {
LegoWorld *world = GetCurrentWorld();
if (world) {
world->Notify(MxParam(0x18, this));
}
}
}
}
// OFFSET: LEGO1 0x1004bd10
void MxTransitionManager::Transition_Dissolve()
{
// If the animation is finished
if (m_animationTimer == 40) {
m_animationTimer = 0;
EndTransition(TRUE);
return;
}
// If we are starting the animation
if (m_animationTimer == 0) {
// Generate the list of columns in order...
for (MxS32 i = 0; i < 640; i++) {
m_columnOrder[i] = i;
}
// ...then shuffle the list (to ensure that we hit each column once)
for (i = 0; i < 640; i++) {
MxS32 swap = rand() % 640;
MxU16 t = m_columnOrder[i];
m_columnOrder[i] = m_columnOrder[swap];
m_columnOrder[swap] = t;
}
// For each scanline, pick a random X offset
for (i = 0; i < 480; i++) {
m_randomShift[i] = rand() % 640;
}
}
// Run one tick of the animation
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
HRESULT res = m_ddSurface->Lock(NULL, &ddsd, 1, NULL);
if (res == DDERR_SURFACELOST) {
m_ddSurface->Restore();
res = m_ddSurface->Lock(NULL, &ddsd, 1, NULL);
}
if (res == DD_OK) {
SubmitCopyRect(ddsd);
for (MxS32 i = 0; i < 640; i++) {
// Select 16 columns on each tick
if (m_animationTimer * 16 > m_columnOrder[i])
continue;
if (m_animationTimer * 16 + 15 < m_columnOrder[i])
continue;
for (MxS32 j = 0; j < 480; j++) {
// Shift the chosen column a different amount at each scanline.
// We use the same shift for that scanline each time.
// By the end, every pixel gets hit.
MxS32 ofs = (m_randomShift[j] + i) % 640;
// Set the chosen pixel to black
if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8) {
((MxU8*)ddsd.lpSurface)[j * ddsd.lPitch + ofs] = 0;
} else {
((MxU16*)ddsd.lpSurface)[j * ddsd.lPitch + ofs] = 0;
}
}
}
SetupCopyRect(ddsd);
m_ddSurface->Unlock(ddsd.lpSurface);
if (VideoManager()->GetVideoParam().flags().GetFlipSurfaces()) {
LPDIRECTDRAWSURFACE surf = VideoManager()->GetDisplaySurface()->GetDirectDrawSurface1();
surf->BltFast(NULL, NULL, m_ddSurface, &g_fullScreenRect, 0x10);
}
m_animationTimer++;
}
}
// OFFSET: LEGO1 0x1004baa0
MxResult MxTransitionManager::GetDDrawSurfaceFromVideoManager() // vtable+0x14
{
LegoVideoManager *videoManager = VideoManager();
this->m_ddSurface = videoManager->GetDisplaySurface()->GetDirectDrawSurface2();
return SUCCESS;
}
// OFFSET: LEGO1 0x1004bb70
MxResult MxTransitionManager::StartTransition(TransitionType p_animationType, MxS32 p_speed,
MxBool p_doCopy, MxBool p_playMusicInAnim)
{
if (this->m_transitionType == NOT_TRANSITIONING) {
if (!p_playMusicInAnim) {
MxBackgroundAudioManager *backgroundAudioManager = BackgroundAudioManager();
backgroundAudioManager->Stop();
}
this->m_transitionType = p_animationType;
m_copyFlags.bit0 = p_doCopy;
if (m_copyFlags.bit0 && m_waitIndicator != NULL) {
m_waitIndicator->Enable(TRUE);
MxDSAction *action = m_waitIndicator->GetAction();
action->SetLoopCount(10000);
action->SetFlags(action->GetFlags() | MxDSAction::Flag_Bit9);
}
MxU32 time = timeGetTime();
this->m_systemTime = time;
this->m_animationSpeed = p_speed;
MxTickleManager *tickleManager = TickleManager();
tickleManager->RegisterClient(this, p_speed);
LegoInputManager *inputManager = InputManager();
LegoInputManager: some members and functions (#81) * Squashed commit of the following: commit 1fe03a4a787693616c56f59622bcaae8fd53b30b Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 21:04:15 2023 -0700 data types commit 7c8432f88236c42c17998d51e820b5e219f3c326 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 12:39:13 2023 -0700 Destroy commit f60eb3923b24bc87bb31ba783676c6a50d48e9b8 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 12:15:33 2023 -0700 compile fix commit e2f78d557f223c2552a046470578d154c29e473b Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 13:37:33 2023 -0700 Timer functions commit 447e234e6324a5b0958e9e94c5cda53703abada2 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 02:40:10 2023 -0700 fix commit 4670fd790b16a15b5797d50bc3cd1f6e2c9e890d Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 02:39:04 2023 -0700 improvements commit 7f70bce1eefe550fe6bef193e7ee54948af354b6 Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 03:42:47 2023 -0700 Update legoinputmanager.cpp commit 0d3433a75d2b20a3fff1da8147ce502b279b1e9c Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 03:38:32 2023 -0700 Add ReleaseDX commit 72d27fd402efb37da1ce8c41a3350df66c99db1d Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 02:27:12 2023 -0700 Update CMakeLists.txt commit 09626a62f9d2c56a523ca582be95a4dfb29ee188 Author: ecumber <ecumber05@gmail.com> Date: Mon Jul 3 13:48:46 2023 -0700 Move to new branch * Squashed commit of the following: commit d9148242a322ec54750c89357a0db2154310907d Author: ecumber <ecumber05@gmail.com> Date: Sun Jul 16 23:56:54 2023 -0700 Update legoinputmanager.cpp commit 983d08650eb3df0b9103761b4023a6d3395686b2 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 21:04:15 2023 -0700 data types commit 4e8aac36ece6f3d7cfff39432ebc4e731876fb75 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 12:39:13 2023 -0700 Destroy commit 907801567a8c93ebd242b25b4aa2b00d38eaedc8 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 12:15:33 2023 -0700 compile fix commit 91a5f75e938d796f153cc872e46acef2c342818c Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 13:37:33 2023 -0700 Timer functions commit e77f08f5358b6cc4ee41583f70281c40b95bea29 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 02:40:10 2023 -0700 fix commit 30d204b7734a56b4140a3bf53c9825126a1f80c7 Author: ecumber <ecumber05@gmail.com> Date: Thu Jul 6 02:39:04 2023 -0700 improvements commit dd4ff493355796c41a6fb328fda1892c0f1fec0a Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 03:42:47 2023 -0700 Update legoinputmanager.cpp commit 852658cdbc0e6f792a6a79dfc77df3539ea4a15a Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 03:38:32 2023 -0700 Add ReleaseDX commit 430d4e100811bc00dc983a9fe78aa1482fb92f7f Author: ecumber <ecumber05@gmail.com> Date: Tue Jul 4 02:27:12 2023 -0700 Update CMakeLists.txt commit 6fb94f007613e920b1d64775b7b76cb721482884 Author: ecumber <ecumber05@gmail.com> Date: Mon Jul 3 13:48:46 2023 -0700 Move to new branch * Fixes * Remove obsolete stuff * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-10-03 13:53:22 -04:00
inputManager->m_unk0x88 = TRUE;
inputManager->m_unk0x336 = FALSE;
LegoVideoManager *videoManager = VideoManager();
videoManager->SetUnkE4(FALSE);
SetAppCursor(1);
return SUCCESS;
}
return FAILURE;
}
// OFFSET: LEGO1 0x1004c470 STUB
void MxTransitionManager::SetWaitIndicator(MxVideoPresenter *videoPresenter)
{
// TODO
}
// OFFSET: LEGO1 0x1004c4d0
void MxTransitionManager::SubmitCopyRect(DDSURFACEDESC &ddsc)
{
// Check if the copy rect is setup
if (m_copyFlags.bit0 == FALSE || m_waitIndicator == NULL || m_copyBuffer == NULL) {
return;
}
// Copy the copy rect onto the surface
char *dst;
DWORD bytesPerPixel = ddsc.ddpfPixelFormat.dwRGBBitCount / 8;
const char *src = (const char *)m_copyBuffer;
LONG copyPitch;
copyPitch = ((m_copyRect.right - m_copyRect.left) + 1) * bytesPerPixel;
LONG y;
dst = (char *)ddsc.lpSurface + (ddsc.lPitch * m_copyRect.top) + (bytesPerPixel * m_copyRect.left);
for (y = 0; y < m_copyRect.bottom - m_copyRect.top + 1; ++y) {
memcpy(dst, src, copyPitch);
src += copyPitch;
dst += ddsc.lPitch;
}
// Free the copy buffer
free(m_copyBuffer);
m_copyBuffer = NULL;
}
// OFFSET: LEGO1 0x1004c580 STUB
void MxTransitionManager::SetupCopyRect(DDSURFACEDESC &ddsc)
{
// TODO
}