Skip to content

Commit 2846aec

Browse files
committed
Fixed camera movement
1 parent 466df1c commit 2846aec

File tree

1 file changed

+5
-34
lines changed
  • examples_tests/35.GeometryCreator

1 file changed

+5
-34
lines changed

examples_tests/35.GeometryCreator/main.cpp

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,19 @@ class GeometryCreatorSampleApp : public ApplicationBase
157157
video::IGPUObjectFromAssetConverter::SParams cpu2gpuParams;
158158
core::smart_refctd_ptr<nbl::video::IUtilities> utilities;
159159

160-
int32_t m_resourceIx = -1;
161160
core::smart_refctd_ptr<video::IGPUFence> m_frameComplete[FRAMES_IN_FLIGHT] = { nullptr };
162161
core::smart_refctd_ptr<video::IGPUSemaphore> m_imageAcquire[FRAMES_IN_FLIGHT] = { nullptr };
163162
core::smart_refctd_ptr<video::IGPUSemaphore> m_renderFinished[FRAMES_IN_FLIGHT] = { nullptr };
164163
core::smart_refctd_ptr<video::IGPUCommandBuffer> m_commandBuffers[FRAMES_IN_FLIGHT];
165164

166-
std::chrono::system_clock::time_point m_lastTime;
167-
double m_time_sum = 0;
168-
size_t m_frame_count = 0ull;
169-
double m_dtList[NBL_FRAMES_TO_AVERAGE] = {};
170-
bool m_frameDataFilled = false;
165+
int32_t m_resourceIx = -1;
171166
uint32_t m_acquiredNextFBO = {};
172167

173168
CommonAPI::InputSystem::ChannelReader<IMouseEventChannel> m_mouse;
174169
CommonAPI::InputSystem::ChannelReader<IKeyboardEventChannel> m_keyboard;
175170
std::unique_ptr<Camera> m_camera = nullptr;
176171
std::unique_ptr<Objects> m_cpuGpuObjects = nullptr;
172+
video::CDumbPresentationOracle oracle;
177173

178174
public:
179175

@@ -479,10 +475,8 @@ class GeometryCreatorSampleApp : public ApplicationBase
479475
core::vectorSIMDf cameraPosition(0, 5, -10);
480476
matrix4SIMD projectionMatrix = matrix4SIMD::buildProjectionMatrixPerspectiveFovLH(core::radians(60.0f), float(WIN_W) / WIN_H, 0.001, 1000);
481477
m_camera = std::make_unique<Camera>(cameraPosition, core::vectorSIMDf(0, 0, 0), projectionMatrix, 10.f, 1.f);
482-
m_lastTime = std::chrono::system_clock::now();
483-
484-
for (size_t i = 0ull; i < NBL_FRAMES_TO_AVERAGE; ++i)
485-
m_dtList[i] = 0.0;
478+
479+
oracle.reportBeginFrameRecord();
486480

487481
logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_GRAPHICS].get(), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, m_commandBuffers);
488482

@@ -530,30 +524,7 @@ class GeometryCreatorSampleApp : public ApplicationBase
530524
else
531525
fence = logicalDevice->createFence(static_cast<video::IGPUFence::E_CREATE_FLAGS>(0));
532526

533-
auto renderStart = std::chrono::system_clock::now();
534-
const auto renderDt = std::chrono::duration_cast<std::chrono::milliseconds>(renderStart - m_lastTime).count();
535-
m_lastTime = renderStart;
536-
{ // Calculate Simple Moving Average for FrameTime
537-
m_time_sum -= m_dtList[m_frame_count];
538-
m_time_sum += renderDt;
539-
m_dtList[m_frame_count] = renderDt;
540-
m_frame_count++;
541-
if (m_frame_count >= NBL_FRAMES_TO_AVERAGE)
542-
{
543-
m_frameDataFilled = true;
544-
m_frame_count = 0;
545-
}
546-
547-
}
548-
const double averageFrameTime = m_frameDataFilled ? (m_time_sum / (double)NBL_FRAMES_TO_AVERAGE) : (m_time_sum / m_frame_count);
549-
550-
#ifdef NBL_MORE_LOGS
551-
logger->log("renderDt = %f ------ averageFrameTime = %f", system::ILogger::ELL_INFO, renderDt, averageFrameTime);
552-
#endif // NBL_MORE_LOGS
553-
554-
auto averageFrameTimeDuration = std::chrono::duration<double, std::milli>(averageFrameTime);
555-
auto nextPresentationTime = renderStart + averageFrameTimeDuration;
556-
auto nextPresentationTimeStamp = std::chrono::duration_cast<std::chrono::microseconds>(nextPresentationTime.time_since_epoch());
527+
const auto nextPresentationTimeStamp = oracle.acquireNextImage(swapchain.get(), m_imageAcquire[m_resourceIx].get(), nullptr, &m_acquiredNextFBO);
557528

558529
inputSystem->getDefaultMouse(&m_mouse);
559530
inputSystem->getDefaultKeyboard(&m_keyboard);

0 commit comments

Comments
 (0)