diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-01-14 15:50:04 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-01-14 15:50:04 -0500 |
| commit | 80a67230fe192287503092a3d256aea3a494409c (patch) | |
| tree | 187f2e7a41e0cd206d9969284a3abce4028d89f5 /src/game.cpp | |
| parent | 46d814de510d0a7753c3e49eed3b3440d1c7c681 (diff) | |
pke: camera can track a given target
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/game.cpp b/src/game.cpp index 220aebd..be4bb25 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -36,8 +36,8 @@ const long readLineLength = 128; char readLine[readLineLength]; struct InstMapping { InstanceHandle origHandle = InstanceHandle_MAX; - Entity_Base *newEnt = nullptr; - CompInstance *newInst = nullptr; + EntityHandle newEntHandle; + InstanceHandle newInstHandle; InstPos newInstance{}; }; PkeArray<InstMapping> loadFileInstanceMappings{}; @@ -82,12 +82,12 @@ void SerializeCamera(std::ostringstream &stream, const PkeCamera &cam) { if (cam.view != c.view) { stream << PKE_FILE_CAMERA_ORIENTATION << int(static_cast<PkeCameraView_T>(cam.view)) << std::endl; } - if (cam.phys.inst != c.phys.inst && cam.phys.inst != CAFE_BABE(CompInstance)) { - snprintf(handleStr, 22, "0x%08X 0x%08X", cam.phys.inst->instanceHandle.bucketIndex, cam.phys.inst->instanceHandle.itemIndex); + if (cam.phys.instHandle != InstanceHandle_MAX) { + snprintf(handleStr, 22, "0x%08X 0x%08X", cam.phys.instHandle.bucketIndex, cam.phys.instHandle.itemIndex); stream << PKE_FILE_CAMERA_INSTANCE_HANDLE << handleStr << std::endl; } - if (cam.phys.targetInst != c.phys.targetInst && cam.phys.targetInst != CAFE_BABE(CompInstance)) { - snprintf(handleStr, 22, "0x%08X 0x%08X", cam.phys.targetInst->instanceHandle.bucketIndex, cam.phys.targetInst->instanceHandle.itemIndex); + if (cam.phys.targetInstHandle != InstanceHandle_MAX) { + snprintf(handleStr, 22, "0x%08X 0x%08X", cam.phys.targetInstHandle.bucketIndex, cam.phys.targetInstHandle.itemIndex); stream << PKE_FILE_CAMERA_TARGET_INSTANCE_HANDLE << handleStr << std::endl; } if (cam.isPrimary != c.isPrimary) { @@ -107,11 +107,11 @@ void SerializeInstance(std::ostringstream &stream, const CompInstance &comp) { baseInst.posRot.setIdentity(); baseInst.scale = btVector3(1, 1, 1); baseInst.mass = 1; - if (comp.entHandle != c.entHandle) { + if (comp.entHandle != InstanceHandle_MAX) { snprintf(handleStr, 22, "0x%08X 0x%08X", comp.entHandle.bucketIndex, comp.entHandle.itemIndex); stream << PKE_FILE_INSTANCE_ENTITY_HANDLE << handleStr << std::endl; } - if (comp.entHandle != c.entHandle) { + if (comp.instanceHandle != InstanceHandle_MAX) { snprintf(handleStr, 22, "0x%08X 0x%08X", comp.instanceHandle.bucketIndex, comp.instanceHandle.itemIndex); stream << PKE_FILE_INSTANCE_HANDLE << handleStr << std::endl; } @@ -190,9 +190,10 @@ void ParseCamera(PkeLevel *level, std::ifstream &stream) { rCam.type = cam.type; rCam.view = cam.view; rCam.isPrimary = cam.isPrimary; + rCam.phys.targetInstHandle = targetInstanceHandle; PkeLevel_RegisterCamera(level->levelHandle, rCam.camHandle); if (targetInstanceIndex > -1) { - PkeCamera_AttachToInstance(rCam.camHandle, loadFileInstanceMappings.data[targetInstanceIndex].newInst); + PkeCamera_TargetInstance(rCam.camHandle, ECS_GetInstance(loadFileInstanceMappings.data[targetInstanceIndex].newInstHandle)); } if (rCam.isPrimary == true) { ActiveCamera = &rCam; @@ -250,6 +251,8 @@ void ParseInstance(Entity_Base *parentEntity, std::ifstream &stream) { CompInstance comp{}; InstMapping mapping { .origHandle = InstanceHandle_MAX, + .newEntHandle = EntityHandle_MAX, + .newInstHandle = InstanceHandle_MAX, .newInstance = { .scale = btVector3(1.f, 1.f, 1.f), .mass = 1.f, @@ -261,6 +264,7 @@ void ParseInstance(Entity_Base *parentEntity, std::ifstream &stream) { while (stream.getline(readLine, readLineLength)) { if (strstr(PKE_FILE_OBJ_END, readLine)) { EntityType *etPtr = nullptr; + Entity_Base *entity = nullptr; bool skipEntCreate = false; if (strlen(entTypeCode) > 1) { etPtr = EntityType_FindByTypeCode(entTypeCode); @@ -281,18 +285,19 @@ void ParseInstance(Entity_Base *parentEntity, std::ifstream &stream) { if (skipEntCreate == false) { if (etPtr != nullptr && etPtr->createInstanceCallback.func != nullptr) { typedef Entity_Base *CreateInst(); - mapping.newEnt = reinterpret_cast<CreateInst*>(etPtr->createInstanceCallback.func)(); + entity = reinterpret_cast<CreateInst*>(etPtr->createInstanceCallback.func)(); } else { - mapping.newEnt = EntityType_CreateGenericInstance(etPtr, parentEntity, &comp, &mapping.newInstance); + entity = EntityType_CreateGenericInstance(etPtr, parentEntity, &comp, &mapping.newInstance); fprintf(stdout ,"[Game::ParseInstance] Debug: entTypeCode '%s' does not have a registered callback func to handle instance creation.\n", entTypeCode); } + mapping.newEntHandle = entity->handle; } - if (mapping.newEnt != nullptr) { + if (mapping.newEntHandle != EntityHandle_MAX) { // TODO this is messy PkeArray<CompInstance *> instances{}; - ECS_GetInstances(mapping.newEnt, instances); + ECS_GetInstances(entity, instances); assert(instances.next > 0); - mapping.newInst = instances.data[0]; + mapping.newInstHandle = instances.data[0]->instanceHandle; } PkeArray_Add(&loadFileInstanceMappings, mapping); break; |
