summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/example.cpp20
-rw-r--r--src/game.cpp2
-rw-r--r--src/plugin-types.hpp20
3 files changed, 29 insertions, 13 deletions
diff --git a/example/example.cpp b/example/example.cpp
index b870806..7b82ebc 100644
--- a/example/example.cpp
+++ b/example/example.cpp
@@ -3,23 +3,23 @@
#include "components.hpp"
-void OnEntityTypeCollision(const EntityHandle &lhs, const EntityHandle &rhs) {
+void OnEntityTypeCollision(const void *lhs, const void *rhs) {
fprintf(stdout, "[Example::OnEntityTypeCollision] Called\n");
}
-void OnEntityCollision(const EntityHandle &lhs, const EntityHandle &rhs) {
+void OnEntityCollision(const void *lhs, const void *rhs) {
fprintf(stdout, "[Example::OnEntityCollision] Called\n");
}
void OnInit() {
- PkeArray_Add(&pkePluginCallbacks, PkeCallback {
- .name = "OnEntTypeColl",
- .func = reinterpret_cast<void *>(OnEntityTypeCollision),
- });
- PkeArray_Add(&pkePluginCallbacks, PkeCallback {
- .name = "OnEntColl",
- .func = reinterpret_cast<void *>(OnEntityCollision),
- });
+ // create/register entity types
+ pkePluginInterface.PkeEntityInterfaceCount = 1;
+ pkePluginInterface.PkeEntityInterface = Pke_New<PkeEntityTypeInterface>(1);
+
+ // set up entity types
+ auto *typeIntfs = reinterpret_cast<PkeEntityTypeInterface *>(pkePluginInterface.PkeEntityInterface);
+ typeIntfs[0].OnEntityTypeCollision = reinterpret_cast<CollisionDelegate>(OnEntityTypeCollision);
+ typeIntfs[0].OnEntityInstanceCollision = reinterpret_cast<CollisionDelegate>(OnEntityCollision);
}
PKEPluginInterface pkePluginInterface {
diff --git a/src/game.cpp b/src/game.cpp
index 8c2bc2a..bca8bb2 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -219,12 +219,14 @@ void ParseCamera(PkeLevel *level, std::ifstream &stream) {
uint64_t prefixLen = strlen(PKE_FILE_CAMERA_INSTANCE_HANDLE);
STR2NUM_ERROR result = str2num(instanceHandle.hash, readLine + prefixLen);
assert(result == STR2NUM_ERROR::SUCCESS);
+ // TODO add to global list
continue;
}
if (strstr(readLine, PKE_FILE_CAMERA_TARGET_INSTANCE_HANDLE)) {
uint64_t prefixLen = strlen(PKE_FILE_CAMERA_TARGET_INSTANCE_HANDLE);
STR2NUM_ERROR result = str2num(targetInstanceHandle.hash, readLine + prefixLen);
assert(result == STR2NUM_ERROR::SUCCESS);
+ // TODO find and set
continue;
}
if (strncmp(readLine, PKE_FILE_CAMERA_IS_PRIMARY, strlen(PKE_FILE_CAMERA_IS_PRIMARY)) == 0) {
diff --git a/src/plugin-types.hpp b/src/plugin-types.hpp
index 22f9707..10139b0 100644
--- a/src/plugin-types.hpp
+++ b/src/plugin-types.hpp
@@ -2,6 +2,21 @@
#define PKE_PLUGIN_TYPES_HPP
#include <cstdint>
+#include <fstream>
+
+constexpr int64_t CallbackSignatureLength = 16;
+using CallbackSignature = char[CallbackSignatureLength];
+
+typedef void (*ParseDelegate)(std::ifstream *stream);
+typedef void (*SerializeDelegate)(std::ifstream *stream);
+typedef void (*CollisionDelegate)(const void *entHandleLeft, const void *entHandleRight);
+
+struct PkeEntityTypeInterface {
+ void (*OnParse)(std::ifstream *stream) = nullptr;
+ void (*OnSerialize)(std::ostringstream *stream, void *obj) = nullptr;
+ void (*OnEntityTypeCollision)(const void *entHandleLeft, const void *entHandleRight) = nullptr;
+ void (*OnEntityInstanceCollision)(const void *entHandleLeft, const void *entHandleRight) = nullptr;
+};
struct PKEPluginInterface {
// for internal use only
@@ -10,11 +25,10 @@ struct PKEPluginInterface {
void (*OnTick)(double delta) = nullptr;
void (*OnTeardown)() = nullptr;
void (*OnImGuiRender)() = nullptr;
+ void *PkeEntityInterface = nullptr;
+ std::size_t PkeEntityInterfaceCount = 0;
};
-constexpr int64_t CallbackSignatureLength = 16;
-using CallbackSignature = char[CallbackSignatureLength];
-
struct PkeCallback {
// the 16 char signature(name) of a function
CallbackSignature name = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};