[Scummvm-git-logs] scummvm master -> 42095cf1d792f5d11527148e16112a63657c592b

dreammaster dreammaster at scummvm.org
Thu Feb 25 03:41:39 UTC 2021


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f1642da870 AGS: Fix jps routefinder
42095cf1d7 AGS: Change route_finder_jps from inline to cpp file


Commit: f1642da87008cea2cafce48926180bd48fe3f183
    https://github.com/scummvm/scummvm/commit/f1642da87008cea2cafce48926180bd48fe3f183
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-02-24T19:41:12-08:00

Commit Message:
AGS: Fix jps routefinder

Changed paths:
    engines/ags/engine/ac/route_finder_jps.inl
    engines/ags/lib/std/algorithm.h


diff --git a/engines/ags/engine/ac/route_finder_jps.inl b/engines/ags/engine/ac/route_finder_jps.inl
index 4b861953e1..dea4d2ba11 100644
--- a/engines/ags/engine/ac/route_finder_jps.inl
+++ b/engines/ags/engine/ac/route_finder_jps.inl
@@ -695,7 +695,7 @@ Navigation::NavResult Navigation::NavigateRefined(int sx, int sy, int ex, int ey
 
 	std::swap(opath, fpath);
 
-	// validate cpath
+	// Validate ncpath in debug builds
 	for (int i = 0; i < (int)ncpath.size() - 1; i++) {
 		int tx, ty;
 		UnpackSquare(ncpath[i], fx, fy);
diff --git a/engines/ags/lib/std/algorithm.h b/engines/ags/lib/std/algorithm.h
index 427779ca84..c4f3d355a8 100644
--- a/engines/ags/lib/std/algorithm.h
+++ b/engines/ags/lib/std/algorithm.h
@@ -34,7 +34,7 @@ template<typename T> inline T min(T a, T b) { return MIN(a, b); }
 template<typename T> inline T max(T a, T b) { return MAX(a, b); }
 template<typename T> inline T clip(T v, T amin, T amax) { return CLIP(v, amin, amax); }
 template<typename T> inline T sqrt(T x) { return ::sqrt(x); }
-template<typename T> inline void swap(T a, T b) { SWAP(a, b); }
+template<typename T> inline void swap(T &a, T &b) { SWAP(a, b); }
 
 template<class In, class Value>
 In fill(In first, In last, const Value &val) {


Commit: 42095cf1d792f5d11527148e16112a63657c592b
    https://github.com/scummvm/scummvm/commit/42095cf1d792f5d11527148e16112a63657c592b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-02-24T19:41:12-08:00

Commit Message:
AGS: Change route_finder_jps from inline to cpp file

Changed paths:
  A engines/ags/engine/ac/route_finder_jps.cpp
  A engines/ags/engine/ac/route_finder_jps.h
  R engines/ags/engine/ac/route_finder_jps.inl
    engines/ags/engine/ac/route_finder_impl.cpp
    engines/ags/module.mk


diff --git a/engines/ags/engine/ac/route_finder_impl.cpp b/engines/ags/engine/ac/route_finder_impl.cpp
index 95bcdb4ba6..49bfdee00a 100644
--- a/engines/ags/engine/ac/route_finder_impl.cpp
+++ b/engines/ags/engine/ac/route_finder_impl.cpp
@@ -27,18 +27,13 @@
 //=============================================================================
 
 #include "ags/engine/ac/route_finder_impl.h"
-
-//include <string.h>
-//include <math.h>
-
+#include "ags/engine/ac/route_finder_jps.h"
 #include "ags/shared/ac/common.h"   // quit()
 #include "ags/engine/ac/movelist.h"     // MoveList
 #include "ags/shared/ac/common_defines.h"
 #include "ags/shared/gfx/bitmap.h"
 #include "ags/shared/debugging/out.h"
 
-#include "ags/engine/ac/route_finder_jps.inl"
-
 namespace AGS3 {
 
 extern MoveList *mls;
@@ -263,7 +258,6 @@ int find_route(short srcx, short srcy, short xx, short yy, Bitmap *onscreen, int
 	return mlist;
 }
 
-
 } // namespace RouteFinder
 } // namespace Engine
 } // namespace AGS
diff --git a/engines/ags/engine/ac/route_finder_jps.inl b/engines/ags/engine/ac/route_finder_jps.cpp
similarity index 82%
rename from engines/ags/engine/ac/route_finder_jps.inl
rename to engines/ags/engine/ac/route_finder_jps.cpp
index dea4d2ba11..a84d411a31 100644
--- a/engines/ags/engine/ac/route_finder_jps.inl
+++ b/engines/ags/engine/ac/route_finder_jps.cpp
@@ -27,14 +27,7 @@
 //
 //=============================================================================
 
-#include "ags/lib/std/queue.h"
-#include "ags/lib/std/vector.h"
-#include "ags/lib/std/algorithm.h"
-#include "ags/lib/std/functional.h"
-#include "ags/lib/std/xutility.h"
-//include <assert.h>
-//include <stddef.h>
-//include <math.h>
+#include "ags/engine/ac/route_finder_jps.h"
 
 // Not all platforms define INFINITY
 #ifndef INFINITY
@@ -43,145 +36,6 @@
 
 namespace AGS3 {
 
-// TODO: this could be cleaned up/simplified ...
-
-// further optimizations possible:
-//    - forward refinement should use binary search
-
-class Navigation {
-public:
-	Navigation();
-
-	void Resize(int width, int height);
-
-	enum NavResult {
-		// unreachable
-		NAV_UNREACHABLE,
-		// straight line exists
-		NAV_STRAIGHT,
-		// path used
-		NAV_PATH
-	};
-
-	// ncpath = navpoint-compressed path
-	// opath = path composed of individual grid elements
-	NavResult NavigateRefined(int sx, int sy, int ex, int ey, std::vector<int> &opath,
-		std::vector<int> &ncpath);
-
-	NavResult Navigate(int sx, int sy, int ex, int ey, std::vector<int> &opath);
-
-	bool TraceLine(int srcx, int srcy, int targx, int targy, int &lastValidX, int &lastValidY) const;
-	bool TraceLine(int srcx, int srcy, int targx, int targy, std::vector<int> *rpath = nullptr) const;
-
-	inline void SetMapRow(int y, const unsigned char *row) {
-		map[y] = row;
-	}
-
-	inline static int PackSquare(int x, int y);
-	inline static void UnpackSquare(int sq, int &x, int &y);
-
-private:
-	// priority queue entry
-	struct Entry {
-		float cost;
-		int index;
-
-		inline Entry() = default;
-
-		inline Entry(float ncost, int nindex)
-			: cost(ncost)
-			, index(nindex) {
-		}
-
-		inline bool operator <(const Entry &b) const {
-			return cost < b.cost;
-		}
-
-		inline bool operator >(const Entry &b) const {
-			return cost > b.cost;
-		}
-	};
-
-	int mapWidth;
-	int mapHeight;
-	std::vector<const unsigned char *> map;
-
-	typedef unsigned short tFrameId;
-	typedef int tPrev;
-
-	struct NodeInfo {
-		// quantized min distance from origin
-		unsigned short dist;
-		// frame id (counter to detect new search)
-		tFrameId frameId;
-		// previous node index (packed, relative to current node)
-		tPrev prev;
-
-		inline NodeInfo()
-			: dist(0)
-			, frameId(0)
-			, prev(-1) {
-		}
-	};
-
-	static const float DIST_SCALE_PACK;
-	static const float DIST_SCALE_UNPACK;
-
-	std::vector<NodeInfo> mapNodes;
-	tFrameId frameId;
-
-	std::priority_queue<Entry, std::vector<Entry>, Common::Greater<Entry> > pq;
-
-	// temporary buffers:
-	mutable std::vector<int> fpath;
-	std::vector<int> ncpathIndex;
-	std::vector<int> rayPath, orayPath;
-
-	// temps for routing towards unreachable areas
-	int cnode;
-	int closest;
-
-	// orthogonal only (this should correspond to what AGS is doing)
-	bool nodiag;
-
-	bool navLock;
-
-	void IncFrameId();
-
-	// outside map test
-	inline bool Outside(int x, int y) const;
-	// stronger inside test
-	bool Passable(int x, int y) const;
-	// plain access, unchecked
-	inline bool Walkable(int x, int y) const;
-
-	void AddPruned(int *buf, int &bcount, int x, int y) const;
-	bool HasForcedNeighbor(int x, int y, int dx, int dy) const;
-	int FindJump(int x, int y, int dx, int dy, int ex, int ey);
-	int FindOrthoJump(int x, int y, int dx, int dy, int ex, int ey);
-
-	// neighbor reachable (nodiag only)
-	bool Reachable(int x0, int y0, int x1, int y1) const;
-
-	static inline int sign(int n) {
-		return n < 0 ? -1 : (n > 0 ? 1 : 0);
-	}
-
-	static inline int iabs(int n) {
-		return n < 0 ? -n : n;
-	}
-
-	static inline int iclamp(int v, int min, int max) {
-		return v < min ? min : (v > max ? max : v);
-	}
-
-	static inline int ClosestDist(int dx, int dy) {
-		return dx * dx + dy * dy;
-		// Manhattan?
-		//return iabs(dx) + iabs(dy);
-	}
-};
-
 // Navigation
 
 // scale pack of 2 means we can route up to 32767 units (euclidean distance) from starting point
diff --git a/engines/ags/engine/ac/route_finder_jps.h b/engines/ags/engine/ac/route_finder_jps.h
new file mode 100644
index 0000000000..b4963f8aab
--- /dev/null
+++ b/engines/ags/engine/ac/route_finder_jps.h
@@ -0,0 +1,175 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "ags/lib/std/queue.h"
+#include "ags/lib/std/vector.h"
+#include "ags/lib/std/algorithm.h"
+#include "ags/lib/std/functional.h"
+#include "ags/lib/std/xutility.h"
+
+// Not all platforms define INFINITY
+#ifndef INFINITY
+#define INFINITY   ((float)(1e+300 * 1e+300)) // This must overflow
+#endif
+
+namespace AGS3 {
+
+// TODO: this could be cleaned up/simplified ...
+
+// further optimizations possible:
+//    - forward refinement should use binary search
+
+class Navigation {
+public:
+	Navigation();
+
+	void Resize(int width, int height);
+
+	enum NavResult {
+		// unreachable
+		NAV_UNREACHABLE,
+		// straight line exists
+		NAV_STRAIGHT,
+		// path used
+		NAV_PATH
+	};
+
+	// ncpath = navpoint-compressed path
+	// opath = path composed of individual grid elements
+	NavResult NavigateRefined(int sx, int sy, int ex, int ey, std::vector<int> &opath,
+		std::vector<int> &ncpath);
+
+	NavResult Navigate(int sx, int sy, int ex, int ey, std::vector<int> &opath);
+
+	bool TraceLine(int srcx, int srcy, int targx, int targy, int &lastValidX, int &lastValidY) const;
+	bool TraceLine(int srcx, int srcy, int targx, int targy, std::vector<int> *rpath = nullptr) const;
+
+	inline void SetMapRow(int y, const unsigned char *row) {
+		map[y] = row;
+	}
+
+	inline static int PackSquare(int x, int y);
+	inline static void UnpackSquare(int sq, int &x, int &y);
+
+private:
+	// priority queue entry
+	struct Entry {
+		float cost;
+		int index;
+
+		inline Entry() = default;
+
+		inline Entry(float ncost, int nindex)
+			: cost(ncost)
+			, index(nindex) {
+		}
+
+		inline bool operator <(const Entry &b) const {
+			return cost < b.cost;
+		}
+
+		inline bool operator >(const Entry &b) const {
+			return cost > b.cost;
+		}
+	};
+
+	int mapWidth;
+	int mapHeight;
+	std::vector<const unsigned char *> map;
+
+	typedef unsigned short tFrameId;
+	typedef int tPrev;
+
+	struct NodeInfo {
+		// quantized min distance from origin
+		unsigned short dist;
+		// frame id (counter to detect new search)
+		tFrameId frameId;
+		// previous node index (packed, relative to current node)
+		tPrev prev;
+
+		inline NodeInfo()
+			: dist(0)
+			, frameId(0)
+			, prev(-1) {
+		}
+	};
+
+	static const float DIST_SCALE_PACK;
+	static const float DIST_SCALE_UNPACK;
+
+	std::vector<NodeInfo> mapNodes;
+	tFrameId frameId;
+
+	std::priority_queue<Entry, std::vector<Entry>, Common::Greater<Entry> > pq;
+
+	// temporary buffers:
+	mutable std::vector<int> fpath;
+	std::vector<int> ncpathIndex;
+	std::vector<int> rayPath, orayPath;
+
+	// temps for routing towards unreachable areas
+	int cnode;
+	int closest;
+
+	// orthogonal only (this should correspond to what AGS is doing)
+	bool nodiag;
+
+	bool navLock;
+
+	void IncFrameId();
+
+	// outside map test
+	inline bool Outside(int x, int y) const;
+	// stronger inside test
+	bool Passable(int x, int y) const;
+	// plain access, unchecked
+	inline bool Walkable(int x, int y) const;
+
+	void AddPruned(int *buf, int &bcount, int x, int y) const;
+	bool HasForcedNeighbor(int x, int y, int dx, int dy) const;
+	int FindJump(int x, int y, int dx, int dy, int ex, int ey);
+	int FindOrthoJump(int x, int y, int dx, int dy, int ex, int ey);
+
+	// neighbor reachable (nodiag only)
+	bool Reachable(int x0, int y0, int x1, int y1) const;
+
+	static inline int sign(int n) {
+		return n < 0 ? -1 : (n > 0 ? 1 : 0);
+	}
+
+	static inline int iabs(int n) {
+		return n < 0 ? -n : n;
+	}
+
+	static inline int iclamp(int v, int min, int max) {
+		return v < min ? min : (v > max ? max : v);
+	}
+
+	static inline int ClosestDist(int dx, int dy) {
+		return dx * dx + dy * dy;
+		// Manhattan?
+		//return iabs(dx) + iabs(dy);
+	}
+};
+
+} // namespace AGS3
diff --git a/engines/ags/module.mk b/engines/ags/module.mk
index 9e571bf333..3b7a17745e 100644
--- a/engines/ags/module.mk
+++ b/engines/ags/module.mk
@@ -208,6 +208,7 @@ MODULE_OBJS = \
     engine/ac/roomobject.o \
     engine/ac/roomstatus.o \
     engine/ac/route_finder.o \
+	engine/ac/route_finder_jps.o \
     engine/ac/screen.o \
     engine/ac/screenoverlay.o \
     engine/ac/slider.o \




More information about the Scummvm-git-logs mailing list