src/SDL.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 13 Oct 2013 19:48:45 -0700
changeset 7810 ab1b92bf0327
parent 7592 063a932a264f
child 7828 1451063c8ecd
permissions -rw-r--r--
Added an assert to catch init/quit call mismatch that might bite people.
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"
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4419
diff changeset
    28
#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
    29
#include "events/SDL_events_c.h"
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4419
diff changeset
    30
#include "haptic/SDL_haptic_c.h"
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4419
diff changeset
    31
#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
    32
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
/* 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
    34
#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
    35
extern int SDL_TimerInit(void);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
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
    37
extern void SDL_InitTicks(void);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    38
#endif
7110
2a98852fd58d Fixed bug 1582 - Allow disabling SDL_VIDEO_DRIVER_WINDOWS
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    39
#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
    40
extern int SDL_HelperWindowCreate(void);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
    41
extern int SDL_HelperWindowDestroy(void);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
    42
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    43
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
    44
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    45
/* 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
    46
#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
    47
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
    48
#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
    49
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
    50
#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
    51
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
    52
static Uint8 SDL_SubsystemRefCount[ 32 ];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    53
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    54
/* 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
    55
static void
4c899e841091 Fix build issue on Win/Haiku.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6866
diff changeset
    56
SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    57
{
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    58
    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
    59
    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
    60
    ++SDL_SubsystemRefCount[subsystem_index];
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    61
}
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
/* 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
    64
static void
4c899e841091 Fix build issue on Win/Haiku.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6866
diff changeset
    65
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
    66
{
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    67
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
7810
ab1b92bf0327 Added an assert to catch init/quit call mismatch that might bite people.
Sam Lantinga <slouken@libsdl.org>
parents: 7592
diff changeset
    68
    /* If this assert triggers there is a mismatch between init and quit calls */
ab1b92bf0327 Added an assert to catch init/quit call mismatch that might bite people.
Sam Lantinga <slouken@libsdl.org>
parents: 7592
diff changeset
    69
    SDL_assert(SDL_SubsystemRefCount[subsystem_index] > 0);
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    70
    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
    71
        --SDL_SubsystemRefCount[subsystem_index];
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
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    75
/* 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
    76
static SDL_bool
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
    77
SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    78
{
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
    79
    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
    80
    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
    81
    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
    82
}
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    83
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    84
/* 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
    85
static SDL_bool
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    86
SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    87
    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
    88
    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
    89
      return SDL_FALSE;
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
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    92
    /* 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
    93
     * isn't zero.
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    94
     */
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
    95
    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
    96
}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
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
    98
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
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
   100
{
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
    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
   102
}
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
   103
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
   104
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
   105
