Subversion Repositories dloadsdl

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**
 * Example Application for Dynamic Loading of SDL
 * Copyright (C) 2010  Matthias -apoc- Hecker <apoc@sixserv.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _DLLOADERSDL_H
#define _DLLOADERSDL_H

#include <stdlib.h>
#include <iostream>
#include <string>

#include <SDL/SDL.h>

#ifdef _WIN32
    #include <windows.h>
#else
    #include <dlfcn.h>
#endif

#include "TSingleton.h"
#include "DLLoader.h"

#define DLSDL(fnk) (DLLoaderSDL::GetInstance()->GetSDL()->fnk)

class DLLoaderSDL : public DLLoader, public TSingleton<DLLoaderSDL>
{
protected:
    struct SProcSymbolsSDL {
        /**** Auto generated function pointer declarations (by libsdl_header_parser.rb) ****/
        // Function declarations for SDL_loadso.h
        void * (*SDL_LoadObject)(const char *);
        void * (*SDL_LoadFunction)(void *, const char *);
        void (*SDL_UnloadObject)(void *);

        // Function declarations for SDL.h
        int (*SDL_Init)(Uint32);
        int (*SDL_InitSubSystem)(Uint32);
        void (*SDL_QuitSubSystem)(Uint32);
        Uint32 (*SDL_WasInit)(Uint32);
        void (*SDL_Quit)(void);

        // Function declarations for SDL_thread.h
        Uint32 (*SDL_ThreadID)(void);
        Uint32 (*SDL_GetThreadID)(SDL_Thread *);
        void (*SDL_WaitThread)(SDL_Thread *, int *);
        void (*SDL_KillThread)(SDL_Thread *);

        // Function declarations for SDL_mouse.h
        Uint8 (*SDL_GetMouseState)(int *, int *);
        Uint8 (*SDL_GetRelativeMouseState)(int *, int *);
        void (*SDL_WarpMouse)(Uint16, Uint16);
        SDL_Cursor * (*SDL_CreateCursor)(Uint8 *, Uint8 *, int, int, int, int);
        void (*SDL_SetCursor)(SDL_Cursor *);
        SDL_Cursor * (*SDL_GetCursor)(void);
        void (*SDL_FreeCursor)(SDL_Cursor *);
        int (*SDL_ShowCursor)(int);

        // Function declarations for SDL_audio.h
        int (*SDL_AudioInit)(const char *);
        void (*SDL_AudioQuit)(void);
        char * (*SDL_AudioDriverName)(char *, int);
        int (*SDL_OpenAudio)(SDL_AudioSpec *, SDL_AudioSpec *);
        SDL_audiostatus (*SDL_GetAudioStatus)(void);
        void (*SDL_PauseAudio)(int);
        SDL_AudioSpec * (*SDL_LoadWAV_RW)(SDL_RWops *, int, SDL_AudioSpec *, Uint8 **, Uint32 *);
        void (*SDL_FreeWAV)(Uint8 *);
        int (*SDL_BuildAudioCVT)(SDL_AudioCVT *, Uint16, Uint8, int, Uint16, Uint8, int);
        int (*SDL_ConvertAudio)(SDL_AudioCVT *);
        void (*SDL_MixAudio)(Uint8 *, const Uint8 *, Uint32, int);
        void (*SDL_LockAudio)(void);
        void (*SDL_UnlockAudio)(void);
        void (*SDL_CloseAudio)(void);

        // Function declarations for SDL_cpuinfo.h
        SDL_bool (*SDL_HasRDTSC)(void);
        SDL_bool (*SDL_HasMMX)(void);
        SDL_bool (*SDL_HasMMXExt)(void);
        SDL_bool (*SDL_Has3DNow)(void);
        SDL_bool (*SDL_Has3DNowExt)(void);
        SDL_bool (*SDL_HasSSE)(void);
        SDL_bool (*SDL_HasSSE2)(void);
        SDL_bool (*SDL_HasAltiVec)(void);

