Add path-finding test and measurement to selftest.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4890 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
03bc81c0fb
commit
1423e2d742
12
src/astar.c
12
src/astar.c
|
@ -404,16 +404,13 @@ SDWORD fpathAStarRoute(SDWORD routeMode, ASTAR_ROUTE *psRoutePoints,
|
|||
{
|
||||
FP_NODE *psFound, *psCurr, *psNew, *psParent, *psNext;
|
||||
static FP_NODE *psNearest, *psRoute;
|
||||
SDWORD tileSX,tileSY,tileFX,tileFY;
|
||||
SDWORD dir, x,y, currDist;
|
||||
SDWORD index;
|
||||
SDWORD retval;
|
||||
|
||||
tileSX = map_coord(sx);
|
||||
tileSY = map_coord(sy);
|
||||
|
||||
tileFX = map_coord(fx);
|
||||
tileFY = map_coord(fy);
|
||||
int tileSX = map_coord(sx);
|
||||
int tileSY = map_coord(sy);
|
||||
int tileFX = map_coord(fx);
|
||||
int tileFY = map_coord(fy);
|
||||
|
||||
if (routeMode == ASR_NEWROUTE)
|
||||
{
|
||||
|
@ -506,7 +503,6 @@ static FP_NODE *psNearest, *psRoute;
|
|||
astarInner += 1;
|
||||
ASSERT(astarInner >= 0, "astarInner overflowed!");
|
||||
|
||||
|
||||
// Now insert the point into the appropriate list
|
||||
if (!psFound)
|
||||
{
|
||||
|
|
|
@ -670,5 +670,6 @@ void levTest(void)
|
|||
levTestLoad("CAM_3A");
|
||||
levTestLoad("FASTPLAY");
|
||||
levTestLoad("TUTORIAL3");
|
||||
levTestLoad("BeggarsKanyon-T1");
|
||||
fprintf(stdout, "\tLevels self-test: PASSED\n");
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
#include "main.h"
|
||||
#include "wrappers.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "map.h"
|
||||
|
||||
/* Always use fallbacks on Windows */
|
||||
#if defined(WZ_OS_WIN)
|
||||
|
@ -936,6 +936,7 @@ int main(int argc, char *argv[])
|
|||
NETtest();
|
||||
tagTest();
|
||||
levTest();
|
||||
mapTest();
|
||||
fprintf(stdout, "All tests PASSED!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
|
58
src/map.c
58
src/map.c
|
@ -23,6 +23,8 @@
|
|||
* Utility functions for the map data structure.
|
||||
*
|
||||
*/
|
||||
#include <time.h>
|
||||
|
||||
#include "lib/framework/frame.h"
|
||||
#include "lib/framework/tagfile.h"
|
||||
#include "lib/framework/file.h"
|
||||
|
@ -44,6 +46,9 @@
|
|||
#include "gateway.h"
|
||||
#include "wrappers.h"
|
||||
#include "mapgrid.h"
|
||||
#include "astar.h"
|
||||
#include "fpath.h"
|
||||
#include "levels.h"
|
||||
|
||||
//scroll min and max values
|
||||
SDWORD scrollMinX, scrollMaxX, scrollMinY, scrollMaxY;
|
||||
|
@ -169,11 +174,6 @@ BOOL mapNew(UDWORD width, UDWORD height)
|
|||
mapWidth = width;
|
||||
mapHeight = height;
|
||||
|
||||
for (i=0; i<MAX_TILE_TEXTURES; i++)
|
||||
{
|
||||
terrainTypes[i] = TER_SANDYBRUSH;
|
||||
}
|
||||
|
||||
intSetMapPos(mapWidth * TILE_UNITS/2, mapHeight * TILE_UNITS/2);
|
||||
|
||||
environReset();
|
||||
|
@ -1506,4 +1506,50 @@ bool readVisibilityData(const char* fileName)
|
|||
/* Hopefully everything's just fine by now */
|
||||
return true;
|
||||
}
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
static void astarTest(const char *name, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int asret, i;
|
||||
ASTAR_ROUTE route;
|
||||
int x = world_coord(x1);
|
||||
int y = world_coord(y1);
|
||||
int endx = world_coord(x2);
|
||||
int endy = world_coord(y2);
|
||||
clock_t stop;
|
||||
clock_t start = clock();
|
||||
int iterations;
|
||||
bool retval;
|
||||
|
||||
retval = levLoadData(name, NULL, 0);
|
||||
ASSERT(retval, "Could not load %s", name);
|
||||
fpathInitialise();
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
iterations = 1;
|
||||
route.numPoints = 0;
|
||||
astarResetCounters();
|
||||
ASSERT(astarInner == 0, "astarInner not reset");
|
||||
asret = fpathAStarRoute(ASR_NEWROUTE, &route, x, y, endx, endy);
|
||||
while (asret == ASR_PARTIAL)
|
||||
{
|
||||
astarResetCounters();
|
||||
ASSERT(astarInner == 0, "astarInner not reset");
|
||||
asret = fpathAStarRoute(ASR_CONTINUE, &route, x, y, endx, endy);
|
||||
iterations++;
|
||||
}
|
||||
}
|
||||
stop = clock();
|
||||
fprintf(stdout, "\t\tPath-finding timing %s: %.02f (%d nodes, %d iterations)\n", name,
|
||||
(double)(stop - start) / (double)CLOCKS_PER_SEC, route.numPoints, iterations);
|
||||
levReleaseAll();
|
||||
}
|
||||
|
||||
void mapTest()
|
||||
{
|
||||
fprintf(stdout, "\tMap self-test...\n");
|
||||
|
||||
astarTest("BeggarsKanyon-T1", 16, 5, 119, 182);
|
||||
astarTest("MizaMaze-T3", 5, 5, 108, 112);
|
||||
|
||||
fprintf(stdout, "\tMap self-test: PASSED\n");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue