[Scummvm-git-logs] scummvm master -> 7315a17f3d9033ca0e8947179c66a01afcfaed38

OMGPizzaGuy noreply at scummvm.org
Tue Sep 12 23:51:07 UTC 2023


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:
39b6065875 ULTIMA8 - Merge PaintMirrored with other shape paint methods
7315a17f3d ULTIMA8: Fix off-by-one x-coordinate on mirrored shape paint


Commit: 39b606587598c04c0668ce6392eede8065efd9a9
    https://github.com/scummvm/scummvm/commit/39b606587598c04c0668ce6392eede8065efd9a9
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-09-12T18:50:32-05:00

Commit Message:
ULTIMA8 - Merge PaintMirrored with other shape paint methods

Changed paths:
    engines/ultima/ultima8/graphics/render_surface.cpp
    engines/ultima/ultima8/graphics/render_surface.h
    engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
    engines/ultima/ultima8/misc/debugger.cpp
    engines/ultima/ultima8/world/item_sorter.cpp


diff --git a/engines/ultima/ultima8/graphics/render_surface.cpp b/engines/ultima/ultima8/graphics/render_surface.cpp
index 393da24f9a4..0f1ebbc8de8 100644
--- a/engines/ultima/ultima8/graphics/render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/render_surface.cpp
@@ -615,9 +615,8 @@ template<typename uintX>
 void inline paintLogic(uint8 *pixels, int32 pitch,
 					   const Common::Rect &clipWindow,
 					   const Graphics::PixelFormat &format,
-					   const ShapeFrame *frame, int32 x, int32 y,
+					   const ShapeFrame *frame, int32 x, int32 y, bool mirrored,
 					   const uint32 *map) {
-	const bool mirrored = false;
 #include "ultima/ultima8/graphics/render_surface.inl"
 }
 
@@ -625,30 +624,13 @@ template<class uintX>
 void inline paintTranslucentLogic(uint8 *pixels, int32 pitch,
 								  const Common::Rect &clipWindow,
 								  const Graphics::PixelFormat &format,
-								  const ShapeFrame *frame, int32 x, int32 y,
+								  const ShapeFrame *frame, int32 x, int32 y, bool mirrored,
 								  const uint32 *map, const uint32 *xform_map) {
-	const bool mirrored = false;
 #define XFORM_SHAPES
 #include "ultima/ultima8/graphics/render_surface.inl"
 #undef XFORM_SHAPES
 }
 
-template<class uintX>
-void inline paintMirroredLogic(uint8 *pixels, int32 pitch,
-							   const Common::Rect &clipWindow,
-							   const Graphics::PixelFormat &format,
-							   const ShapeFrame *frame, int32 x, int32 y, bool trans,
-							   const uint32 *map, const uint32 *xform_map) {
-	const bool mirrored = true;
-#define XFORM_SHAPES
-#define XFORM_CONDITIONAL trans
-
-#include "ultima/ultima8/graphics/render_surface.inl"
-
-#undef XFORM_SHAPES
-#undef XFORM_CONDITIONAL
-}
-
 template<class uintX>
 void inline paintInvisibleLogic(uint8 *pixels, int32 pitch,
 								const Common::Rect &clipWindow,
@@ -713,11 +695,11 @@ void inline paintHighlightInvisLogic(uint8 *pixels, int32 pitch,
 } // End of anonymous namespace
 
 //
-// void RenderSurface::Paint(Shape*s, uint32 framenum, int32 x, int32 y)
+// void RenderSurface::Paint(Shape*s, uint32 framenum, int32 x, int32 y, bool mirrored)
 //
 // Desc: Standard shape drawing functions. Clips but doesn't do anything else
 //
-void RenderSurface::Paint(const Shape *s, uint32 framenum, int32 x, int32 y) {
+void RenderSurface::Paint(const Shape *s, uint32 framenum, int32 x, int32 y, bool mirrored) {
 	const ShapeFrame *frame = s->getFrame(framenum);
 	if (!frame || !s->getPalette())
 		return;
@@ -725,36 +707,17 @@ void RenderSurface::Paint(const Shape *s, uint32 framenum, int32 x, int32 y) {
 	const uint32 *map = s->getPalette()->_native;
 
 	if (_surface->format.bytesPerPixel == 4)
-		paintLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, map);
+		paintLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, map);
 	else if (_surface->format.bytesPerPixel == 2)
-		paintLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, map);
+		paintLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, map);
 }
 
 //
