Update to new Arbutils memory model.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-12-12 14:25:27 +01:00
parent b6a5e41b51
commit 53bd6e7a94
19 changed files with 87 additions and 74 deletions

View File

@@ -91,7 +91,7 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg,
_contextPool = new ContextPool(_engine);
}
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle);
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle);
void AngelScriptResolver::RegisterTypes() {
// Register static library types
@@ -129,23 +129,26 @@ void AngelScriptResolver::MessageCallback(const asSMessageInfo* msg, void*) {
CreatureLib::Battling::Script* AngelScriptResolver::LoadScript(ScriptCategory category,
const ArbUt::StringView& scriptName) {
ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*> innerDb;
if (!_typeDatabase.TryGet(category, innerDb)) {
auto v = _typeDatabase.TryGet(category);
if (!v.has_value()) {
innerDb.Insert(scriptName, nullptr);
_typeDatabase.Insert(category, innerDb);
return nullptr;
} else {
innerDb = v.value();
}
AngelScriptTypeInfo* t;
if (!innerDb.TryGet(scriptName, t)) {
auto t = innerDb.TryGet(scriptName);
if (!t.has_value()) {
innerDb.Insert(scriptName, nullptr);
return nullptr;
}
if (t == nullptr) {
if (!t.has_value()) {
return nullptr;
}
auto ctx = _contextPool->RequestContext();
auto obj = t->Instantiate(ctx);
auto obj = const_cast<AngelScriptTypeInfo*>(t.value().get())->Instantiate(ctx);
_contextPool->ReturnContextToPool(ctx);
return new AngelScriptScript(this, t, obj, _contextPool);
return new AngelScriptScript(this, t.value(), obj, _contextPool);
}
void AngelScriptResolver::FinalizeModule() {
int r = _builder.BuildModule();

View File

@@ -70,10 +70,13 @@ public:
}
asITypeInfo* GetBaseType(const ArbUt::StringView& name) {
asITypeInfo* t = nullptr;
if (!_baseTypes.TryGet(name, t)) {
asITypeInfo* t;
auto v = _baseTypes.TryGet(name);
if (!v.has_value()) {
t = this->_engine->GetTypeInfoByDecl(name.c_str());
_baseTypes.Insert(name, t);
} else {
t = v.value();
}
return t;
}

View File

@@ -42,11 +42,11 @@ public:
const char* GetDecl() { return _type->GetName(); }
asIScriptFunction* GetFunction(const ArbUt::BasicStringView& functionName) {
asIScriptFunction* func;
if (_functions.TryGet(functionName, func)) {
return func;
auto v = _functions.TryGet(functionName);
if (v.has_value()) {
return v.value();
}
func = _type->GetMethodByName(functionName.c_str());
auto func = _type->GetMethodByName(functionName.c_str());
if (func != nullptr) {
func->AddRef();
}

View File

@@ -83,7 +83,7 @@ static std::string NicknameWrapper(const PkmnLib::Battling::Pokemon* obj) { retu
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies);
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme);
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);

View File

@@ -1,4 +1,6 @@
#define BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetRaw(); }
#define OPTIONAL_BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetValue(); }
#define UNIQUE_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().get(); }