Mercurial > might-and-magic-trilogy
diff LOD.cpp @ 1:ac0fb48cd27a
Texture, hwl loading, video player
author | Nomad |
---|---|
date | Tue, 09 Oct 2012 13:09:08 +0200 |
parents | 8b8875f5b359 |
children | 2ca04ccb612a |
line wrap: on
line diff
--- a/LOD.cpp Fri Oct 05 16:07:14 2012 +0200 +++ b/LOD.cpp Tue Oct 09 13:09:08 2012 +0200 @@ -3,6 +3,7 @@ #include "Allocator.h" #include "PaletteManager.h" #include "Viewport.h" +#include "Log.h" #include "mm7_data.h" @@ -380,7 +381,7 @@ v3 = 0; do { - v4 = v1->pHardwareSprites[v3].pTextureSurface; + v4 = (IDirectDrawSurface *)v1->pHardwareSprites[v3].pTextureSurface; if ( v4 && v4->IsLost() == DDERR_SURFACELOST ) { v5 = v1->pHardwareSprites[v3].pTexture; @@ -389,7 +390,7 @@ v5->Release(); v1->pHardwareSprites[v3].pTexture = 0; } - v6 = v1->pHardwareSprites[v3].pTextureSurface; + v6 = (IDirectDrawSurface *)v1->pHardwareSprites[v3].pTextureSurface; v6->Release(); v1->pHardwareSprites[v3].pTextureSurface = 0; pRenderer->MoveSpriteToDevice(&v1->pHardwareSprites[v3]); @@ -434,7 +435,7 @@ v6 = v1->pHardwareSprites; if ( v6 ) { - v7 = v6[v3].pTextureSurface; + v7 = (IDirectDrawSurface *)v6[v3].pTextureSurface; if ( v7 ) { v7->Release(); @@ -1135,22 +1136,17 @@ //----- (00450D68) -------------------------------------------------------- void Sprite::Release() { - Sprite *v1; // esi@1 - IDirectDrawSurface *v2; // eax@3 - IDirect3DTexture2 *v3; // eax@5 + if (pName) + pAllocator->FreeChunk((void *)pName); + pName = nullptr; - v1 = this; - if ( this->pName ) - pAllocator->FreeChunk((void *)this->pName); - v2 = v1->pTextureSurface; - if ( v2 ) - v2->Release(); - v3 = v1->pTexture; - if ( v3 ) - v3->Release(); - v1->pName = 0; - v1->pTextureSurface = 0; - v1->pTexture = 0; + if (pTextureSurface) + pTextureSurface->Release(); + pTextureSurface = nullptr; + + if (pTexture) + pTexture->Release(); + pTexture = nullptr; } @@ -2623,7 +2619,7 @@ pRenderer->LoadTexture( v3 - 2, *((short *)v3 + 17), - &v1->pHardwareSurfaces[v2], + (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], &v1->pHardwareTextures[v2]); } else @@ -2635,7 +2631,7 @@ pRenderer->LoadTexture( v5, *((short *)v3 + 17), - &v1->pHardwareSurfaces[v2], + (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], &v1->pHardwareTextures[v2]); free(v5); } @@ -2819,12 +2815,7 @@ //----- (0040FC08) -------------------------------------------------------- int LODFile_IconsBitmaps::LoadTextureFromLOD(Texture *pOutTex, const char *pContainer, enum TEXTURE_TYPE eTextureType) { - const char *v4; // ebx@1 - LODFile_IconsBitmaps *v5; // edi@1 - FILE *v6; // eax@1 Texture *v8; // esi@3 - char *v9; // eax@8 - void *v10; // ST24_4@8 size_t v11; // eax@14 enum TEXTURE_TYPE v12; // eax@14 signed int v13; // esi@14 @@ -2857,59 +2848,59 @@ int v40; // edx@40 signed int v41; // ecx@43 signed int v42; // ecx@48 - FILE *File; // [sp+14h] [bp-4h]@1 - v4 = pContainer; - v5 = this; - v6 = FindContainer(pContainer, 0); - File = v6; - if ( !v6 ) + //v4 = pContainer; + //v5 = this; + //v6 = FindContainer(pContainer, 0); + //File = v6; + auto pFile = FindContainer(pContainer, false); + if (!pFile) return -1; v8 = pOutTex; - fread(pOutTex, 1u, 0x30u, v6); - strcpy(v8->pName, v4); - if ( pRenderer->pRenderD3D && v8->pBits & 2 && v5->dword_011BA8 ) + fread(pOutTex, 1u, 0x30u, pFile); + strcpy(v8->pName, pContainer); + if (pRenderer->pRenderD3D && v8->pBits & 2 && dword_011BA8) { - if ( !v5->pHardwareSurfaces || !v5->pHardwareTextures ) + if ( !pHardwareSurfaces || !pHardwareTextures ) { - v5->pHardwareSurfaces = (struct IDirectDrawSurface **)operator new(0xFA0u); - v5->pHardwareTextures = (struct IDirect3DTexture2 **)operator new(0xFA0u); - v9 = (char *)operator new(0x3E8u); - v10 = v5->pHardwareSurfaces; - v5->ptr_011BB4 = v9; - memset(v10, 0, 0xFA0u); - memset(v5->pHardwareTextures, 0, 0xFA0u); - memset(v5->ptr_011BB4, 0, 0x3E8u); + pHardwareSurfaces = new IDirectDrawSurface *[1000]; + memset(pHardwareSurfaces, 0, 1000 * sizeof(IDirectDrawSurface4 *)); + + pHardwareTextures = new IDirect3DTexture2 *[1000]; + memset(pHardwareTextures, 0, 1000 * sizeof(IDirect3DTexture2 *)); + + ptr_011BB4 = new char[1000]; + memset(ptr_011BB4, 0, 1000); } - if ( *v4 != 'w' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'd' || v4[4] != 'r' ) + if (strcmp(pContainer, "wtrdr"))//*v4 != 'w' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'd' || v4[4] != 'r' ) { - if ( *v4 != 'W' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'T' || v4[4] != 'y' || v4[5] != 'l' ) + if (strcmp(pContainer, "WtrTyl"))//if ( *v4 != 'W' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'T' || v4[4] != 'y' || v4[5] != 'l' ) { - v14 = v5->uNumLoadedFiles; + v14 = uNumLoadedFiles; } else { - pRenderer->field_1036AC_bitmapid = v5->uNumLoadedFiles; - v14 = v5->uNumLoadedFiles; + pRenderer->field_1036AC_bitmapid = uNumLoadedFiles; + v14 = uNumLoadedFiles; } v13 = pRenderer->LoadTexture( - v4, - LOWORD(v8->palette), - &v5->pHardwareSurfaces[v14], - &v5->pHardwareTextures[v14]); + pContainer, + v8->palette_id1, + (IDirectDrawSurface4 **)&pHardwareSurfaces[v14], + &pHardwareTextures[v14]); } else { - v11 = strlen(v4); + v11 = strlen(pContainer); v12 = (enum TEXTURE_TYPE)(int)operator new(v11 + 2); eTextureType = v12; *(char *)v12 = 104; - strcpy((char *)(v12 + 1), v4); + strcpy((char *)(v12 + 1), pContainer); v13 = pRenderer->LoadTexture( (const char *)eTextureType, - LOWORD(v8->palette), - &v5->pHardwareSurfaces[v5->uNumLoadedFiles], - &v5->pHardwareTextures[v5->uNumLoadedFiles]); + v8->palette_id1, + (IDirectDrawSurface4 **)&pHardwareSurfaces[uNumLoadedFiles], + &pHardwareTextures[uNumLoadedFiles]); free((void *)eTextureType); } return v13; @@ -2917,12 +2908,12 @@ v15 = v8->uTextureSize; v16 = &v8->uDecompressedSize; pOutTex = (Texture *)v8->uTextureSize; - if ( !v8->uDecompressedSize || v5->dword_011BA4 ) + if ( !v8->uDecompressedSize || dword_011BA4 ) { v20 = pAllocator; v32 = pAllocator->AllocNamedChunk(v8->pLevelOfDetail0, v15, v8->pName); v8->pLevelOfDetail0 = (unsigned __int8 *)v32; - fread(v32, 1u, (size_t)pOutTex, File); + fread(v32, 1u, (size_t)pOutTex, pFile); } else { @@ -2930,7 +2921,7 @@ v18 = v8->uTextureSize; pContainer = (const char *)v17; v19 = malloc(v18); - fread(v19, 1u, (size_t)pOutTex, File); + fread(v19, 1u, (size_t)pOutTex, pFile); zlib::MemUnzip((void *)pContainer, &v8->uDecompressedSize, v19, v8->uTextureSize); v8->uTextureSize = *v16; free(v19); @@ -2976,7 +2967,7 @@ { v33 = pAllocator->AllocNamedChunk(v8->pPalette24, 0x300u, v8->pName); v8->pPalette24 = (unsigned __int8 *)v33; - fread(v33, 1u, 0x300u, File); + fread(v33, 1u, 0x300u, pFile); } else { @@ -2987,14 +2978,14 @@ v38 = 0; do { - fread((char *)&eTextureType + 3, 1u, 1u, File); - fread((char *)&pContainer + 3, 1u, 1u, File); - v39 = fread((char *)&pOutTex + 3, 1u, 1u, File); - LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(v5->uTextureRedBits))); - v8->pPalette16[v38] = v39 << (LOBYTE(v5->uTextureBlueBits) + LOBYTE(v5->uTextureGreenBits)); - LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(v5->uTextureGreenBits))); - v8->pPalette16[v38] += v40 << v5->uTextureBlueBits; - v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(v5->uTextureBlueBits))); + fread((char *)&eTextureType + 3, 1u, 1u, pFile); + fread((char *)&pContainer + 3, 1u, 1u, pFile); + v39 = fread((char *)&pOutTex + 3, 1u, 1u, pFile); + LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(uTextureRedBits))); + v8->pPalette16[v38] = v39 << (LOBYTE(uTextureBlueBits) + LOBYTE(uTextureGreenBits)); + LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(uTextureGreenBits))); + v8->pPalette16[v38] += v40 << uTextureBlueBits; + v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(uTextureBlueBits))); ++v38; } while ( v38 < 256 ); @@ -3120,50 +3111,57 @@ //----- (0040FB20) -------------------------------------------------------- unsigned int LODFile_IconsBitmaps::LoadTexture(const char *pContainer, enum TEXTURE_TYPE uTextureType) { - LODFile_IconsBitmaps *v3; // esi@1 - unsigned int v4; // edi@1 - Texture *v5; // ebx@2 + //LODFile_IconsBitmaps *v3; // esi@1 + //unsigned int v4; // edi@1 + //Texture *v5; // ebx@2 unsigned int v6; // ebx@8 const char *Sourcea; // [sp+14h] [bp+8h]@9 - v3 = this; - v4 = 0; + //v3 = this; + //v4 = 0; areWeLoadingTexture = 1; - if ( (signed int)this->uNumLoadedFiles <= 0 ) - { -LABEL_5: - if ( (signed int)v3->uNumLoadedFiles >= 1000 ) + + for (uint i = 0; i < uNumLoadedFiles; ++i) + if (!strcmpi(pContainer, pTextures[i].pName)) + return i; + +// if (!uNumLoadedFiles) +// { +//LABEL_5: + if (uNumLoadedFiles >= 1000) + { + Log::Warning(L"Maximum texture number exceeded"); AbortWithError(); - if ( v3->LoadTextureFromLOD(&v3->pTextures[v3->uNumLoadedFiles], pContainer, uTextureType) == -1 ) + } + if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer, uTextureType) == -1) { v6 = 0; - if ( (signed int)v3->uNumLoadedFiles > 0 ) + if (uNumLoadedFiles > 0) { - Sourcea = (const char *)v3->pTextures; + Sourcea = (const char *)pTextures; while ( _strcmpi(Sourcea, "pending") ) { Sourcea += 72; ++v6; - if ( (signed int)v6 >= (signed int)v3->uNumLoadedFiles ) + if (v6 >= uNumLoadedFiles) goto LABEL_15; } return v6; } LABEL_15: - v3->LoadTextureFromLOD(&v3->pTextures[v3->uNumLoadedFiles], "pending", uTextureType); + LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", uTextureType); } areWeLoadingTexture = 0; - ++v3->uNumLoadedFiles; - return v3->uNumLoadedFiles - 1; - } - v5 = this->pTextures; - while ( _strcmpi(v5->pName, pContainer) ) - { - ++v4; - ++v5; - if ( (signed int)v4 >= (signed int)v3->uNumLoadedFiles ) - goto LABEL_5; - } - return v4; + ++uNumLoadedFiles; + return uNumLoadedFiles - 1; +// } +// v5 = pTextures; +// while ( _strcmpi(v5->pName, pContainer) ) +// { +// ++v4; +// ++v5; +// if (v4 >= uNumLoadedFiles ) +// goto LABEL_5; +// } +// return v4; } -// 506128: using guessed type int areWeLoadingTexture; \ No newline at end of file