src/SDL.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 30 Jul 2013 21:39:38 -0700
changeset 7550 ff3e041c27f3
parent 7360 b86947ea2749
child 7588 f1ca6adffc4b
permissions -rw-r--r--
Added code signature step to Framework build process
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5359
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6867
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5359
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: 5359
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: 5359
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5359
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: 5359
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: 5359
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5359
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: 5359
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: 5359
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: 5359
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5359
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: 5359
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: 5359
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    21
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
/* Initialization code for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    25
#include "SDL.h"
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    26
#include "SDL_bits.h"
5310
a9945ce48999 Made it possible to build SDL from a fresh checkout without any additional steps.
Sam Lantinga <slouken@libsdl.org>
parents: 5270
diff changeset
    27
#include "SDL_revision.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    28
#include "SDL_fatal.h"
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4419
diff changeset
    29
#include "SDL_assert_c.h"
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
    30
#include "events/SDL_events_c.h"
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4419
diff changeset
    31
#include "haptic/SDL_haptic_c.h"
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4419
diff changeset
    32
#include "joystick/SDL_joystick_c.h"
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
    33
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
/* Initialization/Cleanup routines */
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    35
#if !SDL_TIMERS_DISABLED
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    36
extern int SDL_TimerInit(void);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
extern void SDL_TimerQuit(void);
7139
dd722e7460c5 move Ticks initialization tracking to separate function and ensure it's called with SDL_VideoInit is called to init SDL instead of SDL_Init
Edward Rudd <urkle@outoforder.cc>
parents: 7110
diff changeset
    38
extern void SDL_InitTicks(void);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
#endif
7110
2a98852fd58d Fixed bug 1582 - Allow disabling SDL_VIDEO_DRIVER_WINDOWS
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    40
#if SDL_VIDEO_DRIVER_WINDOWS
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
    41
extern int SDL_HelperWindowCreate(void);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
    42
extern int SDL_HelperWindowDestroy(void);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
    43
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    44
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
    45
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    46
/* The initialized subsystems */
7281
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    47
#ifdef SDL_MAIN_NEEDED
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    48
static SDL_bool SDL_MainIsReady = SDL_FALSE;
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    49
#else
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    50
static SDL_bool SDL_MainIsReady = SDL_TRUE;
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    51
#endif
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
    52
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    53
static Uint8 SDL_SubsystemRefCount[ 32 ];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    54
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    55
/* Private helper to increment a subsystem's ref counter. */
6867
4c899e841091 Fix build issue on Win/Haiku.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6866
diff changeset
    56
static void
4c899e841091 Fix build issue on Win/Haiku.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6866
diff changeset
    57
SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    58
{
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    59
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    60
    SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    61
    ++SDL_SubsystemRefCount[subsystem_index];
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    62
}
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    63
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    64
/* Private helper to decrement a subsystem's ref counter. */
6867
4c899e841091 Fix build issue on Win/Haiku.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6866
diff changeset
    65
static void
4c899e841091 Fix build issue on Win/Haiku.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6866
diff changeset
    66
SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
    67
{
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    68
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    69
    if (SDL_SubsystemRefCount[subsystem_index] > 0) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    70
        --SDL_SubsystemRefCount[subsystem_index];
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    71
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    72
}
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    73
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    74
/* Private helper to check if a system needs init. */
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    75
static SDL_bool
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
    76
SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    77
{
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
    78
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    79
    SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    80
    return (SDL_SubsystemRefCount[subsystem_index] == 0);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    81
}
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    82
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    83
/* Private helper to check if a system needs to be quit. */
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    84
static SDL_bool
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    85
SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    86
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    87
    if (SDL_SubsystemRefCount[subsystem_index] == 0) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    88
      return SDL_FALSE;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    89
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    90
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    91
    /* If we're in SDL_Quit, we shut down every subsystem, even if refcount
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    92
     * isn't zero.
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    93
     */
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    94
    return SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
    95
}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    96
7281
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    97
void
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    98
SDL_SetMainReady(void)
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
    99
{
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   100
    SDL_MainIsReady = SDL_TRUE;
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   101
}
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   102
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   103
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   104
SDL_InitSubSystem(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   105
{
7281
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   106
    if (!SDL_MainIsReady) {
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   107
        SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   108
        return -1;
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   109
    }
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   110
6128
2804d71badce Initialize timers first so the tick counter is valid by the time the audio and video systems initialize.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   111
#if !SDL_TIMERS_DISABLED
7139
dd722e7460c5 move Ticks initialization tracking to separate function and ensure it's called with SDL_VideoInit is called to init SDL instead of SDL_Init
Edward Rudd <urkle@outoforder.cc>
parents: 7110
diff changeset
   112
    SDL_InitTicks();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   113
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   114
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   115
    if ((flags & SDL_INIT_GAMECONTROLLER)) {
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   116
        /* game controller implies joystick */
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   117
        flags |= SDL_INIT_JOYSTICK;
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   118
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   119
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   120
    if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   121
        /* video or joystick implies events */
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   122
        flags |= SDL_INIT_EVENTS;
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   123
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   124
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   125
    /* Initialize the event subsystem */
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   126
    if ((flags & SDL_INIT_EVENTS)) {
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   127
#if !SDL_EVENTS_DISABLED
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   128
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   129
            if (SDL_StartEventLoop() < 0) {
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   130
                return (-1);
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   131
            }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   132
            SDL_QuitInit();
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   133
        }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   134
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   135
#else
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   136
        return SDL_SetError("SDL not built with events support");
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   137
#endif
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   138
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   139
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   140
    /* Initialize the timer subsystem */
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   141
    if ((flags & SDL_INIT_TIMER)){
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   142
#if !SDL_TIMERS_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   143
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   144
            if (SDL_TimerInit() < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   145
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   146
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   147
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   148
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   149
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   150
        return SDL_SetError("SDL not built with timer support");
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   151
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   152
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   153
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   154
    /* Initialize the video subsystem */
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   155
    if ((flags & SDL_INIT_VIDEO)){
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   156
#if !SDL_VIDEO_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   157
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   158
            if (SDL_VideoInit(NULL) < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   159
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   160
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   161
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   162
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   163
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   164
        return SDL_SetError("SDL not built with video support");
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   165
#endif
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   166
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   167
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   168
    /* Initialize the audio subsystem */
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   169
    if ((flags & SDL_INIT_AUDIO)){
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   170
#if !SDL_AUDIO_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   171
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   172
            if (SDL_AudioInit(NULL) < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   173
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   174
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   175
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   176
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   177
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   178
        return SDL_SetError("SDL not built with audio support");
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   179
#endif
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   180
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
   181
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   182
    /* Initialize the joystick subsystem */
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   183
    if ((flags & SDL_INIT_JOYSTICK)){
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   184
#if !SDL_JOYSTICK_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   185
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   186
           if (SDL_JoystickInit() < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   187
               return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   188
           }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   189
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   190
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   192
        return SDL_SetError("SDL not built with joystick support");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   193
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   194
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   195
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   196
    if ((flags & SDL_INIT_GAMECONTROLLER)){
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   197
#if !SDL_JOYSTICK_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   198
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   199
            if (SDL_GameControllerInit() < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   200
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   201
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   202
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   203
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   204
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   205
        return SDL_SetError("SDL not built with joystick support");
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   206
#endif
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   207
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   208
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   209
    /* Initialize the haptic subsystem */
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   210
    if ((flags & SDL_INIT_HAPTIC)){
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   211
#if !SDL_HAPTIC_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   212
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   213
            if (SDL_HapticInit() < 0) {
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   214
                return (-1);
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   215
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   216
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   217
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   218
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   219
        return SDL_SetError("SDL not built with haptic (force feedback) support");
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   220
#endif
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   221
    }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   222
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   223
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   224
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   225
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   226
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   227
SDL_Init(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   228
{
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
   229
    if (SDL_AssertionsInit() < 0) {
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
   230
        return -1;
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
   231
    }
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
   232
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   233
    /* Clear the error message */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   234
    SDL_ClearError();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   235
7110
2a98852fd58d Fixed bug 1582 - Allow disabling SDL_VIDEO_DRIVER_WINDOWS
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   236
#if SDL_VIDEO_DRIVER_WINDOWS
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   237
    if (SDL_HelperWindowCreate() < 0) {
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   238
        return -1;
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   239
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   240
#endif
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   241
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   242
    /* Initialize the desired subsystems */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   243
    if (SDL_InitSubSystem(flags) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   244
        return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   245
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   246
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   247
    /* Everything is initialized */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   248
    if (!(flags & SDL_INIT_NOPARACHUTE)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   249
        SDL_InstallParachute();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   250
    }
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
   251
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   252
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   253
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   254
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   255
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   256
SDL_QuitSubSystem(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   257
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   258
    /* Shut down requested initialized subsystems */
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   259
#if !SDL_JOYSTICK_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   260
    if ((flags & SDL_INIT_GAMECONTROLLER)) {
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   261
        /* game controller implies joystick */
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   262
        flags |= SDL_INIT_JOYSTICK;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   263
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   264
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   265
            SDL_GameControllerQuit();
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   266
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   267
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   268
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
   269
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   270
    if ((flags & SDL_INIT_JOYSTICK)) {
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   271
        /* joystick implies events */
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   272
        flags |= SDL_INIT_EVENTS;
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   273
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   274
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   275
            SDL_JoystickQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   276
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   277
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   278
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   279
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   280
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   281
#if !SDL_HAPTIC_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   282
    if ((flags & SDL_INIT_HAPTIC)) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   283
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   284
            SDL_HapticQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   285
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   286
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   287
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   288
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   289
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   290
#if !SDL_AUDIO_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   291
    if ((flags & SDL_INIT_AUDIO)) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   292
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   293
            SDL_AudioQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   294
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   295
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   296
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   297
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   298
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   299
#if !SDL_VIDEO_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   300
    if ((flags & SDL_INIT_VIDEO)) {
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   301
        /* video implies events */
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   302
        flags |= SDL_INIT_EVENTS;
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   303
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   304
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   305
            SDL_VideoQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   306
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   307
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   308
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   309
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   310
6128
2804d71badce Initialize timers first so the tick counter is valid by the time the audio and video systems initialize.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   311
#if !SDL_TIMERS_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   312
    if ((flags & SDL_INIT_TIMER)) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   313
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   314
            SDL_TimerQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   315
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   316
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
6128
2804d71badce Initialize timers first so the tick counter is valid by the time the audio and video systems initialize.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   317
    }
2804d71badce Initialize timers first so the tick counter is valid by the time the audio and video systems initialize.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   318
#endif
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   319
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   320
#if !SDL_EVENTS_DISABLED
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   321
    if ((flags & SDL_INIT_EVENTS)) {
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   322
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   323
            SDL_QuitQuit();
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   324
            SDL_StopEventLoop();
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   325
        }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   326
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   327
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   328
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   329
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   330
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   331
Uint32
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   332
SDL_WasInit(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   333
{
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   334
    int i;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   335
    int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   336
    Uint32 initialized = 0;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   337
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   338
    if (!flags) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   339
        flags = SDL_INIT_EVERYTHING;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   340
    }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   341
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   342
    num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   343
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   344
    /* Iterate over each bit in flags, and check the matching subsystem. */
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   345
    for (i = 0; i < num_subsystems; ++i) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   346
        if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   347
            initialized |= (1 << i);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   348
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   349
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   350
        flags >>= 1;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   351
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   352
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   353
    return initialized;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   354
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   355
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   356
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   357
SDL_Quit(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   358
{
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   359
    SDL_bInMainQuit = SDL_TRUE;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   360
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   361
    /* Quit all subsystems */
7110
2a98852fd58d Fixed bug 1582 - Allow disabling SDL_VIDEO_DRIVER_WINDOWS
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   362
#if SDL_VIDEO_DRIVER_WINDOWS
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   363
    SDL_HelperWindowDestroy();
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   364
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   365
    SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   366
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   367
    /* Uninstall any parachute signal handlers */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   368
    SDL_UninstallParachute();
397
283d348cb624 Pth threading bug fix
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   369
5189
6f6a9340fb93 Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   370
    SDL_ClearHints();
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
   371
    SDL_AssertionsQuit();
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents: 5189
diff changeset
   372
    SDL_LogResetPriorities();
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
   373
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   374
    /* Now that every subsystem has been quit, we reset the subsystem refcount
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   375
     * and the list of initialized subsystems.
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   376
     */
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   377
    SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   378
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   379
    SDL_bInMainQuit = SDL_FALSE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   380
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   381
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   382
/* Get the library version number */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   383
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   384
SDL_GetVersion(SDL_version * ver)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   385
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   386
    SDL_VERSION(ver);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   387
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   388
2982
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   389
/* Get the library source revision */
4419
5e7e1f1a4056 Changed revision details to be a string (an hg changeset) instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
   390
const char *
2996
972a69e47cd9 Added missing void
Sam Lantinga <slouken@libsdl.org>
parents: 2983
diff changeset
   391
SDL_GetRevision(void)
2982
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   392
{
2983
388c5a2daeac Fine tuned revision code, updated testver
Sam Lantinga <slouken@libsdl.org>
parents: 2982
diff changeset
   393
    return SDL_REVISION;
2982
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   394
}
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   395
5359
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   396
/* Get the library source revision number */
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   397
int
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   398
SDL_GetRevisionNumber(void)
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   399
{
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   400
    return SDL_REVISION_NUMBER;
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   401
}
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   402
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   403
/* Get the name of the platform */
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   404
const char *
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   405
SDL_GetPlatform()
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   406
{
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   407
#if __AIX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   408
    return "AIX";
6441
ada3545fed23 Fixed bug 1600 - SDL_GetPlatform() returns "unknown os" on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   409
#elif __ANDROID__
ada3545fed23 Fixed bug 1600 - SDL_GetPlatform() returns "unknown os" on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   410
    return "Android";
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   411
#elif __BEOS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   412
    return "BeOS";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   413
#elif __BSDI__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   414
    return "BSDI";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   415
#elif __DREAMCAST__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   416
    return "Dreamcast";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   417
#elif __FREEBSD__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   418
    return "FreeBSD";
7346
ff228f955a48 Fixed some __BEOS__ vs __HAIKU__ preprocessor tests (thanks, Axel!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7281
diff changeset
   419
#elif __HAIKU__
ff228f955a48 Fixed some __BEOS__ vs __HAIKU__ preprocessor tests (thanks, Axel!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7281
diff changeset
   420
    return "Haiku";
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   421
#elif __HPUX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   422
    return "HP-UX";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   423
#elif __IRIX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   424
    return "Irix";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   425
#elif __LINUX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   426
    return "Linux";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   427
#elif __MINT__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   428
    return "Atari MiNT";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   429
#elif __MACOS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   430
    return "MacOS Classic";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   431
#elif __MACOSX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   432
    return "Mac OS X";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   433
#elif __NETBSD__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   434
    return "NetBSD";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   435
#elif __OPENBSD__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   436
    return "OpenBSD";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   437
#elif __OS2__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   438
    return "OS/2";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   439
#elif __OSF__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   440
    return "OSF/1";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   441
#elif __QNXNTO__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   442
    return "QNX Neutrino";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   443
#elif __RISCOS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   444
    return "RISC OS";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   445
#elif __SOLARIS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   446
    return "Solaris";
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   447
#elif __WIN32__
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   448
    return "Windows";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   449
#elif __IPHONEOS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   450
    return "iPhone OS";
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6927
diff changeset
   451
#elif __PSP__
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6927
diff changeset
   452
    return "PlayStation Portable";
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   453
#else
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   454
    return "Unknown (see SDL_platform.h)";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   455
#endif
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   456
}
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   457
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   458
#if defined(__WIN32__)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   459
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
   460
#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
   461
/* Need to include DllMain() on Watcom C for some reason.. */
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
   462
#include "core/windows/SDL_windows.h"
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   463
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   464
BOOL APIENTRY
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   465
_DllMainCRTStartup(HANDLE hModule,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   466
                   DWORD ul_reason_for_call, LPVOID lpReserved)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   467
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   468
    switch (ul_reason_for_call) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   469
    case DLL_PROCESS_ATTACH:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   470
    case DLL_THREAD_ATTACH:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   471
    case DLL_THREAD_DETACH:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   472
    case DLL_PROCESS_DETACH:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   473
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   474
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   475
    return TRUE;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   476
}
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
   477
#endif /* building DLL with Watcom C */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   478
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   479
#endif /* __WIN32__ */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   480
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   481
/* vi: set sts=4 ts=4 sw=4 expandtab: */