Mercurial > sdl-ios-xcode
annotate test/testtimer.c @ 3978:b966761fef6c SDL-1.2
Significantly improved XIM support.
Fixes Bugzilla #429.
Selected notes from the patch's README:
= FIXES =
This patch fixes the above issues as follows.
== X11 events ==
Moved XFilterEvent just after XNextEvent so that all events are passed
to it. Also, XFilterEvent will receive masks indicated by IM through
XNFilterEvents IC value as well as masks surpplied by SDL.
X11_KeyRepeat is called between XNextEvent and XFilterEvent, after
testing an event is a KeyRelease. I'm not 100% comfortable to do so,
but I couldn't find a better timing to call it, and use of the
function is inevitable.
== Xutf8LookupString ==
Used a longer buffer to receive UTF-8 string. If it is insufficient,
a dynamic storage of the requested size will be allocated. The
initial size of the buffer is set to 32, because the Japanese text
converted from the most widely used benchmark key sequence for
Japanese IM, "WATASHINONAMAEHANAKANODESU." has ten Japanese characters
in it, that occupies 30 bytes when encoded in UTF-8.
== SDL_keysym.unicode ==
On Windows version of SDL implementation, SDL_keysym.unicode stores
UTF-16 encoded unicode characters, one UTF-16 encoding unit per an SDL
event. A Unicode supplementary characters are sent to an application
as two events. (One with a high surrogate and another with a low
surrogate.) The behavior seems reasonable since it is upward
compatible with existing handling of BMP characters.
I wrote a UTF-8 to UTF-16 conversion function for the purpose. It is
designed with the execution speed in mind, having a minimum set of
features that my patch requires.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 25 Jun 2007 19:58:32 +0000 |
parents | 290b5baf2fca |
children | 782fd950bd46 c121d94672cb |
rev | line source |
---|---|
0 | 1 |
2 /* Test program to check the resolution of the SDL timer on the current | |
3 platform | |
4 */ | |
5 | |
6 #include <stdlib.h> | |
7 #include <stdio.h> | |
8 | |
9 #include "SDL.h" | |
10 | |
11 #define DEFAULT_RESOLUTION 1 | |
12 | |
13 static int ticks = 0; | |
14 | |
1769 | 15 static Uint32 SDLCALL ticktock(Uint32 interval) |
0 | 16 { |
17 ++ticks; | |
18 return(interval); | |
19 } | |
20 | |
1769 | 21 static Uint32 SDLCALL callback(Uint32 interval, void *param) |
0 | 22 { |
1615
d5298e8f22b3
Ugh, more 64-bit cleanup
Sam Lantinga <slouken@libsdl.org>
parents:
1500
diff
changeset
|
23 printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param); |
0 | 24 return interval; |
25 } | |
26 | |
27 int main(int argc, char *argv[]) | |
28 { | |
29 int desired; | |
30 SDL_TimerID t1, t2, t3; | |
31 | |
32 if ( SDL_Init(SDL_INIT_TIMER) < 0 ) { | |
1484
b2b476a4a73c
Added documentation on how to build a completely useless SDL library. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1151
diff
changeset
|
33 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
34 return(1); |
0 | 35 } |
36 | |
37 /* Start the timer */ | |
38 desired = 0; | |
39 if ( argv[1] ) { | |
40 desired = atoi(argv[1]); | |
41 } | |
42 if ( desired == 0 ) { | |
43 desired = DEFAULT_RESOLUTION; | |
44 } | |
45 SDL_SetTimer(desired, ticktock); | |
46 | |
47 /* Wait 10 seconds */ | |
48 printf("Waiting 10 seconds\n"); | |
49 SDL_Delay(10*1000); | |
50 | |
51 /* Stop the timer */ | |
52 SDL_SetTimer(0, NULL); | |
53 | |
54 /* Print the results */ | |
55 if ( ticks ) { | |
56 fprintf(stderr, | |
57 "Timer resolution: desired = %d ms, actual = %f ms\n", | |
58 desired, (double)(10*1000)/ticks); | |
59 } | |
60 | |
61 /* Test multiple timers */ | |
62 printf("Testing multiple timers...\n"); | |
63 t1 = SDL_AddTimer(100, callback, (void*)1); | |
64 if(!t1) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
65 fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError()); |
0 | 66 t2 = SDL_AddTimer(50, callback, (void*)2); |
67 if(!t2) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
68 fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError()); |
0 | 69 t3 = SDL_AddTimer(233, callback, (void*)3); |
70 if(!t3) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
71 fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError()); |
0 | 72 |
73 /* Wait 10 seconds */ | |
74 printf("Waiting 10 seconds\n"); | |
75 SDL_Delay(10*1000); | |
76 | |
77 printf("Removing timer 1 and waiting 5 more seconds\n"); | |
78 SDL_RemoveTimer(t1); | |
79 | |
80 SDL_Delay(5*1000); | |
81 | |
82 SDL_RemoveTimer(t2); | |
83 SDL_RemoveTimer(t3); | |
84 | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
85 SDL_Quit(); |
0 | 86 return(0); |
87 } |