Mercurial > mm7
diff Sprites.cpp @ 1477:7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Added support for most of mm6 resources, placeholders for mm8 resources.
Fixed few C4258
author | Nomad |
---|---|
date | Wed, 28 Aug 2013 18:43:07 +0200 |
parents | 86a83e12d795 |
children | a27cdb3d753e 86cb7398d2a8 |
line wrap: on
line diff
--- a/Sprites.cpp Wed Aug 28 14:39:01 2013 +0600 +++ b/Sprites.cpp Wed Aug 28 18:43:07 2013 +0200 @@ -245,7 +245,7 @@ while ( 1 ) { int searchRange = endPos - startPos; - int middleFrameIndex = (endPos - startPos) / 2 + startPos; + int middleFrameIndex = startPos + (endPos - startPos) / 2; int comparisonResult = _stricmp(pSpriteName, this->pSpritePFrames[middleFrameIndex]->pIconName); if ( !comparisonResult ) { @@ -360,23 +360,68 @@ } //----- (0044D9D7) -------------------------------------------------------- -void SpriteFrameTable::FromFile(void *pSerialized) +void SpriteFrameTable::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) { - //v2 = this; - uNumSpriteFrames = *(int *)pSerialized; - uNumEFrames = *((int *)pSerialized + 1); - //memcpy(this, pSerialized, 4u); - //memcpy(&v2->field_4, (char *)pSerialized + 4, 4u); - pSpriteSFrames = (SpriteFrame *)pAllocator->AllocNamedChunk(pSpriteSFrames, 60 * uNumSpriteFrames, "S Frames"); - pSpriteEFrames = (__int16 *)pAllocator->AllocNamedChunk(pSpriteEFrames, 2 * uNumSpriteFrames, "E Frames"); - //v3 = pAllocator->AllocNamedChunk(pSpritePFrames, 4 * uNumSpriteFrames, "P Frames"); - //v4 = v2->uNumSpriteFrames; + uint num_mm6_frames = 0; + uint num_mm6_eframes = 0; + if (data_mm6) + { + num_mm6_frames = *(int *)data_mm6; + num_mm6_eframes = *((int *)data_mm6 + 1); + } + + uint num_mm7_frames = 0; + uint num_mm7_eframes = 0; + if (data_mm7) + { + num_mm7_frames = *(int *)data_mm7; + num_mm7_eframes = *((int *)data_mm7 + 1); + } + + uint num_mm8_frames = 0; + uint num_mm8_eframes = 0; + if (data_mm8) + { + num_mm8_frames = *(int *)data_mm8; + num_mm8_eframes = *((int *)data_mm8 + 1); + } + + uNumSpriteFrames = num_mm6_frames + num_mm7_frames + num_mm8_frames; + uNumEFrames = num_mm6_eframes + num_mm7_eframes + num_mm8_eframes; + + pSpriteSFrames = (SpriteFrame *)pAllocator->AllocNamedChunk(pSpriteSFrames, uNumSpriteFrames * sizeof(SpriteFrame), "S Frames"); + pSpriteEFrames = (__int16 *)pAllocator->AllocNamedChunk(pSpriteEFrames, uNumSpriteFrames * sizeof(short), "E Frames"); + pSpritePFrames = (SpriteFrame **)pAllocator->AllocNamedChunk(pSpritePFrames, 4 * uNumSpriteFrames, "P Frames"); - auto uSpriteFramesSize = 60 * uNumSpriteFrames; - memcpy(pSpriteSFrames, (char *)pSerialized + 8, uSpriteFramesSize); - memcpy(pSpriteEFrames, (char *)pSerialized + uSpriteFramesSize + 8, 2 * uNumEFrames); - for (uint i = 0; i < uNumSpriteFrames; ++i) + + auto mm7_frames_size = num_mm7_frames * sizeof(SpriteFrame); + memcpy(pSpriteSFrames, (char *)data_mm7 + 8, mm7_frames_size); + memcpy(pSpriteEFrames, (char *)data_mm7 + 8 + mm7_frames_size, 2 * num_mm7_eframes); + + auto mm6_frames_size = num_mm6_frames * sizeof(SpriteFrame_mm6); + for (uint i = 0; i < num_mm6_frames; ++i) + { + memcpy(pSpriteSFrames + num_mm7_frames + i, (char *)data_mm6 + 8 + i * sizeof(SpriteFrame_mm6), sizeof(SpriteFrame_mm6)); + pSpriteSFrames[num_mm7_frames + i].uAnimLength = 0; + } + memcpy(pSpriteEFrames + num_mm7_frames, (char *)data_mm6 + 8 + mm6_frames_size, 2 * num_mm6_eframes); + + if (data_mm8) __debugbreak(); + auto mm8_frames_size = num_mm8_frames * sizeof(SpriteFrame); + memcpy(pSpriteSFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8, mm8_frames_size); + memcpy(pSpriteEFrames + num_mm6_frames + num_mm7_frames, (char *)data_mm8 + 8 + mm8_frames_size, 2 * num_mm8_eframes); + + for (uint i = 0; i < num_mm7_frames; ++i) pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]]; + + for (uint i = num_mm7_frames; i < num_mm6_frames + num_mm7_frames; ++i) + pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i] + num_mm7_frames]; + + for (uint i = num_mm6_frames + num_mm7_frames; i < num_mm6_frames + num_mm7_frames + num_mm8_frames; ++i) + pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i] + num_mm6_frames + num_mm7_frames]; + + //for (uint i = 0; i < uNumSpriteFrames; ++i) + // pSpritePFrames[i] = &pSpriteSFrames[pSpriteEFrames[i]]; } //----- (0044DA92) --------------------------------------------------------