summaryrefslogtreecommitdiff
path: root/test/testgesture.c
diff options
context:
space:
mode:
authorRyan C. Gordon <icculus@icculus.org>2014-12-18 00:19:52 -0500
committerRyan C. Gordon <icculus@icculus.org>2014-12-18 00:19:52 -0500
commitcd59ce679ba2846d89f43eea77a5afc18888b816 (patch)
treeb576781d0469b2b86fc8c18662faab8dea44d2eb /test/testgesture.c
parent5e49d7fdbdcd9c18d2c8aa4d5270099a1b993778 (diff)
downloadsdl-cd59ce679ba2846d89f43eea77a5afc18888b816.tar.gz
Initial merge of Emscripten port!
With this commit, you can compile SDL2 with Emscripten ( http://emscripten.org/ ), and make your SDL-based C/C++ program into a web app. This port was due to the efforts of several people, including: Charlie Birks, Sathyanarayanan Gunasekaran, Jukka Jyl?nki, Alon Zakai, Edward Rudd, Bruce Mitchener, and Martin Gerhardy. (Thanks, everyone!)
Diffstat (limited to 'test/testgesture.c')
-rw-r--r--test/testgesture.c68
1 files changed, 41 insertions, 27 deletions
diff --git a/test/testgesture.c b/test/testgesture.c
index ecb78e303..4c988f46f 100644
--- a/test/testgesture.c
+++ b/test/testgesture.c
@@ -17,6 +17,10 @@
#include "SDL.h"
+#ifdef __EMSCRIPTEN__
+#include <emscripten/emscripten.h>
+#endif
+
#define WIDTH 640
#define HEIGHT 480
#define BPP 4
@@ -34,6 +38,9 @@ static int eventWrite;
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
+SDL_Surface *screen;
+SDL_bool quitting = SDL_FALSE;
+
typedef struct {
float x,y;
} Point;
@@ -161,33 +168,13 @@ SDL_Window* initWindow(SDL_Window *window, int width,int height)
return window;
}
-int main(int argc, char* argv[])
+void loop()
{
- SDL_Window *window = NULL;
- SDL_Surface *screen;
- SDL_Event event;
- SDL_bool quitting = SDL_FALSE;
- SDL_RWops *stream;
-
- /* Enable standard application logging */
- SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
-
- /* gesture variables */
- knob.r = .1f;
- knob.ang = 0;
+ SDL_Event event;
+ SDL_RWops *stream;
- if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
-
- if (!(window = initWindow(window, WIDTH, HEIGHT)) ||
- !(screen = SDL_GetWindowSurface(window)))
- {
- SDL_Quit();
- return 1;
- }
-
- while(!quitting) {
while(SDL_PollEvent(&event))
- {
+ {
/* Record _all_ events */
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
eventWrite++;
@@ -233,7 +220,7 @@ int main(int argc, char* argv[])
!(screen = SDL_GetWindowSurface(window)))
{
SDL_Quit();
- return 1;
+ exit(1);
}
}
break;
@@ -278,9 +265,36 @@ int main(int argc, char* argv[])
SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
break;
}
- }
- DrawScreen(screen, window);
+ }
+ DrawScreen(screen);
+}
+
+int main(int argc, char* argv[])
+{
+
+ /* Enable standard application logging */
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+
+ /* gesture variables */
+ knob.r = .1f;
+ knob.ang = 0;
+
+ if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
+
+ if (!(screen = initScreen(WIDTH,HEIGHT)))
+ {
+ SDL_Quit();
+ return 1;
}
+
+#ifdef __EMSCRIPTEN__
+ emscripten_set_main_loop(loop, 0, 1);
+#else
+ while(!quitting) {
+ loop();
+ }
+#endif
+
SDL_Quit();
return 0;
}