Reorganize sources and files (#414)

* Reorganize sources

* Refactor

* Remove relative paths

* Renames

* Fix gitignore

* Remove stuff

* Try fixing format script

* Fix format

* Fix format

* Fix naming script

* Test format

* Fix format
This commit is contained in:
Christian Semmler
2024-01-08 04:58:49 -05:00
committed by GitHub
parent 6a85e62406
commit c47206617d
447 changed files with 347 additions and 346 deletions

View File

@@ -0,0 +1,393 @@
#include "mxbitmap.h"
#include "decomp.h"
DECOMP_SIZE_ASSERT(MxBitmap, 0x20);
DECOMP_SIZE_ASSERT(MxBITMAPINFO, 0x428);
// Bitmap header magic string "BM" (42 4d)
// Sources: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapfileheader, DirectX Complete
// (1998) GLOBAL: LEGO1 0x10102184
MxU16 g_bitmapSignature = TWOCC('B', 'M');
// FUNCTION: LEGO1 0x1004e0d0
int MxBitmap::VTable0x28(int)
{
return -1;
}
// FUNCTION: LEGO1 0x100bc980
MxBitmap::MxBitmap()
{
this->m_info = NULL;
this->m_bmiHeader = NULL;
this->m_paletteData = NULL;
this->m_data = NULL;
this->m_isHighColor = FALSE;
this->m_palette = NULL;
}
// FUNCTION: LEGO1 0x100bca10
MxBitmap::~MxBitmap()
{
if (this->m_info)
delete m_info;
if (this->m_data)
delete m_data;
if (this->m_palette)
delete m_palette;
}
// FUNCTION: LEGO1 0x100bcaa0
MxResult MxBitmap::SetSize(MxS32 p_width, MxS32 p_height, MxPalette* p_palette, MxBool p_isHighColor)
{
MxResult ret = FAILURE;
MxLong size = AlignToFourByte(p_width) * p_height;
m_info = new MxBITMAPINFO;
if (m_info) {
m_data = new MxU8[size];
if (m_data) {
m_bmiHeader = &m_info->m_bmiHeader;
m_paletteData = m_info->m_bmiColors;
memset(&m_info->m_bmiHeader, 0, sizeof(m_info->m_bmiHeader));
m_bmiHeader->biSize = sizeof(*m_bmiHeader); // should be 40 bytes
m_bmiHeader->biWidth = p_width;
m_bmiHeader->biHeight = p_height;
m_bmiHeader->biPlanes = 1;
m_bmiHeader->biBitCount = 8;
m_bmiHeader->biCompression = 0;
m_bmiHeader->biSizeImage = size;
if (!ImportColorsToPalette(m_paletteData, p_palette)) {
if (!SetBitDepth(p_isHighColor)) {
ret = SUCCESS;
}
}
}
}
if (ret) {
if (m_info) {
delete m_info;
m_info = NULL;
}
if (m_data) {
delete[] m_data;
m_data = NULL;
}
}
return ret;
}
// FUNCTION: LEGO1 0x100bcba0
MxResult MxBitmap::ImportBitmapInfo(MxBITMAPINFO* p_info)
{
MxResult result = FAILURE;
MxLong width = p_info->m_bmiHeader.biWidth;
MxLong height = p_info->m_bmiHeader.biHeight;
MxLong size = AlignToFourByte(width) * height;
this->m_info = new MxBITMAPINFO;
if (this->m_info) {
this->m_data = new MxU8[size];
if (this->m_data) {
memcpy(this->m_info, p_info, sizeof(*this->m_info));
this->m_bmiHeader = &this->m_info->m_bmiHeader;
this->m_paletteData = this->m_info->m_bmiColors;
result = SUCCESS;
}
}
if (result != SUCCESS) {
if (this->m_info) {
delete this->m_info;
this->m_info = NULL;
}
if (this->m_data) {
delete this->m_data;
this->m_data = NULL;
}
}
return result;
}
// FUNCTION: LEGO1 0x100bcc40
MxResult MxBitmap::ImportBitmap(MxBitmap* p_bitmap)
{
MxResult result = FAILURE;
this->m_info = new MxBITMAPINFO;
if (this->m_info) {
this->m_data = new MxU8[p_bitmap->GetDataSize()];
if (this->m_data) {
memcpy(this->m_info, p_bitmap->GetBitmapInfo(), MxBITMAPINFO::Size());
memcpy(this->m_data, p_bitmap->GetBitmapData(), p_bitmap->GetDataSize());
this->m_bmiHeader = &this->m_info->m_bmiHeader;
this->m_paletteData = this->m_info->m_bmiColors;
result = SUCCESS;
}
}
if (result != SUCCESS) {
if (this->m_info) {
delete this->m_info;
this->m_info = NULL;
}
if (this->m_data) {
delete this->m_data;
this->m_data = NULL;
}
}
return result;
}
// FUNCTION: LEGO1 0x100bcd10
MxLong MxBitmap::Read(const char* p_filename)
{
MxResult result = FAILURE;
HANDLE handle =
CreateFileA(p_filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (handle != INVALID_HANDLE_VALUE && !LoadFile(handle))
result = SUCCESS;
if (handle)
CloseHandle(handle);
return result;
}
// FUNCTION: LEGO1 0x100bcd60
MxResult MxBitmap::LoadFile(HANDLE p_handle)
{
MxResult result = FAILURE;
DWORD bytesRead;
BITMAPFILEHEADER hdr;
BOOL ret = ReadFile(p_handle, &hdr, sizeof(hdr), &bytesRead, NULL);
if (ret && (hdr.bfType == g_bitmapSignature)) {
this->m_info = new MxBITMAPINFO;
if (this->m_info) {
ret = ReadFile(p_handle, this->m_info, sizeof(*this->m_info), &bytesRead, NULL);
if (ret && (this->m_info->m_bmiHeader.biBitCount == 8)) {
MxLong size = hdr.bfSize - (sizeof(MxBITMAPINFO) + sizeof(BITMAPFILEHEADER));
this->m_data = new MxU8[size];
if (this->m_data) {
ret = ReadFile(p_handle, this->m_data, size, &bytesRead, NULL);
if (ret) {
this->m_bmiHeader = &this->m_info->m_bmiHeader;
this->m_paletteData = this->m_info->m_bmiColors;
if (this->m_info->m_bmiHeader.biSizeImage == 0) {
MxLong height = AbsFlipped(this->m_info->m_bmiHeader.biHeight);
this->m_info->m_bmiHeader.biSizeImage =
AlignToFourByte(this->m_info->m_bmiHeader.biWidth) * height;
}
result = SUCCESS;
}
}
}
}
}
if (result != SUCCESS) {
if (this->m_info) {
delete this->m_info;
this->m_info = NULL;
}
if (this->m_data) {
delete this->m_data;
this->m_data = NULL;
}
}
return result;
}
// STUB: LEGO1 0x100bce70
void MxBitmap::VTable0x2c(int, int, int, int, int, int, int)
{
}
// STUB: LEGO1 0x100bd020
void MxBitmap::VTable0x30(int, int, int, int, int, int, int)
{
}
// FUNCTION: LEGO1 0x100bd1c0
MxPalette* MxBitmap::CreatePalette()
{
MxBool success = FALSE;
MxPalette* palette = NULL;
switch (this->m_isHighColor) {
case FALSE:
palette = new MxPalette(this->m_paletteData);
if (!palette)
goto done;
break;
case TRUE:
palette = this->m_palette->Clone();
if (!palette)
goto done;
break;
default:
goto done;
}
success = TRUE;
done:
if (!success && palette) {
delete palette;
palette = NULL;
}
return palette;
}
// FUNCTION: LEGO1 0x100bd280
void MxBitmap::ImportPalette(MxPalette* p_palette)
{
// Odd to use a switch on a boolean, but it matches.
switch (this->m_isHighColor) {
case FALSE:
ImportColorsToPalette(this->m_paletteData, p_palette);
break;
case TRUE:
if (this->m_palette) {
delete this->m_palette;
}
this->m_palette = p_palette->Clone();
break;
}
}
// FUNCTION: LEGO1 0x100bd2d0
MxResult MxBitmap::SetBitDepth(MxBool p_isHighColor)
{
MxResult ret = FAILURE;
MxPalette* pal = NULL;
if (m_isHighColor == p_isHighColor) {
// no change: do nothing.
ret = SUCCESS;
goto done;
}
switch (p_isHighColor) {
case FALSE:
ImportColorsToPalette(m_paletteData, m_palette);
if (m_palette)
delete m_palette;
m_palette = NULL;
break;
case TRUE: {
pal = NULL;
pal = new MxPalette(m_paletteData);
if (!pal)
goto done;
m_palette = pal;
// TODO: what is this? zeroing out top half of palette?
MxU16* buf = (MxU16*) m_paletteData;
for (MxU16 i = 0; i < 256; i++) {
buf[i] = i;
}
break;
}
default:
goto done;
}
m_isHighColor = p_isHighColor;
ret = SUCCESS;
done:
// If we were unsuccessful overall but did manage to alloc
// the MxPalette, free it.
if (ret && pal)
delete pal;
return ret;
}
// FUNCTION: LEGO1 0x100bd3e0
MxResult MxBitmap::StretchBits(
HDC p_hdc,
MxS32 p_xSrc,
MxS32 p_ySrc,
MxS32 p_xDest,
MxS32 p_yDest,
MxS32 p_destWidth,
MxS32 p_destHeight
)
{
// Compression fix?
if ((this->m_bmiHeader->biCompression != BI_RGB_TOPDOWN) && (0 < this->m_bmiHeader->biHeight)) {
p_ySrc = (this->m_bmiHeader->biHeight - p_destHeight) - p_ySrc;
}
return StretchDIBits(
p_hdc,
p_xDest,
p_yDest,
p_destWidth,
p_destHeight,
p_xSrc,
p_ySrc,
p_destWidth,
p_destHeight,
this->m_data,
(BITMAPINFO*) this->m_info,
this->m_isHighColor,
SRCCOPY
);
}
// FUNCTION: LEGO1 0x100bd450
MxResult MxBitmap::ImportColorsToPalette(RGBQUAD* p_rgbquad, MxPalette* p_palette)
{
MxResult ret = FAILURE;
PALETTEENTRY entries[256];
if (p_palette) {
if (p_palette->GetEntries(entries))
goto done;
}
else {
MxPalette palette;
if (palette.GetEntries(entries))
goto done;
}
MxS32 i;
for (i = 0; i < 256; i++) {
p_rgbquad[i].rgbRed = entries[i].peRed;
p_rgbquad[i].rgbGreen = entries[i].peGreen;
p_rgbquad[i].rgbBlue = entries[i].peBlue;
p_rgbquad[i].rgbReserved = 0;
}
ret = SUCCESS;
done:
return ret;
}

View File

@@ -0,0 +1,606 @@
#include "mxdisplaysurface.h"
#include "legoomni.h"
#include "mxvideomanager.h"
#include <windows.h>
DECOMP_SIZE_ASSERT(MxDisplaySurface, 0xac);
MxU32 g_unk0x1010215c = 0;
// FUNCTION: LEGO1 0x100ba500
MxDisplaySurface::MxDisplaySurface()
{
this->Init();
}
// FUNCTION: LEGO1 0x100ba5a0
MxDisplaySurface::~MxDisplaySurface()
{
this->Destroy();
}
// FUNCTION: LEGO1 0x100ba610
void MxDisplaySurface::Init()
{
this->m_ddSurface1 = NULL;
this->m_ddSurface2 = NULL;
this->m_ddClipper = NULL;
this->m_16bitPal = NULL;
this->m_initialized = FALSE;
memset(&this->m_surfaceDesc, 0, sizeof(this->m_surfaceDesc));
}
// FUNCTION: LEGO1 0x100ba640
void MxDisplaySurface::FUN_100ba640()
{
MxS32 backBuffers;
DDSURFACEDESC desc;
HRESULT hr;
if (!m_videoParam.Flags().GetFlipSurfaces()) {
backBuffers = 1;
}
else {
backBuffers = m_videoParam.GetBackBuffers() + 1;
}
for (MxS32 i = 0; i < backBuffers; i++) {
memset(&desc, 0, sizeof(DDSURFACEDESC));
desc.dwSize = sizeof(DDSURFACEDESC);
hr = m_ddSurface2->Lock(NULL, &desc, DDLOCK_WAIT, NULL);
if (hr == DDERR_SURFACELOST) {
m_ddSurface2->Restore();
hr = m_ddSurface2->Lock(NULL, &desc, DDLOCK_WAIT, NULL);
}
if (hr != DD_OK) {
return;
}
MxU8* surface = (MxU8*) desc.lpSurface;
MxS32 height = m_videoParam.GetRect().GetHeight();
while (height--) {
memset(surface, 0, m_videoParam.GetRect().GetWidth() * desc.ddpfPixelFormat.dwRGBBitCount / 8);
surface += desc.lPitch;
}
m_ddSurface2->Unlock(desc.lpSurface);
if (m_videoParam.Flags().GetFlipSurfaces()) {
m_ddSurface1->Flip(NULL, DDFLIP_WAIT);
}
}
}
// FUNCTION: LEGO1 0x100ba750
MxU8 MxDisplaySurface::CountTotalBitsSetTo1(MxU32 p_param)
{
MxU8 count = 0;
for (; p_param; p_param >>= 1)
count += ((MxU8) p_param & 1);
return count;
}
// FUNCTION: LEGO1 0x100ba770
MxU8 MxDisplaySurface::CountContiguousBitsSetTo1(MxU32 p_param)
{
MxU8 count = 0;
for (; (p_param & 1) == 0; p_param >>= 1)
count++;
return count;
}
// FUNCTION: LEGO1 0x100ba790
MxResult MxDisplaySurface::Init(
MxVideoParam& p_videoParam,
LPDIRECTDRAWSURFACE p_ddSurface1,
LPDIRECTDRAWSURFACE p_ddSurface2,
LPDIRECTDRAWCLIPPER p_ddClipper
)
{
MxResult result = SUCCESS;
this->m_videoParam = p_videoParam;
this->m_ddSurface1 = p_ddSurface1;
this->m_ddSurface2 = p_ddSurface2;
this->m_ddClipper = p_ddClipper;
this->m_initialized = FALSE;
memset(&this->m_surfaceDesc, 0, sizeof(this->m_surfaceDesc));
this->m_surfaceDesc.dwSize = sizeof(this->m_surfaceDesc);
if (this->m_ddSurface2->GetSurfaceDesc(&this->m_surfaceDesc))
result = FAILURE;
return result;
}
// FUNCTION: LEGO1 0x100ba7f0
MxResult MxDisplaySurface::Create(MxVideoParam& p_videoParam)
{
DDSURFACEDESC ddsd;
MxResult result = FAILURE;
LPDIRECTDRAW lpDirectDraw = MVideoManager()->GetDirectDraw();
HWND hWnd = MxOmni::GetInstance()->GetWindowHandle();
this->m_initialized = TRUE;
this->m_videoParam = p_videoParam;
if (!this->m_videoParam.Flags().GetFullScreen())
this->m_videoParam.Flags().SetFlipSurfaces(FALSE);
if (!this->m_videoParam.Flags().GetFlipSurfaces()) {
this->m_videoParam.SetBackBuffers(1);
}
else {
MxU32 backBuffers = this->m_videoParam.GetBackBuffers();
if (backBuffers < 1)
this->m_videoParam.SetBackBuffers(1);
else if (backBuffers > 2)
this->m_videoParam.SetBackBuffers(2);
this->m_videoParam.Flags().SetBackBuffers(TRUE);
}
if (this->m_videoParam.Flags().GetFullScreen()) {
MxS32 width = this->m_videoParam.GetRect().GetWidth();
MxS32 height = this->m_videoParam.GetRect().GetHeight();
if (lpDirectDraw->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN))
goto done;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
if (lpDirectDraw->GetDisplayMode(&ddsd))
goto done;
MxS32 bitdepth = !this->m_videoParam.Flags().Get16Bit() ? 8 : 16;
if (ddsd.dwWidth != width || ddsd.dwHeight != height || ddsd.ddpfPixelFormat.dwRGBBitCount != bitdepth) {
if (lpDirectDraw->SetDisplayMode(width, height, bitdepth))
goto done;
}
}
if (this->m_videoParam.Flags().GetFlipSurfaces()) {
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwBackBufferCount = this->m_videoParam.GetBackBuffers();
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
if (lpDirectDraw->CreateSurface(&ddsd, &this->m_ddSurface1, NULL))
goto done;
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
if (this->m_ddSurface1->GetAttachedSurface(&ddsd.ddsCaps, &this->m_ddSurface2))
goto done;
}
else {
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if (lpDirectDraw->CreateSurface(&ddsd, &this->m_ddSurface1, NULL))
goto done;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_CAPS;
ddsd.dwWidth = this->m_videoParam.GetRect().GetWidth();
ddsd.dwHeight = this->m_videoParam.GetRect().GetHeight();
ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN;
if (!this->m_videoParam.Flags().GetBackBuffers())
ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
if (lpDirectDraw->CreateSurface(&ddsd, &this->m_ddSurface2, NULL))
goto done;
}
memset(&this->m_surfaceDesc, 0, sizeof(this->m_surfaceDesc));
this->m_surfaceDesc.dwSize = sizeof(this->m_surfaceDesc);
if (!this->m_ddSurface2->GetSurfaceDesc(&this->m_surfaceDesc)) {
if (!lpDirectDraw->CreateClipper(0, &this->m_ddClipper, NULL) && !this->m_ddClipper->SetHWnd(0, hWnd) &&
!this->m_ddSurface1->SetClipper(this->m_ddClipper))
result = SUCCESS;
}
done:
return result;
}
// FUNCTION: LEGO1 0x100baa90
void MxDisplaySurface::Destroy()
{
if (this->m_initialized) {
if (this->m_ddSurface2)
this->m_ddSurface2->Release();
if (this->m_ddSurface1)
this->m_ddSurface1->Release();
if (this->m_ddClipper)
this->m_ddClipper->Release();
}
if (this->m_16bitPal)
delete this->m_16bitPal;
this->Init();
}
// FUNCTION: LEGO1 0x100baae0
void MxDisplaySurface::SetPalette(MxPalette* p_palette)
{
if (m_surfaceDesc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
m_ddSurface1->SetPalette(p_palette->CreateNativePalette());
m_ddSurface2->SetPalette(p_palette->CreateNativePalette());
if ((m_videoParam.Flags().GetFullScreen() & 1) == 0) {
struct {
WORD m_palVersion;
WORD m_palNumEntries;
PALETTEENTRY m_palPalEntry[256];
} lpal;
lpal.m_palVersion = 0x300;
lpal.m_palNumEntries = 256;
memset(lpal.m_palPalEntry, 0, sizeof(lpal.m_palPalEntry));
p_palette->GetEntries(lpal.m_palPalEntry);
HPALETTE hpal = CreatePalette((LPLOGPALETTE) &lpal);
HDC hdc = ::GetDC(0);
SelectPalette(hdc, hpal, FALSE);
RealizePalette(hdc);
::ReleaseDC(NULL, hdc);
DeleteObject(hpal);
}
}
if (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount == 16) {
if (!m_16bitPal)
m_16bitPal = new MxU16[256];
PALETTEENTRY palette[256];
p_palette->GetEntries(palette);
MxU8 contiguousBitsRed = CountContiguousBitsSetTo1(m_surfaceDesc.ddpfPixelFormat.dwRBitMask);
MxU8 totalBitsRed = CountTotalBitsSetTo1(m_surfaceDesc.ddpfPixelFormat.dwRBitMask);
MxU8 contiguousBitsGreen = CountContiguousBitsSetTo1(m_surfaceDesc.ddpfPixelFormat.dwGBitMask);
MxU8 totalBitsGreen = CountTotalBitsSetTo1(m_surfaceDesc.ddpfPixelFormat.dwGBitMask);
MxU8 contiguousBitsBlue = CountContiguousBitsSetTo1(m_surfaceDesc.ddpfPixelFormat.dwBBitMask);
MxU8 totalBitsBlue = CountTotalBitsSetTo1(m_surfaceDesc.ddpfPixelFormat.dwBBitMask);
for (MxS32 i = 0; i < 256; i++) {
m_16bitPal[i] = (((palette[i].peRed >> (8 - totalBitsRed & 0x1f)) << (contiguousBitsRed & 0x1f))) |
(((palette[i].peGreen >> (8 - totalBitsGreen & 0x1f)) << (contiguousBitsGreen & 0x1f))) |
(((palette[i].peBlue >> (8 - totalBitsBlue & 0x1f)) << (contiguousBitsBlue & 0x1f)));
}
}
}
// FUNCTION: LEGO1 0x100bacc0
void MxDisplaySurface::VTable0x28(
MxBitmap* p_bitmap,
MxS32 p_left,
MxS32 p_top,
MxS32 p_right,
MxS32 p_bottom,
MxS32 p_width,
MxS32 p_height
)
{
if (FUN_100b6e10(
p_bitmap->GetBmiWidth(),
p_bitmap->GetBmiHeightAbs(),
m_videoParam.GetRect().GetWidth(),
m_videoParam.GetRect().GetHeight(),
&p_left,
&p_top,
&p_right,
&p_bottom,
&p_width,
&p_height
)) {
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
HRESULT hr = m_ddSurface2->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
if (hr == DDERR_SURFACELOST) {
m_ddSurface2->Restore();
hr = m_ddSurface2->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
}
if (hr == DD_OK) {
MxU8* data;
switch (p_bitmap->GetBmiHeader()->biCompression) {
case BI_RGB: {
MxS32 rowsBeforeTop;
if (p_bitmap->GetBmiHeight() < 0)
rowsBeforeTop = p_top;
else
rowsBeforeTop = p_bitmap->GetBmiHeightAbs() - p_top - 1;
data = p_bitmap->GetBitmapData() + p_left + (p_bitmap->GetBmiStride() * rowsBeforeTop);
break;
}
case BI_RGB_TOPDOWN:
data = p_bitmap->GetBitmapData();
break;
default: {
MxS32 rowsBeforeTop;
if (p_bitmap->GetBmiHeight() < 0)
rowsBeforeTop = 0;
else
rowsBeforeTop = p_bitmap->GetBmiHeightAbs() - 1;
data = p_bitmap->GetBitmapData() + (p_bitmap->GetBmiStride() * rowsBeforeTop);
}
}
if (m_videoParam.Flags().GetF1bit3()) {
p_bottom *= 2;
p_right *= 2;
switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) {
case 8: {
MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride();
MxLong v22 = stride - p_width;
MxLong length = ddsd.lPitch - (2 * p_width);
while (p_height--) {
MxU8* surfaceBefore = surface;
for (MxS32 i = 0; p_width > i; i++) {
MxU8 element = *data;
*surface++ = element;
data++;
*surface++ = *(data - 1);
}
data += v22;
surface += length;
memcpy(surface, surfaceBefore, 2 * p_width);
surface += ddsd.lPitch;
}
break;
}
case 16: {
MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride();
// TODO: Match
stride -= p_width;
MxS32 length = p_width * 4;
MxLong v62 = ddsd.lPitch - length;
MxS32 height = p_height;
MxS32 width = p_width;
MxU16* p16BitPal = m_16bitPal;
if (stride || v62) {
while (height--) {
MxU8* surfaceBefore = surface;
for (MxS32 i = width; i > 0; i--) {
MxU16 element = p16BitPal[*data++];
*(MxU16*) surface = element;
surface += 2;
*(MxU16*) surface = element;
surface += 2;
}
data += stride;
surface += v62;
// Odd expression for the length?
memcpy(surface, surfaceBefore, 4 * ((MxU32) (4 * p_width) / 4));
surface += ddsd.lPitch;
}
}
else {
while (height--) {
MxU8* surfaceBefore = surface;
for (MxS32 i = width; i > 0; i--) {
MxU16 element = p16BitPal[*data++];
*(MxU16*) surface = element;
surface += 2;
*(MxU16*) surface = element;
surface += 2;
}
memcpy(surface, surfaceBefore, length);
surface += ddsd.lPitch;
}
}
}
}
}
else {
switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) {
case 8: {
MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride();
MxLong length = ddsd.lPitch;
while (p_height--) {
memcpy(surface, data, p_width);
data += stride;
surface += length;
}
break;
}
case 16: {
MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride();
MxLong v50 = stride - p_width;
MxLong length = ddsd.lPitch - (2 * p_width);
for (MxS32 i = 0; p_height > i; i++) {
for (MxS32 j = 0; p_width > j; j++) {
*(MxU16*) surface = m_16bitPal[*data++];
surface += 2;
}
data += v50;
surface += length;
}
}
}
}
m_ddSurface2->Unlock(ddsd.lpSurface);
}
}
}
// STUB: LEGO1 0x100bb1d0
MxBool MxDisplaySurface::VTable0x30(
MxBitmap* p_bitmap,
MxS32 p_left,
MxS32 p_top,
MxS32 p_right,
MxS32 p_bottom,
MxS32 p_width,
MxS32 p_height,
MxBool
)
{
return 0;
}
// STUB: LEGO1 0x100bb850
undefined4 MxDisplaySurface::VTable0x34(undefined4, undefined4, undefined4, undefined4, undefined4, undefined4)
{
return 0;
}
// FUNCTION: LEGO1 0x100bba50
void MxDisplaySurface::Display(MxS32 p_left, MxS32 p_top, MxS32 p_left2, MxS32 p_top2, MxS32 p_width, MxS32 p_height)
{
if (m_videoParam.Flags().GetF2bit1()) {
if (m_videoParam.Flags().GetFlipSurfaces()) {
if (g_unk0x1010215c < 2) {
g_unk0x1010215c++;
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
if (m_ddSurface2->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) == DD_OK) {
MxU8* surface = (MxU8*) ddsd.lpSurface;
MxS32 height = m_videoParam.GetRect().GetHeight();
for (MxU32 i = 0; i < ddsd.dwHeight; i++) {
memset(surface, 0, ddsd.dwWidth * ddsd.ddpfPixelFormat.dwRGBBitCount / 8);
surface += ddsd.lPitch;
}
m_ddSurface2->Unlock(ddsd.lpSurface);
}
else {
OutputDebugString("MxDisplaySurface::Display error\n");
}
}
m_ddSurface1->Flip(NULL, DDFLIP_WAIT);
}
else {
POINT point = {0, 0};
ClientToScreen(MxOmni::GetInstance()->GetWindowHandle(), &point);
// TODO: Match
RECT rect1, rect2;
rect1.left = p_left2 + m_videoParam.GetRect().GetLeft() + point.x;
rect2.left = p_left;
rect1.top = p_top2 + m_videoParam.GetRect().GetTop() + point.y;
rect2.right = p_left + p_width;
rect2.top = p_top;
rect2.bottom = p_top + p_height;
rect1.right = rect1.left + p_width;
rect1.bottom = rect1.top + p_height;
DDBLTFX data;
memset(&data, 0, sizeof(data));
data.dwSize = sizeof(data);
data.dwDDFX = 8;
if (m_ddSurface1->Blt(&rect1, m_ddSurface2, &rect2, 0, &data) == DDERR_SURFACELOST) {
m_ddSurface1->Restore();
m_ddSurface1->Blt(&rect1, m_ddSurface2, &rect2, 0, &data);
}
}
}
}
// FUNCTION: LEGO1 0x100bbc10
void MxDisplaySurface::GetDC(HDC* p_hdc)
{
if (this->m_ddSurface2 && !this->m_ddSurface2->GetDC(p_hdc))
return;
*p_hdc = NULL;
}
// FUNCTION: LEGO1 0x100bbc40
void MxDisplaySurface::ReleaseDC(HDC p_hdc)
{
if (this->m_ddSurface2 && p_hdc)
this->m_ddSurface2->ReleaseDC(p_hdc);
}
// STUB: LEGO1 0x100bbc60
LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(MxBitmap*, undefined4*, undefined4, undefined4)
{
return NULL;
}
// STUB: LEGO1 0x100bc070
LPDIRECTDRAWSURFACE MxDisplaySurface::FUN_100bc070()
{
return NULL;
}
// STUB: LEGO1 0x100bc200
void MxDisplaySurface::VTable0x24(
LPDDSURFACEDESC,
MxBitmap*,
undefined4,
undefined4,
undefined4,
undefined4,
undefined4,
undefined4
)
{
}
// STUB: LEGO1 0x100bc630
MxBool MxDisplaySurface::VTable0x2c(
LPDDSURFACEDESC,
MxBitmap*,
undefined4,
undefined4,
undefined4,
undefined4,
undefined4,
undefined4,
MxBool
)
{
return 0;
}

