From 0a109e37bc94606dffce917139bac3d2a9721c77 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 29 Feb 2020 14:09:03 +0100 Subject: [PATCH] Initial work on creating C interface. --- CInterface/Library/DataLibrary.cpp | 23 +++++++++++++++++++++++ CInterface/Library/LibrarySettings.cpp | 17 +++++++++++++++++ CInterface/Library/SpeciesLibrary.cpp | 13 +++++++++++++ CMakeLists.txt | 6 +++--- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 CInterface/Library/DataLibrary.cpp create mode 100644 CInterface/Library/LibrarySettings.cpp create mode 100644 CInterface/Library/SpeciesLibrary.cpp diff --git a/CInterface/Library/DataLibrary.cpp b/CInterface/Library/DataLibrary.cpp new file mode 100644 index 0000000..428773f --- /dev/null +++ b/CInterface/Library/DataLibrary.cpp @@ -0,0 +1,23 @@ +#include "../../src/Library/DataLibrary.hpp" +#define export extern "C" + +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 void CreatureLib_DataLibrary_Destruct(const CreatureLib::Library::DataLibrary* p) { delete p; } + +#define SIMPLE_GET_FUNC(type, name, returnType) \ + export returnType CreatureLib_##type##_##name(const CreatureLib::Library::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*); + +#undef SIMPLE_GET_FUNC \ No newline at end of file diff --git a/CInterface/Library/LibrarySettings.cpp b/CInterface/Library/LibrarySettings.cpp new file mode 100644 index 0000000..191ef60 --- /dev/null +++ b/CInterface/Library/LibrarySettings.cpp @@ -0,0 +1,17 @@ +#include "../../src/Library/LibrarySettings.hpp" +#define export extern "C" + +export const CreatureLib::Library::LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maximalLevel, + uint8_t maximalMoves) { + return new CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves); +} + +export void CreatureLib_LibrarySettings_Destruct(const CreatureLib::Library::LibrarySettings* p) { delete p; } + +#define SIMPLE_GET_FUNC(type, name, returnType) \ + export returnType CreatureLib_##type##_##name(const CreatureLib::Library::type* p) { return p->name(); } + +SIMPLE_GET_FUNC(LibrarySettings, GetMaximalLevel, uint8_t); +SIMPLE_GET_FUNC(LibrarySettings, GetMaximalMoves, uint8_t); + +#undef SIMPLE_GET_FUNC \ No newline at end of file diff --git a/CInterface/Library/SpeciesLibrary.cpp b/CInterface/Library/SpeciesLibrary.cpp new file mode 100644 index 0000000..06961b2 --- /dev/null +++ b/CInterface/Library/SpeciesLibrary.cpp @@ -0,0 +1,13 @@ +#include "../../src/Library/SpeciesLibrary.hpp" +#define export extern "C" + +export const CreatureLib::Library::SpeciesLibrary* CreatureLib_SpeciesLibrary_Construct(size_t initialCapacity = 32) { + return new CreatureLib::Library::SpeciesLibrary(initialCapacity); +}; + +export void CreatureLib_SpeciesLibrary_Destruct(const CreatureLib::Library::SpeciesLibrary* p) { delete p; } + +void CreatureLib_SpeciesLibrary_Insert(CreatureLib::Library::SpeciesLibrary* p, const char* name, + CreatureLib::Library::CreatureSpecies* species) { + p->Insert(Arbutils::CaseInsensitiveConstString(name), species); +} diff --git a/CMakeLists.txt b/CMakeLists.txt index f54a696..139e9be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,16 +32,16 @@ if (WINDOWS) endif (WINDOWS) # Create Core library with files in src/Core -file(GLOB_RECURSE CORE_SRC_FILES "src/Core/*.cpp" "src/Core/*.hpp") +file(GLOB_RECURSE CORE_SRC_FILES "src/Core/*.cpp" "src/Core/*.hpp" "CInterface/Core/*.hpp") add_library(CreatureLibCore SHARED ${CORE_SRC_FILES}) set_target_properties(CreatureLibCore PROPERTIES LINKER_LANGUAGE CXX) # Create main Library library with files in src/Library -file(GLOB_RECURSE LIBRARY_SRC_FILES "src/Library/*.cpp" "src/Library/*.hpp") +file(GLOB_RECURSE LIBRARY_SRC_FILES "src/Library/*.cpp" "src/Library/*.hpp" "CInterface/Library/*.cpp") add_library(CreatureLibLibrary SHARED ${LIBRARY_SRC_FILES}) # Create Battling library with files in src/Battling -file(GLOB_RECURSE BATTLING_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp") +file(GLOB_RECURSE BATTLING_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "CInterface/Battling/*.hpp") add_library(CreatureLibBattling SHARED ${BATTLING_SRC_FILES}) if (NOT DEFINED CONAN_EXPORTED)