-// void RenderSurface::PaintTranslucent(Shape*s, uint32 framenum, int32 x, int32 y)
+// void RenderSurface::PaintTranslucent(Shape*s, uint32 framenum, int32 x, int32 y, bool mirrored)
 //
 // Desc: Standard shape drawing functions. Clips and XForms
 //
-void RenderSurface::PaintTranslucent(const Shape *s, uint32 framenum, int32 x, int32 y) {
-	const ShapeFrame *frame = s->getFrame(framenum);
-	if (!frame || !s->getPalette())
-		return;
-
-	const uint32 *map = s->getPalette()->_native;
-	const uint32 *xform_map = s->getPalette()->_xform;
-
-	if (_surface->format.bytesPerPixel == 4)
-		paintTranslucentLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, map, xform_map);
-	else if (_surface->format.bytesPerPixel == 2)
-		paintTranslucentLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, map, xform_map);
-}
-
-//
-// void RenderSurface::PaintMirrored(Shape*s, uint32 framenum, int32 x, int32 y, bool trans)
-//
-// Desc: Standard shape drawing functions. Clips, Flips and conditionally XForms
-//
-void RenderSurface::PaintMirrored(const Shape *s, uint32 framenum, int32 x, int32 y, bool trans) {
+void RenderSurface::PaintTranslucent(const Shape *s, uint32 framenum, int32 x, int32 y, bool mirrored) {
 	const ShapeFrame *frame = s->getFrame(framenum);
 	if (!frame || !s->getPalette())
 		return;
@@ -763,9 +726,9 @@ void RenderSurface::PaintMirrored(const Shape *s, uint32 framenum, int32 x, int3
 	const uint32 *xform_map = s->getPalette()->_xform;
 
 	if (_surface->format.bytesPerPixel == 4)
-		paintMirroredLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, map, xform_map);
+		paintTranslucentLogic<uint32>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, map, xform_map);
 	else if (_surface->format.bytesPerPixel == 2)
-		paintMirroredLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, trans, map, xform_map);
+		paintTranslucentLogic<uint16>(_pixels, _pitch, _clipWindow, _surface->format, frame, x, y, mirrored, map, xform_map);
 }
 
 //
diff --git a/engines/ultima/ultima8/graphics/render_surface.h b/engines/ultima/ultima8/graphics/render_surface.h
index 1103925ad02..95305d4c8ea 100644
--- a/engines/ultima/ultima8/graphics/render_surface.h
+++ b/engines/ultima/ultima8/graphics/render_surface.h
@@ -150,13 +150,10 @@ public:
 	//
 
 	//! Paint a Shape
-	void Paint(const Shape *s, uint32 frame, int32 x, int32 y);
+	void Paint(const Shape *s, uint32 frame, int32 x, int32 y, bool mirrored = false);
 
 	//! Paint a Translucent Shape.
-	void PaintTranslucent(const Shape *s, uint32 frame, int32 x, int32 y);
-
-	//! Paint a Mirrored Shape
-	void PaintMirrored(const Shape *s, uint32 frame, int32 x, int32 y, bool trans = false);
+	void PaintTranslucent(const Shape *s, uint32 frame, int32 x, int32 y, bool mirrored = false);
 
 	//! Paint an Invisible Shape
 	void PaintInvisible(const Shape *s, uint32 frame, int32 x, int32 y, bool trans, bool mirrored);
