[Scummvm-git-logs] scummvm master -> 43fb0d20666240095650328eb1d3e9281fe65a9e

OMGPizzaGuy noreply at scummvm.org
Mon Jan 2 20:22:22 UTC 2023


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

Summary:
56bb953dd7 ULTIMA8: Add get item location to minimap to avoid calculation in gump
b808457b2b ULTIMA8: Adjust sweep test when items hit at same time.
906379789d ULTIMA8: Replace minimap sample top item trace with a sweeep test.
43fb0d2066 ULTIMA8: Remove map trace top item now that it is unused


Commit: 56bb953dd7c1e00c1e00af3ca022f6a0b0aca6ba
    https://github.com/scummvm/scummvm/commit/56bb953dd7c1e00c1e00af3ca022f6a0b0aca6ba
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-01-02T14:18:36-06:00

Commit Message:
ULTIMA8: Add get item location to minimap to avoid calculation in gump

Changed paths:
    engines/ultima/ultima8/gumps/minimap_gump.cpp
    engines/ultima/ultima8/world/current_map.cpp
    engines/ultima/ultima8/world/current_map.h
    engines/ultima/ultima8/world/minimap.cpp
    engines/ultima/ultima8/world/minimap.h


diff --git a/engines/ultima/ultima8/gumps/minimap_gump.cpp b/engines/ultima/ultima8/gumps/minimap_gump.cpp
index 6b0a84fc9fe..44b18cc3ab4 100644
--- a/engines/ultima/ultima8/gumps/minimap_gump.cpp
+++ b/engines/ultima/ultima8/gumps/minimap_gump.cpp
@@ -62,27 +62,23 @@ void MiniMapGump::run() {
 	if (!actor || actor->isDead())
 		return;
 
-	int32 ax, ay, az;
-	actor->getLocation(ax, ay, az);
-
-	ax = ax / (mapChunkSize / MINMAPGUMP_SCALE);
-	ay = ay / (mapChunkSize / MINMAPGUMP_SCALE);
-
-	// Skip map update if location has not changed
-	if (ax == _ax && ay == _ay)
-		return;
-
-	_ax = ax;
-	_ay = ay;
-
 	uint32 mapNum = currentmap->getNum();
-
 	MiniMap *minimap = _minimaps[mapNum];
 	if (!minimap) {
 		minimap = new MiniMap(mapNum);
 		_minimaps[mapNum] = minimap;
 	}
-	minimap->update(currentmap);
+
+	Common::Point p = minimap->getItemLocation(*actor, mapChunkSize);
+
+	// Skip map update if location has not changed
+	if (p.x == _ax && p.y == _ay)
+		return;
+
+	_ax = p.x;
+	_ay = p.y;
+
+	minimap->update(*currentmap);
 }
 
 void MiniMapGump::generate() {
@@ -97,7 +93,7 @@ void MiniMapGump::generate() {
 		minimap = new MiniMap(mapNum);
 		_minimaps[mapNum] = minimap;
 	}
-	minimap->update(currentmap);
+	minimap->update(*currentmap);
 }
 
 void MiniMapGump::clear() {
diff --git a/engines/ultima/ultima8/world/current_map.cpp b/engines/ultima/ultima8/world/current_map.cpp
index 155b5751ec6..16596c506a8 100644
--- a/engines/ultima/ultima8/world/current_map.cpp
+++ b/engines/ultima/ultima8/world/current_map.cpp
@@ -1253,7 +1253,7 @@ bool CurrentMap::sweepTest(const int32 start[3], const int32 end[3],
 }
 
 
-const Item *CurrentMap::traceTopItem(int32 x, int32 y, int32 ztop, int32 zbot, ObjId ignore, uint32 shflags) {
+const Item *CurrentMap::traceTopItem(int32 x, int32 y, int32 ztop, int32 zbot, ObjId ignore, uint32 shflags) const {
 	const Item *top = nullptr;
 
 	if (ztop < zbot) {
diff --git a/engines/ultima/ultima8/world/current_map.h b/engines/ultima/ultima8/world/current_map.h
index 2c1d50aaf81..6dd9f4065b1 100644
--- a/engines/ultima/ultima8/world/current_map.h
+++ b/engines/ultima/ultima8/world/current_map.h
@@ -204,7 +204,7 @@ public:
 	}
 
 	// A simple trace to find the top item at a specific xy point
-	const Item *traceTopItem(int32 x, int32 y, int32 ztop, int32 zbot, ObjId ignore, uint32 shflags);
+	const Item *traceTopItem(int32 x, int32 y, int32 ztop, int32 zbot, ObjId ignore, uint32 shflags) const;
 
 	// Set the entire map as being 'fast'
 	void setWholeMapFast();
diff --git a/engines/ultima/ultima8/world/minimap.cpp b/engines/ultima/ultima8/world/minimap.cpp
index c7f03c8e828..47a2da1e6a1 100644
--- a/engines/ultima/ultima8/world/minimap.cpp
+++ b/engines/ultima/ultima8/world/minimap.cpp
@@ -41,8 +41,8 @@ MiniMap::~MiniMap() {
 	_surface.free();
 }
 
-void MiniMap::update(CurrentMap *currentmap) {
-	int mapChunkSize = currentmap->getChunkSize();
+void MiniMap::update(const CurrentMap &map) {
+	int mapChunkSize = map.getChunkSize();
 
 	// Draw into the map surface
 	for (int x = 0; x < _surface.w; x++) {
@@ -51,7 +51,7 @@ void MiniMap::update(CurrentMap *currentmap) {
 			if (val == 0) {
 				int cx = x / MINMAPGUMP_SCALE;
 				int cy = y / MINMAPGUMP_SCALE;
-				if (currentmap->isChunkFast(cx, cy)) {
+				if (map.isChunkFast(cx, cy)) {
 					int mx = (x * mapChunkSize) / MINMAPGUMP_SCALE;
 					int my = (y * mapChunkSize) / MINMAPGUMP_SCALE;
 
@@ -59,7 +59,7 @@ void MiniMap::update(CurrentMap *currentmap) {
 					mx += mapChunkSize / (MINMAPGUMP_SCALE * 2);
 					my += mapChunkSize / (MINMAPGUMP_SCALE * 2);
 
-					val = sampleAtPoint(currentmap, mx, my);
+					val = sampleAtPoint(map, mx, my);
 					_surface.setPixel(x, y, val);
 				}
 			}
@@ -67,15 +67,24 @@ void MiniMap::update(CurrentMap *currentmap) {
 	}
 }
 
-uint32 MiniMap::sampleAtPoint(CurrentMap *currentmap, int x, int y) {
+Common::Point MiniMap::getItemLocation(const Item &item, unsigned int chunkSize) {
+	int32 x, y, z;
+	item.getLocation(x, y, z);
+
+	x = x / (chunkSize / MINMAPGUMP_SCALE);
+	y = y / (chunkSize / MINMAPGUMP_SCALE);
+	return Common::Point(x, y);
+}
+
+uint32 MiniMap::sampleAtPoint(const CurrentMap &map, int x, int y) {
 	uint32 val = 0;
-	const Item *item = currentmap->traceTopItem(x, y, 1 << 15, -1, 0, ShapeInfo::SI_ROOF | ShapeInfo::SI_OCCL | ShapeInfo::SI_LAND | ShapeInfo::SI_SEA);
+	const Item *item = map.traceTopItem(x, y, 1 << 15, -1, 0, ShapeInfo::SI_ROOF | ShapeInfo::SI_OCCL | ShapeInfo::SI_LAND | ShapeInfo::SI_SEA);
 	if (item) {
-		val = sampleAtPoint(item, x, y);
+		val = sampleAtPoint(*item, x, y);
 		if (val == 0) {
-			item = currentmap->traceTopItem(x, y, 1 << 15, -1, item->getObjId(), ShapeInfo::SI_ROOF | ShapeInfo::SI_OCCL | ShapeInfo::SI_LAND | ShapeInfo::SI_SEA);
+			item = map.traceTopItem(x, y, 1 << 15, -1, item->getObjId(), ShapeInfo::SI_ROOF | ShapeInfo::SI_OCCL | ShapeInfo::SI_LAND | ShapeInfo::SI_SEA);
 			if (item) {
-				val = sampleAtPoint(item, x, y);
+				val = sampleAtPoint(*item, x, y);
 			}
 		}
 
@@ -87,19 +96,19 @@ uint32 MiniMap::sampleAtPoint(CurrentMap *currentmap, int x, int y) {
 	return val;
 }
 
-uint32 MiniMap::sampleAtPoint(const Item *item, int x, int y) {
+uint32 MiniMap::sampleAtPoint(const Item &item, int x, int y) {
 	int32 ix, iy, iz, idx, idy, idz;
-	item->getLocation(ix, iy, iz);
-	item->getFootpadWorld(idx, idy, idz);
+	item.getLocation(ix, iy, iz);
+	item.getFootpadWorld(idx, idy, idz);
 
 	ix -= x;
 	iy -= y;
 
-	const Shape *sh = item->getShapeObject();
+	const Shape *sh = item.getShapeObject();
 	if (!sh)
 		return 0;
 
-	const ShapeFrame *frame = sh->getFrame(item->getFrame());
+	const ShapeFrame *frame = sh->getFrame(item.getFrame());
 	if (!frame)
 		return 0;
 
@@ -107,7 +116,7 @@ uint32 MiniMap::sampleAtPoint(const Item *item, int x, int y) {
 	if (!pal)
 		return 0;
 
-	if (item->canDrag())
+	if (item.canDrag())
 		return 0;
 
 	// Screenspace bounding box bottom x_ coord (RNB x_ coord)
diff --git a/engines/ultima/ultima8/world/minimap.h b/engines/ultima/ultima8/world/minimap.h
index bfb90844d72..18c7e633d86 100644
--- a/engines/ultima/ultima8/world/minimap.h
+++ b/engines/ultima/ultima8/world/minimap.h
@@ -38,15 +38,16 @@ private:
 	uint32 _mapNum;
 	Graphics::Surface _surface;
 
-	uint32 sampleAtPoint(CurrentMap *map, int x, int y);
-	uint32 sampleAtPoint(const Item *item, int x, int y);
+	uint32 sampleAtPoint(const CurrentMap &map, int x, int y);
+	uint32 sampleAtPoint(const Item &item, int x, int y);
 
 	const Common::Rect getCropBounds() const;
 public:
 	MiniMap(uint32 mapNum);
 	~MiniMap();
 
-	void update(CurrentMap *map);
+	void update(const CurrentMap &map);
+	Common::Point getItemLocation(const Item &item, unsigned int chunkSize);
 
 	uint32 getMapNum() const { return _mapNum; }
 	Graphics::Surface *getSurface() { return &_surface; }


Commit: b808457b2b6a60444cbb80dd6804e2eac9e4a2ef
    https://github.com/scummvm/scummvm/commit/b808457b2b6a60444cbb80dd6804e2eac9e4a2ef
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-01-02T14:18:36-06:00

Commit Message:
ULTIMA8: Adjust sweep test when items hit at same time.
If hit starts are the same sort collisions by hit end. If a sweep moves through flat items, this will usually sort them before a non-flat item

Changed paths:
    engines/ultima/ultima8/world/current_map.cpp


diff --git a/engines/ultima/ultima8/world/current_map.cpp b/engines/ultima/ultima8/world/current_map.cpp
index 16596c506a8..b965ecce2fd 100644
--- a/engines/ultima/ultima8/world/current_map.cpp
+++ b/engines/ultima/ultima8/world/current_map.cpp
@@ -1227,14 +1227,16 @@ bool CurrentMap::sweepTest(const int32 start[3], const int32 end[3],
 
 					// Small speed up.
 					if (sw_it != hit->end()) {
-						const SweepItem &si = *sw_it;
-						if (si._hitTime > first) sw_it = hit->begin();
+						if (sw_it->_hitTime > first)
+							sw_it = hit->begin();
 					} else
 						sw_it = hit->begin();
 
-					for (; sw_it != hit->end(); ++sw_it)
-						if ((*sw_it)._hitTime > first)
+					for (; sw_it != hit->end(); ++sw_it) {
+						if (sw_it->_hitTime > first ||
+							sw_it->_hitTime == first && sw_it->_endTime > last)
 							break;
+					}
 
 					// Now add it
 					sw_it = hit->insert(sw_it, SweepItem(other_item->getObjId(), first, last, touch, touch_floor, blocking, dirs));


Commit: 906379789de64428627a2d6a4f631ba59920ddf0
    https://github.com/scummvm/scummvm/commit/906379789de64428627a2d6a4f631ba59920ddf0
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-01-02T14:18:36-06:00

Commit Message:
ULTIMA8: Replace minimap sample top item trace with a sweeep test.
Sweep test largely samples the same items as top item trace, but this appears to be preferrable when different.

Changed paths:
    engines/ultima/ultima8/world/minimap.cpp


diff --git a/engines/ultima/ultima8/world/minimap.cpp b/engines/ultima/ultima8/world/minimap.cpp
index 47a2da1e6a1..bea2fa4cb57 100644
--- a/engines/ultima/ultima8/world/minimap.cpp
+++ b/engines/ultima/ultima8/world/minimap.cpp
@@ -24,6 +24,7 @@
 #include "ultima/ultima8/world/minimap.h"
 #include "ultima/ultima8/world/current_map.h"
 #include "ultima/ultima8/world/item.h"
+#include "ultima/ultima8/world/get_object.h"
 #include "ultima/ultima8/graphics/render_surface.h"
 #include "ultima/ultima8/graphics/shape.h"
 #include "ultima/ultima8/graphics/shape_frame.h"
@@ -77,23 +78,30 @@ Common::Point MiniMap::getItemLocation(const Item &item, unsigned int chunkSize)
 }
 
 uint32 MiniMap::sampleAtPoint(const CurrentMap &map, int x, int y) {
-	uint32 val = 0;
-	const Item *item = map.traceTopItem(x, y, 1 << 15, -1, 0, ShapeInfo::SI_ROOF | ShapeInfo::SI_OCCL | ShapeInfo::SI_LAND | ShapeInfo::SI_SEA);
-	if (item) {
-		val = sampleAtPoint(*item, x, y);
-		if (val == 0) {
-			item = map.traceTopItem(x, y, 1 << 15, -1, item->getObjId(), ShapeInfo::SI_ROOF | ShapeInfo::SI_OCCL | ShapeInfo::SI_LAND | ShapeInfo::SI_SEA);
-			if (item) {
-				val = sampleAtPoint(*item, x, y);
-			}
-		}
+	int32 start[3] = {x, y, 1 << 15};
+	int32 end[3] = {x, y, -1};
+	int32 dims[3] = {0, 0, 0};
+	uint32 shflags = ShapeInfo::SI_ROOF | ShapeInfo::SI_OCCL | ShapeInfo::SI_LAND | ShapeInfo::SI_SEA;
+	Std::list<CurrentMap::SweepItem> collisions;
+	if (!map.sweepTest(start, end, dims, shflags, 0, false, &collisions))
+		return 0;
 
-		if (val == 0) {
-			// set to avoid reprocessing
-			val = _surface.format.RGBToColor(0x00, 0x00, 0x00);
+	Std::list<CurrentMap::SweepItem>::const_iterator it;
+	for (it = collisions.begin(); it != collisions.end(); it++) {
+		const Item *item = getItem(it->_item);
+		if (item) {
+			const ShapeInfo *si = item->getShapeInfo();
+			if (!(si->_flags & shflags) || si->is_editor() || si->is_translucent())
+				continue;
+
+			uint32 val = sampleAtPoint(*item, x, y);
+			if (val != 0)
+				return val;
 		}
 	}
-	return val;
+
+	// set to avoid reprocessing
+	return _surface.format.RGBToColor(0x00, 0x00, 0x00);
 }
 
 uint32 MiniMap::sampleAtPoint(const Item &item, int x, int y) {


Commit: 43fb0d20666240095650328eb1d3e9281fe65a9e
    https://github.com/scummvm/scummvm/commit/43fb0d20666240095650328eb1d3e9281fe65a9e
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-01-02T14:18:36-06:00

Commit Message:
ULTIMA8: Remove map trace top item now that it is unused

Changed paths:
    engines/ultima/ultima8/world/current_map.cpp
    engines/ultima/ultima8/world/current_map.h


diff --git a/engines/ultima/ultima8/world/current_map.cpp b/engines/ultima/ultima8/world/current_map.cpp
index b965ecce2fd..061e063d605 100644
--- a/engines/ultima/ultima8/world/current_map.cpp
+++ b/engines/ultima/ultima8/world/current_map.cpp
@@ -1254,62 +1254,6 @@ bool CurrentMap::sweepTest(const int32 start[3], const int32 end[3],
 	return hit && hit->size();
 }
 
-
-const Item *CurrentMap::traceTopItem(int32 x, int32 y, int32 ztop, int32 zbot, ObjId ignore, uint32 shflags) const {
-	const Item *top = nullptr;
-
-	if (ztop < zbot) {
-		int32 temp = ztop;
-		ztop = zbot;
-		zbot = temp;
-	}
-
-	int minx = (x / _mapChunkSize);
-	int maxx = (x / _mapChunkSize) + 1;
-	int miny = (y / _mapChunkSize);
-	int maxy = (y / _mapChunkSize) + 1;
-	clipMapChunks(minx, maxx, miny, maxy);
-
-	for (int cx = minx; cx <= maxx; cx++) {
-		for (int cy = miny; cy <= maxy; cy++) {
-			item_list::const_iterator iter;
-			for (iter = _items[cx][cy].begin();
-			        iter != _items[cx][cy].end(); ++iter) {
-				const Item *item = *iter;
-				if (item->getObjId() == ignore)
-					continue;
-				if (item->hasExtFlags(Item::EXT_SPRITE))
-					continue;
-
-				const ShapeInfo *si = item->getShapeInfo();
-				if (!(si->_flags & shflags) || si->is_editor() || si->is_translucent()) continue;
-
-				int32 ix, iy, iz, ixd, iyd, izd;
-				item->getLocation(ix, iy, iz);
-				item->getFootpadWorld(ixd, iyd, izd);
-
-				if ((ix - ixd) >= x || ix <= x)
-					continue;
-				if ((iy - iyd) >= y || iy <= y)
-					continue;
-				if (iz >= ztop || (iz + izd) <= zbot)
-					continue;
-
-				if (top) {
-					int32 tix, tiy, tiz, tixd, tiyd, tizd;
-					top->getLocation(tix, tiy, tiz);
-					top->getFootpadWorld(tixd, tiyd, tizd);
-
-					if ((tiz + tizd) < (iz + izd)) top = nullptr;
-				}
-
-				if (!top) top = item;
-			}
-		}
-	}
-	return top;
-}
-
 void CurrentMap::setWholeMapFast() {
 	for (unsigned int i = 0; i < MAP_NUM_CHUNKS; ++i) {
 		for (unsigned int j = 0; j < MAP_NUM_CHUNKS; ++j) {
diff --git a/engines/ultima/ultima8/world/current_map.h b/engines/ultima/ultima8/world/current_map.h
index 6dd9f4065b1..a202bafe703 100644
--- a/engines/ultima/ultima8/world/current_map.h
+++ b/engines/ultima/ultima8/world/current_map.h
@@ -203,9 +203,6 @@ public:
 		return (_fast[cy][cx / 32] & (1 << (cx & 31))) != 0;
 	}
 
-	// A simple trace to find the top item at a specific xy point
-	const Item *traceTopItem(int32 x, int32 y, int32 ztop, int32 zbot, ObjId ignore, uint32 shflags) const;
-
 	// Set the entire map as being 'fast'
 	void setWholeMapFast();
 




More information about the Scummvm-git-logs mailing list