metaforce/Runtime/IFactory.hpp

53 lines
2.4 KiB
C++
Raw Permalink Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2015-08-18 05:54:43 +00:00
2016-09-25 01:58:20 +00:00
#include <functional>
#include <memory>
#include <vector>
#include "Runtime/RetroTypes.hpp"
2015-08-22 01:58:41 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
class CFactoryMgr;
class CObjectReference;
2017-10-26 05:37:46 +00:00
class CResLoader;
class CSimplePool;
class CVParamTransfer;
2017-10-27 10:10:32 +00:00
class IDvdRequest;
class IObj;
2015-08-18 05:54:43 +00:00
2016-04-13 06:07:23 +00:00
using CFactoryFnReturn = std::unique_ptr<IObj>;
2021-06-07 19:29:18 +00:00
using FFactoryFunc =
std::function<CFactoryFnReturn(const metaforce::SObjectTag& tag, metaforce::CInputStream& in,
const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef)>;
using FMemFactoryFunc =
std::function<CFactoryFnReturn(const metaforce::SObjectTag& tag, std::unique_ptr<u8[]>&& in, u32 len,
const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef)>;
2016-04-13 06:07:23 +00:00
2018-12-08 05:30:43 +00:00
class IFactory {
2015-08-22 01:58:41 +00:00
public:
2018-12-08 05:30:43 +00:00
virtual ~IFactory() = default;
virtual CFactoryFnReturn Build(const SObjectTag&, const CVParamTransfer&, CObjectReference*) = 0;
virtual void BuildAsync(const SObjectTag&, const CVParamTransfer&, std::unique_ptr<IObj>*, CObjectReference*) = 0;
virtual void CancelBuild(const SObjectTag&) = 0;
virtual bool CanBuild(const SObjectTag&) = 0;
virtual const SObjectTag* GetResourceIdByName(std::string_view) const = 0;
virtual FourCC GetResourceTypeById(CAssetId id) const = 0;
virtual void EnumerateResources(const std::function<bool(const SObjectTag&)>& lambda) const = 0;
virtual void
EnumerateNamedResources(const std::function<bool(std::string_view, const SObjectTag&)>& lambda) const = 0;
virtual CResLoader* GetResLoader() { return nullptr; }
virtual CFactoryMgr* GetFactoryMgr() { return nullptr; }
virtual bool AsyncIdle(std::chrono::nanoseconds target) { return false; }
2018-12-08 05:30:43 +00:00
/* Non-factory versions, replaces CResLoader */
2021-04-10 08:42:06 +00:00
virtual u32 ResourceSize(const metaforce::SObjectTag& tag) = 0;
virtual std::shared_ptr<IDvdRequest> LoadResourceAsync(const metaforce::SObjectTag& tag, void* target) = 0;
virtual std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const metaforce::SObjectTag& tag, u32 off, u32 size,
2018-12-08 05:30:43 +00:00
void* target) = 0;
2021-04-10 08:42:06 +00:00
virtual std::unique_ptr<u8[]> LoadResourceSync(const metaforce::SObjectTag& tag) = 0;
virtual std::unique_ptr<u8[]> LoadNewResourcePartSync(const metaforce::SObjectTag& tag, u32 off, u32 size) = 0;
2018-12-08 05:30:43 +00:00
virtual void GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const {}
2015-08-18 05:54:43 +00:00
};
2021-04-10 08:42:06 +00:00
} // namespace metaforce