        // Function declarations for SDL_events.h
        void (*SDL_PumpEvents)(void);
        int (*SDL_PeepEvents)(SDL_Event *, int, SDL_eventaction, Uint32);
        int (*SDL_PollEvent)(SDL_Event *);
        int (*SDL_WaitEvent)(SDL_Event *);
        int (*SDL_PushEvent)(SDL_Event *);
        void (*SDL_SetEventFilter)(SDL_EventFilter);
        SDL_EventFilter (*SDL_GetEventFilter)(void);
        Uint8 (*SDL_EventState)(Uint8, int);

        // Function declarations for SDL_version.h
        const SDL_version * (*SDL_Linked_Version)(void);

        // Function declarations for SDL_keyboard.h
        int (*SDL_EnableUNICODE)(int);
        int (*SDL_EnableKeyRepeat)(int, int);
        void (*SDL_GetKeyRepeat)(int *, int *);
        Uint8 * (*SDL_GetKeyState)(int *);
        SDLMod (*SDL_GetModState)(void);
        void (*SDL_SetModState)(SDLMod);
        char * (*SDL_GetKeyName)(SDLKey);

        // Function declarations for SDL_timer.h
        Uint32 (*SDL_GetTicks)(void);
        void (*SDL_Delay)(Uint32);
        int (*SDL_SetTimer)(Uint32, SDL_TimerCallback);
        SDL_TimerID (*SDL_AddTimer)(Uint32, SDL_NewTimerCallback, void *);
        SDL_bool (*SDL_RemoveTimer)(SDL_TimerID);

        // Function declarations for SDL_rwops.h
        SDL_RWops * (*SDL_RWFromFile)(const char *, const char *);
        SDL_RWops * (*SDL_RWFromFP)(FILE *, int);
        SDL_RWops * (*SDL_RWFromMem)(void *, int);
        SDL_RWops * (*SDL_RWFromConstMem)(const void *, int);
        SDL_RWops * (*SDL_AllocRW)(void);
        void (*SDL_FreeRW)(SDL_RWops *);
        Uint16 (*SDL_ReadLE16)(SDL_RWops *);
        Uint16 (*SDL_ReadBE16)(SDL_RWops *);
        Uint32 (*SDL_ReadLE32)(SDL_RWops *);
        Uint32 (*SDL_ReadBE32)(SDL_RWops *);
        Uint64 (*SDL_ReadLE64)(SDL_RWops *);
        Uint64 (*SDL_ReadBE64)(SDL_RWops *);
        int (*SDL_WriteLE16)(SDL_RWops *, Uint16);
        int (*SDL_WriteBE16)(SDL_RWops *, Uint16);
        int (*SDL_WriteLE32)(SDL_RWops *, Uint32);
        int (*SDL_WriteBE32)(SDL_RWops *, Uint32);
        int (*SDL_WriteLE64)(SDL_RWops *, Uint64);
        int (*SDL_WriteBE64)(SDL_RWops *, Uint64);

        // Function declarations for SDL_active.h
        Uint8 (*SDL_GetAppState)(void);

        // Function declarations for SDL_cdrom.h
        int (*SDL_CDNumDrives)(void);
        const char * (*SDL_CDName)(int);
        SDL_CD * (*SDL_CDOpen)(int);
        CDstatus (*SDL_CDStatus)(SDL_CD *);
        int (*SDL_CDPlayTracks)(SDL_CD *, int, int, int, int);
        int (*SDL_CDPlay)(SDL_CD *, int, int);
        int (*SDL_CDPause)(SDL_CD *);
        int (*SDL_CDResume)(SDL_CD *);
        int (*SDL_CDStop)(SDL_CD *);
        int (*SDL_CDEject)(SDL_CD *);
        void (*SDL_CDClose)(SDL_CD *);

