Showing the changes to interface/src/workload/GameWorkload.cpp (1 of 3 files). Show all
Unified · Split
| @@ -15,77 +15,6 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | #include "PhysicsBoundary.h" |
| 17 | 17 | |
| 18 | −ControlViews::ControlViews() { | |
| 19 | − regionBackFronts[0] = glm::vec2(1.0f, 3.0f); | |
| 20 | − regionBackFronts[1] = glm::vec2(1.0f, 5.0f); | |
| 21 | − regionBackFronts[2] = glm::vec2(1.0f, 10.0f); | |
| 22 | − regionRegulators[0] = Regulator(std::chrono::milliseconds(2), regionBackFronts[0], 5.0f * regionBackFronts[0], glm::vec2(0.4f, 0.2f), 0.5f * glm::vec2(0.3f, 0.2f)); | |
| 23 | − regionRegulators[1] = Regulator(std::chrono::milliseconds(2), regionBackFronts[1], 8.0f * regionBackFronts[1], glm::vec2(0.4f, 0.2f), 0.5f * glm::vec2(0.3f, 0.2f)); | |
| 24 | − regionRegulators[2] = Regulator(std::chrono::milliseconds(2), regionBackFronts[2], 10.0f * regionBackFronts[2], glm::vec2(0.4f, 0.2f), 0.5f * glm::vec2(0.3f, 0.2f)); | |
| 25 | −} | |
| 26 | − | |
| 27 | −void ControlViews::configure(const Config& config) { | |
| 28 | − _data = config.data; | |
| 29 | −} | |
| 30 | − | |
| 31 | −void ControlViews::run(const workload::WorkloadContextPointer& runContext, const Input& inputs, Output& outputs) { | |
| 32 | − const auto& inViews = inputs.get0(); | |
| 33 | − const auto& inTimings = inputs.get1(); | |
| 34 | − auto& outViews = outputs; | |
| 35 | − outViews.clear(); | |
| 36 | − outViews = inViews; | |
| 37 | − | |
| 38 | − if (_data.regulateViewRanges && inTimings.size()) { | |
| 39 | − regulateViews(outViews, inTimings); | |
| 40 | − | |
| 41 | − auto config = std::static_pointer_cast<Config>(runContext->jobConfig); | |
| 42 | − config->dataExport = _dataExport; | |
| 43 | − config->emitDirty(); | |
| 44 | − } | |
| 45 | − | |
| 46 | − | |
| 47 | −} | |
| 48 | − | |
| 49 | −glm::vec2 Regulator::run(const Timing_ns& regulationDuration, const Timing_ns& measured, const glm::vec2& current) { | |
| 50 | − glm::vec2 next = current; | |
| 51 | − | |
| 52 | − // Regulate next value based on current moving toward the goal budget | |
| 53 | − float error_ms = std::chrono::duration<float, std::milli>(_budget - measured).count(); | |
| 54 | − float coef = error_ms / std::chrono::duration<float, std::milli>(regulationDuration).count(); | |
| 55 | − next += coef * (error_ms < 0.0f ? _speedDown : _speedUp); | |
| 56 | − | |
| 57 | − // Clamp to min max | |
| 58 | − next = glm::clamp(next, _minRange, _maxRange); | |
| 59 | − | |
| 60 | − return next; | |
| 61 | −} | |
| 62 | − | |
| 63 | −void ControlViews::regulateViews(workload::Views& outViews, const workload::Timings& timings) { | |
| 64 | − | |
| 65 | − for (auto& outView : outViews) { | |
| 66 | − for (int r = 0; r < workload::Region::NUM_VIEW_REGIONS; r++) { | |
| 67 | − outView.regionBackFronts[r] = regionBackFronts[r]; | |
| 68 | − } | |
| 69 | − } | |
| 70 | − | |
| 71 | − auto loopDuration = std::chrono::nanoseconds{ std::chrono::milliseconds(16) }; | |
| 72 | − _dataExport.ranges[workload::Region::R1] = regionBackFronts[workload::Region::R1] = regionRegulators[workload::Region::R1].run(loopDuration, timings[0], regionBackFronts[workload::Region::R1]); | |
| 73 | − _dataExport.ranges[workload::Region::R2] = regionBackFronts[workload::Region::R2] = regionRegulators[workload::Region::R2].run(loopDuration, timings[0], regionBackFronts[workload::Region::R2]); | |
| 74 | − _dataExport.ranges[workload::Region::R3] = regionBackFronts[workload::Region::R3] = regionRegulators[workload::Region::R3].run(loopDuration, timings[1], regionBackFronts[workload::Region::R3]); | |
| 75 | − | |
| 76 | − _dataExport.timings[workload::Region::R1] = std::chrono::duration<float, std::milli>(timings[0]).count(); | |
| 77 | − _dataExport.timings[workload::Region::R2] = _dataExport.timings[workload::Region::R1]; | |
| 78 | − _dataExport.timings[workload::Region::R3] = std::chrono::duration<float, std::milli>(timings[1]).count(); | |
| 79 | − | |
| 80 | − for (auto& outView : outViews) { | |
| 81 | − outView.regionBackFronts[workload::Region::R1] = regionBackFronts[workload::Region::R1]; | |
| 82 | − outView.regionBackFronts[workload::Region::R2] = regionBackFronts[workload::Region::R2]; | |
| 83 | − outView.regionBackFronts[workload::Region::R3] = regionBackFronts[workload::Region::R3]; | |
| 84 | − | |
| 85 | − workload::View::updateRegionsFromBackFronts(outView); | |
| 86 | − } | |
| 87 | −} | |
| 88 | − | |
| 89 | 18 | class WorkloadEngineBuilder { |
| 90 | 19 | public: |
| 91 | 20 | public: |
| @@ -99,8 +28,8 @@ public: · 7 unmodified lines | ||
| 99 | 28 | |
| 100 | 29 | const auto usedViews = model.addJob<workload::SetupViews>("setupViews", inViews); |
| 101 | 30 | |
| 102 | − const auto controlViewsIn = ControlViews::Input(usedViews, inTimings).asVarying(); | |
| 103 | − const auto fixedViews = model.addJob<ControlViews>("controlViews", controlViewsIn); | |
| 31 | + const auto controlViewsIn = workload::ControlViews::Input(usedViews, inTimings).asVarying(); | |
| 32 | + const auto fixedViews = model.addJob<workload::ControlViews>("controlViews", controlViewsIn); | |
| 104 | 33 | |
| 105 | 34 | const auto regionTrackerOut = model.addJob<workload::SpaceClassifierTask>("spaceClassifier", fixedViews); |
| 106 | 35 | |