Map code cleanup

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2987 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2007-12-06 21:25:56 +00:00
parent ed05f84188
commit 747df597fb
2 changed files with 9 additions and 97 deletions

105
src/map.c
View File

@ -26,14 +26,9 @@
#include <stdio.h>
#include <string.h>
#include <physfs.h>
/* map line printf's */
#include <assert.h>
#include "lib/framework/frame.h"
#include "lib/framework/frameint.h"
#include "lib/framework/tagfile.h"
#include "map.h"
#include "lib/gamelib/gtime.h"
#include "lib/ivis_common/tex.h"
#include "hci.h"
#include "projectile.h"
@ -46,11 +41,10 @@
#include "research.h"
#include "mission.h"
#include "formationdef.h"
#include "gateway.h"
#include "wrappers.h"
#include "lib/framework/fractions.h"
#include "map.h"
//scroll min and max values
SDWORD scrollMinX, scrollMaxX, scrollMinY, scrollMaxY;
@ -118,10 +112,6 @@ typedef struct _zonemap_save_header {
#define DIR_STEEP 1 /* set when abs(dy) > abs(dx) */
#define DIR_NEGY 2 /* set whey dy < 0 */
/* Defines to access the map for aaLine */
#define PIXADDR(x,y) mapTile(x,y)
#define PIXINC(dx,dy) ((dy * mapWidth) + dx)
/* The size and contents of the map */
UDWORD mapWidth = 0, mapHeight = 0;
MAPTILE *psMapTiles = NULL;
@ -132,21 +122,10 @@ TILE_COORD *aMapLinePoints = NULL;
/* Look up table that returns the terrain type of a given tile texture */
UBYTE terrainTypes[MAX_TILE_TEXTURES];
/* pointer to a load map function - depends on version */
BOOL (*pLoadMapFunc)(char *pFileData, UDWORD fileSize);
MAPTILE *GetCurrentMap(void) // returns a pointer to the current loaded map data
{
return(psMapTiles);
}
/* Create a new map of a specified size */
BOOL mapNew(UDWORD width, UDWORD height)
{
// UDWORD numPoints;
UDWORD i;
MAPTILE *psTile;
/* See if a map has already been allocated */
if (psMapTiles != NULL)
@ -156,10 +135,10 @@ BOOL mapNew(UDWORD width, UDWORD height)
freeAllStructs();
freeAllFeatures();
proj_FreeAllProjectiles();
// free(psMapTiles);
free(aMapLinePoints);
psMapTiles = NULL;
aMapLinePoints = NULL;
free(psMapTiles);
psMapTiles = NULL;
}
if (width*height > MAP_MAXAREA)
@ -169,14 +148,8 @@ BOOL mapNew(UDWORD width, UDWORD height)
return FALSE;
}
psMapTiles = (MAPTILE *)malloc(sizeof(MAPTILE) * width*height);
if (psMapTiles == NULL)
{
debug( LOG_ERROR, "mapNew: Out of memory" );
abort();
return FALSE;
}
memset(psMapTiles, 0, sizeof(MAPTILE) * width*height);
psMapTiles = calloc(width * height, sizeof(MAPTILE));
ASSERT(psMapTiles != NULL, "mapNew: Out of memory")
mapWidth = width;
mapHeight = height;
@ -186,36 +159,15 @@ BOOL mapNew(UDWORD width, UDWORD height)
terrainTypes[i] = TER_SANDYBRUSH;
}
/* Allocate a buffer for the LOS routines points */
/* numPoints = sqrtf(mapWidth * mapWidth + mapHeight * mapHeight) + 1;
aMapLinePoints = (TILE_COORD *)malloc(sizeof(TILE_COORD) * numPoints);
if (!aMapLinePoints)
{
DBERROR(("Out of memory"));
return FALSE;
}
maxLinePoints = numPoints;
*/
intSetMapPos(mapWidth * TILE_UNITS/2, mapHeight * TILE_UNITS/2);
/* Initialise the map terrain type */
psTile = psMapTiles;
/*
for(i=mapWidth * mapHeight; i>0; i--)
{
psTile->type = TER_GRASS;
psTile++;
}
*/
environReset();
/*set up the scroll mins and maxs - set values to valid ones for a new map*/
scrollMinX = scrollMinY = 0;
scrollMaxX = mapWidth;
scrollMaxY = mapHeight;
return TRUE;
}
@ -239,10 +191,7 @@ static BOOL mapLoadV3(char *pFileData, UDWORD fileSize)
endian_uword(&psTileData->texture);
psMapTiles[i].texture = psTileData->texture;
// psMapTiles[i].type = psTileData->type;
psMapTiles[i].height = psTileData->height;
// Changed line - alex
//end of change - alex
for (j=0; j<MAX_PLAYERS; j++)
{
psMapTiles[i].tileVisBits =(UBYTE)(( (psMapTiles[i].tileVisBits) &~ (UBYTE)(1<<j) ));
@ -250,7 +199,6 @@ static BOOL mapLoadV3(char *pFileData, UDWORD fileSize)
psTileData = (MAP_SAVETILEV2 *)(((UBYTE *)psTileData) + SAVE_TILE_SIZE);
}
psGateHeader = (GATEWAY_SAVEHEADER*)psTileData;
psGate = (GATEWAY_SAVE*)(psGateHeader+1);
@ -269,16 +217,6 @@ static BOOL mapLoadV3(char *pFileData, UDWORD fileSize)
psGate++;
}
// if (!gwProcessMap())
// {
// return FALSE;
// }
//
// if ((psGateways != NULL) &&
// !gwGenerateLinkGates())
// {
// return FALSE;
// }
psZoneHeader = (ZONEMAP_SAVEHEADER*)psGate;
/* ZONEMAP_SAVEHEADER */
@ -400,7 +338,6 @@ BOOL mapLoad(char *pFileData, UDWORD fileSize)
endian_udword(&psHeader->width);
endian_udword(&psHeader->height);
/* Check the file version - deal with version 1 files */
/* Check the file version */
if (psHeader->version <= VERSION_9)
{
@ -408,11 +345,7 @@ BOOL mapLoad(char *pFileData, UDWORD fileSize)
free(pFileData);
return FALSE;
}
else if (psHeader->version <= CURRENT_VERSION_NUM)
{
pLoadMapFunc = mapLoadV3; // Includes gateway data for routing.
}
else
else if (psHeader->version > CURRENT_VERSION_NUM)
{
ASSERT(FALSE, "MapLoad: undefined save format version %d", psHeader->version);
free(pFileData);
@ -466,30 +399,10 @@ BOOL mapLoad(char *pFileData, UDWORD fileSize)
mapWidth = width;
mapHeight = height;
/* a terrain type is loaded when necessary - so don't reset
for (i=0; i<MAX_TILE_TEXTURES; i++)
{
terrainTypes[i] = TER_SANDYBRUSH;
}*/
/* Allocate a buffer for the LOS routines points */
/* numPoints = sqrtf(mapWidth * mapWidth + mapHeight * mapHeight) + 1;
aMapLinePoints = (TILE_COORD *)malloc(sizeof(TILE_COORD) * numPoints);
if (!aMapLinePoints)
{
DBERROR(("Out of memory"));
return FALSE;
}
maxLinePoints = numPoints;
*/
// intSetMapPos(mapWidth * TILE_UNITS/2, mapHeight * TILE_UNITS/2);
}
//load in the map data itself
pLoadMapFunc(pFileData, fileSize);
mapLoadV3(pFileData, fileSize);
environReset();
@ -930,7 +843,7 @@ BOOL mapSaveTagged(char *pFileName)
tagWriteLeave(0x05);
tagWriteEnter(0x0a, mapWidth * mapHeight); // tile group
psTile = GetCurrentMap();
psTile = psMapTiles;
for (i = 0, x = 0, y = 0; i < mapWidth * mapHeight; i++)
{
tagWrite(0x01, terrainType(psTile));

View File

@ -290,7 +290,6 @@ extern BOOL mapObjIsAboveGround( BASE_OBJECT *psObj );
in tile coords */
extern void getTileMaxMin(UDWORD x, UDWORD y, UDWORD *pMax, UDWORD *pMin);
MAPTILE *GetCurrentMap(void); // returns a pointer to the current loaded map data
UDWORD GetHeightOfMap(void);
UDWORD GetWidthOfMap(void);
extern bool readVisibilityData(const char* fileName);