        // Function declarations for SDL_joystick.h
        int (*SDL_NumJoysticks)(void);
        const char * (*SDL_JoystickName)(int);
        SDL_Joystick * (*SDL_JoystickOpen)(int);
        int (*SDL_JoystickOpened)(int);
        int (*SDL_JoystickIndex)(SDL_Joystick *);
        int (*SDL_JoystickNumAxes)(SDL_Joystick *);
        int (*SDL_JoystickNumBalls)(SDL_Joystick *);
        int (*SDL_JoystickNumHats)(SDL_Joystick *);
        int (*SDL_JoystickNumButtons)(SDL_Joystick *);
        void (*SDL_JoystickUpdate)(void);
        int (*SDL_JoystickEventState)(int);
        Sint16 (*SDL_JoystickGetAxis)(SDL_Joystick *, int);
        Uint8 (*SDL_JoystickGetHat)(SDL_Joystick *, int);
        int (*SDL_JoystickGetBall)(SDL_Joystick *, int, int *, int *);
        Uint8 (*SDL_JoystickGetButton)(SDL_Joystick *, int);
        void (*SDL_JoystickClose)(SDL_Joystick *);

        // Function declarations for SDL_video.h
        int (*SDL_VideoInit)(const char *, Uint32);
        void (*SDL_VideoQuit)(void);
        char * (*SDL_VideoDriverName)(char *, int);
        SDL_Surface * (*SDL_GetVideoSurface)(void);
        const SDL_VideoInfo * (*SDL_GetVideoInfo)(void);
        int (*SDL_VideoModeOK)(int, int, int, Uint32);
        SDL_Rect ** (*SDL_ListModes)(SDL_PixelFormat *, Uint32);
        SDL_Surface * (*SDL_SetVideoMode)(int, int, int, Uint32);
        void (*SDL_UpdateRects)(SDL_Surface *, int, SDL_Rect *);
        void (*SDL_UpdateRect)(SDL_Surface *, Sint32, Sint32, Uint32, Uint32);
        int (*SDL_Flip)(SDL_Surface *);
        int (*SDL_SetGamma)(float, float, float);
        int (*SDL_SetGammaRamp)(const Uint16 *, const Uint16 *, const Uint16 *);
        int (*SDL_GetGammaRamp)(Uint16 *, Uint16 *, Uint16 *);
        int (*SDL_SetColors)(SDL_Surface *, SDL_Color *, int, int);
        int (*SDL_SetPalette)(SDL_Surface *, int, SDL_Color *, int, int);
        Uint32 (*SDL_MapRGB)(const SDL_PixelFormat * const, const Uint8, const Uint8, const Uint8);
        Uint32 (*SDL_MapRGBA)(const SDL_PixelFormat * const, const Uint8, const Uint8, const Uint8, const Uint8);
        void (*SDL_GetRGB)(Uint32, const SDL_PixelFormat * const, Uint8 *, Uint8 *, Uint8 *);
        void (*SDL_GetRGBA)(Uint32, const SDL_PixelFormat * const, Uint8 *, Uint8 *, Uint8 *, Uint8 *);
        SDL_Surface * (*SDL_CreateRGBSurface)(Uint32, int, int, int, Uint32, Uint32, Uint32, Uint32);
        SDL_Surface * (*SDL_CreateRGBSurfaceFrom)(void *, int, int, int, int, Uint32, Uint32, Uint32, Uint32);
        void (*SDL_FreeSurface)(SDL_Surface *);
        int (*SDL_LockSurface)(SDL_Surface *);
        void (*SDL_UnlockSurface)(SDL_Surface *);
        SDL_Surface * (*SDL_LoadBMP_RW)(SDL_RWops *, int);
        int (*SDL_SaveBMP_RW)(SDL_Surface *, SDL_RWops *, int);
        int (*SDL_SetColorKey)(SDL_Surface *, Uint32, Uint32);
        int (*SDL_SetAlpha)(SDL_Surface *, Uint32, Uint8);
        SDL_bool (*SDL_SetClipRect)(SDL_Surface *, const SDL_Rect *);
        void (*SDL_GetClipRect)(SDL_Surface *, SDL_Rect *);
        SDL_Surface * (*SDL_ConvertSurface)(SDL_Surface *, SDL_PixelFormat *, Uint32);
        int (*SDL_UpperBlit)(SDL_Surface *, SDL_Rect *, SDL_Surface *, SDL_Rect *);
        int (*SDL_LowerBlit)(SDL_Surface *, SDL_Rect *, SDL_Surface *, SDL_Rect *);
        int (*SDL_FillRect)(SDL_Surface *, SDL_Rect *, Uint32);
        SDL_Surface * (*SDL_DisplayFormat)(SDL_Surface *);
        SDL_Surface * (*SDL_DisplayFormatAlpha)(SDL_Surface *);
        SDL_Overlay * (*SDL_CreateYUVOverlay)(int, int, Uint32, SDL_Surface *);
        int (*SDL_LockYUVOverlay)(SDL_Overlay *);
        void (*SDL_UnlockYUVOverlay)(SDL_Overlay *);
        int (*SDL_DisplayYUVOverlay)(SDL_Overlay *, SDL_Rect *);
        void (*SDL_FreeYUVOverlay)(SDL_Overlay *);
        int (*SDL_GL_LoadLibrary)(const char *);
        void * (*SDL_GL_GetProcAddress)(const char*);
        int (*SDL_GL_SetAttribute)(SDL_GLattr, int);
        int (*SDL_GL_GetAttribute)(SDL_GLattr, int*);
        void (*SDL_GL_SwapBuffers)(void);
        void (*SDL_GL_UpdateRects)(int, SDL_Rect*);
        void (*SDL_GL_Lock)(void);
        void (*SDL_GL_Unlock)(void);
        void (*SDL_WM_SetCaption)(const char *, const char *);
        void (*SDL_WM_GetCaption)(char **, char **);
        void (*SDL_WM_SetIcon)(SDL_Surface *, Uint8 *);
        int (*SDL_WM_IconifyWindow)(void);
        int (*SDL_WM_ToggleFullScreen)(SDL_Surface *);
        SDL_GrabMode (*SDL_WM_GrabInput)(SDL_GrabMode);
        int (*SDL_SoftStretch)(SDL_Surface *, SDL_Rect *, SDL_Surface *, SDL_Rect *);