View File

@@ -0,0 +1,50 @@
#include "mxflcpresenter.h"
#include "decomp.h"
#include "mxbitmap.h"
#include "mxomni.h"
#include "mxpalette.h"
#include "mxvideomanager.h"
DECOMP_SIZE_ASSERT(MxFlcPresenter, 0x68);
// FUNCTION: LEGO1 0x100b3310
MxFlcPresenter::MxFlcPresenter()
{
this->m_flicHeader = NULL;
this->m_flags &= ~Flag_Bit2;
this->m_flags &= ~Flag_Bit3;
}
// FUNCTION: LEGO1 0x100b3420
MxFlcPresenter::~MxFlcPresenter()
{
if (this->m_flicHeader) {
delete this->m_flicHeader;
}
}
// FUNCTION: LEGO1 0x100b3490
void MxFlcPresenter::LoadHeader(MxStreamChunk* p_chunk)
{
m_flicHeader = (FLIC_HEADER*) new MxU8[p_chunk->GetLength()];
memcpy(m_flicHeader, p_chunk->GetData(), p_chunk->GetLength());
}
// FUNCTION: LEGO1 0x100b34d0
void MxFlcPresenter::CreateBitmap()
{
if (m_bitmap)
delete m_bitmap;
m_bitmap = new MxBitmap;
m_bitmap->SetSize(m_flicHeader->width, m_flicHeader->height, NULL, FALSE);
}
// FUNCTION: LEGO1 0x100b3620
void MxFlcPresenter::RealizePalette()
{
MxPalette* palette = m_bitmap->CreatePalette();
MVideoManager()->RealizePalette(palette);
delete palette;
}

View File

@@ -0,0 +1,54 @@
#include "mxloopingflcpresenter.h"
#include "decomp.h"
DECOMP_SIZE_ASSERT(MxLoopingFlcPresenter, 0x6c);
// FUNCTION: LEGO1 0x100b4310
MxLoopingFlcPresenter::MxLoopingFlcPresenter()
{
Init();
}
// FUNCTION: LEGO1 0x100b43b0
MxLoopingFlcPresenter::~MxLoopingFlcPresenter()
{
Destroy(TRUE);
}
// FUNCTION: LEGO1 0x100b4410
void MxLoopingFlcPresenter::Init()
{
this->m_unk0x68 = 0;
this->m_flags &= ~Flag_Bit2;
this->m_flags &= ~Flag_Bit3;
}
// FUNCTION: LEGO1 0x100b4430
void MxLoopingFlcPresenter::Destroy(MxBool p_fromDestructor)
{
m_criticalSection.Enter();
Init();
m_criticalSection.Leave();
if (!p_fromDestructor)
MxFlcPresenter::Destroy(FALSE);
}
// FUNCTION: LEGO1 0x100b4470
void MxLoopingFlcPresenter::NextFrame()
{
MxStreamChunk* chunk = NextChunk();
if (chunk->GetFlags() & MxDSChunk::Flag_End) {
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Repeating;
}
else {
LoadFrame(chunk);
AppendChunk(chunk);
m_unk0x68 += m_flicHeader->speed;
}
m_subscriber->FUN_100b8390(chunk);
}

View File

