Compare commits
	
		
			3 Commits
		
	
	
		
			dc081ae2aa
			...
			d5dede5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d5dede5a61 | |||
| 719400068a | |||
| aaf8c6adc1 | 
@@ -35,6 +35,16 @@ namespace Components {
 | 
				
			|||||||
		float fade {1.f};
 | 
							float fade {1.f};
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct ConvertedTimeCache {
 | 
				
			||||||
 | 
							// calling localtime is expensive af
 | 
				
			||||||
 | 
							int tm_year {0};
 | 
				
			||||||
 | 
							int tm_yday {0};
 | 
				
			||||||
 | 
							int tm_mon {0};
 | 
				
			||||||
 | 
							int tm_mday {0};
 | 
				
			||||||
 | 
							int tm_hour {0};
 | 
				
			||||||
 | 
							int tm_min {0};
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // Components
 | 
					} // Components
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static constexpr float lerp(float a, float b, float t) {
 | 
					static constexpr float lerp(float a, float b, float t) {
 | 
				
			||||||
@@ -324,7 +334,8 @@ float ChatGui4::render(float time_delta) {
 | 
				
			|||||||
						//tmp_view.use<Message::Components::Timestamp>();
 | 
											//tmp_view.use<Message::Components::Timestamp>();
 | 
				
			||||||
						//tmp_view.each([&](const Message3 e, Message::Components::ContactFrom& c_from, Message::Components::ContactTo& c_to, Message::Components::Timestamp ts
 | 
											//tmp_view.each([&](const Message3 e, Message::Components::ContactFrom& c_from, Message::Components::ContactTo& c_to, Message::Components::Timestamp ts
 | 
				
			||||||
						//) {
 | 
											//) {
 | 
				
			||||||
						uint64_t prev_ts {0};
 | 
											//uint64_t prev_ts {0};
 | 
				
			||||||
 | 
											Components::ConvertedTimeCache prev_time {};
 | 
				
			||||||
						auto tmp_view = msg_reg.view<Message::Components::Timestamp>();
 | 
											auto tmp_view = msg_reg.view<Message::Components::Timestamp>();
 | 
				
			||||||
						for (auto view_it = tmp_view.rbegin(), view_last = tmp_view.rend(); view_it != view_last; view_it++) {
 | 
											for (auto view_it = tmp_view.rbegin(), view_last = tmp_view.rend(); view_it != view_last; view_it++) {
 | 
				
			||||||
							const Message3 e = *view_it;
 | 
												const Message3 e = *view_it;
 | 
				
			||||||
@@ -342,15 +353,12 @@ float ChatGui4::render(float time_delta) {
 | 
				
			|||||||
							// TODO: why?
 | 
												// TODO: why?
 | 
				
			||||||
							ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
 | 
												ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							{ // check if date changed
 | 
												if (msg_reg.all_of<Components::ConvertedTimeCache>(e)) { // check if date changed
 | 
				
			||||||
								// TODO: find defined ways of casting to time_t
 | 
													// TODO: move conversion up?
 | 
				
			||||||
								std::time_t prev = prev_ts / 1000;
 | 
													const auto& next_time = msg_reg.get<Components::ConvertedTimeCache>(e);
 | 
				
			||||||
								std::time_t next = ts.ts / 1000;
 | 
					 | 
				
			||||||
								std::tm prev_tm = *std::localtime(&prev);
 | 
					 | 
				
			||||||
								std::tm next_tm = *std::localtime(&next);
 | 
					 | 
				
			||||||
								if (
 | 
													if (
 | 
				
			||||||
									prev_tm.tm_yday != next_tm.tm_yday ||
 | 
														prev_time.tm_yday != next_time.tm_yday ||
 | 
				
			||||||
									prev_tm.tm_year != next_tm.tm_year // making sure
 | 
														prev_time.tm_year != next_time.tm_year // making sure
 | 
				
			||||||
								) {
 | 
													) {
 | 
				
			||||||
									// name
 | 
														// name
 | 
				
			||||||
									if (ImGui::TableNextColumn()) {
 | 
														if (ImGui::TableNextColumn()) {
 | 
				
			||||||
@@ -359,14 +367,14 @@ float ChatGui4::render(float time_delta) {
 | 
				
			|||||||
									// msg
 | 
														// msg
 | 
				
			||||||
									if (ImGui::TableNextColumn()) {
 | 
														if (ImGui::TableNextColumn()) {
 | 
				
			||||||
										ImGui::TextDisabled("DATE CHANGED from %d.%d.%d to %d.%d.%d",
 | 
															ImGui::TextDisabled("DATE CHANGED from %d.%d.%d to %d.%d.%d",
 | 
				
			||||||
											1900+prev_tm.tm_year, 1+prev_tm.tm_mon, prev_tm.tm_mday,
 | 
																1900+prev_time.tm_year, 1+prev_time.tm_mon, prev_time.tm_mday,
 | 
				
			||||||
											1900+next_tm.tm_year, 1+next_tm.tm_mon, next_tm.tm_mday
 | 
																1900+next_time.tm_year, 1+next_time.tm_mon, next_time.tm_mday
 | 
				
			||||||
										);
 | 
															);
 | 
				
			||||||
									}
 | 
														}
 | 
				
			||||||
									ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
 | 
														ImGui::TableNextRow(0, TEXT_BASE_HEIGHT);
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
								prev_ts = ts.ts;
 | 
													prev_time = next_time;
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -519,12 +527,24 @@ float ChatGui4::render(float time_delta) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
							// ts
 | 
												// ts
 | 
				
			||||||
							if (ImGui::TableNextColumn()) {
 | 
												if (ImGui::TableNextColumn()) {
 | 
				
			||||||
								auto time = std::chrono::system_clock::to_time_t(
 | 
													if (!msg_reg.all_of<Components::ConvertedTimeCache>(e)) {
 | 
				
			||||||
									std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>{std::chrono::milliseconds{ts.ts}}
 | 
														auto time = std::chrono::system_clock::to_time_t(
 | 
				
			||||||
								);
 | 
															std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>{std::chrono::milliseconds{ts.ts}}
 | 
				
			||||||
								auto localtime = std::localtime(&time);
 | 
														);
 | 
				
			||||||
 | 
														auto localtime = std::localtime(&time);
 | 
				
			||||||
 | 
														msg_reg.emplace<Components::ConvertedTimeCache>(
 | 
				
			||||||
 | 
															e,
 | 
				
			||||||
 | 
															localtime->tm_year,
 | 
				
			||||||
 | 
															localtime->tm_yday,
 | 
				
			||||||
 | 
															localtime->tm_mon,
 | 
				
			||||||
 | 
															localtime->tm_mday,
 | 
				
			||||||
 | 
															localtime->tm_hour,
 | 
				
			||||||
 | 
															localtime->tm_min
 | 
				
			||||||
 | 
														);
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
													const auto& ctc = msg_reg.get<Components::ConvertedTimeCache>(e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
								ImGui::Text("%.2d:%.2d", localtime->tm_hour, localtime->tm_min);
 | 
													ImGui::Text("%.2d:%.2d", ctc.tm_hour, ctc.tm_min);
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							// extra
 | 
												// extra
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -10,7 +10,6 @@
 | 
				
			|||||||
#include "./start_screen.hpp"
 | 
					#include "./start_screen.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
#include <future>
 | 
					 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <thread>
 | 
					#include <thread>
 | 
				
			||||||
#include <chrono>
 | 
					#include <chrono>
 | 
				
			||||||
@@ -29,8 +28,6 @@ int main(int argc, char** argv) {
 | 
				
			|||||||
		std::cerr << "SDL_Init failed (" << SDL_GetError() << ")\n";
 | 
							std::cerr << "SDL_Init failed (" << SDL_GetError() << ")\n";
 | 
				
			||||||
		return 1;
 | 
							return 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// me just messing with RAII cleanup
 | 
					 | 
				
			||||||
	auto sdl_scope = std::async(std::launch::deferred, &SDL_Quit);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// more RAII
 | 
						// more RAII
 | 
				
			||||||
	std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window {
 | 
						std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window {
 | 
				
			||||||
@@ -86,9 +83,7 @@ int main(int argc, char** argv) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
 | 
						ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
 | 
				
			||||||
	auto imgui_sdl_scope = std::async(std::launch::deferred, &ImGui_ImplSDL3_Shutdown);
 | 
					 | 
				
			||||||
	ImGui_ImplSDLRenderer3_Init(renderer.get());
 | 
						ImGui_ImplSDLRenderer3_Init(renderer.get());
 | 
				
			||||||
	auto imgui_sdlrenderer_scope = std::async(std::launch::deferred, &ImGui_ImplSDLRenderer3_Shutdown);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get());
 | 
						std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -213,6 +208,12 @@ int main(int argc, char** argv) {
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ImGui_ImplSDLRenderer3_Shutdown();
 | 
				
			||||||
 | 
						ImGui_ImplSDL3_Shutdown();
 | 
				
			||||||
 | 
						ImGui::DestroyContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SDL_Quit();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -376,7 +376,7 @@ Screen* MainScreen::render(float time_delta, bool&) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Screen* MainScreen::tick(float time_delta, bool& quit) {
 | 
					Screen* MainScreen::tick(float time_delta, bool& quit) {
 | 
				
			||||||
	quit = !tc.iterate(); // compute
 | 
						quit = !tc.iterate(time_delta); // compute
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tcm.iterate(time_delta); // compute
 | 
						tcm.iterate(time_delta); // compute
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,4 @@
 | 
				
			|||||||
#include "./tox_client.hpp"
 | 
					#include "./tox_client.hpp"
 | 
				
			||||||
#include "toxcore/tox.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// meh, change this
 | 
					// meh, change this
 | 
				
			||||||
#include <exception>
 | 
					#include <exception>
 | 
				
			||||||
@@ -121,10 +120,13 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ToxClient::~ToxClient(void) {
 | 
					ToxClient::~ToxClient(void) {
 | 
				
			||||||
 | 
						if (_tox_profile_dirty) {
 | 
				
			||||||
 | 
							saveToxProfile();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	tox_kill(_tox);
 | 
						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;
 | 
						Tox_Err_Events_Iterate err_e_it = TOX_ERR_EVENTS_ITERATE_OK;
 | 
				
			||||||
	auto* events = tox_events_iterate(_tox, false, &err_e_it);
 | 
						auto* events = tox_events_iterate(_tox, false, &err_e_it);
 | 
				
			||||||
	if (err_e_it == TOX_ERR_EVENTS_ITERATE_OK && events != nullptr) {
 | 
						if (err_e_it == TOX_ERR_EVENTS_ITERATE_OK && events != nullptr) {
 | 
				
			||||||
@@ -136,7 +138,8 @@ bool ToxClient::iterate(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	tox_events_free(events);
 | 
						tox_events_free(events);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_tox_profile_dirty) {
 | 
						_save_heat -= time_delta;
 | 
				
			||||||
 | 
						if (_tox_profile_dirty && _save_heat <= 0.f) {
 | 
				
			||||||
		saveToxProfile();
 | 
							saveToxProfile();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -180,5 +183,6 @@ void ToxClient::saveToxProfile(void) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_tox_profile_dirty = false;
 | 
						_tox_profile_dirty = false;
 | 
				
			||||||
 | 
						_save_heat = 10.f;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
 | 
				
			|||||||
		std::string _tox_profile_path;
 | 
							std::string _tox_profile_path;
 | 
				
			||||||
		std::string _tox_profile_password;
 | 
							std::string _tox_profile_password;
 | 
				
			||||||
		bool _tox_profile_dirty {true}; // set in callbacks
 | 
							bool _tox_profile_dirty {true}; // set in callbacks
 | 
				
			||||||
 | 
							float _save_heat {0.f};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		//ToxClient(/*const CommandLine& cl*/);
 | 
							//ToxClient(/*const CommandLine& cl*/);
 | 
				
			||||||
@@ -34,7 +35,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
 | 
				
			|||||||
		void setDirty(void) { _tox_profile_dirty = true; }
 | 
							void setDirty(void) { _tox_profile_dirty = true; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// returns false when we shoul stop the program
 | 
							// 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 stop(void); // let it know it should exit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; }
 | 
							void setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user