diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-03-31 16:00:14 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-03-31 16:00:14 -0400 |
| commit | fad302f7db146a78900f9b21dbbcd97761093c1b (patch) | |
| tree | 9f1d6d27386ff513b5e78646394edaeea972c555 /src/game.cpp | |
| parent | 96698b567b2e56768ca3e8762ce55dd3b2849ccb (diff) | |
pke: serialize camera instance + camera together
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/game.cpp b/src/game.cpp index 8e65b1b..f7b539b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -98,6 +98,33 @@ void SerializeCamera(std::ostream &stream, const PkeCamera &cam) { if (cam.isPrimary != c.isPrimary) { stream << PKE_FILE_CAMERA_IS_PRIMARY << cam.isPrimary << std::endl; } + + CompInstance &comp = *ECS_GetInstance(cam.phys.instHandle); + InstPos baseInst{}; + baseInst.posRot = btTransform{}; + baseInst.posRot.setIdentity(); + baseInst.scale = btVector3(1, 1, 1); + btTransform trans; + comp.bt.motionState->getWorldTransform(trans); + btVector3 scale = comp.bt.rigidBody->getCollisionShape()->getLocalScaling(); + if (trans != baseInst.posRot) { + btVector3 pos = trans.getOrigin(); + btQuaternion rot = trans.getRotation(); + stream << PKE_FILE_INSTANCE_POS_POS << "[" + << std::setw(10) << pos[0] << "," + << std::setw(10) << pos[1] << "," + << std::setw(10) << pos[2] << "]" << std::endl + << PKE_FILE_INSTANCE_POS_ROT << "[" + << std::setw(10) << rot[0] << "," + << std::setw(10) << rot[1] << "," + << std::setw(10) << rot[2] << "," + << std::setw(10) << rot[3] << "]" << std::endl; + } + if (scale != baseInst.scale) + stream << PKE_FILE_INSTANCE_POS_SCALE << "[" + << std::setw(10) << scale[0] << "," + << std::setw(10) << scale[1] << "," + << std::setw(10) << scale[2] << "]" << std::endl; } void SerializeInstance(std::ostream &stream, const CompInstance &comp) { @@ -450,6 +477,9 @@ void Game_SaveSceneFile(const char *sceneFilePath) { const auto &instance = instances[i]; if (instance.entHandle == EntityHandle_MAX) continue; + if (instance.flags & COMPONENT_INSTANCE_FLAG_DO_NOT_SERIALIZE) { + continue; + } stream << PKE_FILE_OBJ_INSTANCE << std::endl; SerializeInstance(stream, instance); stream << PKE_FILE_OBJ_END << std::endl; |
