From ce08ec2a1f7b193cbc8dfb9f7942692772c7b551 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 23 Jul 2018 05:16:16 +0200 Subject: [PATCH] improved SDL_GetTicks without SDL, and getticks() replaced with it --- fake-mobile.cpp | 2 -- hyperroid/app/src/main/jni/hyper.cpp | 2 -- init.cpp | 4 +--- util.cpp | 21 +++++++++++++-------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/fake-mobile.cpp b/fake-mobile.cpp index 55318943..0a967200 100644 --- a/fake-mobile.cpp +++ b/fake-mobile.cpp @@ -86,8 +86,6 @@ int textwidth(int siz, const string &str) { char action; -int getticks() { return SDL_GetTicks(); } - bool currentlyConnecting() { return false; } bool currentlyConnected() { return false; } void viewAchievements() { printf("view Achievements\n"); } diff --git a/hyperroid/app/src/main/jni/hyper.cpp b/hyperroid/app/src/main/jni/hyper.cpp index e30fabe6..08cf2257 100644 --- a/hyperroid/app/src/main/jni/hyper.cpp +++ b/hyperroid/app/src/main/jni/hyper.cpp @@ -276,8 +276,6 @@ void shareScore(MOBPAR_FORMAL) { env->DeleteLocalRef(cls); } -int nticks; int getticks() { return nticks; } - extern "C" void Java_com_roguetemple_hyperroid_HyperRogue_draw(MOBPAR_FORMAL) { // if(debfile) fprintf(debfile, "draw started.\n"), fflush(debfile); diff --git a/init.cpp b/init.cpp index 5dc11ee1..e611ef07 100644 --- a/init.cpp +++ b/init.cpp @@ -223,8 +223,6 @@ void handleclick(MOBPAR_FORMAL) { int touchedAt; -int getticks(); - #if CAP_ANDROIDSHARE void shareScore(MOBPAR_FORMAL); #endif @@ -233,7 +231,7 @@ void mobile_draw(MOBPAR_FORMAL) { optimizeview(); - int lastt = ticks; ticks = getticks(); + int lastt = ticks; ticks = SDL_GetTicks(); if(lastt > ticks) lastt = ticks; int tdiff = ticks - lastt; diff --git a/util.cpp b/util.cpp index 4b0c2bd1..34601926 100644 --- a/util.cpp +++ b/util.cpp @@ -6,16 +6,21 @@ namespace hr { #if CAP_TIMEOFDAY -long long getms() { - struct timeval tval; - gettimeofday(&tval, NULL); - return tval.tv_sec * 1000000 + tval.tv_usec; +#if !CAP_SDL +int lastusec; +int uticks; + +int SDL_GetTicks() { + struct timeval tim; + gettimeofday(&tim, NULL); + int newusec = tim.tv_usec; + uticks += newusec - lastusec; + if(newusec <= lastusec) + uticks += 1000000; + lastusec = newusec; + return uticks / 1000; } -#if !CAP_SDL -int SDL_GetTicks() { - return getms() / 1000; - } #endif #endif