~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/sdl_pumpevents.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <SDL/SDL.h>
 
4
 
 
5
#include <emscripten.h>
 
6
// bug - SDL_GetKeyboardState doesn't return scancodes, it returns keycodes, so acts exactly like
 
7
// SDL_GetKeyState instead
 
8
#define SDL_GetKeyState SDL_GetKeyboardState
 
9
 
 
10
int result = 0;
 
11
 
 
12
int loop1()
 
13
{
 
14
   unsigned i;
 
15
   int r = 0;
 
16
 
 
17
   // method 1: SDL_PollEvent loop
 
18
   SDL_Event e;
 
19
   while (SDL_PollEvent(&e));
 
20
 
 
21
   const Uint8 *keys = SDL_GetKeyState(NULL);
 
22
   if (keys[SDLK_LEFT])
 
23
      r = 1;
 
24
 
 
25
   return r;
 
26
}
 
27
 
 
28
int loop2()
 
29
{
 
30
   unsigned i;
 
31
   int r = 0;
 
32
   
 
33
   // method 2: SDL_PumpEvents
 
34
   SDL_PumpEvents();
 
35
 
 
36
   const Uint8 *keys = SDL_GetKeyState(NULL);
 
37
   if (keys[SDLK_RIGHT])
 
38
      r = 2;
 
39
 
 
40
   return r;
 
41
}
 
42
 
 
43
int alphakey()
 
44
{
 
45
   unsigned i;
 
46
   int r = 0;
 
47
 
 
48
   SDL_PumpEvents();
 
49
 
 
50
   const Uint8 *keys = SDL_GetKeyState(NULL);
 
51
   if (keys[SDLK_a])
 
52
      r = 4;
 
53
 
 
54
   return r;
 
55
}
 
56
 
 
57
int main(int argc, char *argv[])
 
58
{
 
59
   SDL_Init(SDL_INIT_EVERYTHING);
 
60
   SDL_SetVideoMode(600, 400, 32, SDL_SWSURFACE);
 
61
 
 
62
   emscripten_run_script("keydown(37);"); // left
 
63
   result += loop1();
 
64
   emscripten_run_script("keydown(39);"); // right
 
65
   result += loop2();
 
66
   emscripten_run_script("keydown(65);"); // A
 
67
   result += alphakey();
 
68
   REPORT_RESULT();
 
69
   return 0;
 
70
}