2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2011-02-11 22:37:15 -08:00
|
|
|
Copyright (C) 1997-2011 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Initialization code for SDL */
|
|
|
|
|
|
|
|
#include "SDL.h"
|
2011-02-16 02:37:09 -08:00
|
|
|
#include "SDL_revision.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
#include "SDL_fatal.h"
|
2010-06-26 08:56:48 -07:00
|
|
|
#include "SDL_assert_c.h"
|
|
|
|
#include "haptic/SDL_haptic_c.h"
|
|
|
|
#include "joystick/SDL_joystick_c.h"
|
2010-01-13 06:47:17 +00:00
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
/* Initialization/Cleanup routines */
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_TIMERS_DISABLED
|
2001-04-26 16:45:43 +00:00
|
|
|
extern void SDL_StartTicks(void);
|
2006-07-10 21:04:37 +00:00
|
|
|
extern int SDL_TimerInit(void);
|
2001-04-26 16:45:43 +00:00
|
|
|
extern void SDL_TimerQuit(void);
|
|
|
|
#endif
|
2011-01-24 15:46:11 -08:00
|
|
|
#if defined(__WIN32__)
|
2008-08-25 09:55:03 +00:00
|
|
|
extern int SDL_HelperWindowCreate(void);
|
|
|
|
extern int SDL_HelperWindowDestroy(void);
|
|
|
|
#endif
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2010-01-13 06:47:17 +00:00
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
/* The initialized subsystems */
|
|
|
|
static Uint32 SDL_initialized = 0;
|
|
|
|
static Uint32 ticks_started = 0;
|
|
|
|
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_InitSubSystem(Uint32 flags)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_VIDEO_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Initialize the video/event subsystem */
|
|
|
|
if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) {
|
2011-01-27 22:44:08 -08:00
|
|
|
if (SDL_VideoInit(NULL) < 0) {
|
2006-07-10 21:04:37 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
SDL_initialized |= SDL_INIT_VIDEO;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
if (flags & SDL_INIT_VIDEO) {
|
|
|
|
SDL_SetError("SDL not built with video support");
|
|
|
|
return (-1);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_AUDIO_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Initialize the audio subsystem */
|
|
|
|
if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) {
|
2006-07-15 19:30:18 +00:00
|
|
|
if (SDL_AudioInit(NULL) < 0) {
|
2006-07-10 21:04:37 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
SDL_initialized |= SDL_INIT_AUDIO;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
if (flags & SDL_INIT_AUDIO) {
|
|
|
|
SDL_SetError("SDL not built with audio support");
|
|
|
|
return (-1);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_TIMERS_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Initialize the timer subsystem */
|
|
|
|
if (!ticks_started) {
|
|
|
|
SDL_StartTicks();
|
|
|
|
ticks_started = 1;
|
|
|
|
}
|
|
|
|
if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) {
|
|
|
|
if (SDL_TimerInit() < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
SDL_initialized |= SDL_INIT_TIMER;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
if (flags & SDL_INIT_TIMER) {
|
|
|
|
SDL_SetError("SDL not built with timer support");
|
|
|
|
return (-1);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_JOYSTICK_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Initialize the joystick subsystem */
|
|
|
|
if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) {
|
|
|
|
if (SDL_JoystickInit() < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
SDL_initialized |= SDL_INIT_JOYSTICK;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
if (flags & SDL_INIT_JOYSTICK) {
|
|
|
|
SDL_SetError("SDL not built with joystick support");
|
|
|
|
return (-1);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-25 09:55:03 +00:00
|
|
|
#if !SDL_HAPTIC_DISABLED
|
|
|
|
/* Initialize the haptic subsystem */
|
|
|
|
if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) {
|
|
|
|
if (SDL_HapticInit() < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
SDL_initialized |= SDL_INIT_HAPTIC;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (flags & SDL_INIT_HAPTIC) {
|
|
|
|
SDL_SetError("SDL not built with haptic (force feedback) support");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
return (0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_Init(Uint32 flags)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-13 06:47:17 +00:00
|
|
|
if (SDL_AssertionsInit() < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Clear the error message */
|
|
|
|
SDL_ClearError();
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-01-24 15:46:11 -08:00
|
|
|
#if defined(__WIN32__)
|
2008-08-25 09:55:03 +00:00
|
|
|
if (SDL_HelperWindowCreate() < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Initialize the desired subsystems */
|
|
|
|
if (SDL_InitSubSystem(flags) < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Everything is initialized */
|
|
|
|
if (!(flags & SDL_INIT_NOPARACHUTE)) {
|
|
|
|
SDL_InstallParachute();
|
|
|
|
}
|
2010-01-13 06:47:17 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
return (0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_QuitSubSystem(Uint32 flags)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Shut down requested initialized subsystems */
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_JOYSTICK_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
|
|
|
|
SDL_JoystickQuit();
|
|
|
|
SDL_initialized &= ~SDL_INIT_JOYSTICK;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2008-08-25 09:55:03 +00:00
|
|
|
#if !SDL_HAPTIC_DISABLED
|
|
|
|
if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) {
|
|
|
|
SDL_HapticQuit();
|
|
|
|
SDL_initialized &= ~SDL_INIT_HAPTIC;
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_TIMERS_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
|
|
|
|
SDL_TimerQuit();
|
|
|
|
SDL_initialized &= ~SDL_INIT_TIMER;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_AUDIO_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
if ((flags & SDL_initialized & SDL_INIT_AUDIO)) {
|
|
|
|
SDL_AudioQuit();
|
|
|
|
SDL_initialized &= ~SDL_INIT_AUDIO;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if !SDL_VIDEO_DISABLED
|
2006-07-10 21:04:37 +00:00
|
|
|
if ((flags & SDL_initialized & SDL_INIT_VIDEO)) {
|
|
|
|
SDL_VideoQuit();
|
|
|
|
SDL_initialized &= ~SDL_INIT_VIDEO;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
Uint32
|
|
|
|
SDL_WasInit(Uint32 flags)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!flags) {
|
|
|
|
flags = SDL_INIT_EVERYTHING;
|
|
|
|
}
|
|
|
|
return (SDL_initialized & flags);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_Quit(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Quit all subsystems */
|
2011-01-24 15:46:11 -08:00
|
|
|
#if defined(__WIN32__)
|
2008-08-25 09:55:03 +00:00
|
|
|
SDL_HelperWindowDestroy();
|
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Uninstall any parachute signal handlers */
|
|
|
|
SDL_UninstallParachute();
|
2002-06-10 20:42:02 +00:00
|
|
|
|
2011-02-05 10:02:39 -08:00
|
|
|
SDL_ClearHints();
|
2010-01-13 06:47:17 +00:00
|
|
|
SDL_AssertionsQuit();
|
2011-02-07 16:45:40 -08:00
|
|
|
SDL_LogResetPriorities();
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Get the library version number */
|
|
|
|
void
|
|
|
|
SDL_GetVersion(SDL_version * ver)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VERSION(ver);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-04 05:08:12 +00:00
|
|
|
/* Get the library source revision */
|
2010-02-28 02:07:40 -05:00
|
|
|
const char *
|
2009-01-04 23:36:53 +00:00
|
|
|
SDL_GetRevision(void)
|
2009-01-04 05:08:12 +00:00
|
|
|
{
|
2009-01-04 05:27:13 +00:00
|
|
|
return SDL_REVISION;
|
2009-01-04 05:08:12 +00:00
|
|
|
}
|
|
|
|
|
2011-02-20 10:42:51 -08:00
|
|
|
/* Get the library source revision number */
|
|
|
|
int
|
|
|
|
SDL_GetRevisionNumber(void)
|
|
|
|
{
|
|
|
|
return SDL_REVISION_NUMBER;
|
|
|
|
}
|
|
|
|
|
2009-09-26 10:32:14 +00:00
|
|
|
/* Get the name of the platform */
|
|
|
|
const char *
|
|
|
|
SDL_GetPlatform()
|
|
|
|
{
|
|
|
|
#if __AIX__
|
|
|
|
return "AIX";
|
|
|
|
#elif __HAIKU__
|
|
|
|
/* Haiku must appear here before BeOS, since it also defines __BEOS__ */
|
|
|
|
return "Haiku";
|
|
|
|
#elif __BEOS__
|
|
|
|
return "BeOS";
|
|
|
|
#elif __BSDI__
|
|
|
|
return "BSDI";
|
|
|
|
#elif __DREAMCAST__
|
|
|
|
return "Dreamcast";
|
|
|
|
#elif __FREEBSD__
|
|
|
|
return "FreeBSD";
|
|
|
|
#elif __HPUX__
|
|
|
|
return "HP-UX";
|
|
|
|
#elif __IRIX__
|
|
|
|
return "Irix";
|
|
|
|
#elif __LINUX__
|
|
|
|
return "Linux";
|
|
|
|
#elif __MINT__
|
|
|
|
return "Atari MiNT";
|
|
|
|
#elif __MACOS__
|
|
|
|
return "MacOS Classic";
|
|
|
|
#elif __MACOSX__
|
|
|
|
return "Mac OS X";
|
|
|
|
#elif __NETBSD__
|
|
|
|
return "NetBSD";
|
2011-02-12 11:36:56 -08:00
|
|
|
#elif __NDS__
|
|
|
|
return "Nintendo DS";
|
2009-09-26 10:32:14 +00:00
|
|
|
#elif __OPENBSD__
|
|
|
|
return "OpenBSD";
|
|
|
|
#elif __OS2__
|
|
|
|
return "OS/2";
|
|
|
|
#elif __OSF__
|
|
|
|
return "OSF/1";
|
|
|
|
#elif __QNXNTO__
|
|
|
|
return "QNX Neutrino";
|
|
|
|
#elif __RISCOS__
|
|
|
|
return "RISC OS";
|
|
|
|
#elif __SOLARIS__
|
|
|
|
return "Solaris";
|
2011-01-24 15:46:11 -08:00
|
|
|
#elif __WIN32__
|
2009-09-26 10:32:14 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
return "Windows CE";
|
|
|
|
#else
|
|
|
|
return "Windows";
|
|
|
|
#endif
|
|
|
|
#elif __IPHONEOS__
|
|
|
|
return "iPhone OS";
|
|
|
|
#else
|
|
|
|
return "Unknown (see SDL_platform.h)";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-01-24 15:46:11 -08:00
|
|
|
#if defined(__WIN32__)
|
2006-02-06 08:28:51 +00:00
|
|
|
|
2006-03-04 08:24:35 +00:00
|
|
|
#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
|
|
|
|
/* Need to include DllMain() on Watcom C for some reason.. */
|
2011-01-24 21:20:30 -08:00
|
|
|
#include "core/windows/SDL_windows.h"
|
2006-02-06 08:28:51 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
BOOL APIENTRY
|
|
|
|
_DllMainCRTStartup(HANDLE hModule,
|
|
|
|
DWORD ul_reason_for_call, LPVOID lpReserved)
|
2006-02-06 08:28:51 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
switch (ul_reason_for_call) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2006-02-06 08:28:51 +00:00
|
|
|
}
|
2006-03-04 08:24:35 +00:00
|
|
|
#endif /* building DLL with Watcom C */
|
2006-02-06 08:28:51 +00:00
|
|
|
|
2011-01-24 15:46:11 -08:00
|
|
|
#endif /* __WIN32__ */
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|