diff --git a/interface/src/workload/GameWorkload.cpp b/interface/src/workload/GameWorkload.cpp index b2f4001afa..22f41669dc 100644 --- a/interface/src/workload/GameWorkload.cpp +++ b/interface/src/workload/GameWorkload.cpp @@ -15,8 +15,32 @@ #include "PhysicsBoundary.h" #pragma optimize( "[optimization-list]", off ) + +ControlViews::ControlViews() { + regionBackFronts[0] = glm::vec2(2.0f, 10.0f); + regionBackFronts[1] = glm::vec2(5.0f, 30.0f); + regionBackFronts[2] = glm::vec2(10.0f, 100.0f); + +} + +void ControlViews::configure(const Config& config) { + _data = config.data; +} + +void ControlViews::run(const workload::WorkloadContextPointer& runContext, const Input& inputs, Output& outputs) { + const auto& inViews = inputs.get0(); + const auto& inTimings = inputs.get1(); + auto& outViews = outputs; + outViews.clear(); + outViews = inViews; + + if (_data.regulateViewRanges) { + regulateViews(outViews, inTimings); + } +} + float wtf_adjust(float current, float timing) { - float error = (timing * 0.001f) - 2.0f; + float error = -((timing * 0.001f) - 2.0f); if (error < 0.0f) { current += 0.2f * (error) / 16.0f; } else { @@ -30,22 +54,25 @@ float wtf_adjust(float current, float timing) { } return current; } -void ControlViews::run(const workload::WorkloadContextPointer& runContext, const Input& inputs, Output& outputs) { - const auto& inViews = inputs.get0(); - const auto& inTimings = inputs.get1(); - auto& outViews = outputs; - outViews.clear(); - outViews = inViews; - - + +void ControlViews::regulateViews(workload::Views& outViews, const workload::Timings& timings) { + + for (auto& outView : outViews) { + for (int r = 0; r < workload::Region::NUM_VIEW_REGIONS; r++) { + outView.regionBackFronts[r] = regionBackFronts[r]; + } + } + int i = 0; for (auto& outView : outViews) { - auto& current = regionBackFronts[workload::Region::R2].y; - auto newCurrent = wtf_adjust(current, inTimings[0]); - outView.regions[workload::Region::R2].y = newCurrent; + auto current = regionBackFronts[workload::Region::R2].y; + auto newCurrent = wtf_adjust(current, timings[0]); + regionBackFronts[workload::Region::R2].y = newCurrent; + outView.regionBackFronts[workload::Region::R2].y = newCurrent; workload::View::updateRegionsFromBackFronts(outView); } } + #pragma optimize( "[optimization-list]", on ) class WorkloadEngineBuilder { diff --git a/interface/src/workload/GameWorkload.h b/interface/src/workload/GameWorkload.h index 219383b974..7dffd6ac58 100644 --- a/interface/src/workload/GameWorkload.h +++ b/interface/src/workload/GameWorkload.h @@ -45,8 +45,17 @@ public: class ControlViewsConfig : public workload::Job::Config { Q_OBJECT + Q_PROPERTY(bool regulateViewRanges READ regulateViewRanges WRITE setRegulateViewRanges NOTIFY dirty) + public: + bool regulateViewRanges() const { return data.regulateViewRanges; } + void setRegulateViewRanges(bool use) { data.regulateViewRanges = use; emit dirty(); } + + struct Data { + bool regulateViewRanges{ true }; + + } data; signals: void dirty(); }; @@ -58,12 +67,17 @@ public: using Output = workload::Views; using JobModel = workload::Job::ModelIO; - ControlViews() = default; + ControlViews(); - void configure(const Config& config) {} + void configure(const Config& config); void run(const workload::WorkloadContextPointer& runContext, const Input& inputs, Output& outputs); glm::vec2 regionBackFronts[workload::Region::NUM_VIEW_REGIONS + 1]; + + void regulateViews(workload::Views& views, const workload::Timings& timings); + +protected: + Config::Data _data; }; #endif // hifi_GameWorkload_h diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 27bbfbe0e3..e91d7cfdc6 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -190,18 +190,21 @@ const VectorOfMotionStates& PhysicalEntitySimulation::getObjectsToRemoveFromPhys for (auto entity: _entitiesToRemoveFromPhysics) { EntityMotionState* motionState = static_cast(entity->getPhysicsInfo()); assert(motionState); + // TODO CLEan this, just a n extra check to avoid the crash that shouldn;t happen + if (motionState) { - _entitiesToAddToPhysics.remove(entity); - if (entity->isDead() && entity->getElement()) { - _deadEntities.insert(entity); + _entitiesToAddToPhysics.remove(entity); + if (entity->isDead() && entity->getElement()) { + _deadEntities.insert(entity); + } + + _incomingChanges.remove(motionState); + removeOwnershipData(motionState); + _physicalObjects.remove(motionState); + + // remember this motionState and delete it later (after removing its RigidBody from the PhysicsEngine) + _objectsToDelete.push_back(motionState); } - - _incomingChanges.remove(motionState); - removeOwnershipData(motionState); - _physicalObjects.remove(motionState); - - // remember this motionState and delete it later (after removing its RigidBody from the PhysicsEngine) - _objectsToDelete.push_back(motionState); } _entitiesToRemoveFromPhysics.clear(); return _objectsToDelete; diff --git a/libraries/workload/src/workload/ViewTask.cpp b/libraries/workload/src/workload/ViewTask.cpp index d817ac6fdd..672078fb9a 100644 --- a/libraries/workload/src/workload/ViewTask.cpp +++ b/libraries/workload/src/workload/ViewTask.cpp @@ -62,11 +62,7 @@ void SetupViews::run(const WorkloadContextPointer& renderContext, const Input& i // Update regions based on the current config for (auto& v : outViews) { - if (data.applyViewRanges) { - View::updateRegionsFromBackFrontDistances(v, (float*) &data); - } else { - View::updateRegionsFromBackFronts(v); - } + View::updateRegionsFromBackFrontDistances(v, (float*) &data); } // outViews is ready to be used diff --git a/libraries/workload/src/workload/ViewTask.h b/libraries/workload/src/workload/ViewTask.h index 25fad29f20..dd1b60890c 100644 --- a/libraries/workload/src/workload/ViewTask.h +++ b/libraries/workload/src/workload/ViewTask.h @@ -27,7 +27,7 @@ namespace workload { Q_PROPERTY(bool forceViewHorizontal READ forceViewHorizontal WRITE setForceViewHorizontal NOTIFY dirty) Q_PROPERTY(bool simulateSecondaryCamera READ simulateSecondaryCamera WRITE setSimulateSecondaryCamera NOTIFY dirty) - Q_PROPERTY(bool applyViewRanges READ applyViewRanges WRITE setApplyViewRanges NOTIFY dirty) + public: @@ -55,9 +55,6 @@ namespace workload { bool simulateSecondaryCamera() const { return data.simulateSecondaryCamera; } void setSimulateSecondaryCamera(bool use) { data.simulateSecondaryCamera = use; emit dirty(); } - bool applyViewRanges() const { return data.applyViewRanges; } - void setApplyViewRanges(bool use) { data.applyViewRanges = use; emit dirty(); } - struct Data { float r1Back { 2.0f }; float r1Front { 10.0f }; @@ -72,8 +69,6 @@ namespace workload { bool useAvatarView{ false }; bool forceViewHorizontal{ false }; bool simulateSecondaryCamera{ false }; - bool applyViewRanges{ true }; - } data; signals: diff --git a/scripts/developer/utilities/workload/workloadInspector.qml b/scripts/developer/utilities/workload/workloadInspector.qml index ffe80f35f4..885d8ddb66 100644 --- a/scripts/developer/utilities/workload/workloadInspector.qml +++ b/scripts/developer/utilities/workload/workloadInspector.qml @@ -113,9 +113,9 @@ Rectangle { Separator {} HifiControls.CheckBox { boxSize: 20 - text: "Apply Front Back Ranges" - checked: Workload.getConfig("setupViews")["applyViewRanges"] - onCheckedChanged: { Workload.getConfig("setupViews")["applyViewRanges"] = checked; } + text: "Regulate View Ranges" + checked: Workload.getConfig("controlViews")["regulateViewRanges"] + onCheckedChanged: { Workload.getConfig("controlViews")["regulateViewRanges"] = checked; } } RowLayout {