Very initial work on SpeciesVariant C Interface, slight cleanup of other C Interfaces.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-02-29 17:21:36 +01:00
parent 5f341ffbb7
commit 19316644fc
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
9 changed files with 109 additions and 85 deletions

View File

@ -1,11 +1,12 @@
#include "../../src/Library/AttackLibrary.hpp"
#include "BaseLibrary.cpp"
#define export extern "C"
using namespace CreatureLib::Library;
export const CreatureLib::Library::AttackLibrary* CreatureLib_AttackLibrary_Construct(size_t initialCapacity = 32) {
return new CreatureLib::Library::AttackLibrary(initialCapacity);
export const AttackLibrary* CreatureLib_AttackLibrary_Construct(size_t initialCapacity = 32) {
return new AttackLibrary(initialCapacity);
};
export void CreatureLib_AttackLibrary_Destruct(const CreatureLib::Library::AttackLibrary* p) { delete p; }
export void CreatureLib_AttackLibrary_Destruct(const AttackLibrary* p) { delete p; }
BASELIBRARY(CreatureLib_AttackLibrary, CreatureLib::Library::AttackLibrary, CreatureLib::Library::AttackData);
BASELIBRARY(CreatureLib_AttackLibrary, AttackLibrary, AttackData);

View File

@ -1,52 +1,45 @@
#include "../../src/Library/CreatureData/CreatureSpecies.hpp"
#define export extern "C"
using namespace CreatureLib::Library;
export CreatureLib::Library::CreatureSpecies*
CreatureLib_CreatureSpecies_Construct(uint16_t id, const char* name,
CreatureLib::Library::SpeciesVariant* defaultVariant, float genderRatio,
const char* growthRate, uint8_t captureRate) {
return new CreatureLib::Library::CreatureSpecies(id, Arbutils::CaseInsensitiveConstString(name), defaultVariant,
genderRatio, Arbutils::CaseInsensitiveConstString(growthRate),
captureRate);
export CreatureSpecies* CreatureLib_CreatureSpecies_Construct(uint16_t id, const char* name,
SpeciesVariant* defaultVariant, float genderRatio,
const char* growthRate, uint8_t captureRate) {
return new CreatureSpecies(id, Arbutils::CaseInsensitiveConstString(name), defaultVariant, genderRatio,
Arbutils::CaseInsensitiveConstString(growthRate), captureRate);
}
export void CreatureLib_CreatureSpecies_Destruct(const CreatureLib::Library::CreatureSpecies* p) { delete p; }
export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const CreatureLib::Library::type* p) { return p->name(); }
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
SIMPLE_GET_FUNC(CreatureSpecies, GetId, uint16_t);
SIMPLE_GET_FUNC(CreatureSpecies, GetGenderRate, float);
SIMPLE_GET_FUNC(CreatureSpecies, GetCaptureRate, uint8_t);
export const char* CreatureLib_CreatureSpecies_GetName(const CreatureLib::Library::CreatureSpecies* p) {
return p->GetName().c_str();
}
export const char* CreatureLib_CreatureSpecies_GetGrowthRate(const CreatureLib::Library::CreatureSpecies* p) {
export const char* CreatureLib_CreatureSpecies_GetName(const CreatureSpecies* p) { return p->GetName().c_str(); }
export const char* CreatureLib_CreatureSpecies_GetGrowthRate(const CreatureSpecies* p) {
return p->GetGrowthRate().c_str();
}
export bool CreatureLib_CreatureSpecies_HasVariant(const CreatureLib::Library::CreatureSpecies* p, const char* name) {
export bool CreatureLib_CreatureSpecies_HasVariant(const CreatureSpecies* p, const char* name) {
return p->HasVariant(Arbutils::CaseInsensitiveConstString::GetHash(name));
}
export bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureLib::Library::CreatureSpecies* p,
uint32_t hash) {
export bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureSpecies* p, uint32_t hash) {
return p->HasVariant(hash);
}
export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureLib::Library::CreatureSpecies* p, const char* name,
const CreatureLib::Library::SpeciesVariant* out) {
export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p, const char* name,
const SpeciesVariant* out) {
return p->TryGetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name), out);
}
export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureLib::Library::CreatureSpecies* p,
uint32_t hash,
const CreatureLib::Library::SpeciesVariant* out) {
export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpecies* p, uint32_t hash,
const SpeciesVariant* out) {
return p->TryGetVariant(hash, out);
}
export const CreatureLib::Library::SpeciesVariant*
CreatureLib_CreatureSpecies_GetVariant(const CreatureLib::Library::CreatureSpecies* p, const char* name) {
export const SpeciesVariant* CreatureLib_CreatureSpecies_GetVariant(const CreatureSpecies* p, const char* name) {
return p->GetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name));
}
export const CreatureLib::Library::SpeciesVariant*
CreatureLib_CreatureSpecies_GetVariantWithHash(const CreatureLib::Library::CreatureSpecies* p, uint32_t hash) {
export const SpeciesVariant* CreatureLib_CreatureSpecies_GetVariantWithHash(const CreatureSpecies* p, uint32_t hash) {
return p->GetVariant(hash);
}

View File

@ -1,23 +1,23 @@
#include "../../src/Library/DataLibrary.hpp"
#define export extern "C"
using namespace CreatureLib::Library;
export const CreatureLib::Library::DataLibrary* CreatureLib_DataLibrary_Construct(
CreatureLib::Library::LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates, CreatureLib::Library::TypeLibrary* typeLibrary) {
return new CreatureLib::Library::DataLibrary(settings, species, attacks, items, growthRates, typeLibrary);
export const DataLibrary* CreatureLib_DataLibrary_Construct(LibrarySettings* settings, SpeciesLibrary* species,
AttackLibrary* attacks, ItemLibrary* items,
GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary) {
return new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary);
}
export void CreatureLib_DataLibrary_Destruct(const CreatureLib::Library::DataLibrary* p) { delete p; }
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const CreatureLib::Library::type* p) { return p->name(); }
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
SIMPLE_GET_FUNC(DataLibrary, GetSettings, const CreatureLib::Library::LibrarySettings*);
SIMPLE_GET_FUNC(DataLibrary, GetSpeciesLibrary, const CreatureLib::Library::SpeciesLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetAttackLibrary, const CreatureLib::Library::AttackLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetItemLibrary, const CreatureLib::Library::ItemLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetGrowthRates, const CreatureLib::Library::GrowthRateLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetTypeLibrary, const CreatureLib::Library::TypeLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetSettings, const LibrarySettings*);
SIMPLE_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetAttackLibrary, const AttackLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetItemLibrary, const ItemLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetGrowthRates, const GrowthRateLibrary*);
SIMPLE_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*);
#undef SIMPLE_GET_FUNC

