Material: Remove color field, use textures as is

This also removes ColorByMaterial, which was alread unused in CE and CR.
stable-5.2
Günther Brammer 2009-07-24 23:50:04 +02:00
parent 1889d79478
commit fc5c384681
29 changed files with 31 additions and 149 deletions

View File

@ -204,7 +204,6 @@ class C4Def: public C4PropList
int32_t NoComponentMass;
int32_t NoStabilize;
char STimerCall[C4D_MaxIDLen];
char ColorByMaterial[C4M_MaxName+1];
int32_t ClosedContainer; // if set, contained objects are not damaged by lava/acid etc. 1: Contained objects can't view out; 2: They can
int32_t SilentCommands; // if set, no command failure messages are printed
int32_t NoBurnDamage; // if set, the object won't take damage when burning
@ -292,7 +291,6 @@ class C4Def: public C4PropList
virtual C4Def* GetDef() { return this; }
protected:
bool LoadPortraits(C4Group &hGroup);
BOOL ColorizeByMaterial(class C4MaterialMap &rMats, BYTE bGBM);
BOOL LoadActMap(C4Group &hGroup);
void CrossMapActMap();
private:
@ -346,7 +344,6 @@ class C4DefList
int32_t GetDefCount(DWORD dwCategory = C4D_All);
int32_t GetIndex(C4ID id);
int32_t RemoveTemporary();
int32_t ColorizeByMaterial(C4MaterialMap &rMats, BYTE bGBM);
int32_t CheckEngineVersion(int32_t ver1, int32_t ver2, int32_t ver3, int32_t ver4);
int32_t CheckRequireDef();
void Draw(C4ID id, C4Facet &cgo, BOOL fSelected, int32_t iColor);

View File

@ -54,7 +54,6 @@ class C4DefGraphics
bool LoadBitmap(C4Group &hGroup, const char *szFilename, const char *szFilenamePNG, const char *szOverlayPNG, bool fColorByOwner); // load specified graphics from group
bool LoadBitmaps(C4Group &hGroup, bool fColorByOwner); // load graphics from group
bool ColorizeByMaterial(int32_t iMat, C4MaterialMap &rMats, BYTE bGBM); // colorize all graphics by material
C4DefGraphics *Get(const char *szGrpName); // get graphics by name
void Clear(); // clear fields; delete additional graphics
bool IsColorByOwner() // returns whether ColorByOwner-surfaces have been created

View File

@ -32,7 +32,6 @@
#define C4MatOv_Exact 1
#define C4MatOv_None 2
#define C4MatOv_HugeZoom 4
#define C4MatOv_Monochrome 8
enum MaterialInteractionEvent
{
@ -81,8 +80,6 @@ class C4MaterialCore
std::vector<C4MaterialReaction> CustomReactionList;
public:
char Name[C4M_MaxName+1];
uint32_t Color[C4M_ColsPerMat*3];
uint32_t Alpha[C4M_ColsPerMat*2];
int32_t MapChunkType;
int32_t Density;
int32_t Friction;
@ -128,7 +125,6 @@ class C4MaterialCore
void Clear();
void Default();
BOOL Load(C4Group &hGroup, const char *szEntryName);
DWORD GetDWordColor(int32_t iIndex); // get indexed material color as DWord
void CompileFunc(StdCompiler *pComp);
};

View File

@ -53,7 +53,7 @@ class C4TexMapEntry
const char *GetTextureName() const { return Texture.getData(); }
int32_t GetMaterialIndex() const { return iMaterialIndex; }
C4Material *GetMaterial() const { return pMaterial; }
const CPattern &getPattern() const { return MatPattern; }
const CPattern &GetPattern() const { return MatPattern; }
void Clear();
bool Create(const char *szMaterial, const char *szTexture);
bool Init();

View File

