From e04ab6497a10d302ae197c6340cf98c9476dfa2f Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 2 Feb 2020 11:01:49 +0100 Subject: [PATCH] Revert "Reduces some overhead from creating AngelScript array for Pokemon.GetTypes()" This reverts commit cec9f090, as it doesn't account for multiple different script engines --- .../Battling/RegisterPokemonClass.cpp | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index f3c5344..362ee44 100644 --- a/src/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -53,24 +53,19 @@ void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) { ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender) - -static asITypeInfo* _uint8TypeInfo = nullptr; -static CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) { - if (_uint8TypeInfo == nullptr){ - asIScriptContext* ctx = asGetActiveContext(); - if (!ctx) { - return nullptr; - } +CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) { + asIScriptContext* ctx = asGetActiveContext(); + if (ctx) { asIScriptEngine* engine = ctx->GetEngine(); - _uint8TypeInfo = engine->GetTypeInfoByDecl("array"); + asITypeInfo* t = engine->GetTypeInfoByDecl("array"); + auto a = obj->GetTypes(); + CScriptArray* arr = CScriptArray::Create(t, a.size()); + for (size_t i = 0; i < a.size(); i++){ + arr->SetValue(i, &a[i]); + } + return arr; } - - auto a = obj->GetTypes(); - CScriptArray* arr = CScriptArray::Create(_uint8TypeInfo, a.size()); - for (size_t i = 0; i < a.size(); i++){ - arr->SetValue(i, &a[i]); - } - return arr; + return nullptr; } void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {