Update to newer CreatureLib.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-07-04 15:50:30 +02:00
parent 698bc62b47
commit 7f1bc252ba
49 changed files with 207 additions and 237 deletions

View File

@@ -124,8 +124,9 @@ void AngelScriptResolver::MessageCallback(const asSMessageInfo* msg, void* param
printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}
CreatureLib::Battling::Script* AngelScriptResolver::LoadScript(ScriptCategory category, const ConstString& scriptName) {
ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*> innerDb;
CreatureLib::Battling::Script* AngelScriptResolver::LoadScript(ScriptCategory category,
const ArbUt::StringView& scriptName) {
ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*> innerDb;
if (!_typeDatabase.TryGet(category, innerDb)) {
innerDb.Insert(scriptName, nullptr);
_typeDatabase.Insert(category, innerDb);
@@ -159,16 +160,17 @@ void AngelScriptResolver::FinalizeModule() {
for (size_t m = 0; m < metadata.size(); m++) {
auto data = metadata[m];
if (std::regex_match(data, base_match, metadataMatcher)) {
auto metadataKind = ArbUt::CaseInsensitiveConstString(base_match[1].str());
auto mt = base_match[1].str();
auto metadataKind = ArbUt::StringView(mt.c_str(), mt.length());
auto metadataVariables = base_match[2].str();
if (!std::regex_match(metadataVariables, base_match, variableMatcher)) {
continue;
}
ConstString effectName;
ArbUt::StringView effectName;
for (size_t variableIndex = 1; variableIndex < base_match.size(); variableIndex += 2) {
if (ArbUt::CaseInsensitiveConstString::GetHash(base_match[variableIndex]) == "effect"_cnc) {
if (ArbUt::StringView::CalculateHash(base_match[variableIndex].str().c_str()) == "effect"_cnc) {
auto val = base_match[variableIndex + 1].str();
effectName = ConstString(val);
effectName = ArbUt::StringView(val.c_str(), val.length());
}
}
if (effectName.Empty()) {
@@ -299,17 +301,18 @@ void AngelScriptResolver::LoadByteCodeFromMemory(uint8_t* byte, size_t size) {
delete stream;
}
void AngelScriptResolver::InitializeByteCode(
asIBinaryStream* stream, const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>>& types) {
asIBinaryStream* stream,
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, uint32_t>>& types) {
auto typeCount = _mainModule->GetObjectTypeCount();
ArbUt::Dictionary<uint32_t, asITypeInfo*> objectTypes;
for (asUINT i = 0; i < typeCount; i++) {
auto t = _mainModule->GetObjectTypeByIndex(i);
objectTypes.Insert(ConstString::GetHash(t->GetName()), t);
objectTypes.Insert(ArbUt::StringView::CalculateHash(t->GetName()), t);
}
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*>> typeDatabase;
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*>> typeDatabase;
for (const auto& innerDb : types) {
ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*> newInnerDb;
ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*> newInnerDb;
for (const auto& val : innerDb.second) {
auto decl = val.second;
auto type = objectTypes[decl];

View File

@@ -20,14 +20,13 @@ private:
static void MessageCallback(const asSMessageInfo* msg, void* param);
static void Print(const std::string& str) { std::cout << str << std::endl; }
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, AngelScriptTypeInfo*>>
_typeDatabase;
ArbUt::Dictionary<ConstString, asITypeInfo*> _baseTypes;
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*>> _typeDatabase;
ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _baseTypes;
void RegisterTypes();
void InitializeByteCode(
asIBinaryStream* stream,
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, uint32_t>>& types);
void
InitializeByteCode(asIBinaryStream* stream,
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, uint32_t>>& types);
public:
~AngelScriptResolver() override {
@@ -45,14 +44,14 @@ public:
void FinalizeModule();
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const ConstString& scriptName) override;
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const ArbUt::StringView& scriptName) override;
void WriteByteCodeToFile(const char* file, bool stripDebugInfo = false);
void LoadByteCodeFromFile(const char* file);
uint8_t* WriteByteCodeToMemory(size_t& size, bool stripDebugInfo = false);
void LoadByteCodeFromMemory(uint8_t*, size_t size);
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, AngelScriptTypeInfo*>>&
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*>>&
GetTypeDatabase() const noexcept {
return _typeDatabase;
}
@@ -70,7 +69,7 @@ public:
Assert(r >= 0);
}
asITypeInfo* GetBaseType(const ConstString& name) {
asITypeInfo* GetBaseType(const ArbUt::StringView& name) {
asITypeInfo* t = nullptr;
if (!_baseTypes.TryGet(name, t)) {
t = this->_engine->GetTypeInfoByDecl(name.c_str());

View File

@@ -66,7 +66,7 @@ void AngelScriptScript::OnRemove() { CALL_HOOK(OnRemove, ); }
void AngelScriptScript::OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) {
CALL_HOOK(OnBeforeTurn, { ctx->SetArgObject(0, (void*)choice); })
}
void AngelScriptScript::ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ConstString* outAttack) {
void AngelScriptScript::ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ArbUt::StringView* outAttack) {
CALL_HOOK(ChangeAttack, {
ctx->SetArgObject(0, (void*)choice);
ctx->SetArgAddress(0, outAttack);

View File

@@ -27,11 +27,9 @@ public:
~AngelScriptScript() override { _obj->Release(); }
[[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetName() const noexcept override {
return _type->GetName();
}
[[nodiscard]] const ArbUt::StringView& GetName() const noexcept override { return _type->GetName(); }
asIScriptFunction* PrepareMethod(const ArbUt::CaseInsensitiveConstString& name, asIScriptContext* ctx) {
asIScriptFunction* PrepareMethod(const ArbUt::BasicStringView& name, asIScriptContext* ctx) {
auto func = _type->GetFunction(name);
ctx->Prepare(func);
ctx->SetObject(_obj);
@@ -47,8 +45,7 @@ public:
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override;
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice,
ArbUt::CaseInsensitiveConstString* outAttack) override;
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ArbUt::StringView* outAttack) override;
void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override;

View File

@@ -3,7 +3,7 @@
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
#include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/ConstString.hpp>
#include <Arbutils/StringView.hpp>
#include <CreatureLib/Library/Exceptions/CreatureException.hpp>
#include <angelscript.h>
#include <cstring>
@@ -14,7 +14,7 @@ class AngelScriptTypeInfo {
private:
asITypeInfo* _type = nullptr;
ArbUt::Dictionary<uint32_t, asIScriptFunction*> _functions;
ArbUt::CaseInsensitiveConstString _name;
ArbUt::StringView _name;
struct FunctionInfo {
bool Exists = false;
@@ -33,8 +33,8 @@ private:
}
public:
explicit AngelScriptTypeInfo(const ArbUt::CaseInsensitiveConstString& name, asITypeInfo* type)
: _type(type), _name(name) {}
explicit AngelScriptTypeInfo(const ArbUt::StringView& name, asITypeInfo* type) : _type(type), _name(name) {}
~AngelScriptTypeInfo() {
for (const auto& f : _functions) {
f.second->Release();
@@ -42,11 +42,11 @@ public:
_functions.Clear();
}
const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
const ArbUt::StringView& GetName() const noexcept { return _name; }
const char* GetDecl() { return _type->GetName(); }
asIScriptFunction* GetFunction(const ArbUt::CaseInsensitiveConstString& functionName) {
asIScriptFunction* GetFunction(const ArbUt::BasicStringView& functionName) {
asIScriptFunction* func;
if (_functions.TryGet(functionName, func)) {
return func;

View File

@@ -2,7 +2,7 @@
#define PKMNLIB_IPKMNBINARYSTREAM_HPP
#include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/ConstString.hpp>
#include <Arbutils/StringView.hpp>
#include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp>
#include <angelscript.h>
@@ -13,8 +13,8 @@ protected:
IPkmnBinaryStream(size_t angelScriptBound) : _angelScriptBound(angelScriptBound) {}
public:
virtual void
WriteTypes(const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*>>& types) {
virtual void WriteTypes(
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*>>& types) {
// We serialize our types in the format
// "[category(byte)][name(str)]\2[decl(str)]\2[name(str)]\2[decl(str)]\1[category(byte)]...."
@@ -38,9 +38,9 @@ public:
Write("\1", sizeof(char));
}
}
virtual ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>> ReadTypes() {
virtual ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, uint32_t>> ReadTypes() {
_angelScriptBound = SIZE_MAX;
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>> types;
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, uint32_t>> types;
ScriptCategory categoryArr[1];
while (true) {
// Every inner database starts with the category, of known size. Read that.
@@ -49,7 +49,7 @@ public:
if (read == 0) {
break;
}
ArbUt::Dictionary<ConstString, uint32_t> innerDb;
ArbUt::Dictionary<ArbUt::StringView, uint32_t> innerDb;
// We don't know the sizes of the name and decl. Allocate 128 characters for them, as that should be enough.
char name[128];
@@ -68,8 +68,7 @@ public:
if (isDecl) {
// Insert the name and decl into the dictionary. Close off the decl with eof as well.
decl[pos] = '\0';
innerDb.Insert(ArbUt::CaseInsensitiveConstString(name),
ArbUt::CaseInsensitiveConstString::GetHash(decl));
innerDb.Insert(ArbUt::StringView(name), ArbUt::StringView::CalculateHash(decl));
}
// If we have found \1, we are done with the current category, so break.
break;
@@ -80,8 +79,7 @@ public:
if (isDecl) {
// Insert the name and decl into the dictionary. Close off the decl with eof as well.
decl[pos] = '\0';
innerDb.Insert(ArbUt::CaseInsensitiveConstString(name),
ArbUt::CaseInsensitiveConstString::GetHash(decl));
innerDb.Insert(ArbUt::StringView(name), ArbUt::StringView::CalculateHash(decl));
// Reset our position and toggle back to name.
pos = 0;
isDecl = false;

View File

@@ -65,22 +65,22 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void AddVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
asMETHODPR(PkmnLib::Battling::Battle, AddVolatileScript, (const ArbUt::StringView&), void), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
asMETHODPR(PkmnLib::Battling::Battle, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Battle", "void SetWeather(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ConstString&), void),
asCALL_THISCALL);
r = engine->RegisterObjectMethod(
"Battle", "void SetWeather(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), void), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "const constString& GetWeatherName() const",
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::CaseInsensitiveConstString&),
asCALL_THISCALL);
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL);
Assert(r >= 0);
}

View File

@@ -21,10 +21,11 @@ void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("DamageSource");
Assert(r >= 0);
for (auto v : CreatureLib::Battling::DamageSourceHelper::GetValues()) {
r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v), (int)v);
r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v).c_str(),
(int)v);
}
for (auto v : PkmnDamageSourceHelper::GetValues()) {
r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v), (int)v);
r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v).c_str(), (int)v);
}
Assert(r >= 0);
@@ -75,10 +76,12 @@ CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) {
}
return nullptr;
}
static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString& str) {
static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& str) {
return obj->HasHeldItem(str.GetHash());
}
static std::string NicknameWrapper(const PkmnLib::Battling::Pokemon* obj) { return std::string(obj->GetNickname()); }
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies);
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme);
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
@@ -90,7 +93,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asFUNCTION(GetSpeciesWrapper), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", asFUNCTION(GetFormeWrapper),
asCALL_CDECL_OBJLAST);
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL);
@@ -99,7 +102,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asMETHOD(PkmnLib::Battling::Pokemon, GetExperience), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "Gender get_Gender() const property", asFUNCTION(Pkmn_GenderWrapper),
asCALL_CDECL_OBJLAST);
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL);
@@ -108,15 +111,14 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
asFUNCTION(GetHeldItemWrapper), asCALL_CDECL_OBJLAST);
asFUNCTION(GetHeldItemWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const",
asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void SetHeldItem(const string &in name)",
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const ArbUt::CaseInsensitiveConstString&), void),
asCALL_THISCALL);
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const ArbUt::BasicStringView&), void), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const Item@ item)",
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem,
@@ -127,7 +129,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const string& get_Nickname() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetNickname), asCALL_THISCALL);
asFUNCTION(NicknameWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const constString& get_ActiveAbility() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetActiveTalent), asCALL_THISCALL);
@@ -151,7 +153,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const", asFUNCTION(GetMoves),
asCALL_CDECL_OBJLAST);
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)",
asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL);
@@ -176,10 +178,11 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void AddVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ArbUt::StringView&), void), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
asCALL_THISCALL);
Assert(r >= 0);
}

