diff --git a/src/main_screen.cpp b/src/main_screen.cpp index 41bf93c..dfa6240 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -376,7 +376,7 @@ Screen* MainScreen::render(float time_delta, bool&) { } Screen* MainScreen::tick(float time_delta, bool& quit) { - quit = !tc.iterate(); // compute + quit = !tc.iterate(time_delta); // compute tcm.iterate(time_delta); // compute diff --git a/src/tox_client.cpp b/src/tox_client.cpp index 7d62877..dec854b 100644 --- a/src/tox_client.cpp +++ b/src/tox_client.cpp @@ -1,5 +1,4 @@ #include "./tox_client.hpp" -#include "toxcore/tox.h" // meh, change this #include @@ -121,10 +120,13 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) } ToxClient::~ToxClient(void) { + if (_tox_profile_dirty) { + saveToxProfile(); + } tox_kill(_tox); } -bool ToxClient::iterate(void) { +bool ToxClient::iterate(float time_delta) { Tox_Err_Events_Iterate err_e_it = TOX_ERR_EVENTS_ITERATE_OK; auto* events = tox_events_iterate(_tox, false, &err_e_it); if (err_e_it == TOX_ERR_EVENTS_ITERATE_OK && events != nullptr) { @@ -136,7 +138,8 @@ bool ToxClient::iterate(void) { tox_events_free(events); - if (_tox_profile_dirty) { + _save_heat -= time_delta; + if (_tox_profile_dirty && _save_heat <= 0.f) { saveToxProfile(); } @@ -180,5 +183,6 @@ void ToxClient::saveToxProfile(void) { } _tox_profile_dirty = false; + _save_heat = 10.f; } diff --git a/src/tox_client.hpp b/src/tox_client.hpp index 208c95b..dc412b6 100644 --- a/src/tox_client.hpp +++ b/src/tox_client.hpp @@ -22,6 +22,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase { std::string _tox_profile_path; std::string _tox_profile_password; bool _tox_profile_dirty {true}; // set in callbacks + float _save_heat {0.f}; public: //ToxClient(/*const CommandLine& cl*/); @@ -34,7 +35,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase { void setDirty(void) { _tox_profile_dirty = true; } // returns false when we shoul stop the program - bool iterate(void); + bool iterate(float time_delta); void stop(void); // let it know it should exit void setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; }