@@ -0,0 +1,131 @@
#include "mxloopingsmkpresenter.h"
#include "mxautolocker.h"
#include "mxdsmediaaction.h"
DECOMP_SIZE_ASSERT(MxLoopingSmkPresenter, 0x724);
// FUNCTION: LEGO1 0x100b48b0
MxLoopingSmkPresenter::MxLoopingSmkPresenter()
{
Init();
}
// FUNCTION: LEGO1 0x100b4950
MxLoopingSmkPresenter::~MxLoopingSmkPresenter()
{
Destroy(TRUE);
}
// FUNCTION: LEGO1 0x100b49b0
void MxLoopingSmkPresenter::Init()
{
this->m_elapsedDuration = 0;
this->m_flags &= ~Flag_Bit2;
this->m_flags &= ~Flag_Bit3;
}
// FUNCTION: LEGO1 0x100b49d0
void MxLoopingSmkPresenter::Destroy(MxBool p_fromDestructor)
{
m_criticalSection.Enter();
Init();
m_criticalSection.Leave();
if (!p_fromDestructor)
MxSmkPresenter::Destroy();
}
// FUNCTION: LEGO1 0x100b4a00
void MxLoopingSmkPresenter::VTable0x88()
{
if (m_mxSmack.m_smackTag.Frames == m_currentFrame) {
m_currentFrame = 0;
// TODO: struct incorrect, Palette at wrong offset?
memset(&m_mxSmack.m_smackTag.Palette[4], 0, sizeof(m_mxSmack.m_smackTag.Palette));
}
}
// FUNCTION: LEGO1 0x100b4a30
void MxLoopingSmkPresenter::NextFrame()
{
MxStreamChunk* chunk = NextChunk();
if (chunk->GetFlags() & MxDSChunk::Flag_End) {
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Repeating;
}
else {
LoadFrame(chunk);
AppendChunk(chunk);
m_elapsedDuration += 1000 / ((MxDSMediaAction*) m_action)->GetFramesPerSecond();
}
m_subscriber->FUN_100b8390(chunk);
}
// FUNCTION: LEGO1 0x100b4a90
void MxLoopingSmkPresenter::VTable0x8c()
{
if (m_action->GetDuration() < m_elapsedDuration) {
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_unk5;
}
else {
MxStreamChunk* chunk;
m_cursor->Current(chunk);
LoadFrame(chunk);
m_elapsedDuration += 1000 / ((MxDSMediaAction*) m_action)->GetFramesPerSecond();
}
}
// FUNCTION: LEGO1 0x100b4b00
void MxLoopingSmkPresenter::RepeatingTickle()
{
for (MxS16 i = 0; i < m_unk0x5c; i++) {
if (!m_cursor->HasMatch()) {
MxStreamChunk* chunk;
MxStreamChunkListCursor cursor(m_chunks);
cursor.Last(chunk);
MxLong time = chunk->GetTime();
cursor.First(chunk);
time -= chunk->GetTime();
time += 1000 / ((MxDSMediaAction*) m_action)->GetFramesPerSecond();
cursor.Reset();
while (cursor.Next(chunk))
chunk->SetTime(chunk->GetTime() + time);
m_cursor->Next();
}
MxStreamChunk* chunk;
m_cursor->Current(chunk);
if (m_action->GetElapsedTime() < chunk->GetTime())
break;
VTable0x8c();
m_cursor->Next(chunk);
if (m_currentTickleState != TickleState_Repeating)
break;
}
}
// FUNCTION: LEGO1 0x100b4cd0
MxResult MxLoopingSmkPresenter::AddToManager()
{
MxAutoLocker lock(&m_criticalSection);
return MxSmkPresenter::AddToManager();
}
// FUNCTION: LEGO1 0x100b4d40
void MxLoopingSmkPresenter::Destroy()
{
Destroy(FALSE);
}

View File

@@ -0,0 +1,280 @@
#include "mxpalette.h"
#include "mxomni.h"
#include "mxvideomanager.h"
// GLOBAL: LEGO1 0x10102188
PALETTEENTRY g_defaultPaletteEntries[256] = {
{0u, 0u, 0u, 0u}, {128u, 0u, 0u, 0u}, {0u, 128u, 0u, 0u}, {128u, 128u, 0u, 0u},
{0u, 0u, 128u, 0u}, {128u, 0u, 128u, 0u}, {0u, 128u, 128u, 0u}, {128u, 128u, 128u, 0u},
{192u, 220u, 192u, 0u}, {166u, 202u, 240u, 0u}, {255u, 255u, 255u, 0u}, {250u, 250u, 250u, 0u},
{239u, 239u, 239u, 0u}, {228u, 228u, 228u, 0u}, {217u, 217u, 217u, 0u}, {206u, 206u, 206u, 0u},
{195u, 195u, 195u, 0u}, {185u, 185u, 185u, 0u}, {174u, 174u, 174u, 0u}, {163u, 163u, 163u, 0u},
{152u, 152u, 152u, 0u}, {141u, 141u, 141u, 0u}, {130u, 130u, 130u, 0u}, {123u, 123u, 123u, 0u},
{115u, 115u, 115u, 0u}, {108u, 108u, 108u, 0u}, {101u, 101u, 101u, 0u}, {93u, 93u, 93u, 0u},
{86u, 86u, 86u, 0u}, {79u, 79u, 79u, 0u}, {71u, 71u, 71u, 0u}, {64u, 64u, 64u, 0u},
{54u, 54u, 54u, 0u}, {43u, 43u, 43u, 0u}, {33u, 33u, 33u, 0u}, {22u, 22u, 22u, 0u},
{12u, 12u, 12u, 0u}, {8u, 8u, 8u, 0u}, {4u, 4u, 4u, 0u}, {0u, 0u, 0u, 0u},
{225u, 218u, 217u, 0u}, {195u, 182u, 179u, 0u}, {165u, 145u, 141u, 0u}, {134u, 108u, 102u, 0u},
{104u, 72u, 64u, 0u}, {74u, 35u, 26u, 0u}, {59u, 28u, 21u, 0u}, {44u, 21u, 16u, 0u},
{30u, 14u, 10u, 0u}, {15u, 7u, 5u, 0u}, {250u, 231u, 232u, 0u}, {240u, 185u, 189u, 0u},
{233u, 154u, 160u, 0u}, {226u, 124u, 131u, 0u}, {219u, 93u, 102u, 0u}, {213u, 62u, 73u, 0u},
{203u, 18u, 32u, 0u}, {172u, 15u, 27u, 0u}, {159u, 14u, 25u, 0u}, {146u, 13u, 23u, 0u},
{133u, 12u, 21u, 0u}, {120u, 11u, 19u, 0u}, {107u, 10u, 17u, 0u}, {94u, 8u, 15u, 0u},
{81u, 7u, 13u, 0u}, {68u, 6u, 11u, 0u}, {55u, 5u, 9u, 0u}, {42u, 4u, 7u, 0u},
{29u, 3u, 5u, 0u}, {10u, 1u, 2u, 0u}, {227u, 236u, 242u, 0u}, {178u, 203u, 220u, 0u},
{145u, 181u, 205u, 0u}, {112u, 159u, 191u, 0u}, {79u, 137u, 176u, 0u}, {30u, 104u, 154u, 0u},
{0u, 84u, 140u, 0u}, {0u, 79u, 132u, 0u}, {0u, 72u, 119u, 0u}, {0u, 66u, 110u, 0u},
{0u, 61u, 101u, 0u}, {0u, 55u, 92u, 0u}, {0u, 47u, 78u, 0u}, {0u, 39u, 65u, 0u},
{0u, 34u, 56u, 0u}, {0u, 28u, 47u, 0u}, {0u, 23u, 38u, 0u}, {0u, 18u, 29u, 0u},
{0u, 12u, 20u, 0u}, {0u, 4u, 7u, 0u}, {230u, 242u, 234u, 0u}, {180u, 215u, 193u, 0u},
{147u, 198u, 166u, 0u}, {113u, 180u, 138u, 0u}, {80u, 162u, 111u, 0u}, {30u, 136u, 70u, 0u},
{0u, 120u, 45u, 0u}, {0u, 114u, 43u, 0u}, {0u, 102u, 38u, 0u}, {0u, 95u, 35u, 0u},
{0u, 83u, 31u, 0u}, {0u, 72u, 27u, 0u}, {0u, 63u, 24u, 0u}, {0u, 56u, 21u, 0u},
{0u, 48u, 18u, 0u}, {0u, 36u, 14u, 0u}, {0u, 25u, 9u, 0u}, {0u, 17u, 6u, 0u},
{0u, 9u, 3u, 0u}, {0u, 1u, 1u, 0u}, {254u, 244u, 220u, 0u}, {255u, 239u, 181u, 0u},
{255u, 231u, 156u, 0u}, {255u, 222u, 132u, 0u}, {255u, 222u, 115u, 0u}, {255u, 214u, 99u, 0u},
{255u, 206u, 66u, 0u}, {255u, 198u, 41u, 0u}, {255u, 185u, 0u, 0u}, {255u, 189u, 8u, 0u},
{247u, 181u, 0u, 0u}, {222u, 156u, 0u, 0u}, {189u, 140u, 0u, 0u}, {173u, 123u, 0u, 0u},
{148u, 107u, 0u, 0u}, {132u, 90u, 0u, 0u}, {107u, 74u, 0u, 0u}, {74u, 49u, 0u, 0u},
{57u, 41u, 0u, 0u}, {33u, 24u, 0u, 0u}, {117u, 52u, 87u, 0u}, {176u, 158u, 50u, 0u},
{122u, 165u, 29u, 0u}, {242u, 142u, 8u, 0u}, {164u, 43u, 36u, 0u}, {113u, 67u, 20u, 0u},
{255u, 0u, 255u, 0u}, {255u, 0u, 255u, 0u}, {255u, 0u, 255u, 0u}, {255u, 0u, 255u, 0u},
{255u, 0u, 255u, 0u}, {57u, 163u, 217u, 0u}, {255u, 255u, 255u, 0u}, {254u, 255u, 247u, 0u},
{253u, 253u, 239u, 0u}, {248u, 247u, 247u, 0u}, {248u, 247u, 231u, 0u}, {240u, 240u, 240u, 0u},
{239u, 239u, 218u, 0u}, {227u, 232u, 236u, 0u}, {224u, 221u, 209u, 0u}, {215u, 222u, 215u, 0u},
{213u, 214u, 215u, 0u}, {214u, 214u, 203u, 0u}, {255u, 219u, 57u, 0u}, {206u, 206u, 206u, 0u},
{206u, 206u, 198u, 0u}, {255u, 214u, 18u, 0u}, {207u, 203u, 186u, 0u}, {197u, 199u, 199u, 0u},
{255u, 206u, 0u, 0u}, {207u, 198u, 159u, 0u}, {247u, 204u, 0u, 0u}, {189u, 198u, 189u, 0u},
{189u, 189u, 189u, 0u}, {238u, 199u, 0u, 0u}, {189u, 189u, 181u, 0u}, {238u, 190u, 24u, 0u},
{181u, 189u, 184u, 0u}, {161u, 186u, 224u, 0u}, {181u, 181u, 181u, 0u}, {231u, 189u, 0u, 0u},
{173u, 182u, 173u, 0u}, {222u, 181u, 0u, 0u}, {173u, 173u, 173u, 0u}, {213u, 182u, 0u, 0u},
{172u, 173u, 160u, 0u}, {214u, 173u, 0u, 0u}, {165u, 165u, 165u, 0u}, {206u, 173u, 0u, 0u},
{160u, 168u, 151u, 0u}, {206u, 164u, 0u, 0u}, {198u, 165u, 0u, 0u}, {157u, 156u, 156u, 0u},
{134u, 156u, 200u, 0u}, {153u, 156u, 144u, 0u}, {142u, 156u, 161u, 0u}, {189u, 156u, 0u, 0u},
{148u, 148u, 148u, 0u}, {146u, 148u, 138u, 0u}, {133u, 143u, 161u, 0u}, {189u, 143u, 0u, 0u},
{140u, 140u, 140u, 0u}, {177u, 147u, 0u, 0u}, {131u, 140u, 136u, 0u}, {146u, 130u, 126u, 0u},
{170u, 137u, 0u, 0u}, {132u, 132u, 130u, 0u}, {123u, 125u, 125u, 0u}, {123u, 123u, 133u, 0u},
{153u, 126u, 0u, 0u}, {114u, 116u, 118u, 0u}, {110u, 112u, 108u, 0u}, {97u, 109u, 136u, 0u},
{127u, 108u, 6u, 0u}, {0u, 173u, 0u, 0u}, {100u, 99u, 101u, 0u}, {176u, 71u, 41u, 0u},
{36u, 142u, 33u, 0u}, {98u, 91u, 75u, 0u}, {80u, 88u, 104u, 0u}, {252u, 0u, 0u, 0u},
{78u, 71u, 73u, 0u}, {73u, 71u, 78u, 0u}, {62u, 63u, 61u, 0u}, {0u, 66u, 211u, 0u},
{99u, 51u, 14u, 0u}, {198u, 0u, 0u, 0u}, {189u, 0u, 0u, 0u}, {0u, 57u, 206u, 0u},
{181u, 0u, 0u, 0u}, {0u, 56u, 185u, 0u}, {173u, 0u, 0u, 0u}, {165u, 0u, 0u, 0u},
{49u, 49u, 49u, 0u}, {0u, 49u, 165u, 0u}, {156u, 0u, 0u, 0u}, {42u, 45u, 60u, 0u},
{148u, 0u, 0u, 0u}, {140u, 0u, 0u, 0u}, {41u, 41u, 41u, 0u}, {0u, 41u, 144u, 0u},
{132u, 0u, 0u, 0u}, {123u, 0u, 0u, 0u}, {7u, 35u, 114u, 0u}, {34u, 36u, 32u, 0u},
{115u, 0u, 0u, 0u}, {107u, 0u, 0u, 0u}, {90u, 0u, 0u, 0u}, {23u, 24u, 27u, 0u},
{74u, 0u, 0u, 0u}, {15u, 15u, 16u, 0u}, {49u, 0u, 0u, 0u}, {16u, 12u, 4u, 0u},
{7u, 8u, 8u, 0u}, {0u, 0u, 8u, 0u}, {255u, 251u, 240u, 0u}, {160u, 160u, 164u, 0u},
{128u, 128u, 128u, 0u}, {255u, 0u, 0u, 0u}, {0u, 255u, 0u, 0u}, {255u, 255u, 0u, 0u},
{0u, 0u, 255u, 0u}, {255u, 0u, 255u, 0u}, {0u, 255u, 255u, 0u}, {255u, 255u, 255u, 0u}
};
// FUNCTION: LEGO1 0x100bee30
MxPalette::MxPalette()
{
this->m_overrideSkyColor = FALSE;
this->m_palette = NULL;
GetDefaultPalette(this->m_entries);
this->m_skyColor = this->m_entries[141];
}
// FUNCTION: LEGO1 0x100beed0
MxPalette::MxPalette(const RGBQUAD* p_colors)
{
this->m_overrideSkyColor = FALSE;
this->m_palette = NULL;
ApplySystemEntriesToPalette(this->m_entries);
for (MxS32 i = 10; i < 246; i++) {
this->m_entries[i].peRed = p_colors[i].rgbRed;
this->m_entries[i].peGreen = p_colors[i].rgbGreen;
this->m_entries[i].peBlue = p_colors[i].rgbBlue;
this->m_entries[i].peFlags = 0;
}
this->m_skyColor = this->m_entries[141];
}
// FUNCTION: LEGO1 0x100bef90
MxPalette::~MxPalette()
{
if (m_palette) {
m_palette->Release();
}
}
// FUNCTION: LEGO1 0x100bf000
LPDIRECTDRAWPALETTE MxPalette::CreateNativePalette()
{
MxS32 i;
if (this->m_palette == NULL) {
for (i = 0; i < 10; i++)
this->m_entries[i].peFlags = 0x80;
for (i = 10; i < 136; i++)
this->m_entries[i].peFlags = 0x44;
for (i = 136; i < 140; i++)
this->m_entries[i].peFlags = 0x84;
this->m_entries[140].peFlags = 0x84;
this->m_entries[141].peFlags = 0x44;
for (i = 142; i < 246; i++)
this->m_entries[i].peFlags = 0x84;
for (i = 246; i < 256; i++)
this->m_entries[i].peFlags = 0x80;
if (MVideoManager() && MVideoManager()->GetDirectDraw()) {
MVideoManager()->GetDirectDraw()->CreatePalette(4, this->m_entries, &this->m_palette, NULL);
}
}
return this->m_palette;
}
// FUNCTION: LEGO1 0x100bf0b0
MxPalette* MxPalette::Clone()
{
MxPalette* result = new MxPalette;
this->GetEntries(result->m_entries);
result->m_overrideSkyColor = this->m_overrideSkyColor;
return result;
}
// FUNCTION: LEGO1 0x100bf150
MxResult MxPalette::GetEntries(LPPALETTEENTRY p_entries)
{
memcpy(p_entries, this->m_entries, sizeof(this->m_entries));
return SUCCESS;
}
// FUNCTION: LEGO1 0x100bf170
MxResult MxPalette::SetEntries(LPPALETTEENTRY p_entries)
{
MxS32 i;
MxResult status = SUCCESS;
if (this->m_palette) {
for (i = 0; i < 10; i++)
this->m_entries[i].peFlags = 0x80;
for (i = 10; i < 136; i++) {
this->m_entries[i].peFlags = 68;
this->m_entries[i].peRed = p_entries[i].peRed;
this->m_entries[i].peGreen = p_entries[i].peGreen;
this->m_entries[i].peBlue = p_entries[i].peBlue;
}
for (i = 136; i < 140; i++) {
this->m_entries[i].peFlags = 132;
this->m_entries[i].peRed = p_entries[i].peRed;
this->m_entries[i].peGreen = p_entries[i].peGreen;
this->m_entries[i].peBlue = p_entries[i].peBlue;
}
if (!this->m_overrideSkyColor) {
this->m_entries[140].peFlags = 0x44;
this->m_entries[140].peRed = p_entries[140].peRed;
this->m_entries[140].peGreen = p_entries[140].peGreen;
this->m_entries[140].peBlue = p_entries[140].peBlue;
this->m_entries[141].peFlags = 0x84;
this->m_entries[141].peRed = p_entries[141].peRed;
this->m_entries[141].peGreen = p_entries[141].peGreen;
this->m_entries[141].peBlue = p_entries[141].peBlue;
}
for (i = 142; i < 246; i++) {
this->m_entries[i].peFlags = 132;
this->m_entries[i].peRed = p_entries[i].peRed;
this->m_entries[i].peGreen = p_entries[i].peGreen;
this->m_entries[i].peBlue = p_entries[i].peBlue;
}
for (i = 246; i < 256; i++)
this->m_entries[i].peFlags = 0x80;
if (this->m_palette->SetEntries(0, 0, 256, this->m_entries))
status = FAILURE;
}
return status;
}
// FUNCTION: LEGO1 0x100bf2d0
MxResult MxPalette::SetSkyColor(LPPALETTEENTRY p_skyColor)
{
MxResult status = 0;
if (this->m_palette != NULL) {
this->m_entries[141].peRed = p_skyColor->peRed;
this->m_entries[141].peGreen = p_skyColor->peGreen;
this->m_entries[141].peBlue = p_skyColor->peBlue;
this->m_skyColor = this->m_entries[141];
if (this->m_palette->SetEntries(0, 141, 1, &this->m_skyColor)) {
status = -1;
}
}
return status;
}
// FUNCTION: LEGO1 0x100bf330
void MxPalette::Detach()
{
this->m_palette = NULL;
}
// FUNCTION: LEGO1 0x100bf340
MxBool MxPalette::operator==(MxPalette& p_other)
{
for (MxS32 i = 0; i < 256; i++) {
if (this->m_entries[i].peRed != p_other.m_entries[i].peRed)
return FALSE;
if (this->m_entries[i].peGreen != p_other.m_entries[i].peGreen)
return FALSE;
if (this->m_entries[i].peBlue != p_other.m_entries[i].peBlue)
return FALSE;
}
return TRUE;
}
// FUNCTION: LEGO1 0x100bf390
void MxPalette::ApplySystemEntriesToPalette(LPPALETTEENTRY p_entries)
{
HDC hdc;
hdc = GetDC(0);
if ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) != 0 && GetDeviceCaps(hdc, SIZEPALETTE) == 256) {
GetSystemPaletteEntries(hdc, 0, 10, p_entries);
GetSystemPaletteEntries(hdc, 246, 10, &p_entries[246]);
}
else {
memcpy(p_entries, g_defaultPaletteEntries, sizeof(PALETTEENTRY) * 10);
memcpy(&p_entries[246], &g_defaultPaletteEntries[246], sizeof(PALETTEENTRY) * 10);
}
ReleaseDC(0, hdc);
}
// FUNCTION: LEGO1 0x100bf420
void MxPalette::GetDefaultPalette(LPPALETTEENTRY p_entries)
{
HDC hdc;
hdc = GetDC(0);
if ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) != 0 && GetDeviceCaps(hdc, SIZEPALETTE) == 256) {
GetSystemPaletteEntries(hdc, 0, 256, p_entries);
memcpy(&p_entries[10], &g_defaultPaletteEntries[10], sizeof(PALETTEENTRY) * 236);
}
else {
memcpy(p_entries, g_defaultPaletteEntries, sizeof(PALETTEENTRY) * 256);
}
ReleaseDC(0, hdc);
}
// FUNCTION: LEGO1 0x100bf490
void MxPalette::Reset(MxBool p_ignoreSkyColor)
{
if (this->m_palette != NULL) {
GetDefaultPalette(this->m_entries);
if (!p_ignoreSkyColor) {
this->m_entries[140] = this->m_entries[141] = this->m_skyColor;
}
SetEntries(this->m_entries);
this->m_palette->SetEntries(0, 0, 256, this->m_entries);
}
}

