Adds caching for expensive type resolution.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-09-22 19:02:01 +02:00
parent 7e9e574577
commit e5ea2bbc90
22 changed files with 124 additions and 42 deletions

View File

@@ -9,8 +9,10 @@
#include "../../Battling/PkmnScriptCategory.hpp"
#include "../../Battling/Pokemon/Pokemon.hpp"
#include "AngelScriptMetadata.hpp"
#include "AngelscriptUserdata.hpp"
#include "ByteCodeHandling/FileByteCodeStream.hpp"
#include "ByteCodeHandling/MemoryByteCodeStream.hpp"
#include "ContextPool.hpp"
#include "TypeRegistry/BasicScriptClass.hpp"
#include "TypeRegistry/Battling/RegisterBattleClass.hpp"
#include "TypeRegistry/Battling/RegisterBattleLibrary.hpp"
@@ -48,6 +50,22 @@ static void TranslateException(asIScriptContext* ctx, void* /*userParam*/) {
}
}
AngelScriptResolver::AngelScriptResolver() : _userData(new AngelscriptUserdata(this)) {}
AngelScriptResolver::~AngelScriptResolver() {
for (const auto& ius : _itemUseScripts) {
delete ius.second;
}
delete _contextPool;
for (const auto& category : _typeDatabase) {
for (const auto& type : category.second) {
delete type.second;
}
}
delete _userData;
_engine->ShutDownAndRelease();
}
void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg, bool includeStandard) {
for (auto scriptCategory : ScriptCategoryHelper::GetValues()) {
_typeDatabase.Insert(scriptCategory, {});
@@ -101,7 +119,7 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg,
_engine->RegisterGlobalProperty("const StaticLibrary@ StaticLib", (void*)staticLib.get());
}
_contextPool = new ContextPool(_engine);
_contextPool = new ContextPool(_engine, _userData);
asPrepareMultithread();
}
@@ -209,6 +227,7 @@ AngelScriptResolver::LoadEvolutionScript(const ArbUt::StringView& view) {
return nullptr;
}
auto* ctx = _contextPool->RequestContext();
auto* factory = typeInfoOption.value().get()->GetFactoryByIndex(0);
ctx->Prepare(factory);
auto result = ctx->Execute();
@@ -441,4 +460,4 @@ i32 AngelScriptResolver::IncludeCallback(const char* include, const char*, CScri
return -102;
}
return builder->AddSectionFromFile((const char*)path.c_str());
}
}