[Scummvm-cvs-logs] SF.net SVN: scummvm:[53949] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Sat Oct 30 19:26:49 CEST 2010


Revision: 53949
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53949&view=rev
Author:   drmccoy
Date:     2010-10-30 17:26:49 +0000 (Sat, 30 Oct 2010)

Log Message:
-----------
GOB: Make Map::_wayPoints protected

Only allow const access through Map::getWayPoint()

Modified Paths:
--------------
    scummvm/trunk/engines/gob/goblin_v1.cpp
    scummvm/trunk/engines/gob/goblin_v2.cpp
    scummvm/trunk/engines/gob/goblin_v4.cpp
    scummvm/trunk/engines/gob/map.cpp
    scummvm/trunk/engines/gob/map.h
    scummvm/trunk/engines/gob/map_v1.cpp
    scummvm/trunk/engines/gob/map_v2.cpp

Modified: scummvm/trunk/engines/gob/goblin_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin_v1.cpp	2010-10-30 17:26:06 UTC (rev 53948)
+++ scummvm/trunk/engines/gob/goblin_v1.cpp	2010-10-30 17:26:49 UTC (rev 53949)
@@ -154,8 +154,10 @@
 			_vm->_map->_nearestWayPoint, _vm->_map->_nearestDest) == 0) {
 			_pathExistence = 0;
 		} else {
-			_vm->_map->_destX = _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].x;
-			_vm->_map->_destY = _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].y;
+			const WayPoint &wayPoint = _vm->_map->getWayPoint(_vm->_map->_nearestWayPoint);
+
+			_vm->_map->_destX = wayPoint.x;
+			_vm->_map->_destY = wayPoint.y;
 		}
 	}
 }
@@ -199,29 +201,33 @@
 				if (_vm->_map->_nearestWayPoint > _vm->_map->_nearestDest) {
 					_vm->_map->optimizePoints(0, 0, 0);
 
-					_vm->_map->_destX =
-					    _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].x;
-					_vm->_map->_destY =
-					    _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].y;
+					const WayPoint &wayPoint = _vm->_map->getWayPoint(_vm->_map->_nearestWayPoint);
 
+					_vm->_map->_destX = wayPoint.x;
+					_vm->_map->_destY = wayPoint.y;
+
 					if (_vm->_map->_nearestWayPoint > _vm->_map->_nearestDest)
 						_vm->_map->_nearestWayPoint--;
 				} else if (_vm->_map->_nearestWayPoint < _vm->_map->_nearestDest) {
 					_vm->_map->optimizePoints(0, 0, 0);
 
-					_vm->_map->_destX =
-					    _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].x;
-					_vm->_map->_destY =
-					    _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].y;
+					const WayPoint &wayPoint = _vm->_map->getWayPoint(_vm->_map->_nearestWayPoint);
 
+					_vm->_map->_destX = wayPoint.x;
+					_vm->_map->_destY = wayPoint.y;
+
 					if (_vm->_map->_nearestWayPoint < _vm->_map->_nearestDest)
 						_vm->_map->_nearestWayPoint++;
 				} else {
 					if ((_vm->_map->checkDirectPath(0, _vm->_map->_curGoblinX,
 						_vm->_map->_curGoblinY, _gobDestX, _gobDestY) == 3) &&
 							(_vm->_map->getPass(_pressedMapX, _pressedMapY) != 0)) {
-						_vm->_map->_destX = _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].x;
-						_vm->_map->_destY = _vm->_map->_wayPoints[_vm->_map->_nearestWayPoint].y;
+
+						const WayPoint &wayPoint = _vm->_map->getWayPoint(_vm->_map->_nearestWayPoint);
+
+						_vm->_map->_destX = wayPoint.x;
+						_vm->_map->_destY = wayPoint.y;
+
 					} else {
 						_pathExistence = 1;
 						_vm->_map->_destX = _pressedMapX;

Modified: scummvm/trunk/engines/gob/goblin_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin_v2.cpp	2010-10-30 17:26:06 UTC (rev 53948)
+++ scummvm/trunk/engines/gob/goblin_v2.cpp	2010-10-30 17:26:49 UTC (rev 53949)
@@ -121,8 +121,10 @@
 	obj->pAnimData->pathExistence = _vm->_map->checkDirectPath(obj,
 			obj->goblinX, obj->goblinY, obj->gobDestX, obj->gobDestY);
 	if (obj->pAnimData->pathExistence == 3) {
-		obj->destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
-		obj->destY = _vm->_map->_wayPoints[obj->nearestWayPoint].y;
+		const WayPoint &wayPoint = _vm->_map->getWayPoint(obj->nearestWayPoint);
+
+		obj->destX = wayPoint.x;
+		obj->destY = wayPoint.y;
 	}
 }
 