View File

@@ -0,0 +1,197 @@
#include "mxregion.h"
#include <limits.h>
DECOMP_SIZE_ASSERT(MxRegion, 0x1c);
DECOMP_SIZE_ASSERT(MxRegionTopBottom, 0x0c);
DECOMP_SIZE_ASSERT(MxRegionLeftRight, 0x08);
// FUNCTION: LEGO1 0x100c31c0
MxRegion::MxRegion()
{
m_list = new MxRegionTopBottomList;
m_rect = MxRect32(INT_MAX, INT_MAX, -1, -1);
}
// FUNCTION: LEGO1 0x100c3660
MxBool MxRegion::VTable0x20()
{
return m_list->GetCount() == 0;
}
// FUNCTION: LEGO1 0x100c3690
MxRegion::~MxRegion()
{
if (m_list)
delete m_list;
}
// FUNCTION: LEGO1 0x100c3700
void MxRegion::Reset()
{
m_list->DeleteAll();
m_rect = MxRect32(INT_MAX, INT_MAX, -1, -1);
}
// FUNCTION: LEGO1 0x100c3750
void MxRegion::VTable0x18(MxRect32& p_rect)
{
MxRect32 rect(p_rect);
MxRect32 newRect;
MxRegionTopBottomListCursor cursor(m_list);
MxRegionTopBottom* topBottom;
while (rect.IsValid() && cursor.Next(topBottom)) {
if (topBottom->GetTop() >= rect.GetBottom()) {
MxRegionTopBottom* newTopBottom = new MxRegionTopBottom(rect);
cursor.Prepend(newTopBottom);
rect.SetTop(rect.GetBottom());
}
else if (rect.GetTop() < topBottom->GetBottom()) {
if (rect.GetTop() < topBottom->GetTop()) {
newRect = rect;
newRect.SetBottom(topBottom->GetTop());
MxRegionTopBottom* newTopBottom = new MxRegionTopBottom(newRect);
cursor.Prepend(newTopBottom);
rect.SetTop(topBottom->GetTop());
}
else if (topBottom->GetTop() < rect.GetTop()) {
MxRegionTopBottom* newTopBottom = topBottom->Clone();
newTopBottom->SetBottom(rect.GetTop());
topBottom->SetTop(rect.GetTop());
cursor.Prepend(newTopBottom);
}
if (rect.GetBottom() < topBottom->GetBottom()) {
MxRegionTopBottom* newTopBottom = topBottom->Clone();
newTopBottom->SetBottom(rect.GetBottom());
topBottom->SetTop(rect.GetBottom());
newTopBottom->FUN_100c5280(rect.GetLeft(), rect.GetRight());
cursor.Prepend(newTopBottom);
rect.SetTop(rect.GetBottom());
}
else {
topBottom->FUN_100c5280(rect.GetLeft(), rect.GetRight());
rect.SetTop(topBottom->GetBottom());
}
}
}
if (rect.IsValid()) {
MxRegionTopBottom* newTopBottom = new MxRegionTopBottom(rect);
m_list->Append(newTopBottom);
}
m_rect.UpdateBounds(p_rect);
}
// FUNCTION: LEGO1 0x100c3e20
MxBool MxRegion::VTable0x1c(MxRect32& p_rect)
{
if (!m_rect.IntersectsWith(p_rect))
return FALSE;
MxRegionTopBottomListCursor cursor(m_list);
MxRegionTopBottom* topBottom;
while (cursor.Next(topBottom)) {
if (topBottom->GetTop() >= p_rect.GetBottom())
return FALSE;
if (topBottom->GetBottom() > p_rect.GetTop() && topBottom->FUN_100c57b0(p_rect))
return TRUE;
}
return FALSE;
}
// FUNCTION: LEGO1 0x100c4c90
MxRegionTopBottom::MxRegionTopBottom(MxS32 p_top, MxS32 p_bottom)
{
m_top = p_top;
m_bottom = p_bottom;
m_leftRightList = new MxRegionLeftRightList;
}
// FUNCTION: LEGO1 0x100c50e0
MxRegionTopBottom::MxRegionTopBottom(MxRect32& p_rect)
{
m_top = p_rect.GetTop();
m_bottom = p_rect.GetBottom();
m_leftRightList = new MxRegionLeftRightList;
MxRegionLeftRight* leftRight = new MxRegionLeftRight(p_rect.GetLeft(), p_rect.GetRight());
m_leftRightList->Append(leftRight);
}
// FUNCTION: LEGO1 0x100c5280
void MxRegionTopBottom::FUN_100c5280(MxS32 p_left, MxS32 p_right)
{
MxRegionLeftRightListCursor a(m_leftRightList);
MxRegionLeftRightListCursor b(m_leftRightList);
MxRegionLeftRight* leftRight;
while (a.Next(leftRight) && leftRight->GetRight() < p_left)
;
if (!a.HasMatch()) {
MxRegionLeftRight* copy = new MxRegionLeftRight(p_left, p_right);
m_leftRightList->Append(copy);
}
else {
if (p_left > leftRight->GetLeft())
p_left = leftRight->GetLeft();
while (leftRight->GetLeft() < p_right) {
if (p_right < leftRight->GetRight())
p_right = leftRight->GetRight();
b = a;
b.Next();
a.Destroy();
if (!b.Current(leftRight))
break;
a = b;
}
if (a.HasMatch()) {
MxRegionLeftRight* copy = new MxRegionLeftRight(p_left, p_right);
a.Prepend(copy);
}
else {
MxRegionLeftRight* copy = new MxRegionLeftRight(p_left, p_right);
m_leftRightList->Append(copy);
}
}
}
// FUNCTION: LEGO1 0x100c55d0
MxRegionTopBottom* MxRegionTopBottom::Clone()
{
MxRegionTopBottom* clone = new MxRegionTopBottom(m_top, m_bottom);
MxRegionLeftRightListCursor cursor(m_leftRightList);
MxRegionLeftRight* leftRight;
while (cursor.Next(leftRight))
clone->m_leftRightList->Append(leftRight->Clone());
return clone;
}
// FUNCTION: LEGO1 0x100c57b0
MxBool MxRegionTopBottom::FUN_100c57b0(MxRect32& p_rect)
{
MxRegionLeftRightListCursor cursor(m_leftRightList);
MxRegionLeftRight* leftRight;
while (cursor.Next(leftRight)) {
if (p_rect.GetRight() <= leftRight->GetLeft())
return FALSE;
if (leftRight->GetRight() > p_rect.GetLeft())
return TRUE;
}
return FALSE;
}

View File

@@ -0,0 +1,284 @@
#include "mxregioncursor.h"
DECOMP_SIZE_ASSERT(MxRegionCursor, 0x18);
// FUNCTION: LEGO1 0x100c3f70
MxRegionCursor::MxRegionCursor(MxRegion* p_region)
{
m_region = p_region;
m_rect = NULL;
m_topBottomCursor = new MxRegionTopBottomListCursor(m_region->m_list);
m_leftRightCursor = NULL;
}
// FUNCTION: LEGO1 0x100c40b0
MxRegionCursor::~MxRegionCursor()
{
if (m_rect)
delete m_rect;
if (m_topBottomCursor)
delete m_topBottomCursor;
if (m_leftRightCursor)
delete m_leftRightCursor;
}
// FUNCTION: LEGO1 0x100c4140
MxRect32* MxRegionCursor::VTable0x18()
{
m_topBottomCursor->Head();
MxRegionTopBottom* topBottom;
if (m_topBottomCursor->Current(topBottom)) {
FUN_100c46c0(*topBottom->m_leftRightList);
MxRegionLeftRight* leftRight;
m_leftRightCursor->First(leftRight);
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
}
else
Reset();
return m_rect;
}
// FUNCTION: LEGO1 0x100c41d0
MxRect32* MxRegionCursor::VTable0x20()
{
m_topBottomCursor->Tail();
MxRegionTopBottom* topBottom;
if (m_topBottomCursor->Current(topBottom)) {
FUN_100c46c0(*topBottom->m_leftRightList);
MxRegionLeftRight* leftRight;
m_leftRightCursor->Last(leftRight);
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
}
else
Reset();
return m_rect;
}
// FUNCTION: LEGO1 0x100c4260
MxRect32* MxRegionCursor::VTable0x28()
{
MxRegionLeftRight* leftRight;
MxRegionTopBottom* topBottom;
if (m_leftRightCursor && m_leftRightCursor->Next(leftRight)) {
m_topBottomCursor->Current(topBottom);
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
return m_rect;
}
if (m_topBottomCursor->Next(topBottom)) {
FUN_100c46c0(*topBottom->m_leftRightList);
m_leftRightCursor->First(leftRight);
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
return m_rect;
}
Reset();
return m_rect;
}
// FUNCTION: LEGO1 0x100c4360
MxRect32* MxRegionCursor::VTable0x30()
{
MxRegionLeftRight* leftRight;
MxRegionTopBottom* topBottom;
if (m_leftRightCursor && m_leftRightCursor->Prev(leftRight)) {
m_topBottomCursor->Current(topBottom);
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
return m_rect;
}
if (m_topBottomCursor->Prev(topBottom)) {
FUN_100c46c0(*topBottom->m_leftRightList);
m_leftRightCursor->Last(leftRight);
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
return m_rect;
}
Reset();
return m_rect;
}
// FUNCTION: LEGO1 0x100c4460
MxRect32* MxRegionCursor::VTable0x14(MxRect32& p_rect)
{
m_topBottomCursor->Reset();
FUN_100c4a20(p_rect);
return m_rect;
}
// FUNCTION: LEGO1 0x100c4480
MxRect32* MxRegionCursor::VTable0x1c(MxRect32& p_rect)
{
m_topBottomCursor->Reset();
FUN_100c4b50(p_rect);
return m_rect;
}
// FUNCTION: LEGO1 0x100c44a0
MxRect32* MxRegionCursor::VTable0x24(MxRect32& p_rect)
{
MxRegionLeftRight* leftRight;
if (m_leftRightCursor && m_leftRightCursor->Next(leftRight)) {
MxRegionTopBottom* topBottom;
m_topBottomCursor->Current(topBottom);
if (topBottom->IntersectsWith(p_rect) && leftRight->IntersectsWith(p_rect)) {
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
m_rect->Intersect(p_rect);
}
else
FUN_100c4a20(p_rect);
}
else
FUN_100c4a20(p_rect);
return m_rect;
}
// FUNCTION: LEGO1 0x100c4590
MxRect32* MxRegionCursor::VTable0x2c(MxRect32& p_rect)
{
MxRegionLeftRight* leftRight;
if (m_leftRightCursor && m_leftRightCursor->Prev(leftRight)) {
MxRegionTopBottom* topBottom;
m_topBottomCursor->Current(topBottom);
if (topBottom->IntersectsWith(p_rect) && leftRight->IntersectsWith(p_rect)) {
UpdateRect(leftRight->GetLeft(), topBottom->GetTop(), leftRight->GetRight(), topBottom->GetBottom());
m_rect->Intersect(p_rect);
}
else
FUN_100c4b50(p_rect);
}
else
FUN_100c4b50(p_rect);
return m_rect;
}
// FUNCTION: LEGO1 0x100c4680
void MxRegionCursor::Reset()
{
if (m_rect) {
delete m_rect;
m_rect = NULL;
}
m_topBottomCursor->Reset();
if (m_leftRightCursor) {
delete m_leftRightCursor;
m_leftRightCursor = NULL;
}
}
// FUNCTION: LEGO1 0x100c46c0
void MxRegionCursor::FUN_100c46c0(MxRegionLeftRightList& p_leftRightList)
{
if (m_leftRightCursor)
delete m_leftRightCursor;
m_leftRightCursor = new MxRegionLeftRightListCursor(&p_leftRightList);
}
// FUNCTION: LEGO1 0x100c4980
void MxRegionCursor::UpdateRect(MxS32 p_left, MxS32 p_top, MxS32 p_right, MxS32 p_bottom)
{
if (!m_rect)
m_rect = new MxRect32;
m_rect->SetLeft(p_left);
m_rect->SetTop(p_top);
m_rect->SetRight(p_right);
m_rect->SetBottom(p_bottom);
}
// FUNCTION: LEGO1 0x100c4a20
void MxRegionCursor::FUN_100c4a20(MxRect32& p_rect)
{
MxRegionTopBottom* topBottom;
while (m_topBottomCursor->Next(topBottom)) {
if (p_rect.GetBottom() <= topBottom->GetTop()) {
Reset();
return;
}
if (p_rect.GetTop() < topBottom->GetBottom()) {
FUN_100c46c0(*topBottom->m_leftRightList);
MxRegionLeftRight* leftRight;
while (m_leftRightCursor->Next(leftRight)) {
if (p_rect.GetRight() <= leftRight->GetLeft())
break;
if (p_rect.GetLeft() < leftRight->GetRight()) {
UpdateRect(
leftRight->GetLeft(),
topBottom->GetTop(),
leftRight->GetRight(),
topBottom->GetBottom()
);
m_rect->Intersect(p_rect);
return;
}
}
}
}
Reset();
}
// FUNCTION: LEGO1 0x100c4b50
void MxRegionCursor::FUN_100c4b50(MxRect32& p_rect)
{
MxRegionTopBottom* topBottom;
while (m_topBottomCursor->Prev(topBottom)) {
if (topBottom->GetBottom() <= p_rect.GetTop()) {
Reset();
return;
}
if (topBottom->GetTop() < p_rect.GetBottom()) {
FUN_100c46c0(*topBottom->m_leftRightList);
MxRegionLeftRight* leftRight;
while (m_leftRightCursor->Prev(leftRight)) {
if (leftRight->GetRight() <= p_rect.GetLeft())
break;
if (leftRight->GetLeft() < p_rect.GetRight()) {
UpdateRect(
leftRight->GetLeft(),
topBottom->GetTop(),
leftRight->GetRight(),
topBottom->GetBottom()
);
m_rect->Intersect(p_rect);
return;
}
}
}
}
Reset();
}

