limit fps to 60 and disable imgui demo window

This commit is contained in:
Green Sky 2023-08-28 14:06:27 +02:00
parent 610ed10011
commit 9d9a486537
No known key found for this signature in database
3 changed files with 28 additions and 2 deletions

View File

@ -386,6 +386,7 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
[](const auto& path) -> bool { return std::filesystem::is_directory(path); }, [](const auto& path) -> bool { return std::filesystem::is_directory(path); },
[this, &reg, e](const auto& path) { [this, &reg, e](const auto& path) {
if (reg.valid(e)) { // still valid if (reg.valid(e)) { // still valid
// TODO: trim file?
reg.emplace<Message::Components::Transfer::ActionAccept>(e, path.string()); reg.emplace<Message::Components::Transfer::ActionAccept>(e, path.string());
_rmm.throwEventUpdate(reg, e); _rmm.throwEventUpdate(reg, e);
} }

View File

@ -12,9 +12,19 @@
#include <memory> #include <memory>
#include <future> #include <future>
#include <iostream> #include <iostream>
#include <thread>
#include <chrono>
int main(int argc, char** argv) { int main(int argc, char** argv) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { // setup hints
if (SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1") != SDL_TRUE) {
std::cerr << "Failed to set '" << SDL_HINT_VIDEO_ALLOW_SCREENSAVER << "' to 1\n";
}
auto last_time = std::chrono::steady_clock::now();
// actual setup
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "SDL_Init failed (" << SDL_GetError() << ")\n"; std::cerr << "SDL_Init failed (" << SDL_GetError() << ")\n";
return 1; return 1;
} }
@ -54,8 +64,13 @@ int main(int argc, char** argv) {
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get()); std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get());
bool quit = false; bool quit = false;
while (!quit) { while (!quit) {
auto new_time = std::chrono::steady_clock::now();
//const float time_delta {std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time).count()};
last_time = new_time;
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_QUIT) { if (event.type == SDL_EVENT_QUIT) {
@ -73,6 +88,11 @@ int main(int argc, char** argv) {
break; break;
} }
//float fps_target = 60.f;
//if (SDL_GetWindowFlags(window.get()) & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) {
//fps_target = 30.f;
//}
ImGui_ImplSDLRenderer3_NewFrame(); ImGui_ImplSDLRenderer3_NewFrame();
ImGui_ImplSDL3_NewFrame(); ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
@ -91,6 +111,11 @@ int main(int argc, char** argv) {
// clearing after present is (should) more performant, but first frame is a mess // clearing after present is (should) more performant, but first frame is a mess
SDL_SetRenderDrawColor(renderer.get(), 0x10, 0x10, 0x10, SDL_ALPHA_OPAQUE); SDL_SetRenderDrawColor(renderer.get(), 0x10, 0x10, 0x10, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer.get()); SDL_RenderClear(renderer.get());
std::this_thread::sleep_for( // time left to get to 60fps
std::chrono::duration<float, std::chrono::seconds::period>(0.0166f) // 60fps frame duration
- std::chrono::duration<float, std::chrono::seconds::period>(std::chrono::steady_clock::now() - new_time) // time used for rendering
);
} }
return 0; return 0;

View File

@ -84,7 +84,7 @@ Screen* MainScreen::poll(bool& quit) {
cg.render(); cg.render();
{ if constexpr (false) {
bool open = !quit; bool open = !quit;
ImGui::ShowDemoWindow(&open); ImGui::ShowDemoWindow(&open);
quit = !open; quit = !open;