diff --git a/src/RuntimeModuleManager.h b/src/RuntimeModuleManager.h index ce9051b..c0b69af 100644 --- a/src/RuntimeModuleManager.h +++ b/src/RuntimeModuleManager.h @@ -23,6 +23,7 @@ struct RuntimeModule { struct RuntimeModuleManager { std::vector mModules; int mNumUpdatesSinceLastModuleChange = 0; + int mTargetFPS = 30; void RegisterModule(const char* name); void UnregisterModules(); diff --git a/src/main.cc b/src/main.cc index c240e58..f8bc9f0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -231,7 +231,11 @@ int main(void) ImGui::Render(); - usleep(16000); + // Send the application to sleep if we have some time left for this frame + double frame_target_time = 1.0 / module_manager.mTargetFPS; + if (frame_delta_time < frame_target_time) { + usleep ((frame_target_time - frame_delta_time) * 1000000 * 0.98); + } if (glfwGetKey(gWindow, GLFW_KEY_F5) == GLFW_PRESS) { gFileModificationObserver->Update(); diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index a09df20..1638070 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -285,7 +285,10 @@ void Light::UpdateSplits(const Camera& camera) { assert(camera.mIsOrthographic == false); float near = camera.mNear; - float far = camera.mFar; + // Clamp the far plane of the camera so that we only + // create shadow maps for things that are relatively near + // the camera. + float far = fmin(camera.mFar, 10.0f); float length = far - near; float split_near = near; float aspect = camera.mWidth / camera.mHeight;