View File

@@ -0,0 +1,252 @@
#include "mxsmack.h"
#include <string.h>
DECOMP_SIZE_ASSERT(SmackTag, 0x390);
DECOMP_SIZE_ASSERT(MxSmack, 0x6b8);
// FUNCTION: LEGO1 0x100c5a90
MxResult MxSmack::LoadHeader(MxU8* p_data, MxSmack* p_mxSmack)
{
// Macros for readability
#define FRAME_COUNT(mxSmack) (p_mxSmack->m_smackTag.Frames + (p_mxSmack->m_smackTag.SmackerType & 1))
MxResult result = SUCCESS;
MxU8* frameTypes = NULL;
MxU8* huffmanTrees = NULL;
if (!p_data || !p_mxSmack) {
result = FAILURE;
}
else {
p_mxSmack->m_frameTypes = NULL;
p_mxSmack->m_frameSizes = NULL;
p_mxSmack->m_huffmanTrees = NULL;
p_mxSmack->m_huffmanTables = NULL;
memcpy(&p_mxSmack->m_smackTag, p_data, SmackHeaderSize(&p_mxSmack->m_smackTag));
p_data += SmackHeaderSize(&p_mxSmack->m_smackTag);
MxU32* frameSizes = new MxU32[FRAME_COUNT(p_mxSmack)];
if (!frameSizes) {
result = FAILURE;
}
else {
memcpy(frameSizes, p_data, FRAME_COUNT(p_mxSmack) * sizeof(MxU32));
p_data += FRAME_COUNT(p_mxSmack) * sizeof(MxU32);
p_mxSmack->m_maxFrameSize = 0;
// TODO
for (MxU32 i = 0; i < FRAME_COUNT(p_mxSmack); i++) {
if (p_mxSmack->m_maxFrameSize < frameSizes[i])
p_mxSmack->m_maxFrameSize = frameSizes[i];
}
frameTypes = new MxU8[FRAME_COUNT(p_mxSmack)];
if (!frameTypes) {
result = FAILURE;
}
else {
memcpy(frameTypes, p_data, FRAME_COUNT(p_mxSmack));
p_data += FRAME_COUNT(p_mxSmack);
MxU32 treeSize = p_mxSmack->m_smackTag.tablesize + 0x1000;
if (treeSize <= 0x2000)
treeSize = 0x2000;
huffmanTrees = new MxU8[treeSize];
if (!huffmanTrees) {
result = FAILURE;
}
else {
memcpy(huffmanTrees + 0x1000, p_data, p_mxSmack->m_smackTag.tablesize);
p_mxSmack->m_huffmanTables = new MxU8
[p_mxSmack->m_smackTag.codesize + p_mxSmack->m_smackTag.absize +
p_mxSmack->m_smackTag.detailsize + p_mxSmack->m_smackTag.typesize + SmackGetSizeTables()];
if (!p_mxSmack->m_huffmanTables) {
result = FAILURE;
}
else {
SmackDoTables(
huffmanTrees,
p_mxSmack->m_huffmanTables,
p_mxSmack->m_smackTag.codesize,
p_mxSmack->m_smackTag.absize,
p_mxSmack->m_smackTag.detailsize,
p_mxSmack->m_smackTag.typesize
);
MxU32 size = SmackGetSizeDeltas(p_mxSmack->m_smackTag.Width, p_mxSmack->m_smackTag.Height) + 32;
p_mxSmack->m_unk0x6b4 = new MxU8[size];
memset(p_mxSmack->m_unk0x6b4, 0, size);
MxS32 width = p_mxSmack->m_smackTag.Width;
MxU32* data = (MxU32*) p_mxSmack->m_unk0x6b4;
*data = 1;
data++;
*data = NULL; // MxU8* bitmapData
data++;
*data = p_mxSmack->m_smackTag.Width / 4;
data++;
*data = p_mxSmack->m_smackTag.Height / 4;
data++;
*data = width - 4;
data++;
*data = width * 3;
data++;
*data = width;
data++;
*data = width * 4 - p_mxSmack->m_smackTag.Width;
data++;
data++;
*data = p_mxSmack->m_smackTag.Width;
data++;
*data = p_mxSmack->m_smackTag.Height;
}
}
}
}
p_mxSmack->m_frameTypes = frameTypes;
p_mxSmack->m_frameSizes = frameSizes;
p_mxSmack->m_huffmanTrees = huffmanTrees;
}
return result;
#undef FRAME_COUNT
}
// FUNCTION: LEGO1 0x100c5d40
void MxSmack::Destroy(MxSmack* p_mxSmack)
{
if (p_mxSmack->m_frameSizes)
delete[] p_mxSmack->m_frameSizes;
if (p_mxSmack->m_frameTypes)
delete[] p_mxSmack->m_frameTypes;
if (p_mxSmack->m_huffmanTrees)
delete[] p_mxSmack->m_huffmanTrees;
if (p_mxSmack->m_huffmanTables)
delete[] p_mxSmack->m_huffmanTables;
if (p_mxSmack->m_unk0x6b4)
delete[] p_mxSmack->m_unk0x6b4;
}
// This should be refactored to somewhere else
inline MxLong AbsFlipped(MxLong p_value)
{
return p_value > 0 ? p_value : -p_value;
}
// FUNCTION: LEGO1 0x100c5db0
MxResult MxSmack::LoadFrame(
MxBITMAPINFO* p_bitmapInfo,
MxU8* p_bitmapData,
MxSmack* p_mxSmack,
MxU8* p_chunkData,
MxBool p_paletteChanged,
MxRectList* p_list
)
{
p_bitmapInfo->m_bmiHeader.biHeight = -AbsFlipped(p_bitmapInfo->m_bmiHeader.biHeight);
*(MxU8**) (p_mxSmack->m_unk0x6b4 + 4) = p_bitmapData;
// Reference: https://wiki.multimedia.cx/index.php/Smacker#Palette_Chunk
if (p_paletteChanged) {
MxU8 palette[772];
MxU8* intoChunk = p_chunkData + 1;
MxU8* intoPalette = palette;
MxU16 paletteIndex = 0;
// TODO: struct incorrect, Palette at wrong offset?
MxU8* currentPalette = &p_mxSmack->m_smackTag.Palette[4];
do {
if (*intoChunk & 0x80) {
MxU8 length = (*intoChunk & 0x7f) + 1;
memcpy(intoPalette, &currentPalette[paletteIndex * 3], length * 3);
intoPalette += length * 3;
paletteIndex += length;
intoChunk++;
}
else {
if (*intoChunk & 0x40) {
MxU8 length = (*intoChunk & 0x3f) + 1;
memcpy(intoPalette, &currentPalette[*(intoChunk + 1) * 3], length * 3);
intoPalette += length * 3;
paletteIndex += length;
intoChunk += 2;
}
else {
*(MxU32*) intoPalette = *(MxU32*) intoChunk;
intoPalette += 3;
paletteIndex++;
intoChunk += 3;
}
}
} while (paletteIndex < 256);
for (MxU32 i = 0; i < 256; i++) {
memcpy(currentPalette, &palette[i * 3], 3);
currentPalette += 3;
p_bitmapInfo->m_bmiColors[i].rgbBlue = palette[i * 3 + 2] * 4;
p_bitmapInfo->m_bmiColors[i].rgbGreen = palette[i * 3 + 1] * 4;
p_bitmapInfo->m_bmiColors[i].rgbRed = palette[i * 3] * 4;
}
p_chunkData += *p_chunkData * 4;
}
SmackDoFrameToBuffer(p_chunkData, p_mxSmack->m_huffmanTables, p_mxSmack->m_unk0x6b4);
MxU16 und = 1;
u32 smackRect[4];
MxRect32 rect;
while (GetRect(p_mxSmack->m_unk0x6b4, &und, smackRect, &rect)) {
MxRect32* newRect = new MxRect32(rect);
p_list->Append(newRect);
}
return SUCCESS;
}
// FUNCTION: LEGO1 0x100c6050
MxBool MxSmack::GetRect(MxU8* p_unk0x6b4, MxU16* p_und, u32* p_smackRect, MxRect32* p_rect)
{
u32 left, bottom, top, right;
if (!*p_und)
return FALSE;
if (*p_und == 1) {
if (!SmackGetRect(p_unk0x6b4, p_smackRect))
return FALSE;
*p_und = 2;
}
left = p_smackRect[0];
top = p_smackRect[1];
right = p_smackRect[2] + p_smackRect[0];
bottom = p_smackRect[3] + p_smackRect[1];
while (SmackGetRect(p_unk0x6b4, p_smackRect)) {
if (left > p_smackRect[0])
left = p_smackRect[0];
if (right < p_smackRect[0] + p_smackRect[2])
right = p_smackRect[0] + p_smackRect[2];
bottom = p_smackRect[1] + p_smackRect[3];
}
*p_und = 0;
*p_rect = MxRect32(left, top, right, bottom);
return TRUE;
}

View File

@@ -0,0 +1,124 @@
#include "mxsmkpresenter.h"
#include "decomp.h"
#include "mxdsmediaaction.h"
#include "mxvideomanager.h"
DECOMP_SIZE_ASSERT(MxSmkPresenter, 0x720);
// FUNCTION: LEGO1 0x100b3650
MxSmkPresenter::MxSmkPresenter()
{
Init();
}
// FUNCTION: LEGO1 0x100b3870
MxSmkPresenter::~MxSmkPresenter()
{
Destroy(TRUE);
}
// FUNCTION: LEGO1 0x100b38d0
void MxSmkPresenter::Init()
{
m_currentFrame = 0;
memset(&m_mxSmack, 0, sizeof(m_mxSmack));
m_flags &= ~Flag_Bit2;
m_flags &= ~Flag_Bit3;
}
// FUNCTION: LEGO1 0x100b3900
void MxSmkPresenter::Destroy(MxBool p_fromDestructor)
{
m_criticalSection.Enter();
MxSmack::Destroy(&m_mxSmack);
Init();
m_criticalSection.Leave();
if (!p_fromDestructor) {
MxVideoPresenter::Destroy(FALSE);
}
}
// FUNCTION: LEGO1 0x100b3940
void MxSmkPresenter::LoadHeader(MxStreamChunk* p_chunk)
{
MxSmack::LoadHeader(p_chunk->GetData(), &m_mxSmack);
}
// FUNCTION: LEGO1 0x100b3960
void MxSmkPresenter::CreateBitmap()
{
if (m_bitmap)
delete m_bitmap;
m_bitmap = new MxBitmap;
m_bitmap->SetSize(m_mxSmack.m_smackTag.Width, m_mxSmack.m_smackTag.Height, NULL, FALSE);
}
// FUNCTION: LEGO1 0x100b3a00
void MxSmkPresenter::LoadFrame(MxStreamChunk* p_chunk)
{
MxBITMAPINFO* bitmapInfo = m_bitmap->GetBitmapInfo();
MxU8* bitmapData = m_bitmap->GetBitmapData();
MxU8* chunkData = p_chunk->GetData();
MxBool paletteChanged = m_mxSmack.m_frameTypes[m_currentFrame] & 1;
m_currentFrame++;
VTable0x88();
MxRectList list(TRUE);
MxSmack::LoadFrame(bitmapInfo, bitmapData, &m_mxSmack, chunkData, paletteChanged, &list);
if (((MxDSMediaAction*) m_action)->GetPaletteManagement() && paletteChanged)
RealizePalette();
MxRect32 invalidateRect;
MxRectListCursor cursor(&list);
MxRect32* rect;
while (cursor.Next(rect)) {
invalidateRect = *rect;
invalidateRect.AddPoint(GetLocation());
MVideoManager()->InvalidateRect(invalidateRect);
}
}
// FUNCTION: LEGO1 0x100b4260
void MxSmkPresenter::VTable0x88()
{
if ((m_mxSmack.m_smackTag.SmackerType & 1) != 0) {
MxU32 und = (m_currentFrame % m_mxSmack.m_smackTag.Frames);
if (1 < m_currentFrame && und == 1)
m_currentFrame = 1;
}
else {
if (m_mxSmack.m_smackTag.Frames == m_currentFrame) {
m_currentFrame = 0;
// TODO: struct incorrect, Palette at wrong offset?
memset(&m_mxSmack.m_smackTag.Palette[4], 0, sizeof(m_mxSmack.m_smackTag.Palette));
}
}
}
// FUNCTION: LEGO1 0x100b42c0
void MxSmkPresenter::RealizePalette()
{
MxPalette* palette = m_bitmap->CreatePalette();
MVideoManager()->RealizePalette(palette);
delete palette;
}
// FUNCTION: LEGO1 0x100b42f0
MxResult MxSmkPresenter::AddToManager()
{
return MxVideoPresenter::AddToManager();
}
// FUNCTION: LEGO1 0x100b4300
void MxSmkPresenter::Destroy()
{
Destroy(FALSE);
}

View File

