Move Game.TextureMap to TextureMap

stable-5.2
Günther Brammer 2009-06-05 17:09:54 +02:00
parent 08957a3b9a
commit 25639bc659
9 changed files with 48 additions and 45 deletions

View File

@ -90,7 +90,6 @@ class C4Game
~C4Game();
public:
C4DefList Defs;
C4TextureMap TextureMap;
C4RankSystem Rank;
C4GraphicsSystem GraphicsSystem;
C4MessageInput MessageInput;

View File

@ -95,4 +95,6 @@ class C4TextureMap
BOOL AddTexture(const char *szTexture, CSurface * sfcSurface);
};
extern C4TextureMap TextureMap;
#endif

View File

@ -144,7 +144,7 @@ inline int32_t PixCol2Mat(BYTE pixc)
int32_t iTex = PixCol2Tex(pixc);
if(!iTex) return MNone;
// Get material-texture mapping
const C4TexMapEntry *pTex = Game.TextureMap.GetEntry(iTex);
const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
// Return material
return pTex ? pTex->GetMaterialIndex() : MNone;
}

View File

@ -712,7 +712,7 @@ void C4EditCursor::ApplyToolPicker()
// Material-texture from map
if (byIndex=Game.Landscape.GetMapIndex(X/Game.Landscape.MapZoom,Y/Game.Landscape.MapZoom))
{
const C4TexMapEntry *pTex = Game.TextureMap.GetEntry(byIndex & (IFT-1));
const C4TexMapEntry *pTex = ::TextureMap.GetEntry(byIndex & (IFT-1));
if(pTex)
{
Console.ToolsDlg.SelectMaterial(pTex->GetMaterialName());

View File

@ -185,7 +185,7 @@ int32_t C4Landscape::DoScan(int32_t cx, int32_t cy, int32_t mat, int32_t dir)
// nothing to do?
if (!conv_to_tex) return 0;
// find material
int32_t conv_to = Game.TextureMap.GetEntry(conv_to_tex)->GetMaterialIndex();
int32_t conv_to = ::TextureMap.GetEntry(conv_to_tex)->GetMaterialIndex();
// find mat top
int32_t mconv = Game.Material.Map[mat].TempConvStrength,
mconvs = mconv;
@ -368,7 +368,7 @@ void C4Landscape::ChunkOZoom(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, i
int32_t iIFT;
BYTE byMapPixel, byMapPixelBelow;
int iMapWidth,iMapHeight;
C4Material *pMaterial = Game.TextureMap.GetEntry(iTexture)->GetMaterial();
C4Material *pMaterial = ::TextureMap.GetEntry(iTexture)->GetMaterial();
if(!pMaterial) return;
int32_t iChunkType=pMaterial->MapChunkType;
BYTE byColor=MatTex2PixCol(iTexture);
@ -552,7 +552,7 @@ CSurface8 * C4Landscape::CreateMap()
// Fill sfcMap
C4MapCreator MapCreator;
MapCreator.Create(sfcMap,
Game.C4S.Landscape, Game.TextureMap,
Game.C4S.Landscape, ::TextureMap,
TRUE,Game.StartupPlayerCount);
return sfcMap;
@ -565,7 +565,7 @@ CSurface8 * C4Landscape::CreateMapS2(C4Group &ScenFile)
// create map creator
if (!pMapCreator)
pMapCreator = new C4MapCreatorS2(&Game.C4S.Landscape, &Game.TextureMap, &Game.Material, Game.StartupPlayerCount);
pMapCreator = new C4MapCreatorS2(&Game.C4S.Landscape, &::TextureMap, &Game.Material, Game.StartupPlayerCount);
// read file
pMapCreator->ReadFile(C4CFN_DynLandscape, &ScenFile);
@ -2154,7 +2154,7 @@ BOOL C4Landscape::SaveMap(C4Group &hGroup)
// Create map palette
BYTE bypPalette[3*256];
Game.TextureMap.StoreMapPalette(bypPalette,Game.Material);
::TextureMap.StoreMapPalette(bypPalette,Game.Material);
// Save map surface
if (!Map->Save(Config.AtTempPath(C4CFN_TempMap), bypPalette))
@ -2172,7 +2172,7 @@ BOOL C4Landscape::SaveMap(C4Group &hGroup)
bool C4Landscape::SaveTextures(C4Group &hGroup)
{
// if material-texture-combinations have been added, write the texture map
if (Game.TextureMap.fEntriesAdded)
if (::TextureMap.fEntriesAdded)
{
C4Group *pMatGroup = new C4Group();
bool fSuccess=false;
@ -2184,7 +2184,7 @@ bool C4Landscape::SaveTextures(C4Group &hGroup)
// create at temp path
if (pMatGroup->Open(Config.AtTempPath(C4CFN_Material), TRUE))
// write to it
if (Game.TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap))
if (::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap))
// close (flush)
if (pMatGroup->Close())
// add it
@ -2196,7 +2196,7 @@ bool C4Landscape::SaveTextures(C4Group &hGroup)
else
// simply write it to the local material file
if (pMatGroup->OpenAsChild(&hGroup, C4CFN_Material))
fSuccess = Game.TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap);
fSuccess = ::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap);
// close material group again
if (pMatGroup->IsOpen()) pMatGroup->Close();
delete pMatGroup;
@ -2231,7 +2231,7 @@ BOOL C4Landscape::GetMapColorIndex(const char *szMaterial, const char *szTexture
// Material-Texture
else
{
if (!(rbyCol=Game.TextureMap.GetIndex(szMaterial,szTexture))) return FALSE;
if (!(rbyCol=::TextureMap.GetIndex(szMaterial,szTexture))) return FALSE;
if (fIFT) rbyCol+=IFT;
}
// Found
@ -2392,7 +2392,7 @@ BOOL C4Landscape::DrawChunks(int32_t tx, int32_t ty, int32_t wdt, int32_t hgt, i
BOOL C4Landscape::DrawQuad(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iX3, int32_t iY3, int32_t iX4, int32_t iY4, const char *szMaterial, bool fIFT)
{
// get texture
int32_t iMatTex = Game.TextureMap.GetIndexMatTex(szMaterial);
int32_t iMatTex = ::TextureMap.GetIndexMatTex(szMaterial);
if(!iMatTex) return FALSE;
// prepate pixel count update
C4Rect BoundingBox(iX1, iY1, 1, 1);
@ -2557,7 +2557,7 @@ DWORD C4Landscape::GetClrByTex(int32_t iX, int32_t iY)
DWORD dwPix = Surface8->pPal->GetClr(pix);
// get texture map entry for pixel
const C4TexMapEntry *pTex;
if(pix && (pTex = Game.TextureMap.GetEntry(PixCol2Tex(pix))))
if(pix && (pTex = ::TextureMap.GetEntry(PixCol2Tex(pix))))
{
// pattern color
pTex->getPattern().PatternClr(iX, iY, pix, dwPix, Application.DDraw->Pal);
@ -2578,7 +2578,7 @@ BOOL C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, co
FakeLS.MapWdt.Set(iMapWdt, 0, iMapWdt, iMapWdt);
FakeLS.MapHgt.Set(iMapHgt, 0, iMapHgt, iMapHgt);
// create map creator
C4MapCreatorS2 MapCreator(&FakeLS, &Game.TextureMap, &Game.Material, Game.StartupPlayerCount);
C4MapCreatorS2 MapCreator(&FakeLS, &::TextureMap, &Game.Material, Game.StartupPlayerCount);
// read file
MapCreator.ReadScript(szMapDef);
// render map
@ -2663,13 +2663,13 @@ BOOL C4Landscape::SetTextureIndex(const char *szMatTex, BYTE iNewIndex, bool fIn
// get last mat index - returns zero for not found (valid for insertion mode)
StdStrBuf Material, Texture;
Material.CopyUntil(szMatTex, '-'); Texture.Copy(SSearch(szMatTex, "-"));
BYTE iOldIndex = (szMatTex && *szMatTex) ? Game.TextureMap.GetIndex(Material.getData(), Texture.getData(), FALSE) : 0;
BYTE iOldIndex = (szMatTex && *szMatTex) ? ::TextureMap.GetIndex(Material.getData(), Texture.getData(), FALSE) : 0;
// insertion mode?
if (fInsert)
{
// there must be room to move up to
BYTE byLastMoveIndex = C4M_MaxTexIndex - 1;
while (Game.TextureMap.GetEntry(byLastMoveIndex))
while (::TextureMap.GetEntry(byLastMoveIndex))
if (--byLastMoveIndex == iNewIndex)
{
DebugLogF("Cannot insert new texture %s to index %d: No room for insertion.", (const char *) szMatTex, (int) iNewIndex);
@ -2678,10 +2678,10 @@ BOOL C4Landscape::SetTextureIndex(const char *szMatTex, BYTE iNewIndex, bool fIn
// then move up all other textures first
// could do this in one loop, but it's just a developement call anyway, so move one index at a time
while (--byLastMoveIndex >= iNewIndex)
if (Game.TextureMap.GetEntry(byLastMoveIndex))
if (::TextureMap.GetEntry(byLastMoveIndex))
{
ReplaceMapColor(byLastMoveIndex, byLastMoveIndex+1);
Game.TextureMap.MoveIndex(byLastMoveIndex, byLastMoveIndex+1);
::TextureMap.MoveIndex(byLastMoveIndex, byLastMoveIndex+1);
}
// new insertion desired?
if (szMatTex && *szMatTex)
@ -2690,14 +2690,14 @@ BOOL C4Landscape::SetTextureIndex(const char *szMatTex, BYTE iNewIndex, bool fIn
if (iOldIndex)
{
ReplaceMapColor(iOldIndex, iNewIndex);
Game.TextureMap.MoveIndex(iOldIndex, iNewIndex);
::TextureMap.MoveIndex(iOldIndex, iNewIndex);
}
else
{
StdStrBuf Material, Texture;
Material.CopyUntil(szMatTex, '-'); Texture.Copy(SSearch(szMatTex, "-"));
// new insertion
if (!Game.TextureMap.AddEntry(iNewIndex, Material.getData(), Texture.getData()))
if (!::TextureMap.AddEntry(iNewIndex, Material.getData(), Texture.getData()))
{
LogF("Cannot insert new texture %s to index %d: Texture map entry error", (const char *) szMatTex, (int) iNewIndex);
return FALSE;
@ -2711,7 +2711,7 @@ BOOL C4Landscape::SetTextureIndex(const char *szMatTex, BYTE iNewIndex, bool fIn
{
// new index must not be occupied
const C4TexMapEntry *pOld;
if ((pOld = Game.TextureMap.GetEntry(iNewIndex)) && !pOld->isNull())
if ((pOld = ::TextureMap.GetEntry(iNewIndex)) && !pOld->isNull())
{
DebugLogF("Cannot move texture %s to index %d: Index occupied by %s-%s.", (const char *) szMatTex, (int) iNewIndex, pOld->GetMaterialName(), pOld->GetTextureName());
return FALSE;
@ -2725,7 +2725,7 @@ BOOL C4Landscape::SetTextureIndex(const char *szMatTex, BYTE iNewIndex, bool fIn
// update map
ReplaceMapColor(iOldIndex, iNewIndex);
// change to new index in texmap
Game.TextureMap.MoveIndex(iOldIndex, iNewIndex);
::TextureMap.MoveIndex(iOldIndex, iNewIndex);
// done, success
return TRUE;
}
@ -2761,7 +2761,7 @@ bool C4Landscape::Mat2Pal()
int32_t tex,rgb;
for (tex=0; tex<C4M_MaxTexIndex; tex++)
{
const C4TexMapEntry *pTex = Game.TextureMap.GetEntry(tex);
const C4TexMapEntry *pTex = ::TextureMap.GetEntry(tex);
if(!pTex || pTex->isNull())
continue;
// colors
@ -2930,9 +2930,9 @@ void C4Landscape::RemoveUnusedTexMapEntries()
// remove unused
for (iMatTex = 1; iMatTex < C4M_MaxTexIndex; ++iMatTex)
if (!fTexUsage[iMatTex])
Game.TextureMap.RemoveEntry(iMatTex);
::TextureMap.RemoveEntry(iMatTex);
// flag rewrite
Game.TextureMap.fEntriesAdded = true;
::TextureMap.fEntriesAdded = true;
}
bool C4Landscape::DebugSave(const char *szFilename)

View File

@ -394,7 +394,7 @@ void C4MaterialMap::CrossMapMaterials() // Called after load
const char *szTextureOverlay = NULL;
// newgfx: init pattern
if (Map[cnt].sTextureOverlay.getLength())
if (Game.TextureMap.GetTexture(Map[cnt].sTextureOverlay.getLength()))
if (::TextureMap.GetTexture(Map[cnt].sTextureOverlay.getLength()))
{
szTextureOverlay = Map[cnt].sTextureOverlay.getData();
// backwards compatibility: if a pattern was specified although the no-pattern flag was set, overwrite that flag
@ -408,13 +408,13 @@ void C4MaterialMap::CrossMapMaterials() // Called after load
if (!szTextureOverlay)
szTextureOverlay = "Smooth";
// search/create entry in texmap
Map[cnt].DefaultMatTex = Game.TextureMap.GetIndex(Map[cnt].Name, szTextureOverlay, TRUE,
Map[cnt].DefaultMatTex = ::TextureMap.GetIndex(Map[cnt].Name, szTextureOverlay, TRUE,
FormatString("DefaultMatTex of mat %s", Map[cnt].Name).getData());
// init PXS facet
SURFACE sfcTexture;
C4Texture * Texture;
if (Map[cnt].sPXSGfx.getLength())
if (Texture=Game.TextureMap.GetTexture(Map[cnt].sPXSGfx.getData()))
if (Texture=::TextureMap.GetTexture(Map[cnt].sPXSGfx.getData()))
if (sfcTexture=Texture->Surface32)
Map[cnt].PXSFace.Set(sfcTexture, Map[cnt].PXSGfxRt.x, Map[cnt].PXSGfxRt.y, Map[cnt].PXSGfxRt.Wdt, Map[cnt].PXSGfxRt.Hgt);
// evaluate reactions for that material
@ -499,13 +499,13 @@ void C4MaterialMap::CrossMapMaterials() // Called after load
for (cnt=0; cnt<Num; cnt++)
{
if (Map[cnt].sBlastShiftTo.getLength())
Map[cnt].BlastShiftTo=Game.TextureMap.GetIndexMatTex(Map[cnt].sBlastShiftTo.getData(), NULL, TRUE, FormatString("BlastShiftTo of mat %s", Map[cnt].Name).getData());
Map[cnt].BlastShiftTo=::TextureMap.GetIndexMatTex(Map[cnt].sBlastShiftTo.getData(), NULL, TRUE, FormatString("BlastShiftTo of mat %s", Map[cnt].Name).getData());
if (Map[cnt].sInMatConvertTo.getLength())
Map[cnt].InMatConvertTo=Get(Map[cnt].sInMatConvertTo.getData());
if (Map[cnt].sBelowTempConvertTo.getLength())
Map[cnt].BelowTempConvertTo=Game.TextureMap.GetIndexMatTex(Map[cnt].sBelowTempConvertTo.getData(), NULL, TRUE, FormatString("BelowTempConvertTo of mat %s", Map[cnt].Name).getData());
Map[cnt].BelowTempConvertTo=::TextureMap.GetIndexMatTex(Map[cnt].sBelowTempConvertTo.getData(), NULL, TRUE, FormatString("BelowTempConvertTo of mat %s", Map[cnt].Name).getData());
if (Map[cnt].sAboveTempConvertTo.getLength())
Map[cnt].AboveTempConvertTo=Game.TextureMap.GetIndexMatTex(Map[cnt].sAboveTempConvertTo.getData(), NULL, TRUE, FormatString("AboveTempConvertTo of mat %s", Map[cnt].Name).getData());
Map[cnt].AboveTempConvertTo=::TextureMap.GetIndexMatTex(Map[cnt].sAboveTempConvertTo.getData(), NULL, TRUE, FormatString("AboveTempConvertTo of mat %s", Map[cnt].Name).getData());
}
#if 0
int32_t i=0;

View File

@ -2294,7 +2294,7 @@ static C4String *FnGetTexture(C4AulContext* cthr, long x, long y)
int32_t iTex = PixCol2Tex(GBackPix(x, y));
if(!iTex) return NULL;
// Get material-texture mapping
const C4TexMapEntry *pTex = Game.TextureMap.GetEntry(iTex);
const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
if(!pTex) return NULL;
// Return tex name
return String(pTex->GetTextureName());
@ -5072,7 +5072,7 @@ static bool FnDrawModLandscape(C4AulContext *cctx, long iX, long iY, long iWdt,
}
// apply buffer
//Application.DDraw->DefinePattern(Game.TextureMap.GetTexture("Smooth2"));
//Application.DDraw->DefinePattern(::TextureMap.GetTexture("Smooth2"));
pZ=map;
for (int y=iY; y<iY2; ++y)
for (int x=iX; x<iX2; ++x)

View File

@ -85,7 +85,7 @@ bool C4TexMapEntry::Init()
}
pMaterial = &Game.Material.Map[iMaterialIndex];
// Find texture
C4Texture * sfcTexture = Game.TextureMap.GetTexture(Texture.getData());
C4Texture * sfcTexture = ::TextureMap.GetTexture(Texture.getData());
if(!sfcTexture)
{
DebugLogF("Error initializing material %s-%s: Invalid texture!", Material.getData(), Texture.getData());
@ -462,3 +462,5 @@ void C4TextureMap::StoreMapPalette(BYTE *bypPalette, C4MaterialMap &rMaterial)
if(rand() < RAND_MAX / 2) bypPalette[3*i+2] += 3; else bypPalette[3*i+2] -= 3;
}
}
C4TextureMap TextureMap;

View File

@ -537,9 +537,9 @@ void C4ToolsDlg::UpdateTextures()
// bottom-most: any invalid textures
bool fAnyEntry = false; int32_t cnt; const char *szTexture;
if (Game.Landscape.Mode!=C4LSC_Exact)
for (cnt=0; (szTexture=Game.TextureMap.GetTexture(cnt)); cnt++)
for (cnt=0; (szTexture=::TextureMap.GetTexture(cnt)); cnt++)
{
if (!Game.TextureMap.GetIndex(Material, szTexture, FALSE))
if (!::TextureMap.GetIndex(Material, szTexture, FALSE))
{
fAnyEntry = true;
#ifdef _WIN32
@ -564,10 +564,10 @@ void C4ToolsDlg::UpdateTextures()
}
// atop: valid textures
for (cnt=0; (szTexture=Game.TextureMap.GetTexture(cnt)); cnt++)
for (cnt=0; (szTexture=::TextureMap.GetTexture(cnt)); cnt++)
{
// Current material-texture valid? Always valid for exact mode
if (Game.TextureMap.GetIndex(Material,szTexture,FALSE) || Game.Landscape.Mode==C4LSC_Exact)
if (::TextureMap.GetIndex(Material,szTexture,FALSE) || Game.Landscape.Mode==C4LSC_Exact)
{
#ifdef _WIN32
SendDlgItemMessage(hDialog,IDC_COMBOTEXTURE,CB_INSERTSTRING,0,(LPARAM)szTexture);
@ -602,7 +602,7 @@ void C4ToolsDlg::SetMaterial(const char *szMaterial)
void C4ToolsDlg::SetTexture(const char *szTexture)
{
// assert valid (for seperator selection)
if (!Game.TextureMap.GetTexture(szTexture))
if (!::TextureMap.GetTexture(szTexture))
{
// ensure correct texture is in dlg
#ifdef _WIN32
@ -679,11 +679,11 @@ void C4ToolsDlg::UpdatePreview()
{
bCol=Mat2PixColDefault(Game.Material.Get(Material));
// Get/Create TexMap entry
BYTE iTex = Game.TextureMap.GetIndex(Material, Texture, TRUE);
BYTE iTex = ::TextureMap.GetIndex(Material, Texture, TRUE);
if (iTex)
{
// Define texture pattern
const C4TexMapEntry *pTex = Game.TextureMap.GetEntry(iTex);
const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
// Security
if(pTex)
{
@ -990,12 +990,12 @@ void C4ToolsDlg::AssertValidTexture()
// Ignore if sky
if (SEqual(Material,C4TLS_MatSky)) return;
// Current material-texture valid
if (Game.TextureMap.GetIndex(Material,Texture,FALSE)) return;
if (::TextureMap.GetIndex(Material,Texture,FALSE)) return;
// Find valid material-texture
const char *szTexture;
for (int32_t iTexture=0; szTexture=Game.TextureMap.GetTexture(iTexture); iTexture++)
for (int32_t iTexture=0; szTexture=::TextureMap.GetTexture(iTexture); iTexture++)
{
if (Game.TextureMap.GetIndex(Material,szTexture,FALSE))
if (::TextureMap.GetIndex(Material,szTexture,FALSE))
{ SelectTexture(szTexture); return; }
}
// No valid texture found