istereo2

changeset 8:661bf09db398

- replaced Quartz timer with cross-platform timer code - protected goatkit builtin theme function from being optimized out
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 07:09:37 +0300
parents a3c4fcc9f8f3
children 64e15874f3bd
files istereo.xcodeproj/project.pbxproj src/istereo.c src/timer.c src/timer.h src/uitheme.cc
diffstat 5 files changed, 92 insertions(+), 27 deletions(-) [+]
line diff
     1.1 --- a/istereo.xcodeproj/project.pbxproj	Thu Sep 24 06:49:25 2015 +0300
     1.2 +++ b/istereo.xcodeproj/project.pbxproj	Thu Sep 24 07:09:37 2015 +0300
     1.3 @@ -30,6 +30,7 @@
     1.4  		060ECB071BB36FD800CE9B80 /* linux-libertine_s24.glyphmap in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */; settings = {ASSET_TAGS = (); }; };
     1.5  		060ECB091BB3989500CE9B80 /* uitheme.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB081BB3989500CE9B80 /* uitheme.cc */; settings = {ASSET_TAGS = (); }; };
     1.6  		060ECB0B1BB3A8DB00CE9B80 /* font.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */; settings = {ASSET_TAGS = (); }; };
     1.7 +		060ECB0E1BB3AC0D00CE9B80 /* timer.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB0C1BB3AC0D00CE9B80 /* timer.c */; settings = {ASSET_TAGS = (); }; };
     1.8  		0669D67F1BA85DDE00611CFA /* app_delegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67B1BA85DDE00611CFA /* app_delegate.m */; };
     1.9  		0669D6801BA85DDE00611CFA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67C1BA85DDE00611CFA /* main.m */; };
    1.10  		0669D6811BA85DDE00611CFA /* viewctl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67E1BA85DDE00611CFA /* viewctl.m */; };
    1.11 @@ -180,6 +181,8 @@
    1.12  		060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "linux-libertine_s24.glyphmap"; path = "data/linux-libertine_s24.glyphmap"; sourceTree = "<group>"; };
    1.13  		060ECB081BB3989500CE9B80 /* uitheme.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = uitheme.cc; path = src/uitheme.cc; sourceTree = "<group>"; };
    1.14  		060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = font.p.glsl; path = sdr/font.p.glsl; sourceTree = "<group>"; };
    1.15 +		060ECB0C1BB3AC0D00CE9B80 /* timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = timer.c; path = src/timer.c; sourceTree = "<group>"; };
    1.16 +		060ECB0D1BB3AC0D00CE9B80 /* timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = timer.h; path = src/timer.h; sourceTree = "<group>"; };
    1.17  		0669D6471BA851BE00611CFA /* istereo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = istereo.app; sourceTree = BUILT_PRODUCTS_DIR; };
    1.18  		0669D6741BA858BF00611CFA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Info.plist; sourceTree = "<group>"; };
    1.19  		0669D67A1BA85DDE00611CFA /* app_delegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = app_delegate.h; path = src/ios/app_delegate.h; sourceTree = "<group>"; };
    1.20 @@ -419,6 +422,8 @@
    1.21  		0669D6761BA858D600611CFA /* src */ = {
    1.22  			isa = PBXGroup;
    1.23  			children = (
    1.24 +				060ECB0C1BB3AC0D00CE9B80 /* timer.c */,
    1.25 +				060ECB0D1BB3AC0D00CE9B80 /* timer.h */,
    1.26  				060ECB011BB361C300CE9B80 /* assman.c */,
    1.27  				060ECB021BB361C300CE9B80 /* assman.h */,
    1.28  				060ECAED1BB22A4400CE9B80 /* ui.cc */,
    1.29 @@ -751,6 +756,7 @@
    1.30  			files = (
    1.31  				060ECB001BB2BD5C00CE9B80 /* utf8.c in Sources */,
    1.32  				0669D7121BAD024700611CFA /* jcparam.c in Sources */,
    1.33 +				060ECB0E1BB3AC0D00CE9B80 /* timer.c in Sources */,
    1.34  				0669D7551BAD025B00611CFA /* pngwio.c in Sources */,
    1.35  				0669D70F1BAD024700611CFA /* jcmarker.c in Sources */,
    1.36  				0669D6CB1BAD022C00611CFA /* imago2.c in Sources */,
    1.37 @@ -958,6 +964,7 @@
    1.38  				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
    1.39  				ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
    1.40  				CODE_SIGN_IDENTITY = "iPhone Developer";
    1.41 +				COMPRESS_PNG_FILES = NO;
    1.42  				GCC_PREPROCESSOR_DEFINITIONS = (
    1.43  					"DEBUG=1",
    1.44  					HAVE_OPENGL_H,
    1.45 @@ -979,6 +986,7 @@
    1.46  				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
    1.47  				ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
    1.48  				CODE_SIGN_IDENTITY = "iPhone Developer";
    1.49 +				COMPRESS_PNG_FILES = NO;
    1.50  				GCC_PREPROCESSOR_DEFINITIONS = (
    1.51  					HAVE_OPENGL_H,
    1.52  					HAVE_CONFIG_H,
     2.1 --- a/src/istereo.c	Thu Sep 24 06:49:25 2015 +0300
     2.2 +++ b/src/istereo.c	Thu Sep 24 07:09:37 2015 +0300
     2.3 @@ -32,6 +32,7 @@
     2.4  #include "config.h"
     2.5  #include "ui.h"
     2.6  #include "drawtext.h"
     2.7 +#include "timer.h"
     2.8  
     2.9  static void render(float t);
    2.10  static void draw_tunnel(float t);
    2.11 @@ -40,7 +41,6 @@
    2.12  static void draw_text(float idx, vec3_t tpos, float alpha);
    2.13  static void worm(float t, float z, float *tx, float *ty);
    2.14  static unsigned int get_shader_program(const char *vfile, const char *pfile);
    2.15 -static float get_sec(void);
    2.16  
    2.17  unsigned int prog, prog_simple, prog_tunnel, prog_text, prog_color, prog_ui, prog_font;
    2.18  unsigned int tex, tex_stones, tex_normal, tex_text;
    2.19 @@ -133,7 +133,7 @@
    2.20  void redraw(void)
    2.21  {
    2.22  	float pan_x, pan_y, z;
    2.23 -	float tsec = get_sec();
    2.24 +	float tsec = get_time_sec();
    2.25  
    2.26  	z = ring_height * segm;
    2.27  	worm(tsec, z, &pan_x, &pan_y);
    2.28 @@ -442,28 +442,3 @@
    2.29  	}
    2.30  	return prog;
    2.31  }
    2.32 -
    2.33 -
    2.34 -#ifdef IPHONE
    2.35 -#include <QuartzCore/QuartzCore.h>
    2.36 -
    2.37 -static float get_sec(void)
    2.38 -{
    2.39 -	static float first;
    2.40 -	static int init;
    2.41 -
    2.42 -	if(!init) {
    2.43 -		init = 1;
    2.44 -		first = CACurrentMediaTime();
    2.45 -		return 0.0f;
    2.46 -	}
    2.47 -	return CACurrentMediaTime() - first;
    2.48 -}
    2.49 -
    2.50 -#else
    2.51 -
    2.52 -static float get_sec(void)
    2.53 -{
    2.54 -	return (float)glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
    2.55 -}
    2.56 -#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/timer.c	Thu Sep 24 07:09:37 2015 +0300
     3.3 @@ -0,0 +1,71 @@
     3.4 +#include "timer.h"
     3.5 +
     3.6 +#if defined(__APPLE__) && !defined(__unix__)
     3.7 +#define __unix__
     3.8 +#endif
     3.9 +
    3.10 +#ifdef __unix__
    3.11 +#include <time.h>
    3.12 +#include <unistd.h>
    3.13 +#include <sys/time.h>
    3.14 +
    3.15 +#ifdef CLOCK_MONOTONIC
    3.16 +unsigned long get_time_msec(void)
    3.17 +{
    3.18 +	struct timespec ts;
    3.19 +	static struct timespec ts0;
    3.20 +
    3.21 +	clock_gettime(CLOCK_MONOTONIC, &ts);
    3.22 +	if(ts0.tv_sec == 0 && ts0.tv_nsec == 0) {
    3.23 +		ts0 = ts;
    3.24 +		return 0;
    3.25 +	}
    3.26 +	return (ts.tv_sec - ts0.tv_sec) * 1000 + (ts.tv_nsec - ts0.tv_nsec) / 1000000;
    3.27 +}
    3.28 +#else	/* no fancy POSIX clocks, fallback to good'ol gettimeofday */
    3.29 +unsigned long get_time_msec(void)
    3.30 +{
    3.31 +	struct timeval tv;
    3.32 +	static struct timeval tv0;
    3.33 +
    3.34 +	gettimeofday(&tv, 0);
    3.35 +	if(tv0.tv_sec == 0 && tv0.tv_usec == 0) {
    3.36 +		tv0 = tv;
    3.37 +		return 0;
    3.38 +	}
    3.39 +	return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
    3.40 +}
    3.41 +#endif	/* !posix clock */
    3.42 +
    3.43 +void sleep_msec(unsigned long msec)
    3.44 +{
    3.45 +	usleep(msec * 1000);
    3.46 +}
    3.47 +#endif
    3.48 +
    3.49 +#ifdef WIN32
    3.50 +#include <windows.h>
    3.51 +#pragma comment(lib, "winmm.lib")
    3.52 +
    3.53 +unsigned long get_time_msec(void)
    3.54 +{
    3.55 +	return timeGetTime();
    3.56 +}
    3.57 +
    3.58 +void sleep_msec(unsigned long msec)
    3.59 +{
    3.60 +	Sleep(msec);
    3.61 +}
    3.62 +#endif
    3.63 +
    3.64 +double get_time_sec(void)
    3.65 +{
    3.66 +	return get_time_msec() / 1000.0f;
    3.67 +}
    3.68 +
    3.69 +void sleep_sec(double sec)
    3.70 +{
    3.71 +	if(sec > 0.0f) {
    3.72 +		sleep_msec(sec * 1000.0f);
    3.73 +	}
    3.74 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/timer.h	Thu Sep 24 07:09:37 2015 +0300
     4.3 @@ -0,0 +1,10 @@
     4.4 +#ifndef TIMER_H_
     4.5 +#define TIMER_H_
     4.6 +
     4.7 +unsigned long get_time_msec(void);
     4.8 +void sleep_msec(unsigned long msec);
     4.9 +
    4.10 +double get_time_sec(void);
    4.11 +void sleep_sec(double sec);
    4.12 +
    4.13 +#endif	/* TIMER_H_ */
     5.1 --- a/src/uitheme.cc	Thu Sep 24 06:49:25 2015 +0300
     5.2 +++ b/src/uitheme.cc	Thu Sep 24 07:09:37 2015 +0300
     5.3 @@ -26,6 +26,7 @@
     5.4  
     5.5  static std::map<std::string, WidgetDrawFunc> funcmap;
     5.6  
     5.7 +__attribute__ ((used))
     5.8  extern "C" WidgetDrawFunc get_widget_func(const char *name)
     5.9  {
    5.10  	static bool initialized;