View File

@@ -1,18 +1,18 @@
#include "ConstString.hpp"
using ConstString = ArbUt::CaseInsensitiveConstString;
#include <Arbutils/StringView.hpp>
static void ConstructConstString(void* self) { new (self) ConstString(); }
static void CopyConstructConstString(const ConstString& other, void* self) { new (self) ConstString(other); }
static void DestructConstString(void* self) { ((ConstString*)self)->~ConstString(); }
static bool ConstStringEquality(const ConstString& a, const ConstString& b) { return a == b; }
static bool ConstStringStdStringEquality(const ConstString& a, const std::string& b) { return a == b; }
static ConstString ImplStdStringConstStringConv(const std::string& s) { return ConstString(s); }
static std::string ImplConstStringStdStringConv(const ConstString& s) { return s.std_str(); }
static uint32_t ImplConstStringHashConv(const ConstString& s) { return s.GetHash(); }
static void ConstructConstString(void* self) { new (self) ArbUt::StringView(); }
static void CopyConstructConstString(const ArbUt::StringView& other, void* self) {
new (self) ArbUt::StringView(other);
}
static void DestructConstString(void* self) { ((ArbUt::StringView*)self)->~StringView(); }
static bool ConstStringEquality(const ArbUt::StringView& a, const ArbUt::StringView& b) { return a == b; }
static bool ConstStringStdStringEquality(const ArbUt::StringView& a, const std::string& b) { return a == b; }
static uint32_t ImplConstStringHashConv(const ArbUt::StringView& s) { return s.GetHash(); }
void ConstStringRegister::Register(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("constString", sizeof(ArbUt::CaseInsensitiveConstString),
asOBJ_VALUE | asOBJ_APP_CLASS_CDAK);
auto r = engine->RegisterObjectType("constString", sizeof(ArbUt::StringView),
asOBJ_VALUE | asGetTypeTraits<ArbUt::StringView>());
Assert(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructConstString),
@@ -27,33 +27,24 @@ void ConstStringRegister::Register(asIScriptEngine* engine) {
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("constString", "constString &opAssign(const constString &in)",
asMETHODPR(ConstString, operator=,(const ConstString&), ConstString&),
asCALL_THISCALL);
r = engine->RegisterObjectMethod(
"constString", "constString &opAssign(const constString &in)",
asMETHODPR(ArbUt::StringView, operator=, (const ArbUt::StringView&), ArbUt::StringView&), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("constString", "bool opEquals(const constString &in) const",
asFUNCTIONPR(ConstStringEquality, (const ConstString&, const ConstString&), bool),
asCALL_CDECL_OBJFIRST);
r = engine->RegisterObjectMethod(
"constString", "bool opEquals(const constString &in) const",
asFUNCTIONPR(ConstStringEquality, (const ArbUt::StringView&, const ArbUt::StringView&), bool),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"constString", "bool opEquals(const string &in) const",
asFUNCTIONPR(ConstStringStdStringEquality, (const ConstString&, const std::string&), bool),
asFUNCTIONPR(ConstStringStdStringEquality, (const ArbUt::StringView&, const std::string&), bool),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("string", "constString opImplConv()",
asFUNCTIONPR(ImplStdStringConstStringConv, (const std::string&), ConstString),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("constString", "string opImplConv()",
asFUNCTIONPR(ImplConstStringStdStringConv, (const ConstString&), std::string),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
r = engine->RegisterObjectMethod("constString", "uint opImplConv()",
asFUNCTIONPR(ImplConstStringHashConv, (const ConstString&), uint32_t),
asFUNCTIONPR(ImplConstStringHashConv, (const ArbUt::StringView&), uint32_t),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
}

View File

@@ -1,7 +1,6 @@
#ifndef PKMNLIB_CONSTSTRING_HPP
#define PKMNLIB_CONSTSTRING_HPP
#include <Arbutils/Assert.hpp>
#include <Arbutils/ConstString.hpp>
#include <angelscript.h>
class ConstStringRegister {
public:

View File

@@ -4,16 +4,14 @@
static CreatureLib::Library::EffectParameter* Ref_Factory() { return new CreatureLib::Library::EffectParameter(); }
static const ArbUt::CaseInsensitiveConstString& AsString(const CreatureLib::Library::EffectParameter* p) {
return p->AsString();
}
static const ArbUt::StringView& AsString(const CreatureLib::Library::EffectParameter* p) { return p->AsString(); }
void RegisterEffectParameter::Register(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("EffectParameterType");
Assert(r >= 0);
for (auto val : CreatureLib::Library::EffectParameterTypeHelper::GetValues()) {
r = engine->RegisterEnumValue("EffectParameterType",
CreatureLib::Library::EffectParameterTypeHelper::ToString(val), (int)val);
CreatureLib::Library::EffectParameterTypeHelper::ToString(val).c_str(), (int)val);
Assert(r >= 0);
}
@@ -36,9 +34,9 @@ void RegisterEffectParameter::Register(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("EffectParameter", "float AsFloat() const",
asMETHOD(CreatureLib::Library::EffectParameter, AsFloat), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("EffectParameter", "const constString& AsString() const",
asFUNCTIONPR(AsString, (const CreatureLib::Library::EffectParameter*),
const ArbUt::CaseInsensitiveConstString&),
asCALL_CDECL_OBJFIRST);
r = engine->RegisterObjectMethod(
"EffectParameter", "const constString& AsString() const",
asFUNCTIONPR(AsString, (const CreatureLib::Library::EffectParameter*), const ArbUt::StringView&),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
}

View File

@@ -18,11 +18,11 @@ void RegisterGrowthRateTypes::RegisterGrowthRateType(asIScriptEngine* engine) {
assert(r >= 0);
}
static uint8_t CalculateLevel(const CreatureLib::Library::GrowthRateLibrary* obj, const ConstString& str,
static uint8_t CalculateLevel(const CreatureLib::Library::GrowthRateLibrary* obj, const ArbUt::StringView& str,
uint32_t experience) {
return obj->CalculateLevel(str, experience);
}
static uint32_t CalculateExperience(const CreatureLib::Library::GrowthRateLibrary* obj, const ConstString& str,
static uint32_t CalculateExperience(const CreatureLib::Library::GrowthRateLibrary* obj, const ArbUt::StringView& str,
uint8_t level) {
return obj->CalculateExperience(str, level);
}

View File

@@ -58,9 +58,7 @@ void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine)
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::Item, GetCategory)
ENUM__SIZE_WRAPPER(Move_BattleCategoryWrapper, PkmnLib::Library::Item, GetBattleCategory)
static bool HasFlag(const PkmnLib::Library::Item* obj, const ArbUt::CaseInsensitiveConstString& str) {
return obj->HasFlag(str);
}
static bool HasFlag(const PkmnLib::Library::Item* obj, const ArbUt::BasicStringView& str) { return obj->HasFlag(str); }
void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT);

View File

@@ -1,5 +1,5 @@
#include "RegisterMoveTypes.hpp"
#include <cassert>
#include <Arbutils/Assert.hpp>
#include "../../../../Library/Moves/MoveData.hpp"
#include "../../../../Library/Moves/MoveLibrary.hpp"
@@ -12,11 +12,11 @@ void RegisterMoveTypes::Register(asIScriptEngine* engine) {
#define REGISTER_ENUM_VALUE(asName, cName, valueName) \
r = engine->RegisterEnumValue(#asName, #valueName, (int)cName::valueName); \
assert(r >= 0);
Assert(r >= 0);
void RegisterMoveTypes::RegisterMoveCategory(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("MoveCategory");
assert(r >= 0);
Assert(r >= 0);
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Physical)
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Special)
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Status)
@@ -24,7 +24,7 @@ void RegisterMoveTypes::RegisterMoveCategory(asIScriptEngine* engine) {
void RegisterMoveTypes::RegisterMoveTarget(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("MoveTarget");
assert(r >= 0);
Assert(r >= 0);
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, Adjacent)
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AdjacentAlly)
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AdjacentAllySelf)
@@ -46,47 +46,47 @@ void RegisterMoveTypes::RegisterMoveTarget(asIScriptEngine* engine) {
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::MoveData, GetCategory)
ENUM__SIZE_WRAPPER(Move_TargetWrapper, PkmnLib::Library::MoveData, GetTarget)
static bool HasFlag(const PkmnLib::Library::MoveData* obj, const ArbUt::CaseInsensitiveConstString& str) {
static bool HasFlag(const PkmnLib::Library::MoveData* obj, const ArbUt::BasicStringView& str) {
return obj->HasFlag(str);
}
void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveData", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::MoveData, GetName), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Type() const property",
asMETHOD(PkmnLib::Library::MoveData, GetType), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "MoveCategory get_Category() const property",
asFUNCTION(Move_CategoryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BasePower() const property",
asMETHOD(PkmnLib::Library::MoveData, GetBasePower), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Accuracy() const property",
asMETHOD(PkmnLib::Library::MoveData, GetAccuracy), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BaseUsages() const property",
asMETHOD(PkmnLib::Library::MoveData, GetBaseUsages), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "MoveTarget get_Target() const property",
asFUNCTION(Move_TargetWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
asCALL_CDECL_OBJLAST);
assert(r >= 0);
Assert(r >= 0);
}
void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveLibrary", "const MoveData@ Get(const constString &in name) const",
asMETHOD(PkmnLib::Library::MoveLibrary, Get), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
}
#undef REGISTER_ENUM_VALUE

View File

@@ -43,7 +43,7 @@ void RegisterSpeciesTypes::RegisterStatisticEnum(asIScriptEngine* engine) {
static const PkmnLib::Library::PokemonForme* GetFormeWrapper(const std::string& s,
const PkmnLib::Library::PokemonSpecies* species) {
return species->GetForme(ArbUt::CaseInsensitiveConstString(s.c_str(), s.length()))
return species->GetForme(ArbUt::StringView(s.c_str(), s.length()))
.As<const PkmnLib::Library::PokemonForme>()
.GetRaw();
}
@@ -75,7 +75,7 @@ void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
assert(r >= 0);
}
const ArbUt::CaseInsensitiveConstString& GetAbility(PkmnLib::Library::PokemonForme* p, bool hidden, uint8_t index) {
const ArbUt::StringView& GetAbility(PkmnLib::Library::PokemonForme* p, bool hidden, uint8_t index) {
return p->GetAbility(CreatureLib::Library::TalentIndex(hidden, index));
}
@@ -106,7 +106,7 @@ void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Forme", "const constString& GetAbility(bool hidden, uint8 index) const",
asFUNCTIONPR(GetAbility,
(PkmnLib::Library::PokemonForme * p, bool hidden, uint8_t index),
const ArbUt::CaseInsensitiveConstString&),
const ArbUt::StringView&),
asCALL_CDECL_OBJFIRST);
assert(r >= 0);
}

View File

@@ -4,7 +4,7 @@
void RegisterTypeLibrary::Register(asIScriptEngine* engine) { RegisterTypeLibraryType(engine); }
static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const ArbUt::CaseInsensitiveConstString& str) {
static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const ArbUt::BasicStringView& str) {
return obj->GetTypeId(str);
}