@@ -162,8 +164,12 @@
 
 					if (obj->nearestWayPoint > obj->nearestDest) {
 						_vm->_map->optimizePoints(obj, gobX, gobY);
-						destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
-						destY = _vm->_map->_wayPoints[obj->nearestWayPoint].y;
+
+						const WayPoint &wayPoint = _vm->_map->getWayPoint(obj->nearestWayPoint);
+
+						destX = wayPoint.x;
+						destY = wayPoint.y;
+
 						if (_vm->_map->checkDirectPath(obj, gobX, gobY, destX, destY) == 3) {
 							WRITE_VAR(56, 1);
 							animData->pathExistence = 0;
@@ -172,8 +178,12 @@
 							obj->nearestWayPoint--;
 					} else if (obj->nearestWayPoint < obj->nearestDest) {
 						_vm->_map->optimizePoints(obj, gobX, gobY);
-						destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
-						destY = _vm->_map->_wayPoints[obj->nearestWayPoint].y;
+
+						const WayPoint &wayPoint = _vm->_map->getWayPoint(obj->nearestWayPoint);
+
+						destX = wayPoint.x;
+						destY = wayPoint.y;
+
 						if (_vm->_map->checkDirectPath(obj, gobX, gobY, destX, destY) == 3) {
 							WRITE_VAR(56, 1);
 							animData->pathExistence = 0;
@@ -183,8 +193,12 @@
 					} else {
 						if ((_vm->_map->checkDirectPath(obj, gobX, gobY, gobDestX, gobDestY) == 3) &&
 								(_vm->_map->getPass(gobDestX, gobDestY) != 0)) {
-							destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
-							destY = _vm->_map->_wayPoints[obj->nearestWayPoint].y;
+
+							const WayPoint &wayPoint = _vm->_map->getWayPoint(obj->nearestWayPoint);
+
+							destX = wayPoint.x;
+							destY = wayPoint.y;
+
 							WRITE_VAR(56, 1);
 						} else {
 							animData->pathExistence = 1;

Modified: scummvm/trunk/engines/gob/goblin_v4.cpp
===================================================================
--- scummvm/trunk/engines/gob/goblin_v4.cpp	2010-10-30 17:26:06 UTC (rev 53948)
+++ scummvm/trunk/engines/gob/goblin_v4.cpp	2010-10-30 17:26:49 UTC (rev 53949)
@@ -77,8 +77,12 @@
 				if ((gobX == destX) && (gobY == destY)) {
 					if (obj->nearestWayPoint > obj->nearestDest) {
 						_vm->_map->optimizePoints(obj, gobX, gobY);
-						destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
-						destY = _vm->_map->_wayPoints[obj->nearestWayPoint].y;
+
+						const WayPoint &wayPoint = _vm->_map->getWayPoint(obj->nearestWayPoint);
+
+						destX = wayPoint.x;
+						destY = wayPoint.y;
+
 						if (_vm->_map->checkDirectPath(obj, gobX, gobY, destX, destY) == 3) {
 							WRITE_VAR(56, 1);
 							animData->pathExistence = 0;
@@ -87,8 +91,12 @@
 							obj->nearestWayPoint--;
 					} else if (obj->nearestWayPoint < obj->nearestDest) {
 						_vm->_map->optimizePoints(obj, gobX, gobY);
-						destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
-						destY = _vm->_map->_wayPoints[obj->nearestWayPoint].y;
+
+						const WayPoint &wayPoint = _vm->_map->getWayPoint(obj->nearestWayPoint);
+
+						destX = wayPoint.x;
+						destY = wayPoint.y;
+
 						if (_vm->_map->checkDirectPath(obj, gobX, gobY, destX, destY) == 3) {
 							WRITE_VAR(56, 1);
 							animData->pathExistence = 0;
@@ -98,8 +106,12 @@
 					} else {
 						if ((_vm->_map->checkDirectPath(obj, gobX, gobY, gobDestX, gobDestY) == 3) &&
 								(_vm->_map->getPass(gobDestX, gobDestY) != 0)) {
-							destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
-							destY = _vm->_map->_wayPoints[obj->nearestWayPoint].y;
+
+							const WayPoint &wayPoint = _vm->_map->getWayPoint(obj->nearestWayPoint);
+
+							destX = wayPoint.x;
+							destY = wayPoint.y;
+
 							WRITE_VAR(56, 1);
 						} else {
 							animData->pathExistence = 1;

Modified: scummvm/trunk/engines/gob/map.cpp
===================================================================
--- scummvm/trunk/engines/gob/map.cpp	2010-10-30 17:26:06 UTC (rev 53948)
+++ scummvm/trunk/engines/gob/map.cpp	2010-10-30 17:26:49 UTC (rev 53949)
@@ -106,6 +106,13 @@
 	_passMap[y * width + x] = pass;
 }
 
+const WayPoint &Map::getWayPoint(int n) const {
+	assert(_wayPoints);
+	assert(n < _wayPointCount);
+
+	return _wayPoints[n];
+}
+
 void Map::placeItem(int16 x, int16 y, int16 id) {
 	if ((getItem(x, y) & 0xFF00) != 0)
 		setItem(x, y, (getItem(x, y) & 0xFF00) | id);

Modified: scummvm/trunk/engines/gob/map.h
===================================================================
--- scummvm/trunk/engines/gob/map.h	2010-10-30 17:26:06 UTC (rev 53948)
+++ scummvm/trunk/engines/gob/map.h	2010-10-30 17:26:49 UTC (rev 53949)
@@ -57,18 +57,18 @@
 	kDirSE   = 0x5100
 };
 
+struct WayPoint {
+	int16 x;
+	int16 y;
+	int16 notWalkable;
+};
+
+
 class Map {
 public:
 #include "common/pack-start.h"	// START STRUCT PACKING
 
-	struct Point {
-		int16 x;
-		int16 y;
-		int16 notWalkable;
-	} PACKED_STRUCT;
-
 #define szMap_ItemPos 3
-
 	struct ItemPos {
 		int8 x;
 		int8 y;
@@ -91,9 +91,6 @@
 
 	bool _mapUnknownBool;
 
-	int16 _wayPointCount;
-	Point *_wayPoints;
-
 	int16 _nearestWayPoint;
 	int16 _nearestDest;
 
@@ -113,6 +110,8 @@
 	int8 getPass(int x, int y, int width = -1) const;
 	void setPass(int x, int y, int8 pass, int width = -1);
 
+	const WayPoint &getWayPoint(int n) const;
+
 	void findNearestWalkable(int16 &gobDestX, int16 &gobDestY,
 		int16 mouseX, int16 mouseY);
 
@@ -143,6 +142,9 @@
 	int16 _passWidth;
 	int8 *_passMap; // [y * _mapWidth + x], getPass(x, y);
 
+	int16 _wayPointCount;
+	WayPoint *_wayPoints;
+
 	int16 findNearestWayPoint(int16 x, int16 y);
 
 private:

Modified: scummvm/trunk/engines/gob/map_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/map_v1.cpp	2010-10-30 17:26:06 UTC (rev 53948)
+++ scummvm/trunk/engines/gob/map_v1.cpp	2010-10-30 17:26:49 UTC (rev 53949)
@@ -58,8 +58,8 @@
 	}
 
 	_wayPointCount = 40;
-	_wayPoints = new Point[40];
-	memset(_wayPoints, 0, sizeof(Point));
+	_wayPoints = new WayPoint[40];
+	memset(_wayPoints, 0, sizeof(WayPoint));
 }
 
 void Map_v1::loadMapObjects(const char *avjFile) {

Modified: scummvm/trunk/engines/gob/map_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/map_v2.cpp	2010-10-30 17:26:06 UTC (rev 53948)
+++ scummvm/trunk/engines/gob/map_v2.cpp	2010-10-30 17:26:49 UTC (rev 53949)
@@ -138,7 +138,7 @@
 		wayPointsCount = _wayPointCount == 0 ? 1 : _wayPointCount;
 
 	delete[] _wayPoints;
-	_wayPoints = new Point[wayPointsCount];
+	_wayPoints = new WayPoint[wayPointsCount];
 	for (int i = 0; i < _wayPointCount; i++) {
 		_wayPoints[i].x = mapData.readSByte();
 		_wayPoints[i].y = mapData.readSByte();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list