mirror of https://github.com/AxioDL/metaforce.git
AngelScript UniqueModule type
This commit is contained in:
parent
4252bd6e39
commit
050085cc6d
|
@ -30,7 +30,7 @@ public:
|
||||||
HECL::Database::IDataSpec* ds = entry->m_factory(HECL::Database::TOOL_EXTRACT);
|
HECL::Database::IDataSpec* ds = entry->m_factory(HECL::Database::TOOL_EXTRACT);
|
||||||
if (ds)
|
if (ds)
|
||||||
{
|
{
|
||||||
if (ds->canExtract(m_einfo, m_reps))
|
if (ds->canExtract(*m_info.project, m_einfo, m_reps))
|
||||||
m_dataSpecs.emplace_back(ds);
|
m_dataSpecs.emplace_back(ds);
|
||||||
else
|
else
|
||||||
delete ds;
|
delete ds;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 94a6707dd32e6aed988c7606c6c28836a398ad6d
|
Subproject commit 94d84d8991dd0c6b5fdb5557476eb4c3421d7b09
|
|
@ -12,6 +12,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <fstream>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
@ -110,11 +111,46 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ASStringType : ASType<std::string>
|
struct ASStringType : ASType<std::string>
|
||||||
{
|
{ASStringType();};
|
||||||
ASStringType();
|
|
||||||
};
|
|
||||||
extern ASStringType asSTRINGTYPE;
|
extern ASStringType asSTRINGTYPE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief AngelScript Module Wrapper designed for HECL usage
|
||||||
|
*
|
||||||
|
* Behaves similarly to unique_ptr. Move construction/assignment only
|
||||||
|
* Implicit conversion is supplied for seamless usage as a module reference
|
||||||
|
*/
|
||||||
|
class ASUniqueModule
|
||||||
|
{
|
||||||
|
AngelScript::asIScriptModule* m_mod;
|
||||||
|
ASUniqueModule() {m_mod = nullptr;}
|
||||||
|
ASUniqueModule(AngelScript::asIScriptModule* mod) : m_mod(mod) {}
|
||||||
|
public:
|
||||||
|
~ASUniqueModule() {if (m_mod) m_mod->Discard();}
|
||||||
|
ASUniqueModule(ASUniqueModule&& other) = default;
|
||||||
|
ASUniqueModule(ASUniqueModule& other) = delete;
|
||||||
|
ASUniqueModule& operator=(ASUniqueModule&& other) = default;
|
||||||
|
ASUniqueModule& operator=(ASUniqueModule& other) = delete;
|
||||||
|
inline operator AngelScript::asIScriptModule&() {return *m_mod;}
|
||||||
|
inline operator bool() {return m_mod != nullptr;}
|
||||||
|
static ASUniqueModule CreateFromCode(const char* module, const char* code)
|
||||||
|
{
|
||||||
|
AngelScript::asIScriptModule* mod = asENGINE->GetModule(module, AngelScript::asGM_ALWAYS_CREATE);
|
||||||
|
assert(mod);
|
||||||
|
assert(mod->AddScriptSection(module, code) >= 0);
|
||||||
|
if (mod->Build() >= 0)
|
||||||
|
return ASUniqueModule(mod);
|
||||||
|
else
|
||||||
|
return ASUniqueModule();
|
||||||
|
}
|
||||||
|
static ASUniqueModule CreateFromPath(const ProjectPath& path)
|
||||||
|
{
|
||||||
|
std::string asStr;
|
||||||
|
std::ifstream(path.getAbsolutePath()) >> asStr;
|
||||||
|
return CreateFromCode(path.getRelativePathUTF8().c_str(), asStr.c_str());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
extern LogVisor::LogModule LogModule;
|
extern LogVisor::LogModule LogModule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,9 +215,9 @@ public:
|
||||||
std::vector<ExtractReport> childOpts;
|
std::vector<ExtractReport> childOpts;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool canExtract(const ExtractPassInfo& info, std::vector<ExtractReport>& reps)
|
virtual bool canExtract(Project& project, const ExtractPassInfo& info, std::vector<ExtractReport>& reps)
|
||||||
{(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}
|
{(void)project;(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}
|
||||||
virtual void doExtract(const Project& project, const ExtractPassInfo& info)
|
virtual void doExtract(Project& project, const ExtractPassInfo& info)
|
||||||
{(void)project;(void)info;}
|
{(void)project;(void)info;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -294,7 +330,7 @@ protected:
|
||||||
typedef std::function<void(const void* data, size_t len)> FDataAppender;
|
typedef std::function<void(const void* data, size_t len)> FDataAppender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Optional private method implemented by CProjectObject subclasses to cook objects
|
* @brief Optional private method implemented by subclasses to cook objects
|
||||||
* @param dataAppender subclass calls this function zero or more times to provide cooked-data linearly
|
* @param dataAppender subclass calls this function zero or more times to provide cooked-data linearly
|
||||||
* @param endianness byte-order to target
|
* @param endianness byte-order to target
|
||||||
* @param platform data-formats to target
|
* @param platform data-formats to target
|
||||||
|
@ -304,8 +340,8 @@ protected:
|
||||||
* Part of the cooking process may include embedding database-refs to dependencies.
|
* Part of the cooking process may include embedding database-refs to dependencies.
|
||||||
* This method should store the 64-bit value provided by IDataObject::id() when doing this.
|
* This method should store the 64-bit value provided by IDataObject::id() when doing this.
|
||||||
*/
|
*/
|
||||||
virtual bool _cookObject(FDataAppender dataAppender,
|
virtual bool cookObject(FDataAppender dataAppender,
|
||||||
DataEndianness endianness, DataPlatform platform)
|
DataEndianness endianness, DataPlatform platform)
|
||||||
{(void)dataAppender;(void)endianness;(void)platform;return true;}
|
{(void)dataAppender;(void)endianness;(void)platform;return true;}
|
||||||
|
|
||||||
typedef std::function<void(ObjectBase*)> FDepAdder;
|
typedef std::function<void(ObjectBase*)> FDepAdder;
|
||||||
|
@ -318,9 +354,16 @@ protected:
|
||||||
* Dependencies registered via this method will eventually have this method called on themselves
|
* Dependencies registered via this method will eventually have this method called on themselves
|
||||||
* as well. This is a non-recursive operation, no need for subclasses to implement recursion-control.
|
* as well. This is a non-recursive operation, no need for subclasses to implement recursion-control.
|
||||||
*/
|
*/
|
||||||
virtual void _gatherDeps(FDepAdder depAdder)
|
virtual void gatherDeps(FDepAdder depAdder)
|
||||||
{(void)depAdder;}
|
{(void)depAdder;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get a packagable FourCC representation of the object's type
|
||||||
|
* @return FourCC of the type
|
||||||
|
*/
|
||||||
|
virtual FourCC getType() const
|
||||||
|
{return FourCC("NULL");}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectBase(const SystemString& path)
|
ObjectBase(const SystemString& path)
|
||||||
: m_path(path) {}
|
: m_path(path) {}
|
||||||
|
|
|
@ -327,7 +327,7 @@ protected:
|
||||||
#endif
|
#endif
|
||||||
ProjectPath() {}
|
ProjectPath() {}
|
||||||
bool _canonAbsPath(const SystemString& path, bool& needsMake);
|
bool _canonAbsPath(const SystemString& path, bool& needsMake);
|
||||||
inline void _makeDir() const {MakeDir(getAbsolutePath());}
|
inline void _makeDir() const {MakeDir(m_absPath);}
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Construct a project subpath representation within another subpath
|
* @brief Construct a project subpath representation within another subpath
|
||||||
|
|
|
@ -8,6 +8,18 @@ namespace Database
|
||||||
/* Centralized AngelScript engine */
|
/* Centralized AngelScript engine */
|
||||||
AngelScript::asIScriptEngine* asENGINE = nullptr;
|
AngelScript::asIScriptEngine* asENGINE = nullptr;
|
||||||
|
|
||||||
|
/* AngelScript Logger */
|
||||||
|
static LogVisor::LogModule Log("AngelScript");
|
||||||
|
static void MessageCallback(const AngelScript::asSMessageInfo* msg, void*)
|
||||||
|
{
|
||||||
|
LogVisor::Level lv = LogVisor::Error;
|
||||||
|
if (msg->type == AngelScript::asMSGTYPE_WARNING)
|
||||||
|
lv = LogVisor::Warning;
|
||||||
|
else if (msg->type == AngelScript::asMSGTYPE_INFORMATION)
|
||||||
|
lv = LogVisor::Info;
|
||||||
|
Log.reportSource(lv, msg->section, msg->row, msg->message);
|
||||||
|
}
|
||||||
|
|
||||||
static bool InitEntered = false;
|
static bool InitEntered = false;
|
||||||
void InitASEngine()
|
void InitASEngine()
|
||||||
{
|
{
|
||||||
|
@ -15,6 +27,8 @@ void InitASEngine()
|
||||||
return;
|
return;
|
||||||
InitEntered = true;
|
InitEntered = true;
|
||||||
assert(asENGINE = AngelScript::asCreateScriptEngine(ANGELSCRIPT_VERSION));
|
assert(asENGINE = AngelScript::asCreateScriptEngine(ANGELSCRIPT_VERSION));
|
||||||
|
assert(asENGINE->SetEngineProperty(AngelScript::asEP_COPY_SCRIPT_SECTIONS, false) >= 0);
|
||||||
|
assert(asENGINE->SetMessageCallback(AngelScript::asFUNCTION(MessageCallback), nullptr, AngelScript::asCALL_CDECL) >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue