Remove the code to remake terrain tiles. Instead just free them and make them anew.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2219 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2007-07-27 14:58:17 +00:00
parent 3c24ae3d6f
commit 176be97ec3
4 changed files with 25 additions and 129 deletions

View File

@ -133,36 +133,6 @@ void pie_MakeTexPageName(char * filename)
}
}
void pie_ChangeTexPage(int tex_index, iV_Image * s, int type, BOOL bResource)
{
assert(s != NULL);
/* DID come from a resource */
_TEX_PAGE[tex_index].bResource = bResource;
// Default values
_TEX_PAGE[tex_index].tex.bmp = s->bmp;
_TEX_PAGE[tex_index].tex.width = s->width;
_TEX_PAGE[tex_index].tex.height = s->height;
_TEX_PAGE[tex_index].tex.depth = s->depth;
_TEX_PAGE[tex_index].type = type;
glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[tex_index].id);
if ((s->width & (s->width-1)) == 0 && (s->height & (s->height-1)) == 0)
{
gluBuild2DMipmaps(GL_TEXTURE_2D, wz_texture_compression, s->width, s->height,
iV_getPixelFormat(s), GL_UNSIGNED_BYTE, s->bmp);
} else {
debug(LOG_ERROR, "pie_ChangeTexPage: non POT texture %i", tex_index);
}
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}
/*!
* Print the names of all loaded textures to LOG_ERROR
*/
@ -231,16 +201,19 @@ void pie_TexShutDown(void)
{
unsigned int i = 0, j = 0;
while (i < _TEX_INDEX) {
while (i < _TEX_INDEX)
{
/* Only free up the ones that were NOT allocated through resource handler cos they'll already be free */
if(_TEX_PAGE[i].bResource == FALSE)
{
if(_TEX_PAGE[i].tex.bmp) {
if(_TEX_PAGE[i].tex.bmp)
{
j++;
free(_TEX_PAGE[i].tex.bmp);
_TEX_PAGE[i].tex.bmp = NULL;
}
}
glDeleteTextures(1, (GLuint *) &_TEX_PAGE[i].id);
i++;
}

View File

@ -681,9 +681,12 @@ static BOOL dataImageLoad(const char *fileName, void **ppData)
// Tertiles (terrain tiles) loader.
static BOOL dataTERTILESLoad(const char *fileName, void **ppData)
{
*ppData = texLoad(fileName);
texLoad(fileName);
debug(LOG_TEXTURE, "HW Tiles loaded");
// set a dummy value so the release function gets called
*ppData = (void *)1;
return TRUE;
}

View File

@ -35,9 +35,6 @@
#define PAGE_DEPTH 4
#define TEXTURE_PAGE_SIZE PAGE_WIDTH*PAGE_HEIGHT*PAGE_DEPTH
/* Stores the graphics data for the terrain tiles textures (in src/data.c) */
static iTexture tilesPCX = { 0, 0, 0, NULL };
/* How many pages have we loaded */
static SDWORD firstTexturePage;
static SDWORD numTexturePages;
@ -50,47 +47,32 @@ static void getRectFromPage(UDWORD width, UDWORD height, unsigned char *src, UDW
static void putRectIntoPage(UDWORD width, UDWORD height, unsigned char *dest, UDWORD bufWidth, unsigned char *src);
static void buildTileIndexes(void);
static void makeTileTexturePages(iV_Image * src, UDWORD tileWidth, UDWORD tileHeight);
static void remakeTileTexturePages(iV_Image * src, UDWORD tileWidth, UDWORD tileHeight);
static void freeTileTextures(void);
static BOOL getTileRadarColours(iTexture *tilesPCX);
void texInit()
{
tilesPCX.bmp = NULL;
}
void texDone()
{
freeTileTextures();
iV_unloadImage(&tilesPCX);
}
// just return a pointer because the resource handler wants to cuddle one
void *texLoad(const char *fileName)
void texLoad(const char *fileName)
{
BOOL bTilesPCXLoaded = (tilesPCX.bmp != NULL);
if (bTilesPCXLoaded)
{
debug(LOG_TEXTURE, "Unloading terrain tiles");
iV_unloadImage(&tilesPCX);
}
iTexture tilesPCX;
if(!iV_loadImage_PNG(fileName, &tilesPCX))
{
debug( LOG_ERROR, "TERTILES load failed" );
return NULL;
debug(LOG_ERROR, "TERTILES load failed");
return;
}
getTileRadarColours();
if (bTilesPCXLoaded)
{
remakeTileTexturePages(&tilesPCX, TILE_WIDTH, TILE_HEIGHT);
}
else
{
getTileRadarColours(&tilesPCX);
makeTileTexturePages(&tilesPCX, TILE_WIDTH, TILE_HEIGHT);
}
return &tilesPCX;
free(tilesPCX.bmp);
}
/*
@ -175,82 +157,21 @@ exit:
return;
}
void remakeTileTexturePages(iV_Image * src, UDWORD tileWidth, UDWORD tileHeight)
{
UDWORD i, j;
UDWORD pageNumber = 0;
UDWORD tilesAcross = src->width / tileWidth, tilesDown = src->height / tileHeight;
UDWORD tilesAcrossPage = PAGE_WIDTH / tileWidth, tilesDownPage = PAGE_HEIGHT / tileHeight;
UDWORD tilesPerPage = tilesAcrossPage * tilesDownPage, tilesPerSource = tilesAcross * tilesDown;
UDWORD tilesProcessed = 0;
iTexture sprite = { PAGE_WIDTH, PAGE_HEIGHT, PAGE_DEPTH, malloc(TEXTURE_PAGE_SIZE) };
/* Get enough memory to store one tile */
unsigned char *tileStorage = malloc(tileWidth * tileHeight * PAGE_DEPTH);
unsigned char *presentLoc = sprite.bmp;
unsigned char *srcBmp = src->bmp;
debug(LOG_TEXTURE, "remakeTileTexturePages: src(%d,%d), tile(%d, %d)", src->width, src->height, tileWidth, tileHeight);
for (i=0; i<tilesDown; i++)
{
for (j=0; j<tilesAcross; j++)
{
getRectFromPage(tileWidth, tileHeight, srcBmp, src->width, tileStorage);
putRectIntoPage(tileWidth, tileHeight, presentLoc, PAGE_WIDTH, tileStorage);
tilesProcessed++;
presentLoc += tileWidth * PAGE_DEPTH;
srcBmp += tileWidth * PAGE_DEPTH;
/* Have we got all the tiles from the source!? */
if (tilesProcessed == tilesPerSource)
{
pie_ChangeTexPage(pageId[pageNumber], &sprite, 0, FALSE);
goto exit;
}
/* Have we run out of texture page? */
if (tilesProcessed % tilesPerPage == 0)
{
debug(LOG_TEXTURE, "remakeTileTexturePages: ran out of texture page ...");
debug(LOG_TEXTURE, "tilesDown=%d tilesAcross=%d tilesProcessed=%d tilesPerPage=%d", tilesDown, tilesAcross, tilesProcessed, tilesPerPage);
pie_ChangeTexPage(pageId[pageNumber], &sprite, 0, FALSE);
pageNumber++;
presentLoc = sprite.bmp;
}
else if (tilesProcessed % tilesAcrossPage == 0)
{
/* Right hand side of texture page */
/* So go to one tile down */
presentLoc += (tileHeight-1) * PAGE_WIDTH * PAGE_DEPTH;
}
}
srcBmp += (tileHeight-1) * src->width * PAGE_DEPTH;
}
//check numTexturePages == pageNumber;
ASSERT( numTexturePages >= (SDWORD)pageNumber, "New Tertiles too large" );
exit:
free(tileStorage);
buildTileIndexes();
return;
}
BOOL getTileRadarColours(void)
static BOOL getTileRadarColours(iTexture *tilesPCX)
{
UDWORD x, y, i, j, w, h, t;
iBitmap *b, *s;
unsigned char tempBMP[TILE_WIDTH * TILE_HEIGHT];
w = tilesPCX.width / TILE_WIDTH;
h = tilesPCX.height / TILE_HEIGHT;
w = tilesPCX->width / TILE_WIDTH;
h = tilesPCX->height / TILE_HEIGHT;
t = 0;
for (i=0; i<h; i++)
{
for (j=0; j<w; j++)
{
b = tilesPCX.bmp + j * TILE_WIDTH + i * tilesPCX.width * TILE_HEIGHT;
b = tilesPCX->bmp + j * TILE_WIDTH + i * tilesPCX->width * TILE_HEIGHT;
s = &tempBMP[0];
if (s)
{
@ -261,7 +182,7 @@ BOOL getTileRadarColours(void)
{
; /* NOP */
}
b+=tilesPCX.width;
b += tilesPCX->width;
}
calcRadarColour(&tempBMP[0],t);
t++;
@ -281,6 +202,7 @@ static void freeTileTextures(void)
for (i = 0; i < numTexturePages; i++)
{
debug(LOG_ERROR, "Unloading page %d + %u", firstTexturePage, i);
iV_unloadImage(&_TEX_PAGE[(firstTexturePage+i)].tex);
}
}

View File

@ -22,9 +22,7 @@
void texInit();
void texDone();
void *texLoad(const char *fileName);
extern BOOL getTileRadarColours(void);
void texLoad(const char *fileName);
typedef struct _tileTexInfo
{