forked from Mirrors/openclonk
Make the C4MapCreatorS2 create background maps
parent
eb98e73b76
commit
fe74cac663
|
@ -2329,11 +2329,10 @@ bool C4Landscape::CreateMapS2(C4Group &ScenFile, CSurface8*& sfcMap, CSurface8*&
|
|||
// read file
|
||||
pMapCreator->ReadFile(C4CFN_DynLandscape, &ScenFile);
|
||||
// render landscape
|
||||
CSurface8 * sfc = pMapCreator->Render(NULL);
|
||||
if(!pMapCreator->Render(NULL, sfcMap, sfcMapBkg))
|
||||
return false;
|
||||
|
||||
// keep map creator until script callbacks have been done
|
||||
sfcMap = sfc;
|
||||
sfcMapBkg = CreateDefaultBkgSurface(*sfcMap); // TODO: Replace this by what was actually generated!
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3603,12 +3602,15 @@ bool C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, co
|
|||
// read file
|
||||
MapCreator.ReadScript(szMapDef);
|
||||
// render map
|
||||
CSurface8 * sfcMap=MapCreator.Render(NULL);
|
||||
if (!sfcMap) return false;
|
||||
CSurface8* sfcMap = NULL;
|
||||
CSurface8* sfcMapBkg = NULL;
|
||||
if (!MapCreator.Render(NULL, sfcMap, sfcMapBkg))
|
||||
return false;
|
||||
// map it to the landscape
|
||||
bool fSuccess=MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
|
||||
bool fSuccess=MapToLandscape(sfcMap, sfcMapBkg, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
|
||||
// cleanup
|
||||
delete sfcMap;
|
||||
delete sfcMapBkg;
|
||||
// return whether successful
|
||||
return fSuccess;
|
||||
}
|
||||
|
@ -3627,13 +3629,15 @@ bool C4Landscape::DrawDefMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt,
|
|||
C4MCMap *pMap=pMapCreator->GetMap(szMapDef);
|
||||
if (!pMap) return false;
|
||||
pMap->SetSize(iMapWdt, iMapHgt);
|
||||
CSurface8 * sfcMap = pMapCreator->Render(szMapDef);
|
||||
if (sfcMap)
|
||||
CSurface8* sfcMap = NULL;
|
||||
CSurface8* sfcMapBkg = NULL;
|
||||
if(pMapCreator->Render(szMapDef, sfcMap, sfcMapBkg))
|
||||
{
|
||||
// map to landscape
|
||||
fSuccess=MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
|
||||
fSuccess = MapToLandscape(sfcMap, sfcMapBkg, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
|
||||
// cleanup
|
||||
delete sfcMap;
|
||||
delete sfcMapBkg;
|
||||
}
|
||||
// done
|
||||
return fSuccess;
|
||||
|
|
|
@ -310,6 +310,7 @@ C4MCOverlay::C4MCOverlay(C4MCNode *pOwner) : C4MCNode(pOwner)
|
|||
*Texture=0;
|
||||
Op=MCT_NONE;
|
||||
MatClr=0;
|
||||
MatClrBkg=0;
|
||||
Algorithm=NULL;
|
||||
Sub=false;
|
||||
ZoomX=ZoomY=0;
|
||||
|
@ -332,6 +333,7 @@ C4MCOverlay::C4MCOverlay(C4MCParser* pParser, C4MCNode *pOwner, C4MCOverlay &rTe
|
|||
Sub=rTemplate.Sub;
|
||||
ZoomX=rTemplate.ZoomX; ZoomY=rTemplate.ZoomY;
|
||||
MatClr=rTemplate.MatClr;
|
||||
MatClrBkg=rTemplate.MatClrBkg;
|
||||
Seed=rTemplate.Seed;
|
||||
Alpha=rTemplate.Alpha; Beta=rTemplate.Beta; Turbulence=rTemplate.Turbulence; Lambda=rTemplate.Lambda;
|
||||
Rotate=rTemplate.Rotate;
|
||||
|
@ -460,10 +462,17 @@ void C4MCOverlay::Evaluate()
|
|||
if (Inside<int32_t>(Material,0,MapCreator->MatMap->Num-1))
|
||||
{
|
||||
MatClr=MapCreator->TexMap->GetIndexMatTex(MapCreator->MatMap->Map[Material].Name, *Texture ? Texture : NULL);
|
||||
if (Sub) MatClr+=128;
|
||||
if(MatClr == 0 || !Sub)
|
||||
MatClrBkg = 0;
|
||||
else
|
||||
MatClrBkg = Mat2PixColDefault(MTunnel);
|
||||
}
|
||||
else
|
||||
{
|
||||
MatClr=0;
|
||||
MatClrBkg=0;
|
||||
}
|
||||
|
||||
// calc size
|
||||
if (Owner)
|
||||
{
|
||||
|
@ -559,7 +568,7 @@ bool C4MCOverlay::CheckMask(int32_t iX, int32_t iY)
|
|||
return (Algorithm->Function) (this, iX, iY)^Invert;
|
||||
}
|
||||
|
||||
bool C4MCOverlay::RenderPix(int32_t iX, int32_t iY, BYTE &rPix, C4MCTokenType eLastOp, bool fLastSet, bool fDraw, C4MCOverlay **ppPixelSetOverlay)
|
||||
bool C4MCOverlay::RenderPix(int32_t iX, int32_t iY, BYTE &rPix, BYTE &rPixBkg, C4MCTokenType eLastOp, bool fLastSet, bool fDraw, C4MCOverlay **ppPixelSetOverlay)
|
||||
{
|
||||
// algo match?
|
||||
bool SetThis=CheckMask(iX, iY);
|
||||
|
@ -589,6 +598,7 @@ bool C4MCOverlay::RenderPix(int32_t iX, int32_t iY, BYTE &rPix, C4MCTokenType eL
|
|||
if (fDraw && DoSet && !Mask)
|
||||
{
|
||||
rPix=MatClr;
|
||||
rPixBkg=MatClrBkg;
|
||||
if (ppPixelSetOverlay) *ppPixelSetOverlay = this;
|
||||
}
|
||||
bool fLastSetC=false; eLastOp=MCT_NONE;
|
||||
|
@ -596,7 +606,7 @@ bool C4MCOverlay::RenderPix(int32_t iX, int32_t iY, BYTE &rPix, C4MCTokenType eL
|
|||
for (C4MCNode *pChild=Child0; pChild; pChild=pChild->Next)
|
||||
if (C4MCOverlay *pOvrl=pChild->Overlay())
|
||||
{
|
||||
fLastSetC=pOvrl->RenderPix(iX, iY, rPix, eLastOp, fLastSetC, fDraw, ppPixelSetOverlay);
|
||||
fLastSetC=pOvrl->RenderPix(iX, iY, rPix, rPixBkg, eLastOp, fLastSetC, fDraw, ppPixelSetOverlay);
|
||||
if (Group && (pOvrl->Op == MCT_NONE))
|
||||
DoSet |= fLastSetC;
|
||||
eLastOp=pOvrl->Op;
|
||||
|
@ -615,7 +625,7 @@ bool C4MCOverlay::PeekPix(int32_t iX, int32_t iY)
|
|||
// loop through op chain
|
||||
while (1)
|
||||
{
|
||||
fLastSetC=pOvrl->RenderPix(iX, iY, Crap, eLastOp, fLastSetC, false);
|
||||
fLastSetC=pOvrl->RenderPix(iX, iY, Crap, Crap, eLastOp, fLastSetC, false);
|
||||
eLastOp=pOvrl->Op;
|
||||
if (!pOvrl->Op) break;
|
||||
// must be another overlay, since there's an operator
|
||||
|
@ -700,7 +710,7 @@ void C4MCMap::Default()
|
|||
MapCreator->Landscape->GetMapSize(Wdt, Hgt, MapCreator->PlayerCount);
|
||||
}
|
||||
|
||||
bool C4MCMap::RenderTo(BYTE *pToBuf, int32_t iPitch)
|
||||
bool C4MCMap::RenderTo(BYTE *pToBuf, BYTE *pToBufBkg, int32_t iPitch)
|
||||
{
|
||||
// set current render target
|
||||
if (MapCreator) MapCreator->pCurrentMap=this;
|
||||
|
@ -710,19 +720,23 @@ bool C4MCMap::RenderTo(BYTE *pToBuf, int32_t iPitch)
|
|||
for (int32_t iX=0; iX<Wdt; iX++)
|
||||
{
|
||||
// default to sky
|
||||
BYTE dummyPix;
|
||||
*pToBuf=0;
|
||||
if (pToBufBkg) *pToBufBkg=0;
|
||||
// render pixel value
|
||||
C4MCOverlay *pRenderedOverlay = NULL;
|
||||
RenderPix(iX, iY, *pToBuf, MCT_NONE, false, true, &pRenderedOverlay);
|
||||
RenderPix(iX, iY, *pToBuf, pToBufBkg ? *pToBufBkg : dummyPix, MCT_NONE, false, true, &pRenderedOverlay);
|
||||
// add draw-callback for rendered overlay
|
||||
if (pRenderedOverlay)
|
||||
if (pRenderedOverlay->pDrawFunc)
|
||||
pRenderedOverlay->pDrawFunc->EnablePixel(iX, iY);
|
||||
// next pixel
|
||||
pToBuf++;
|
||||
if (pToBufBkg) pToBufBkg++;
|
||||
}
|
||||
// next line
|
||||
pToBuf+=iPitch-Wdt;
|
||||
if (pToBufBkg) pToBufBkg+=iPitch-Wdt;
|
||||
}
|
||||
// reset render target
|
||||
if (MapCreator) MapCreator->pCurrentMap=NULL;
|
||||
|
@ -837,25 +851,30 @@ C4MCMap *C4MapCreatorS2::GetMap(const char *szMapName)
|
|||
return pMap;
|
||||
}
|
||||
|
||||
CSurface8 * C4MapCreatorS2::Render(const char *szMapName)
|
||||
bool C4MapCreatorS2::Render(const char *szMapName, CSurface8*& sfcMap, CSurface8*& sfcMapBkg)
|
||||
{
|
||||
assert(sfcMap == NULL);
|
||||
assert(sfcMapBkg == NULL);
|
||||
|
||||
// get map
|
||||
C4MCMap *pMap=GetMap(szMapName);
|
||||
if (!pMap) return NULL;
|
||||
if (!pMap) return false;
|
||||
|
||||
// get size
|
||||
int32_t sfcWdt, sfcHgt;
|
||||
sfcWdt=pMap->Wdt; sfcHgt=pMap->Hgt;
|
||||
if (!sfcWdt || !sfcHgt) return NULL;
|
||||
if (!sfcWdt || !sfcHgt) return false;
|
||||
|
||||
// create surface
|
||||
CSurface8 * sfc = new CSurface8(sfcWdt, sfcHgt);
|
||||
// create surfaces
|
||||
sfcMap = new CSurface8(sfcWdt, sfcHgt);
|
||||
sfcMapBkg = new CSurface8(sfcWdt, sfcHgt);
|
||||
assert(sfcMap->Pitch == sfcMapBkg->Pitch);
|
||||
|
||||
// render map to surface
|
||||
pMap->RenderTo(sfc->Bits, sfc->Pitch);
|
||||
pMap->RenderTo(sfcMap->Bits, sfcMapBkg->Bits, sfcMap->Pitch);
|
||||
|
||||
// success
|
||||
return sfc;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void DWordAlign(int &val)
|
||||
|
@ -880,7 +899,7 @@ BYTE *C4MapCreatorS2::RenderBuf(const char *szMapName, int32_t &sfcWdt, int32_t
|
|||
BYTE *buf=new BYTE[sfcWdt*sfcHgt];
|
||||
|
||||
// render and return it
|
||||
pMap->RenderTo(buf, sfcWdt);
|
||||
pMap->RenderTo(buf, NULL, sfcWdt);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -211,6 +211,7 @@ public:
|
|||
bool Sub; // tunnel bg?
|
||||
char Texture[C4M_MaxName+1]; // texture name
|
||||
BYTE MatClr; // resolved mat-tex color
|
||||
BYTE MatClrBkg; // resolved mat-tex color
|
||||
C4MCTokenType Op; // following operator
|
||||
C4MCAlgorithm *Algorithm; // algorithm to calc whether filled or not
|
||||
int32_t Turbulence, Lambda, Rotate; // turbulence factors; rotation angle
|
||||
|
@ -232,7 +233,7 @@ public:
|
|||
C4MCOverlay *FirstOfChain(); // go backwards in op chain until first overlay of chain
|
||||
|
||||
bool CheckMask(int32_t iX, int32_t iY); // check whether algorithms succeeds at iX/iY
|
||||
bool RenderPix(int32_t iX, int32_t iY, BYTE &rPix, C4MCTokenType eLastOp=MCT_NONE, bool fLastSet=false, bool fDraw=true, C4MCOverlay **ppPixelSetOverlay=NULL); // render this pixel
|
||||
bool RenderPix(int32_t iX, int32_t iY, BYTE &rPix, BYTE &rPixBkg, C4MCTokenType eLastOp=MCT_NONE, bool fLastSet=false, bool fDraw=true, C4MCOverlay **ppPixelSetOverlay=NULL); // render this pixel
|
||||
bool PeekPix(int32_t iX, int32_t iY); // check mask; regard operator chain
|
||||
bool InBounds(int32_t iX, int32_t iY) { return iX>=X && iY>=Y && iX<X+Wdt && iY<Y+Hgt; } // return whether point iX/iY is inside bounds
|
||||
|
||||
|
@ -282,7 +283,7 @@ protected:
|
|||
void Default(); // set default values for default presets
|
||||
|
||||
public:
|
||||
bool RenderTo(BYTE *pToBuf, int32_t iPitch); // render to buffer
|
||||
bool RenderTo(BYTE *pToBuf, BYTE *pToBufBkg, int32_t iPitch); // render to buffer
|
||||
void SetSize(int32_t iWdt, int32_t iHgt);
|
||||
|
||||
public:
|
||||
|
@ -308,7 +309,7 @@ public:
|
|||
C4MCMap *GetMap(const char *szMapName); // get map by name
|
||||
|
||||
public:
|
||||
CSurface8 * Render(const char *szMapName); // create map surface
|
||||
bool Render(const char *szMapName, CSurface8*& sfcMap, CSurface8*& sfcMapBkg); // create map surface
|
||||
BYTE *RenderBuf(const char *szMapName, int32_t &sfcWdt, int32_t &sfcHgt); // create buffer and render it
|
||||
|
||||
void SetC4SLandscape(C4SLandscape *pLandscape) // update source for map size
|
||||
|
|
Loading…
Reference in New Issue