Add new unit test for model files, to check that they are in a valid PIE format. Remove unused and broken A* test.
parent
35c00b924d
commit
c57bd507ed
|
@ -1,5 +1,5 @@
|
|||
PIE 3
|
||||
TYPE 0
|
||||
TYPE 200
|
||||
TEXTURE 0 page-59-more-weapons.png 256 256
|
||||
LEVELS 1
|
||||
LEVEL 1
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
AM_CPPFLAGS = $(SDL_CFLAGS) $(PHYSFS_CFLAGS) $(PNG_CFLAGS) $(OPENGL_CFLAGS) $(WZ_CPPFLAGS) -I$(top_srcdir)/tools -I. -I$(top_srcdir)/lib/framework
|
||||
AM_CFLAGS = -g
|
||||
|
||||
BUILT_SOURCES = \
|
||||
maplist.txt
|
||||
BUILT_SOURCES = maplist.txt modellist.txt
|
||||
|
||||
check_PROGRAMS = \
|
||||
maptest
|
||||
check_PROGRAMS = maptest modeltest
|
||||
|
||||
modeltest_SOURCES = modeltest.c
|
||||
|
||||
maptest_SOURCES = ../tools/map/mapload.c maptest.c
|
||||
noinst_HEADERS = ../tools/map/mapload.h
|
||||
|
@ -14,9 +14,12 @@ maptest_LDADD = $(PHYSFS_LIBS) $(PNG_LIBS)
|
|||
CLEANFILES = \
|
||||
$(BUILT_SOURCES)
|
||||
|
||||
TESTS = \
|
||||
maptest
|
||||
TESTS = maptest modeltest
|
||||
|
||||
maplist.txt:
|
||||
(cd $(abs_top_srcdir)/data ; find base mods -name game.map > $(abs_top_builddir)/tests/maplist.txt )
|
||||
touch $@
|
||||
|
||||
modellist.txt:
|
||||
(cd $(abs_top_srcdir)/data ; find base mods mp -iname \*.pie > $(abs_top_builddir)/tests/modellist.txt )
|
||||
touch $@
|
||||
|
|
|
@ -1,172 +0,0 @@
|
|||
// gcc -o astartest astartest.c -Wall -Werror -g -O0 -I/usr/include/SDL/ `sdl-config --libs --cflags`
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include <time.h>
|
||||
|
||||
#define mapX 64
|
||||
#define mapY 48
|
||||
#define IMPASSABLE 255
|
||||
|
||||
int mapWidth = mapX;
|
||||
int mapHeight = mapY;
|
||||
|
||||
#include "../lib/framework/frame.h"
|
||||
#include "../lib/framework/debug.h"
|
||||
#include "../lib/framework/types.h"
|
||||
#include "../lib/framework/macros.h"
|
||||
#include "../lib/framework/vector.h"
|
||||
#include "../src/movedef.h"
|
||||
#include "../src/map.h"
|
||||
|
||||
/* Faux declarations */
|
||||
void fpathHardTableReset(void);
|
||||
|
||||
typedef enum _fpath_movetype
|
||||
{
|
||||
FMT_MOVE, ///< Move around all obstacles
|
||||
FMT_ATTACK, ///< Assume that we will destroy enemy obstacles
|
||||
} FPATH_MOVETYPE;
|
||||
|
||||
typedef struct _jobNode
|
||||
{
|
||||
PROPULSION_TYPE propulsion;
|
||||
DROID_TYPE droidType;
|
||||
int destX, destY;
|
||||
int origX, origY;
|
||||
UDWORD droidID;
|
||||
struct _jobNode *next;
|
||||
FPATH_MOVETYPE moveType;
|
||||
int owner; ///< Player owner
|
||||
} PATHJOB;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ASR_OK, ///< found a route
|
||||
ASR_FAILED, ///< no route could be found
|
||||
ASR_NEAREST, ///< found a partial route to a nearby position
|
||||
} ASTAR_RESULT;
|
||||
|
||||
static unsigned char testmap[mapX][mapY];
|
||||
|
||||
static inline BOOL fpathBaseBlockingTile(SDWORD x, SDWORD y, PROPULSION_TYPE propulsion, int player, FPATH_MOVETYPE moveType)
|
||||
{
|
||||
return testmap[x][y] == IMPASSABLE;
|
||||
}
|
||||
|
||||
#define WZ_TESTING
|
||||
#include "../src/astar.cpp"
|
||||
|
||||
static void printmap(MOVE_CONTROL *move, PATHJOB *job)
|
||||
{
|
||||
int x, y, z;
|
||||
|
||||
for (y = 0; y < mapY; y++)
|
||||
{
|
||||
for (x = 0; x < mapX; x++)
|
||||
{
|
||||
bool onPos = false;
|
||||
|
||||
for (z = 0; z < move->numPoints; z++)
|
||||
{
|
||||
if (move->asPath[z].x == x && move->asPath[z].y == y)
|
||||
{
|
||||
onPos = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (x == map_coord(job->origX) && y == map_coord(job->origY))
|
||||
{
|
||||
fprintf(stdout, "O");
|
||||
}
|
||||
else if (x == map_coord(job->destX) && y == map_coord(job->destY))
|
||||
{
|
||||
fprintf(stdout, "X");
|
||||
}
|
||||
else if (testmap[x][y] == IMPASSABLE)
|
||||
{
|
||||
assert(!onPos);
|
||||
fprintf(stdout, "#");
|
||||
}
|
||||
else if (onPos)
|
||||
{
|
||||
fprintf(stdout, "+");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout, ".");
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void createmap(void)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
srand(123456789);
|
||||
for (y = 0; y < mapY; y++)
|
||||
{
|
||||
int slitPos = (rand() % (mapX - 2)) + 1; // opening at this position
|
||||
|
||||
for (x = 0; x < mapX; x++)
|
||||
{
|
||||
|
||||
if (x == 0 || x == mapX - 1 || y == 0 || y == mapY - 1)
|
||||
{
|
||||
testmap[x][y] = IMPASSABLE; // add impassable border
|
||||
}
|
||||
else if ((y % 4) == 0 && x != slitPos)
|
||||
{
|
||||
testmap[x][y] = IMPASSABLE; // add barrier
|
||||
}
|
||||
else
|
||||
{
|
||||
testmap[x][y] = 0; // passable space
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ASTAR_RESULT result;
|
||||
PATHJOB job;
|
||||
MOVE_CONTROL move;
|
||||
int i;
|
||||
unsigned int startTicks, endTicks;
|
||||
clock_t startCpu, endCpu;
|
||||
|
||||
createmap();
|
||||
|
||||
startTicks = SDL_GetTicks();
|
||||
startCpu = clock();
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
job.propulsion = 0;
|
||||
job.droidType = 0;
|
||||
job.destX = world_coord(1);
|
||||
job.destY = world_coord(1);
|
||||
job.origX = world_coord(mapX - 2);
|
||||
job.origY = world_coord(mapY - 2);
|
||||
job.droidID = 9;
|
||||
job.next = NULL;
|
||||
job.moveType = 0;
|
||||
job.owner = 0;
|
||||
move.asPath = NULL;
|
||||
move.numPoints = 0;
|
||||
|
||||
result = fpathAStarRoute(&move, &job);
|
||||
assert(result == ASR_OK);
|
||||
assert(move.numPoints == 214);
|
||||
}
|
||||
endCpu = clock();
|
||||
endTicks = SDL_GetTicks();
|
||||
|
||||
fprintf(stdout, "Found a route with %d points (%u ticks, %u clock)\n", move.numPoints, endTicks - startTicks, (unsigned int)(endCpu - startCpu));
|
||||
printmap(&move, &job);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -15,7 +15,7 @@ int main(int argc, char **argv)
|
|||
return -1;
|
||||
}
|
||||
PHYSFS_init(argv[0]);
|
||||
strcat(datapath, getenv("srcdir"));
|
||||
strcpy(datapath, getenv("srcdir"));
|
||||
strcat(datapath, "/../data");
|
||||
PHYSFS_addToSearchPath(datapath, 1);
|
||||
|
||||
|
|
|
@ -0,0 +1,255 @@
|
|||
/*
|
||||
This file is part of Warzone 2100.
|
||||
Copyright (C) 2007-2010 Warzone 2100 Project
|
||||
|
||||
Warzone 2100 is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Warzone 2100 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Warzone 2100; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <stdbool.h>
|
||||
#include <limits.h>
|
||||
#else
|
||||
typedef int bool;
|
||||
#define PATH_MAX 255
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#define iV_IMD_TEX 0x00000200
|
||||
#define iV_IMD_XNOCUL 0x00002000
|
||||
#define iV_IMD_TEXANIM 0x00004000
|
||||
#define iV_IMD_TCMASK 0x00010000
|
||||
#define MAX_POLYGON_SIZE 3 // the game can't handle more
|
||||
|
||||
typedef struct {
|
||||
int index[MAX_POLYGON_SIZE];
|
||||
int texCoord[MAX_POLYGON_SIZE][2];
|
||||
int vertices;
|
||||
int frames, rate, width, height; // animation data
|
||||
bool cull;
|
||||
} WZ_FACE;
|
||||
|
||||
typedef struct {
|
||||
int x, y, z, reindex;
|
||||
bool dupe;
|
||||
} WZ_POSITION;
|
||||
|
||||
static void check_pie(const char *input)
|
||||
{
|
||||
int num, x, y, z, levels, level;
|
||||
FILE *fp = fopen(input, "r");
|
||||
char s[200];
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
fprintf(stderr, "Unable to open %s from %s: %s\n", input, getcwd(s, sizeof(s) - 1), strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
num = fscanf(fp, "PIE %d\n", &x);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "Bad PIE file %s\n", input);
|
||||
exit(1);
|
||||
}
|
||||
if (x != 2 && x != 3)
|
||||
{
|
||||
fprintf(stderr, "Unknown PIE version %d in %s\n", x, input);
|
||||
exit(1);
|
||||
}
|
||||
num = fscanf(fp, "TYPE %x\n", &x); // ignore
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "Bad TYPE directive in %s\n", input);
|
||||
exit(1);
|
||||
}
|
||||
if (!(x & iV_IMD_TEX))
|
||||
{
|
||||
fprintf(stderr, "Missing texture flag in %s\n", input);
|
||||
exit(1);
|
||||
}
|
||||
num = fscanf(fp, "TEXTURE %d %s %d %d\n", &z, s, &x, &y);
|
||||
if (num != 4)
|
||||
{
|
||||
fprintf(stderr, "Bad TEXTURE directive in %s\n", input);
|
||||
exit(1);
|
||||
}
|
||||
num = fscanf(fp, "LEVELS %d\n", &levels);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "Bad LEVELS directive in %s\n", input);
|
||||
exit(1);
|
||||
}
|
||||
for (level = 0; level < levels; level++)
|
||||
{
|
||||
int j, points, faces;
|
||||
|
||||
num = fscanf(fp, "\nLEVEL %d\n", &x);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "Bad LEVEL directive in %s.\n", input);
|
||||
exit(1);
|
||||
}
|
||||
if (level + 1 != x)
|
||||
{
|
||||
fprintf(stderr, "LEVEL directive in %s was %d should be %d.\n", input, x, level + 1);
|
||||
exit(1);
|
||||
}
|
||||
num = fscanf(fp, "POINTS %d\n", &points);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "Bad POINTS directive in %s, level %d.\n", input, level);
|
||||
exit(1);
|
||||
}
|
||||
for (j = 0; j < points; j++)
|
||||
{
|
||||
double a, b, c;
|
||||
num = fscanf(fp, "%f %f %f\n", &a, &b, &c);
|
||||
if (num != 3)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad POINTS entry level %d, number %d.\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
num = fscanf(fp, "POLYGONS %d", &faces);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "Bad POLYGONS directive in %s, level %d.\n", input, level);
|
||||
exit(1);
|
||||
}
|
||||
for (j = 0; j < faces; ++j)
|
||||
{
|
||||
int k;
|
||||
unsigned int flags;
|
||||
|
||||
num = fscanf(fp, "\n%x", &flags);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad POLYGONS flag entry level %d, number %d\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
if (!(flags & iV_IMD_TEX))
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad polygon flag entry level %d, number %d - no texture flag!\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
if (flags & iV_IMD_XNOCUL)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad polygon flag entry level %d, number %d - face culling not supported anymore!\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
num = fscanf(fp, "%d", &k);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad POLYGONS vertices entry level %d, number %d\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
if (k != 3)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad POLYGONS vertices entry level %d, number %d -- non-triangle polygon found\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
// Read in vertex indices and texture coordinates
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
int l;
|
||||
num = fscanf(fp, "%d", &l);
|
||||
if (num != 1)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad vertex position entry level %d, number %d\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (flags & iV_IMD_TEXANIM)
|
||||
{
|
||||
int frames, rate, width, height;
|
||||
num = fscanf(fp, "%d %d %d %d", &frames, &rate, &width, &height);
|
||||
if (num != 4)
|
||||
{
|
||||
fprintf(stderr, "File %s - Bad texture animation entry level %d, number %d.\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
if (frames <= 1)
|
||||
{
|
||||
fprintf(stderr, "File %s - Level %d, polygon %d has a single animation frame.\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
double t, u;
|
||||
num = fscanf(fp, "%f %f", &t, &u);
|
||||
if (num != 2)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad texture coordinate entry level %d, number %d\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
num = fscanf(fp, "\nCONNECTORS %d", &x);
|
||||
if (num == 1)
|
||||
{
|
||||
if (x < 0)
|
||||
{
|
||||
fprintf(stderr, "Bad CONNNECTORS directive in %s, level %d\n", input, level);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
for (j = 0; j < x; ++j)
|
||||
{
|
||||
int a, b, c;
|
||||
|
||||
num = fscanf(fp, "\n%d %d %d", &a, &b, &c);
|
||||
if (num != 3)
|
||||
{
|
||||
fprintf(stderr, "File %s. Bad CONNECTORS directive entry level %d, number %d\n", input, level, j);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char datapath[PATH_MAX], fullpath[PATH_MAX];
|
||||
FILE *fp = fopen("modellist.txt", "r");
|
||||
if (!fp)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to open list file\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
strcpy(datapath, getenv("srcdir"));
|
||||
strcat(datapath, "/../data/");
|
||||
while (!feof(fp))
|
||||
{
|
||||
char filename[PATH_MAX], *delim;
|
||||
|
||||
fscanf(fp, "%s\n", &filename);
|
||||
printf("Testing model: %s\n", filename);
|
||||
strcpy(fullpath, datapath);
|
||||
strcat(fullpath, filename);
|
||||
check_pie(fullpath);
|
||||
}
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue