Initial commit
This commit is contained in:
36
engines/ags/shared/core/asset.cpp
Normal file
36
engines/ags/shared/core/asset.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ags/shared/core/asset.h"
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
AssetInfo::AssetInfo()
|
||||
: LibUid(0)
|
||||
, Offset(0)
|
||||
, Size(0) {
|
||||
}
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
64
engines/ags/shared/core/asset.h
Normal file
64
engines/ags/shared/core/asset.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// AssetInfo and AssetLibInfo - classes describing generic asset library.
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef AGS_SHARED_CORE_ASSET_H
|
||||
#define AGS_SHARED_CORE_ASSET_H
|
||||
|
||||
#include "common/std/vector.h"
|
||||
#include "ags/shared/util/string.h"
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
// Information on single asset
|
||||
struct AssetInfo {
|
||||
// A pair of filename and libuid is assumed to be unique in game scope
|
||||
String FileName; // filename associated with asset
|
||||
int32_t LibUid; // index of library partition (separate file)
|
||||
soff_t Offset; // asset's position in library file (in bytes)
|
||||
soff_t Size; // asset's size (in bytes)
|
||||
|
||||
AssetInfo();
|
||||
};
|
||||
|
||||
// Information on multifile asset library
|
||||
struct AssetLibInfo {
|
||||
String BasePath; // full path to the base filename
|
||||
String BaseDir; // library's directory
|
||||
String BaseFileName; // library's base (head) filename
|
||||
std::vector<String> LibFileNames; // filename for each library part
|
||||
|
||||
// Library contents
|
||||
std::vector<AssetInfo> AssetInfos; // information on contained assets
|
||||
};
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
|
||||
#endif
|
||||
304
engines/ags/shared/core/asset_manager.cpp
Normal file
304
engines/ags/shared/core/asset_manager.cpp
Normal file
@@ -0,0 +1,304 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/memstream.h"
|
||||
#include "common/std/algorithm.h"
|
||||
#include "common/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
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
inline static bool IsAssetLibDir(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());
|
||||
}
|
||||
|
||||
// Asset library sorting function, directories have priority
|
||||
bool SortLibsPriorityDir(const AssetLibInfo *lib1, const AssetLibInfo *lib2) {
|
||||
// first element is less if it's a directory while second is a lib
|
||||
return IsAssetLibDir(lib1) && !IsAssetLibDir(lib2);
|
||||
}
|
||||
|
||||
// Asset library sorting function, packages have priority
|
||||
bool SortLibsPriorityLib(const AssetLibInfo *lib1, const AssetLibInfo *lib2) {
|
||||
// first element is less if it's a lib while second is a directory
|
||||
return !IsAssetLibDir(lib1) && IsAssetLibDir(lib2);
|
||||
}
|
||||
|
||||
AssetManager::AssetManager() {
|
||||
SetSearchPriority(kAssetPriorityDir); // ensure lib sorter is initialized
|
||||
}
|
||||
|
||||
/* static */ bool AssetManager::IsDataFile(const String &data_file) {
|
||||
Stream *in = File::OpenFileCI(data_file.GetCStr(), Shared::kFile_Open, Shared::kFile_Read);
|
||||
if (in) {
|
||||
MFLUtil::MFLError err = MFLUtil::TestIsMFL(in, true);
|
||||
delete in;
|
||||
return err == MFLUtil::kMFLNoError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* static */ AssetError AssetManager::ReadDataFileTOC(const String &data_file, AssetLibInfo &lib) {
|
||||
Stream *in = File::OpenFileCI(data_file.GetCStr(), Shared::kFile_Open, Shared::kFile_Read);
|
||||
if (in) {
|
||||
MFLUtil::MFLError err = MFLUtil::ReadHeader(lib, in);
|
||||
delete in;
|
||||
return (err != MFLUtil::kMFLNoError) ? kAssetErrLibParse : kAssetNoError;
|
||||
}
|
||||
return kAssetErrNoLibFile;
|
||||
}
|
||||
|
||||
void AssetManager::SetSearchPriority(AssetSearchPriority priority) {
|
||||
_libsPriority = priority;
|
||||
_libsSorter = _libsPriority == kAssetPriorityDir ? SortLibsPriorityDir : SortLibsPriorityLib;
|
||||
std::sort(_activeLibs.begin(), _activeLibs.end(), _libsSorter);
|
||||
}
|
||||
|
||||
AssetSearchPriority AssetManager::GetSearchPriority() const {
|
||||
return _libsPriority;
|
||||
}
|
||||
|
||||
AssetError AssetManager::AddLibrary(const String &path, const AssetLibInfo **out_lib) {
|
||||
return AddLibrary(path, "", out_lib);
|
||||
}
|
||||
|
||||
AssetError AssetManager::AddLibrary(const String &path, const String &filters, const AssetLibInfo **out_lib) {
|
||||
if (path.IsEmpty())
|
||||
return kAssetErrNoLibFile;
|
||||
|
||||
for (const auto &lib : _libs) {
|
||||
if (Path::ComparePaths(lib->BasePath, path) == 0) {
|
||||
// already present, only assign new filters
|
||||
lib->Filters = filters.Split(',');
|
||||
if (out_lib)
|
||||
*out_lib = lib;
|
||||
return kAssetNoError;
|
||||
}
|
||||
}
|
||||
|
||||
AssetLibEx *lib;
|
||||
AssetError err = RegisterAssetLib(path, lib);
|
||||
if (err != kAssetNoError)
|
||||
return err;
|
||||
lib->Filters = filters.Split(',');
|
||||
auto place = std::upper_bound(_activeLibs.begin(), _activeLibs.end(), lib, _libsSorter);
|
||||
_activeLibs.insert(place, lib);
|
||||
if (out_lib)
|
||||
*out_lib = lib;
|
||||
return kAssetNoError;
|
||||
}
|
||||
|
||||
void AssetManager::RemoveLibrary(const String &path) {
|
||||
int idx = 0;
|
||||
for (auto it = _libs.begin(); it != _libs.end(); ++it, ++idx) {
|
||||
if (Path::ComparePaths((*it)->BasePath, path) == 0) {
|
||||
_libs.remove_at(idx);
|
||||
_activeLibs.remove(*it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AssetManager::RemoveAllLibraries() {
|
||||
for (uint i = 0; i < _libs.size(); ++i)
|
||||
delete _libs[i];
|
||||
|
||||
_libs.clear();
|
||||
_activeLibs.clear();
|
||||
}
|
||||
|
||||
size_t AssetManager::GetLibraryCount() const {
|
||||
return _libs.size();
|
||||
}
|
||||
|
||||
const AssetLibInfo *AssetManager::GetLibraryInfo(size_t index) const {
|
||||
return index < _libs.size() ? _libs[index] : nullptr;
|
||||
}
|
||||
|
||||
bool AssetManager::DoesAssetExist(const String &asset_name, const String &filter) const {
|
||||
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,
|
||||
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.GetCStr()).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;
|
||||
if (File::IsDirectory(path)) {
|
||||
lib.reset(new AssetLibEx());
|
||||
lib->BasePath = Path::MakeAbsolutePath(path);
|
||||
lib->BaseDir = Path::GetDirectoryPath(lib->BasePath);
|
||||
|
||||
// TODO: maybe parse directory for the file reference? idk if needed
|
||||
}
|
||||
// ...else try open a data library
|
||||
else {
|
||||
Stream *in = File::OpenFileCI(path.GetCStr(), Shared::kFile_Open, Shared::kFile_Read);
|
||||
if (!in)
|
||||
return kAssetErrNoLibFile; // can't be opened, return error code
|
||||
|
||||
lib.reset(new AssetLibEx());
|
||||
MFLUtil::MFLError mfl_err = MFLUtil::ReadHeader(*lib, in);
|
||||
delete in;
|
||||
|
||||
if (mfl_err != MFLUtil::kMFLNoError)
|
||||
return kAssetErrLibParse;
|
||||
|
||||
lib->BasePath = Path::MakeAbsolutePath(path);
|
||||
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();
|
||||
_libs.push_back(out_lib);
|
||||
|
||||
return kAssetNoError;
|
||||
}
|
||||
|
||||
Stream *AssetManager::OpenAsset(const String &asset_name, const String &filter) const {
|
||||
for (const auto *lib : _activeLibs) {
|
||||
if (!lib->TestFilter(filter)) continue; // filter does not match
|
||||
|
||||
Stream *s = nullptr;
|
||||
if (IsAssetLibDir(lib))
|
||||
s = OpenAssetFromDir(lib, asset_name);
|
||||
else
|
||||
s = OpenAssetFromLib(lib, asset_name);
|
||||
if (s)
|
||||
return s;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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 = lib->RealLibFiles[a.LibUid];
|
||||
if (libfile.IsEmpty())
|
||||
return nullptr;
|
||||
return File::OpenFile(libfile, a.Offset, a.Offset + a.Size);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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;
|
||||
return File::OpenFileRead(found_file);
|
||||
}
|
||||
|
||||
Stream *AssetManager::OpenAsset(const String &asset_name) const {
|
||||
return OpenAsset(asset_name, "");
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *AssetManager::OpenAssetStream(const String &asset_name) const {
|
||||
return OpenAssetStream(asset_name, "");
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *AssetManager::OpenAssetStream(const String &asset_name, const String &filter) const {
|
||||
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;
|
||||
|
||||
return new Common::MemoryReadStream(data, assetSize, DisposeAfterUse::YES);
|
||||
}
|
||||
|
||||
String GetAssetErrorText(AssetError err) {
|
||||
switch (err) {
|
||||
case kAssetNoError:
|
||||
return "No error.";
|
||||
case kAssetErrNoLibFile:
|
||||
return "Asset library file not found or could not be opened.";
|
||||
case kAssetErrLibParse:
|
||||
return "Not an asset library or unsupported format.";
|
||||
case kAssetErrNoManager:
|
||||
return "Asset manager is not initialized.";
|
||||
}
|
||||
return "Unknown error.";
|
||||
}
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
160
engines/ags/shared/core/asset_manager.h
Normal file
160
engines/ags/shared/core/asset_manager.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Asset manager class for reading and writing game resources.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// The code is based on CLIB32, by Chris Jones (1998-99), DJGPP implementation
|
||||
// of the CLIB reader.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// TODO: consider replace/merge with PhysFS library in the future.
|
||||
//
|
||||
// TODO: support streams that work on a file subsection, limited by size,
|
||||
// to avoid having to return an asset size separately from a stream.
|
||||
// TODO: return stream as smart pointer.
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef AGS_SHARED_CORE_ASSET_MANAGER_H
|
||||
#define AGS_SHARED_CORE_ASSET_MANAGER_H
|
||||
|
||||
#include "common/stream.h"
|
||||
#include "common/std/functional.h"
|
||||
#include "common/std/memory.h"
|
||||
#include "ags/shared/core/asset.h"
|
||||
#include "ags/shared/util/file.h" // TODO: extract filestream mode constants or introduce generic ones
|
||||
|
||||
namespace AGS3 {
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
|
||||
class Stream;
|
||||
struct MultiFileLib;
|
||||
|
||||
enum AssetSearchPriority {
|
||||
kAssetPriorityDir,
|
||||
kAssetPriorityLib
|
||||
};
|
||||
|
||||
enum AssetError {
|
||||
kAssetNoError = 0,
|
||||
kAssetErrNoLibFile = -1, // library file not found or can't be read
|
||||
kAssetErrLibParse = -2, // bad library file format or read error
|
||||
kAssetErrNoManager = -6, // asset manager not initialized
|
||||
};
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
}
|
||||
};
|
||||
|
||||
class AssetManager {
|
||||
public:
|
||||
AssetManager();
|
||||
~AssetManager() {
|
||||
RemoveAllLibraries();
|
||||
}
|
||||
|
||||
// Test if given file is main data file
|
||||
static bool IsDataFile(const String &data_file);
|
||||
// Read data file table of contents into provided struct
|
||||
static AssetError ReadDataFileTOC(const String &data_file, AssetLibInfo &lib);
|
||||
|
||||
// Sets asset search priority (in which order manager will search available locations)
|
||||
void SetSearchPriority(AssetSearchPriority priority);
|
||||
// Gets current asset search priority
|
||||
AssetSearchPriority GetSearchPriority() const;
|
||||
|
||||
// Add library location to the list of asset locations
|
||||
AssetError AddLibrary(const String &path, const AssetLibInfo **lib = nullptr);
|
||||
// Add library location, specifying comma-separated list of filters;
|
||||
// if library was already added before, this method will overwrite the filters only
|
||||
AssetError AddLibrary(const String &path, const String &filters, const AssetLibInfo **lib = nullptr);
|
||||
// Remove library location from the list of asset locations
|
||||
void RemoveLibrary(const String &path);
|
||||
// Removes all libraries
|
||||
void RemoveAllLibraries();
|
||||
|
||||
size_t GetLibraryCount() const;
|
||||
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);
|
||||
}
|
||||
// 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;
|
||||
// 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;
|
||||
// Open asset stream, providing a single filter to search in matching libraries
|
||||
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;
|
||||
};
|
||||
|
||||
// Loads library and registers its contents into the cache
|
||||
AssetError RegisterAssetLib(const String &path, AssetLibEx *&lib);
|
||||
|
||||
// Tries to find asset in the given location, and then opens a stream for reading
|
||||
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;
|
||||
|
||||
AssetSearchPriority _libsPriority = kAssetPriorityDir;
|
||||
// Sorting function, depends on priority setting
|
||||
bool (*_libsSorter)(const AssetLibInfo *, const AssetLibInfo *);
|
||||
};
|
||||
|
||||
String GetAssetErrorText(AssetError err);
|
||||
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
} // namespace AGS3
|
||||
|
||||
#endif
|
||||
34
engines/ags/shared/core/def_version.h
Normal file
34
engines/ags/shared/core/def_version.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AGS_SHARED_CORE_DEFVERSION_H
|
||||
#define AGS_SHARED_CORE_DEFVERSION_H
|
||||
|
||||
#define ACI_VERSION_STR "3.6.1.33"
|
||||
#if defined (RC_INVOKED) // for MSVC resource compiler
|
||||
#define ACI_VERSION_MSRC_DEF 3.6.1.33
|
||||
#endif
|
||||
|
||||
#define SPECIAL_VERSION ""
|
||||
|
||||
#define ACI_COPYRIGHT_YEARS "2011-2025"
|
||||
|
||||
#endif
|
||||
164
engines/ags/shared/core/platform.h
Normal file
164
engines/ags/shared/core/platform.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AGS_SHARED_CORE_PLATFORM_H
|
||||
#define AGS_SHARED_CORE_PLATFORM_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
|
||||
namespace AGS3 {
|
||||
|
||||
// platform definitions. Not intended for replacing types or checking for libraries.
|
||||
|
||||
// ScummVM implementation is identifying as Linux for now
|
||||
#if 1
|
||||
#define AGS_PLATFORM_SCUMMVM (1)
|
||||
#define AGS_PLATFORM_OS_WINDOWS (0)
|
||||
#define AGS_PLATFORM_OS_LINUX (1)
|
||||
#define AGS_PLATFORM_OS_MACOS (0)
|
||||
#define AGS_PLATFORM_OS_ANDROID (0)
|
||||
#define AGS_PLATFORM_OS_IOS (0)
|
||||
#define AGS_PLATFORM_OS_PSP (0)
|
||||
#define AGS_PLATFORM_OS_EMSCRIPTEN (0)
|
||||
// check Android first because sometimes it can get confused with host OS
|
||||
#elif defined(__ANDROID__) || defined(ANDROID)
|
||||
#define AGS_PLATFORM_SCUMMVM (0)
|
||||
#define AGS_PLATFORM_OS_WINDOWS (0)
|
||||
#define AGS_PLATFORM_OS_LINUX (0)
|
||||
#define AGS_PLATFORM_OS_MACOS (0)
|
||||
#define AGS_PLATFORM_OS_ANDROID (1)
|
||||
#define AGS_PLATFORM_OS_IOS (0)
|
||||
#define AGS_PLATFORM_OS_PSP (0)
|
||||
#elif defined(_WIN32)
|
||||
//define something for Windows (32-bit and 64-bit)
|
||||
#define AGS_PLATFORM_SCUMMVM (0)
|
||||
#define AGS_PLATFORM_OS_WINDOWS (1)
|
||||
#define AGS_PLATFORM_OS_LINUX (0)
|
||||
#define AGS_PLATFORM_OS_MACOS (0)
|
||||
#define AGS_PLATFORM_OS_ANDROID (0)
|
||||
#define AGS_PLATFORM_OS_IOS (0)
|
||||
#define AGS_PLATFORM_OS_PSP (0)
|
||||
#elif defined(__APPLE__)
|
||||
#define AGS_PLATFORM_SCUMMVM (0)
|
||||
#include "ags/shared/ags/shared/TargetConditionals.h"
|
||||
#ifndef TARGET_OS_SIMULATOR
|
||||
#define TARGET_OS_SIMULATOR (0)
|
||||
#endif
|
||||
#ifndef TARGET_OS_IOS
|
||||
#define TARGET_OS_IOS (0)
|
||||
#endif
|
||||
#ifndef TARGET_OS_OSX
|
||||
#define TARGET_OS_OSX (0)
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_SIMULATOR || TARGET_IPHONE_SIMULATOR
|
||||
#define AGS_PLATFORM_OS_WINDOWS (0)
|
||||
#define AGS_PLATFORM_OS_LINUX (0)
|
||||
#define AGS_PLATFORM_OS_MACOS (0)
|
||||
#define AGS_PLATFORM_OS_ANDROID (0)
|
||||
#define AGS_PLATFORM_OS_IOS (1)
|
||||
#define AGS_PLATFORM_OS_PSP (0)
|
||||
#elif TARGET_OS_IOS || TARGET_OS_IPHONE
|
||||
#define AGS_PLATFORM_OS_WINDOWS (0)
|
||||
#define AGS_PLATFORM_OS_LINUX (0)
|
||||
#define AGS_PLATFORM_OS_MACOS (0)
|
||||
#define AGS_PLATFORM_OS_ANDROID (0)
|
||||
#define AGS_PLATFORM_OS_IOS (1)
|
||||
#define AGS_PLATFORM_OS_PSP (0)
|
||||
#elif TARGET_OS_OSX || TARGET_OS_MAC
|
||||
#define AGS_PLATFORM_OS_WINDOWS (0)
|
||||
#define AGS_PLATFORM_OS_LINUX (0)
|
||||
#define AGS_PLATFORM_OS_MACOS (1)
|
||||
#define AGS_PLATFORM_OS_ANDROID (0)
|
||||
#define AGS_PLATFORM_OS_IOS (0)
|
||||
#define AGS_PLATFORM_OS_PSP (0)
|
||||
#else
|
||||
#error "Unknown Apple platform"
|
||||
#endif
|
||||
#elif defined(__linux__)
|
||||
#define AGS_PLATFORM_OS_WINDOWS (0)
|
||||
#define AGS_PLATFORM_OS_LINUX (1)
|
||||
#define AGS_PLATFORM_OS_MACOS (0)
|
||||
#define AGS_PLATFORM_OS_ANDROID (0)
|
||||
#define AGS_PLATFORM_OS_IOS (0)
|
||||
#define AGS_PLATFORM_OS_PSP (0)
|
||||
#else
|
||||
#error "Unknown platform"
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define AGS_PLATFORM_WINDOWS_MINGW (1)
|
||||
#else
|
||||
#define AGS_PLATFORM_WINDOWS_MINGW (0)
|
||||
#endif
|
||||
|
||||
#if defined(__LP64__)
|
||||
// LP64 machine, macOS or Linux
|
||||
// int 32bit | long 64bit | long long 64bit | void* 64bit
|
||||
#define AGS_PLATFORM_64BIT (1)
|
||||
#elif defined(_WIN64)
|
||||
// LLP64 machine, Windows
|
||||
// int 32bit | long 32bit | long long 64bit | void* 64bit
|
||||
#define AGS_PLATFORM_64BIT (1)
|
||||
#else
|
||||
// 32-bit machine, Windows or Linux or macOS
|
||||
// int 32bit | long 32bit | long long 64bit | void* 32bit
|
||||
#define AGS_PLATFORM_64BIT (0)
|
||||
#endif
|
||||
|
||||
#if defined(SCUMM_LITTLE_ENDIAN)
|
||||
#define AGS_PLATFORM_ENDIAN_LITTLE (1)
|
||||
#define AGS_PLATFORM_ENDIAN_BIG (0)
|
||||
#elif defined(SCUMM_BIG_ENDIAN)
|
||||
#define AGS_PLATFORM_ENDIAN_LITTLE (0)
|
||||
#define AGS_PLATFORM_ENDIAN_BIG (1)
|
||||
#else
|
||||
#error "No endianness defined"
|
||||
#endif
|
||||
|
||||
#if defined(SCUMM_NEED_ALIGNMENT)
|
||||
#define AGS_STRICT_ALIGNMENT
|
||||
#endif
|
||||
|
||||
#define AGS_PLATFORM_DESKTOP ((AGS_PLATFORM_OS_WINDOWS) || (AGS_PLATFORM_OS_LINUX) || (AGS_PLATFORM_OS_MACOS))
|
||||
|
||||
#define AGS_PLATFORM_MOBILE ((AGS_PLATFORM_OS_ANDROID) || (AGS_PLATFORM_OS_IOS))
|
||||
|
||||
#define AGS_HAS_DIRECT3D (AGS_PLATFORM_OS_WINDOWS)
|
||||
#define AGS_HAS_OPENGL ((AGS_PLATFORM_OS_WINDOWS) || (AGS_PLATFORM_OS_LINUX) || (AGS_PLATFORM_MOBILE))
|
||||
#define AGS_OPENGL_ES2 (AGS_PLATFORM_OS_ANDROID)
|
||||
|
||||
// Only allow searching around for game data on desktop systems;
|
||||
// otherwise use explicit argument either from program wrapper, command-line
|
||||
// or read from default config.
|
||||
#define AGS_SEARCH_FOR_GAME_ON_LAUNCH ((AGS_PLATFORM_OS_WINDOWS) || (AGS_PLATFORM_OS_LINUX) || (AGS_PLATFORM_OS_MACOS))
|
||||
|
||||
#if !defined(DEBUG_MANAGED_OBJECTS)
|
||||
#define DEBUG_MANAGED_OBJECTS (0)
|
||||
#endif
|
||||
|
||||
#if !defined(DEBUG_SPRITECACHE)
|
||||
#define DEBUG_SPRITECACHE (0)
|
||||
#endif
|
||||
|
||||
} // namespace AGS3
|
||||
|
||||
#endif
|
||||
134
engines/ags/shared/core/types.h
Normal file
134
engines/ags/shared/core/types.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Basic types definition
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef AGS_SHARED_CORE_TYPES_H
|
||||
#define AGS_SHARED_CORE_TYPES_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "ags/lib/std.h"
|
||||
|
||||
namespace AGS3 {
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL nullptr
|
||||
#endif
|
||||
|
||||
// Not all compilers have this. Added in clang and gcc followed
|
||||
#ifndef __has_attribute
|
||||
#define __has_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#ifndef FORCEINLINE
|
||||
#ifdef _MSC_VER
|
||||
#define FORCEINLINE __forceinline
|
||||
|
||||
#elif defined (__GNUC__) || __has_attribute(__always_inline__)
|
||||
#define FORCEINLINE inline __attribute__((__always_inline__))
|
||||
|
||||
#else
|
||||
#define FORCEINLINE inline
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint8 uint8_t;
|
||||
typedef uint16 uint16_t;
|
||||
typedef uint32 uint32_t;
|
||||
typedef uint64 uint64_t;
|
||||
typedef int8 int8_t;
|
||||
typedef int16 int16_t;
|
||||
typedef int32 int32_t;
|
||||
typedef int64 int64_t;
|
||||
|
||||
typedef int64 soff_t; // Stream offset type
|
||||
typedef int64 intptr_t;
|
||||
typedef uint64 uintptr_t;
|
||||
|
||||
// fixed point type
|
||||
#define fixed_t int32_t
|
||||
#define color_t int
|
||||
|
||||
#undef INT16_MIN
|
||||
#undef INT16_MAX
|
||||
#undef UINT16_MAX
|
||||
#undef INT32_MIN
|
||||
#undef INT32_MAX
|
||||
#undef INT_MIN
|
||||
#undef INT_MAX
|
||||
#undef UINT32_MAX
|
||||
#undef UINT_MAX
|
||||
#undef SIZE_MAX
|
||||
#define INT16_MIN -32768
|
||||
#define INT16_MAX 0x7fff
|
||||
#define UINT16_MAX 0xffff
|
||||
#define INT32_MIN (-2147483647 - 1)
|
||||
#define INT32_MAX 2147483647
|
||||
#define INT_MIN (-2147483647 - 1)
|
||||
#define INT_MAX 2147483647
|
||||
#define UINT_MAX 0xffffffff
|
||||
#define SIZE_MAX 0xffffffff
|
||||
#define UINT32_MAX 0xffffffff
|
||||
|
||||
#undef TRUE
|
||||
#undef FALSE
|
||||
#define TRUE true
|
||||
#define FALSE false
|
||||
|
||||
// TODO: use distinct fixed point class
|
||||
enum {
|
||||
kShift = 16,
|
||||
kUnit = 1 << kShift
|
||||
};
|
||||
|
||||
/**
|
||||
* Basic class that can hold either a number or a pointer. Helps avoid some
|
||||
* of the more nasty casts the codebase does, which was causing issues
|
||||
* on 64-bit systems
|
||||
*/
|
||||
class NumberPtr {
|
||||
intptr_t _value;
|
||||
|
||||
public:
|
||||
NumberPtr() : _value(0) {
|
||||
}
|
||||
NumberPtr(int value) : _value(value) {
|
||||
}
|
||||
NumberPtr(void *ptr) : _value((intptr_t)ptr) {
|
||||
}
|
||||
NumberPtr(const void *ptr) : _value((intptr_t)ptr) {
|
||||
}
|
||||
operator int32_t() const {
|
||||
return (int32_t)_value;
|
||||
}
|
||||
intptr_t full() const { return _value; }
|
||||
void *ptr() const { return (void *)_value; }
|
||||
const void *cptr() const { return (const void *)_value; }
|
||||
};
|
||||
|
||||
} // namespace AGS3
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user