@@ -0,0 +1,229 @@
#include "mxstillpresenter.h"
#include "decomp.h"
#include "define.h"
#include "legoomni.h"
#include "mxcompositepresenter.h"
#include "mxdsmediaaction.h"
#include "mxomni.h"
#include "mxvideomanager.h"
DECOMP_SIZE_ASSERT(MxStillPresenter, 0x6c);
// GLOBAL: LEGO1 0x10101eb0
const char* g_strBmpIsmap = "BMP_ISMAP";
// FUNCTION: LEGO1 0x100435b0
void MxStillPresenter::Destroy()
{
Destroy(FALSE);
}
// FUNCTION: LEGO1 0x100b9c70
void MxStillPresenter::Destroy(MxBool p_fromDestructor)
{
m_criticalSection.Enter();
if (m_bitmapInfo)
delete m_bitmapInfo;
m_bitmapInfo = NULL;
m_criticalSection.Leave();
if (!p_fromDestructor)
MxVideoPresenter::Destroy(FALSE);
}
// FUNCTION: LEGO1 0x100b9cc0
void MxStillPresenter::LoadHeader(MxStreamChunk* p_chunk)
{
if (m_bitmapInfo)
delete m_bitmapInfo;
MxU8* data = new MxU8[p_chunk->GetLength()];
m_bitmapInfo = (MxBITMAPINFO*) data;
memcpy(m_bitmapInfo, p_chunk->GetData(), p_chunk->GetLength());
}
// FUNCTION: LEGO1 0x100b9d10
void MxStillPresenter::CreateBitmap()
{
if (m_bitmap)
delete m_bitmap;
m_bitmap = new MxBitmap;
m_bitmap->ImportBitmapInfo(m_bitmapInfo);
delete m_bitmapInfo;
m_bitmapInfo = NULL;
}
// FUNCTION: LEGO1 0x100b9db0
void MxStillPresenter::NextFrame()
{
MxStreamChunk* chunk = NextChunk();
LoadFrame(chunk);
m_subscriber->FUN_100b8390(chunk);
}
// FUNCTION: LEGO1 0x100b9dd0
void MxStillPresenter::LoadFrame(MxStreamChunk* p_chunk)
{
memcpy(m_bitmap->GetBitmapData(), p_chunk->GetData(), p_chunk->GetLength());
// MxRect32 rect(m_location, MxSize32(GetWidth(), GetHeight()));
MxS32 height = GetHeight() - 1;
MxS32 width = GetWidth() - 1;
MxS32 x = m_location.GetX();
MxS32 y = m_location.GetY();
MxRect32 rect(x, y, width + x, height + y);
MVideoManager()->InvalidateRect(rect);
if (m_flags & Flag_Bit2) {
undefined4 und = 0;
m_unk0x58 = MxOmni::GetInstance()->GetVideoManager()->GetDisplaySurface()->VTable0x44(
m_bitmap,
&und,
(m_flags & Flag_Bit4) / 8,
m_action->GetFlags() & MxDSAction::Flag_Bit4
);
delete m_alpha;
m_alpha = new AlphaMask(*m_bitmap);
delete m_bitmap;
m_bitmap = NULL;
if (m_unk0x58 && und)
m_flags |= Flag_Bit3;
else
m_flags &= ~Flag_Bit3;
}
}
// FUNCTION: LEGO1 0x100b9f30
void MxStillPresenter::RealizePalette()
{
MxPalette* palette = m_bitmap->CreatePalette();
MVideoManager()->RealizePalette(palette);
delete palette;
}
// FUNCTION: LEGO1 0x100b9f60
void MxStillPresenter::StartingTickle()
{
MxVideoPresenter::StartingTickle();
if (m_currentTickleState == TickleState_Streaming && ((MxDSMediaAction*) m_action)->GetPaletteManagement())
RealizePalette();
}
// FUNCTION: LEGO1 0x100b9f90
void MxStillPresenter::StreamingTickle()
{
MxStreamChunk* chunk = FUN_100b5650();
if (chunk && m_action->GetElapsedTime() >= chunk->GetTime()) {
m_chunkTime = chunk->GetTime();
NextFrame();
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Repeating;
if (m_action->GetDuration() == -1 && m_compositePresenter)
m_compositePresenter->VTable0x60(this);
}
}
// FUNCTION: LEGO1 0x100b9ff0
void MxStillPresenter::RepeatingTickle()
{
if (m_action->GetDuration() != -1) {
if (m_action->GetElapsedTime() >= m_action->GetStartTime() + m_action->GetDuration()) {
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_unk5;
}
}
}
// FUNCTION: LEGO1 0x100ba040
void MxStillPresenter::VTable0x88(MxS32 p_x, MxS32 p_y)
{
MxS32 x = m_location.GetX();
MxS32 y = m_location.GetY();
m_location.SetX(p_x);
m_location.SetY(p_y);
if (IsEnabled()) {
// Most likely needs to work with MxSize32 and MxPoint32
MxS32 height = GetHeight() - 1;
MxS32 width = GetWidth() - 1;
MxRect32 rectA(x, y, width + x, height + y);
MxRect32 rectB(m_location.GetX(), m_location.GetY(), width + m_location.GetX(), height + m_location.GetY());
MVideoManager()->InvalidateRect(rectA);
MVideoManager()->VTable0x34(rectA.GetLeft(), rectA.GetTop(), rectA.GetWidth(), rectA.GetHeight());
MVideoManager()->InvalidateRect(rectB);
MVideoManager()->VTable0x34(rectB.GetLeft(), rectB.GetTop(), rectB.GetWidth(), rectB.GetHeight());
}
}
// FUNCTION: LEGO1 0x100ba140
void MxStillPresenter::Enable(MxBool p_enable)
{
MxVideoPresenter::Enable(p_enable);
if (MVideoManager() && (m_alpha || m_bitmap)) {
// MxRect32 rect(m_location, MxSize32(GetWidth(), GetHeight()));
MxS32 height = GetHeight();
MxS32 width = GetWidth();
MxS32 x = m_location.GetX();
MxS32 y = m_location.GetY();
MxRect32 rect(x, y, width + x, height + y);
MVideoManager()->InvalidateRect(rect);
MVideoManager()->VTable0x34(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
}
}
// FUNCTION: LEGO1 0x100ba1e0
void MxStillPresenter::ParseExtra()
{
MxPresenter::ParseExtra();
if (m_action->GetFlags() & MxDSAction::Flag_Bit5)
m_flags |= Flag_Bit4;
MxU32 len = m_action->GetExtraLength();
if (len == 0)
return;
len &= MAXWORD;
char buf[512];
memcpy(buf, m_action->GetExtraData(), len);
buf[len] = '\0';
char output[512];
if (KeyValueStringParse(output, g_strVISIBILITY, buf)) {
if (strcmpi(output, "FALSE") == 0) {
Enable(FALSE);
}
}
if (KeyValueStringParse(output, g_strBmpIsmap, buf)) {
m_flags |= Flag_Bit5;
m_flags &= ~Flag_Bit2;
m_flags &= ~Flag_Bit3;
}
}
// STUB: LEGO1 0x100ba2c0
MxStillPresenter* MxStillPresenter::Clone()
{
// TODO
return NULL;
}

View File

@@ -0,0 +1,607 @@
#include "mxtransitionmanager.h"
#include "legoinputmanager.h"
#include "legoutil.h"
#include "legovideomanager.h"
#include "legoworld.h"
#include "mxbackgroundaudiomanager.h"
#include "mxparam.h"
#include "mxticklemanager.h"
DECOMP_SIZE_ASSERT(MxTransitionManager, 0x900);
// GLOBAL: LEGO1 0x100f4378
RECT g_fullScreenRect = {0, 0, 640, 480};
// FUNCTION: LEGO1 0x1004b8d0
MxTransitionManager::MxTransitionManager()
{
m_animationTimer = 0;
m_transitionType = NOT_TRANSITIONING;
m_ddSurface = NULL;
m_waitIndicator = NULL;
m_copyBuffer = NULL;
m_copyFlags.m_bit0 = FALSE;
m_unk0x28.m_bit0 = FALSE;
m_unk0x24 = 0;
}
// FUNCTION: LEGO1 0x1004ba00
MxTransitionManager::~MxTransitionManager()
{
delete[] m_copyBuffer;
if (m_waitIndicator != NULL) {
delete m_waitIndicator->GetAction();
delete m_waitIndicator;
}
TickleManager()->UnregisterClient(this);
}
// FUNCTION: LEGO1 0x1004baa0
MxResult MxTransitionManager::GetDDrawSurfaceFromVideoManager() // vtable+0x14
{
LegoVideoManager* videoManager = VideoManager();
this->m_ddSurface = videoManager->GetDisplaySurface()->GetDirectDrawSurface2();
return SUCCESS;
}
// FUNCTION: LEGO1 0x1004bac0
MxResult MxTransitionManager::Tickle()
{
if (this->m_animationSpeed + this->m_systemTime > timeGetTime()) {
return SUCCESS;
}
this->m_systemTime = timeGetTime();
switch (this->m_transitionType) {
case NO_ANIMATION:
TransitionNone();
break;
case DISSOLVE:
TransitionDissolve();
break;
case PIXELATION:
TransitionPixelation();
break;
case SCREEN_WIPE:
TransitionWipe();
break;
case WINDOWS:
TransitionWindows();
break;
case BROKEN:
TransitionBroken();
break;
}
return SUCCESS;
}
// FUNCTION: 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.m_bit0 = p_doCopy;
if (m_copyFlags.m_bit0 && m_waitIndicator != NULL) {
m_waitIndicator->Enable(TRUE);
MxDSAction* action = m_waitIndicator->GetAction();
action->SetLoopCount(10000);
action->SetFlags(action->GetFlags() | MxDSAction::Flag_Bit10);
}
MxU32 time = timeGetTime();
this->m_systemTime = time;
this->m_animationSpeed = p_speed;
MxTickleManager* tickleManager = TickleManager();
tickleManager->RegisterClient(this, p_speed);
LegoInputManager* inputManager = InputManager();
inputManager->m_unk0x88 = TRUE;
inputManager->m_unk0x336 = FALSE;
LegoVideoManager* videoManager = VideoManager();
videoManager->SetUnkE4(FALSE);
SetAppCursor(1);
return SUCCESS;
}
return FAILURE;
}
// FUNCTION: LEGO1 0x1004bc30
void MxTransitionManager::EndTransition(MxBool p_notifyWorld)
{
if (m_transitionType != NOT_TRANSITIONING) {
m_transitionType = NOT_TRANSITIONING;
m_copyFlags.m_bit0 = FALSE;
TickleManager()->UnregisterClient(this);
if (p_notifyWorld) {
LegoWorld* world = GetCurrentWorld();
if (world) {
#ifdef COMPAT_MODE
{
MxNotificationParam param(MXTRANSITIONMANAGER_TRANSITIONENDED, this);
world->Notify(param);
}
#else
world->Notify(MxNotificationParam(MXTRANSITIONMANAGER_TRANSITIONENDED, this));
#endif
}
}
}
}
// FUNCTION: LEGO1 0x1004bcf0
void MxTransitionManager::TransitionNone()
{
LegoVideoManager* videoManager = VideoManager();
videoManager->GetDisplaySurface()->FUN_100ba640();
EndTransition(TRUE);
}
// FUNCTION: LEGO1 0x1004bd10
void MxTransitionManager::TransitionDissolve()
{
// 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...
MxS32 i;
for (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, DDLOCK_WAIT, NULL);
if (res == DDERR_SURFACELOST) {
m_ddSurface->Restore();
res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
}
if (res == DD_OK) {
SubmitCopyRect(&ddsd);
for (MxS32 col = 0; col < 640; col++) {
// Select 16 columns on each tick
if (m_animationTimer * 16 > m_columnOrder[col])
continue;
if (m_animationTimer * 16 + 15 < m_columnOrder[col])
continue;
for (MxS32 row = 0; row < 480; row++) {
// 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 xShift = (m_randomShift[row] + col) % 640;
// Set the chosen pixel to black
if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8) {
((MxU8*) ddsd.lpSurface)[row * ddsd.lPitch + xShift] = 0;
}
else {
((MxU16*) ddsd.lpSurface)[row * ddsd.lPitch + xShift] = 0;
}
}
}
SetupCopyRect(&ddsd);
m_ddSurface->Unlock(ddsd.lpSurface);
if (VideoManager()->GetVideoParam().Flags().GetFlipSurfaces()) {
LPDIRECTDRAWSURFACE surf = VideoManager()->GetDisplaySurface()->GetDirectDrawSurface1();
surf->BltFast(0, 0, m_ddSurface, &g_fullScreenRect, DDBLTFAST_WAIT);
}
m_animationTimer++;
}
}
// FUNCTION: LEGO1 0x1004bed0
void MxTransitionManager::TransitionPixelation()
{
if (m_animationTimer == 16) {
m_animationTimer = 0;
EndTransition(TRUE);
return;
}
if (m_animationTimer == 0) {
// Same init/shuffle steps as the dissolve transition, except that
// we are using big blocky pixels and only need 64 columns.
MxS32 i;
for (i = 0; i < 64; i++) {
m_columnOrder[i] = i;
}
for (i = 0; i < 64; i++) {
MxS32 swap = rand() % 64;
MxU16 t = m_columnOrder[i];
m_columnOrder[i] = m_columnOrder[swap];
m_columnOrder[swap] = t;
}
// The same is true here. We only need 48 rows.
for (i = 0; i < 48; i++) {
m_randomShift[i] = rand() % 64;
}
}
// 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 col = 0; col < 64; col++) {
// Select 4 columns on each tick
if (m_animationTimer * 4 > m_columnOrder[col])
continue;
if (m_animationTimer * 4 + 3 < m_columnOrder[col])
continue;
for (MxS32 row = 0; row < 48; row++) {
MxS32 xShift = 10 * ((m_randomShift[row] + col) % 64);
// To do the pixelation, we subdivide the 640x480 surface into
// 10x10 pixel blocks. At the chosen block, we sample the top-leftmost
// color and set the other 99 pixels to that value.
// Find the pixel to sample
MxS32 sampleOfs = 10 * row * ddsd.lPitch + xShift;
MxS32 bytesPerPixel = ddsd.ddpfPixelFormat.dwRGBBitCount / 8;
// Save this cast from void* to save time.
// Seems to help accuracy doing it this way.
MxU8* surface = (MxU8*) ddsd.lpSurface;
MxU8* source = surface + sampleOfs * bytesPerPixel;
MxU32 sample = bytesPerPixel == 1 ? *source : *(MxU16*) source;
for (MxS32 k = 10 * row; k < 10 * row + 10; k++) {
if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8) {
// TODO: This block and the next don't match, but they are
// hopefully correct in principle.
MxU16 colorWord = MAKEWORD(LOBYTE(sample), LOBYTE(sample));
MxU32 newColor = MAKELONG(colorWord, colorWord);
MxU8* pos = surface + k * ddsd.lPitch + xShift;
MxU32* dest = (MxU32*) pos;
// Sets 10 pixels (10 bytes)
dest[0] = newColor;
dest[1] = newColor;
MxU16* half = (MxU16*) (dest + 2);
*half = newColor;
}
else {
MxU32 newColor = MAKELONG(sample, sample);
// You might expect a cast to MxU16* instead, but lPitch is
// bytes/scanline, not pixels/scanline. Therefore, we just
// need to double the xShift to get to the right spot.
MxU8* pos = surface + k * ddsd.lPitch + 2 * xShift;
MxU32* dest = (MxU32*) pos;
// Sets 10 pixels (20 bytes)
dest[0] = newColor;
dest[1] = newColor;
dest[2] = newColor;
dest[3] = newColor;
dest[4] = newColor;
}
}
}
}
SetupCopyRect(&ddsd);
m_ddSurface->Unlock(ddsd.lpSurface);
if (VideoManager()->GetVideoParam().Flags().GetFlipSurfaces()) {
LPDIRECTDRAWSURFACE surf = VideoManager()->GetDisplaySurface()->GetDirectDrawSurface1();
surf->BltFast(0, 0, m_ddSurface, &g_fullScreenRect, DDBLTFAST_WAIT);
}
m_animationTimer++;
}
}
// FUNCTION: LEGO1 0x1004c170
void MxTransitionManager::TransitionWipe()
{
// If the animation is finished
if (m_animationTimer == 240) {
m_animationTimer = 0;
EndTransition(TRUE);
return;
}
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
HRESULT res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
if (res == DDERR_SURFACELOST) {
m_ddSurface->Restore();
res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
}
if (res == DD_OK) {
SubmitCopyRect(&ddsd);
// For each of the 240 animation ticks, blank out two scanlines
// starting at the top of the screen.
// (dwRGBBitCount / 8) will tell how many bytes are used per pixel.
MxU8* line = (MxU8*) ddsd.lpSurface + 2 * ddsd.lPitch * m_animationTimer;
memset(line, 0, 640 * ddsd.ddpfPixelFormat.dwRGBBitCount / 8);
line += ddsd.lPitch;
memset(line, 0, 640 * ddsd.ddpfPixelFormat.dwRGBBitCount / 8);
SetupCopyRect(&ddsd);
m_ddSurface->Unlock(ddsd.lpSurface);
m_animationTimer++;
}
}
// FUNCTION: LEGO1 0x1004c270
void MxTransitionManager::TransitionWindows()
{
if (m_animationTimer == 240) {
m_animationTimer = 0;
EndTransition(TRUE);
return;
}
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
HRESULT res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
if (res == DDERR_SURFACELOST) {
m_ddSurface->Restore();
res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
}
if (res == DD_OK) {
SubmitCopyRect(&ddsd);
MxU8* line = (MxU8*) ddsd.lpSurface + m_animationTimer * ddsd.lPitch;
MxS32 bytesPerPixel = ddsd.ddpfPixelFormat.dwRGBBitCount / 8;
MxS32 bytesPerLine = bytesPerPixel * 640;
memset(line, 0, bytesPerLine);
for (MxS32 i = m_animationTimer + 1; i < 480 - m_animationTimer; i++) {
line += ddsd.lPitch;
memset(line + m_animationTimer * bytesPerPixel, 0, bytesPerPixel);
memset(line + 640 + (-1 - m_animationTimer) * bytesPerPixel, 0, bytesPerPixel);
}
line += ddsd.lPitch;
memset(line, 0, bytesPerLine);
SetupCopyRect(&ddsd);
m_ddSurface->Unlock(ddsd.lpSurface);
m_animationTimer++;
}
}
// FUNCTION: LEGO1 0x1004c3e0
void MxTransitionManager::TransitionBroken()
{
// This function has no actual animation logic.
// It also never calls EndTransition to
// properly terminate the transition, so
// the game just hangs forever.
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
HRESULT res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
if (res == DDERR_SURFACELOST) {
m_ddSurface->Restore();
res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
}
if (res == DD_OK) {
SubmitCopyRect(&ddsd);
SetupCopyRect(&ddsd);
m_ddSurface->Unlock(ddsd.lpSurface);
}
}
// FUNCTION: LEGO1 0x1004c470
void MxTransitionManager::SetWaitIndicator(MxVideoPresenter* p_waitIndicator)
{
// End current wait indicator
if (m_waitIndicator != NULL) {
m_waitIndicator->GetAction()->SetFlags(m_waitIndicator->GetAction()->GetFlags() & ~MxDSAction::Flag_World);
m_waitIndicator->EndAction();
m_waitIndicator = NULL;
}
// Check if we were given a new wait indicator
if (p_waitIndicator != NULL) {
// Setup the new wait indicator
m_waitIndicator = p_waitIndicator;
LegoVideoManager* videoManager = VideoManager();
videoManager->RemovePresenter(*m_waitIndicator);
if (m_waitIndicator->GetCurrentTickleState() < MxPresenter::TickleState_Streaming) {
m_waitIndicator->Tickle();
}
}
else {
// Disable copy rect
m_copyFlags.m_bit0 = FALSE;
}
}
// FUNCTION: LEGO1 0x1004c4d0
void MxTransitionManager::SubmitCopyRect(LPDDSURFACEDESC p_ddsc)
{
// Check if the copy rect is setup
if (m_copyFlags.m_bit0 == FALSE || m_waitIndicator == NULL || m_copyBuffer == NULL) {
return;
}
// Copy the copy rect onto the surface
MxU8* dst;
MxU32 bytesPerPixel = p_ddsc->ddpfPixelFormat.dwRGBBitCount / 8;
const MxU8* src = (const MxU8*) m_copyBuffer;
MxS32 copyPitch;
copyPitch = ((m_copyRect.right - m_copyRect.left) + 1) * bytesPerPixel;
MxS32 y;
dst = (MxU8*) p_ddsc->lpSurface + (p_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 += p_ddsc->lPitch;
}
// Free the copy buffer
delete[] m_copyBuffer;
m_copyBuffer = NULL;
}
// FUNCTION: LEGO1 0x1004c580
void MxTransitionManager::SetupCopyRect(LPDDSURFACEDESC p_ddsc)
{
// Check if the copy rect is setup
if (m_copyFlags.m_bit0 == FALSE || m_waitIndicator == NULL) {
return;
}
// Tickle wait indicator
m_waitIndicator->Tickle();
// Check if wait indicator has started
if (m_waitIndicator->GetCurrentTickleState() >= MxPresenter::TickleState_Streaming) {
// Setup the copy rect
MxU32 copyPitch = (p_ddsc->ddpfPixelFormat.dwRGBBitCount / 8) *
(m_copyRect.right - m_copyRect.left + 1); // This uses m_copyRect, seemingly erroneously
MxU32 bytesPerPixel = p_ddsc->ddpfPixelFormat.dwRGBBitCount / 8;
m_copyRect.left = m_waitIndicator->GetLocation().GetX();
m_copyRect.top = m_waitIndicator->GetLocation().GetY();
MxS32 height = m_waitIndicator->GetHeight();
MxS32 width = m_waitIndicator->GetWidth();
m_copyRect.right = m_copyRect.left + width - 1;
m_copyRect.bottom = m_copyRect.top + height - 1;
// Allocate the copy buffer
const MxU8* src =
(const MxU8*) p_ddsc->lpSurface + m_copyRect.top * p_ddsc->lPitch + bytesPerPixel * m_copyRect.left;
m_copyBuffer = new MxU8[bytesPerPixel * width * height];
if (!m_copyBuffer)
return;
// Copy into the copy buffer
MxU8* dst = m_copyBuffer;
for (MxS32 i = 0; i < (m_copyRect.bottom - m_copyRect.top + 1); i++) {
memcpy(dst, src, copyPitch);
src += p_ddsc->lPitch;
dst += copyPitch;
}
}
// Setup display surface
if ((m_waitIndicator->GetAction()->GetFlags() & MxDSAction::Flag_Bit5) != 0) {
MxDisplaySurface* displaySurface = VideoManager()->GetDisplaySurface();
MxBool und = FALSE;
displaySurface->VTable0x2c(
p_ddsc,
m_waitIndicator->GetBitmap(),
0,
0,
m_waitIndicator->GetLocation().GetX(),
m_waitIndicator->GetLocation().GetY(),
m_waitIndicator->GetWidth(),
m_waitIndicator->GetHeight(),
und
);
}
else {
MxDisplaySurface* displaySurface = VideoManager()->GetDisplaySurface();
displaySurface->VTable0x24(
p_ddsc,
m_waitIndicator->GetBitmap(),
0,
0,
m_waitIndicator->GetLocation().GetX(),
m_waitIndicator->GetLocation().GetY(),
m_waitIndicator->GetWidth(),
m_waitIndicator->GetHeight()
);
}
}

