[Scummvm-git-logs] scummvm master -> 106622d44c074d311e22905070264b4d17393885

dreammaster noreply at scummvm.org
Tue Mar 22 05:10:28 UTC 2022


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

Summary:
c63ea5ed84 AGS: ListBox.FillDirList supports $DATA$ path token
2ef749739e AGS: Fixed SOUNDCLIP::set_volume_direct()
5940252185 AGS: In AssetManager separate asset presence check and stream open
42e7f5e81b AGS: In AssetManager precache real CI filenames of the lib parts
46447192e5 AGS: Updated build version (3.5.1.12)
3ca1db4cd8 AGS: Fixed engine shutdown could try to access unallocated objects
106622d44c AGS: Removed "scaling factor" from the FrameScaleDefinition struct


Commit: c63ea5ed847a4ee956779d60ab894a523cd0be15
    https://github.com/scummvm/scummvm/commit/c63ea5ed847a4ee956779d60ab894a523cd0be15
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-21T19:10:30-07:00

Commit Message:
AGS: ListBox.FillDirList supports $DATA$ path token

>From upstream 19a15acbf99ad223348c74d6de61cc56acc1ad69

Changed paths:
    engines/ags/shared/core/asset_manager.cpp
    engines/ags/shared/core/asset_manager.h


diff --git a/engines/ags/shared/core/asset_manager.cpp b/engines/ags/shared/core/asset_manager.cpp
index 870abd7dcc4..e67f2292067 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -24,6 +24,7 @@
 #include "ags/lib/std/utility.h"
 #include "ags/shared/core/platform.h"
 #include "ags/shared/core/asset_manager.h"
+#include "ags/shared/util/directory.h"
 #include "ags/shared/util/multi_file_lib.h"
 #include "ags/shared/util/path.h"
 #include "ags/shared/util/string_utils.h" // cbuf_to_string_and_free
@@ -157,6 +158,33 @@ bool AssetManager::DoesAssetExist(const String &asset_name, const String &filter
 	return GetAsset(asset_name, filter, nullptr);
 }
 