diff --git a/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp b/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
index 56689bab2fa..0a1d97b0c95 100644
--- a/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
+++ b/engines/ultima/ultima8/gumps/shape_viewer_gump.cpp
@@ -143,11 +143,7 @@ void ShapeViewerGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool /*s
 	ShapeArchive *archive = _archives[_curArchive]._archive;
 	const Shape *shape = archive->getShape(_curShape);
 	if (shape && _curFrame < shape->frameCount()) {
-		if (_mirrored) {
-			surf->PaintMirrored(shape, _curFrame, posx, posy);
-		} else {
-			surf->Paint(shape, _curFrame, posx, posy);
-		}
+		surf->Paint(shape, _curFrame, posx, posy, _mirrored);
 	}
 
 	RenderedText *rendtext;
diff --git a/engines/ultima/ultima8/misc/debugger.cpp b/engines/ultima/ultima8/misc/debugger.cpp
index eace5881c78..017f64f974e 100644
--- a/engines/ultima/ultima8/misc/debugger.cpp
+++ b/engines/ultima/ultima8/misc/debugger.cpp
@@ -1846,7 +1846,7 @@ bool Debugger::cmdBenchmarkRenderSurface(int argc, const char **argv) {
 
 	start = g_system->getMillis();
 	for (int i = 0; i < count; i++) {
-		surface->PaintMirrored(s, frame, 160, 100);
+		surface->Paint(s, frame, 160, 100, true);
 	}
 	end = g_system->getMillis();
 	debugPrintf("PaintMirrored: %d\n", end - start);
diff --git a/engines/ultima/ultima8/world/item_sorter.cpp b/engines/ultima/ultima8/world/item_sorter.cpp
index 123053e1d7c..6388905a1ce 100644
--- a/engines/ultima/ultima8/world/item_sorter.cpp
+++ b/engines/ultima/ultima8/world/item_sorter.cpp
@@ -327,12 +327,10 @@ bool ItemSorter::PaintSortItem(RenderSurface *surf, SortItem *si) {
 			surf->PaintHighlight(si->_shape, si->_frame, si->_sxBot, si->_syBot, si->_trans, (si->_flags & Item::FLG_FLIPPED) != 0, TRANSPARENT_COLOR);
 		else if (si->_extFlags & Item::EXT_TRANSPARENT)
 			surf->PaintInvisible(si->_shape, si->_frame, si->_sxBot, si->_syBot, si->_trans, (si->_flags & Item::FLG_FLIPPED) != 0);
-		else if (si->_flags & Item::FLG_FLIPPED)
-			surf->PaintMirrored(si->_shape, si->_frame, si->_sxBot, si->_syBot, si->_trans);
 		else if (si->_trans)
-			surf->PaintTranslucent(si->_shape, si->_frame, si->_sxBot, si->_syBot);
+			surf->PaintTranslucent(si->_shape, si->_frame, si->_sxBot, si->_syBot, (si->_flags & Item::FLG_FLIPPED) != 0);
 		else
-			surf->Paint(si->_shape, si->_frame, si->_sxBot, si->_syBot);
+			surf->Paint(si->_shape, si->_frame, si->_sxBot, si->_syBot, (si->_flags & Item::FLG_FLIPPED) != 0);
 
 	//	if (wire) si->info->draw_box_front(s, dispx, dispy, 255);
 
@@ -347,7 +345,7 @@ bool ItemSorter::PaintSortItem(RenderSurface *surf, SortItem *si) {
 				const Shape *wo_shape = GameData::get_instance()->getMainShapes()->getShape(wo_shapenum);
 				surf->Paint(wo_shape, wo_frame->_frame,
 							si->_sxBot + wo_frame->_xOff,
-							si->_syBot + wo_frame->_yOff);
+							si->_syBot + wo_frame->_yOff, false);
 			}
 		}
 	}


Commit: 7315a17f3d9033ca0e8947179c66a01afcfaed38
    https://github.com/scummvm/scummvm/commit/7315a17f3d9033ca0e8947179c66a01afcfaed38
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-09-12T18:50:33-05:00

Commit Message:
ULTIMA8: Fix off-by-one x-coordinate on mirrored shape paint

Changed paths:
    engines/ultima/ultima8/graphics/render_surface.inl


diff --git a/engines/ultima/ultima8/graphics/render_surface.inl b/engines/ultima/ultima8/graphics/render_surface.inl
index a5db87a6a23..0cac2339ca7 100644
--- a/engines/ultima/ultima8/graphics/render_surface.inl
+++ b/engines/ultima/ultima8/graphics/render_surface.inl
@@ -91,52 +91,68 @@
 	const uint8 keycolor = frame->_keycolor;
 
 	Common::Rect srcRect(0, 0, src.w, src.h);
-	Common::Rect dstRect(x, y, x, y + src.h);
+	Common::Rect dstRect(x, y, x, y);
 
 	const int srcStep = sizeof(uint8);
 	int dstStep = sizeof(uintX);
 
 	if (mirrored) {
-		dstRect.translate(frame->_xoff, -frame->_yoff);
-		dstRect.left = dstRect.right - src.w;
-		dstStep = -dstStep;
-	} else {
-		dstRect.translate(-frame->_xoff, -frame->_yoff);
-		dstRect.right = dstRect.left + src.w;
-	}
+		dstRect.right += frame->_xoff + 1;
+		dstRect.left = dstRect.right - srcRect.width();
 
-	if (dstRect.left < clipWindow.left) {
-		if (mirrored) {
+		if (dstRect.left < clipWindow.left) {
 			srcRect.right += dstRect.left - clipWindow.left;
-		} else {
+			dstRect.left = clipWindow.left;
+		}
+
+		if (dstRect.right > clipWindow.right) {
+			srcRect.left += dstRect.right - clipWindow.right;
+			dstRect.right = clipWindow.right;
+		}
+	} else {
+		dstRect.left -= frame->_xoff;
+		dstRect.right = dstRect.left + srcRect.width();
+
+		if (dstRect.left < clipWindow.left) {
 			srcRect.left -= dstRect.left - clipWindow.left;
+			dstRect.left = clipWindow.left;
+		}
+
+		if (dstRect.right > clipWindow.right) {
+			srcRect.right -= dstRect.right - clipWindow.right;
+			dstRect.right = clipWindow.right;
 		}
-		dstRect.left = clipWindow.left;
 	}
+
+	dstRect.top -= frame->_yoff;
+	dstRect.bottom = dstRect.top + srcRect.height();
+
 	if (dstRect.top < clipWindow.top) {
 		srcRect.top -= dstRect.top - clipWindow.top;
 		dstRect.top = clipWindow.top;
 	}
-	if (dstRect.right > clipWindow.right) {
-		if (mirrored) {
-			srcRect.left += dstRect.right - clipWindow.right;
-		} else {
-			srcRect.right -= dstRect.right - clipWindow.right;
-		}
-		dstRect.right = clipWindow.right;
-	}
+
 	if (dstRect.bottom > clipWindow.bottom) {
 		srcRect.bottom -= dstRect.bottom - clipWindow.bottom;
 		dstRect.bottom = clipWindow.bottom;
 	}
 
+	if (mirrored) {
+		x = dstRect.right - 1;
+		y = dstRect.top;
+		dstStep = -dstStep;
+	} else {
+		x = dstRect.left;
+		y = dstRect.top;
+	}
+
 	const int w = srcRect.width();
 	const int h = srcRect.height();
 	const int srcDelta = src.pitch - (w * srcStep);
 	const int dstDelta = pitch - (w * dstStep);
 
 	const uint8 *srcPixels = reinterpret_cast<const uint8 *>(src.getBasePtr(srcRect.left, srcRect.top));
-	uint8 *dstPixels = reinterpret_cast<uint8 *>(pixels + (mirrored ? dstRect.right - 1 : dstRect.left) * sizeof(uintX) + pitch * dstRect.top);
+	uint8 *dstPixels = reinterpret_cast<uint8 *>(pixels + x * sizeof(uintX) + pitch * y);
 
 	for (int i = 0; i < h; i++)  {
 		for (int j = 0; j < w; j++) {




More information about the Scummvm-git-logs mailing list