[Scummvm-git-logs] scummvm master -> 83c785cf226e3ecb57185dba4808b1d1676f45ec
dreammaster
noreply at scummvm.org
Mon Mar 21 05:14:02 UTC 2022
This automated email contains information about 9 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
a69197bbe0 AGS: Implemented support for opening assets for reading in script
c09781e98e AGS: Removed redundant file mode params from AssetManager's methods
189af0707d AGS: Implement bitmap loading for passed PACKFILE
a57df48467 AGS: DynamicSprite.CreateFromFile supports $DATA$ path token
b61a661907 AGS: Removed redundant asset_size param from AssetManager::OpenAsset
ca7ae36fe4 AGS: Removed FindAssetFileOnly(), was used for specific a workaround
a94d641150 AGS: AssetManager lets use AssetPath struct to call its methods
fff50e3735 AGS: Moved IsFile() and similar functions from Path to File unit
83c785cf22 AGS: Slightly more clear platform driver init/exit steps
Commit: a69197bbe0bf6e968b990f53ab79c89def02ea7c
https://github.com/scummvm/scummvm/commit/a69197bbe0bf6e968b990f53ab79c89def02ea7c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:53-07:00
Commit Message:
AGS: Implemented support for opening assets for reading in script
>From upstream e19d343b2d2cda2757d821532de195bd234f49f0
Changed paths:
engines/ags/engine/ac/file.cpp
engines/ags/engine/ac/global_dynamic_sprite.cpp
engines/ags/engine/ac/global_file.cpp
engines/ags/engine/ac/listbox.cpp
engines/ags/engine/ac/path_helper.h
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 03694cf23d1..7ca3dbb1891 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -206,6 +206,7 @@ const char *GameInstallRootToken = "$INSTALLDIR$";
const char *UserSavedgamesRootToken = "$MYDOCS$";
const char *GameSavedgamesDirToken = "$SAVEGAMEDIR$";
const char *GameDataDirToken = "$APPDATADIR$";
+const char *GameAssetToken = "$DATA$";
const char *UserConfigFileToken = "$CONFIGFILE$";
void FixupFilename(char *filename) {
@@ -283,18 +284,27 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
debugC(::AGS::kDebugFilePath, "ResolveScriptPath(%s)", orig_sc_path.GetCStr());
rp = ResolvedPath();
- bool is_absolute = !is_relative_filename(orig_sc_path.GetCStr());
- if (is_absolute && !read_only) {
- debug_script_warn("Attempt to access file '%s' denied (cannot write to absolute path)", orig_sc_path.GetCStr());
- return false;
- }
+ if (!Path::IsRelativePath(orig_sc_path)) {
+ if (!read_only) {
+ debug_script_warn("Attempt to access file '%s' denied (cannot write to absolute path)", orig_sc_path.GetCStr());
+ return false;
+ }
- if (is_absolute) {
rp = ResolvedPath(orig_sc_path);
return true;
}
String sc_path = orig_sc_path;
+ if (sc_path.CompareLeft(GameAssetToken, strlen(GameAssetToken)) == 0) {
+ if (!read_only) {
+ debug_script_warn("Attempt to access file '%s' denied (cannot write to game assets)", orig_sc_path.GetCStr());
+ return false;
+ }
+ rp.FullPath = sc_path.Mid(strlen(GameAssetToken) + 1);
+ rp.AssetMgr = true;
+ return true;
+ }
+
FSLocation parent_dir;
String child_path;
String alt_path;
diff --git a/engines/ags/engine/ac/global_dynamic_sprite.cpp b/engines/ags/engine/ac/global_dynamic_sprite.cpp
index bccc16e00cf..edaa3dfa1bd 100644
--- a/engines/ags/engine/ac/global_dynamic_sprite.cpp
+++ b/engines/ags/engine/ac/global_dynamic_sprite.cpp
@@ -38,6 +38,9 @@ int LoadImageFile(const char *filename) {
if (!ResolveScriptPath(filename, true, rp))
return 0;
+ // TODO: support loading from asset (stream);
+ // use PACKFILE / load_bmp_pf? Or read data and allocate bitmap struct ourselves
+
Bitmap *loadedFile = BitmapHelper::LoadFromFile(rp.FullPath);
if (!loadedFile && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
loadedFile = BitmapHelper::LoadFromFile(rp.AltPath);
diff --git a/engines/ags/engine/ac/global_file.cpp b/engines/ags/engine/ac/global_file.cpp
index 3dfe008340f..f8057878630 100644
--- a/engines/ags/engine/ac/global_file.cpp
+++ b/engines/ags/engine/ac/global_file.cpp
@@ -26,9 +26,11 @@
#include "ags/engine/ac/runtime_defines.h"
#include "ags/engine/ac/string.h"
#include "ags/engine/debugging/debug_log.h"
+#include "ags/shared/core/asset_manager.h"
#include "ags/shared/util/directory.h"
#include "ags/shared/util/path.h"
#include "ags/shared/util/stream.h"
+#include "ags/globals.h"
namespace AGS3 {
@@ -78,9 +80,14 @@ int32_t FileOpen(const char *fnmm, Shared::FileOpenMode open_mode, Shared::FileW
return 0;
}
- Stream *s = File::OpenFile(rp.FullPath, open_mode, work_mode);
- if (!s && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
- s = File::OpenFile(rp.AltPath, open_mode, work_mode);
+ Stream *s;
+ if (rp.AssetMgr) {
+ s = _GP(AssetMgr)->OpenAsset(rp.FullPath, nullptr, open_mode, work_mode);
+ } else {
+ s = File::OpenFile(rp.FullPath, open_mode, work_mode);
+ if (!s && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
+ s = File::OpenFile(rp.AltPath, open_mode, work_mode);
+ }
valid_handles[useindx].stream = s;
if (valid_handles[useindx].stream == nullptr)
diff --git a/engines/ags/engine/ac/listbox.cpp b/engines/ags/engine/ac/listbox.cpp
index a88f3bbf9b3..651f01a770d 100644
--- a/engines/ags/engine/ac/listbox.cpp
+++ b/engines/ags/engine/ac/listbox.cpp
@@ -108,6 +108,8 @@ void ListBox_FillDirList(GUIListBox *listbox, const char *filemask) {
if (!ResolveScriptPath(filemask, true, rp))
return;
+ // TODO: support listing assets from AssetMgr
+
std::set<String> files;
FillDirList(files, rp.FullPath);
if (!rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
diff --git a/engines/ags/engine/ac/path_helper.h b/engines/ags/engine/ac/path_helper.h
index ec0a758b481..399372b81f1 100644
--- a/engines/ags/engine/ac/path_helper.h
+++ b/engines/ags/engine/ac/path_helper.h
@@ -86,6 +86,7 @@ struct ResolvedPath {
FSLocation Loc; // location (directory)
String FullPath; // full path, including filename
String AltPath; // alternative read-only full path, for backwards compatibility
+ bool AssetMgr = false; // file is to be accessed through the asset manager
ResolvedPath() = default;
ResolvedPath(const String & file, const String & alt = "")
: FullPath(file), AltPath(alt) {
Commit: c09781e98eb31257d72d9190a3022ef9aa80dbc0
https://github.com/scummvm/scummvm/commit/c09781e98eb31257d72d9190a3022ef9aa80dbc0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:54-07:00
Commit Message:
AGS: Removed redundant file mode params from AssetManager's methods
>From upstream d07278a40d4374767fe10cd736475f41c843f10e
Changed paths:
engines/ags/engine/ac/file.cpp
engines/ags/engine/ac/global_file.cpp
engines/ags/shared/core/asset_manager.cpp
engines/ags/shared/core/asset_manager.h
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 7ca3dbb1891..d90bd20f8f8 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -62,6 +62,9 @@ int File_Exists(const char *fnmm) {
if (!ResolveScriptPath(fnmm, true, rp))
return 0;
+ if (rp.AssetMgr)
+ return _GP(AssetMgr)->DoesAssetExist(rp.FullPath);
+
return (File::TestReadFile(rp.FullPath) || File::TestReadFile(rp.AltPath)) ? 1 : 0;
}
diff --git a/engines/ags/engine/ac/global_file.cpp b/engines/ags/engine/ac/global_file.cpp
index f8057878630..ca55dbdf902 100644
--- a/engines/ags/engine/ac/global_file.cpp
+++ b/engines/ags/engine/ac/global_file.cpp
@@ -82,7 +82,7 @@ int32_t FileOpen(const char *fnmm, Shared::FileOpenMode open_mode, Shared::FileW
Stream *s;
if (rp.AssetMgr) {
- s = _GP(AssetMgr)->OpenAsset(rp.FullPath, nullptr, open_mode, work_mode);
+ s = _GP(AssetMgr)->OpenAsset(rp.FullPath, nullptr);
} else {
s = File::OpenFile(rp.FullPath, open_mode, work_mode);
if (!s && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
diff --git a/engines/ags/shared/core/asset_manager.cpp b/engines/ags/shared/core/asset_manager.cpp
index 9506749d928..0b640cf39e8 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -154,12 +154,12 @@ const AssetLibInfo *AssetManager::GetLibraryInfo(size_t index) const {
}
bool AssetManager::DoesAssetExist(const String &asset_name, const String &filter) const {
- return GetAsset(asset_name, filter, false, nullptr, Shared::kFile_Open, Shared::kFile_Read);
+ return GetAsset(asset_name, filter, false, nullptr);
}
String AssetManager::FindAssetFileOnly(const String &asset_name, const String &filter) const {
AssetLocation loc;
- if (GetAsset(asset_name, filter, true, &loc, Shared::kFile_Open, Shared::kFile_Read))
+ if (GetAsset(asset_name, filter, true, &loc))
return loc.FileName;
return "";
}
@@ -199,8 +199,8 @@ AssetError AssetManager::RegisterAssetLib(const String &path, AssetLibEx *&out_l
return kAssetNoError;
}
-bool AssetManager::GetAsset(const String &asset_name, const String &filter, bool dir_only,
- AssetLocation *loc, FileOpenMode open_mode, FileWorkMode work_mode) const {
+bool AssetManager::GetAsset(const String &asset_name, const String &filter,
+ bool dir_only, AssetLocation *loc) const {
for (const auto *lib : _activeLibs) {
auto match = std::find(lib->Filters.begin(), lib->Filters.end(), filter);
if (match == lib->Filters.end())
@@ -208,9 +208,9 @@ bool AssetManager::GetAsset(const String &asset_name, const String &filter, bool
bool found = false;
if (IsAssetLibDir(lib))
- found = GetAssetFromDir(lib, asset_name, loc, open_mode, work_mode);
+ found = GetAssetFromDir(lib, asset_name, loc);
else if (!dir_only)
- found = GetAssetFromLib(lib, asset_name, loc, open_mode, work_mode);
+ found = GetAssetFromLib(lib, asset_name, loc);
if (found)
return true;
}
@@ -218,10 +218,7 @@ bool AssetManager::GetAsset(const String &asset_name, const String &filter, bool
}
bool AssetManager::GetAssetFromLib(const AssetLibInfo *lib, const String &asset_name,
- AssetLocation *loc, FileOpenMode open_mode, FileWorkMode work_mode) const {
- if (open_mode != Shared::kFile_Open || work_mode != Shared::kFile_Read)
- return false; // creating/writing is allowed only for common files on disk
-
+ AssetLocation *loc) const {
const AssetInfo *asset = nullptr;
for (const auto &a : lib->AssetInfos) {
if (a.FileName.CompareNoCase(asset_name) == 0) {
@@ -244,7 +241,7 @@ bool AssetManager::GetAssetFromLib(const AssetLibInfo *lib, const String &asset_
}
bool AssetManager::GetAssetFromDir(const AssetLibInfo *lib, const String &file_name,
- AssetLocation *loc, FileOpenMode open_mode, FileWorkMode work_mode) const {
+ AssetLocation *loc) const {
String found_file = File::FindFileCI(lib->BaseDir, file_name);
if (found_file.IsEmpty() || !Path::IsFile(found_file))
return false; // not found, or not a file
@@ -257,16 +254,14 @@ bool AssetManager::GetAssetFromDir(const AssetLibInfo *lib, const String &file_n
return true;
}
-Stream *AssetManager::OpenAsset(const String &asset_name, soff_t *asset_size, FileOpenMode open_mode, FileWorkMode work_mode) const {
- return OpenAsset(asset_name, "", asset_size, open_mode, work_mode);
+Stream *AssetManager::OpenAsset(const String &asset_name, soff_t *asset_size) const {
+ return OpenAsset(asset_name, "", asset_size);
}
-Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter, soff_t *asset_size, FileOpenMode open_mode, FileWorkMode work_mode) const {
+Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter, soff_t *asset_size) const {
AssetLocation loc;
- if (GetAsset(asset_name, filter, false, &loc, open_mode, work_mode)) {
- Stream *s = work_mode == kFile_Read ?
- File::OpenFile(loc.FileName, loc.Offset, loc.Offset + loc.Size) :
- File::OpenFile(loc.FileName, open_mode, work_mode);
+ if (GetAsset(asset_name, filter, false, &loc)) {
+ Stream *s = File::OpenFile(loc.FileName, loc.Offset, loc.Offset + loc.Size);
if (s) {
if (asset_size)
*asset_size = loc.Size;
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index bddcf61a950..ca0ca6276d3 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -108,13 +108,9 @@ public:
String FindAssetFileOnly(const String &asset_name, 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, soff_t *asset_size = nullptr,
- FileOpenMode open_mode = kFile_Open,
- FileWorkMode work_mode = kFile_Read) const;
+ Stream *OpenAsset(const String &asset_name, soff_t *asset_size = nullptr) const;
// Open asset stream, providing a single filter to search in matching libraries
- Stream *OpenAsset(const String &asset_name, const String &filter, soff_t *asset_size = nullptr,
- FileOpenMode open_mode = kFile_Open,
- FileWorkMode work_mode = kFile_Read) const;
+ Stream *OpenAsset(const String &asset_name, const String &filter, soff_t *asset_size = nullptr) 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
Common::SeekableReadStream *OpenAssetStream(const String &asset_name) const;
@@ -130,9 +126,9 @@ 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
- bool GetAsset(const String &asset_name, const String &filter, bool dir_only, AssetLocation *loc, Shared::FileOpenMode open_mode, Shared::FileWorkMode work_mode) const;
- bool GetAssetFromLib(const AssetLibInfo *lib, const String &asset_name, AssetLocation *loc, Shared::FileOpenMode open_mode, Shared::FileWorkMode work_mode) const;
- bool GetAssetFromDir(const AssetLibInfo *lib, const String &asset_name, AssetLocation *loc, Shared::FileOpenMode open_mode, Shared::FileWorkMode work_mode) const;
+ bool GetAsset(const String &asset_name, const String &filter, bool dir_only, 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;
std::vector<AssetLibEx *> _libs;
std::vector<AssetLibEx *> _activeLibs;
Commit: 189af0707d52320360d22faae482a5d2c2c7d5f6
https://github.com/scummvm/scummvm/commit/189af0707d52320360d22faae482a5d2c2c7d5f6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:54-07:00
Commit Message:
AGS: Implement bitmap loading for passed PACKFILE
This is needed for an upstream commit that adds loading
images via a passed PACKFILE
Changed paths:
engines/ags/shared/gfx/image.cpp
engines/ags/shared/gfx/image.h
engines/ags/shared/util/stream.h
diff --git a/engines/ags/shared/gfx/image.cpp b/engines/ags/shared/gfx/image.cpp
index 828d38cb097..35d4e381e4b 100644
--- a/engines/ags/shared/gfx/image.cpp
+++ b/engines/ags/shared/gfx/image.cpp
@@ -37,15 +37,10 @@
namespace AGS3 {
template<class DECODER>
-BITMAP *decodeImage(const char *filename, color *pal) {
+BITMAP *decodeImageStream(Common::SeekableReadStream &stream, color *pal) {
DECODER decoder;
- AGS::Shared::Stream *file = AGS3::AGS::Shared::File::OpenFileRead(filename);
- if (!file)
- return nullptr;
-
- AGS::Shared::ScummVMReadStream f(file);
- if (decoder.loadStream(f)) {
+ if (decoder.loadStream(stream)) {
// Create the output surface
const Graphics::Surface *src = decoder.getSurface();
@@ -70,6 +65,26 @@ BITMAP *decodeImage(const char *filename, color *pal) {
}
}
+template<class DECODER>
+BITMAP *decodeImage(const char *filename, color *pal) {
+ AGS::Shared::Stream *file = AGS3::AGS::Shared::File::OpenFileRead(filename);
+ if (!file)
+ return nullptr;
+
+ AGS::Shared::ScummVMReadStream f(file);
+ return decodeImageStream<DECODER>(f, pal);
+}
+
+template<class DECODER>
+BITMAP *decodeImage(PACKFILE *pf, color *pal) {
+ if (!pf)
+ return nullptr;
+
+ AGS::Shared::ScummVMPackReadStream f(pf);
+ f.seek(0);
+ return decodeImageStream<DECODER>(f, pal);
+}
+
BITMAP *load_bmp(const char *filename, color *pal) {
return decodeImage<Image::BitmapDecoder>(filename, pal);
}
@@ -101,6 +116,21 @@ BITMAP *load_bitmap(const char *filename, color *pal) {
error("Unknown image file - %s", filename);
}
+BITMAP *load_bitmap(PACKFILE *pf, color *pal) {
+ BITMAP *result;
+
+ if ((result = decodeImage<Image::BitmapDecoder>(pf, pal)) != nullptr)
+ return result;
+ if ((result = decodeImage<Image::IFFDecoder>(pf, pal)) != nullptr)
+ return result;
+ if ((result = decodeImage<Image::PCXDecoder>(pf, pal)) != nullptr)
+ return result;
+ if ((result = decodeImage<Image::TGADecoder>(pf, pal)) != nullptr)
+ return result;
+
+ error("Unknown image file");
+}
+
int save_bitmap(Common::WriteStream &out, BITMAP *bmp, const RGB *pal) {
#ifdef SCUMM_LITTLE_ENDIAN
const Graphics::PixelFormat requiredFormat_3byte(3, 8, 8, 8, 0, 16, 8, 0, 0);
diff --git a/engines/ags/shared/gfx/image.h b/engines/ags/shared/gfx/image.h
index d2031d5c6e0..22aa3c70b48 100644
--- a/engines/ags/shared/gfx/image.h
+++ b/engines/ags/shared/gfx/image.h
@@ -26,13 +26,16 @@
namespace AGS3 {
-BITMAP *load_bitmap(const char *filename, color *pal);
-BITMAP *load_bmp(const char *filename, color *pal);
-BITMAP *load_lbm(const char *filename, color *pal);
-BITMAP *load_pcx(const char *filename, color *pal);
-BITMAP *load_tga(const char *filename, color *pal);
+struct PACKFILE;
-int save_bitmap(Common::WriteStream &out, BITMAP *bmp, const RGB *pal);
+extern BITMAP *load_bitmap(PACKFILE *pf, color *pal);
+extern BITMAP *load_bitmap(const char *filename, color *pal);
+extern BITMAP *load_bmp(const char *filename, color *pal);
+extern BITMAP *load_lbm(const char *filename, color *pal);
+extern BITMAP *load_pcx(const char *filename, color *pal);
+extern BITMAP *load_tga(const char *filename, color *pal);
+
+extern int save_bitmap(Common::WriteStream &out, BITMAP *bmp, const RGB *pal);
} // namespace AGS3
diff --git a/engines/ags/shared/util/stream.h b/engines/ags/shared/util/stream.h
index 7cb1f1560f7..cd322903e89 100644
--- a/engines/ags/shared/util/stream.h
+++ b/engines/ags/shared/util/stream.h
@@ -35,6 +35,7 @@
#define AGS_SHARED_UTIL_STREAM_H
#include "ags/shared/api/stream_api.h"
+#include "ags/lib/allegro/file.h"
#include "common/stream.h"
#include "common/types.h"
@@ -132,6 +133,41 @@ public:
}
};
+
+class ScummVMPackReadStream : public Common::SeekableReadStream {
+private:
+ PACKFILE *_file;
+ DisposeAfterUse::Flag _disposeAfterUse;
+public:
+ ScummVMPackReadStream(PACKFILE *src, DisposeAfterUse::Flag disposeAfterUse =
+ DisposeAfterUse::YES) : _file(src), _disposeAfterUse(disposeAfterUse) {
+ }
+ ~ScummVMPackReadStream() override {
+ if (_disposeAfterUse == DisposeAfterUse::YES)
+ delete _file;
+ }
+
+ bool eos() const override {
+ return _file->pack_feof();
+ }
+
+ uint32 read(void *dataPtr, uint32 dataSize) override {
+ return _file->pack_fread(dataPtr, dataSize);
+ }
+
+ int64 pos() const override {
+ error("Unsupported");
+ }
+
+ int64 size() const override {
+ error("Unsupported");
+ }
+
+ bool seek(int64 offset, int whence = SEEK_SET) override {
+ error("Unsupported");
+ }
+};
+
class StreamScummVMFile : public Stream {
private:
Common::SeekableReadStream *_stream;
Commit: a57df48467c9a9e31f67ffca6689ec81126d7f7b
https://github.com/scummvm/scummvm/commit/a57df48467c9a9e31f67ffca6689ec81126d7f7b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:54-07:00
Commit Message:
AGS: DynamicSprite.CreateFromFile supports $DATA$ path token
>From upstream 57954026cf10593210221dbf3a796c83fc26379d
Changed paths:
engines/ags/engine/ac/global_dynamic_sprite.cpp
engines/ags/shared/gfx/allegro_bitmap.cpp
engines/ags/shared/gfx/allegro_bitmap.h
engines/ags/shared/gfx/bitmap.cpp
engines/ags/shared/gfx/bitmap.h
diff --git a/engines/ags/engine/ac/global_dynamic_sprite.cpp b/engines/ags/engine/ac/global_dynamic_sprite.cpp
index edaa3dfa1bd..5af5235cfc7 100644
--- a/engines/ags/engine/ac/global_dynamic_sprite.cpp
+++ b/engines/ags/engine/ac/global_dynamic_sprite.cpp
@@ -20,6 +20,7 @@
*/
#include "ags/engine/ac/global_dynamic_sprite.h"
+#include "ags/engine/ac/asset_helper.h"
#include "ags/engine/ac/draw.h"
#include "ags/engine/ac/dynamic_sprite.h"
#include "ags/engine/ac/path_helper.h"
@@ -38,12 +39,19 @@ int LoadImageFile(const char *filename) {
if (!ResolveScriptPath(filename, true, rp))
return 0;
- // TODO: support loading from asset (stream);
- // use PACKFILE / load_bmp_pf? Or read data and allocate bitmap struct ourselves
+ Bitmap *loadedFile;
+ if (rp.AssetMgr) {
+ size_t asset_size;
+ PACKFILE *pf = PackfileFromAsset(rp.FullPath, asset_size);
+ if (!pf)
+ return 0;
+ loadedFile = BitmapHelper::LoadFromFile(pf);
+ } else {
+ loadedFile = BitmapHelper::LoadFromFile(rp.FullPath);
+ if (!loadedFile && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
+ loadedFile = BitmapHelper::LoadFromFile(rp.AltPath);
+ }
- Bitmap *loadedFile = BitmapHelper::LoadFromFile(rp.FullPath);
- if (!loadedFile && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
- loadedFile = BitmapHelper::LoadFromFile(rp.AltPath);
if (!loadedFile)
return 0;
diff --git a/engines/ags/shared/gfx/allegro_bitmap.cpp b/engines/ags/shared/gfx/allegro_bitmap.cpp
index 3ffd00e7a9f..7dae6eaad4a 100644
--- a/engines/ags/shared/gfx/allegro_bitmap.cpp
+++ b/engines/ags/shared/gfx/allegro_bitmap.cpp
@@ -134,6 +134,17 @@ bool Bitmap::LoadFromFile(const char *filename) {
return _alBitmap != nullptr;
}
+bool Bitmap::LoadFromFile(PACKFILE *pf) {
+ Destroy();
+
+ BITMAP *al_bmp = load_bitmap(pf, nullptr);
+ if (al_bmp) {
+ _alBitmap = al_bmp;
+ _isDataOwner = true;
+ }
+ return _alBitmap != nullptr;
+}
+
bool Bitmap::SaveToFile(Common::WriteStream &out, const void *palette) {
return save_bitmap(out, _alBitmap, (const RGB *)palette) == 0;
}
diff --git a/engines/ags/shared/gfx/allegro_bitmap.h b/engines/ags/shared/gfx/allegro_bitmap.h
index 18fab261b19..bc39b54049b 100644
--- a/engines/ags/shared/gfx/allegro_bitmap.h
+++ b/engines/ags/shared/gfx/allegro_bitmap.h
@@ -70,6 +70,7 @@ public:
return LoadFromFile(filename.GetCStr());
}
bool LoadFromFile(const char *filename);
+ bool LoadFromFile(PACKFILE *pf);
bool SaveToFile(const String &filename, const void *palette) {
return SaveToFile(filename.GetCStr(), palette);
}
diff --git a/engines/ags/shared/gfx/bitmap.cpp b/engines/ags/shared/gfx/bitmap.cpp
index 7360812309e..a4925aa6153 100644
--- a/engines/ags/shared/gfx/bitmap.cpp
+++ b/engines/ags/shared/gfx/bitmap.cpp
@@ -74,6 +74,15 @@ Bitmap *LoadFromFile(const char *filename) {
return bitmap;
}
+Bitmap *LoadFromFile(PACKFILE *pf) {
+ Bitmap *bitmap = new Bitmap();
+ if (!bitmap->LoadFromFile(pf)) {
+ delete bitmap;
+ bitmap = nullptr;
+ }
+ return bitmap;
+}
+
Bitmap *AdjustBitmapSize(Bitmap *src, int width, int height) {
int oldw = src->GetWidth(), oldh = src->GetHeight();
if ((oldw == width) && (oldh == height))
diff --git a/engines/ags/shared/gfx/bitmap.h b/engines/ags/shared/gfx/bitmap.h
index fc20d34b43b..9ce08b8ebfc 100644
--- a/engines/ags/shared/gfx/bitmap.h
+++ b/engines/ags/shared/gfx/bitmap.h
@@ -63,6 +63,7 @@ class Bitmap;
// TODO: revise this construction later
namespace BitmapHelper {
+
// Helper functions, that delete faulty bitmaps automatically, and return
// NULL if bitmap could not be created.
Bitmap *CreateBitmap(int width, int height, int color_depth = 0);
@@ -73,6 +74,7 @@ Bitmap *LoadFromFile(const char *filename);
inline Bitmap *LoadFromFile(const String &filename) {
return LoadFromFile(filename.GetCStr());
}
+Bitmap *LoadFromFile(PACKFILE *pf);
// Stretches bitmap to the requested size. The new bitmap will have same
// colour depth. Returns original bitmap if no changes are necessary.
@@ -87,8 +89,8 @@ void CopyTransparency(Bitmap *dst, const Bitmap *mask, bool dst_has_alpha, bo
// Pitch is given in bytes and defines the length of the source scan line.
// Offset is optional and defines horizontal offset, in pixels.
void ReadPixelsFromMemory(Bitmap *dst, const uint8_t *src_buffer, const size_t src_pitch, const size_t src_px_offset = 0);
-} // namespace BitmapHelper
+} // namespace BitmapHelper
} // namespace Shared
} // namespace AGS
} // namespace AGS3
Commit: b61a66190775598aa982bccbd87db3cfa8a4406e
https://github.com/scummvm/scummvm/commit/b61a66190775598aa982bccbd87db3cfa8a4406e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:54-07:00
Commit Message:
AGS: Removed redundant asset_size param from AssetManager::OpenAsset
>From upstream 9d8456d4202be698b0a3117679745a8200c1ab9b
Changed paths:
engines/ags/engine/ac/asset_helper.h
engines/ags/engine/ac/file.cpp
engines/ags/engine/ac/global_dynamic_sprite.cpp
engines/ags/engine/ac/global_file.cpp
engines/ags/shared/core/asset_manager.cpp
engines/ags/shared/core/asset_manager.h
engines/ags/shared/font/ttf_font_renderer.cpp
engines/ags/shared/font/wfn_font_renderer.cpp
diff --git a/engines/ags/engine/ac/asset_helper.h b/engines/ags/engine/ac/asset_helper.h
index 4980dd227ea..72db982032e 100644
--- a/engines/ags/engine/ac/asset_helper.h
+++ b/engines/ags/engine/ac/asset_helper.h
@@ -65,7 +65,7 @@ AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename);
AssetPath get_voice_over_assetpath(const String &filename);
// Locates asset among known locations, on success returns open stream and asset's size.
-Stream *LocateAsset(const AssetPath &path, size_t &asset_size);
+Stream *LocateAsset(const AssetPath &path);
// Custom AGS PACKFILE user object
// TODO: it is preferrable to let our Stream define custom readable window instead,
// keeping this as simple as possible for now (we may require a stream classes overhaul).
@@ -77,7 +77,7 @@ struct AGS_PACKFILE_OBJ {
// Creates PACKFILE stream from AGS asset.
// This function is supposed to be used only when you have to create Allegro
// object, passing PACKFILE stream to constructor.
-PACKFILE *PackfileFromAsset(const AssetPath &path, size_t &asset_size);
+PACKFILE *PackfileFromAsset(const AssetPath &path);
bool DoesAssetExistInLib(const AssetPath &assetname);
} // namespace AGS3
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index d90bd20f8f8..eeb3db53bfa 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -401,12 +401,10 @@ bool ResolveWritePathAndCreateDirs(const String &sc_path, ResolvedPath &rp) {
return true;
}
-Stream *LocateAsset(const AssetPath &path, size_t &asset_size) {
+Stream *LocateAsset(const AssetPath &path) {
String assetname = path.Name;
String filter = path.Filter;
- soff_t asset_sz = 0;
- Stream *asset_stream = _GP(AssetMgr)->OpenAsset(assetname, filter, &asset_sz);
- asset_size = asset_sz;
+ Stream *asset_stream = _GP(AssetMgr)->OpenAsset(assetname, filter);
return asset_stream;
}
@@ -475,8 +473,9 @@ static PACKFILE_VTABLE ags_packfile_vtable = {
};
//
-PACKFILE *PackfileFromAsset(const AssetPath &path, size_t &asset_size) {
- Stream *asset_stream = LocateAsset(path, asset_size);
+PACKFILE *PackfileFromAsset(const AssetPath &path) {
+ Stream *asset_stream = LocateAsset(path);
+ const size_t asset_size = asset_stream->GetLength();
if (asset_stream && asset_size > 0) {
AGS_PACKFILE_OBJ *obj = new AGS_PACKFILE_OBJ;
obj->stream.reset(asset_stream);
diff --git a/engines/ags/engine/ac/global_dynamic_sprite.cpp b/engines/ags/engine/ac/global_dynamic_sprite.cpp
index 5af5235cfc7..524daf07893 100644
--- a/engines/ags/engine/ac/global_dynamic_sprite.cpp
+++ b/engines/ags/engine/ac/global_dynamic_sprite.cpp
@@ -41,8 +41,7 @@ int LoadImageFile(const char *filename) {
Bitmap *loadedFile;
if (rp.AssetMgr) {
- size_t asset_size;
- PACKFILE *pf = PackfileFromAsset(rp.FullPath, asset_size);
+ PACKFILE *pf = PackfileFromAsset(AssetPath(rp.FullPath, "*"));
if (!pf)
return 0;
loadedFile = BitmapHelper::LoadFromFile(pf);
diff --git a/engines/ags/engine/ac/global_file.cpp b/engines/ags/engine/ac/global_file.cpp
index ca55dbdf902..80babc04160 100644
--- a/engines/ags/engine/ac/global_file.cpp
+++ b/engines/ags/engine/ac/global_file.cpp
@@ -82,7 +82,7 @@ int32_t FileOpen(const char *fnmm, Shared::FileOpenMode open_mode, Shared::FileW
Stream *s;
if (rp.AssetMgr) {
- s = _GP(AssetMgr)->OpenAsset(rp.FullPath, nullptr);
+ s = _GP(AssetMgr)->OpenAsset(rp.FullPath, "*");
} else {
s = File::OpenFile(rp.FullPath, open_mode, work_mode);
if (!s && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
diff --git a/engines/ags/shared/core/asset_manager.cpp b/engines/ags/shared/core/asset_manager.cpp
index 0b640cf39e8..0d54aaf5a11 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -254,21 +254,15 @@ bool AssetManager::GetAssetFromDir(const AssetLibInfo *lib, const String &file_n
return true;
}
-Stream *AssetManager::OpenAsset(const String &asset_name, soff_t *asset_size) const {
- return OpenAsset(asset_name, "", asset_size);
+Stream *AssetManager::OpenAsset(const String &asset_name) const {
+ return OpenAsset(asset_name, "");
}
-Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter, soff_t *asset_size) const {
+Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter) const {
AssetLocation loc;
- if (GetAsset(asset_name, filter, false, &loc)) {
- Stream *s = File::OpenFile(loc.FileName, loc.Offset, loc.Offset + loc.Size);
- if (s) {
- if (asset_size)
- *asset_size = loc.Size;
- }
- return s;
- }
- return nullptr;
+ if (!GetAsset(asset_name, filter, false, &loc))
+ return nullptr;
+ return File::OpenFile(loc.FileName, loc.Offset, loc.Offset + loc.Size);
}
Common::SeekableReadStream *AssetManager::OpenAssetStream(const String &asset_name) const {
@@ -276,12 +270,12 @@ Common::SeekableReadStream *AssetManager::OpenAssetStream(const String &asset_na
}
Common::SeekableReadStream *AssetManager::OpenAssetStream(const String &asset_name, const String &filter) const {
- soff_t assetSize;
- Stream *stream = OpenAsset(asset_name, filter, &assetSize);
+ Stream *stream = OpenAsset(asset_name, filter);
if (!stream)
return nullptr;
// Get the contents of the asset
+ size_t assetSize = stream->GetLength();
byte *data = (byte *)malloc(assetSize);
stream->Read(data, assetSize);
delete stream;
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index ca0ca6276d3..44f98116115 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -108,9 +108,9 @@ public:
String FindAssetFileOnly(const String &asset_name, 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, soff_t *asset_size = nullptr) const;
+ Stream *OpenAsset(const String &asset_name) const;
// Open asset stream, providing a single filter to search in matching libraries
- Stream *OpenAsset(const String &asset_name, const String &filter, soff_t *asset_size = nullptr) const;
+ Stream *OpenAsset(const String &asset_name, 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
Common::SeekableReadStream *OpenAssetStream(const String &asset_name) const;
diff --git a/engines/ags/shared/font/ttf_font_renderer.cpp b/engines/ags/shared/font/ttf_font_renderer.cpp
index c5638219ae1..a2f208b4ab5 100644
--- a/engines/ags/shared/font/ttf_font_renderer.cpp
+++ b/engines/ags/shared/font/ttf_font_renderer.cpp
@@ -86,13 +86,13 @@ bool TTFFontRenderer::IsBitmapFont() {
bool TTFFontRenderer::LoadFromDiskEx(int fontNumber, int fontSize,
const FontRenderParams *params, FontMetrics *metrics) {
String file_name = String::FromFormat("agsfnt%d.ttf", fontNumber);
- soff_t lenof = 0;
- Stream *reader = _GP(AssetMgr)->OpenAsset(file_name, &lenof);
+ Stream *reader = _GP(AssetMgr)->OpenAsset(file_name);
byte *membuffer;
if (reader == nullptr)
return false;
+ size_t lenof = reader->GetLength();
membuffer = (byte *)malloc(lenof);
reader->ReadArray(membuffer, lenof, 1);
delete reader;
diff --git a/engines/ags/shared/font/wfn_font_renderer.cpp b/engines/ags/shared/font/wfn_font_renderer.cpp
index 3b2d29dab0b..8a5d8c6f0f6 100644
--- a/engines/ags/shared/font/wfn_font_renderer.cpp
+++ b/engines/ags/shared/font/wfn_font_renderer.cpp
@@ -132,20 +132,19 @@ bool WFNFontRenderer::LoadFromDiskEx(int fontNumber, int fontSize,
const FontRenderParams *params, FontMetrics *metrics) {
String file_name;
Stream *ffi = nullptr;
- soff_t asset_size = 0;
file_name.Format("agsfnt%d.wfn", fontNumber);
- ffi = _GP(AssetMgr)->OpenAsset(file_name, &asset_size);
+ ffi = _GP(AssetMgr)->OpenAsset(file_name);
if (ffi == nullptr) {
// actual font not found, try font 0 instead
file_name = "agsfnt0.wfn";
- ffi = _GP(AssetMgr)->OpenAsset(file_name, &asset_size);
+ ffi = _GP(AssetMgr)->OpenAsset(file_name);
if (ffi == nullptr)
return false;
}
WFNFont *font = new WFNFont();
- WFNError err = font->ReadFromFile(ffi, asset_size);
+ WFNError err = font->ReadFromFile(ffi);
delete ffi;
if (err == kWFNErr_HasBadCharacters)
Debug::Printf(kDbgMsg_Warn, "WARNING: font '%s' has mistakes in data format, some characters may be displayed incorrectly", file_name.GetCStr());
Commit: ca7ae36fe46ea9c4e23b24e7586fee5c521bb668
https://github.com/scummvm/scummvm/commit/ca7ae36fe46ea9c4e23b24e7586fee5c521bb668
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:55-07:00
Commit Message:
AGS: Removed FindAssetFileOnly(), was used for specific a workaround
>From upstream 064a606b5799db5bc4eaeb5f2176c90043512e65
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 0d54aaf5a11..7df73dd94bd 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -154,14 +154,7 @@ const AssetLibInfo *AssetManager::GetLibraryInfo(size_t index) const {
}
bool AssetManager::DoesAssetExist(const String &asset_name, const String &filter) const {
- return GetAsset(asset_name, filter, false, nullptr);
-}
-
-String AssetManager::FindAssetFileOnly(const String &asset_name, const String &filter) const {
- AssetLocation loc;
- if (GetAsset(asset_name, filter, true, &loc))
- return loc.FileName;
- return "";
+ return GetAsset(asset_name, filter, false);
}
AssetError AssetManager::RegisterAssetLib(const String &path, AssetLibEx *&out_lib) {
@@ -200,7 +193,7 @@ AssetError AssetManager::RegisterAssetLib(const String &path, AssetLibEx *&out_l
}
bool AssetManager::GetAsset(const String &asset_name, const String &filter,
- bool dir_only, AssetLocation *loc) const {
+ AssetLocation *loc) const {
for (const auto *lib : _activeLibs) {
auto match = std::find(lib->Filters.begin(), lib->Filters.end(), filter);
if (match == lib->Filters.end())
@@ -209,7 +202,7 @@ bool AssetManager::GetAsset(const String &asset_name, const String &filter,
bool found = false;
if (IsAssetLibDir(lib))
found = GetAssetFromDir(lib, asset_name, loc);
- else if (!dir_only)
+ else
found = GetAssetFromLib(lib, asset_name, loc);
if (found)
return true;
@@ -260,7 +253,7 @@ Stream *AssetManager::OpenAsset(const String &asset_name) const {
Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter) const {
AssetLocation loc;
- if (!GetAsset(asset_name, filter, false, &loc))
+ if (!GetAsset(asset_name, filter, &loc))
return nullptr;
return File::OpenFile(loc.FileName, loc.Offset, loc.Offset + loc.Size);
}
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index 44f98116115..fc14eff89fb 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -104,8 +104,6 @@ public:
const AssetLibInfo *GetLibraryInfo(size_t index) const;
// Tells whether asset exists in any of the registered search locations
bool DoesAssetExist(const String &asset_name, const String &filter = "") const;
- // Finds asset only looking for bare files in directories; returns full path or empty string if failed
- String FindAssetFileOnly(const String &asset_name, 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;
@@ -126,7 +124,7 @@ 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
- bool GetAsset(const String &asset_name, const String &filter, bool dir_only, AssetLocation *loc) const;
+ 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;
Commit: a94d6411501d0688ccfd4f3c35f969ad290ce953
https://github.com/scummvm/scummvm/commit/a94d6411501d0688ccfd4f3c35f969ad290ce953
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:55-07:00
Commit Message:
AGS: AssetManager lets use AssetPath struct to call its methods
>From upstream d12adb27fcfb988596ea3ba7d755567a6bdbe6b9
Changed paths:
engines/ags/engine/ac/asset_helper.h
engines/ags/engine/ac/audio_clip.cpp
engines/ags/engine/ac/file.cpp
engines/ags/shared/core/asset_manager.h
diff --git a/engines/ags/engine/ac/asset_helper.h b/engines/ags/engine/ac/asset_helper.h
index 72db982032e..aafe3d7f39e 100644
--- a/engines/ags/engine/ac/asset_helper.h
+++ b/engines/ags/engine/ac/asset_helper.h
@@ -31,41 +31,30 @@
#include "ags/lib/std/memory.h"
#include "ags/lib/std/utility.h"
#include "ags/shared/util/string.h"
+#include "ags/shared/core/asset_manager.h"
namespace AGS3 {
+struct PACKFILE;
+
namespace AGS {
namespace Shared {
class Stream;
} // namespace Shared
} // namespace AGS
+using AGS::Shared::AssetPath;
using AGS::Shared::Stream;
using AGS::Shared::String;
// Looks for valid asset library everywhere and returns path, or empty string if failed
String find_assetlib(const String &filename);
-extern "C" {
- struct PACKFILE; // Allegro 4's own stream type
-}
-
-// AssetPath combines asset name and optional library filter, that serves to narrow down the search
-struct AssetPath {
- String Name;
- String Filter;
-
- AssetPath(const String &name = "", const String &filter = "") : Name(name), Filter(filter) {
- }
-};
-
// Returns the path to the audio asset, considering the given bundling type
AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename);
// Returns the path to the voice-over asset
AssetPath get_voice_over_assetpath(const String &filename);
-// Locates asset among known locations, on success returns open stream and asset's size.
-Stream *LocateAsset(const AssetPath &path);
// Custom AGS PACKFILE user object
// TODO: it is preferrable to let our Stream define custom readable window instead,
// keeping this as simple as possible for now (we may require a stream classes overhaul).
@@ -78,7 +67,6 @@ struct AGS_PACKFILE_OBJ {
// This function is supposed to be used only when you have to create Allegro
// object, passing PACKFILE stream to constructor.
PACKFILE *PackfileFromAsset(const AssetPath &path);
-bool DoesAssetExistInLib(const AssetPath &assetname);
} // namespace AGS3
diff --git a/engines/ags/engine/ac/audio_clip.cpp b/engines/ags/engine/ac/audio_clip.cpp
index a961521c729..0fe43fcd9f8 100644
--- a/engines/ags/engine/ac/audio_clip.cpp
+++ b/engines/ags/engine/ac/audio_clip.cpp
@@ -25,12 +25,15 @@
#include "ags/engine/ac/audio_channel.h"
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/game_setup_struct.h"
+#include "ags/shared/core/asset_manager.h"
#include "ags/engine/ac/dynobj/cc_audio_channel.h"
#include "ags/engine/script/runtime_script_value.h"
#include "ags/globals.h"
namespace AGS3 {
+using namespace AGS::Shared;
+
int AudioClip_GetID(ScriptAudioClip *clip) {
return clip->id;
}
@@ -43,7 +46,7 @@ int AudioClip_GetType(ScriptAudioClip *clip) {
return clip->type;
}
int AudioClip_GetIsAvailable(ScriptAudioClip *clip) {
- return DoesAssetExistInLib(get_audio_clip_assetpath(clip->bundlingType, clip->fileName)) ? 1 : 0;
+ return _GP(AssetMgr)->DoesAssetExist(get_audio_clip_assetpath(clip->bundlingType, clip->fileName)) ? 1 : 0;
}
void AudioClip_Stop(ScriptAudioClip *clip) {
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index eeb3db53bfa..31e8188baf8 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -401,13 +401,6 @@ bool ResolveWritePathAndCreateDirs(const String &sc_path, ResolvedPath &rp) {
return true;
}
-Stream *LocateAsset(const AssetPath &path) {
- String assetname = path.Name;
- String filter = path.Filter;
- Stream *asset_stream = _GP(AssetMgr)->OpenAsset(assetname, filter);
- return asset_stream;
-}
-
//
// AGS custom PACKFILE callbacks, that use our own Stream object
//
@@ -474,7 +467,7 @@ static PACKFILE_VTABLE ags_packfile_vtable = {
//
PACKFILE *PackfileFromAsset(const AssetPath &path) {
- Stream *asset_stream = LocateAsset(path);
+ Stream *asset_stream = _GP(AssetMgr)->OpenAsset(path);
const size_t asset_size = asset_stream->GetLength();
if (asset_stream && asset_size > 0) {
AGS_PACKFILE_OBJ *obj = new AGS_PACKFILE_OBJ;
@@ -486,12 +479,6 @@ PACKFILE *PackfileFromAsset(const AssetPath &path) {
return nullptr;
}
-bool DoesAssetExistInLib(const AssetPath &path) {
- String assetname = path.Name;
- String filter = path.Filter;
- return _GP(AssetMgr)->DoesAssetExist(assetname, filter);
-}
-
String find_assetlib(const String &filename) {
String libname = File::FindFileCI(_GP(ResPaths).DataDir, filename);
if (AssetManager::IsDataFile(libname))
diff --git a/engines/ags/shared/core/asset_manager.h b/engines/ags/shared/core/asset_manager.h
index fc14eff89fb..5a1fc6f0ab3 100644
--- a/engines/ags/shared/core/asset_manager.h
+++ b/engines/ags/shared/core/asset_manager.h
@@ -64,7 +64,20 @@ enum AssetError {
kAssetErrNoManager = -6, // asset manager not initialized
};
-// Explicit location of asset data
+/**
+ * AssetPath combines asset name and optional library filter, that serves to narrow down the search
+ */
+struct AssetPath {
+ String Name;
+ String Filter;
+
+ AssetPath(const String &name = "", const String &filter = "") : Name(name), Filter(filter) {
+ }
+};
+
+/**
+ * Explicit location of asset data
+ */
struct AssetLocation {
String FileName; // file where asset is located
soff_t Offset; // asset's position in file (in bytes)
@@ -104,11 +117,17 @@ public:
const AssetLibInfo *GetLibraryInfo(size_t index) const;
// Tells whether asset exists in any of the registered search locations
bool DoesAssetExist(const String &asset_name, const String &filter = "") const;
+ inline bool DoesAssetExist(const AssetPath &apath) const {
+ return DoesAssetExist(apath.Name, apath.Filter);
+ }
// 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;
// Open asset stream, providing a single filter to search in matching libraries
Stream *OpenAsset(const String &asset_name, const String &filter) const;
+ inline Stream *OpenAsset(const AssetPath &apath) const {
+ return OpenAsset(apath.Name, apath.Filter);
+ }
// 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
Common::SeekableReadStream *OpenAssetStream(const String &asset_name) const;
Commit: fff50e37352358504a01aa8e3844beb5f0b396f5
https://github.com/scummvm/scummvm/commit/fff50e37352358504a01aa8e3844beb5f0b396f5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:55-07:00
Commit Message:
AGS: Moved IsFile() and similar functions from Path to File unit
>From upstream ab78e1c454d1d0e60eac5a27672f27aa2487e24f
Changed paths:
engines/ags/engine/debugging/file_based_ags_debugger.cpp
engines/ags/engine/main/engine.cpp
engines/ags/shared/core/asset_manager.cpp
engines/ags/shared/game/main_game_file.cpp
engines/ags/shared/util/file.cpp
engines/ags/shared/util/file.h
engines/ags/shared/util/path.cpp
engines/ags/shared/util/path.h
diff --git a/engines/ags/engine/debugging/file_based_ags_debugger.cpp b/engines/ags/engine/debugging/file_based_ags_debugger.cpp
index 140a2f79878..f5d1a4f4f3d 100644
--- a/engines/ags/engine/debugging/file_based_ags_debugger.cpp
+++ b/engines/ags/engine/debugging/file_based_ags_debugger.cpp
@@ -34,7 +34,7 @@ using namespace AGS::Shared;
const char *SENT_MESSAGE_FILE_NAME = "dbgrecv.tmp";
bool FileBasedAGSDebugger::Initialize() {
- if (Path::IsFile(SENT_MESSAGE_FILE_NAME)) {
+ if (File::IsFile(SENT_MESSAGE_FILE_NAME)) {
File::DeleteFile(SENT_MESSAGE_FILE_NAME);
}
return true;
@@ -44,7 +44,7 @@ void FileBasedAGSDebugger::Shutdown() {
}
bool FileBasedAGSDebugger::SendMessageToEditor(const char *message) {
- while (Path::IsFile(SENT_MESSAGE_FILE_NAME)) {
+ while (File::IsFile(SENT_MESSAGE_FILE_NAME)) {
_G(platform)->YieldCPU();
}
@@ -58,7 +58,7 @@ bool FileBasedAGSDebugger::SendMessageToEditor(const char *message) {
}
bool FileBasedAGSDebugger::IsMessageAvailable() {
- return (Path::IsFile("dbgsend.tmp") != 0);
+ return (File::IsFile("dbgsend.tmp") != 0);
}
char *FileBasedAGSDebugger::GetNextMessage() {
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 67619cfe469..229a7164961 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -214,9 +214,9 @@ String search_for_game_data_file(String &was_searching_in) {
_G(cmdGameDataPath).GetCStr());
// 1. From command line argument, which may be a directory or actual file
if (!_G(cmdGameDataPath).IsEmpty()) {
- if (Path::IsFile(_G(cmdGameDataPath)))
+ if (File::IsFile(_G(cmdGameDataPath)))
return _G(cmdGameDataPath); // this path is a file
- if (!Path::IsDirectory(_G(cmdGameDataPath)))
+ if (!File::IsDirectory(_G(cmdGameDataPath)))
return ""; // path is neither file nor directory
was_searching_in = _G(cmdGameDataPath);
Debug::Printf("Searching in (cmd arg): %s", was_searching_in.GetCStr());
@@ -867,12 +867,12 @@ HError define_gamedata_location_checkall(String &data_path, String &startup_dir)
// First try if they provided a startup option
if (!_G(cmdGameDataPath).IsEmpty()) {
// If not a valid path - bail out
- if (!Path::IsFileOrDir(_G(cmdGameDataPath)))
+ if (!File::IsFileOrDir(_G(cmdGameDataPath)))
return new Error(String::FromFormat("Provided game location is not a valid path.\n Cwd: %s\n Path: %s",
- Directory::GetCurrentDirectory().GetCStr(),
- _G(cmdGameDataPath).GetCStr()));
+ Directory::GetCurrentDirectory().GetCStr(),
+ _G(cmdGameDataPath).GetCStr()));
// If it's a file, then keep it and proceed
- if (Path::IsFile(_G(cmdGameDataPath))) {
+ if (File::IsFile(_G(cmdGameDataPath))) {
Debug::Printf("Using provided game data path: %s", _G(cmdGameDataPath).GetCStr());
startup_dir = Path::GetDirectoryPath(_G(cmdGameDataPath));
data_path = _G(cmdGameDataPath);
diff --git a/engines/ags/shared/core/asset_manager.cpp b/engines/ags/shared/core/asset_manager.cpp
index 7df73dd94bd..40a87bb4483 100644
--- a/engines/ags/shared/core/asset_manager.cpp
+++ b/engines/ags/shared/core/asset_manager.cpp
@@ -160,7 +160,7 @@ bool AssetManager::DoesAssetExist(const String &asset_name, const String &filter
AssetError AssetManager::RegisterAssetLib(const String &path, AssetLibEx *&out_lib) {
// Test for a directory
std::unique_ptr<AssetLibEx> lib;
- if (Path::IsDirectory(path)) {
+ if (File::IsDirectory(path)) {
lib.reset(new AssetLibEx());
lib->BasePath = Path::MakeAbsolutePath(path);
lib->BaseDir = Path::GetDirectoryPath(lib->BasePath);
@@ -236,7 +236,7 @@ bool AssetManager::GetAssetFromLib(const AssetLibInfo *lib, const String &asset_
bool AssetManager::GetAssetFromDir(const AssetLibInfo *lib, const String &file_name,
AssetLocation *loc) const {
String found_file = File::FindFileCI(lib->BaseDir, file_name);
- if (found_file.IsEmpty() || !Path::IsFile(found_file))
+ if (found_file.IsEmpty() || !File::IsFile(found_file))
return false; // not found, or not a file
if (loc) {
diff --git a/engines/ags/shared/game/main_game_file.cpp b/engines/ags/shared/game/main_game_file.cpp
index f2b3bf75039..3a263992f15 100644
--- a/engines/ags/shared/game/main_game_file.cpp
+++ b/engines/ags/shared/game/main_game_file.cpp
@@ -523,7 +523,7 @@ void UpgradeAudio(GameSetupStruct &game, LoadedGameEntities &ents, GameDataVersi
// Read audio clip names from from registered libraries
for (size_t i = 0; i < _GP(AssetMgr)->GetLibraryCount(); ++i) {
const AssetLibInfo *game_lib = _GP(AssetMgr)->GetLibraryInfo(i);
- if (Path::IsDirectory(game_lib->BasePath))
+ if (File::IsDirectory(game_lib->BasePath))
continue; // might be a directory
for (const AssetInfo &info : game_lib->AssetInfos) {
@@ -538,7 +538,7 @@ void UpgradeAudio(GameSetupStruct &game, LoadedGameEntities &ents, GameDataVersi
// but that have to be done consistently if done at all.
for (size_t i = 0; i < _GP(AssetMgr)->GetLibraryCount(); ++i) {
const AssetLibInfo *game_lib = _GP(AssetMgr)->GetLibraryInfo(i);
- if (!Path::IsDirectory(game_lib->BasePath))
+ if (!File::IsDirectory(game_lib->BasePath))
continue; // might be a library
diff --git a/engines/ags/shared/util/file.cpp b/engines/ags/shared/util/file.cpp
index 6ff55e633c0..3b2bf8d0d17 100644
--- a/engines/ags/shared/util/file.cpp
+++ b/engines/ags/shared/util/file.cpp
@@ -34,6 +34,22 @@ namespace AGS3 {
namespace AGS {
namespace Shared {
+bool File::IsDirectory(const String &filename) {
+ // stat() does not like trailing slashes, remove them
+ String fixed_path = Path::MakePathNoSlash(filename);
+ return ags_directory_exists(fixed_path.GetCStr()) != 0;
+}
+
+bool File::IsFile(const String &filename) {
+ return ags_file_exists(filename.GetCStr()) != 0;
+}
+
+bool File::IsFileOrDir(const String &filename) {
+ // stat() does not like trailing slashes, remove them
+ String fixed_path = Path::MakePathNoSlash(filename);
+ return ags_path_exists(fixed_path.GetCStr()) != 0;
+}
+
soff_t File::GetFileSize(const String &filename) {
if (filename.IsEmpty())
return 0;
diff --git a/engines/ags/shared/util/file.h b/engines/ags/shared/util/file.h
index c349ac4c55a..2fe86547518 100644
--- a/engines/ags/shared/util/file.h
+++ b/engines/ags/shared/util/file.h
@@ -51,6 +51,13 @@ enum FileWorkMode {
};
namespace File {
+// Tells if the given path is a directory
+bool IsDirectory(const String &directory);
+// Tells if the given path is a file
+bool IsFile(const String &filename);
+// Tells if the given path is file or directory;
+// may be used to check if it's valid to use
+bool IsFileOrDir(const String &filename);
// Returns size of a file, or -1 if no such file found
soff_t GetFileSize(const String &filename);
// Tests if file could be opened for reading
diff --git a/engines/ags/shared/util/path.cpp b/engines/ags/shared/util/path.cpp
index 76f63b37f68..341ea15c60e 100644
--- a/engines/ags/shared/util/path.cpp
+++ b/engines/ags/shared/util/path.cpp
@@ -27,6 +27,7 @@
#include "ags/lib/allegro/file.h"
#include "ags/shared/util/path.h"
#include "ags/shared/util/stdio_compat.h"
+#include "ags/shared/util/file.h"
namespace AGS3 {
namespace AGS {
@@ -47,22 +48,6 @@ String get_extension(const String &path) {
filename : Common::String(filename.c_str() + i + 1);
}
-bool IsDirectory(const String &filename) {
- // stat() does not like trailing slashes, remove them
- String fixed_path = MakePathNoSlash(filename);
- return ags_directory_exists(fixed_path.GetCStr()) != 0;
-}
-
-bool IsFile(const String &filename) {
- return ags_file_exists(filename.GetCStr()) != 0;
-}
-
-bool IsFileOrDir(const String &filename) {
- // stat() does not like trailing slashes, remove them
- String fixed_path = MakePathNoSlash(filename);
- return ags_path_exists(fixed_path.GetCStr()) != 0;
-}
-
String GetParent(const String &path) {
const char *cstr = path.GetCStr();
const char *ptr_end = cstr + path.GetLength();
@@ -105,7 +90,7 @@ int ComparePaths(const String &path1, const String &path2) {
}
String GetDirectoryPath(const String &path) {
- if (IsDirectory(path))
+ if (File::IsDirectory(path))
return path;
String dir = path;
diff --git a/engines/ags/shared/util/path.h b/engines/ags/shared/util/path.h
index 2f87b4defaf..90289385dad 100644
--- a/engines/ags/shared/util/path.h
+++ b/engines/ags/shared/util/path.h
@@ -43,13 +43,6 @@ String get_filename(const String &path);
// Get an extension from a filename
String get_extension(const String &path);
-// Tells if the given path is a directory
-bool IsDirectory(const String &directory);
-// Tells if the given path is a file
-bool IsFile(const String &filename);
-// Tells if the given path is file or directory;
-// may be used to check if it's valid to use
-bool IsFileOrDir(const String &filename);
// Returns parent directory of the given path;
// returns "." (current dir) if the path does not contain a parent segment
String GetParent(const String &path);
Commit: 83c785cf226e3ecb57185dba4808b1d1676f45ec
https://github.com/scummvm/scummvm/commit/83c785cf226e3ecb57185dba4808b1d1676f45ec
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-20T22:11:56-07:00
Commit Message:
AGS: Slightly more clear platform driver init/exit steps
>From upstream b539f0c5c57514fb77875b4d15fc623e0251de52
Changed paths:
engines/ags/engine/main/engine.cpp
engines/ags/engine/main/main.cpp
engines/ags/engine/main/main.h
engines/ags/engine/main/quit.cpp
engines/ags/engine/platform/base/ags_platform_driver.cpp
engines/ags/engine/platform/base/ags_platform_driver.h
engines/ags/globals.h
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 229a7164961..97e3be05b59 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -84,6 +84,7 @@ using namespace AGS::Engine;
bool engine_init_backend() {
_G(our_eip) = -199;
+ _G(platform)->PreBackendInit();
// Initialize SDL
Debug::Printf(kDbgMsg_Info, "Initializing backend libs");
if (sys_main_init()) {
diff --git a/engines/ags/engine/main/main.cpp b/engines/ags/engine/main/main.cpp
index a450db05d89..f349ffc4257 100644
--- a/engines/ags/engine/main/main.cpp
+++ b/engines/ags/engine/main/main.cpp
@@ -50,16 +50,6 @@ namespace AGS3 {
using namespace AGS::Shared;
using namespace AGS::Engine;
-void main_pre_init() {
- _G(our_eip) = -999;
- _GP(AssetMgr)->SetSearchPriority(Shared::kAssetPriorityDir);
- _GP(play).takeover_data = 0;
-}
-
-void main_create_platform_driver() {
- _G(platform) = AGSPlatformDriver::GetDriver();
-}
-
// this needs to be updated if the "play" struct changes
#define SVG_VERSION_BWCOMPAT_MAJOR 3
#define SVG_VERSION_BWCOMPAT_MINOR 2
@@ -73,6 +63,8 @@ void main_create_platform_driver() {
#define SVG_VERSION_FWCOMPAT_REVISION 1111
void main_init(int argc, const char *argv[]) {
+ _G(our_eip) = -999;
+
// Init libraries: set text encoding
set_uformat(U_UTF8);
set_filename_encoding(U_UNICODE);
@@ -84,13 +76,12 @@ void main_init(int argc, const char *argv[]) {
_G(SavedgameLowestBackwardCompatVersion) = Version(SVG_VERSION_BWCOMPAT_MAJOR, SVG_VERSION_BWCOMPAT_MINOR, SVG_VERSION_BWCOMPAT_RELEASE, SVG_VERSION_BWCOMPAT_REVISION);
_G(SavedgameLowestForwardCompatVersion) = Version(SVG_VERSION_FWCOMPAT_MAJOR, SVG_VERSION_FWCOMPAT_MINOR, SVG_VERSION_FWCOMPAT_RELEASE, SVG_VERSION_FWCOMPAT_REVISION);
- _GP(AssetMgr).reset(new AssetManager());
- main_pre_init();
- main_create_platform_driver();
- _G(platform)->MainInitAdjustments();
+ _G(platform) = AGSPlatformDriver::GetDriver();
+ _G(platform)->SetCommandArgs(argv, argc);
+ _G(platform)->MainInit();
- _G(global_argv) = argv;
- _G(global_argc) = argc;
+ _GP(AssetMgr).reset(new AssetManager());
+ _GP(AssetMgr)->SetSearchPriority(Shared::kAssetPriorityDir);
}
String get_engine_string() {
@@ -290,12 +281,8 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
else if (arg[0] != '-') datafile_argv = ee;
}
- if (datafile_argv > 0) {
- _G(cmdGameDataPath) = GetPathFromCmdArg(datafile_argv);
- } else {
- // assign standard path for mobile/consoles (defined in their own platform implementation)
- _G(cmdGameDataPath) = _G(psp_game_file_name);
- }
+ // assign standard path (defined in their own platform implementation)
+ _G(cmdGameDataPath) = _G(psp_game_file_name);
if (_G(tellInfoKeys).size() > 0)
_G(justTellInfo) = true;
@@ -304,7 +291,7 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
}
void main_set_gamedir(int argc, const char *argv[]) {
- _G(appPath) = GetPathFromCmdArg(0);
+ _G(appPath) = Path::MakeAbsolutePath(_G(platform)->GetCommandArg(0));
_G(appDirectory) = Path::GetDirectoryPath(_G(appPath));
// TODO: remove following when supporting unicode paths
@@ -323,14 +310,4 @@ void main_set_gamedir(int argc, const char *argv[]) {
}
}
-String GetPathFromCmdArg(int arg_index) {
- if (arg_index < 0 || arg_index >= _G(global_argc))
- return "";
- String path = Path::GetCmdLinePathInASCII(_G(global_argv)[arg_index], arg_index);
- if (!path.IsEmpty())
- return Path::MakeAbsolutePath(path);
- Debug::Printf(kDbgMsg_Error, "Unable to determine path: GetCmdLinePathInASCII failed.\nCommand line argument %i: %s", arg_index, _G(global_argv)[arg_index]);
- return _G(global_argv)[arg_index];
-}
-
} // namespace AGS3
diff --git a/engines/ags/engine/main/main.h b/engines/ags/engine/main/main.h
index 4bbd641ac70..0c1765a1bdf 100644
--- a/engines/ags/engine/main/main.h
+++ b/engines/ags/engine/main/main.h
@@ -35,8 +35,6 @@ extern void main_init(int argc, const char *argv[]);
extern int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]);
-extern AGS::Shared::String GetPathFromCmdArg(int arg_index);
-
extern String get_engine_string();
extern void main_print_help();
diff --git a/engines/ags/engine/main/quit.cpp b/engines/ags/engine/main/quit.cpp
index 89f52edca25..bed47df7001 100644
--- a/engines/ags/engine/main/quit.cpp
+++ b/engines/ags/engine/main/quit.cpp
@@ -45,6 +45,7 @@
#include "ags/shared/gfx/bitmap.h"
#include "ags/shared/core/asset_manager.h"
#include "ags/engine/platform/base/ags_platform_driver.h"
+#include "ags/engine/platform/base/sys_main.h"
#include "ags/plugins/plugin_engine.h"
#include "ags/engine/media/audio/audio_system.h"
#include "ags/globals.h"
@@ -85,23 +86,6 @@ void quit_check_dynamic_sprites(QuitReason qreason) {
}
}
-void quit_shutdown_platform(QuitReason qreason) {
- // Be sure to unlock mouse on exit, or users will hate us
- _G(platform)->UnlockMouse();
- _G(platform)->AboutToQuitGame();
-
- _G(our_eip) = 9016;
-
- pl_stop_plugins();
-
- quit_check_dynamic_sprites(qreason);
-
- _G(platform)->FinishedUsingGraphicsMode();
-
- if (_G(use_cdplayer))
- _G(platform)->ShutdownCDPlayer();
-}
-
void quit_shutdown_audio() {
_G(our_eip) = 9917;
_GP(game).options[OPT_CROSSFADEMUSIC] = 0;
@@ -217,7 +201,17 @@ void quit_free() {
quit_shutdown_scripts();
- quit_shutdown_platform(qreason);
+ // Be sure to unlock mouse on exit, or users will hate us
+ sys_window_lock_mouse(false);
+
+ _G(our_eip) = 9016;
+
+ pl_stop_plugins();
+
+ quit_check_dynamic_sprites(qreason);
+
+ if (_G(use_cdplayer))
+ _G(platform)->ShutdownCDPlayer();
_G(our_eip) = 9019;
@@ -244,6 +238,8 @@ void quit_free() {
quit_release_data();
+ _G(platform)->PreBackendExit();
+
// release backed library
// WARNING: no Allegro objects should remain in memory after this,
// if their destruction is called later, program will crash!
diff --git a/engines/ags/engine/platform/base/ags_platform_driver.cpp b/engines/ags/engine/platform/base/ags_platform_driver.cpp
index d76b2b5f5a2..32958e91188 100644
--- a/engines/ags/engine/platform/base/ags_platform_driver.cpp
+++ b/engines/ags/engine/platform/base/ags_platform_driver.cpp
@@ -53,9 +53,6 @@ AGSPlatformDriver *AGSPlatformDriver::instance = nullptr;
// ******** DEFAULT IMPLEMENTATIONS *******
-void AGSPlatformDriver::AboutToQuitGame() {
-}
-
void AGSPlatformDriver::PostAllegroInit(bool windowed) {
}
@@ -167,6 +164,15 @@ SetupReturnValue AGSPlatformDriver::RunSetup(const ConfigTree &cfg_in, ConfigTre
return kSetup_Cancel;
}
+void AGSPlatformDriver::SetCommandArgs(const char *const argv[], size_t argc) {
+ _cmdArgs = argv;
+ _cmdArgCount = argc;
+}
+
+Common::String AGSPlatformDriver::GetCommandArg(size_t arg_index) {
+ return arg_index < _cmdArgCount ? _cmdArgs[arg_index] : nullptr;
+}
+
void AGSPlatformDriver::SetGameWindowIcon() {
// do nothing
}
diff --git a/engines/ags/engine/platform/base/ags_platform_driver.h b/engines/ags/engine/platform/base/ags_platform_driver.h
index 6862f489a8c..3347bf52e59 100644
--- a/engines/ags/engine/platform/base/ags_platform_driver.h
+++ b/engines/ags/engine/platform/base/ags_platform_driver.h
@@ -70,7 +70,17 @@ struct AGSPlatformDriver
: public AGS::Shared::IOutputHandler {
virtual ~AGSPlatformDriver() { instance = nullptr; }
- virtual void AboutToQuitGame();
+ // Called at the creation of the platform driver
+ virtual void MainInit() { };
+ // Called right before the formal backend init
+ virtual void PreBackendInit() { };
+ // Called right after the formal backend init
+ virtual void PostBackendInit() { };
+ // Called right before the backend is deinitialized
+ virtual void PreBackendExit() { };
+ // Called right after the backend is deinitialized
+ virtual void PostBackendExit() { };
+
virtual void Delay(int millis);
virtual void DisplayAlert(const char *, ...) = 0;
virtual void AttachToParentConsole();
@@ -121,8 +131,6 @@ struct AGSPlatformDriver
virtual void InitialiseAbufAtStartup();
virtual void PostAllegroInit(bool windowed);
virtual void PostAllegroExit() = 0;
- virtual void PostBackendInit() {}
- virtual void PostBackendExit() {}
virtual const char *GetBackendFailUserHint() {
return nullptr;
}
@@ -166,14 +174,17 @@ struct AGSPlatformDriver
virtual int CDPlayerCommand(int cmdd, int datt) = 0;
virtual void ShutdownCDPlayer() = 0;
- // Allows adjusting parameters and other fixes before engine is initialized
- virtual void MainInitAdjustments() {}
+ // Returns command line argument in a UTF-8 format
+ virtual Common::String GetCommandArg(size_t arg_index);
virtual bool LockMouseToWindow();
virtual void UnlockMouse();
static AGSPlatformDriver *GetDriver();
+ // Store command line arguments for the future use
+ void SetCommandArgs(const char *const argv[], size_t argc);
+
// Set whether PrintMessage should output to stdout or stderr
void SetOutputToErr(bool on) {
_logToStdErr = on;
@@ -201,6 +212,9 @@ protected:
// and errors by showing a message box kind of GUI.
bool _guiMode = false;
+ const char *const *_cmdArgs = nullptr;
+ size_t _cmdArgCount = 0u;
+
private:
static AGSPlatformDriver *instance;
};
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index f91f0dcd978..8f7ff74573f 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -1063,9 +1063,6 @@ public:
String _appDirectory; // Needed for library loading
String _cmdGameDataPath;
- const char **_global_argv = nullptr;
- int _global_argc = 0;
-
// Startup flags, set from parameters to engine
int _force_window = 0;
int _override_start_room = 0;
More information about the Scummvm-git-logs
mailing list