+void AssetManager::FindAssets(std::vector<String> &assets, const String &wildcard,
+		const String &filter) const {
+	String pattern = StrUtil::WildcardToRegex(wildcard);
+
+	for (const auto *lib : _activeLibs) {
+		auto match = std::find(lib->Filters.begin(), lib->Filters.end(), filter);
+		if (match == lib->Filters.end())
+			continue; // filter does not match
+
+		if (IsAssetLibDir(lib)) {
+			for (FindFile ff = FindFile::OpenFiles(lib->BaseDir, wildcard);
+				!ff.AtEnd(); ff.Next())
+				assets.push_back(ff.Current());
+		} else {
+			for (const auto &a : lib->AssetInfos) {
+				if (pattern == "*" || (*pattern.GetCStr() &&
+						Common::String(a.FileName).hasSuffixIgnoreCase(pattern.GetCStr() + 1)))
+					assets.push_back(a.FileName);
+			}
+		}
+	}
+
+	// Sort and remove duplicates
+	std::sort(assets.begin(), assets.end());
+	assets.erase(std::unique(assets.begin(), assets.end()), assets.end());
+}
+
 AssetError AssetManager::RegisterAssetLib(const String &path, AssetLibEx *&out_lib) {
 	// Test for a directory
 	std::unique_ptr<AssetLibEx> lib;
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index 5a1fc6f0ab3..cb3e2978a08 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -120,6 +120,10 @@ public:
 	inline bool  DoesAssetExist(const AssetPath &apath) const {
 		return DoesAssetExist(apath.Name, apath.Filter);
 	}
+	// Searches in all the registered locations and collects a list of
+    // assets using given wildcard pattern
+    void FindAssets(std::vector<String> &assets, const String &wildcard,
+		const String &filter = "") const;
 	// Open asset stream in the given work mode; returns null if asset is not found or cannot be opened
 	// This method only searches in libraries that do not have any defined filters
 	Stream *OpenAsset(const String &asset_name) const;


Commit: 2ef749739e65439fb7d901df7774e0b6b4a3cd54
    https://github.com/scummvm/scummvm/commit/2ef749739e65439fb7d901df7774e0b6b4a3cd54
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-21T19:13:00-07:00

Commit Message:
AGS: Fixed SOUNDCLIP::set_volume_direct()

>From upstream e2d8f727811c6ff58a0f05222c3007805abcf3ce

Changed paths:
    engines/ags/engine/media/audio/sound_clip.cpp


diff --git a/engines/ags/engine/media/audio/sound_clip.cpp b/engines/ags/engine/media/audio/sound_clip.cpp
index 8c91ce2d9c0..cab57c7ee64 100644
--- a/engines/ags/engine/media/audio/sound_clip.cpp
+++ b/engines/ags/engine/media/audio/sound_clip.cpp
@@ -44,7 +44,7 @@ void SOUNDCLIP::set_volume255(int volume) {
 }
 
 void SOUNDCLIP::set_volume_direct(int vol_percent, int vol_absolute) {
-	//vol255 = vol255;
+	_vol255 = vol_absolute;
 	_vol100 = vol_percent;
 	adjust_volume();
 }


Commit: 594025218533067f5ed6114929fc08f5e01cc017
    https://github.com/scummvm/scummvm/commit/594025218533067f5ed6114929fc08f5e01cc017
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-21T19:30:33-07:00

Commit Message:
AGS: In AssetManager separate asset presence check and stream open

>From upstream 15acceda9cbed46d0dc5189b878645ebdf2e48f0

Changed paths:
    engines/ags/shared/core/asset_manager.cpp
    engines/ags/shared/core/asset_manager.h


diff --git a/engines/ags/shared/core/asset_manager.cpp b/engines/ags/shared/core/asset_manager.cpp
index e67f2292067..713e4ef2e9e 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -33,18 +33,17 @@ namespace AGS3 {
 namespace AGS {
 namespace Shared {
 
-AssetLocation::AssetLocation()
-	: Offset(0)
-	, Size(0) {
-}
-
-
 inline static bool IsAssetLibDir(const AssetLibInfo *lib) {
 	return lib->BaseFileName.IsEmpty();
 }
-// inline static bool IsAssetLibFile(const AssetLibInfo *lib) {
-// 	return !lib->BaseFileName.IsEmpty();
-// }
+inline static bool IsAssetLibFile(const AssetLibInfo *lib) {
+	return !lib->BaseFileName.IsEmpty();
+}
+
+bool AssetManager::AssetLibEx::TestFilter(const String &filter) const {
+	return filter == "*" ||
+		(std::find(Filters.begin(), Filters.end(), filter) != Filters.end());
+}
 
 bool AssetManager::LibsByPriority::operator()(const AssetLibInfo *lib1, const AssetLibInfo *lib2) const {
 	const bool lib1dir = IsAssetLibDir(lib1);
@@ -155,7 +154,20 @@ const AssetLibInfo *AssetManager::GetLibraryInfo(size_t index) const {
 }
 
 bool AssetManager::DoesAssetExist(const String &asset_name, const String &filter) const {
-	return GetAsset(asset_name, filter, nullptr);
+	for (const auto &lib : _activeLibs) {
+		if (!lib->TestFilter(filter))
+			continue; // filter does not match
+
+		if (IsAssetLibDir(lib)) {
+			String filename = File::FindFileCI(lib->BaseDir, asset_name);
+			if (!filename.IsEmpty() && File::IsFile(filename)) return true;
+		} else {
+			for (const auto &a : lib->AssetInfos) {
+				if (a.FileName.CompareNoCase(asset_name) == 0) return true;
+			}
+		}
+	}
+	return false;
 }
 
 void AssetManager::FindAssets(std::vector<String> &assets, const String &wildcard,
@@ -174,7 +186,7 @@ void AssetManager::FindAssets(std::vector<String> &assets, const String &wildcar
 		} else {
 			for (const auto &a : lib->AssetInfos) {
 				if (pattern == "*" || (*pattern.GetCStr() &&
-						Common::String(a.FileName).hasSuffixIgnoreCase(pattern.GetCStr() + 1)))
+						Common::String(a.FileName.GetCStr()).hasSuffixIgnoreCase(pattern.GetCStr() + 1)))
 					assets.push_back(a.FileName);
 			}
 		}
@@ -220,72 +232,44 @@ AssetError AssetManager::RegisterAssetLib(const String &path, AssetLibEx *&out_l
 	return kAssetNoError;
 }
 
-bool AssetManager::GetAsset(const String &asset_name, const String &filter,
-		AssetLocation *loc) const {
+Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter) const {
 	for (const auto *lib : _activeLibs) {
-		auto match = std::find(lib->Filters.begin(), lib->Filters.end(), filter);
-		if (match == lib->Filters.end())
-			continue; // filter does not match
+		if (!lib->TestFilter(filter)) continue; // filter does not match
 
-		bool found = false;
+		Stream *s = nullptr;
 		if (IsAssetLibDir(lib))
-			found = GetAssetFromDir(lib, asset_name, loc);
+			s = OpenAssetFromDir(lib, asset_name);
 		else
-			found = GetAssetFromLib(lib, asset_name, loc);
-		if (found)
-			return true;
+			s = OpenAssetFromLib(lib, asset_name);
+		if (s)
+			return s;
 	}
-	return false;
+	return nullptr;
 }
 
-bool AssetManager::GetAssetFromLib(const AssetLibInfo *lib, const String &asset_name,
-		AssetLocation *loc) const {
-	const AssetInfo *asset = nullptr;
+Stream *AssetManager::OpenAssetFromLib(const AssetLibInfo *lib, const String &asset_name) const {
 	for (const auto &a : lib->AssetInfos) {
 		if (a.FileName.CompareNoCase(asset_name) == 0) {
-			asset = &a;
-			break;
+			String libfile = File::FindFileCI(lib->BaseDir, lib->LibFileNames[a.LibUid]);
+			if (libfile.IsEmpty())
+				return nullptr;
+			return File::OpenFile(libfile, a.Offset, a.Offset + a.Size);
 		}
 	}
-	if (asset == nullptr)
-		return false;
-
-	String libfile = File::FindFileCI(lib->BaseDir, lib->LibFileNames[asset->LibUid]);
-	if (libfile.IsEmpty())
-		return false;
-	if (loc) {
-		loc->FileName = libfile;
-		loc->Offset = asset->Offset;
-		loc->Size = asset->Size;
-	}
-	return true;
+	return nullptr;
 }
 
-bool AssetManager::GetAssetFromDir(const AssetLibInfo *lib, const String &file_name,
-		AssetLocation *loc) const {
+Stream *AssetManager::OpenAssetFromDir(const AssetLibInfo *lib, const String &file_name) const {
 	String found_file = File::FindFileCI(lib->BaseDir, file_name);
-	if (found_file.IsEmpty() || !File::IsFile(found_file))
-		return false; // not found, or not a file
-
-	if (loc) {
-		loc->FileName = found_file;
-		loc->Offset = 0;
-		loc->Size = File::GetFileSize(found_file);
-	}
-	return true;
+	if (found_file.IsEmpty())
+		return nullptr;
+	return File::OpenFileRead(found_file);
 }
 
 Stream *AssetManager::OpenAsset(const String &asset_name) const {
 	return OpenAsset(asset_name, "");
 }
 
-Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter) const {
-	AssetLocation loc;
-	if (!GetAsset(asset_name, filter, &loc))
-		return nullptr;
-	return File::OpenFile(loc.FileName, loc.Offset, loc.Offset + loc.Size);
-}
-
 Common::SeekableReadStream *AssetManager::OpenAssetStream(const String &asset_name) const {
 	return OpenAssetStream(asset_name, "");
 }
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index cb3e2978a08..b53f60d6b65 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -75,18 +75,6 @@ struct AssetPath {
 	}
 };
 
-/**
- * Explicit location of asset data
- */
-struct AssetLocation {
-	String      FileName;   // file where asset is located
-	soff_t      Offset;     // asset's position in file (in bytes)
-	soff_t      Size;       // asset's size (in bytes)
-
-	AssetLocation();
-};
-
-
 class AssetManager {
 public:
 	AssetManager();
@@ -141,15 +129,16 @@ public:
 private:
 	struct AssetLibEx : AssetLibInfo {
 		std::vector<String> Filters; // asset filters this library is matching to
+
+		bool TestFilter(const String &filter) const;
 	};
 
 	// Loads library and registers its contents into the cache
 	AssetError  RegisterAssetLib(const String &path, AssetLibEx *&lib);
 
 	// Tries to find asset in known locations, tests if it's possible to open, and fills in AssetLocation
-	bool        GetAsset(const String &asset_name, const String &filter, AssetLocation *loc) const;
-	bool        GetAssetFromLib(const AssetLibInfo *lib, const String &asset_name, AssetLocation *loc) const;
-	bool        GetAssetFromDir(const AssetLibInfo *lib, const String &asset_name, AssetLocation *loc) const;
+	Stream *OpenAssetFromLib(const AssetLibInfo *lib, const String &asset_name) const;
+	Stream *OpenAssetFromDir(const AssetLibInfo *lib, const String &asset_name) const;
 
 	std::vector<AssetLibEx *> _libs;
 	std::vector<AssetLibEx *> _activeLibs;


Commit: 42e7f5e81b106689554fe59d4699e5123a7be1fa
    https://github.com/scummvm/scummvm/commit/42e7f5e81b106689554fe59d4699e5123a7be1fa
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-21T19:35:47-07:00

Commit Message:
AGS: In AssetManager precache real CI filenames of the lib parts

>From upstream ca86578dc64e6a8c93287716aa67c860e21659cd

Changed paths:
    engines/ags/shared/core/asset_manager.cpp
    engines/ags/shared/core/asset_manager.h


diff --git a/engines/ags/shared/core/asset_manager.cpp b/engines/ags/shared/core/asset_manager.cpp
index 713e4ef2e9e..9decbff00f9 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -224,6 +224,11 @@ AssetError AssetManager::RegisterAssetLib(const String &path, AssetLibEx *&out_l
 		lib->BaseDir = Path::GetDirectoryPath(lib->BasePath);
 		lib->BaseFileName = Path::GetFilename(lib->BasePath);
 		lib->LibFileNames[0] = lib->BaseFileName;
+
+		// Find out real library files in the current filesystem and save them
+		for (size_t i = 0; i < lib->LibFileNames.size(); ++i) {
+			lib->RealLibFiles.push_back(File::FindFileCI(lib->BaseDir, lib->LibFileNames[i]));
+		}
 	}
 
 	out_lib = lib.release();
@@ -247,10 +252,10 @@ Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter)
 	return nullptr;
 }
 
-Stream *AssetManager::OpenAssetFromLib(const AssetLibInfo *lib, const String &asset_name) const {
+Stream *AssetManager::OpenAssetFromLib(const AssetLibEx *lib, const String &asset_name) const {
 	for (const auto &a : lib->AssetInfos) {
 		if (a.FileName.CompareNoCase(asset_name) == 0) {
-			String libfile = File::FindFileCI(lib->BaseDir, lib->LibFileNames[a.LibUid]);
+			String libfile = lib->RealLibFiles[a.LibUid];
 			if (libfile.IsEmpty())
 				return nullptr;
 			return File::OpenFile(libfile, a.Offset, a.Offset + a.Size);
@@ -259,7 +264,7 @@ Stream *AssetManager::OpenAssetFromLib(const AssetLibInfo *lib, const String &as
 	return nullptr;
 }
 
-Stream *AssetManager::OpenAssetFromDir(const AssetLibInfo *lib, const String &file_name) const {
+Stream *AssetManager::OpenAssetFromDir(const AssetLibEx *lib, const String &file_name) const {
 	String found_file = File::FindFileCI(lib->BaseDir, file_name);
 	if (found_file.IsEmpty())
 		return nullptr;
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index b53f60d6b65..eb51c44e0cd 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -127,8 +127,10 @@ public:
 	Common::SeekableReadStream *OpenAssetStream(const String &asset_name, const String &filter) const;
 
 private:
+	// AssetLibEx combines library info with extended internal data required for the manager
 	struct AssetLibEx : AssetLibInfo {
 		std::vector<String> Filters; // asset filters this library is matching to
+		std::vector<String> RealLibFiles; // fixed up library filenames
 
 		bool TestFilter(const String &filter) const;
 	};
@@ -137,8 +139,8 @@ private:
 	AssetError  RegisterAssetLib(const String &path, AssetLibEx *&lib);
 
 	// Tries to find asset in known locations, tests if it's possible to open, and fills in AssetLocation
-	Stream *OpenAssetFromLib(const AssetLibInfo *lib, const String &asset_name) const;
-	Stream *OpenAssetFromDir(const AssetLibInfo *lib, const String &asset_name) const;
+	Stream *OpenAssetFromLib(const AssetLibEx *lib, const String &asset_name) const;
+	Stream *OpenAssetFromDir(const AssetLibEx *lib, const String &asset_name) const;
 
 	std::vector<AssetLibEx *> _libs;
 	std::vector<AssetLibEx *> _activeLibs;


Commit: 46447192e5ea52d9f3d62a0c858c406c223cb677
    https://github.com/scummvm/scummvm/commit/46447192e5ea52d9f3d62a0c858c406c223cb677
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-21T19:40:40-07:00

Commit Message:
AGS: Updated build version (3.5.1.12)

>From upstream 51bc60954e8d27b48ccc16490cbfe9b83b6bc71a

Changed paths:
    engines/ags/shared/core/def_version.h


diff --git a/engines/ags/shared/core/def_version.h b/engines/ags/shared/core/def_version.h
index f50cd51be16..9b55af08c55 100644
--- a/engines/ags/shared/core/def_version.h
+++ b/engines/ags/shared/core/def_version.h
@@ -22,9 +22,9 @@
 #ifndef AGS_SHARED_CORE_DEFVERSION_H
 #define AGS_SHARED_CORE_DEFVERSION_H
 
-#define ACI_VERSION_STR      "3.6.0.11"
+#define ACI_VERSION_STR      "3.6.0.12"
 #if defined (RC_INVOKED) // for MSVC resource compiler
-#define ACI_VERSION_MSRC_DEF  3,6,0,11
+#define ACI_VERSION_MSRC_DEF  3,6,0,12
 #endif
 
 #define SPECIAL_VERSION ""


Commit: 3ca1db4cd87c1247041829c7cfe7af0274f81488
    https://github.com/scummvm/scummvm/commit/3ca1db4cd87c1247041829c7cfe7af0274f81488
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-21T20:30:33-07:00

Commit Message:
AGS: Fixed engine shutdown could try to access unallocated objects

>From upstream 1b43aeb3051c8e41811dff19d7630584d8f871b3

Changed paths:
    engines/ags/engine/ac/route_finder.cpp
    engines/ags/engine/ac/route_finder.h
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/route_finder.cpp b/engines/ags/engine/ac/route_finder.cpp
index 916c4654adf..7b59d7d9d4b 100644
--- a/engines/ags/engine/ac/route_finder.cpp
+++ b/engines/ags/engine/ac/route_finder.cpp
@@ -29,20 +29,6 @@ namespace AGS3 {
 
 using AGS::Shared::Bitmap;
 
-class IRouteFinder {
-public:
-	virtual ~IRouteFinder() {}
-
-	virtual void init_pathfinder() = 0;
-	virtual void shutdown_pathfinder() = 0;
-	virtual void set_wallscreen(Bitmap *wallscreen) = 0;
-	virtual int can_see_from(int x1, int y1, int x2, int y2) = 0;
-	virtual void get_lastcpos(int &lastcx, int &lastcy) = 0;
-	virtual void set_route_move_speed(int speed_x, int speed_y) = 0;
-	virtual int find_route(short srcx, short srcy, short xx, short yy, Bitmap *onscreen, int movlst, int nocross = 0, int ignore_walls = 0) = 0;
-	virtual void calculate_move_stage(MoveList *mlsp, int aaa) = 0;
-};
-
 class AGSRouteFinder : public IRouteFinder {
 public:
 	virtual ~AGSRouteFinder() {}
@@ -103,47 +89,45 @@ public:
 	}
 };
 
-static IRouteFinder *route_finder_impl = nullptr;
-
 void init_pathfinder(GameDataVersion game_file_version) {
 	if (game_file_version >= kGameVersion_350) {
 		AGS::Shared::Debug::Printf(AGS::Shared::MessageType::kDbgMsg_Info, "Initialize path finder library");
-		route_finder_impl = new AGSRouteFinder();
+		_GP(route_finder_impl).reset(new AGSRouteFinder());
 	} else {
 		AGS::Shared::Debug::Printf(AGS::Shared::MessageType::kDbgMsg_Info, "Initialize legacy path finder library");
-		route_finder_impl = new AGSLegacyRouteFinder();
+		_GP(route_finder_impl).reset(new AGSLegacyRouteFinder());
 	}
 
-	route_finder_impl->init_pathfinder();
+	_GP(route_finder_impl)->init_pathfinder();
 }
 
 void shutdown_pathfinder() {
-	if (route_finder_impl)
-		route_finder_impl->shutdown_pathfinder();
+	if (_GP(route_finder_impl))
+		_GP(route_finder_impl)->shutdown_pathfinder();
 }
 
 void set_wallscreen(Bitmap *wallscreen) {
-	route_finder_impl->set_wallscreen(wallscreen);
+	_GP(route_finder_impl)->set_wallscreen(wallscreen);
 }
 
 int can_see_from(int x1, int y1, int x2, int y2) {
-	return route_finder_impl->can_see_from(x1, y1, x2, y2);
+	return _GP(route_finder_impl)->can_see_from(x1, y1, x2, y2);
 }
 
 void get_lastcpos(int &lastcx, int &lastcy) {
-	route_finder_impl->get_lastcpos(lastcx, lastcy);
+	_GP(route_finder_impl)->get_lastcpos(lastcx, lastcy);
 }
 
 void set_route_move_speed(int speed_x, int speed_y) {
-	route_finder_impl->set_route_move_speed(speed_x, speed_y);
+	_GP(route_finder_impl)->set_route_move_speed(speed_x, speed_y);
 }
 
 int find_route(short srcx, short srcy, short xx, short yy, Bitmap *onscreen, int movlst, int nocross, int ignore_walls) {
-	return route_finder_impl->find_route(srcx, srcy, xx, yy, onscreen, movlst, nocross, ignore_walls);
+	return _GP(route_finder_impl)->find_route(srcx, srcy, xx, yy, onscreen, movlst, nocross, ignore_walls);
 }
 
 void calculate_move_stage(MoveList *mlsp, int aaa) {
-	route_finder_impl->calculate_move_stage(mlsp, aaa);
+	_GP(route_finder_impl)->calculate_move_stage(mlsp, aaa);
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/ac/route_finder.h b/engines/ags/engine/ac/route_finder.h
index 5dd3e91946f..a2dcb2a3099 100644
--- a/engines/ags/engine/ac/route_finder.h
+++ b/engines/ags/engine/ac/route_finder.h
@@ -35,6 +35,21 @@ class Bitmap;
 
 struct MoveList;
 
+class IRouteFinder {
+public:
+	virtual ~IRouteFinder() {
+	}
+
+	virtual void init_pathfinder() = 0;
+	virtual void shutdown_pathfinder() = 0;
+	virtual void set_wallscreen(AGS::Shared::Bitmap *wallscreen) = 0;
+	virtual int can_see_from(int x1, int y1, int x2, int y2) = 0;
+	virtual void get_lastcpos(int &lastcx, int &lastcy) = 0;
+	virtual void set_route_move_speed(int speed_x, int speed_y) = 0;
+	virtual int find_route(short srcx, short srcy, short xx, short yy, AGS::Shared::Bitmap *onscreen, int movlst, int nocross = 0, int ignore_walls = 0) = 0;
+	virtual void calculate_move_stage(MoveList *mlsp, int aaa) = 0;
+};
+
 void init_pathfinder(GameDataVersion game_file_version);
 void shutdown_pathfinder();
 
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 03f9fea61be..903dc00807e 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -319,6 +319,7 @@ Globals::Globals() {
 	// route_finder_impl.cpp globals
 	_navpoints = new int32_t[MAXNEEDSTAGES];
 	_nav = new Navigation();
+	_route_finder_impl = new std::unique_ptr<IRouteFinder>();
 
 	// screen.cpp globals
 	_old_palette = new color[256];
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 8f7ff74573f..169904b8de1 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -99,6 +99,7 @@ class EngineExports;
 } // namespace Core
 } // namespace Plugins
 
+class IRouteFinder;
 class Navigation;
 class SplitLines;
 class TTFFontRenderer;
@@ -1211,6 +1212,7 @@ public:
 	fixed _move_speed_x = 0, _move_speed_y = 0;
 	AGS::Shared::Bitmap *_wallscreen = nullptr;
 	int _lastcx = 0, _lastcy = 0;
+	std::unique_ptr<IRouteFinder> *_route_finder_impl;
 
 	/**@}*/
 


Commit: 106622d44c074d311e22905070264b4d17393885
    https://github.com/scummvm/scummvm/commit/106622d44c074d311e22905070264b4d17393885
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-21T22:08:04-07:00

Commit Message:
AGS: Removed "scaling factor" from the FrameScaleDefinition struct

>From upstream b2a4e98ecdd8cfd1d8e42ab32f6f337af60e5a68

Changed paths:
    engines/ags/engine/ac/game_setup.cpp
    engines/ags/engine/gfx/gfx_util.cpp
    engines/ags/engine/main/config.cpp
    engines/ags/engine/main/config.h
    engines/ags/engine/main/engine.cpp
    engines/ags/engine/main/graphics_mode.cpp
    engines/ags/engine/main/graphics_mode.h
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/game_setup.cpp b/engines/ags/engine/ac/game_setup.cpp
index 15106172c69..e41aa0dbd1c 100644
--- a/engines/ags/engine/ac/game_setup.cpp
+++ b/engines/ags/engine/ac/game_setup.cpp
@@ -45,8 +45,8 @@ GameSetup::GameSetup() {
 	Screen.DisplayMode.RefreshRate = 0;
 	Screen.DisplayMode.VSync = false;
 	Screen.DisplayMode.Windowed = false;
-	Screen.FsGameFrame = GameFrameSetup(kFrame_MaxProportional);
-	Screen.WinGameFrame = GameFrameSetup(kFrame_MaxRound);
+	Screen.FsGameFrame = kFrame_Proportional;
+	Screen.WinGameFrame = kFrame_Round;
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/gfx/gfx_util.cpp b/engines/ags/engine/gfx/gfx_util.cpp
index 11b3d09adb3..e872431d128 100644
--- a/engines/ags/engine/gfx/gfx_util.cpp
+++ b/engines/ags/engine/gfx/gfx_util.cpp
@@ -25,11 +25,6 @@
 
 namespace AGS3 {
 
-// CHECKME: is this hack still relevant?
-#if AGS_PLATFORM_OS_IOS || AGS_PLATFORM_OS_ANDROID
-extern int _G(psp_gfx_renderer);
-#endif
-
 namespace AGS {
 namespace Engine {
 
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index ec861719762..233d32013c8 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -104,64 +104,56 @@ ScreenSizeDefinition parse_screendef(const String &option, ScreenSizeDefinition
 	return def_value;
 }
 
-void parse_scaling_option(const String &scaling_option, FrameScaleDefinition &scale_def, int &scale_factor) {
-	const char *game_scale_options[kNumFrameScaleDef - 1] = { "max_round", "stretch", "proportional" };
-	scale_def = kFrame_IntScale;
-	for (int i = 0; i < kNumFrameScaleDef - 1; ++i) {
-		if (scaling_option.CompareNoCase(game_scale_options[i]) == 0) {
-			scale_def = (FrameScaleDefinition)(i + 1);
-			break;
-		}
-	}
-
-	if (scale_def == kFrame_IntScale)
-		scale_factor = StrUtil::StringToInt(scaling_option);
-	else
-		scale_factor = 0;
+FrameScaleDef parse_scaling_option(const String &option) {
+	if (option.CompareNoCase("round") == 0 || option.CompareNoCase("max_round") == 0)
+		return kFrame_Round;
+	if (option.CompareNoCase("stretch") == 0)
+		return kFrame_Stretch;
+	if (option.CompareNoCase("proportional") == 0)
+		return kFrame_Proportional;
+	return kFrame_Undefined;
 }
 
-void parse_scaling_option(const String &scaling_option, GameFrameSetup &frame_setup) {
-	parse_scaling_option(scaling_option, frame_setup.ScaleDef, frame_setup.ScaleFactor);
+FrameScaleDef parse_legacy_scaling_option(const String &option, int &scale) {
+	FrameScaleDef frame = parse_scaling_option(option);
+	if (frame == kFrame_Undefined) {
+		scale = StrUtil::StringToInt(option);
+		return scale > 0 ? kFrame_Round : kFrame_Undefined;
+	}
+	return frame;
 }
 
 // Parses legacy filter ID and converts it into current scaling options
-bool parse_legacy_frame_config(const String &scaling_option, String &filter_id, GameFrameSetup &frame) {
+bool parse_legacy_frame_config(const String &scaling_option, String &filter_id,
+	FrameScaleDef &frame, int &scale_factor) {
 	struct {
 		String LegacyName;
 		String CurrentName;
 		int    Scaling;
 	} legacy_filters[6] = { {"none", "none", -1}, {"max", "StdScale", 0}, {"StdScale", "StdScale", -1},
-		{"AAx", "Linear", -1}, {"Hq2x", "Hqx", 2}, {"Hq3x", "Hqx", 3}
-	};
+						   {"AAx", "Linear", -1}, {"Hq2x", "Hqx", 2}, {"Hq3x", "Hqx", 3} };
 
 	for (int i = 0; i < 6; i++) {
 		if (scaling_option.CompareLeftNoCase(legacy_filters[i].LegacyName) == 0) {
 			filter_id = legacy_filters[i].CurrentName;
-			frame.ScaleDef = legacy_filters[i].Scaling == 0 ? kFrame_MaxRound : kFrame_IntScale;
-			frame.ScaleFactor = legacy_filters[i].Scaling >= 0 ? legacy_filters[i].Scaling :
-			                    scaling_option.Mid(legacy_filters[i].LegacyName.GetLength()).ToInt();
+			frame = kFrame_Round;
+			scale_factor = legacy_filters[i].Scaling >= 0 ? legacy_filters[i].Scaling :
+				scaling_option.Mid(legacy_filters[i].LegacyName.GetLength()).ToInt();
 			return true;
 		}
 	}
 	return false;
 }
 
-String make_scaling_option(FrameScaleDefinition scale_def, int scale_factor) {
+String make_scaling_option(FrameScaleDef scale_def) {
 	switch (scale_def) {
-	case kFrame_MaxRound:
-		return "max_round";
-	case kFrame_MaxStretch:
+	case kFrame_Stretch:
 		return "stretch";
-	case kFrame_MaxProportional:
+	case kFrame_Proportional:
 		return "proportional";
 	default:
-		break;
+		return "round";
 	}
-	return String::FromFormat("%d", scale_factor);
-}
-
-String make_scaling_option(const GameFrameSetup &frame_setup) {
-	return make_scaling_option(frame_setup.ScaleDef, frame_setup.ScaleFactor);
 }
 
 uint32_t convert_scaling_to_fp(int scale_factor) {
@@ -177,19 +169,19 @@ int convert_fp_to_scaling(uint32_t scaling) {
 	return scaling >= kUnit ? (scaling >> kShift) : -kUnit / (int32_t)scaling;
 }
 
-void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, GameFrameSetup &frame_setup) {
+void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, FrameScaleDef &frame) {
 	scsz_setup.Size = Size();
 	if (windowed) {
-		// For the windowed we define mode by the scaled _GP(game).
+		// For the windowed we define mode by the scaled game.
 		scsz_setup.SizeDef = kScreenDef_ByGameScaling;
 		scsz_setup.MatchDeviceRatio = false;
-		frame_setup = _GP(usetup).Screen.WinGameFrame;
+		frame = _GP(usetup).Screen.WinGameFrame;
 	} else {
 		// For the fullscreen we set current desktop resolution, which
 		// corresponds to most comfortable fullscreen mode for the driver.
 		scsz_setup.SizeDef = kScreenDef_MaxDisplay;
 		scsz_setup.MatchDeviceRatio = true;
-		frame_setup = _GP(usetup).Screen.FsGameFrame;
+		frame = _GP(usetup).Screen.FsGameFrame;
 	}
 }
 
@@ -220,11 +212,11 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 	int default_res = INIreadint(cfg, "misc", "defaultres", 0);
 	int screen_res = INIreadint(cfg, "misc", "screenres", 0);
 	if ((default_res == kGameResolution_320x200 ||
-	        default_res == kGameResolution_320x240) && screen_res > 0) {
+		default_res == kGameResolution_320x240) && screen_res > 0) {
 		_GP(usetup).override_upscale = true; // run low-res game in high-res mode
 	}
 
-	_GP(usetup).Screen.DisplayMode.Windowed = true; // INIreadint(cfg, "misc", "windowed") > 0;
+	_GP(usetup).Screen.DisplayMode.Windowed = INIreadint(cfg, "misc", "windowed") > 0;
 	_GP(usetup).Screen.DriverID = INIreadstring(cfg, "misc", "gfxdriver", _GP(usetup).Screen.DriverID);
 
 	{
@@ -233,28 +225,30 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 			// NOTE: legacy scaling config is applied only to windowed setting
 			if (_GP(usetup).Screen.DisplayMode.Windowed)
 				_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_ByGameScaling;
-			parse_legacy_frame_config(legacy_filter, _GP(usetup).Screen.Filter.ID, _GP(usetup).Screen.WinGameFrame);
+			int scale_factor; // FIXME
+			parse_legacy_frame_config(legacy_filter, _GP(usetup).Screen.Filter.ID, _GP(usetup).Screen.WinGameFrame,
+				scale_factor);
 
 			// AGS 3.2.1 and 3.3.0 aspect ratio preferences
 			if (!_GP(usetup).Screen.DisplayMode.Windowed) {
 				_GP(usetup).Screen.DisplayMode.ScreenSize.MatchDeviceRatio =
-				    (INIreadint(cfg, "misc", "sideborders") > 0 || INIreadint(cfg, "misc", "forceletterbox") > 0 ||
-				     INIreadint(cfg, "misc", "prefer_sideborders") > 0 || INIreadint(cfg, "misc", "prefer_letterbox") > 0);
+					(INIreadint(cfg, "misc", "sideborders") > 0 || INIreadint(cfg, "misc", "forceletterbox") > 0 ||
+						INIreadint(cfg, "misc", "prefer_sideborders") > 0 || INIreadint(cfg, "misc", "prefer_letterbox") > 0);
 			}
 		}
 
 		// AGS 3.4.0 - 3.4.1-rc uniform scaling option
 		String uniform_frame_scale = INIreadstring(cfg, "graphics", "game_scale");
 		if (!uniform_frame_scale.IsEmpty()) {
-			GameFrameSetup frame_setup;
-			parse_scaling_option(uniform_frame_scale, frame_setup);
-			_GP(usetup).Screen.FsGameFrame = frame_setup;
-			_GP(usetup).Screen.WinGameFrame = frame_setup;
+			int scale;
+			FrameScaleDef frame = parse_legacy_scaling_option(uniform_frame_scale, scale);
+			_GP(usetup).Screen.FsGameFrame = frame;
+			_GP(usetup).Screen.WinGameFrame = frame;
+		}
 		}
-	}
 
 	_GP(usetup).Screen.DisplayMode.RefreshRate = INIreadint(cfg, "misc", "refresh");
-}
+	}
 
 void override_config_ext(ConfigTree &cfg) {
 	// Mobile ports always run in fullscreen mode
@@ -310,7 +304,7 @@ void override_config_ext(ConfigTree &cfg) {
 
 	INIwriteint(cfg, "misc", "antialias", _G(psp_gfx_smooth_sprites) != 0);
 	INIwritestring(cfg, "language", "translation", _G(psp_translation));
-}
+	}
 
 void apply_config(const ConfigTree &cfg) {
 	{
@@ -323,21 +317,23 @@ void apply_config(const ConfigTree &cfg) {
 		// Graphics mode
 		_GP(usetup).Screen.DriverID = INIreadstring(cfg, "graphics", "driver", _GP(usetup).Screen.DriverID);
 
-		_GP(usetup).Screen.DisplayMode.Windowed = true; // INIreadint(cfg, "graphics", "windowed") > 0;
+		_GP(usetup).Screen.DisplayMode.Windowed = INIreadint(cfg, "graphics", "windowed") > 0;
 		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = _GP(usetup).Screen.DisplayMode.Windowed ? kScreenDef_ByGameScaling : kScreenDef_MaxDisplay;
 		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = parse_screendef(INIreadstring(cfg, "graphics", "screen_def"),
-		        _GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef);
+			_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef);
 
 		_GP(usetup).Screen.DisplayMode.ScreenSize.Size = Size(INIreadint(cfg, "graphics", "screen_width"),
-		        INIreadint(cfg, "graphics", "screen_height"));
+			INIreadint(cfg, "graphics", "screen_height"));
 		_GP(usetup).Screen.DisplayMode.ScreenSize.MatchDeviceRatio = INIreadint(cfg, "graphics", "match_device_ratio", 1) != 0;
 		// TODO: move to config overrides (replace values during config load)
 #if AGS_PLATFORM_OS_MACOS
 		_GP(usetup).Screen.Filter.ID = "none";
 #else
 		_GP(usetup).Screen.Filter.ID = INIreadstring(cfg, "graphics", "filter", "StdScale");
-		parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs", "proportional"), _GP(usetup).Screen.FsGameFrame);
-		parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win", "max_round"), _GP(usetup).Screen.WinGameFrame);
+		_GP(usetup).Screen.FsGameFrame =
+			parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs", "proportional"));
+		_GP(usetup).Screen.WinGameFrame =
+			parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win", "round"));
 #endif
 
 		_GP(usetup).Screen.DisplayMode.RefreshRate = INIreadint(cfg, "graphics", "refresh");
@@ -353,9 +349,7 @@ void apply_config(const ConfigTree &cfg) {
 		_GP(usetup).user_data_dir = INIreadstring(cfg, "misc", "user_data_dir");
 		_GP(usetup).shared_data_dir = INIreadstring(cfg, "misc", "shared_data_dir");
 
-		Common::String translation;
-		if (ConfMan.getActiveDomain()->tryGetVal("translation", translation) && !translation.empty())
-			_GP(usetup).translation = translation;
+		_GP(usetup).translation = INIreadstring(cfg, "language", "translation");
 
 		int cache_size_kb = INIreadint(cfg, "misc", "cachemax", DEFAULTCACHESIZE_KB);
 		if (cache_size_kb > 0)
@@ -413,11 +407,6 @@ void post_config() {
 	if (_GP(usetup).Screen.Filter.ID.IsEmpty() || _GP(usetup).Screen.Filter.ID.CompareNoCase("none") == 0) {
 		_GP(usetup).Screen.Filter.ID = "StdScale";
 	}
-
-	if (!_GP(usetup).Screen.FsGameFrame.IsValid())
-		_GP(usetup).Screen.FsGameFrame = GameFrameSetup(kFrame_MaxProportional);
-	if (!_GP(usetup).Screen.WinGameFrame.IsValid())
-		_GP(usetup).Screen.WinGameFrame = GameFrameSetup(kFrame_MaxRound);
 }
 
 void save_config_file() {
diff --git a/engines/ags/engine/main/config.h b/engines/ags/engine/main/config.h
index 6ea11c6280b..8aebc32baeb 100644
--- a/engines/ags/engine/main/config.h
+++ b/engines/ags/engine/main/config.h
@@ -48,15 +48,12 @@ void post_config();
 void save_config_file();
 
 ScreenSizeDefinition parse_screendef(const String &option, ScreenSizeDefinition def_value);
-void parse_scaling_option(const String &scaling_option, FrameScaleDefinition &scale_def, int &scale_factor);
-void parse_scaling_option(const String &scaling_option, GameFrameSetup &frame_setup);
-String make_scaling_option(FrameScaleDefinition scale_def, int scale_factor = 0);
-String make_scaling_option(const GameFrameSetup &frame_setup);
+FrameScaleDef parse_scaling_option(const String &option);
+String make_scaling_option(FrameScaleDef scale_def);
 uint32_t convert_scaling_to_fp(int scale_factor);
 int convert_fp_to_scaling(uint32_t scaling);
 // Fill in setup structs with default settings for the given mode (windowed or fullscreen)
-void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, GameFrameSetup &frame_setup);
-
+void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, FrameScaleDef &frame);
 
 bool INIreaditem(const ConfigTree &cfg, const String &sectn, const String &item, String &value);
 int INIreadint(const ConfigTree &cfg, const String &sectn, const String &item, int def_value = 0);
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 97e3be05b59..be8713cf393 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -1254,7 +1254,7 @@ bool engine_try_switch_windowed_gfxmode() {
 
 	// Keep previous mode in case we need to revert back
 	DisplayMode old_dm = _G(gfxDriver)->GetDisplayMode();
-	GameFrameSetup old_frame = graphics_mode_get_render_frame();
+	FrameScaleDef old_frame = graphics_mode_get_render_frame();
 
 	// Release engine resources that depend on display mode
 	engine_pre_gfxmode_release();
@@ -1263,7 +1263,7 @@ bool engine_try_switch_windowed_gfxmode() {
 	bool switch_to_windowed = !old_dm.Windowed;
 	ActiveDisplaySetting setting = graphics_mode_get_last_setting(switch_to_windowed);
 	DisplayMode last_opposite_mode = setting.Dm;
-	GameFrameSetup use_frame_setup = setting.FrameSetup;
+	FrameScaleDef use_frame_setup = setting.Frame;
 
 	// If there are saved parameters for given mode (fullscreen/windowed)
 	// then use them, if there are not, get default setup for the new mode.
diff --git a/engines/ags/engine/main/graphics_mode.cpp b/engines/ags/engine/main/graphics_mode.cpp
index 49d65a5daaa..051dab4b7e1 100644
--- a/engines/ags/engine/main/graphics_mode.cpp
+++ b/engines/ags/engine/main/graphics_mode.cpp
@@ -49,20 +49,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-GameFrameSetup::GameFrameSetup()
-	: ScaleDef(kFrame_IntScale)
-	, ScaleFactor(1) {
-}
-
-GameFrameSetup::GameFrameSetup(FrameScaleDefinition def, int factor)
-	: ScaleDef(def)
-	, ScaleFactor(factor) {
-}
-
-bool GameFrameSetup::IsValid() const {
-	return ScaleDef != kFrame_IntScale || ScaleFactor > 0;
-}
-
 ScreenSizeSetup::ScreenSizeSetup()
 	: SizeDef(kScreenDef_MaxDisplay)
 	, MatchDeviceRatio(true) {
@@ -184,35 +170,36 @@ bool find_nearest_supported_mode(const IGfxModeList &modes, const Size &wanted_s
 	return false;
 }
 
-Size set_game_frame_after_screen_size(const Size &game_size, const Size screen_size, const GameFrameSetup &setup) {
+Size get_game_frame_from_screen_size(const Size &game_size, const Size screen_size,
+	const FrameScaleDef frame, int scale = 0) {
 	// Set game frame as native game resolution scaled by particular method
-	Size frame_size;
-	if (setup.ScaleDef == kFrame_MaxStretch) {
-		frame_size = screen_size;
-	} else if (setup.ScaleDef == kFrame_MaxProportional) {
-		frame_size = ProportionalStretch(screen_size, game_size);
-	} else {
-		int scale;
-		if (setup.ScaleDef == kFrame_MaxRound)
-			scale = Math::Min((screen_size.Width / game_size.Width) << kShift,
-			                  (screen_size.Height / game_size.Height) << kShift);
+	switch (frame) {
+	case kFrame_Stretch: return screen_size;
+	case kFrame_Proportional: return ProportionalStretch(screen_size, game_size);
+	case kFrame_Round: {
+		int fp_scale;
+		if (scale > 0)
+			fp_scale = convert_scaling_to_fp(scale);
 		else
-			scale = convert_scaling_to_fp(setup.ScaleFactor);
-
-		// Ensure scaling factors are sane
-		if (scale <= 0)
-			scale = kUnit;
-
-		frame_size = Size((game_size.Width * scale) >> kShift, (game_size.Height * scale) >> kShift);
+			fp_scale = Math::Max<int32_t>(kUnit,
+				Math::Min((screen_size.Width / game_size.Width) << kShift,
+				(screen_size.Height / game_size.Height) << kShift));
+		Size frame_size = Size(
+			(game_size.Width * fp_scale) >> kShift,
+			(game_size.Height * fp_scale) >> kShift);
 		// If the scaled game size appear larger than the screen,
 		// use "proportional stretch" method instead
 		if (frame_size.ExceedsByAny(screen_size))
 			frame_size = ProportionalStretch(screen_size, game_size);
+		return frame_size;
+	}
+	default:
+		break;
 	}
-	return frame_size;
+	return Size();
 }
 
-Size precalc_screen_size(const Size &game_size, const DisplayModeSetup &dm_setup, const GameFrameSetup &frame_setup) {
+Size precalc_screen_size(const Size &game_size, const DisplayModeSetup &dm_setup, const FrameScaleDef &frame) {
 #if AGS_PLATFORM_SCUMMVM
 	return game_size;
 #else
@@ -228,7 +215,7 @@ Size precalc_screen_size(const Size &game_size, const DisplayModeSetup &dm_setup
 		if (screen_size.IsNull()) {
 			// If the configuration did not define proper screen size,
 			// use the scaled game size instead
-			frame_size = set_game_frame_after_screen_size(game_size, device_size, frame_setup);
+			frame_size = set_game_frame_after_screen_size(game_size, device_size, frame);
 			if (screen_size.Width <= 0)
 				screen_size.Width = frame_size.Width;
 			if (screen_size.Height <= 0)
@@ -237,7 +224,7 @@ Size precalc_screen_size(const Size &game_size, const DisplayModeSetup &dm_setup
 		break;
 	case kScreenDef_ByGameScaling:
 		// Use game frame (scaled game) size
-		frame_size = set_game_frame_after_screen_size(game_size, device_size, frame_setup);
+		frame_size = set_game_frame_after_screen_size(game_size, device_size, frame);
 		screen_size = frame_size;
 		break;
 	case kScreenDef_MaxDisplay:
@@ -303,17 +290,17 @@ bool try_init_compatible_mode(const DisplayMode &dm, const bool match_device_rat
 
 // Try to find and initialize compatible display mode as close to given setup as possible
 bool try_init_mode_using_setup(const GraphicResolution &game_res, const DisplayModeSetup &dm_setup,
-	const int col_depth, const GameFrameSetup &frame_setup,
+	const int col_depth, const FrameScaleDef &frame,
 	const GfxFilterSetup &filter_setup) {
 	// We determine the requested size of the screen using setup options
-	const Size screen_size = precalc_screen_size(game_res, dm_setup, frame_setup);
+	const Size screen_size = precalc_screen_size(game_res, dm_setup, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, col_depth),
 		dm_setup.Windowed, dm_setup.RefreshRate, dm_setup.VSync);
 	if (!try_init_compatible_mode(dm, dm_setup.ScreenSize.SizeDef == kScreenDef_Explicit ? false : dm_setup.ScreenSize.MatchDeviceRatio))
 		return false;
 
 	// Set up native size and render frame
-	if (!graphics_mode_set_native_res(game_res) || !graphics_mode_set_render_frame(frame_setup))
+	if (!graphics_mode_set_native_res(game_res) || !graphics_mode_set_render_frame(frame))
 		return false;
 
 	// Set up graphics filter
@@ -354,7 +341,7 @@ void log_out_driver_modes(const int color_depth) {
 bool create_gfx_driver_and_init_mode_any(const String &gfx_driver_id,
 	const GraphicResolution &game_res,
 	const DisplayModeSetup &dm_setup, const ColorDepthOption &color_depth,
-	const GameFrameSetup &frame_setup, const GfxFilterSetup &filter_setup) {
+	const FrameScaleDef &frame, const GfxFilterSetup &filter_setup) {
 	if (!graphics_mode_create_renderer(gfx_driver_id))
 		return false;
 
@@ -363,15 +350,15 @@ bool create_gfx_driver_and_init_mode_any(const String &gfx_driver_id,
 	// Log out supported driver modes
 	log_out_driver_modes(use_col_depth);
 
-	bool result = try_init_mode_using_setup(game_res, dm_setup, use_col_depth, frame_setup, filter_setup);
+	bool result = try_init_mode_using_setup(game_res, dm_setup, use_col_depth, frame, filter_setup);
 	// Try windowed mode if fullscreen failed, and vice versa
 	if (!result && _G(editor_debugging_enabled) == 0) {
 		// we need to clone from initial config, because not every parameter is set by graphics_mode_get_defaults()
 		DisplayModeSetup dm_setup_alt = dm_setup;
 		dm_setup_alt.Windowed = !dm_setup.Windowed;
-		GameFrameSetup frame_setup_alt;
-		graphics_mode_get_defaults(dm_setup_alt.Windowed, dm_setup_alt.ScreenSize, frame_setup_alt);
-		result = try_init_mode_using_setup(game_res, dm_setup_alt, use_col_depth, frame_setup_alt, filter_setup);
+		FrameScaleDef frame_alt;
+		graphics_mode_get_defaults(dm_setup_alt.Windowed, dm_setup_alt.ScreenSize, frame_alt);
+		result = try_init_mode_using_setup(game_res, dm_setup_alt, use_col_depth, frame_alt, filter_setup);
 	}
 	return result;
 }
@@ -380,7 +367,7 @@ bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
 	const GraphicResolution &game_res,
 	const DisplayModeSetup &dm_setup,
 	const ColorDepthOption &color_depth,
-	const GameFrameSetup &frame_setup,
+	const FrameScaleDef &frame,
 	const GfxFilterSetup &filter_setup) {
 	if (!graphics_mode_create_renderer(gfx_driver_id)) {
 		return false;
@@ -397,7 +384,7 @@ bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
 	if (!graphics_mode_set_native_res(dm)) {
 		return false;
 	}
-	if (!graphics_mode_set_render_frame(frame_setup)) {
+	if (!graphics_mode_set_render_frame(frame)) {
 		return false;
 	}
 	if (!graphics_mode_set_filter_any(filter_setup)) {
@@ -438,7 +425,7 @@ bool graphics_mode_init_any(const GraphicResolution &game_res, const ScreenSetup
 	const char *screen_sz_def_options[kNumScreenDef] = { "explicit", "scaling", "max" };
 	ScreenSizeSetup scsz = setup.DisplayMode.ScreenSize;
 	const bool ignore_device_ratio = setup.DisplayMode.Windowed || scsz.SizeDef == kScreenDef_Explicit;
-	GameFrameSetup gameframe = setup.DisplayMode.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
+	FrameScaleDef gameframe = setup.DisplayMode.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
 	const String scale_option = make_scaling_option(gameframe);
 	Debug::Printf(kDbgMsg_Info, "Graphic settings: driver: %s, windowed: %s, screen def: %s, screen size: %d x %d, match device ratio: %s, game scale: %s",
 	              setup.DriverID.GetCStr(),
@@ -498,9 +485,9 @@ bool graphics_mode_create_renderer(const String &driver_id) {
 }
 
 bool graphics_mode_set_dm_any(const Size &game_size, const DisplayModeSetup &dm_setup,
-                              const ColorDepthOption &color_depth, const GameFrameSetup &frame_setup) {
+                              const ColorDepthOption &color_depth, const FrameScaleDef &frame) {
 	// We determine the requested size of the screen using setup options
-	const Size screen_size = precalc_screen_size(game_size, dm_setup, frame_setup);
+	const Size screen_size = precalc_screen_size(game_size, dm_setup, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, color_depth.Bits),
 	               dm_setup.Windowed, dm_setup.RefreshRate, dm_setup.VSync);
 	return try_init_compatible_mode(dm, dm_setup.ScreenSize.MatchDeviceRatio);
@@ -536,7 +523,7 @@ bool graphics_mode_update_render_frame() {
 	DisplayMode dm = _G(gfxDriver)->GetDisplayMode();
 	Size screen_size = Size(dm.Width, dm.Height);
 	Size native_size = _G(gfxDriver)->GetNativeSize();
-	Size frame_size = set_game_frame_after_screen_size(native_size, screen_size, _GP(CurFrameSetup));
+	Size frame_size = get_game_frame_from_screen_size(native_size, screen_size, _G(CurFrameSetup));
 	Rect render_frame = CenterInRect(RectWH(screen_size), RectWH(frame_size));
 
 	if (!_G(gfxDriver)->SetRenderFrame(render_frame)) {
@@ -565,18 +552,18 @@ bool graphics_mode_set_native_res(const GraphicResolution &native_res) {
 	return true;
 }
 
-GameFrameSetup graphics_mode_get_render_frame() {
-	return _GP(CurFrameSetup);
+FrameScaleDef graphics_mode_get_render_frame() {
+	return _G(CurFrameSetup);
 }
 
-bool graphics_mode_set_render_frame(const GameFrameSetup &frame_setup) {
-	if (!frame_setup.IsValid())
+bool graphics_mode_set_render_frame(const FrameScaleDef &frame) {
+	if (frame < 0 || frame >= kNumFrameScaleDef)
 		return false;
-	_GP(CurFrameSetup) = frame_setup;
+	_G(CurFrameSetup) = frame;
 	if (_G(gfxDriver)->GetDisplayMode().Windowed)
-		_GP(SavedWindowedSetting).FrameSetup = frame_setup;
+		_GP(SavedWindowedSetting).Frame = frame;
 	else
-		_GP(SavedFullscreenSetting).FrameSetup = frame_setup;
+		_GP(SavedWindowedSetting).Frame = frame;
 	graphics_mode_update_render_frame();
 	return true;
 }
diff --git a/engines/ags/engine/main/graphics_mode.h b/engines/ags/engine/main/graphics_mode.h
index 533f4e685a0..a124276f7e0 100644
--- a/engines/ags/engine/main/graphics_mode.h
+++ b/engines/ags/engine/main/graphics_mode.h
@@ -34,7 +34,6 @@ using AGS::Engine::GraphicResolution;
 using AGS::Engine::DisplayMode;
 
 Size get_desktop_size();
-String make_scaling_factor_string(uint32_t scaling);
 
 namespace AGS {
 namespace Engine {
@@ -52,24 +51,15 @@ struct GfxFilterSetup {
 	String UserRequest; // filter name, requested by user
 };
 
-enum FrameScaleDefinition {
-	kFrame_IntScale,        // explicit integer scaling x/y factors
-	kFrame_MaxRound,        // calculate max round uniform scaling factor
-	kFrame_MaxStretch,      // resize to maximal possible inside the display box
-	kFrame_MaxProportional, // same as stretch, but keep game's aspect ratio
+// Defines how game frame is scaled inside a larger window
+enum FrameScaleDef {
+	kFrame_Undefined = -1,
+	kFrame_Round,        // max round (integer) scaling factor
+	kFrame_Stretch,      // resize to maximal possible inside the display box
+	kFrame_Proportional, // same as stretch, but keep game's aspect ratio
 	kNumFrameScaleDef
 };
 
-// Game frame configuration
-struct GameFrameSetup {
-	FrameScaleDefinition ScaleDef;    // a method used to determine game frame scaling
-	int                  ScaleFactor; // explicit scale factor
-
-	GameFrameSetup();
-	GameFrameSetup(FrameScaleDefinition def, int factor = 0);
-	bool IsValid() const;
-};
-
 enum ScreenSizeDefinition {
 	kScreenDef_Explicit,        // define by width & height
 	kScreenDef_ByGameScaling,   // define by game scale factor
@@ -105,8 +95,8 @@ struct ScreenSetup {
 	// Definitions for the fullscreen and windowed scaling methods.
 	// When the initial display mode is set, corresponding scaling method from this pair is used.
 	// The second method is meant to be saved and used if display mode is switched at runtime.
-	GameFrameSetup       FsGameFrame;   // how the game frame should be scaled/positioned in fullscreen mode
-	GameFrameSetup       WinGameFrame;  // how the game frame should be scaled/positioned in windowed mode
+	FrameScaleDef       FsGameFrame;   // how the game frame should be scaled/positioned in fullscreen mode
+	FrameScaleDef       WinGameFrame;  // how the game frame should be scaled/positioned in windowed mode
 
 	GfxFilterSetup       Filter;        // graphics filter definition
 };
@@ -122,11 +112,11 @@ struct ColorDepthOption {
 	}
 };
 
-// ActiveDisplaySetting struct merges DisplayMode and GameFrameSetup,
+// ActiveDisplaySetting struct merges DisplayMode and FrameScaleDef,
 // which is useful if you need to save active settings and reapply them later.
 struct ActiveDisplaySetting {
 	DisplayMode     Dm;
-	GameFrameSetup  FrameSetup;
+	FrameScaleDef  Frame;
 };
 
 // Initializes any possible gfx mode, using user config as a recommendation;
@@ -138,15 +128,15 @@ ActiveDisplaySetting graphics_mode_get_last_setting(bool windowed);
 bool graphics_mode_create_renderer(const String &driver_id);
 // Try to find and initialize compatible display mode as close to given setup as possible
 bool graphics_mode_set_dm_any(const Size &game_size, const DisplayModeSetup &dm_setup,
-                              const ColorDepthOption &color_depth, const GameFrameSetup &frame_setup);
+                              const ColorDepthOption &color_depth, const FrameScaleDef &frame_setup);
 // Set the display mode with given parameters
 bool graphics_mode_set_dm(const AGS::Engine::DisplayMode &dm);
 // Set the native image size
 bool graphics_mode_set_native_res(const GraphicResolution &native_res);
 // Get current render frame setup
-GameFrameSetup graphics_mode_get_render_frame();
+FrameScaleDef graphics_mode_get_render_frame();
 // Set the render frame position inside the window
-bool graphics_mode_set_render_frame(const GameFrameSetup &frame_setup);
+bool graphics_mode_set_render_frame(const FrameScaleDef &frame_setup);
 // Set requested graphics filter, or default filter if the requested one failed
 bool graphics_mode_set_filter_any(const GfxFilterSetup &setup);
 // Set the scaling filter with given ID
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 903dc00807e..b160bb3aabc 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -259,7 +259,6 @@ Globals::Globals() {
 	// graphics_mode.cpp globals
 	_SavedFullscreenSetting = new ActiveDisplaySetting();
 	_SavedWindowedSetting = new ActiveDisplaySetting();
-	_CurFrameSetup = new GameFrameSetup();
 	_GameScaling = new AGS::Shared::PlaneScaling();
 
 	// gui_button.cpp globals
@@ -505,7 +504,6 @@ Globals::~Globals() {
 	// graphics_mode.cpp globals
 	delete _SavedFullscreenSetting;
 	delete _SavedWindowedSetting;
-	delete _CurFrameSetup;
 	delete _GameScaling;
 
 	// gui_button.cpp globals
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 169904b8de1..2f8dcbe4ab0 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -35,6 +35,7 @@
 #include "ags/engine/ac/runtime_defines.h"
 #include "ags/engine/ac/walk_behind.h"
 #include "ags/engine/main/engine.h"
+#include "ags/engine/main/graphics_mode.h"
 #include "ags/engine/media/audio/audio_defines.h"
 #include "ags/engine/script/script.h"
 #include "ags/engine/script/script_runtime.h"
@@ -135,7 +136,6 @@ struct DirtyRects;
 struct EnginePlugin;
 struct ExecutingScript;
 struct EventHappened;
-struct GameFrameSetup;
 struct GameSetup;
 struct GameSetupStruct;
 struct GameState;
@@ -900,7 +900,7 @@ public:
 	ActiveDisplaySetting *_SavedFullscreenSetting;
 	ActiveDisplaySetting *_SavedWindowedSetting;
 	// Current frame scaling setup
-	GameFrameSetup *_CurFrameSetup;
+	FrameScaleDef _CurFrameSetup = kFrame_Undefined;
 	// The game-to-screen transformation
 	AGS::Shared::PlaneScaling *_GameScaling;
 




More information about the Scummvm-git-logs mailing list