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