@ -85,7 +85,6 @@ void C4Def::DefaultDefCore()
BuildTurnTo=C4ID_None;
STimerCall[0]=0;
Timer=35;
ColorByMaterial[0]=0;
GrowthType=0;
Basement=0;
CanBeBase=0;
@ -345,7 +344,6 @@ void C4Def::CompileFunc(StdCompiler *pComp)
pComp->Value(mkNamingAdapt(Float, "Float", 0 ));
pComp->Value(mkNamingAdapt(ContainBlast, "ContainBlast", 0 ));
pComp->Value(mkNamingAdapt(ColorByOwner, "ColorByOwner", 0 ));
pComp->Value(mkNamingAdapt(toC4CStr(ColorByMaterial), "ColorByMaterial", "" ));
pComp->Value(mkNamingAdapt(NoHorizontalMove, "HorizontalFix", 0 ));
pComp->Value(mkNamingAdapt(BorderBound, "BorderBound", 0 ));
pComp->Value(mkNamingAdapt(LiftTop, "LiftTop", 0 ));
@ -699,18 +697,6 @@ BOOL C4Def::Load(C4Group &hGroup,
return TRUE;
}
BOOL C4Def::ColorizeByMaterial(C4MaterialMap &rMats, BYTE bGBM)
{
if (ColorByMaterial[0])
{
int32_t mat=rMats.Get(ColorByMaterial);
if (mat==MNone) { LogF("C4Def::ColorizeByMaterial: mat %s not defined", ColorByMaterial); return FALSE; }
if (!Graphics.ColorizeByMaterial(mat, rMats, bGBM)) return FALSE;
}
// success
return TRUE;
}
void C4Def::Draw(C4Facet &cgo, BOOL fSelected, DWORD iColor, C4Object *pObj, int32_t iPhaseX, int32_t iPhaseY)
{
@ -1196,16 +1182,6 @@ int32_t C4DefList::CheckRequireDef()
return rcount;
}
int32_t C4DefList::ColorizeByMaterial(C4MaterialMap &rMats, BYTE bGBM)
{
C4Def *cdef;
int32_t rval=0;
for (cdef=FirstDef; cdef; cdef=cdef->Next)
if (cdef->ColorizeByMaterial(rMats,bGBM))
rval++;
return rval;
}
void C4DefList::Draw(C4ID id, C4Facet &cgo, BOOL fSelected, int32_t iColor)
{
C4Def *cdef = ID2Def(id);

View File

@ -227,20 +227,6 @@ bool C4DefGraphics::LoadBitmaps(C4Group &hGroup, bool fColorByOwner)
return true;
}
bool C4DefGraphics::ColorizeByMaterial(int32_t iMat, C4MaterialMap &rMats, BYTE bGBM)
{
SURFACE sfcBitmap = GetBitmap(); // first bitmap only
if (sfcBitmap)
{
DWORD dwMatColors[C4M_ColsPerMat];
for (int32_t i=0; i<C4M_ColsPerMat; ++i)
dwMatColors[i] = rMats.Map[iMat].GetDWordColor(i);
Application.DDraw->SurfaceAllowColor(sfcBitmap,dwMatColors,C4M_ColsPerMat,TRUE);
}
// colorize other graphics
if (pNext) return pNext->ColorizeByMaterial(iMat, rMats, bGBM); else return true;
}
C4DefGraphics *C4DefGraphics::Get(const char *szGrpName)
{
// no group or empty string: base graphics

View File

@ -2272,19 +2272,15 @@ BOOL C4Game::InitGame(C4Group &hGroup, bool fLoadSection, bool fLoadSky)
// After defs to get overloading priority
if (!LoadScenarioScripts())
{ LogFatal(LoadResStr("IDS_PRC_FAIL")); return FALSE; }
SetInitProgress(56);
SetInitProgress(57);
// Link scripts
if (!LinkScriptEngine()) return FALSE;
SetInitProgress(57);
SetInitProgress(58);
// Materials
if (!InitMaterialTexture())
{ LogFatal(LoadResStr("IDS_PRC_MATERROR")); return FALSE; }
SetInitProgress(58);
// Colorize defs by material
::Definitions.ColorizeByMaterial(::MaterialMap,GBM);
SetInitProgress(59);
// Videos

View File

@ -307,7 +307,7 @@ void C4Landscape::Draw(C4TargetFacet &cgo, int32_t iPlayer)
const CSurface * Surfaces[C4M_MaxTexIndex];
if (Config.Graphics.HighResLandscape)
for (int i = 0; i < C4M_MaxTexIndex; ++i)
Surfaces[i] = ::TextureMap.GetEntry(i)->getPattern().getSurface();
Surfaces[i] = ::TextureMap.GetEntry(i)->GetPattern().getSurface();
Application.DDraw->BlitLandscape(Surface32, cgo.TargetX, cgo.TargetY, cgo.Surface,
cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt,
Config.Graphics.HighResLandscape ? Surfaces : 0);
@ -2558,15 +2558,14 @@ DWORD C4Landscape::GetClrByTex(int32_t iX, int32_t iY)
{
// Get pixel and default color
BYTE pix = _GetPix(iX, iY);
DWORD dwPix = Surface8->pPal->GetClr(pix);
// get texture map entry for pixel
const C4TexMapEntry *pTex;
if(pix && (pTex = ::TextureMap.GetEntry(PixCol2Tex(pix))))
{
// pattern color
pTex->getPattern().PatternClr(iX, iY, pix, dwPix, Application.DDraw->Pal);
return pTex->GetPattern().PatternClr(iX, iY);
}
return dwPix;
return Surface8->pPal->GetClr(pix);
}
BOOL C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef)
@ -2769,13 +2768,14 @@ bool C4Landscape::Mat2Pal()
if(!pTex || pTex->isNull())
continue;
// colors
DWORD dwPix = pTex->GetPattern().PatternClr(0, 0);
for (rgb=0; rgb<3; rgb++)
Surface8->pPal->Colors[MatTex2PixCol(tex)*3+rgb]
= Surface8->pPal->Colors[(MatTex2PixCol(tex)+IFT)*3+rgb]
= pTex->GetMaterial()->Color[rgb];
= dwPix >> ((2-rgb) * 8);
// alpha
Surface8->pPal->Alpha[MatTex2PixCol(tex)] = pTex->GetMaterial()->Alpha[0];
Surface8->pPal->Alpha[MatTex2PixCol(tex)+IFT] = pTex->GetMaterial()->Alpha[C4M_ColsPerMat];
Surface8->pPal->Alpha[MatTex2PixCol(tex)] = 0;
Surface8->pPal->Alpha[MatTex2PixCol(tex)+IFT] = 0;
}
// success
return true;

