#include #include #include #include #include #include #include "./tox_private_impl.hpp" #include #include #include #include "./tox_client.hpp" #include "./auto_dirty.hpp" #include #include #include #include #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) #include #include #elif defined (_WIN32) #include #endif std::atomic_bool quit = false; #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32) void sigint_handler(int signo) { if (signo == SIGINT) { quit = true; } } #endif int main(int argc, char** argv) { #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) struct sigaction sigint_action; sigint_action.sa_handler = sigint_handler; sigemptyset (&sigint_action.sa_mask); sigint_action.sa_flags = 0; sigaction(SIGINT, &sigint_action, NULL); #elif defined (_WIN32) signal(SIGINT, sigint_handler); #endif auto last_time = std::chrono::steady_clock::now(); // TODO: parse arg // totato -p // HACK: config std::string tox_profile_path {"totato.tox"}; SimpleConfigModel conf; Contact3Registry cr; RegistryMessageModel rmm{cr}; MessageTimeSort mts{rmm}; PluginManager pm; ToxEventLogger tel{std::cout}; ToxClient tc{tox_profile_path, ""}; ToxPrivateImpl tpi{tc.getTox()}; AutoDirty ad{tc}; ToxContactModel2 tcm{cr, tc, tc}; ToxMessageManager tmm{rmm, cr, tcm, tc, tc}; ToxTransferManager ttm{rmm, cr, tcm, tc, tc}; { // setup plugin instances g_provideInstance("ConfigModelI", "host", &conf); g_provideInstance("Contact3Registry", "host", &cr); g_provideInstance("RegistryMessageModel", "host", &rmm); //g_provideInstance("ToxI", "host", &tc); //g_provideInstance("ToxPrivateI", "host", &tpi); //g_provideInstance("ToxEventProviderI", "host", &tc); //g_provideInstance("ToxContactModel2", "host", &tcm); // TODO: pm? } for (const auto& ppath : {"../../solanaceae_ecosystem/build/bin/libplugin_transfer_auto_accept.so"}) { if (!pm.add(ppath)) { std::cerr << "TOTATO error: loading plugin '" << ppath << "' failed!\n"; // thow? assert(false && "failed to load plugin"); } } conf.dump(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); // at startup, just to be safe while (!quit) { //auto new_time = std::chrono::steady_clock::now(); quit = !tc.iterate(); tcm.iterate(/*time_delta*/0.02f); ttm.iterate(); mts.iterate(); pm.tick(/*time_delta*/0.02f); //std::this_thread::sleep_for( // time left to get to 60fps //std::chrono::duration(0.0166f) // 60fps frame duration //- std::chrono::duration(std::chrono::steady_clock::now() - new_time) // time used for rendering //); std::this_thread::sleep_for(std::chrono::milliseconds(20)); // HACK: until i figure out the best main loop } std::cout << "\nTOTATO shutting down...\n"; return 0; }