src/SDL_hints.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 27 Jul 2013 14:06:06 +0200
changeset 7532 2c54272792e2
parent 7432 58908b180ebd
child 7716 be4cda94bce2
permissions -rw-r--r--
Removed C++ macro setup in internal header for Android port which is only C now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6389
diff changeset
     3
  Copyright (C) 1997-2013 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
*/
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
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
                }
7432
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    75
                if (hint->value) {
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    76
                    SDL_free(hint->value);
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    77
                }
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    78
                if (value) {
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    79
                    hint->value = SDL_strdup(value);
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    80
                } else {
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    81
                    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
    82
                }
5189
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
            }
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->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
    85
            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
    86
        }
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
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    /* 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
    90
    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
    91
    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
    92
        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
    93
    }
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
    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
    95
    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
    96
    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
    97
    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
    98
    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
    99
    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
   100
    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
   101
}
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
5200
01bced9a4cc1 Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents: 5189
diff changeset
   103
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
   104
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
   105
{
01bced9a4cc1 Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents: 5189
diff changeset
   106
    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
   107
}
01bced9a4cc1 Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents: 5189
diff changeset
   108
5189
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
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
   110
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
   111
{
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    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
   113
    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
   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
    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
   116
    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
   117
        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
   118
            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
   119
                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
   120
            }
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
            break;
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
        }
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
    }
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
    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
   125
}
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
7432
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   127
void
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   128
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
   129
{
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   130
    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
   131
    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
   132
    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
   133
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   134
    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
   135
        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
   136
        return;
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   137
    }
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   138
    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
   139
        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
   140
        return;
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   141
    }
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   142
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   143
    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
   144
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 = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   146
    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
   147
    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
   148
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   149
    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
   150
        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
   151
            break;
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   152
        }
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   153
    }
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   154
    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
   155
        /* 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
   156
        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
   157
        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
   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);
7432
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   213
        if (hint->value) {
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   214
            SDL_free(hint->value);
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   215
        }
58908b180ebd Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   216
        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
   217
            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
   218
            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
   219
            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
   220
        }
5189
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
        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
   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
}
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
/* vi: set ts=4 sw=4 expandtab: */