Reduces some overhead from creating AngelScript array for Pokemon.GetTypes()
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-01 17:13:30 +01:00
parent 72df9ba01a
commit cec9f0907f
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 16 additions and 11 deletions

View File

@ -53,19 +53,24 @@ void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender) ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender)
CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) {
static asITypeInfo* _uint8TypeInfo = nullptr;
static CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) {
if (_uint8TypeInfo == nullptr){
asIScriptContext* ctx = asGetActiveContext(); asIScriptContext* ctx = asGetActiveContext();
if (ctx) { if (!ctx) {
return nullptr;
}
asIScriptEngine* engine = ctx->GetEngine(); asIScriptEngine* engine = ctx->GetEngine();
asITypeInfo* t = engine->GetTypeInfoByDecl("array<uint8>"); _uint8TypeInfo = engine->GetTypeInfoByDecl("array<uint8>");
}
auto a = obj->GetTypes(); auto a = obj->GetTypes();
CScriptArray* arr = CScriptArray::Create(t, a.size()); CScriptArray* arr = CScriptArray::Create(_uint8TypeInfo, a.size());
for (size_t i = 0; i < a.size(); i++){ for (size_t i = 0; i < a.size(); i++){
arr->SetValue(i, &a[i]); arr->SetValue(i, &a[i]);
} }
return arr; return arr;
}
return nullptr;
} }
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {