Compare commits

...

6 Commits

Author SHA1 Message Date
7d0e5c80bd lil dep update 2024-02-04 12:48:04 +01:00
f716ad9dd1 limit max main loop sleep 2024-02-03 20:49:52 +01:00
671772a20e min fps for inactive reduced now 1fps 2024-02-03 19:07:14 +01:00
b0173f6d68 tox iterate interval pow(1.6)
fix faux offline inbetween timer
crop by default
2024-02-03 15:00:32 +01:00
3da5872df8 fix tffom and have it actually functioning 2024-02-03 01:05:50 +01:00
3deb6e8469 fix using bool for timestamps (oops) 2024-02-02 20:55:20 +01:00
8 changed files with 75 additions and 36 deletions

View File

@ -178,9 +178,13 @@ int main(int argc, char** argv) {
//) //)
//)); //));
const float min_delay = std::min<float>( const float min_delay =
screen->nextTick() - time_delta_tick, std::min<float>(
screen->nextRender() - time_delta_render std::min<float>(
screen->nextTick() - time_delta_tick,
screen->nextRender() - time_delta_render
),
0.25f // dont sleep too long
) * 1000.f; ) * 1000.f;
if (min_delay > 0.f) { if (min_delay > 0.f) {

View File

@ -5,6 +5,7 @@
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <memory> #include <memory>
#include <cmath>
MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins) : MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins) :
renderer(renderer_), renderer(renderer_),
@ -227,7 +228,7 @@ Screen* MainScreen::render(float time_delta, bool&) {
_window_hidden _window_hidden
) )
) { ) {
_render_interval = std::min<float>(1.f/4.f, pm_interval); _render_interval = std::min<float>(1.f/1.f, pm_interval);
} else { } else {
_render_interval = std::min<float>(1.f/60.f, pm_interval); _render_interval = std::min<float>(1.f/60.f, pm_interval);
} }
@ -253,7 +254,9 @@ Screen* MainScreen::tick(float time_delta, bool& quit) {
mts.iterate(); // compute mts.iterate(); // compute
_min_tick_interval = std::min<float>( _min_tick_interval = std::min<float>(
tc.toxIterationInterval()/1000.f, // HACK: pow by 1.6 to increase 50 -> ~500 (~522)
// and it does not change 1
std::pow(tc.toxIterationInterval(), 1.6f)/1000.f,
pm_interval pm_interval
); );
_min_tick_interval = std::min<float>( _min_tick_interval = std::min<float>(
@ -261,6 +264,8 @@ Screen* MainScreen::tick(float time_delta, bool& quit) {
fo_interval fo_interval
); );
//std::cout << "MS: min tick interval: " << _min_tick_interval << "\n";
switch (_compute_perf_mode) { switch (_compute_perf_mode) {
// normal 1ms lower bound // normal 1ms lower bound
case 0: _min_tick_interval = std::max<float>(_min_tick_interval, 0.001f); break; case 0: _min_tick_interval = std::max<float>(_min_tick_interval, 0.001f); break;

View File

@ -69,7 +69,7 @@ struct MainScreen final : public Screen {
bool _show_tool_style_editor {false}; bool _show_tool_style_editor {false};
bool _window_hidden {false}; bool _window_hidden {false};
bool _window_hidden_ts {0}; uint64_t _window_hidden_ts {0};
float _time_since_event {0.f}; float _time_since_event {0.f};
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins); MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);

View File

@ -32,7 +32,7 @@ struct SendImagePopup {
Rect crop_rect; Rect crop_rect;
Rect crop_before_drag; Rect crop_before_drag;
bool cropping {false}; bool cropping {true};
bool dragging_last_frame_ul {false}; bool dragging_last_frame_ul {false};
bool dragging_last_frame_lr {false}; bool dragging_last_frame_lr {false};

View File

@ -10,6 +10,8 @@
#include <limits> #include <limits>
#include <cstdint> #include <cstdint>
//#include <iostream>
namespace Message::Components { namespace Message::Components {
struct LastSendAttempt { struct LastSendAttempt {
uint64_t ts {0}; uint64_t ts {0};
@ -29,15 +31,17 @@ ToxFriendFauxOfflineMessaging::ToxFriendFauxOfflineMessaging(
ToxI& t, ToxI& t,
ToxEventProviderI& tep ToxEventProviderI& tep
) : _cr(cr), _rmm(rmm), _tcm(tcm), _t(t), _tep(tep) { ) : _cr(cr), _rmm(rmm), _tcm(tcm), _t(t), _tep(tep) {
_tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS);
} }
float ToxFriendFauxOfflineMessaging::tick(float time_delta) { float ToxFriendFauxOfflineMessaging::tick(float time_delta) {
// hard limit interval to once per minute _interval_timer -= time_delta;
_interval_timer += time_delta; if (_interval_timer > 0.f) {
if (_interval_timer < 1.f * 60.f) { return std::max(_interval_timer, 0.001f); // TODO: min next timer
return std::max(60.f - _interval_timer, 0.001f); // TODO: min next timer
} }
_interval_timer = 0.f; // interval ~ once per minute
_interval_timer = 60.f;
const uint64_t ts_now = Message::getTimeMS(); const uint64_t ts_now = Message::getTimeMS();
@ -50,37 +54,47 @@ float ToxFriendFauxOfflineMessaging::tick(float time_delta) {
// cleanup // cleanup
if (_cr.all_of<Contact::Components::NextSendAttempt>(c)) { if (_cr.all_of<Contact::Components::NextSendAttempt>(c)) {
_cr.remove<Contact::Components::NextSendAttempt>(c); _cr.remove<Contact::Components::NextSendAttempt>(c);
auto* mr = static_cast<const RegistryMessageModel&>(_rmm).get(c);
if (mr != nullptr) {
mr->storage<Message::Components::LastSendAttempt>().clear();
}
} }
} else { } else {
if (!_cr.all_of<Contact::Components::NextSendAttempt>(c)) { if (!_cr.all_of<Contact::Components::NextSendAttempt>(c)) {
const auto& nsa = _cr.emplace<Contact::Components::NextSendAttempt>(c, ts_now + uint64_t(_delay_after_cc*1000)); // wait before first message is sent if (false) { // has unsent messages
min_next_attempt_ts = std::min(min_next_attempt_ts, nsa.ts); const auto& nsa = _cr.emplace<Contact::Components::NextSendAttempt>(c, ts_now + uint64_t(_delay_after_cc*1000)); // wait before first message is sent
} else { min_next_attempt_ts = std::min(min_next_attempt_ts, nsa.ts);
auto& next_attempt = _cr.get<Contact::Components::NextSendAttempt>(c).ts; }
} else {
if (doFriendMessageCheck(c, tfe)) { auto ret = doFriendMessageCheck(c, tfe);
next_attempt = ts_now + uint64_t(_delay_inbetween*1000); if (ret == dfmc_Ret::SENT_THIS_TICK) {
const auto ts = _cr.get<Contact::Components::NextSendAttempt>(c).ts = ts_now + uint64_t(_delay_inbetween*1000);
min_next_attempt_ts = std::min(min_next_attempt_ts, ts);
} else if (ret == dfmc_Ret::TOO_SOON) {
// TODO: set to _delay_inbetween? prob expensive for no good reason
min_next_attempt_ts = std::min(min_next_attempt_ts, _cr.get<Contact::Components::NextSendAttempt>(c).ts);
} else {
_cr.remove<Contact::Components::NextSendAttempt>(c);
} }
min_next_attempt_ts = std::min(min_next_attempt_ts, next_attempt);
} }
} }
}); });
if (min_next_attempt_ts <= ts_now) { if (min_next_attempt_ts <= ts_now) {
// we (probably) sent this iterate // we (probably) sent this iterate
_interval_timer = 60.f - 0.1f; // TODO: ugly magic _interval_timer = 0.1f; // TODO: ugly magic
return 0.1f;
} else if (min_next_attempt_ts == std::numeric_limits<uint64_t>::max()) { } else if (min_next_attempt_ts == std::numeric_limits<uint64_t>::max()) {
// nothing to sync or all offline that need syncing // nothing to sync or all offline that need syncing
return 60.f; // TODO: ugly magic
} else { } else {
// TODO: ugly magic _interval_timer = std::min(_interval_timer, (min_next_attempt_ts - ts_now) / 1000.f);
return _interval_timer = 60.f - std::min(60.f, (min_next_attempt_ts - ts_now) / 1000.f);
} }
//std::cout << "TFFOM: iterate (i:" << _interval_timer << ")\n";
return _interval_timer;
} }
bool ToxFriendFauxOfflineMessaging::doFriendMessageCheck(const Contact3 c, const Contact::Components::ToxFriendEphemeral& tfe) { ToxFriendFauxOfflineMessaging::dfmc_Ret ToxFriendFauxOfflineMessaging::doFriendMessageCheck(const Contact3 c, const Contact::Components::ToxFriendEphemeral& tfe) {
// walk all messages and check if // walk all messages and check if
// unacked message // unacked message
// timeouts for exising unacked messages expired (send) // timeouts for exising unacked messages expired (send)
@ -88,7 +102,7 @@ bool ToxFriendFauxOfflineMessaging::doFriendMessageCheck(const Contact3 c, const
auto* mr = static_cast<const RegistryMessageModel&>(_rmm).get(c); auto* mr = static_cast<const RegistryMessageModel&>(_rmm).get(c);
if (mr == nullptr) { if (mr == nullptr) {
// no messages // no messages
return false; return dfmc_Ret::NO_MSG;
} }
const uint64_t ts_now = Message::getTimeMS(); const uint64_t ts_now = Message::getTimeMS();
@ -98,6 +112,7 @@ bool ToxFriendFauxOfflineMessaging::doFriendMessageCheck(const Contact3 c, const
// we assume sorted // we assume sorted
// ("reverse" iteration <.<) // ("reverse" iteration <.<)
auto msg_view = mr->view<Message::Components::Timestamp>(); auto msg_view = mr->view<Message::Components::Timestamp>();
bool valid_unsent {false};
// we search for the oldest, not too recently sent, unconfirmed message // we search for the oldest, not too recently sent, unconfirmed message
for (auto it = msg_view.rbegin(), view_end = msg_view.rend(); it != view_end; it++) { for (auto it = msg_view.rbegin(), view_end = msg_view.rend(); it != view_end; it++) {
const Message3 msg = *it; const Message3 msg = *it;
@ -119,6 +134,12 @@ bool ToxFriendFauxOfflineMessaging::doFriendMessageCheck(const Contact3 c, const
continue; // skip continue; // skip
} }
if (mr->get<Message::Components::ContactTo>(msg).c != c) {
continue; // not outbound (in private)
}
valid_unsent = true;
uint64_t msg_ts = msg_view.get<Message::Components::Timestamp>(msg).ts; uint64_t msg_ts = msg_view.get<Message::Components::Timestamp>(msg).ts;
if (mr->all_of<Message::Components::TimestampWritten>(msg)) { if (mr->all_of<Message::Components::TimestampWritten>(msg)) {
msg_ts = mr->get<Message::Components::TimestampWritten>(msg).ts; msg_ts = mr->get<Message::Components::TimestampWritten>(msg).ts;
@ -155,12 +176,17 @@ bool ToxFriendFauxOfflineMessaging::doFriendMessageCheck(const Contact3 c, const
} // else error } // else error
// we sent our message, no point further iterating // we sent our message, no point further iterating
return true; return dfmc_Ret::SENT_THIS_TICK;
} }
// TODO: somehow cleanup lsa if (!valid_unsent) {
// somehow cleanup lsa
mr->storage<Message::Components::LastSendAttempt>().clear();
//std::cout << "TFFOM: all sent, deleting lsa\n";
return dfmc_Ret::NO_MSG;
}
return false; return dfmc_Ret::TOO_SOON;
} }
bool ToxFriendFauxOfflineMessaging::onToxEvent(const Tox_Event_Friend_Connection_Status* e) { bool ToxFriendFauxOfflineMessaging::onToxEvent(const Tox_Event_Friend_Connection_Status* e) {
@ -180,8 +206,7 @@ bool ToxFriendFauxOfflineMessaging::onToxEvent(const Tox_Event_Friend_Connection
_cr.emplace_or_replace<Contact::Components::NextSendAttempt>(c, Message::getTimeMS() + uint64_t(_delay_after_cc*1000)); // wait before first message is sent _cr.emplace_or_replace<Contact::Components::NextSendAttempt>(c, Message::getTimeMS() + uint64_t(_delay_after_cc*1000)); // wait before first message is sent
// TODO: ugly magic _interval_timer = 0.f;
_interval_timer = 60.f - 0.1f;
return false; return false;
} }

View File

@ -39,10 +39,15 @@ class ToxFriendFauxOfflineMessaging : public ToxEventI {
float tick(float time_delta); float tick(float time_delta);
private: private:
enum class dfmc_Ret {
TOO_SOON,
SENT_THIS_TICK,
NO_MSG,
};
// only called for online friends // only called for online friends
// returns true if a message was sent // returns true if a message was sent
// dont call this too often // dont call this too often
bool doFriendMessageCheck(const Contact3 c, const Contact::Components::ToxFriendEphemeral& tfe); dfmc_Ret doFriendMessageCheck(const Contact3 c, const Contact::Components::ToxFriendEphemeral& tfe);
protected: protected:
bool onToxEvent(const Tox_Event_Friend_Connection_Status* e) override; bool onToxEvent(const Tox_Event_Friend_Connection_Status* e) override;