View File

@ -110,9 +110,6 @@ void C4MaterialCore::Clear()
sBelowTempConvertTo.Clear();
sAboveTempConvertTo.Clear();
*Name='\0';
int32_t i;
for (i=0; i<C4M_ColsPerMat*3; ++i) Color[i]=0;
for (i=0; i<C4M_ColsPerMat*2; ++i) Alpha[i]=0;
MapChunkType = 0;
Density = 0;
Friction = 0;
@ -180,22 +177,11 @@ BOOL C4MaterialCore::Load(C4Group &hGroup,
return TRUE;
}
DWORD C4MaterialCore::GetDWordColor(int32_t iIndex)
{
if (iIndex<0) return 0;
iIndex %= (C4M_ColsPerMat*2);
int32_t iClrIndex = iIndex % C4M_ColsPerMat;
return RGB(Color[iClrIndex*3+2],Color[iClrIndex*3+1],Color[iClrIndex*3]) | (Alpha[iIndex]<<24);
}
void C4MaterialCore::CompileFunc(StdCompiler *pComp)
{
if (pComp->isCompiler()) Clear();
pComp->Name("Material");
pComp->Value(mkNamingAdapt(toC4CStr(Name), "Name", "" ));
pComp->Value(mkNamingAdapt(toC4CArrU(Color), "Color" ));
pComp->Value(mkNamingAdapt(toC4CArrU(Color), "ColorX", Color ));
pComp->Value(mkNamingAdapt(toC4CArrU(Alpha), "Alpha" ));
pComp->Value(mkNamingAdapt(ColorAnimation, "ColorAnimation", 0 ));
pComp->Value(mkNamingAdapt(MapChunkType, "Shape", 0 ));
pComp->Value(mkNamingAdapt(Density, "Density", 0 ));

View File

@ -91,13 +91,11 @@ bool C4TexMapEntry::Init()
}
// Get overlay properties
int32_t iOverlayType=pMaterial->OverlayType;
bool fMono = !!(iOverlayType & C4MatOv_Monochrome);
int32_t iZoom=0;
if (iOverlayType & C4MatOv_Exact) iZoom=1;
if (iOverlayType & C4MatOv_HugeZoom) iZoom=4;
// Create pattern
MatPattern.Set(sfcTexture->Surface32, iZoom, fMono);
MatPattern.SetColors(pMaterial->Color, pMaterial->Alpha);
MatPattern.Set(sfcTexture->Surface32, iZoom);
return true;
}
@ -405,17 +403,14 @@ void C4TextureMap::StoreMapPalette(BYTE *bypPalette, C4MaterialMap &rMaterial)
for(i = 0; i < C4M_MaxTexIndex; i++)
{
// Find material
C4Material *pMat = Entry[i].GetMaterial();
if (pMat)
{
bypPalette[3*i+0]=pMat->Color[6];
bypPalette[3*i+1]=pMat->Color[7];
bypPalette[3*i+2]=pMat->Color[8];
bypPalette[3*(i+IFT)+0]=pMat->Color[3];
bypPalette[3*(i+IFT)+1]=pMat->Color[4];
bypPalette[3*(i+IFT)+2]=pMat->Color[5];
fSet[i] = fSet[i + IFT] = true;
}
DWORD dwPix = Entry[i].GetPattern().PatternClr(0, 0);
bypPalette[3*i+0]=dwPix >> 16;
bypPalette[3*i+1]=dwPix >> 8;
bypPalette[3*i+2]=dwPix;
bypPalette[3*(i+IFT)+0]=dwPix >> 16;
bypPalette[3*(i+IFT)+1]=dwPix >> 8;
bypPalette[3*(i+IFT)+2]=dwPix | 0x0F; // IFT arbitrarily gets more blue
fSet[i] = fSet[i + IFT] = true;
}
// Crosscheck colors, change equal palette entries
for(i = 0; i < 256; i++) if(fSet[i])

