main.cpp
1 #include <atomic> 2 3 #include <thread> 4 5 #include "server/server.h" 6 #include "client/client.h" 7 #include "common/themes.h" 8 PLATFORM platform=LINUX; 9 std::string androidpackage="kn.kinfuyuki.forespend"; 10 inline const char* COMMONCONFIG(){return "common.tdf";} 11 tiny::ErrorLevel tiny::level{4}; 12 int main(int argc, char** argv) { 13 { 14 system("echo $PWD"); 15 system("ls $PWD/res"); 16 system("ls $PWD/res/fonts"); 17 } 18 enginend::program* game; 19 tiny::startup("forespend","0.03g-rewrite.5"); 20 21 bool isserver = false; 22 if (argc>1) { 23 for (int i=1;i<argc;i++) { 24 if (argv[i]=="server ") { 25 isserver = true; 26 } 27 } 28 } 29 if (isserver) game = new server();else game = new client(); 30 game->boot(); 31 std::atomic<bool> running{true}; 32 std::thread tickthread([game, &running]() { 33 double tickrate=1.0/game->tickrate; 34 auto lasttick=std::chrono::high_resolution_clock::now(); 35 36 while (running) { 37 auto now=std::chrono::high_resolution_clock::now(); 38 double elapsed=std::chrono::duration_cast<std::chrono::duration<double>>(now-lasttick).count(); 39 40 if (elapsed>=tickrate) { 41 game->tick(); 42 lasttick=now; 43 } else { 44 std::this_thread::sleep_for(std::chrono::duration<double>(tickrate-elapsed)); 45 } 46 } 47 }); 48 49 double framerate=1.0/game->framerate; 50 auto lastframe=std::chrono::high_resolution_clock::now(); 51 while (!WindowShouldClose()) { 52 auto now=std::chrono::high_resolution_clock::now(); 53 double elapsed=std::chrono::duration_cast<std::chrono::duration<double>>(now-lastframe).count(); 54 55 if (elapsed>=framerate) { 56 game->draw(); 57 lastframe=now; 58 } else { 59 WaitTime(framerate-elapsed); 60 } 61 } 62 game->exit(); 63 return 0; 64 }