View File

@@ -0,0 +1,317 @@
#include "mxvideomanager.h"
#include "legoomni.h"
#include "mxautolocker.h"
#include "mxpresenter.h"
#include "mxticklemanager.h"
DECOMP_SIZE_ASSERT(MxVideoManager, 0x64)
// FUNCTION: LEGO1 0x100be1f0
MxVideoManager::MxVideoManager()
{
Init();
}
// FUNCTION: LEGO1 0x100be270
void MxVideoManager::VTable0x34(MxU32 p_x, MxU32 p_y, MxU32 p_width, MxU32 p_height)
{
}
// FUNCTION: LEGO1 0x100be2a0
MxVideoManager::~MxVideoManager()
{
Destroy(TRUE);
}
// FUNCTION: LEGO1 0x100be320
MxResult MxVideoManager::Init()
{
this->m_pDirectDraw = NULL;
this->m_pDirect3D = NULL;
this->m_displaySurface = NULL;
this->m_region = NULL;
this->m_videoParam.SetPalette(NULL);
this->m_unk0x60 = FALSE;
return SUCCESS;
}
// FUNCTION: LEGO1 0x100be340
void MxVideoManager::Destroy(MxBool p_fromDestructor)
{
if (m_thread) {
m_thread->Terminate();
delete m_thread;
}
else
TickleManager()->UnregisterClient(this);
m_criticalSection.Enter();
if (m_displaySurface)
delete m_displaySurface;
if (m_region)
delete m_region;
if (m_videoParam.GetPalette())
delete m_videoParam.GetPalette();
if (m_unk0x60) {
if (m_pDirectDraw)
m_pDirectDraw->Release();
if (m_pDirect3D)
m_pDirect3D->Release();
}
Init();
m_criticalSection.Leave();
if (!p_fromDestructor)
MxMediaManager::Destroy();
}
// FUNCTION: LEGO1 0x100be3e0
void MxVideoManager::UpdateRegion()
{
if (m_region->VTable0x20() == FALSE) {
MxRect32 rect(m_region->GetRect());
rect.Intersect(m_videoParam.GetRect());
m_displaySurface
->Display(rect.GetLeft(), rect.GetTop(), rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
}
}
// FUNCTION: LEGO1 0x100be440
void MxVideoManager::SortPresenterList()
{
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--) {
MxPresenter *presenterA, *presenterB;
a.Next(presenterA);
b.Next(presenterB);
if (presenterA->GetDisplayZ() < presenterB->GetDisplayZ()) {
a.SetValue(presenterB);
b.SetValue(presenterA);
finished = FALSE;
}
}
} while (!finished && --count != 0);
}
}
// FUNCTION: LEGO1 0x100be600
MxResult MxVideoManager::VTable0x28(
MxVideoParam& p_videoParam,
LPDIRECTDRAW p_pDirectDraw,
LPDIRECT3D2 p_pDirect3D,
LPDIRECTDRAWSURFACE p_ddSurface1,
LPDIRECTDRAWSURFACE p_ddSurface2,
LPDIRECTDRAWCLIPPER p_ddClipper,
MxU32 p_frequencyMS,
MxBool p_createThread
)
{
MxBool locked = FALSE;
MxResult status = FAILURE;
m_unk0x60 = FALSE;
if (MxMediaManager::InitPresenters() != SUCCESS)
goto done;
m_criticalSection.Enter();
locked = TRUE;
m_videoParam = p_videoParam;
m_region = new MxRegion();
if (!m_region)
goto done;
m_pDirectDraw = p_pDirectDraw;
m_pDirect3D = p_pDirect3D;
MxPalette* palette;
if (p_videoParam.GetPalette() == NULL) {
palette = new MxPalette();
m_videoParam.SetPalette(palette);
if (!palette)
goto done;
}
else {
palette = p_videoParam.GetPalette()->Clone();
m_videoParam.SetPalette(palette);
if (!palette)
goto done;
}
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());
if (p_createThread) {
m_thread = new MxTickleThread(this, p_frequencyMS);
if (!m_thread || m_thread->Start(0, 0) != SUCCESS)
goto done;
}
else
TickleManager()->RegisterClient(this, p_frequencyMS);
status = SUCCESS;
}
done:
if (status != SUCCESS)
Destroy();
if (locked)
m_criticalSection.Leave();
return status;
}
// FUNCTION: LEGO1 0x100be820
MxResult MxVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyMS, MxBool p_createThread)
{
MxBool locked = FALSE;
MxResult status = FAILURE;
m_unk0x60 = TRUE;
if (MxMediaManager::InitPresenters() != SUCCESS)
goto done;
m_criticalSection.Enter();
locked = TRUE;
m_videoParam = p_videoParam;
m_region = new MxRegion();
if (!m_region)
goto done;
if (DirectDrawCreate(NULL, &m_pDirectDraw, NULL) != DD_OK)
goto done;
if (m_pDirectDraw->SetCooperativeLevel(MxOmni::GetInstance()->GetWindowHandle(), DDSCL_NORMAL) != DD_OK)
goto done;
MxPalette* palette;
if (p_videoParam.GetPalette() == NULL) {
palette = new MxPalette();
m_videoParam.SetPalette(palette);
if (!palette)
goto done;
}
else {
palette = p_videoParam.GetPalette()->Clone();
m_videoParam.SetPalette(palette);
if (!palette)
goto done;
}
m_displaySurface = new MxDisplaySurface();
if (m_displaySurface && m_displaySurface->Create(m_videoParam) == SUCCESS) {
m_displaySurface->SetPalette(m_videoParam.GetPalette());
if (p_createThread) {
m_thread = new MxTickleThread(this, p_frequencyMS);
if (!m_thread || m_thread->Start(0, 0) != SUCCESS)
goto done;
}
else
TickleManager()->RegisterClient(this, p_frequencyMS);
status = SUCCESS;
}
done:
if (status != SUCCESS)
Destroy();
if (locked)
m_criticalSection.Leave();
return status;
}
// FUNCTION: LEGO1 0x100bea50
void MxVideoManager::Destroy()
{
Destroy(FALSE);
}
// FUNCTION: LEGO1 0x100bea60
void MxVideoManager::InvalidateRect(MxRect32& p_rect)
{
m_criticalSection.Enter();
if (m_region)
m_region->VTable0x18(p_rect);
m_criticalSection.Leave();
}
// FUNCTION: LEGO1 0x100bea90
MxResult MxVideoManager::Tickle()
{
MxAutoLocker lock(&this->m_criticalSection);
SortPresenterList();
MxPresenter* presenter;
MxPresenterListCursor cursor(this->m_presenters);
while (cursor.Next(presenter))
presenter->Tickle();
cursor.Reset();
while (cursor.Next(presenter))
presenter->PutData();
UpdateRegion();
m_region->Reset();
return SUCCESS;
}
// FUNCTION: LEGO1 0x100bebe0
MxResult MxVideoManager::RealizePalette(MxPalette* p_palette)
{
PALETTEENTRY paletteEntries[256];
this->m_criticalSection.Enter();
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());
}
this->m_criticalSection.Leave();
return SUCCESS;
}

View File

@@ -0,0 +1,87 @@
#include "mxvideoparam.h"
#include "decomp.h"
#include <stdlib.h>
#include <string.h>
DECOMP_SIZE_ASSERT(MxVideoParam, 0x24);
// FUNCTION: LEGO1 0x100bec70
MxVideoParam::MxVideoParam()
{
this->m_rect.SetRight(640);
this->m_rect.SetBottom(480);
this->m_rect.SetLeft(0);
this->m_rect.SetTop(0);
this->m_palette = NULL;
this->m_backBuffers = 0;
this->m_unk0x1c = 0;
this->m_deviceId = NULL;
}
// FUNCTION: LEGO1 0x100beca0
MxVideoParam::MxVideoParam(
COMPAT_CONST MxRect32& p_rect,
MxPalette* p_palette,
MxULong p_backBuffers,
COMPAT_CONST MxVideoParamFlags& p_flags
)
{
this->m_rect = p_rect;
this->m_palette = p_palette;
this->m_backBuffers = p_backBuffers;
this->m_flags = p_flags;
this->m_unk0x1c = 0;
this->m_deviceId = NULL;
}
// FUNCTION: LEGO1 0x100becf0
MxVideoParam::MxVideoParam(MxVideoParam& p_videoParam)
{
this->m_rect = p_videoParam.m_rect;
this->m_palette = p_videoParam.m_palette;
this->m_backBuffers = p_videoParam.m_backBuffers;
this->m_flags = p_videoParam.m_flags;
this->m_unk0x1c = p_videoParam.m_unk0x1c;
this->m_deviceId = NULL;
SetDeviceName(p_videoParam.m_deviceId);
}
// FUNCTION: LEGO1 0x100bed50
MxVideoParam::~MxVideoParam()
{
if (this->m_deviceId != NULL)
delete[] this->m_deviceId;
}
// FUNCTION: LEGO1 0x100bed70
void MxVideoParam::SetDeviceName(char* p_deviceId)
{
if (this->m_deviceId != NULL)
delete[] this->m_deviceId;
if (p_deviceId != NULL) {
this->m_deviceId = new char[strlen(p_deviceId) + 1];
if (this->m_deviceId != NULL) {
strcpy(this->m_deviceId, p_deviceId);
}
}
else {
this->m_deviceId = NULL;
}
}
// FUNCTION: LEGO1 0x100bede0
MxVideoParam& MxVideoParam::operator=(const MxVideoParam& p_videoParam)
{
this->m_rect = p_videoParam.m_rect;
this->m_palette = p_videoParam.m_palette;
this->m_backBuffers = p_videoParam.m_backBuffers;
this->m_flags = p_videoParam.m_flags;
this->m_unk0x1c = p_videoParam.m_unk0x1c;
SetDeviceName(p_videoParam.m_deviceId);
return *this;
}

View File

@@ -0,0 +1,15 @@
#include "mxvideoparamflags.h"
// FUNCTION: LEGO1 0x100bec40
MxVideoParamFlags::MxVideoParamFlags()
{
this->SetFullScreen(0);
this->SetFlipSurfaces(0);
this->SetBackBuffers(0);
this->SetF1bit3(0);
this->SetF1bit4(0);
this->Set16Bit(0);
this->SetWideViewAngle(1);
this->SetF1bit7(1);
this->SetF2bit1(1);
}

View File

