# HG changeset patch # User John Tsiombikas # Date 1443067777 -10800 # Node ID 661bf09db398148564afeaeed5994943ea789394 # Parent a3c4fcc9f8f39238d7872a87e4ad96fc71042fdd - replaced Quartz timer with cross-platform timer code - protected goatkit builtin theme function from being optimized out diff -r a3c4fcc9f8f3 -r 661bf09db398 istereo.xcodeproj/project.pbxproj --- a/istereo.xcodeproj/project.pbxproj Thu Sep 24 06:49:25 2015 +0300 +++ b/istereo.xcodeproj/project.pbxproj Thu Sep 24 07:09:37 2015 +0300 @@ -30,6 +30,7 @@ 060ECB071BB36FD800CE9B80 /* linux-libertine_s24.glyphmap in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */; settings = {ASSET_TAGS = (); }; }; 060ECB091BB3989500CE9B80 /* uitheme.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB081BB3989500CE9B80 /* uitheme.cc */; settings = {ASSET_TAGS = (); }; }; 060ECB0B1BB3A8DB00CE9B80 /* font.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */; settings = {ASSET_TAGS = (); }; }; + 060ECB0E1BB3AC0D00CE9B80 /* timer.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB0C1BB3AC0D00CE9B80 /* timer.c */; settings = {ASSET_TAGS = (); }; }; 0669D67F1BA85DDE00611CFA /* app_delegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67B1BA85DDE00611CFA /* app_delegate.m */; }; 0669D6801BA85DDE00611CFA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67C1BA85DDE00611CFA /* main.m */; }; 0669D6811BA85DDE00611CFA /* viewctl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67E1BA85DDE00611CFA /* viewctl.m */; }; @@ -180,6 +181,8 @@ 060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "linux-libertine_s24.glyphmap"; path = "data/linux-libertine_s24.glyphmap"; sourceTree = ""; }; 060ECB081BB3989500CE9B80 /* uitheme.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = uitheme.cc; path = src/uitheme.cc; sourceTree = ""; }; 060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = font.p.glsl; path = sdr/font.p.glsl; sourceTree = ""; }; + 060ECB0C1BB3AC0D00CE9B80 /* timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = timer.c; path = src/timer.c; sourceTree = ""; }; + 060ECB0D1BB3AC0D00CE9B80 /* timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = timer.h; path = src/timer.h; sourceTree = ""; }; 0669D6471BA851BE00611CFA /* istereo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = istereo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0669D6741BA858BF00611CFA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Info.plist; sourceTree = ""; }; 0669D67A1BA85DDE00611CFA /* app_delegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = app_delegate.h; path = src/ios/app_delegate.h; sourceTree = ""; }; @@ -419,6 +422,8 @@ 0669D6761BA858D600611CFA /* src */ = { isa = PBXGroup; children = ( + 060ECB0C1BB3AC0D00CE9B80 /* timer.c */, + 060ECB0D1BB3AC0D00CE9B80 /* timer.h */, 060ECB011BB361C300CE9B80 /* assman.c */, 060ECB021BB361C300CE9B80 /* assman.h */, 060ECAED1BB22A4400CE9B80 /* ui.cc */, @@ -751,6 +756,7 @@ files = ( 060ECB001BB2BD5C00CE9B80 /* utf8.c in Sources */, 0669D7121BAD024700611CFA /* jcparam.c in Sources */, + 060ECB0E1BB3AC0D00CE9B80 /* timer.c in Sources */, 0669D7551BAD025B00611CFA /* pngwio.c in Sources */, 0669D70F1BAD024700611CFA /* jcmarker.c in Sources */, 0669D6CB1BAD022C00611CFA /* imago2.c in Sources */, @@ -958,6 +964,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CODE_SIGN_IDENTITY = "iPhone Developer"; + COMPRESS_PNG_FILES = NO; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", HAVE_OPENGL_H, @@ -979,6 +986,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CODE_SIGN_IDENTITY = "iPhone Developer"; + COMPRESS_PNG_FILES = NO; GCC_PREPROCESSOR_DEFINITIONS = ( HAVE_OPENGL_H, HAVE_CONFIG_H, diff -r a3c4fcc9f8f3 -r 661bf09db398 src/istereo.c --- a/src/istereo.c Thu Sep 24 06:49:25 2015 +0300 +++ b/src/istereo.c Thu Sep 24 07:09:37 2015 +0300 @@ -32,6 +32,7 @@ #include "config.h" #include "ui.h" #include "drawtext.h" +#include "timer.h" static void render(float t); static void draw_tunnel(float t); @@ -40,7 +41,6 @@ static void draw_text(float idx, vec3_t tpos, float alpha); static void worm(float t, float z, float *tx, float *ty); static unsigned int get_shader_program(const char *vfile, const char *pfile); -static float get_sec(void); unsigned int prog, prog_simple, prog_tunnel, prog_text, prog_color, prog_ui, prog_font; unsigned int tex, tex_stones, tex_normal, tex_text; @@ -133,7 +133,7 @@ void redraw(void) { float pan_x, pan_y, z; - float tsec = get_sec(); + float tsec = get_time_sec(); z = ring_height * segm; worm(tsec, z, &pan_x, &pan_y); @@ -442,28 +442,3 @@ } return prog; } - - -#ifdef IPHONE -#include - -static float get_sec(void) -{ - static float first; - static int init; - - if(!init) { - init = 1; - first = CACurrentMediaTime(); - return 0.0f; - } - return CACurrentMediaTime() - first; -} - -#else - -static float get_sec(void) -{ - return (float)glutGet(GLUT_ELAPSED_TIME) / 1000.0f; -} -#endif diff -r a3c4fcc9f8f3 -r 661bf09db398 src/timer.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/timer.c Thu Sep 24 07:09:37 2015 +0300 @@ -0,0 +1,71 @@ +#include "timer.h" + +#if defined(__APPLE__) && !defined(__unix__) +#define __unix__ +#endif + +#ifdef __unix__ +#include +#include +#include + +#ifdef CLOCK_MONOTONIC +unsigned long get_time_msec(void) +{ + struct timespec ts; + static struct timespec ts0; + + clock_gettime(CLOCK_MONOTONIC, &ts); + if(ts0.tv_sec == 0 && ts0.tv_nsec == 0) { + ts0 = ts; + return 0; + } + return (ts.tv_sec - ts0.tv_sec) * 1000 + (ts.tv_nsec - ts0.tv_nsec) / 1000000; +} +#else /* no fancy POSIX clocks, fallback to good'ol gettimeofday */ +unsigned long get_time_msec(void) +{ + struct timeval tv; + static struct timeval tv0; + + gettimeofday(&tv, 0); + if(tv0.tv_sec == 0 && tv0.tv_usec == 0) { + tv0 = tv; + return 0; + } + return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000; +} +#endif /* !posix clock */ + +void sleep_msec(unsigned long msec) +{ + usleep(msec * 1000); +} +#endif + +#ifdef WIN32 +#include +#pragma comment(lib, "winmm.lib") + +unsigned long get_time_msec(void) +{ + return timeGetTime(); +} + +void sleep_msec(unsigned long msec) +{ + Sleep(msec); +} +#endif + +double get_time_sec(void) +{ + return get_time_msec() / 1000.0f; +} + +void sleep_sec(double sec) +{ + if(sec > 0.0f) { + sleep_msec(sec * 1000.0f); + } +} diff -r a3c4fcc9f8f3 -r 661bf09db398 src/timer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/timer.h Thu Sep 24 07:09:37 2015 +0300 @@ -0,0 +1,10 @@ +#ifndef TIMER_H_ +#define TIMER_H_ + +unsigned long get_time_msec(void); +void sleep_msec(unsigned long msec); + +double get_time_sec(void); +void sleep_sec(double sec); + +#endif /* TIMER_H_ */ diff -r a3c4fcc9f8f3 -r 661bf09db398 src/uitheme.cc --- a/src/uitheme.cc Thu Sep 24 06:49:25 2015 +0300 +++ b/src/uitheme.cc Thu Sep 24 07:09:37 2015 +0300 @@ -26,6 +26,7 @@ static std::map funcmap; +__attribute__ ((used)) extern "C" WidgetDrawFunc get_widget_func(const char *name) { static bool initialized;