author | Ryan C. Gordon <icculus@icculus.org> |
Mon, 01 Aug 2016 00:20:47 -0400 | |
changeset 10214 | 4f29bb9e19c3 |
parent 9998 | f67cf37e9cd4 |
permissions | -rw-r--r-- |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
/* |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
2 |
Simple DirectMedia Layer |
9998
f67cf37e9cd4
Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents:
9619
diff
changeset
|
3 |
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
7 |
arising from the use of this software. |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
11 |
freely, subject to the following restrictions: |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
16 |
appreciated but is not required. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
18 |
misrepresented as being the original software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5273
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
*/ |
8093
b43765095a6f
Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents:
7719
diff
changeset
|
21 |
#include "./SDL_internal.h" |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
#include "SDL_hints.h" |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
24 |
#include "SDL_error.h" |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
/* Assuming there aren't many hints set and they aren't being queried in |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
28 |
critical performance paths, we'll just use linked lists here. |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
*/ |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
30 |
typedef struct SDL_HintWatch { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
31 |
SDL_HintCallback callback; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
32 |
void *userdata; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
33 |
struct SDL_HintWatch *next; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
34 |
} SDL_HintWatch; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
35 |
|
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
typedef struct SDL_Hint { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
char *name; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
char *value; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
SDL_HintPriority priority; |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
40 |
SDL_HintWatch *callbacks; |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
struct SDL_Hint *next; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
} SDL_Hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
static SDL_Hint *SDL_hints; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
|
5555
3ecad5e5dbe4
* SDL_IOS_IDLE_TIMER_DISABLED hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents:
5535
diff
changeset
|
46 |
SDL_bool |
5200
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
47 |
SDL_SetHintWithPriority(const char *name, const char *value, |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
48 |
SDL_HintPriority priority) |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
{ |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 |
const char *env; |
6389
43a190ad60a7
Removed some unused variables that gcc 4.6.1 complains about.
Ryan C. Gordon <icculus@icculus.org>
parents:
6138
diff
changeset
|
51 |
SDL_Hint *hint; |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
52 |
SDL_HintWatch *entry; |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
if (!name || !value) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
env = SDL_getenv(name); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
if (env && priority < SDL_HINT_OVERRIDE) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
|
6389
43a190ad60a7
Removed some unused variables that gcc 4.6.1 complains about.
Ryan C. Gordon <icculus@icculus.org>
parents:
6138
diff
changeset
|
63 |
for (hint = SDL_hints; hint; hint = hint->next) { |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
if (SDL_strcmp(name, hint->name) == 0) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
if (priority < hint->priority) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
} |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
68 |
if (!hint->value || !value || SDL_strcmp(hint->value, value) != 0) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
69 |
for (entry = hint->callbacks; entry; ) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
70 |
/* Save the next entry in case this one is deleted */ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
71 |
SDL_HintWatch *next = entry->next; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
72 |
entry->callback(entry->userdata, name, hint->value, value); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
73 |
entry = next; |
5555
3ecad5e5dbe4
* SDL_IOS_IDLE_TIMER_DISABLED hint
Tim Angus <tim@blackcompanystudios.co.uk>
parents:
5535
diff
changeset
|
74 |
} |
7719
31b5f9ff36ca
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents:
7716
diff
changeset
|
75 |
SDL_free(hint->value); |
7716
be4cda94bce2
Christoph Mallon: Simplify assignment.
Sam Lantinga <slouken@libsdl.org>
parents:
7432
diff
changeset
|
76 |
hint->value = value ? SDL_strdup(value) : NULL; |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
hint->priority = priority; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
return SDL_TRUE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
/* Couldn't find the hint, add a new one */ |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
if (!hint) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
hint->name = SDL_strdup(name); |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
89 |
hint->value = value ? SDL_strdup(value) : NULL; |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
hint->priority = priority; |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
91 |
hint->callbacks = NULL; |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
hint->next = SDL_hints; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
SDL_hints = hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
return SDL_TRUE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
|
5200
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
97 |
SDL_bool |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
98 |
SDL_SetHint(const char *name, const char *value) |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
99 |
{ |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
100 |
return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL); |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
101 |
} |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5189
diff
changeset
|
102 |
|
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 |
const char * |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 |
SDL_GetHint(const char *name) |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
{ |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 |
const char *env; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
SDL_Hint *hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 |
env = SDL_getenv(name); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
for (hint = SDL_hints; hint; hint = hint->next) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
if (SDL_strcmp(name, hint->name) == 0) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
if (!env || hint->priority == SDL_HINT_OVERRIDE) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
return hint->value; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
break; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
return env; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
|
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
121 |
void |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
122 |
SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata) |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
123 |
{ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
124 |
SDL_Hint *hint; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
125 |
SDL_HintWatch *entry; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
126 |
const char *value; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
127 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
128 |
if (!name || !*name) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
129 |
SDL_InvalidParamError("name"); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
130 |
return; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
131 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
132 |
if (!callback) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
133 |
SDL_InvalidParamError("callback"); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
134 |
return; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
135 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
136 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
137 |
SDL_DelHintCallback(name, callback, userdata); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
138 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
139 |
entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry)); |
9202
01bb8e3ba14f
Fixed SDL_AddHintCallback() crashing if no more memory available.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9201
diff
changeset
|
140 |
if (!entry) { |
01bb8e3ba14f
Fixed SDL_AddHintCallback() crashing if no more memory available.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9201
diff
changeset
|
141 |
SDL_OutOfMemory(); |
01bb8e3ba14f
Fixed SDL_AddHintCallback() crashing if no more memory available.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9201
diff
changeset
|
142 |
return; |
01bb8e3ba14f
Fixed SDL_AddHintCallback() crashing if no more memory available.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9201
diff
changeset
|
143 |
} |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
144 |
entry->callback = callback; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
145 |
entry->userdata = userdata; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
146 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
147 |
for (hint = SDL_hints; hint; hint = hint->next) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
148 |
if (SDL_strcmp(name, hint->name) == 0) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
149 |
break; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
150 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
151 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
152 |
if (!hint) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
153 |
/* Need to add a hint entry for this watcher */ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
154 |
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
155 |
if (!hint) { |
9202
01bb8e3ba14f
Fixed SDL_AddHintCallback() crashing if no more memory available.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9201
diff
changeset
|
156 |
SDL_OutOfMemory(); |
9204
b331795924d3
Removed unnecessary NULL check.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9202
diff
changeset
|
157 |
SDL_free(entry); |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
158 |
return; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
159 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
160 |
hint->name = SDL_strdup(name); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
161 |
hint->value = NULL; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
162 |
hint->priority = SDL_HINT_DEFAULT; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
163 |
hint->callbacks = NULL; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
164 |
hint->next = SDL_hints; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
165 |
SDL_hints = hint; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
166 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
167 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
168 |
/* Add it to the callbacks for this hint */ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
169 |
entry->next = hint->callbacks; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
170 |
hint->callbacks = entry; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
171 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
172 |
/* Now call it with the current value */ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
173 |
value = SDL_GetHint(name); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
174 |
callback(userdata, name, value, value); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
175 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
176 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
177 |
void |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
178 |
SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata) |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
179 |
{ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
180 |
SDL_Hint *hint; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
181 |
SDL_HintWatch *entry, *prev; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
182 |
|
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
183 |
for (hint = SDL_hints; hint; hint = hint->next) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
184 |
if (SDL_strcmp(name, hint->name) == 0) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
185 |
prev = NULL; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
186 |
for (entry = hint->callbacks; entry; entry = entry->next) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
187 |
if (callback == entry->callback && userdata == entry->userdata) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
188 |
if (prev) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
189 |
prev->next = entry->next; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
190 |
} else { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
191 |
hint->callbacks = entry->next; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
192 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
193 |
SDL_free(entry); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
194 |
break; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
195 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
196 |
prev = entry; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
197 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
198 |
return; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
199 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
200 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
201 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
202 |
|
5273
151f40ed9e55
This should match the header change.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
203 |
void SDL_ClearHints(void) |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 |
{ |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 |
SDL_Hint *hint; |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
206 |
SDL_HintWatch *entry; |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 |
while (SDL_hints) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 |
hint = SDL_hints; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 |
SDL_hints = hint->next; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 |
SDL_free(hint->name); |
7719
31b5f9ff36ca
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents:
7716
diff
changeset
|
213 |
SDL_free(hint->value); |
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
214 |
for (entry = hint->callbacks; entry; ) { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
215 |
SDL_HintWatch *freeable = entry; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
216 |
entry = entry->next; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
217 |
SDL_free(freeable); |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7191
diff
changeset
|
218 |
} |
5189
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 |
SDL_free(hint); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 |
} |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 |
|
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 |
/* vi: set ts=4 sw=4 expandtab: */ |