From 19bfa0d8f6ba80b796825147b4d084142aef666b Mon Sep 17 00:00:00 2001 From: Cyp Date: Sun, 15 Aug 2010 20:23:56 +0200 Subject: [PATCH] Fix comparing with the wrong variable when trying to make pathfinding deterministic. (Fixed before, hope it's the right variable this time.) --- src/astar.cpp | 12 +++++++----- src/fpath.c | 7 ++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/astar.cpp b/src/astar.cpp index c47ee2702..757104fb9 100644 --- a/src/astar.cpp +++ b/src/astar.cpp @@ -51,6 +51,9 @@ #include #include +#include "lib/framework/crc.h" +#include "lib/netplay/netplay.h" + /// A coordinate. struct PathCoord { @@ -112,9 +115,6 @@ struct PathBlockingMap std::vector map; }; -/// Game time for all blocking maps in fpathBlockingMaps. -static uint32_t fpathCurrentGameTime; - // Data structures used for pathfinding, can contain cached results. struct PathfindContext { @@ -126,8 +126,8 @@ struct PathfindContext } bool matches(PathBlockingMap const *blockingMap_, PathCoord tileS_) const { - // Must check myGameTime == fpathCurrentGameTime, otherwise blockingMap be a deleted pointer which coincidentally compares equal to the valid pointer blockingMap_. - return myGameTime == fpathCurrentGameTime && blockingMap == blockingMap_ && tileS == tileS_; + // Must check myGameTime == blockingMap_->type.gameTime, otherwise blockingMap be a deleted pointer which coincidentally compares equal to the valid pointer blockingMap_. + return myGameTime == blockingMap_->type.gameTime && blockingMap == blockingMap_ && tileS == tileS_; } void assign(PathBlockingMap const *blockingMap_, PathCoord tileS_) { @@ -168,6 +168,8 @@ static std::list fpathContexts; static std::list fpathBlockingMaps; /// Lists of blocking maps from previous tick, will be cleared next tick (since it will be no longer needed after that). static std::list fpathPrevBlockingMaps; +/// Game time for all blocking maps in fpathBlockingMaps. +static uint32_t fpathCurrentGameTime; // Convert a direction into an offset // dir 0 => x = 0, y = -1 diff --git a/src/fpath.c b/src/fpath.c index 2f36855e5..1bf45ec92 100644 --- a/src/fpath.c +++ b/src/fpath.c @@ -164,6 +164,7 @@ static int fpathThreadFunc(WZ_DECL_UNUSED void *data) psResult->done = false; psResult->droidID = job.droidID; psResult->sMove.asPath = NULL; + psResult->sMove.numPoints = 0; psResult->retval = FPR_FAILED; // Add to beginning of result list @@ -540,11 +541,7 @@ static FPATH_RETVAL fpathRoute(MOVE_CONTROL *psMove, int id, int startX, int sta // We were not waiting for a result, and found no trivial path, so create new job and start waiting psJob = malloc(sizeof(*psJob)); - ASSERT(psJob, "Out of memory"); - if (!psJob) - { - return FPR_FAILED; - } + ASSERT_OR_RETURN(FPR_FAILED, psJob, "Out of memory"); psJob->origX = startX; psJob->origY = startY; psJob->droidID = id;