isle-portable/LEGO1/lego/sources/misc/legocontainer.cpp
Anonymous Maarten 7fc4080a15
Some checks failed
CI / clang-format (push) Has been cancelled
CI / ${{ matrix.name }} (false, --toolchain /usr/local/vitasdk/share/vita.toolchain.cmake, false, false, Ninja, Vita, ubuntu-latest, true, true) (push) Has been cancelled
CI / ${{ matrix.name }} (false, -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0, false, false, Visual Studio 17 2022, true, Xbox One, windows-latest, amd64, false, true) (push) Has been cancelled
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake, false, devkitpro/devkitarm:latest, false, Ninja, true, Nintendo 3DS, ubuntu-latest, true) (push) Has been cancelled
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake, false, devkitpro/devkita64:latest, false, Ninja, Nintendo Switch, true, ubuntu-latest, true) (push) Has been cancelled
CI / ${{ matrix.name }} (false, emcmake, false, false, true, Ninja, Emscripten, ubuntu-latest, true) (push) Has been cancelled
CI / ${{ matrix.name }} (false, false, false, Ninja, true, MSVC (arm64), windows-latest, amd64_arm64, false) (push) Has been cancelled
CI / ${{ matrix.name }} (false, false, true, Ninja, true, MSVC (x86), windows-latest, amd64_x86, false) (push) Has been cancelled
CI / ${{ matrix.name }} (false, true, false, Ninja, true, MSVC (x64), windows-latest, amd64, false) (push) Has been cancelled
CI / ${{ matrix.name }} (false, true, true, false, Ninja, true, MSVC (x64 Debug), windows-latest, amd64, false) (push) Has been cancelled
CI / ${{ matrix.name }} (true, false, -DCMAKE_SYSTEM_NAME=iOS, false, false, Xcode, true, iOS, macos-15, true) (push) Has been cancelled
CI / ${{ matrix.name }} (true, false, false, Ninja, true, mingw-w64-i686, mingw32, msys2 mingw32, windows-latest, msys2 {0}, true) (push) Has been cancelled
CI / ${{ matrix.name }} (true, false, false, false, Ninja, Android, ubuntu-latest, true) (push) Has been cancelled
CI / ${{ matrix.name }} (true, false, true, false, Ninja, macOS, macos-latest, true) (push) Has been cancelled
CI / ${{ matrix.name }} (true, true, false, Ninja, true, mingw-w64-x86_64, mingw64, msys2 mingw64, windows-latest, msys2 {0}, true) (push) Has been cancelled
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux (Debug), ubuntu-latest, true) (push) Has been cancelled
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux, ubuntu-latest, true) (push) Has been cancelled
CI / Flatpak (${{ matrix.arch }}) (aarch64, ubuntu-22.04-arm) (push) Has been cancelled
CI / Flatpak (${{ matrix.arch }}) (x86_64, ubuntu-latest) (push) Has been cancelled
CI / C++ (push) Has been cancelled
Docker / Publish web port (push) Has been cancelled
CI / Release (push) Has been cancelled
Plug memory leaks while moving around in the Information Center (#768)
Plug all leaks when moving around in the Information Center.

This does not include:

-    loading a save game
-    starting a new game
-    selecting a LEGO character and enter the world
-    launching a paper plane on the observation deck
2026-01-06 04:17:23 +01:00

131 lines
3.8 KiB
C++

#include "legocontainer.h"
#include "lego/legoomni/include/legovideomanager.h"
#include "lego/legoomni/include/misc.h"
#include "mxdirectx/mxdirect3d.h"
#include "tgl/d3drm/impl.h"
DECOMP_SIZE_ASSERT(LegoContainerInfo<LegoTexture>, 0x10);
// DECOMP_SIZE_ASSERT(LegoContainer<LegoTexture>, 0x18);
DECOMP_SIZE_ASSERT(LegoTextureContainer, 0x24);
// FUNCTION: LEGO1 0x10099870
LegoTextureContainer::~LegoTextureContainer()
{
}
// FUNCTION: LEGO1 0x100998e0
LegoTextureInfo* LegoTextureContainer::GetCached(LegoTextureInfo* p_textureInfo)
{
DDSURFACEDESC desc, newDesc;
DWORD width, height;
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
if (p_textureInfo->m_surface->GetSurfaceDesc(&desc) == DD_OK) {
width = desc.dwWidth;
height = desc.dwHeight;
}
for (LegoCachedTextureList::iterator it = m_cached.begin(); it != m_cached.end(); it++) {
if ((*it).second == FALSE && (*it).first->m_texture->AddRef() != 0 && (*it).first->m_texture->Release() == 1) {
if (!strcmp((*it).first->m_name, p_textureInfo->m_name)) {
LPDIRECTDRAWSURFACE surface = (*it).first->m_surface;
memset(&newDesc, 0, sizeof(newDesc));
newDesc.dwSize = sizeof(newDesc);
if (surface->GetSurfaceDesc(&newDesc) == DD_OK) {
if (newDesc.dwWidth == width && newDesc.dwHeight == height) {
(*it).second = TRUE;
(*it).first->m_texture->AddRef();
return (*it).first;
}
}
}
}
}
LegoTextureInfo* textureInfo = new LegoTextureInfo();
textureInfo->m_palette = p_textureInfo->m_palette;
textureInfo->m_palette->AddRef();
memset(&newDesc, 0, sizeof(newDesc));
newDesc.dwWidth = desc.dwWidth;
newDesc.dwHeight = desc.dwHeight;
newDesc.dwSize = sizeof(newDesc);
newDesc.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
newDesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
newDesc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
newDesc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
newDesc.ddpfPixelFormat.dwRGBBitCount = 8;
if (VideoManager()->GetDirect3D()->DirectDraw()->CreateSurface(&newDesc, &textureInfo->m_surface, NULL) == DD_OK) {
RECT rect;
rect.left = 0;
rect.right = newDesc.dwWidth - 1;
rect.top = 0;
rect.bottom = newDesc.dwHeight - 1;
textureInfo->m_surface->SetPalette(textureInfo->m_palette);
if (textureInfo->m_surface->BltFast(0, 0, p_textureInfo->m_surface, &rect, DDBLTFAST_WAIT) != DD_OK) {
textureInfo->m_surface->Release();
textureInfo->m_palette->Release();
delete textureInfo;
return NULL;
}
else {
if (((TglImpl::RendererImpl*) VideoManager()->GetRenderer())
->CreateTextureFromSurface(textureInfo->m_surface, &textureInfo->m_texture) != D3DRM_OK) {
textureInfo->m_surface->Release();
textureInfo->m_palette->Release();
delete textureInfo;
return NULL;
}
else {
textureInfo->m_texture->SetAppData((LPD3DRM_APPDATA) textureInfo);
m_cached.push_back(LegoCachedTexture(textureInfo, TRUE));
textureInfo->m_texture->AddRef();
if (textureInfo->m_name != NULL) {
delete[] textureInfo->m_name;
}
textureInfo->m_name = new char[strlen(p_textureInfo->m_name) + 1];
strcpy(textureInfo->m_name, p_textureInfo->m_name);
return textureInfo;
}
}
}
return NULL;
}
// FUNCTION: LEGO1 0x10099cc0
void LegoTextureContainer::EraseCached(LegoTextureInfo* p_textureInfo)
{
if (p_textureInfo == NULL) {
return;
}
#ifdef COMPAT_MODE
LegoCachedTextureList::iterator it;
for (it = m_cached.begin(); it != m_cached.end(); it++) {
#else
for (LegoCachedTextureList::iterator it = m_cached.begin(); it != m_cached.end(); it++) {
#endif
if ((*it).first == p_textureInfo) {
(*it).second = FALSE;
if (p_textureInfo->m_texture->Release() == 1) {
delete p_textureInfo;
m_cached.erase(it);
}
return;
}
}
}