Make solidmask not overwrite background material

Also, remove Landscape.SetPix in favor of Landscape.SetPix2
lights3
Armin Burgmeier 2015-07-13 20:15:28 -04:00
parent c43ca4ce9a
commit 1f6825fb4b
3 changed files with 10 additions and 34 deletions

View File

@ -689,11 +689,6 @@ bool C4Landscape::ClearPix(int32_t tx, int32_t ty)
return SetPix2(tx, ty, bkgPix, bkgPix);
}
bool C4Landscape::SetPix(int32_t x, int32_t y, BYTE npix)
{
return SetPix2(x, y, npix, DefaultBkgMat(npix));
}
bool C4Landscape::SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
{
// check bounds
@ -720,11 +715,6 @@ bool C4Landscape::SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
return _SetPix2(x, y, fgPix, bgPix);
}
bool C4Landscape::_SetPix(int32_t x, int32_t y, BYTE npix)
{
return _SetPix2(x, y, npix, DefaultBkgMat(npix));
}
bool C4Landscape::_SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
{
if (Config.General.DebugRec)
@ -795,15 +785,6 @@ bool C4Landscape::_SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
return true;
}
bool C4Landscape::_SetPixIfMask(int32_t x, int32_t y, BYTE npix, BYTE nMask)
{
// set 8bpp-surface only!
if (_GetPix(x, y) == nMask)
_SetPix(x, y, npix);
// success
return true;
}
bool C4Landscape::CheckInstability(int32_t tx, int32_t ty, int32_t recursion_count)
{
int32_t mat=GetMat(tx,ty);
@ -859,9 +840,9 @@ void C4Landscape::RaiseTerrain(int32_t tx, int32_t ty, int32_t wdt)
for (cy=ty; (cy+1<GBackHgt) && !GBackSolid(cx,cy+1); cy++) {}
if (cy+1<GBackHgt) if (cy-ty<20)
{
cpix=GBackPix(cx,cy+1);
cpix=GetPix(cx,cy+1);
if (!MatVehicle(PixCol2Mat(cpix)))
while (cy>=ty) { SetPix(cx,cy,cpix); cy--; }
while (cy>=ty) { SetPix2(cx,cy,cpix,GetBackPix(cx,cy+1)); cy--; }
}
}
}
@ -1795,7 +1776,7 @@ bool C4Landscape::ApplyDiff(C4Group &hGroup)
if (pDiff->GetPix(x, y) != C4M_MaxTexIndex)
if (Surface8->_GetPix(x,y) != (byPix=pDiff->_GetPix(x,y)))
// material has changed here: readjust with new texture
SetPix(x,y, byPix);
Surface8->SetPix(x,y, byPix);
if (pDiffBkg->GetPix(x, y) != C4M_MaxTexIndex)
if (Surface8Bkg->_GetPix(x, y) != (byPix=pDiffBkg->_GetPix(x, y)))
Surface8Bkg->_SetPix(x, y, byPix);

View File

@ -109,11 +109,8 @@ public:
bool MapToLandscape();
bool ApplyDiff(C4Group &hGroup);
bool SetMode(int32_t iMode);
bool SetPix(int32_t x, int32_t y, BYTE npix); // set landscape pixel (bounds checked)
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix); // set landscape pixel (bounds checked)
bool _SetPix(int32_t x, int32_t y, BYTE npix); // set landsape pixel (bounds not checked)
bool _SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix); // set landsape pixel (bounds not checked)
bool _SetPixIfMask(int32_t x, int32_t y, BYTE npix, BYTE nMask) ; // set landscape pixel, if it matches nMask color (no bound-checks)
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx = 0, int32_t vy = 0, bool query_only=false); // modifies tx/ty to actual insertion position
bool InsertDeadMaterial(int32_t mat, int32_t tx, int32_t ty);
bool FindMatPath(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const;
@ -371,11 +368,8 @@ int32_t PixCol2Mat(BYTE pixc);
#define GBackWdt ::Landscape.Width
#define GBackHgt ::Landscape.Height
#define GBackPix ::Landscape.GetPix
#define SBackPix ::Landscape.SetPix
#define ClearBackPix ::Landscape.ClearPix
#define _GBackPix ::Landscape._GetPix
#define _SBackPix ::Landscape._SetPix
#define _SBackPixIfMask ::Landscape._SetPixIfMask
inline bool DensitySolid(int32_t dens)
{

View File

@ -100,7 +100,7 @@ void C4SolidMask::Put(bool fCauseInstability, C4TargetRect *pClipRect, bool fRes
pSolidMaskMatBuff[(ycnt+pClipRect->ty)*MatBuffPitch+xcnt+pClipRect->tx]=byPixel;
}
// and set mask
_SBackPix(iTx,iTy,MCVehic);
::Landscape.SetPix2(iTx,iTy,MCVehic,::Landscape.TRANSPARENT);
}
else
// no SolidMask: mark buffer as unused here
@ -166,7 +166,7 @@ void C4SolidMask::Put(bool fCauseInstability, C4TargetRect *pClipRect, bool fRes
pSolidMaskMatBuff[i + xcnt] = byPixel;
}
// set mask pix
_SBackPix(iTx, iTy, MCVehic);
::Landscape.SetPix2(iTx, iTy, MCVehic, ::Landscape.TRANSPARENT);
}
else if (!MaskPut)
// mark pix as unused in buf
@ -260,7 +260,8 @@ void C4SolidMask::Remove(bool fBackupAttachment)
// Non-SolidMask-pixels should not happen here, because all relevant landscape change routines should
// temp remove SolidMasks before
assert(_GBackPix(iTx,iTy) == MCVehic);
_SBackPixIfMask(iTx,iTy,*pPix,MCVehic);
if (::Landscape._GetPix(iTx, iTy) == MCVehic)
::Landscape._SetPix2(iTx, iTy, *pPix, ::Landscape.TRANSPARENT);
// Instability
::Landscape.CheckInstabilityRange(iTx,iTy);
}
@ -343,7 +344,7 @@ void C4SolidMask::RemoveTemporary(C4Rect where)
{
// restore
assert(GBackPix(x,y)==MCVehic);
_SBackPix(x, y, *pPix);
::Landscape.SetPix2(x, y, *pPix, ::Landscape.TRANSPARENT);
}
}
}
@ -364,7 +365,7 @@ void C4SolidMask::PutTemporary(C4Rect where)
{
// put
assert(GBackPix(x,y)==*pPix);
_SBackPix(x,y,MCVehic);
::Landscape.SetPix2(x, y, MCVehic, ::Landscape.TRANSPARENT);
}
}
}
@ -386,7 +387,7 @@ void C4SolidMask::Repair(C4Rect where)
// record changed landscape in MatBuff
*pPix = GBackPix(x,y);
// put
_SBackPix(x,y,MCVehic);
::Landscape.SetPix2(x, y, MCVehic, ::Landscape.TRANSPARENT);
}
}
}