[Scummvm-git-logs] scummvm master -> 8f0da16853b226061ebdd145154a7e2598950e49

dreammaster noreply at scummvm.org
Sat May 7 03:17:33 UTC 2022


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:
cf091f2d3e AGS: Replaced couple of variables in ScreenOverlay with flags
7282304951 AGS: Script API: implemented room overlays
d323d2388b AGS: Added readonly bool Overlay.InRoom
8f0da16853 AGS: Re-enable std::move call in ObjTexture constructor


Commit: cf091f2d3e011e6bb922e267f49925f31ed708c0
    https://github.com/scummvm/scummvm/commit/cf091f2d3e011e6bb922e267f49925f31ed708c0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-05-06T20:16:41-07:00

Commit Message:
AGS: Replaced couple of variables in ScreenOverlay with flags

>From upstream 38a4e8c262f0ec796225494fc939b283680caf57

Changed paths:
    engines/ags/engine/ac/display.cpp
    engines/ags/engine/ac/draw.cpp
    engines/ags/engine/ac/overlay.cpp
    engines/ags/engine/ac/screen_overlay.cpp
    engines/ags/engine/ac/screen_overlay.h
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/engine/main/update.cpp


diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index 308a955701d..9b8f39d95ed 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -341,7 +341,7 @@ ScreenOverlay *_display_main(int xx, int yy, int wii, const char *text, int disp
 			_GP(play).messagetime = 2;
 
 		if (!overlayPositionFixed) {
-			_GP(screenover)[nse].positionRelativeToScreen = false;
+			_GP(screenover)[nse].SetRoomRelative(true);
 			VpPoint vpt = _GP(play).GetRoomViewport(0)->ScreenToRoom(_GP(screenover)[nse].x, _GP(screenover)[nse].y, false);
 			_GP(screenover)[nse].x = vpt.first.X;
 			_GP(screenover)[nse].y = vpt.first.Y;
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index 23af33e5e95..03996f95a76 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -1868,9 +1868,9 @@ void draw_gui_and_overlays() {
 		if (_GP(screenover)[i].HasChanged()) {
 			// For software mode - prepare transformed bitmap if necessary
 			Bitmap *use_bmp = is_software_mode ?
-				transform_sprite(over.pic, over.hasAlphaChannel, _GP(overlaybmp)[i], Size(over.scaleWidth, over.scaleHeight)) :
+				transform_sprite(over.pic, over.HasAlphaChannel(), _GP(overlaybmp)[i], Size(over.scaleWidth, over.scaleHeight)) :
 				over.pic;
-			over.ddb = recycle_ddb_bitmap(over.ddb, use_bmp, over.hasAlphaChannel);
+			over.ddb = recycle_ddb_bitmap(over.ddb, use_bmp, over.HasAlphaChannel());
 			over.ClearChanged();
 		}
 
diff --git a/engines/ags/engine/ac/overlay.cpp b/engines/ags/engine/ac/overlay.cpp
index 97b35d0c3a2..1691be88b13 100644
--- a/engines/ags/engine/ac/overlay.cpp
+++ b/engines/ags/engine/ac/overlay.cpp
@@ -340,8 +340,8 @@ size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic
 	over.timeout = 0;
 	over.bgSpeechForChar = -1;
 	over.associatedOverlayHandle = 0;
-	over.hasAlphaChannel = alphaChannel;
-	over.positionRelativeToScreen = true;
+	over.SetAlphaChannel(alphaChannel);
+	over.SetRoomRelative(false);
 	// TODO: move these custom settings outside of this function
 	if (type == OVER_COMPLETE) _GP(play).complete_overlay_on = type;
 	else if (type == OVER_TEXTMSG || type == OVER_TEXTSPEECH) {
@@ -388,9 +388,9 @@ Point get_overlay_position(const ScreenOverlay &over) {
 		// and only in the case where the overlay is using a GUI. See issue #1098
 		int tdxp = over.x + over.offsetX;
 		int tdyp = over.y + over.offsetY;
-		if (over.positionRelativeToScreen)
-			return Point(tdxp, tdyp);
-		return _GP(play).RoomToScreen(tdxp, tdyp);
+		if (over.IsRoomRelative())
+			return _GP(play).RoomToScreen(tdxp, tdyp);
+		return Point(tdxp, tdyp);
 	}
 }
 
diff --git a/engines/ags/engine/ac/screen_overlay.cpp b/engines/ags/engine/ac/screen_overlay.cpp
index 857e09599ea..928aa3c9385 100644
--- a/engines/ags/engine/ac/screen_overlay.cpp
+++ b/engines/ags/engine/ac/screen_overlay.cpp
@@ -37,8 +37,15 @@ void ScreenOverlay::ReadFromFile(Stream *in, bool &has_bitmap, int32_t cmp_ver)
 	timeout = in->ReadInt32();
 	bgSpeechForChar = in->ReadInt32();
 	associatedOverlayHandle = in->ReadInt32();
-	hasAlphaChannel = in->ReadBool();
-	positionRelativeToScreen = in->ReadBool();
+	if (cmp_ver >= 3) {
+		_flags = in->ReadInt16();
+	} else {
+		if (in->ReadBool()) // has alpha
+			_flags |= kOver_AlphaChannel;
+		if (!(in->ReadBool())) // screen relative position
+			_flags |= kOver_PositionAtRoomXY;
+	}
+
 	if (cmp_ver >= 1) {
 		offsetX = in->ReadInt32();
 		offsetY = in->ReadInt32();
@@ -60,8 +67,7 @@ void ScreenOverlay::WriteToFile(Stream *out) const {
 	out->WriteInt32(timeout);
 	out->WriteInt32(bgSpeechForChar);
 	out->WriteInt32(associatedOverlayHandle);
-	out->WriteBool(hasAlphaChannel);
-	out->WriteBool(positionRelativeToScreen);
+	out->WriteInt16(_flags);
 	// since cmp_ver = 1
 	out->WriteInt32(offsetX);
 	out->WriteInt32(offsetY);
diff --git a/engines/ags/engine/ac/screen_overlay.h b/engines/ags/engine/ac/screen_overlay.h
index fcd08fd4501..479f94eb79b 100644
--- a/engines/ags/engine/ac/screen_overlay.h
+++ b/engines/ags/engine/ac/screen_overlay.h
@@ -44,6 +44,11 @@ class IDriverDependantBitmap;
 
 using namespace AGS; // FIXME later
 
+enum OverlayFlags {
+	kOver_AlphaChannel = 0x0001,
+	kOver_PositionAtRoomXY = 0x0002, // room-relative position
+};
+
 // Overlay class.
 // TODO: currently overlay creates and stores its own bitmap, even if
 // created using existing sprite. As a side-effect, changing that sprite
@@ -57,7 +62,6 @@ struct ScreenOverlay {
 	Engine::IDriverDependantBitmap *ddb = nullptr;
 	// Original bitmap
 	Shared::Bitmap *pic = nullptr;
-	bool hasAlphaChannel = false;
 	int type = 0, timeout = 0;
 	// Note that x,y are overlay's properties, that define its position in script;
 	// but real drawn position is x + offsetX, y + offsetY;
@@ -69,9 +73,21 @@ struct ScreenOverlay {
 	int bgSpeechForChar = -1;
 	int associatedOverlayHandle = 0; // script obj handle
 	int zorder = INT_MIN;
-	bool positionRelativeToScreen = false;
 	int transparency = 0;
 
+	bool HasAlphaChannel() const {
+		return (_flags & kOver_AlphaChannel) != 0;
+	}
+	bool IsRoomRelative() const {
+		return (_flags & kOver_PositionAtRoomXY) != 0;
+	}
+	void SetAlphaChannel(bool on) {
+		on ? _flags |= kOver_AlphaChannel : _flags &= ~kOver_AlphaChannel;
+	}
+	void SetRoomRelative(bool on) {
+		on ? _flags |= kOver_PositionAtRoomXY : _flags &= ~kOver_PositionAtRoomXY;
+	}
+
 	// Tells if Overlay has graphically changed recently
 	bool HasChanged() const {
 		return _hasChanged;
@@ -89,6 +105,7 @@ struct ScreenOverlay {
 	void WriteToFile(Shared::Stream *out) const;
 
 private:
+	int _flags = 0; // OverlayFlags
 	bool _hasChanged = false;
 };
 
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index e16c1e35fe6..11c0cf89593 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -1088,7 +1088,7 @@ ComponentHandler ComponentHandlers[] = {
 	},
 	{
 		"Overlays",
-		2,
+		3,
 		0,
 		WriteOverlays,
 		ReadOverlays
diff --git a/engines/ags/engine/main/update.cpp b/engines/ags/engine/main/update.cpp
index ac2254adf01..3e93fd7d6f6 100644
--- a/engines/ags/engine/main/update.cpp
+++ b/engines/ags/engine/main/update.cpp
@@ -410,7 +410,7 @@ void update_sierra_speech() {
 				DrawViewFrame(frame_pic, blink_vf, view_frame_x, view_frame_y, face_has_alpha);
 			}
 
-			_GP(screenover)[_G(face_talking)].hasAlphaChannel = face_has_alpha;
+			_GP(screenover)[_G(face_talking)].SetAlphaChannel(face_has_alpha);
 			_GP(screenover)[_G(face_talking)].MarkChanged();
 		}  // end if updatedFrame
 	}


Commit: 72823049516a345f6e827fcbd4b5987a3adaa3e8
    https://github.com/scummvm/scummvm/commit/72823049516a345f6e827fcbd4b5987a3adaa3e8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-05-06T20:16:42-07:00

Commit Message:
AGS: Script API: implemented room overlays

>From upstream 65a7cd7e7566d3a1111be10b70dcb51b1853cd88

Changed paths:
    engines/ags/engine/ac/character.cpp
    engines/ags/engine/ac/display.cpp
    engines/ags/engine/ac/display.h
    engines/ags/engine/ac/draw.cpp
    engines/ags/engine/ac/global_overlay.cpp
    engines/ags/engine/ac/overlay.cpp
    engines/ags/engine/ac/overlay.h
    engines/ags/engine/ac/screen_overlay.h
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/character.cpp b/engines/ags/engine/ac/character.cpp
index 259d85b1a3f..983561e3f1a 100644
--- a/engines/ags/engine/ac/character.cpp
+++ b/engines/ags/engine/ac/character.cpp
@@ -2596,7 +2596,7 @@ void _displayspeech(const char *texx, int aschar, int xx, int yy, int widd, int
 			}
 			if (_GP(game).options[OPT_SPEECHTYPE] == 3)
 				overlay_x = 0;
-			_G(face_talking) = add_screen_overlay(overlay_x, ovr_yp, ovr_type, closeupface, closeupface_has_alpha);
+			_G(face_talking) = add_screen_overlay(false, overlay_x, ovr_yp, ovr_type, closeupface, closeupface_has_alpha);
 			_G(facetalkframe) = 0;
 			_G(facetalkwait) = viptr->loops[0].frames[0].speed + GetCharacterSpeechAnimationDelay(speakingChar);
 			_G(facetalkloop) = 0;
diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index 9b8f39d95ed..85a2d5a6b6f 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -70,7 +70,8 @@ struct DisplayVars {
 // Pass yy = -1 to find Y co-ord automatically
 // allowShrink = 0 for none, 1 for leftwards, 2 for rightwards
 // pass blocking=2 to create permanent overlay
-ScreenOverlay *_display_main(int xx, int yy, int wii, const char *text, int disp_type, int usingfont, int asspch, int isThought, int allowShrink, bool overlayPositionFixed) {
+ScreenOverlay *_display_main(int xx, int yy, int wii, const char *text, int disp_type, int usingfont,
+		int asspch, int isThought, int allowShrink, bool overlayPositionFixed, bool roomlayer) {
 	const bool use_speech_textwindow = (asspch < 0) && (_GP(game).options[OPT_SPEECHTYPE] >= 2);
 	const bool use_thought_gui = (isThought) && (_GP(game).options[OPT_THOUGHTGUI] > 0);
 
@@ -252,7 +253,7 @@ ScreenOverlay *_display_main(int xx, int yy, int wii, const char *text, int disp
 	default: ovrtype = disp_type; break; // must be precreated overlay id
 	}
 
-	size_t nse = add_screen_overlay(xx, yy, ovrtype, text_window_ds, adjustedXX - xx, adjustedYY - yy, alphaChannel);
+	size_t nse = add_screen_overlay(roomlayer, xx, yy, ovrtype, text_window_ds, adjustedXX - xx, adjustedYY - yy, alphaChannel);
 	// we should not delete text_window_ds here, because it is now owned by Overlay
 
 	if (disp_type >= DISPLAYTEXT_NORMALOVERLAY) {
diff --git a/engines/ags/engine/ac/display.h b/engines/ags/engine/ac/display.h
index 7047868c142..f929b145af5 100644
--- a/engines/ags/engine/ac/display.h
+++ b/engines/ags/engine/ac/display.h
@@ -42,7 +42,8 @@ struct ScreenOverlay;
 // Pass yy = -1 to find Y co-ord automatically
 // allowShrink = 0 for none, 1 for leftwards, 2 for rightwards
 // pass blocking=2 to create permanent overlay
-ScreenOverlay *_display_main(int xx, int yy, int wii, const char *text, int disp_type, int usingfont, int asspch, int isThought, int allowShrink, bool overlayPositionFixed);
+ScreenOverlay *_display_main(int xx, int yy, int wii, const char *text, int disp_type, int usingfont,
+	int asspch, int isThought, int allowShrink, bool overlayPositionFixed, bool roomlayer = false);
 void _display_at(int xx, int yy, int wii, const char *text, int disp_type, int asspch, int isThought, int allowShrink, bool overlayPositionFixed);
 // Tests the given string for the voice-over tags and plays cue clip for the given character;
 // will assign replacement string, which will be blank string if game is in "voice-only" mode
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index 03996f95a76..b0feffed98e 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -443,6 +443,9 @@ void clear_drawobj_cache() {
 		_G(objcache)[i].image = nullptr;
 	}
 
+	// room overlays cache
+	_GP(screenovercache).clear();
+
 	// cleanup Character + Room object textures
 	for (auto &o : _GP(actsps)) o = ObjTexture();
 	for (auto &o : _GP(walkbehindobj)) o = ObjTexture();
@@ -1672,6 +1675,17 @@ void add_walkbehind_image(size_t index, Shared::Bitmap *bmp, int x, int y) {
 	_GP(walkbehindobj)[index].Pos = Point(x, y);
 }
 
+// Add active room overlays to the sprite list
+static void add_roomovers_for_drawing() {
+	for (size_t i = 0; i < _GP(screenover).size(); ++i) {
+		auto &over = _GP(screenover)[i];
+		if (!over.IsRoomLayer()) continue; // not a room layer
+		if (over.transparency == 255) continue; // skip fully transparent
+		Point pos = get_overlay_position(over);
+		add_to_sprite_list(over.ddb, pos.X, pos.Y, over.zorder, false);
+	}
+}
+
 // Compiles a list of room sprites (characters, objects, background)
 void prepare_room_sprites() {
 	// Background sprite is required for the non-software renderers always,
@@ -1699,6 +1713,7 @@ void prepare_room_sprites() {
 	if ((_G(debug_flags) & DBG_NOOBJECTS) == 0) {
 		prepare_objects_for_drawing();
 		prepare_characters_for_drawing();
+		add_roomovers_for_drawing();
 
 		if ((_G(debug_flags) & DBG_NODRAWSPRITES) == 0) {
 			_G(our_eip) = 34;
@@ -1860,22 +1875,10 @@ void draw_gui_and_overlays() {
 
 	const bool is_software_mode = !_G(gfxDriver)->HasAcceleratedTransform();
 	// Add active overlays to the sprite list
-	if (_GP(overlaybmp).size() < _GP(screenover).size())
-		_GP(overlaybmp).resize(_GP(screenover).size());
 	for (size_t i = 0; i < _GP(screenover).size(); ++i) {
 		auto &over = _GP(screenover)[i];
+		if (over.IsRoomLayer()) continue; // not a ui layer
 		if (over.transparency == 255) continue; // skip fully transparent
-		if (_GP(screenover)[i].HasChanged()) {
-			// For software mode - prepare transformed bitmap if necessary
-			Bitmap *use_bmp = is_software_mode ?
-				transform_sprite(over.pic, over.HasAlphaChannel(), _GP(overlaybmp)[i], Size(over.scaleWidth, over.scaleHeight)) :
-				over.pic;
-			over.ddb = recycle_ddb_bitmap(over.ddb, use_bmp, over.HasAlphaChannel());
-			over.ClearChanged();
-		}
-
-		over.ddb->SetStretch(over.scaleWidth, over.scaleHeight);
-		over.ddb->SetAlpha(GfxDef::LegacyTrans255ToAlpha255(over.transparency));
 		Point pos = get_overlay_position(over);
 		add_to_sprite_list(over.ddb, pos.X, pos.Y, over.zorder, false);
 	}
@@ -2091,6 +2094,52 @@ static void construct_ui_view() {
 	clear_draw_list();
 }
 
+// Prepares overlay textures;
+// but does not put them on screen yet - that's done in respective construct_*_view functions
+static void construct_overlays() {
+	const bool is_software_mode = !_G(gfxDriver)->HasAcceleratedTransform();
+	if (_GP(overlaybmp).size() < _GP(screenover).size()) {
+		_GP(overlaybmp).resize(_GP(screenover).size());
+		_GP(screenovercache).resize(_GP(screenover).size());
+	}
+	for (size_t i = 0; i < _GP(screenover).size(); ++i) {
+		auto &over = _GP(screenover)[i];
+		if (over.transparency == 255) continue; // skip fully transparent
+
+		bool has_changed = over.HasChanged();
+		if (over.IsRoomLayer() && (_G(walkBehindMethod) == DrawOverCharSprite)) {
+			Point pos = get_overlay_position(over);
+			has_changed |= (pos.X != _GP(screenovercache)[i].X || pos.Y != _GP(screenovercache)[i].Y);
+			_GP(screenovercache)[i].X = pos.X; _GP(screenovercache)[i].Y = pos.Y;
+		}
+
+		if (has_changed) {
+			// For software mode - prepare transformed bitmap if necessary
+			Bitmap *use_bmp = is_software_mode ?
+				transform_sprite(over.pic, over.HasAlphaChannel(), _GP(overlaybmp)[i], Size(over.scaleWidth, over.scaleHeight)) :
+				over.pic;
+
+			if ((_G(walkBehindMethod) == DrawOverCharSprite) && over.IsRoomLayer()) {
+				if (use_bmp != _GP(overlaybmp)[i].get()) {
+					recycle_bitmap(_GP(overlaybmp)[i], over.pic->GetColorDepth(), over.pic->GetWidth(), over.pic->GetHeight(), true);
+					_GP(overlaybmp)[i]->Blit(over.pic);
+				}
+				Point pos = get_overlay_position(over);
+				walkbehinds_cropout(_GP(overlaybmp)[i].get(), pos.X, pos.Y, over.zorder);
+				use_bmp = _GP(overlaybmp)[i].get();
+			}
+
+			over.ddb = recycle_ddb_bitmap(over.ddb, use_bmp, over.HasAlphaChannel());
+			over.ClearChanged();
+		}
+
+		assert(over.ddb); // Test for missing texture, might happen if not marked for update
+		if (!over.ddb) continue;
+		over.ddb->SetStretch(over.scaleWidth, over.scaleHeight);
+		over.ddb->SetAlpha(GfxDef::LegacyTrans255ToAlpha255(over.transparency));
+	}
+}
+
 void construct_game_scene(bool full_redraw) {
 	_G(gfxDriver)->ClearDrawLists();
 
@@ -2111,6 +2160,9 @@ void construct_game_scene(bool full_redraw) {
 	if (full_redraw || _GP(play).screen_tint > 0 || _GP(play).shakesc_length > 0)
 		invalidate_screen();
 
+	// Overlays may be both in rooms and ui layer, prepare their textures beforehand
+	construct_overlays();
+
 	// TODO: move to game update! don't call update during rendering pass!
 	// IMPORTANT: keep the order same because sometimes script may depend on it
 	if (_G(displayed_room) >= 0)
diff --git a/engines/ags/engine/ac/global_overlay.cpp b/engines/ags/engine/ac/global_overlay.cpp
index 0b540623b34..81bce47e535 100644
--- a/engines/ags/engine/ac/global_overlay.cpp
+++ b/engines/ags/engine/ac/global_overlay.cpp
@@ -36,8 +36,8 @@ void RemoveOverlay(int ovrid) {
 	remove_screen_overlay(ovrid);
 }
 
-int CreateGraphicOverlay(int x, int y, int slot, int trans) {
-	auto *over = Overlay_CreateGraphicCore(x, y, slot, trans != 0);
+int CreateGraphicOverlay(int xx, int yy, int slott, int trans) {
+	auto *over = Overlay_CreateGraphicCore(false, xx, yy, slott, trans);
 	return over ? over->type : 0;
 }
 
@@ -50,7 +50,7 @@ int CreateTextOverlay(int xx, int yy, int wii, int fontid, int text_color, const
 	} else  // allow DisplaySpeechBackground to be shrunk
 		allowShrink = 1;
 
-	auto *over = Overlay_CreateTextCore(xx, yy, wii, fontid, text_color, text, disp_type, allowShrink);
+	auto *over = Overlay_CreateTextCore(false, xx, yy, wii, fontid, text_color, text, disp_type, allowShrink);
 	return over ? over->type : 0;
 }
 
diff --git a/engines/ags/engine/ac/overlay.cpp b/engines/ags/engine/ac/overlay.cpp
index 1691be88b13..f14258202eb 100644
--- a/engines/ags/engine/ac/overlay.cpp
+++ b/engines/ags/engine/ac/overlay.cpp
@@ -168,15 +168,16 @@ int Overlay_GetValid(ScriptOverlay *scover) {
 	return 1;
 }
 
-ScreenOverlay *Overlay_CreateGraphicCore(int x, int y, int slot, bool transparent) {
+ScreenOverlay *Overlay_CreateGraphicCore(bool room_layer, int x, int y, int slot, bool transparent) {
 	data_to_game_coords(&x, &y);
 	Bitmap *screeno = BitmapHelper::CreateTransparentBitmap(_GP(game).SpriteInfos[slot].Width, _GP(game).SpriteInfos[slot].Height, _GP(game).GetColorDepth());
 	screeno->Blit(_GP(spriteset)[slot], 0, 0, transparent ? kBitmap_Transparency : kBitmap_Copy);
-	size_t nse = add_screen_overlay(x, y, OVER_CUSTOM, screeno, (_GP(game).SpriteInfos[slot].Flags & SPF_ALPHACHANNEL) != 0);
+	size_t nse = add_screen_overlay(room_layer, x, y, OVER_CUSTOM, screeno,
+		(_GP(game).SpriteInfos[slot].Flags & SPF_ALPHACHANNEL) != 0);
 	return nse < SIZE_MAX ? &_GP(screenover)[nse] : nullptr;
 }
 
-ScreenOverlay *Overlay_CreateTextCore(int x, int y, int width, int font, int text_color,
+ScreenOverlay *Overlay_CreateTextCore(bool room_layer, int x, int y, int width, int font, int text_color,
 	const char *text, int disp_type, int allow_shrink) {
 	if (width < 8) width = _GP(play).GetUIViewport().GetWidth() / 2;
 	if (x < 0) x = _GP(play).GetUIViewport().GetWidth() / 2 - width / 2;
@@ -184,18 +185,27 @@ ScreenOverlay *Overlay_CreateTextCore(int x, int y, int width, int font, int tex
 	return _display_main(x, y, width, text, disp_type, font, -text_color, 0, allow_shrink, false);
 }
 
+ScriptOverlay *Overlay_CreateGraphicalEx(bool room_layer, int x, int y, int slot, int transparent) {
+	auto *over = Overlay_CreateGraphicCore(room_layer, x, y, slot, transparent != 0);
+	return over ? create_scriptoverlay(*over) : nullptr;
+}
+
 ScriptOverlay *Overlay_CreateGraphical(int x, int y, int slot, int transparent) {
-	auto *over = Overlay_CreateGraphicCore(x, y, slot, transparent != 0);
+	auto *over = Overlay_CreateGraphicCore(false, x, y, slot, transparent != 0);
 	return over ? create_scriptoverlay(*over) : nullptr;
 }
 
-ScriptOverlay *Overlay_CreateTextual(int x, int y, int width, int font, int colour, const char *text) {
+ScriptOverlay *Overlay_CreateTextualEx(bool room_layer, int x, int y, int width, int font, int colour, const char *text) {
 	data_to_game_coords(&x, &y);
 	width = data_to_game_coord(width);
-	auto *over = Overlay_CreateTextCore(x, y, width, font, colour, text, DISPLAYTEXT_NORMALOVERLAY, 0);
+	auto *over = Overlay_CreateTextCore(room_layer, x, y, width, font, colour, text, DISPLAYTEXT_NORMALOVERLAY, 0);
 	return over ? create_scriptoverlay(*over) : nullptr;
 }
 
+ScriptOverlay *Overlay_CreateTextual(int x, int y, int width, int font, int colour, const char *text) {
+	return Overlay_CreateTextualEx(false, x, y, width, font, colour, text);
+}
+
 int Overlay_GetTransparency(ScriptOverlay *scover) {
 	int ovri = find_overlay_of_type(scover->overlayId);
 	if (ovri < 0)
@@ -310,11 +320,11 @@ int find_overlay_of_type(int type) {
 	return -1;
 }
 
-size_t add_screen_overlay(int x, int y, int type, Bitmap *piccy, bool alphaChannel) {
-	return add_screen_overlay(x, y, type, piccy, 0, 0, alphaChannel);
+size_t add_screen_overlay(bool roomlayer, int x, int y, int type, Bitmap *piccy, bool alphaChannel) {
+	return add_screen_overlay(roomlayer, x, y, type, piccy, 0, 0, alphaChannel);
 }
 
-size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic_offx, int pic_offy, bool alphaChannel) {
+size_t add_screen_overlay(bool roomlayer, int x, int y, int type, Bitmap *piccy, int pic_offx, int pic_offy, bool alphaChannel) {
 	if (type == OVER_CUSTOM) {
 		// find an unused custom ID; TODO: find a better approach!
 		for (int id = OVER_CUSTOM + 1; (size_t)id <= _GP(screenover).size() + OVER_CUSTOM + 1; ++id) {
@@ -334,14 +344,14 @@ size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic
 	over.scaleWidth = piccy->GetWidth();
 	over.scaleHeight = piccy->GetHeight();
 	// by default draw speech and portraits over GUI, and the rest under GUI
-	over.zorder = (type == OVER_TEXTMSG || type == OVER_PICTURE || type == OVER_TEXTSPEECH) ?
+	over.zorder = (roomlayer || type == OVER_TEXTMSG || type == OVER_PICTURE || type == OVER_TEXTSPEECH) ?
 		INT_MAX : INT_MIN;
 	over.type = type;
 	over.timeout = 0;
 	over.bgSpeechForChar = -1;
 	over.associatedOverlayHandle = 0;
 	over.SetAlphaChannel(alphaChannel);
-	over.SetRoomRelative(false);
+	over.SetRoomLayer(roomlayer);
 	// TODO: move these custom settings outside of this function
 	if (type == OVER_COMPLETE) _GP(play).complete_overlay_on = type;
 	else if (type == OVER_TEXTMSG || type == OVER_TEXTSPEECH) {
@@ -360,6 +370,10 @@ size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic
 }
 
 Point get_overlay_position(const ScreenOverlay &over) {
+	if (over.IsRoomLayer()) {
+		return Point(over.x + over.offsetX, over.y + over.offsetY);
+	}
+
 	if (over.x == OVR_AUTOPLACE) {
 		const Rect &ui_view = _GP(play).GetUIViewport();
 		// auto place on character
@@ -411,14 +425,31 @@ void recreate_overlay_ddbs() {
 
 // ScriptOverlay* (int x, int y, int slot, int transparent)
 RuntimeScriptValue Sc_Overlay_CreateGraphical(const RuntimeScriptValue *params, int32_t param_count) {
-	API_SCALL_OBJAUTO_PINT4(ScriptOverlay, Overlay_CreateGraphical);
+	ASSERT_PARAM_COUNT(FUNCTION, 4);
+	ScriptOverlay *overlay = Overlay_CreateGraphicalEx(false, params[0].IValue, params[1].IValue, params[2].IValue,
+		params[3].IValue);
+	return RuntimeScriptValue().SetDynamicObject(overlay, overlay);
+}
+
+RuntimeScriptValue Sc_Overlay_CreateRoomGraphical(const RuntimeScriptValue *params, int32_t param_count) {
+	ASSERT_PARAM_COUNT(FUNCTION, 4);
+	ScriptOverlay *overlay = Overlay_CreateGraphicalEx(true, params[0].IValue, params[1].IValue, params[2].IValue,
+		params[3].IValue);
+	return RuntimeScriptValue().SetDynamicObject(overlay, overlay);
 }
 
 // ScriptOverlay* (int x, int y, int width, int font, int colour, const char* text, ...)
 RuntimeScriptValue Sc_Overlay_CreateTextual(const RuntimeScriptValue *params, int32_t param_count) {
 	API_SCALL_SCRIPT_SPRINTF(Overlay_CreateTextual, 6);
-	ScriptOverlay *overlay = Overlay_CreateTextual(params[0].IValue, params[1].IValue, params[2].IValue,
-	                         params[3].IValue, params[4].IValue, scsf_buffer);
+	ScriptOverlay *overlay = Overlay_CreateTextualEx(false, params[0].IValue, params[1].IValue, params[2].IValue,
+		params[3].IValue, params[4].IValue, scsf_buffer);
+	return RuntimeScriptValue().SetDynamicObject(overlay, overlay);
+}
+
+RuntimeScriptValue Sc_Overlay_CreateRoomTextual(const RuntimeScriptValue *params, int32_t param_count) {
+	API_SCALL_SCRIPT_SPRINTF(Overlay_CreateRoomTextual, 6);
+	ScriptOverlay *overlay = Overlay_CreateTextualEx(true, params[0].IValue, params[1].IValue, params[2].IValue,
+		params[3].IValue, params[4].IValue, scsf_buffer);
 	return RuntimeScriptValue().SetDynamicObject(overlay, overlay);
 }
 
@@ -515,6 +546,8 @@ void ScPl_Overlay_SetText(ScriptOverlay *scover, int wii, int fontid, int clr, c
 void RegisterOverlayAPI() {
 	ccAddExternalStaticFunction("Overlay::CreateGraphical^4", Sc_Overlay_CreateGraphical);
 	ccAddExternalStaticFunction("Overlay::CreateTextual^106", Sc_Overlay_CreateTextual);
+	ccAddExternalStaticFunction("Overlay::CreateRoomGraphical^4", Sc_Overlay_CreateRoomGraphical);
+	ccAddExternalStaticFunction("Overlay::CreateRoomTextual^106", Sc_Overlay_CreateRoomTextual);
 	ccAddExternalObjectFunction("Overlay::SetText^104", Sc_Overlay_SetText);
 	ccAddExternalObjectFunction("Overlay::Remove^0", Sc_Overlay_Remove);
 	ccAddExternalObjectFunction("Overlay::get_Valid", Sc_Overlay_GetValid);
diff --git a/engines/ags/engine/ac/overlay.h b/engines/ags/engine/ac/overlay.h
index c3d048ed24b..48d277b07bd 100644
--- a/engines/ags/engine/ac/overlay.h
+++ b/engines/ags/engine/ac/overlay.h
@@ -45,18 +45,18 @@ void Overlay_SetY(ScriptOverlay *scover, int newy);
 int  Overlay_GetValid(ScriptOverlay *scover);
 ScriptOverlay *Overlay_CreateGraphical(int x, int y, int slot, int transparent);
 ScriptOverlay *Overlay_CreateTextual(int x, int y, int width, int font, int colour, const char *text);
-ScreenOverlay *Overlay_CreateGraphicCore(int x, int y, int slot, bool transparent);
-ScreenOverlay *Overlay_CreateTextCore(int x, int y, int width, int font, int text_color,
+ScreenOverlay *Overlay_CreateGraphicCore(bool room_layer, int x, int y, int slot, bool transparent);
+ScreenOverlay *Overlay_CreateTextCore(bool room_layer, int x, int y, int width, int font, int text_color,
 	const char *text, int disp_type, int allow_shrink);
 
 int  find_overlay_of_type(int type);
 void remove_screen_overlay(int type);
-// Calculates overlay position in screen coordinates
+// Calculates overlay position in its respective layer (screen or room)
 Point get_overlay_position(const ScreenOverlay &over);
-size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, bool alphaChannel = false);
-size_t  add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic_offx, int pic_offy, bool alphaChannel = false);
+size_t add_screen_overlay(bool roomlayer, int x, int y, int type, Shared::Bitmap *piccy, bool alphaChannel = false);
+size_t add_screen_overlay(bool roomlayer, int x, int y, int type, Shared::Bitmap *piccy, int pic_offx, int pic_offy, bool alphaChannel = false);
 void remove_screen_overlay_index(size_t over_idx);
-// Creates and registers a managed script object for existing overlay object;
+// Creates and registers a managed script object for // Creates and registers a managed script object for existing overlay object;
 // optionally adds an internal engine reference to prevent object's disposal
 ScriptOverlay *create_scriptoverlay(ScreenOverlay &over, bool internal_ref = false);
 void recreate_overlay_ddbs();
diff --git a/engines/ags/engine/ac/screen_overlay.h b/engines/ags/engine/ac/screen_overlay.h
index 479f94eb79b..2425f98be8b 100644
--- a/engines/ags/engine/ac/screen_overlay.h
+++ b/engines/ags/engine/ac/screen_overlay.h
@@ -46,7 +46,8 @@ using namespace AGS; // FIXME later
 
 enum OverlayFlags {
 	kOver_AlphaChannel = 0x0001,
-	kOver_PositionAtRoomXY = 0x0002, // room-relative position
+	kOver_PositionAtRoomXY = 0x0002, // room-relative position, may be in ui
+	kOver_RoomLayer = 0x0004         // work in room layer (as opposed to UI)
 };
 
 // Overlay class.
@@ -81,12 +82,19 @@ struct ScreenOverlay {
 	bool IsRoomRelative() const {
 		return (_flags & kOver_PositionAtRoomXY) != 0;
 	}
+	bool IsRoomLayer() const {
+		return (_flags & kOver_RoomLayer) != 0;
+	}
 	void SetAlphaChannel(bool on) {
 		on ? _flags |= kOver_AlphaChannel : _flags &= ~kOver_AlphaChannel;
 	}
 	void SetRoomRelative(bool on) {
 		on ? _flags |= kOver_PositionAtRoomXY : _flags &= ~kOver_PositionAtRoomXY;
 	}
+	void SetRoomLayer(bool on) {
+		on ? _flags |= (kOver_RoomLayer | kOver_PositionAtRoomXY) :
+			_flags &= ~(kOver_RoomLayer | kOver_PositionAtRoomXY);
+	}
 
 	// Tells if Overlay has graphically changed recently
 	bool HasChanged() const {
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 23ac78fb66b..83cd4a8e778 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -238,6 +238,7 @@ Globals::Globals() {
 	_scrInv = new ScriptInvItem[MAX_INV];
 	_charcache = new std::vector<ObjectCache>();
 	_objcache = new ObjectCache[MAX_ROOM_OBJECTS];
+	_screenovercache = new std::vector<Point>();
 	_charextra = new std::vector<CharacterExtras>();
 	_mls = new std::vector<MoveList>();
 	_views = new std::vector<ViewStruct>();
@@ -497,6 +498,7 @@ Globals::~Globals() {
 	delete[] _scrInv;
 	delete _charcache;
 	delete[] _objcache;
+	delete _screenovercache;
 	delete _charextra;
 	delete _mls;
 	delete _views;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 9b88b069835..214f5d3da91 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -754,6 +754,7 @@ public:
 	// whether these require texture update
 	std::vector<ObjectCache> *_charcache;
 	ObjectCache *_objcache;
+	std::vector<Point> *_screenovercache;
 	std::vector<CharacterExtras> *_charextra;
 	std::vector<MoveList> *_mls;
 


Commit: d323d2388bb68636b9a6141c161f232fdc1df356
    https://github.com/scummvm/scummvm/commit/d323d2388bb68636b9a6141c161f232fdc1df356
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-05-06T20:16:42-07:00

Commit Message:
AGS: Added readonly bool Overlay.InRoom

>From upstream 481f9208c93b12e432bb0454b67b808e0921bc2b

Changed paths:
    engines/ags/engine/ac/overlay.cpp


diff --git a/engines/ags/engine/ac/overlay.cpp b/engines/ags/engine/ac/overlay.cpp
index f14258202eb..dbe8a6daef6 100644
--- a/engines/ags/engine/ac/overlay.cpp
+++ b/engines/ags/engine/ac/overlay.cpp
@@ -101,6 +101,13 @@ void Overlay_SetY(ScriptOverlay *scover, int newy) {
 	_GP(screenover)[ovri].y = data_to_game_coord(newy);
 }
 
+bool Overlay_InRoom(ScriptOverlay *scover) {
+	int ovri = find_overlay_of_type(scover->overlayId);
+	if (ovri < 0)
+		quit("!invalid overlay ID specified");
+	return _GP(screenover)[ovri].IsRoomLayer();
+}
+
 int Overlay_GetWidth(ScriptOverlay *scover) {
 	int ovri = find_overlay_of_type(scover->overlayId);
 	if (ovri < 0)
@@ -490,6 +497,10 @@ RuntimeScriptValue Sc_Overlay_SetY(void *self, const RuntimeScriptValue *params,
 	API_OBJCALL_VOID_PINT(ScriptOverlay, Overlay_SetY);
 }
 
+RuntimeScriptValue Sc_Overlay_InRoom(void *self, const RuntimeScriptValue *params, int32_t param_count) {
+	API_OBJCALL_BOOL(ScriptOverlay, Overlay_InRoom);
+}
+
 RuntimeScriptValue Sc_Overlay_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
 	API_OBJCALL_INT(ScriptOverlay, Overlay_GetWidth);
 }
@@ -555,6 +566,7 @@ void RegisterOverlayAPI() {
 	ccAddExternalObjectFunction("Overlay::set_X", Sc_Overlay_SetX);
 	ccAddExternalObjectFunction("Overlay::get_Y", Sc_Overlay_GetY);
 	ccAddExternalObjectFunction("Overlay::set_Y", Sc_Overlay_SetY);
+	ccAddExternalObjectFunction("Overlay::get_InRoom", Sc_Overlay_InRoom);
 	ccAddExternalObjectFunction("Overlay::get_Width", Sc_Overlay_GetWidth);
 	ccAddExternalObjectFunction("Overlay::set_Width", Sc_Overlay_SetWidth);
 	ccAddExternalObjectFunction("Overlay::get_Height", Sc_Overlay_GetHeight);


Commit: 8f0da16853b226061ebdd145154a7e2598950e49
    https://github.com/scummvm/scummvm/commit/8f0da16853b226061ebdd145154a7e2598950e49
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-05-06T20:16:42-07:00

Commit Message:
AGS: Re-enable std::move call in ObjTexture constructor

Changed paths:
    engines/ags/engine/ac/draw.cpp


diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index b0feffed98e..941efeeb68c 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -80,8 +80,7 @@ using namespace AGS::Engine;
 int _places_r = 3, _places_g = 2, _places_b = 3;
 
 ObjTexture::ObjTexture(ObjTexture &&o) {
-//	*this = std::move(o);
-	error("TODO: ObjTexture");
+	*this = std::move(o);
 }
 
 ObjTexture::~ObjTexture() {




More information about the Scummvm-git-logs mailing list