diff options
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/game.cpp b/src/game.cpp index 20e67a0..5df32a0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -47,6 +47,7 @@ const char *PKE_FILE_INSTANCE_POS_SCALE = "InstPos::Scale: "; const char *PKE_FILE_INSTANCE_PHYSICS_MASS = "InstPos::Mass: "; const char *PKE_FILE_INSTANCE_PHYSICS_COLLISION_LAYER = "InstPos::CollisionLayer: "; const char *PKE_FILE_INSTANCE_PHYSICS_COLLISION_MASK = "InstPos::CollisionMask: "; +const char *PKE_FILE_INSTANCE_COLLISION_CALLBACK_SIGNATURE = "Inst::CollisionCallbackSignature: "; const char *PKE_FILE_CAMERA_POS = "Cam::Pos: "; const char *PKE_FILE_CAMERA_ROT = "Cam::Rot: "; @@ -141,6 +142,9 @@ void SerializeInstance(std::ofstream &stream, const CompInstance &comp) { if (collisionMask != c.physicsMask) { stream << PKE_FILE_INSTANCE_PHYSICS_COLLISION_MASK << static_cast<PhysicsCollision_T>(collisionMask) << std::endl; } + if (comp.collisionCallback.name[0] != '\0') { + stream << PKE_FILE_INSTANCE_COLLISION_CALLBACK_SIGNATURE << comp.collisionCallback.name << std::endl; + } } void ParseCamera(LevelHandle levelHandle, std::ifstream &stream) { @@ -238,6 +242,7 @@ void ParseInstance(EntityHandle parentEntHandle, std::ifstream &stream) { instPos.posRot.setIdentity(); instPos.scale = btVector3(1, 1, 1); instPos.mass = 1.f; + comp.collisionCallback.name[0] = '\0'; char entTypeCode[21]; memset(reinterpret_cast<void *>(entTypeCode), '\0', 21); while (stream.getline(readLine, readLineLength)) { @@ -255,6 +260,9 @@ void ParseInstance(EntityHandle parentEntHandle, std::ifstream &stream) { auto entityHandle = ECS_CreateEntity(parentEntHandle); auto &compInst = ECS_CreateInstance(entityHandle, et.entityHandle); + strncpy(compInst.collisionCallback.name, comp.collisionCallback.name, 16); + PkePlugin_SetSignatureFunc(&compInst.collisionCallback); + compInst.physicsLayer = comp.physicsLayer; compInst.physicsMask = comp.physicsMask; btVector3 localInertia(0, 0, 0); @@ -356,6 +364,11 @@ void ParseInstance(EntityHandle parentEntHandle, std::ifstream &stream) { assert(result == STR2NUM_ERROR::SUCCESS); continue; } + if (strstr(readLine, PKE_FILE_INSTANCE_COLLISION_CALLBACK_SIGNATURE)) { + uint64_t prefixLen = strlen(PKE_FILE_INSTANCE_COLLISION_CALLBACK_SIGNATURE); + strncpy(comp.collisionCallback.name, readLine + prefixLen, 16); + continue; + } } } @@ -496,9 +509,11 @@ void Game_Tick(double delta) { ECS_Tick(delta); PkeInput_Tick(delta); - // TODO invoke external ticks here - if (pkePlugin.OnTick) { - pkePlugin.OnTick(delta); + const auto pluginCount = LoadedPkePlugins.Count(); + for (long i = 0; i < pluginCount; ++i) { + if (LoadedPkePlugins[i].OnTick != nullptr) { + LoadedPkePlugins[i].OnTick(delta); + } } EntityType_Tick_Late(delta); @@ -517,11 +532,14 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) { CreateWindow(windowProps); PkeInput_Init(); EntityType_Init(); - if (pkeSettings.args.pluginPath) { - Pke_LoadPlugin(pkeSettings.args.pluginPath); + if (pkeSettings.args.pluginPath != nullptr) { + PkePlugin_Load(pkeSettings.args.pluginPath); } - if (pkePlugin.OnInit) { - pkePlugin.OnInit(); + const long pluginCount = LoadedPkePlugins.Count(); + for (long i = 0; i < pluginCount; ++i) { + if (LoadedPkePlugins[i].OnInit != nullptr) { + LoadedPkePlugins[i].OnInit(); + } } PkeProject_Load(pkeSettings.args.projectPath); @@ -612,8 +630,11 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) { #ifndef NDEBUG Pke_DebugPrint(); #endif - if (pkePlugin.OnTeardown) { - pkePlugin.OnTeardown(); + const auto pluginCount = LoadedPkePlugins.Count(); + for (long i = 0; i < pluginCount; ++i) { + if (LoadedPkePlugins[i].OnTeardown) { + LoadedPkePlugins[i].OnTeardown(); + } } Game_Teardown(); Event_Teardown(); |