View File

@ -671,8 +671,7 @@ void C4ToolsDlg::UpdatePreview()
// Sky material: sky as pattern only
if (SEqual(Material,C4TLS_MatSky))
{
Pattern.SetColors(0, 0);
Pattern.Set(::Landscape.Sky.Surface, 0, false);
Pattern.Set(::Landscape.Sky.Surface, 0);
}
// Material-Texture
else
@ -688,7 +687,7 @@ void C4ToolsDlg::UpdatePreview()
if(pTex)
{
// Set drawing pattern
Pattern = pTex->getPattern();
Pattern = pTex->GetPattern();
}
}
}

View File

@ -1,6 +1,5 @@
[Material]
Name=Acid
Color=128,128,128,128,128,128,128,128,128
ColorAnimation=1
Density=25
Instable=1

View File

@ -1,6 +1,5 @@
[Material]
Name=Coal
Color=128,128,128,128,128,128,128,128,128
Shape=3
Density=50
Friction=75

View File

@ -1,6 +1,5 @@
[Material]
Name=DuroLava
Color=245,200,15,251,240,15,248,220,18
ColorAnimation=1
Density=25
Instable=1

View File

@ -1,6 +1,5 @@
[Material]
Name=Earth
Color=128,128,128,128,128,128,128,128,128
Shape=2
Density=50
Friction=80

View File

@ -1,6 +1,5 @@
[Material]
Name=Gold
Color=128,128,128,128,128,128,128,128,128
Shape=3
Density=50
Friction=100

View File

@ -1,6 +1,5 @@
[Material]
Name=Granite
Color=128,128,128,128,128,128,128,128,128
Shape=3
Density=50
Friction=100

View File

@ -1,6 +1,5 @@
[Material]
Name=Ice
Color=128,128,128,128,128,128,128,128,128
Shape=1
Density=50
Friction=15

View File

@ -1,6 +1,5 @@
[Material]
Name=Lava
Color=128,128,128,128,128,128,128,128,128
ColorAnimation=1
Density=25
Instable=1

View File

@ -1,6 +1,5 @@
[Material]
Name=Ore
Color=128,128,128,128,128,128,128,128,128
Shape=3
Density=50
Friction=100

View File

@ -1,6 +1,5 @@
[Material]
Name=Rock
Color=128,128,128,128,128,128,128,128,128
Shape=3
Density=50
Friction=100

View File

@ -1,6 +1,5 @@
[Material]
Name=Sand
Color=128,128,128,128,128,128,128,128,128
Shape=2
Density=50
Friction=80

View File

@ -1,6 +1,5 @@
[Material]
Name=Snow
Color=128,128,128,128,128,128,128,128,128
Shape=2
Density=50
Friction=40

View File

@ -1,6 +1,5 @@
[Material]
Name=Sulphur
Color=128,128,128,128,128,128,128,128,128
Shape=3
Density=50
Friction=75

View File

@ -1,6 +1,5 @@
[Material]
Name=Tunnel
Color=128,128,128,128,128,128,128,128,128
Shape=2
Placement=5
TextureOverlay=tunnel

View File

@ -1,6 +1,5 @@
[Material]
Name=Vehicle
Color=120,100,70,120,100,70,120,100,70
Density=100
Friction=100

View File

@ -1,7 +1,5 @@
[Material]
Name=Water
Color=128,128,128,128,128,128,128,128,128
Alpha=0,0,0,0,0,0
ColorAnimation=1
Density=25
Instable=1

View File

