From 8d2da3075c2e158871cce76e96870e62f256a8f8 Mon Sep 17 00:00:00 2001 From: Nathan Fulton Date: Sat, 29 Apr 2017 22:22:48 -0400 Subject: [PATCH] Read RGBA mini-map data --- game/SimUI.cpp | 36 +++++++++++++++++++++++------------- game/fogmap.cpp | 4 +--- game/ht.h | 10 +++++----- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/game/SimUI.cpp b/game/SimUI.cpp index 57498a6..9264bbc 100644 --- a/game/SimUI.cpp +++ b/game/SimUI.cpp @@ -2283,12 +2283,15 @@ MiniMapControl::MiniMapControl() m_xOff = 0; m_yOff = 0; m_tInvalidateLast = 0; + m_pbTileData = NULL; } MiniMapControl::~MiniMapControl() { gpmm = NULL; delete m_pbm; + delete[] m_pbTileData; + m_pbTileData = NULL; } int MiniMapControl::CalcWidth() @@ -2393,16 +2396,23 @@ bool MiniMapControl::Init(Form *pfrm, IniReader *pini, FindProp *pfind) TileMap *ptmap = gsim.GetLevel()->GetTileMap(); MiniTileSetHeader *pmtseth = ptmap->GetMiniTileSetHeader(m_nScale); - m_pbTileData = (byte *)(pmtseth + 1); m_pwTileMap = ptmap->m_pwMapData; m_pbFogMap = gsim.GetLevel()->GetFogMap()->GetMapPtr(); ggobm.GetMapSize(&m_ctx, &m_cty); - m_cbRowBytes = m_pbm->GetRowBytes(); - m_clrBlack = (byte)GetColor(kiclrBlack); - m_clrWhite = (byte)GetColor(kiclrWhite); - m_clrGalaxite = (byte)GetColor(kiclrGalaxite); + m_cbRowBytes = m_ctx * m_nScale; + m_clrBlack = GetColor(kiclrBlack); + m_clrWhite = GetColor(kiclrWhite); + m_clrGalaxite = GetColor(kiclrGalaxite); for (Side sideT = ksideNeutral; sideT < kcSides; sideT++) - m_aclrSide[sideT] = (byte)GetSideColor(sideT); + m_aclrSide[sideT] = GetSideColor(sideT); + + // Cache the tile data + + dword *pbtd = (dword *)(pmtseth + 1); + m_pbTileData = new dword[pmtseth->cTiles]; + for (int i = 0; i < pmtseth->cTiles; i++, pbtd++) { + m_pbTileData[i] = BigDword(*pbtd); + } // Calc powered radar flag @@ -2694,7 +2704,7 @@ void MiniMapControl::RedrawTRect(TRect *ptrc) // Redraw this rect - byte *pbDst = m_pbm->GetBits() + (long)ptrc->top * m_cbRowBytes * m_nScale + + dword *pbDst = m_pbm->GetBits() + (long)ptrc->top * m_cbRowBytes * m_nScale + ptrc->left * m_nScale + (long)m_yOff * m_cbRowBytes + m_xOff; int cbDstReturn = m_cbRowBytes - ptrc->Width() * m_nScale; long offset = (long)ptrc->top * m_ctx + ptrc->left; @@ -2774,7 +2784,7 @@ void MiniMapControl::RedrawTRect(TRect *ptrc) if (punt != NULL) { dword wf = punt->GetFlags(); if ((wf & (kfGobMobileUnit | kfGobActive)) != (kfGobMobileUnit)) { - byte clr; + dword clr; if (wf & kfGobSelected) { clr = m_clrWhite; } else { @@ -2802,11 +2812,11 @@ void MiniMapControl::RedrawTRect(TRect *ptrc) // Tile int nTile = (BigWord(*pwTileMap) & 0x7fc); - byte *pbSrc = &m_pbTileData[nTile]; - *pbDst++ = *pbSrc++; - *pbDst++ = *pbSrc++; - *(pbDst + m_cbRowBytes - 2) = *pbSrc++; - *(pbDst + m_cbRowBytes - 1) = *pbSrc++; + dword pbSrc = m_pbTileData[nTile]; + *pbDst++ = pbSrc; + *pbDst++ = pbSrc; + *(pbDst + m_cbRowBytes - 2) = pbSrc; + *(pbDst + m_cbRowBytes - 1) = pbSrc; continue; } pwTileMap += ctReturn; diff --git a/game/fogmap.cpp b/game/fogmap.cpp index 03a1d1e..96bac60 100644 --- a/game/fogmap.cpp +++ b/game/fogmap.cpp @@ -354,7 +354,6 @@ void FogMap::Draw(DibBitmap *pbm, int xMap, int yMap, UpdateMap *pupd) int cfInvalidNextScan = sizMap.cx - ctx; Assert(sizMap.cx >= ctx && sizMap.cy >= cty); - byte *pbDib = pbm->GetBits(); byte *pbMapT = &m_pbMap[ty * m_ctxMap + tx]; int cbNextScan = m_ctxMap - ctx; int xTile = tx * gcxTile - xMap; @@ -362,7 +361,7 @@ void FogMap::Draw(DibBitmap *pbm, int xMap, int yMap, UpdateMap *pupd) int xTileStart = xTile; for (int tyT = ty; tyT < ty + cty; tyT++) { int cEmpty = 0; - int xStart; + int xStart = 0; for (int txT = tx; txT < tx + ctx; txT++) { byte bFog = *pbMapT++ & kbfFogMask; if (*pfInvalid++ == false) @@ -439,7 +438,6 @@ void FogMap::DrawGalaxite(DibBitmap *pbm, int xMap, int yMap, UpdateMap *pupd, b int cty = (siz.cy + (gcyTile - 1)) / gcyTile + 1; if (ty + cty > m_ctyMap) cty = m_ctyMap - ty; - byte *pbDib = pbm->GetBits(); byte *pbMapT = &m_pbMap[ty * m_ctxMap + tx]; int cbNextScan = m_ctxMap - ctx; int xTile = tx * gcxTile - xMap; diff --git a/game/ht.h b/game/ht.h index 7fc0f08..131dbca 100644 --- a/game/ht.h +++ b/game/ht.h @@ -3451,14 +3451,14 @@ private: int m_yOff; TCoord m_ctx; TCoord m_cty; - byte *m_pbTileData; + dword *m_pbTileData; word *m_pwTileMap; int m_cbRowBytes; byte *m_pbFogMap; - byte m_clrWhite; - byte m_clrBlack; - byte m_clrGalaxite; - byte m_aclrSide[kcSides]; + Color m_clrWhite; + Color m_clrBlack; + Color m_clrGalaxite; + Color m_aclrSide[kcSides]; }; // Pip Meter Control