Skip to content

Commit

Permalink
fixes (round #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaylewt committed Oct 22, 2011
1 parent d7cc2c4 commit 91065c1
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion rts/ExternalAI/AICallback.cpp
Expand Up @@ -733,7 +733,7 @@ int CAICallback::InitPath(const float3& start, const float3& end, int pathType,

float3 CAICallback::GetNextWaypoint(int pathId)
{
return pathManager->NextWaypoint(pathId, ZeroVector, 0.0f, 0, 0, false);
return pathManager->NextWayPoint(pathId, ZeroVector, 0.0f, 0, 0, false);
}

void CAICallback::FreePath(int pathId)
Expand Down
2 changes: 1 addition & 1 deletion rts/Game/Game.cpp
Expand Up @@ -567,7 +567,7 @@ void CGame::LoadSimulation(const std::string& mapName)
loshandler = new CLosHandler();
radarhandler = new CRadarHandler(false);

pathManager = IPathManager::GetInstance();
pathManager = IPathManager::GetInstance(IPathManager::PM_TYPE_QTPFS);

wind.LoadWind(mapInfo->atmosphere.minWind, mapInfo->atmosphere.maxWind);

Expand Down
2 changes: 1 addition & 1 deletion rts/Lua/LuaPathFinder.cpp
Expand Up @@ -127,7 +127,7 @@ static int path_next(lua_State* L)
const float minDist = luaL_optfloat(L, 5, 0.0f);

const bool synced = CLuaHandle::GetSynced(L);
const float3 point = pathManager->NextWaypoint(pathID, callerPos, minDist, 0, 0, synced);
const float3 point = pathManager->NextWayPoint(pathID, callerPos, minDist, 0, 0, synced);

if ((point.x == -1.0f) &&
(point.y == -1.0f) &&
Expand Down
13 changes: 6 additions & 7 deletions rts/Sim/MoveTypes/GroundMoveType.cpp
Expand Up @@ -258,7 +258,7 @@ bool CGroundMoveType::Update()
const bool wpBehind = (waypointDir.dot(flatFrontDir) < 0.0f);

if (!haveFinalWaypoint) {
GetNextWaypoint();
GetNextWayPoint();
} else {
if (atGoal) {
Arrived();
Expand Down Expand Up @@ -492,7 +492,7 @@ void CGroundMoveType::SetDeltaSpeed(float newWantedSpeed, bool wantReverse, bool
}

if (startBreaking) {
// at this point, Update() will no longer call GetNextWaypoint()
// at this point, Update() will no longer call GetNextWayPoint()
// and we must slow down to prevent entering an infinite circle
wSpeed = std::min(wSpeed, fastmath::apxsqrt(currWayPointDist * decRate));
}
Expand Down Expand Up @@ -1084,7 +1084,7 @@ void CGroundMoveType::GetNewPath()
haveFinalWaypoint = false;

waypoint = owner->pos;
nextWaypoint = pathManager->NextWaypoint(pathId, waypoint, 1.25f * SQUARE_SIZE, 0, owner->id);
nextWaypoint = pathManager->NextWayPoint(pathId, waypoint, 1.25f * SQUARE_SIZE, 0, owner->id);
} else {
Fail();
}
Expand All @@ -1097,9 +1097,8 @@ void CGroundMoveType::GetNewPath()
/*
Sets waypoint to next in path.
*/
void CGroundMoveType::GetNextWaypoint()
void CGroundMoveType::GetNextWayPoint()
{

if (pathId == 0) {
return;
}
Expand Down Expand Up @@ -1131,7 +1130,7 @@ void CGroundMoveType::GetNextWaypoint()

if (nextWaypoint.x != -1.0f && (nextWaypoint - waypoint).SqLength2D() > 0.1f) {
waypoint = nextWaypoint;
nextWaypoint = pathManager->NextWaypoint(pathId, waypoint, 1.25f * SQUARE_SIZE, 0, owner->id);
nextWaypoint = pathManager->NextWayPoint(pathId, waypoint, 1.25f * SQUARE_SIZE, 0, owner->id);

if (waypoint.SqDistance2D(goalPos) < Square(MIN_WAYPOINT_DISTANCE)) {
waypoint = goalPos;
Expand Down Expand Up @@ -1681,7 +1680,7 @@ void CGroundMoveType::TestNewTerrainSquare()
break;
}

GetNextWaypoint();
GetNextWayPoint();

nwsx = (int) nextWaypoint.x / (MIN_WAYPOINT_DISTANCE) - moveSquareX;
nwsy = (int) nextWaypoint.z / (MIN_WAYPOINT_DISTANCE) - moveSquareY;
Expand Down
2 changes: 1 addition & 1 deletion rts/Sim/MoveTypes/GroundMoveType.h
Expand Up @@ -71,7 +71,7 @@ class CGroundMoveType : public AMoveType
float Distance2D(CSolidObject* object1, CSolidObject* object2, float marginal = 0.0f);

void GetNewPath();
void GetNextWaypoint();
void GetNextWayPoint();

float BreakingDistance(float speed) const;
float3 Here();
Expand Down
6 changes: 3 additions & 3 deletions rts/Sim/Path/Default/PathManager.cpp
Expand Up @@ -282,14 +282,14 @@ void CPathManager::LowRes2MedRes(MultiPath& multiPath, const float3& startPos, i
/*
Removes and return the next waypoint in the multipath corresponding to given id.
*/
float3 CPathManager::NextWaypoint(
float3 CPathManager::NextWayPoint(
unsigned int pathId,
float3 callerPos,
float minDistance,
int numRetries,
int ownerId,
bool synced
) const {
) {
SCOPED_TIMER("PathManager::NextWaypoint");

// 0 indicates a no-path id
Expand Down Expand Up @@ -350,7 +350,7 @@ float3 CPathManager::NextWaypoint(
return float3(-1.0f, -1.0f, -1.0f);
}
} else {
return NextWaypoint(pathId, callerPos, minDistance, numRetries + 1, ownerId, synced);
return NextWayPoint(pathId, callerPos, minDistance, numRetries + 1, ownerId, synced);
}
} else {
waypoint = multiPath->maxResPath.path.back();
Expand Down
4 changes: 2 additions & 2 deletions rts/Sim/Path/Default/PathManager.h
Expand Up @@ -30,14 +30,14 @@ class CPathManager: public IPathManager {
void DeletePath(unsigned int pathId);


float3 NextWaypoint(
float3 NextWayPoint(
unsigned int pathId,
float3 callerPos,
float minDistance = 0.0f,
int numRetries = 0,
int ownerId = 0,
bool synced = true
) const;
);

unsigned int RequestPath(
const MoveData* moveData,
Expand Down
11 changes: 5 additions & 6 deletions rts/Sim/Path/IPathManager.cpp
Expand Up @@ -6,15 +6,14 @@

IPathManager* pathManager = NULL;

IPathManager* IPathManager::GetInstance() {
IPathManager* IPathManager::GetInstance(unsigned int type) {
static IPathManager* pm = NULL;

if (pm == NULL) {
#ifdef DEFAULT_PFS
pm = new CPathManager();
#else
pm = new QTPFS::PathManager();
#endif
switch (type) {
case PM_TYPE_DEFAULT: { pm = new CPathManager(); } break;
case PM_TYPE_QTPFS: { pm = new QTPFS::PathManager(); } break;
}
}

return pm;
Expand Down
11 changes: 8 additions & 3 deletions rts/Sim/Path/IPathManager.h
Expand Up @@ -11,7 +11,7 @@ class CSolidObject;

class IPathManager {
public:
static IPathManager* GetInstance();
static IPathManager* GetInstance(unsigned int type);

virtual ~IPathManager() {}

Expand Down Expand Up @@ -53,14 +53,14 @@ class IPathManager {
* the next waypoint of the path, or (-1,-1,-1) in case no new
* waypoint could be found.
*/
virtual float3 NextWaypoint(
virtual float3 NextWayPoint(
unsigned int pathId,
float3 callerPos,
float minDistance = 0.0f,
int numRetries = 0,
int ownerId = 0,
bool synced = true
) const { return ZeroVector; }
) { return ZeroVector; }

//! NOTE: should not be in the interface
/**
Expand Down Expand Up @@ -138,6 +138,11 @@ class IPathManager {
virtual bool SetNodeExtraCost(unsigned int x, unsigned int z, float cost, bool synced) { return false; }
virtual float GetNodeExtraCost(unsigned int x, unsigned int z, bool synced) const { return 0.0f; }
virtual const float* GetNodeExtraCosts(bool synced) const { return NULL; }

enum {
PM_TYPE_DEFAULT = 0,
PM_TYPE_QTPFS = 1,
};
};

extern IPathManager* pathManager;
Expand Down
13 changes: 10 additions & 3 deletions rts/Sim/Path/QTPFS/PathManager.cpp
Expand Up @@ -351,7 +351,14 @@ void QTPFS::PathManager::Update() {
}
}

float3 QTPFS::PathManager::NextWaypoint(unsigned int pathID, float3 curPoint, float rad, int, int, bool) {
float3 QTPFS::PathManager::NextWayPoint(
unsigned int pathID,
float3 curPoint,
float radius,
int, // numTrials
int, // ownerID
bool synced
) {
const PathCacheMap::const_iterator cacheIt = pathCacheMap.find(pathID);

// dangling ID after re-request failure or regular deletion
Expand All @@ -371,7 +378,7 @@ float3 QTPFS::PathManager::NextWaypoint(unsigned int pathID, float3 curPoint, fl

assert(livePath->GetID() != 0);

const float radSq = std::max(float(SQUARE_SIZE), rad * rad);
const float radiusSq = std::max(float(SQUARE_SIZE), radius * radius);

unsigned int curPointIdx = 0;
unsigned int nxtPointIdx = -1U;
Expand All @@ -381,7 +388,7 @@ float3 QTPFS::PathManager::NextWaypoint(unsigned int pathID, float3 curPoint, fl
for (unsigned int i = 0; i < (livePath->NumPoints() - 1); i++) {
const float3& point = livePath->GetPoint(i);

if ((curPoint - point).SqLength() < radSq) {
if ((curPoint - point).SqLength() < radiusSq) {
curPointIdx = i;
nxtPointIdx = i + 1;
}
Expand Down
9 changes: 8 additions & 1 deletion rts/Sim/Path/QTPFS/PathManager.hpp
Expand Up @@ -36,7 +36,14 @@ namespace QTPFS {
bool synced
);

float3 NextWaypoint(unsigned int pathID, float3 pos, float rad, int, int, bool);
float3 NextWayPoint(
unsigned int pathID,
float3 curPoint,
float radius = 0.0f,
int = 0, // numRetries
int = 0, // ownerID
bool synced = true
);
static NodeLayer* GetSerializingNodeLayer() { return serializingNodeLayer; }

static const unsigned int NUM_SPEEDMOD_BINS = 20;
Expand Down

0 comments on commit 91065c1

Please sign in to comment.