@ -131,20 +131,11 @@ class CPattern
uint32_t * CachedPattern; int Wdt; int Hgt;
// pattern zoom factor; 0 means no zoom
int Zoom;
// pattern is to be applied monochromatic
bool Monochrome;
// color array for old-style patterns
uint32_t *pClrs;
// alpha array for old-style patterns
uint32_t *pAlpha;
public:
CPattern& operator=(const CPattern&);
const CSurface *getSurface() const { return sfcPattern32; }
bool PatternClr(int iX, int iY, BYTE &byClr, DWORD &dwClr, CStdPalette &rPal) const; // apply pattern to color
bool IsNewStyle() { if (sfcPattern32) return true; }
bool Set(class CSurface *sfcSource, int iZoom=0, bool fMonochrome=false); // set and enable pattern
bool Set(class CSurface8 *sfcSource, int iZoom=0, bool fMonochrome=false); // set and enable pattern
void SetColors(uint32_t *pClrs, uint32_t *pAlpha) { this->pClrs=pClrs; this->pAlpha=pAlpha; } // set color triplet for old-style textures
DWORD PatternClr(unsigned int iX, unsigned int iY) const; // apply pattern to color
bool Set(class CSurface *sfcSource, int iZoom=0); // set and enable pattern
void SetZoom(int iZoom) { Zoom = iZoom; }
void Clear(); // clear pattern
CPattern(); // ctor

View File

@ -101,8 +101,6 @@ void CBltTransform::TransformPoint(float &rX, float &rY)
CPattern& CPattern::operator=(const CPattern& nPattern)
{
pClrs = nPattern.pClrs;
pAlpha = nPattern.pAlpha;
sfcPattern32 = nPattern.sfcPattern32;
if (sfcPattern32) sfcPattern32->Lock();
delete [] CachedPattern;
@ -118,11 +116,10 @@ CPattern& CPattern::operator=(const CPattern& nPattern)
Wdt = nPattern.Wdt;
Hgt = nPattern.Hgt;
Zoom = nPattern.Zoom;
Monochrome = nPattern.Monochrome;
return *this;
}
bool CPattern::Set(SURFACE sfcSource, int iZoom, bool fMonochrome)
bool CPattern::Set(SURFACE sfcSource, int iZoom)
{
// Safety
if (!sfcSource) return false;
@ -136,7 +133,6 @@ bool CPattern::Set(SURFACE sfcSource, int iZoom, bool fMonochrome)
// set zoom
Zoom=iZoom;
// set flags
Monochrome=fMonochrome;
CachedPattern = new uint32_t[Wdt * Hgt];
if (!CachedPattern) return false;
for (int y = 0; y < Hgt; ++y)
@ -153,8 +149,6 @@ CPattern::CPattern()
sfcPattern32=NULL;
CachedPattern = 0;
Zoom=0;
Monochrome=false;
pClrs=NULL; pAlpha=NULL;
}
void CPattern::Clear()
@ -170,25 +164,12 @@ void CPattern::Clear()
delete[] CachedPattern; CachedPattern = 0;
}
bool CPattern::PatternClr(int iX, int iY, BYTE &byClr, DWORD &dwClr, CStdPalette &rPal) const
DWORD CPattern::PatternClr(unsigned int iX, unsigned int iY) const
{
if (!CachedPattern) return false;
// position zoomed?
if (Zoom) { iX/=Zoom; iY/=Zoom; }
// modulate position
((unsigned int &)iX) %= Wdt; ((unsigned int &)iY) %= Hgt;
// modulate clr
DWORD dwPix = CachedPattern[iY * Wdt + iX];
if (byClr)
{
if (Monochrome)
ModulateClrMonoA(dwClr, BYTE(dwPix), BYTE(dwPix>>24));
else
ModulateClrA(dwClr, dwPix);
LightenClr(dwClr);
}
else dwClr=dwPix;
return true;
if (!CachedPattern) return 0;
// wrap position
iX %= Wdt; iY %= Hgt;
return CachedPattern[iY * Wdt + iX];
}
void CGammaControl::SetClrChannel(WORD *pBuf, BYTE c1, BYTE c2, int c3)
@ -1541,10 +1522,7 @@ void CStdDDraw::DrawPatternedCircle(SURFACE sfcDest, int x, int y, int r, BYTE c
// Set line
for (int xcnt = x - lwdt; xcnt < x + lwdt; ++xcnt)
{
// apply both patterns
DWORD dwClr=rPal.GetClr(col);
Pattern.PatternClr(xcnt, y + ycnt, col, dwClr, rPal);
sfcDest->SetPixDw(xcnt, y + ycnt, dwClr);
sfcDest->SetPixDw(xcnt, y + ycnt, Pattern.PatternClr(xcnt, y + ycnt));
}
}
sfcDest->Unlock();