SDL_InitSubSystem(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   106
{
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
   107
    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
   108
        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
   109
        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
   110
    }
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
   111
7590
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   112
    /* Clear the error message */
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   113
    SDL_ClearError();
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   114
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   115
#if SDL_VIDEO_DRIVER_WINDOWS
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   116
    if (SDL_HelperWindowCreate() < 0) {
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   117
        return -1;
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   118
    }
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   119
#endif
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   120
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
   121
#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
   122
    SDL_InitTicks();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   123
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   124
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   125
    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
   126
        /* 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
   127
        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
   128
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   129
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   130
    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
   131
        /* 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
   132
        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
   133
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   134
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   135
    /* 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
   136
    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
   137
#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
   138
        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
   139
            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
   140
                return (-1);
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   141
            }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   142
            SDL_QuitInit();
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   143
        }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   144
        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
   145
#else
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   146
        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
   147
#endif
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   148
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   149
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   150
    /* 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
   151
    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
   152
#if !SDL_TIMERS_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   153
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   154
            if (SDL_TimerInit() < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   155
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   156
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   157
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   158
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   159
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   160
        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
   161
#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
   162
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   164
    /* 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
   165
    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
   166
#if !SDL_VIDEO_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   167
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   168
            if (SDL_VideoInit(NULL) < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   169
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   170
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   171
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   172
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   173
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   174
        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
   175
#endif
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   176
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   177
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   178
    /* 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
   179
    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
   180
#if !SDL_AUDIO_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   181
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   182
            if (SDL_AudioInit(NULL) < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   183
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   184
            }
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
   185
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   186
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   187
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   188
        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
   189
#endif
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   190
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
   191
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   192
    /* 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
   193
    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
   194
#if !SDL_JOYSTICK_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   195
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   196
           if (SDL_JoystickInit() < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   197
               return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   198
           }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   199
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   200
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   202
        return SDL_SetError("SDL not built with joystick support");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   203
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   204
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   205
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   206
    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
   207
#if !SDL_JOYSTICK_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   208
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   209
            if (SDL_GameControllerInit() < 0) {
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   210
                return (-1);
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   211
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   212
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   213
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   214
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   215
        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
   216
#endif
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   217
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   218
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   219
    /* 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
   220
    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
   221
#if !SDL_HAPTIC_DISABLED
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   222
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
6924
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   223
            if (SDL_HapticInit() < 0) {
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   224
                return (-1);
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   225
            }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   226
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   227
        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
   228
#else
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7011
diff changeset
   229
        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
   230
#endif
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   231
    }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
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
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   234
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   235
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
   236
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
   237
SDL_Init(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
{
7590
5706d7fc10d0 SDL_Init() is now just a wrapper around SDL_InitSubSystem().
Ryan C. Gordon <icculus@icculus.org>
parents: 7589
diff changeset
   239
    return SDL_InitSubSystem(flags);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   240
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
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
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
   243
SDL_QuitSubSystem(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   244
{
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
   245
    /* 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
   246
#if !SDL_JOYSTICK_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   247
    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
   248
        /* game controller implies joystick */
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   249
        flags |= SDL_INIT_JOYSTICK;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   250
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   251
        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
   252
            SDL_GameControllerQuit();
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   253
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   254
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   255
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6441
diff changeset
   256
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   257
    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
   258
        /* 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
   259
        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
   260
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   261
        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
   262
            SDL_JoystickQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   263
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   264
        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
   265
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   266
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   267
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   268
#if !SDL_HAPTIC_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   269
    if ((flags & SDL_INIT_HAPTIC)) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   270
        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
   271
            SDL_HapticQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   272
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   273
        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
   274
    }
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   275
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   276
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   277
#if !SDL_AUDIO_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   278
    if ((flags & SDL_INIT_AUDIO)) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   279
        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
   280
            SDL_AudioQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   281
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   282
        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
   283
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   284
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   285
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   286
#if !SDL_VIDEO_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   287
    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
   288
        /* 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
   289
        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
   290
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   291
        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
   292
            SDL_VideoQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   293
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   294
        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
   295
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   296
#endif
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   297
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
   298
#if !SDL_TIMERS_DISABLED
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   299
    if ((flags & SDL_INIT_TIMER)) {
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   300
        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
   301
            SDL_TimerQuit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7139
diff changeset
   302
        }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   303
        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
   304
    }
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
   305
#endif
7360
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   306
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   307
#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
   308
    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
   309
        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
   310
            SDL_QuitQuit();
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   311
            SDL_StopEventLoop();
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   312
        }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   313
        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
   314
    }
b86947ea2749 Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents: 7346
diff changeset
   315
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   316
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   317
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
   318
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
   319
SDL_WasInit(Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   320
{
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   321
    int i;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   322
    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
   323
    Uint32 initialized = 0;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   324
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
   325
    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
   326
        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
   327
    }
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   328
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   329
    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
   330
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   331
    /* 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
   332
    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
   333
        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
   334
            initialized |= (1 << i);
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   335
        }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   336
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   337
        flags >>= 1;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   338
    }
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   339
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   340
    return initialized;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   341
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   342
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
   343
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
   344
SDL_Quit(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   345
{
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   346
    SDL_bInMainQuit = SDL_TRUE;
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   347
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
   348
    /* Quit all subsystems */
7110
2a98852fd58d Fixed bug 1582 - Allow disabling SDL_VIDEO_DRIVER_WINDOWS
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   349
#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
   350
    SDL_HelperWindowDestroy();
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1909
diff changeset
   351
#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
   352
    SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   353
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
   354
    SDL_ClearHints();
3647
c5925cd41955 First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents: 3319
diff changeset
   355
    SDL_AssertionsQuit();
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents: 5189
diff changeset
   356
    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
   357
6866
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   358
    /* 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
   359
     * 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
   360
     */
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   361
    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
   362
e74a4b282450 Don't clobber refcounting in SDL_Init.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6690
diff changeset
   363
    SDL_bInMainQuit = SDL_FALSE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   364
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   365
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
   366
/* 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
   367
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
   368
SDL_GetVersion(SDL_version * ver)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   369
{
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
   370
    SDL_VERSION(ver);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   371
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   372
2982
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   373
/* 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
   374
const char *
2996
972a69e47cd9 Added missing void
Sam Lantinga <slouken@libsdl.org>
parents: 2983
diff changeset
   375
SDL_GetRevision(void)
2982
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   376
{
2983
388c5a2daeac Fine tuned revision code, updated testver
Sam Lantinga <slouken@libsdl.org>
parents: 2982
diff changeset
   377
    return SDL_REVISION;
2982
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   378
}
b64c1d23039b Make the current revision number available
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   379
5359
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   380
/* 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
   381
int
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   382
SDL_GetRevisionNumber(void)
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   383
{
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   384
    return SDL_REVISION_NUMBER;
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   385
}
d5fe4ed3a28d Added a revision number for easy compile-time tests.
Sam Lantinga <slouken@libsdl.org>
parents: 5310
diff changeset
   386
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   387
/* Get the name of the platform */
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   388
const char *
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   389
SDL_GetPlatform()
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   390
{
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   391
#if __AIX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   392
    return "AIX";
6441
ada3545fed23 Fixed bug 1600 - SDL_GetPlatform() returns "unknown os" on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   393
#elif __ANDROID__
ada3545fed23 Fixed bug 1600 - SDL_GetPlatform() returns "unknown os" on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   394
    return "Android";
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   395
#elif __BEOS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   396
    return "BeOS";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   397
#elif __BSDI__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   398
    return "BSDI";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   399
#elif __DREAMCAST__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   400
    return "Dreamcast";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   401
#elif __FREEBSD__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   402
    return "FreeBSD";
7346
ff228f955a48 Fixed some __BEOS__ vs __HAIKU__ preprocessor tests (thanks, Axel!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7281
diff changeset
   403
#elif __HAIKU__
ff228f955a48 Fixed some __BEOS__ vs __HAIKU__ preprocessor tests (thanks, Axel!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7281
diff changeset
   404
    return "Haiku";
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   405
#elif __HPUX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   406
    return "HP-UX";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   407
#elif __IRIX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   408
    return "Irix";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   409
#elif __LINUX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   410
    return "Linux";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   411
#elif __MINT__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   412
    return "Atari MiNT";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   413
#elif __MACOS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   414
    return "MacOS Classic";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   415
#elif __MACOSX__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   416
    return "Mac OS X";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   417
#elif __NETBSD__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   418
    return "NetBSD";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   419
#elif __OPENBSD__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   420
    return "OpenBSD";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   421
#elif __OS2__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   422
    return "OS/2";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   423
#elif __OSF__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   424
    return "OSF/1";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   425
#elif __QNXNTO__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   426
    return "QNX Neutrino";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   427
#elif __RISCOS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   428
    return "RISC OS";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   429
#elif __SOLARIS__
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   430
    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
   431
#elif __WIN32__
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   432
    return "Windows";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   433
#elif __IPHONEOS__
7592
063a932a264f Updated the name of the iOS platform
Sam Lantinga <slouken@libsdl.org>
parents: 7591
diff changeset
   434
    return "iOS";
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6927
diff changeset
   435
#elif __PSP__
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6927
diff changeset
   436
    return "PlayStation Portable";
3319
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   437
#else
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   438
    return "Unknown (see SDL_platform.h)";
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   439
#endif
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   440
}
63d4517fc4ac Fixed bug #777
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
   441
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   442
#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
   443
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
   444
#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
   445
/* 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
   446
#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
   447
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
   448
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
   449
_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
   450
                   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
   451
{
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
   452
    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
   453
    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
   454
    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
   455
    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
   456
    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
   457
        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
   458
    }
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
   459
    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
   460
}
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
   461
#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
   462
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   463
#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
   464
6927
982b03203b73 Cleanup of SDL_PrivateShouldInitSubsystem.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6924
diff changeset
   465
/* vi: set sts=4 ts=4 sw=4 expandtab: */