View File

@ -1,39 +1,37 @@
#include "../../src/Library/GrowthRates/GrowthRateLibrary.hpp"
#define export extern "C"
using namespace CreatureLib::Library;
export CreatureLib::Library::GrowthRateLibrary* CreatureLib_GrowthRateLibrary_Construct(size_t initialCapacity) {
return new CreatureLib::Library::GrowthRateLibrary(initialCapacity);
export GrowthRateLibrary* CreatureLib_GrowthRateLibrary_Construct(size_t initialCapacity) {
return new GrowthRateLibrary(initialCapacity);
}
export void CreatureLib_GrowthRateLibrary_Destruct(CreatureLib::Library::GrowthRateLibrary* p) { delete p; }
export void CreatureLib_GrowthRateLibrary_Destruct(GrowthRateLibrary* p) { delete p; }
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(CreatureLib::Library::GrowthRateLibrary* library,
const char* growthRate, uint32_t experience) {
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(GrowthRateLibrary* library, const char* growthRate,
uint32_t experience) {
return library->CalculateLevel(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), experience);
}
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(CreatureLib::Library::GrowthRateLibrary* library,
uint32_t growthRateHash, uint32_t experience) {
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(GrowthRateLibrary* library, uint32_t growthRateHash,
uint32_t experience) {
return library->CalculateLevel(growthRateHash, experience);
}
export uint32_t CreatureLib_GrowthRateLibrary_CalculateExperience(CreatureLib::Library::GrowthRateLibrary* library,
const char* growthRate, uint8_t level) {
export uint32_t CreatureLib_GrowthRateLibrary_CalculateExperience(GrowthRateLibrary* library, const char* growthRate,
uint8_t level) {
return library->CalculateExperience(Arbutils::CaseInsensitiveConstString::GetHash(growthRate), level);
}
export uint32_t
CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(CreatureLib::Library::GrowthRateLibrary* library,
uint32_t growthRateHash, uint8_t level) {
export uint32_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(GrowthRateLibrary* library,
uint32_t growthRateHash, uint8_t level) {
return library->CalculateExperience(growthRateHash, level);
}
export void CreatureLib_GrowthRateLibrary_AddGrowthRate(CreatureLib::Library::GrowthRateLibrary* library,
const char* growthRateName,
CreatureLib::Library::GrowthRate* growthRate) {
export void CreatureLib_GrowthRateLibrary_AddGrowthRate(GrowthRateLibrary* library, const char* growthRateName,
GrowthRate* growthRate) {
return library->AddGrowthRate(Arbutils::CaseInsensitiveConstString::GetHash(growthRateName), growthRate);
}
export void CreatureLib_GrowthRateLibrary_AddGrowthRateWithHash(CreatureLib::Library::GrowthRateLibrary* library,
uint32_t growthRateHash,
CreatureLib::Library::GrowthRate* growthRate) {
export void CreatureLib_GrowthRateLibrary_AddGrowthRateWithHash(GrowthRateLibrary* library, uint32_t growthRateHash,
GrowthRate* growthRate) {
return library->AddGrowthRate(growthRateHash, growthRate);
}

View File

@ -1,11 +1,12 @@
#include "../../src/Library/ItemLibrary.hpp"
#include "BaseLibrary.cpp"
#define export extern "C"
using namespace CreatureLib::Library;
export const CreatureLib::Library::ItemLibrary* CreatureLib_ItemLibrary_Construct(size_t initialCapacity = 32) {
return new CreatureLib::Library::ItemLibrary(initialCapacity);
export const ItemLibrary* CreatureLib_ItemLibrary_Construct(size_t initialCapacity = 32) {
return new ItemLibrary(initialCapacity);
};
export void CreatureLib_ItemLibrary_Destruct(const CreatureLib::Library::ItemLibrary* p) { delete p; }
export void CreatureLib_ItemLibrary_Destruct(const ItemLibrary* p) { delete p; }
BASELIBRARY(CreatureLib_ItemLibrary, CreatureLib::Library::ItemLibrary, CreatureLib::Library::Item);
BASELIBRARY(CreatureLib_ItemLibrary, ItemLibrary, Item);

View File

@ -1,12 +1,12 @@
#include "../../src/Library/LibrarySettings.hpp"
#define export extern "C"
using namespace CreatureLib::Library;
export const CreatureLib::Library::LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maximalLevel,
uint8_t maximalMoves) {
return new CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves);
export const LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maximalLevel, uint8_t maximalMoves) {
return new LibrarySettings(maximalLevel, maximalMoves);
}
export void CreatureLib_LibrarySettings_Destruct(const CreatureLib::Library::LibrarySettings* p) { delete p; }
export void CreatureLib_LibrarySettings_Destruct(const LibrarySettings* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const CreatureLib::Library::type* p) { return p->name(); }

View File

@ -1,11 +1,12 @@
#include "../../src/Library/SpeciesLibrary.hpp"
#include "BaseLibrary.cpp"
#define export extern "C"
using namespace CreatureLib::Library;
export const CreatureLib::Library::SpeciesLibrary* CreatureLib_SpeciesLibrary_Construct(size_t initialCapacity = 32) {
return new CreatureLib::Library::SpeciesLibrary(initialCapacity);
export const SpeciesLibrary* CreatureLib_SpeciesLibrary_Construct(size_t initialCapacity = 32) {
return new SpeciesLibrary(initialCapacity);
};
export void CreatureLib_SpeciesLibrary_Destruct(const CreatureLib::Library::SpeciesLibrary* p) { delete p; }
export void CreatureLib_SpeciesLibrary_Destruct(const SpeciesLibrary* p) { delete p; }
BASELIBRARY(CreatureLib_SpeciesLibrary, CreatureLib::Library::SpeciesLibrary, CreatureLib::Library::CreatureSpecies);
BASELIBRARY(CreatureLib_SpeciesLibrary, SpeciesLibrary, CreatureSpecies);

View File

@ -0,0 +1,30 @@
#include "../../src/Library/CreatureData/SpeciesVariant.hpp"
#define export extern "C"
using namespace CreatureLib::Library;
using ConstString = Arbutils::CaseInsensitiveConstString;
export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
const char* name, float height, float weight, uint32_t baseExperience, uint8_t types[], size_t typeLength,
uint16_t baseHealth, uint16_t baseAttack, uint16_t baseDefense, uint16_t baseMagicalAttack,
uint16_t baseMagicalDefense, __uint8_t baseSpeed, const char* talents[], size_t talentsLength,
const char* secretTalents[], size_t secretTalentsLength, const LearnableAttacks* attacks) {
auto talentsWrapped = std::vector<ConstString>(talentsLength);
for (size_t i = 0; i < talentsLength; i++) {
talentsWrapped[i] = ConstString(talents[i]);
}
auto secretTalentsWrapped = std::vector<ConstString>(secretTalentsLength);
for (size_t i = 0; i < secretTalentsLength; i++) {
secretTalentsWrapped[i] = ConstString(secretTalents[i]);
}
return new SpeciesVariant(Arbutils::CaseInsensitiveConstString(name), height, weight, baseExperience,
std::vector<uint8_t>(types, types + typeLength),
CreatureLib::Core::StatisticSet<uint16_t>(baseHealth, baseAttack, baseDefense,
baseMagicalAttack, baseMagicalDefense,
baseSpeed),
talentsWrapped, secretTalentsWrapped, attacks);
}
export void CreatureLib_SpeciesVariant_Destruct(SpeciesVariant* p) { delete p; }

View File

@ -1,37 +1,37 @@
#include "../../src/Library/TypeLibrary.hpp"
#define export extern "C"
using namespace CreatureLib::Library;
export CreatureLib::Library::TypeLibrary* CreatureLib_TypeLibrary_Construct(size_t initialCapacity) {
return new CreatureLib::Library::TypeLibrary(initialCapacity);
export TypeLibrary* CreatureLib_TypeLibrary_Construct(size_t initialCapacity) {
return new TypeLibrary(initialCapacity);
};
export void CreatureLib_TypeLibrary_Destruct(const CreatureLib::Library::TypeLibrary* p) { delete p; }
export void CreatureLib_TypeLibrary_Destruct(const TypeLibrary* p) { delete p; }
export uint8_t CreatureLib_TypeLibrary_GetTypeId(const CreatureLib::Library::TypeLibrary* p, const char* type) {
export uint8_t CreatureLib_TypeLibrary_GetTypeId(const TypeLibrary* p, const char* type) {
return p->GetTypeId(Arbutils::CaseInsensitiveConstString::GetHash(type));
}
export uint8_t CreatureLib_TypeLibrary_GetTypeIdWithHash(const CreatureLib::Library::TypeLibrary* p, uint32_t type) {
export uint8_t CreatureLib_TypeLibrary_GetTypeIdWithHash(const TypeLibrary* p, uint32_t type) {
return p->GetTypeId(type);
}
export uint8_t CreatureLib_TypeLibrary_RegisterType(CreatureLib::Library::TypeLibrary* p, const char* type) {
export uint8_t CreatureLib_TypeLibrary_RegisterType(TypeLibrary* p, const char* type) {
return p->RegisterType(Arbutils::CaseInsensitiveConstString::GetHash(type));
}
export uint8_t CreatureLib_TypeLibrary_RegisterTypeWithHash(CreatureLib::Library::TypeLibrary* p, uint32_t type) {
export uint8_t CreatureLib_TypeLibrary_RegisterTypeWithHash(TypeLibrary* p, uint32_t type) {
return p->RegisterType(type);
}
export void CreatureLib_TypeLibrary_SetEffectiveness(CreatureLib::Library::TypeLibrary* p, uint8_t attacking,
uint8_t defensive, float effectiveness) {
export void CreatureLib_TypeLibrary_SetEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive,
float effectiveness) {
p->SetEffectiveness(attacking, defensive, effectiveness);
}
export float CreatureLib_TypeLibrary_GetSingleEffectiveness(CreatureLib::Library::TypeLibrary* p, uint8_t attacking,
uint8_t defensive) {
export float CreatureLib_TypeLibrary_GetSingleEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive) {
return p->GetSingleEffectiveness(attacking, defensive);
}
export float CreatureLib_TypeLibrary_GetEffectiveness(CreatureLib::Library::TypeLibrary* p, uint8_t attacking,
uint8_t defensive[], size_t defensiveCount) {
export float CreatureLib_TypeLibrary_GetEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive[],
size_t defensiveCount) {
return p->GetEffectiveness(attacking, std::vector<uint8_t>(defensive, defensive + defensiveCount));
}