@@ -0,0 +1,627 @@
#include "mxvideopresenter.h"
#include "mxautolocker.h"
#include "mxdsmediaaction.h"
#include "mxregioncursor.h"
#include "mxvideomanager.h"
DECOMP_SIZE_ASSERT(MxVideoPresenter, 0x64);
DECOMP_SIZE_ASSERT(MxVideoPresenter::AlphaMask, 0xc);
// FUNCTION: LEGO1 0x1000c700
void MxVideoPresenter::LoadHeader(MxStreamChunk* p_chunk)
{
// Empty
}
// FUNCTION: LEGO1 0x1000c710
void MxVideoPresenter::CreateBitmap()
{
// Empty
}
// FUNCTION: LEGO1 0x1000c720
void MxVideoPresenter::LoadFrame(MxStreamChunk* p_chunk)
{
// Empty
}
// FUNCTION: LEGO1 0x1000c730
void MxVideoPresenter::RealizePalette()
{
// Empty
}
// FUNCTION: LEGO1 0x1000c740
MxVideoPresenter::~MxVideoPresenter()
{
Destroy(TRUE);
}
// FUNCTION: LEGO1 0x1000c7a0
void MxVideoPresenter::Destroy()
{
Destroy(FALSE);
}
// FUNCTION: LEGO1 0x1000c7b0
LPDIRECTDRAWSURFACE MxVideoPresenter::VTable0x78()
{
return m_unk0x58;
}
// FUNCTION: LEGO1 0x1000c7c0
MxBool MxVideoPresenter::VTable0x7c()
{
return (m_bitmap != NULL) || (m_alpha != NULL);
}
// FUNCTION: LEGO1 0x1000c7e0
MxS32 MxVideoPresenter::GetWidth()
{
return m_alpha ? m_alpha->m_width : m_bitmap->GetBmiWidth();
}
// FUNCTION: LEGO1 0x1000c800
MxS32 MxVideoPresenter::GetHeight()
{
return m_alpha ? m_alpha->m_height : m_bitmap->GetBmiHeightAbs();
}
// FUNCTION: LEGO1 0x100b24f0
MxVideoPresenter::AlphaMask::AlphaMask(const MxBitmap& p_bitmap)
{
m_width = p_bitmap.GetBmiWidth();
// DECOMP: ECX becomes word-sized if these are not two separate actions.
MxLong height = p_bitmap.GetBmiHeightAbs();
m_height = height;
MxS32 size = ((m_width * m_height) / 8) + 1;
m_bitmask = new MxU8[size];
memset(m_bitmask, 0, size);
MxU32 biCompression = p_bitmap.GetBmiHeader()->biCompression;
MxU32 rowsBeforeTop;
MxU8* bitmapSrcPtr;
// The goal here is to enable us to walk through the bitmap's rows
// in order, regardless of the orientation. We want to end up at the
// start of the first row, which is either at position 0, or at
// (image_stride * biHeight) - 1.
// Reminder: Negative biHeight means this is a top-down DIB.
// Otherwise it is bottom-up.
if (biCompression == BI_RGB) {
// DECOMP: I think this must be an OR. If not, the check for
// biCompression == 16 gets optimized away.
if (biCompression == BI_RGB_TOPDOWN || p_bitmap.GetBmiHeight() < 0) {
rowsBeforeTop = 0;
}
else {
rowsBeforeTop = p_bitmap.GetBmiHeightAbs();
rowsBeforeTop--;
}
goto seek_to_last_row;
}
else if (biCompression == BI_RGB_TOPDOWN) {
// DECOMP: This is the only condition where we skip the
// calculation below.
bitmapSrcPtr = p_bitmap.GetBitmapData();
}
else {
if (p_bitmap.GetBmiHeight() < 0) {
rowsBeforeTop = 0;
}
else {
rowsBeforeTop = p_bitmap.GetBmiHeightAbs();
rowsBeforeTop--;
}
// TODO: would prefer not to use goto if we can figure this structure out
seek_to_last_row:
bitmapSrcPtr = p_bitmap.GetBmiStride() * rowsBeforeTop + p_bitmap.GetBitmapData();
}
// How many bytes are there for each row of the bitmap?
// (i.e. the image stride)
// If this is a bottom-up DIB, we will walk it in reverse.
// TODO: Same rounding trick as in MxBitmap
MxS32 rowSeek = ((m_width + 3) & -4);
if (p_bitmap.GetBmiHeight() < 0)
rowSeek = -rowSeek;
// The actual offset into the m_bitmask array. The two for-loops
// are just for counting the pixels.
MxS32 offset = 0;
MxU8* tPtr = bitmapSrcPtr;
for (MxS32 j = 0; j < m_height; j++) {
for (MxS32 i = 0; i < m_width; i++) {
if (*tPtr) {
// TODO: Second CDQ instruction for abs() should not be there.
MxU32 shift = abs(offset) & 7;
m_bitmask[offset / 8] |= (1 << abs((MxS32) shift));
}
tPtr++;
offset++;
}
// Seek to the start of the next row
bitmapSrcPtr += rowSeek;
tPtr = bitmapSrcPtr;
}
}
// FUNCTION: LEGO1 0x100b2670
MxVideoPresenter::AlphaMask::AlphaMask(const MxVideoPresenter::AlphaMask& p_alpha)
{
m_width = p_alpha.m_width;
m_height = p_alpha.m_height;
MxS32 size = ((m_width * m_height) / 8) + 1;
m_bitmask = new MxU8[size];
memcpy(m_bitmask, p_alpha.m_bitmask, size);
}
// FUNCTION: LEGO1 0x100b26d0
MxVideoPresenter::AlphaMask::~AlphaMask()
{
if (m_bitmask)
delete[] m_bitmask;
}
// FUNCTION: LEGO1 0x100b26f0
MxS32 MxVideoPresenter::AlphaMask::IsHit(MxU32 p_x, MxU32 p_y)
{
if (p_x >= m_width || p_y >= m_height)
return 0;
MxS32 pos = p_y * m_width + p_x;
return m_bitmask[pos / 8] & (1 << abs(abs(pos) & 7)) ? 1 : 0;
}
// FUNCTION: LEGO1 0x100b2760
void MxVideoPresenter::Init()
{
m_bitmap = NULL;
m_alpha = NULL;
m_unk0x5c = 1;
m_unk0x58 = NULL;
m_unk0x60 = -1;
m_flags &= ~Flag_Bit1;
if (MVideoManager() != NULL) {
MVideoManager();
m_flags |= Flag_Bit2;
m_flags &= ~Flag_Bit3;
}
m_flags &= ~Flag_Bit4;
m_flags &= ~Flag_Bit5;
}
// FUNCTION: LEGO1 0x100b27b0
void MxVideoPresenter::Destroy(MxBool p_fromDestructor)
{
if (MVideoManager() != NULL)
MVideoManager()->RemovePresenter(*this);
if (m_unk0x58) {
m_unk0x58->Release();
m_unk0x58 = NULL;
m_flags &= ~Flag_Bit2;
m_flags &= ~Flag_Bit3;
}
if (MVideoManager() && (m_alpha || m_bitmap)) {
// MxRect32 rect(m_location, MxSize32(GetWidth(), GetHeight()));
MxS32 height = GetHeight();
MxS32 width = GetWidth();
MxS32 x = m_location.GetX();
MxS32 y = m_location.GetY();
MxRect32 rect(x, y, x + width, y + height);
MVideoManager()->InvalidateRect(rect);
MVideoManager()->VTable0x34(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
}
delete m_bitmap;
delete m_alpha;
Init();
if (!p_fromDestructor)
MxMediaPresenter::Destroy(FALSE);
}
// FUNCTION: LEGO1 0x100b28b0
void MxVideoPresenter::NextFrame()
{
MxStreamChunk* chunk = NextChunk();
if (chunk->GetFlags() & MxDSChunk::Flag_End) {
m_subscriber->FUN_100b8390(chunk);
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Repeating;
}
else {
LoadFrame(chunk);
m_subscriber->FUN_100b8390(chunk);
}
}
// FUNCTION: LEGO1 0x100b2900
MxBool MxVideoPresenter::IsHit(MxS32 p_x, MxS32 p_y)
{
MxDSAction* action = GetAction();
if ((action == NULL) || (((action->GetFlags() & MxDSAction::Flag_Bit11) == 0) && !IsEnabled()) ||
(!m_bitmap && !m_alpha))
return FALSE;
if (!m_bitmap)
return m_alpha->IsHit(p_x - m_location.GetX(), p_y - m_location.GetY());
MxLong heightAbs = m_bitmap->GetBmiHeightAbs();
MxLong minX = m_location.GetX();
MxLong minY = m_location.GetY();
MxLong maxY = minY + heightAbs;
MxLong maxX = minX + m_bitmap->GetBmiWidth();
if (p_x < minX || p_x >= maxX || p_y < minY || p_y >= maxY)
return FALSE;
MxU8* pixel;
MxLong biCompression = m_bitmap->GetBmiHeader()->biCompression;
MxLong height = m_bitmap->GetBmiHeight();
MxLong seekRow;
// DECOMP: Same basic layout as AlphaMask constructor
// The idea here is to again seek to the correct place in the bitmap's
// m_data buffer. The x,y args are (most likely) screen x and y, so we
// need to shift that to coordinates local to the bitmap by removing
// the MxPresenter location x and y coordinates.
if (biCompression == BI_RGB) {
if (biCompression == BI_RGB_TOPDOWN || height < 0) {
seekRow = p_y - m_location.GetY();
}
else {
height = height > 0 ? height : -height;
seekRow = height - p_y - 1 + m_location.GetY();
}
pixel = m_bitmap->GetBmiStride() * seekRow + m_bitmap->GetBitmapData() - m_location.GetX() + p_x;
}
else if (biCompression == BI_RGB_TOPDOWN) {
pixel = m_bitmap->GetBitmapData();
}
else {
height = height > 0 ? height : -height;
height--;
pixel = m_bitmap->GetBmiStride() * height + m_bitmap->GetBitmapData();
}
// DECOMP: m_flags is 1 byte, so no enum here
if (m_flags & 0x10)
return (MxBool) *pixel;
if ((GetAction()->GetFlags() & MxDSAction::Flag_Bit4) && *pixel == 0)
return FALSE;
return TRUE;
}
inline MxS32 MxVideoPresenter::PrepareRects(MxRect32& p_rectDest, MxRect32& p_rectSrc)
{
if (p_rectDest.GetTop() > 480 || p_rectDest.GetLeft() > 640 || p_rectSrc.GetTop() > 480 ||
p_rectSrc.GetLeft() > 640)
return -1;
if (p_rectDest.GetBottom() > 480)
p_rectDest.SetBottom(480);
if (p_rectDest.GetRight() > 640)
p_rectDest.SetRight(640);
if (p_rectSrc.GetBottom() > 480)
p_rectSrc.SetBottom(480);
if (p_rectSrc.GetRight() > 640)
p_rectSrc.SetRight(640);
MxS32 height = p_rectDest.GetHeight();
if (height <= 1)
return -1;
MxS32 width = p_rectDest.GetWidth();
if (width <= 1)
return -1;
if (p_rectSrc.GetRight() - width - p_rectSrc.GetLeft() == -1 &&
p_rectSrc.GetBottom() - height - p_rectSrc.GetTop() == -1)
return 1;
p_rectSrc.SetRight(p_rectSrc.GetLeft() + width - 1);
p_rectSrc.SetBottom(p_rectSrc.GetTop() + height - 1);
return 0;
}
// FUNCTION: LEGO1 0x100b2a70
void MxVideoPresenter::PutFrame()
{
MxDisplaySurface* displaySurface = MVideoManager()->GetDisplaySurface();
MxRegion* region = MVideoManager()->GetRegion();
MxRect32 rect(m_location, MxSize32(GetWidth(), GetHeight()));
LPDIRECTDRAWSURFACE ddSurface = displaySurface->GetDirectDrawSurface2();
MxRect32 rectSrc, rectDest;
if (m_action->GetFlags() & MxDSAction::Flag_Bit5) {
if (m_unk0x58) {
// TODO: Match
rectSrc.SetPoint(MxPoint32(0, 0));
rectSrc.SetRight(GetWidth());
rectSrc.SetBottom(GetHeight());
rectDest.SetPoint(m_location);
rectDest.SetRight(rectDest.GetLeft() + GetWidth());
rectDest.SetBottom(rectDest.GetTop() + GetHeight());
switch (PrepareRects(rectDest, rectSrc)) {
case 0:
ddSurface->Blt((LPRECT) &rectDest, m_unk0x58, (LPRECT) &rectSrc, DDBLT_KEYSRC, NULL);
break;
case 1:
ddSurface->BltFast(
rectDest.GetLeft(),
rectDest.GetTop(),
m_unk0x58,
(LPRECT) &rectSrc,
DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT
);
}
}
else {
displaySurface->VTable0x30(
m_bitmap,
0,
0,
rect.GetLeft(),
rect.GetTop(),
m_bitmap->GetBmiWidth(),
m_bitmap->GetBmiHeightAbs(),
TRUE
);
}
}
else {
MxRegionCursor cursor(region);
MxRect32* regionRect;
while (regionRect = cursor.VTable0x24(rect)) {
if (regionRect->GetWidth() >= 1 && regionRect->GetHeight() >= 1) {
if (m_unk0x58) {
rectSrc.SetLeft(regionRect->GetLeft() - m_location.GetX());
rectSrc.SetTop(regionRect->GetTop() - m_location.GetY());
rectSrc.SetRight(rectSrc.GetLeft() + regionRect->GetWidth());
rectSrc.SetBottom(rectSrc.GetTop() + regionRect->GetHeight());
rectDest.SetLeft(regionRect->GetLeft());
rectDest.SetTop(regionRect->GetTop());
rectDest.SetRight(rectDest.GetLeft() + regionRect->GetWidth());
rectDest.SetBottom(rectDest.GetTop() + regionRect->GetHeight());
}
if (m_action->GetFlags() & MxDSAction::Flag_Bit4) {
if (m_unk0x58) {
if (PrepareRects(rectDest, rectSrc) >= 0)
ddSurface->Blt((LPRECT) &rectDest, m_unk0x58, (LPRECT) &rectSrc, DDBLT_KEYSRC, NULL);
}
else {
displaySurface->VTable0x30(
m_bitmap,
regionRect->GetLeft() - m_location.GetX(),
regionRect->GetTop() - m_location.GetY(),
regionRect->GetLeft(),
regionRect->GetTop(),
regionRect->GetWidth(),
regionRect->GetHeight(),
FALSE
);
}
}
else if (m_unk0x58) {
if (PrepareRects(rectDest, rectSrc) >= 0)
ddSurface->Blt((LPRECT) &rectDest, m_unk0x58, (LPRECT) &rectSrc, 0, NULL);
}
else {
displaySurface->VTable0x28(
m_bitmap,
regionRect->GetLeft() - m_location.GetX(),
regionRect->GetTop() - m_location.GetY(),
regionRect->GetLeft(),
regionRect->GetTop(),
regionRect->GetWidth(),
regionRect->GetHeight()
);
}
}
}
}
}
// FUNCTION: LEGO1 0x100b2f60
void MxVideoPresenter::ReadyTickle()
{
MxStreamChunk* chunk = NextChunk();
if (chunk) {
LoadHeader(chunk);
m_subscriber->FUN_100b8390(chunk);
ParseExtra();
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Starting;
}
}
// FUNCTION: LEGO1 0x100b2fa0
void MxVideoPresenter::StartingTickle()
{
MxStreamChunk* chunk = FUN_100b5650();
if (chunk && m_action->GetElapsedTime() >= chunk->GetTime()) {
CreateBitmap();
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Streaming;
}
}
// FUNCTION: LEGO1 0x100b2fe0
void MxVideoPresenter::StreamingTickle()
{
if (m_action->GetFlags() & MxDSAction::Flag_Bit10) {
if (!m_currentChunk)
MxMediaPresenter::StreamingTickle();
if (m_currentChunk) {
LoadFrame(m_currentChunk);
m_currentChunk = NULL;
}
}
else {
for (MxS16 i = 0; i < m_unk0x5c; i++) {
if (!m_currentChunk) {
MxMediaPresenter::StreamingTickle();
if (!m_currentChunk)
break;
}
if (m_action->GetElapsedTime() < m_currentChunk->GetTime())
break;
LoadFrame(m_currentChunk);
m_subscriber->FUN_100b8390(m_currentChunk);
m_currentChunk = NULL;
m_flags |= Flag_Bit1;
if (m_currentTickleState != TickleState_Streaming)
break;
}
if (m_flags & Flag_Bit1)
m_unk0x5c = 5;
}
}
// FUNCTION: LEGO1 0x100b3080
void MxVideoPresenter::RepeatingTickle()
{
if (IsEnabled()) {
if (m_action->GetFlags() & MxDSAction::Flag_Bit10) {
if (!m_currentChunk)
MxMediaPresenter::RepeatingTickle();
if (m_currentChunk) {
LoadFrame(m_currentChunk);
m_currentChunk = NULL;
}
}
else {
for (MxS16 i = 0; i < m_unk0x5c; i++) {
if (!m_currentChunk) {
MxMediaPresenter::RepeatingTickle();
if (!m_currentChunk)
break;
}
if (m_action->GetElapsedTime() % m_action->GetLoopCount() < m_currentChunk->GetTime())
break;
LoadFrame(m_currentChunk);
m_currentChunk = NULL;
m_flags |= Flag_Bit1;
if (m_currentTickleState != TickleState_Repeating)
break;
}
if (m_flags & Flag_Bit1)
m_unk0x5c = 5;
}
}
}
// FUNCTION: LEGO1 0x100b3130
void MxVideoPresenter::Unk5Tickle()
{
MxLong sustainTime = ((MxDSMediaAction*) m_action)->GetSustainTime();
if (sustainTime != -1) {
if (sustainTime) {
if (m_unk0x60 == -1)
m_unk0x60 = m_action->GetElapsedTime();
if (m_action->GetElapsedTime() >= m_unk0x60 + ((MxDSMediaAction*) m_action)->GetSustainTime()) {
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Done;
}
}
else {
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
m_currentTickleState = TickleState_Done;
}
}
}
// FUNCTION: LEGO1 0x100b31a0
MxResult MxVideoPresenter::AddToManager()
{
MxResult result = FAILURE;
if (MVideoManager()) {
result = SUCCESS;
MVideoManager()->AddPresenter(*this);
}
return result;
}
// FUNCTION: LEGO1 0x100b31d0
void MxVideoPresenter::EndAction()
{
if (m_action) {
MxMediaPresenter::EndAction();
MxAutoLocker lock(&m_criticalSection);
if (m_bitmap) {
MxLong height = m_bitmap->GetBmiHeightAbs();
MxLong width = m_bitmap->GetBmiWidth();
MxS32 x = m_location.GetX();
MxS32 y = m_location.GetY();
MxRect32 rect(x, y, x + width, y + height);
MVideoManager()->InvalidateRect(rect);
}
}
}
// FUNCTION: LEGO1 0x100b3280
MxResult MxVideoPresenter::PutData()
{
MxAutoLocker lock(&m_criticalSection);
if (IsEnabled() && m_currentTickleState >= TickleState_Streaming && m_currentTickleState <= TickleState_unk5)
PutFrame();
return SUCCESS;
}
// FUNCTION: LEGO1 0x100b3300
undefined MxVideoPresenter::VTable0x74()
{
return 0;
}