        // Function declarations for SDL_mutex.h
        SDL_mutex * (*SDL_CreateMutex)(void);
        int (*SDL_mutexP)(SDL_mutex *);
        int (*SDL_mutexV)(SDL_mutex *);
        void (*SDL_DestroyMutex)(SDL_mutex *);
        SDL_sem * (*SDL_CreateSemaphore)(Uint32);
        void (*SDL_DestroySemaphore)(SDL_sem *);
        int (*SDL_SemWait)(SDL_sem *);
        int (*SDL_SemTryWait)(SDL_sem *);
        int (*SDL_SemWaitTimeout)(SDL_sem *, Uint32);
        int (*SDL_SemPost)(SDL_sem *);
        Uint32 (*SDL_SemValue)(SDL_sem *);
        SDL_cond * (*SDL_CreateCond)(void);
        void (*SDL_DestroyCond)(SDL_cond *);
        int (*SDL_CondSignal)(SDL_cond *);
        int (*SDL_CondBroadcast)(SDL_cond *);
        int (*SDL_CondWait)(SDL_cond *, SDL_mutex *);
        int (*SDL_CondWaitTimeout)(SDL_cond *, SDL_mutex *, Uint32);

        // Function declarations for SDL_error.h
        void (*SDL_SetError)(const char *);
        char * (*SDL_GetError)(void);
        void (*SDL_ClearError)(void);
        void (*SDL_Error)(SDL_errorcode);
        /**** End auto generated function pointer declarations ****/
    };

    void LoadProcSymbols();
    void UnloadProcSymbols();

public:
    DLLoaderSDL();
    // DLLoaderSDL(const DLLoaderSDL& orig);
    virtual ~DLLoaderSDL();

    SProcSymbolsSDL *GetSDL();

private:
    SProcSymbolsSDL *proc_symbols_sdl;

};

#endif  /* _DLLOADERSDL_H */