Example #1
0
'''Time management routines.
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id: $'

from ctypes import *

import dll

SDL_GetTicks = dll.function('SDL_GetTicks',
    '''Get the number of milliseconds since the SDL library initialization.

    Note that this value wraps if the program runs for more than ~49 days.

    :rtype: int
    ''',
    args=[],
    arg_types=[],
    return_type=c_uint)

SDL_Delay = dll.function('SDL_Delay',
    '''Wait a specified number of milliseconds before returning.

    :Parameters:
        `ms` : int
            delay in milliseconds

    ''',
    args=['ms'],
    arg_types=[c_uint],
Example #2
0
    :rtype: int
    :return: undocumented (FIXME)
    :see: `SDL_Init`, `SDL_QuitSubSystem`
    '''
    if sys.platform == 'darwin' and flags & SDL_INIT_VIDEO:
        import cocos.audio.SDL.darwin
        cocos.audio.SDL.darwin.init()
    return _SDL_InitSubSystem(flags)


SDL_QuitSubSystem = SDL_dll.function('SDL_QuitSubSystem',
                                     '''Clean up specific SDL subsystems.

    :Parameters:
     - `flags`: int

    :see: `SDL_InitSubSystem`
    ''',
                                     args=['flags'],
                                     arg_types=[ctypes.c_uint],
                                     return_type=None)

SDL_WasInit = SDL_dll.function(
    'SDL_WasInit',
    '''Return a mask of the specified subsystems which have been
    initialized.

    If `flags` is 0, return a mask of all initialized subsystems.

    :Parameters:
     - `flags`: int
Example #3
0
        callback(userdata, ar)

    desired._callback = _SDL_AudioSpec_fn(cb)
    _SDL_OpenAudio(desired, obtained)
    if obtained:
        obtained.userdata = desired.userdata
        obtained.callback = desired.callback
        ctype[0] = _ctype_audio_format(obtained.format)


SDL_GetAudioStatus = dll.function(
    "SDL_GetAudioStatus",
    """Get the current audio state.

    :rtype: int
    :return: one of SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED
    """,
    args=[],
    arg_types=[],
    return_type=c_int,
)

SDL_PauseAudio = dll.function(
    "SDL_PauseAudio",
    """Pause and unpause the audio callback processing.

    It should be called with a parameter of 0 after opening the audio
    device to start playing sound.  This is so you can safely initalize
    data for your callback function after opening the audio device.
    Silence will be written to the audio device during the pause.
Example #4
0
    def __str__(self):
        return self.message


class SDL_NotImplementedError(NotImplementedError):
    '''Exception raised when the available SDL library predates the
    requested function.'''
    pass


SDL_SetError = dll.function('SDL_SetError',
                            '''Set the static error string.

    :Parameters:
        `fmt`
            format string; subsequent integer and string arguments are
            interpreted as in printf().
    ''',
                            args=['fmt'],
                            arg_types=[c_char_p],
                            return_type=None)

SDL_GetError = dll.function('SDL_GetError',
                            '''Return the last error string set.

    :rtype: string
    ''',
                            args=[],
                            arg_types=[],
                            return_type=c_char_p)
Example #5
0
    :Parameters:
     - `major`: int
     - `minor`: int
     - `patch`: int

    :rtype: int
    """
    return x * 1000 + y * 100 + z


SDL_Linked_Version = dll.function(
    "SDL_Linked_Version",
    """Get the version of the dynamically linked SDL library.

    :rtype: `SDL_version`
    """,
    args=[],
    arg_types=[],
    return_type=POINTER(SDL_version),
    dereference_return=True,
    require_return=True,
)


def SDL_VERSION_ATLEAST(major, minor, patch):
    """Determine if the SDL library is at least the given version.
    
    :Parameters:
     - `major`: int
     - `minor`: int
     - `patch`: int
Example #6
0
    _fields_ = [('seek', _seek_fn),
                ('read', _read_fn),
                ('write', _write_fn),
                ('close', _close_fn),
                ('type', c_uint),
                ('_hidden_mem', _hidden_mem_t)]
SetPointerType(_rwops_p, SDL_RWops)

SDL_RWFromFile = dll.function('SDL_RWFromFile',
    '''Create an SDL_RWops structure from a file on disk.

    :Parameters:
        `file` : string
            Filename
        `mode` : string
            Mode to open the file with; as with the built-in function ``open``.

    :rtype: `SDL_RWops`
    ''',
    args=['file', 'mode'],
    arg_types=[c_char_p, c_char_p],
    return_type=POINTER(SDL_RWops),
    dereference_return=True,
    require_return=True)

SDL_RWFromMem = dll.function('SDL_RWFromMem',
    '''Create an SDL_RWops structure from a contiguous region of memory.

    :Parameters:
     - `mem`: ``c_void_p``
     - `size`: int
Example #7
0
        self.message = message

    def __str__(self):
        return self.message

class SDL_NotImplementedError(NotImplementedError):
    '''Exception raised when the available SDL library predates the
    requested function.'''
    pass

SDL_SetError = dll.function('SDL_SetError',
    '''Set the static error string.

    :Parameters:
        `fmt`
            format string; subsequent integer and string arguments are
            interpreted as in printf().
    ''',
    args=['fmt'],
    arg_types=[c_char_p],
    return_type=None)

SDL_GetError = dll.function('SDL_GetError',
    '''Return the last error string set.

    :rtype: string
    ''',
    args=[],
    arg_types=[],
    return_type=c_char_p)
Example #8
0
    _fields_ = [('seek', _seek_fn), ('read', _read_fn), ('write', _write_fn),
                ('close', _close_fn), ('type', c_uint),
                ('_hidden_mem', _hidden_mem_t)]


SetPointerType(_rwops_p, SDL_RWops)

SDL_RWFromFile = dll.function(
    'SDL_RWFromFile',
    '''Create an SDL_RWops structure from a file on disk.

    :Parameters:
        `file` : string
            Filename
        `mode` : string
            Mode to open the file with; as with the built-in function ``open``.

    :rtype: `SDL_RWops`
    ''',
    args=['file', 'mode'],
    arg_types=[c_char_p, c_char_p],
    return_type=POINTER(SDL_RWops),
    dereference_return=True,
    require_return=True)

SDL_RWFromMem = dll.function(
    'SDL_RWFromMem',
    '''Create an SDL_RWops structure from a contiguous region of memory.

    :Parameters:
     - `mem`: ``c_void_p``
Example #9
0
        ar = array.SDL_array(stream, len / sizeof(ctype[0]), ctype[0])
        callback(userdata, ar)

    desired._callback = _SDL_AudioSpec_fn(cb)
    _SDL_OpenAudio(desired, obtained)
    if obtained:
        obtained.userdata = desired.userdata
        obtained.callback = desired.callback
        ctype[0] = _ctype_audio_format(obtained.format)


SDL_GetAudioStatus = dll.function('SDL_GetAudioStatus',
                                  '''Get the current audio state.

    :rtype: int
    :return: one of SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED
    ''',
                                  args=[],
                                  arg_types=[],
                                  return_type=c_int)

SDL_PauseAudio = dll.function(
    'SDL_PauseAudio',
    '''Pause and unpause the audio callback processing.

    It should be called with a parameter of 0 after opening the audio
    device to start playing sound.  This is so you can safely initalize
    data for your callback function after opening the audio device.
    Silence will be written to the audio device during the pause.

    :Parameters:
Example #10
0
    :rtype: int
    :return: undocumented (FIXME)
    :see: `SDL_Init`, `SDL_QuitSubSystem`
    '''
    if sys.platform == 'darwin' and flags & SDL_INIT_VIDEO:
        import cocos.audio.SDL.darwin
        cocos.audio.SDL.darwin.init()
    return _SDL_InitSubSystem(flags)

SDL_QuitSubSystem = SDL_dll.function('SDL_QuitSubSystem',
    '''Clean up specific SDL subsystems.

    :Parameters:
     - `flags`: int

    :see: `SDL_InitSubSystem`
    ''',
    args=['flags'],
    arg_types=[ctypes.c_uint],
    return_type=None)

SDL_WasInit = SDL_dll.function('SDL_WasInit',
    '''Return a mask of the specified subsystems which have been
    initialized.

    If `flags` is 0, return a mask of all initialized subsystems.

    :Parameters:
     - `flags`: int
Example #11
0
        1203

    :Parameters:
     - `major`: int
     - `minor`: int
     - `patch`: int

    :rtype: int
    '''
    return x * 1000 + y * 100 + z

SDL_Linked_Version = dll.function('SDL_Linked_Version',
    '''Get the version of the dynamically linked SDL library.

    :rtype: `SDL_version`
    ''',
    args=[],
    arg_types=[],
    return_type=POINTER(SDL_version),
    dereference_return=True,
    require_return=True)

def SDL_VERSION_ATLEAST(major, minor, patch):
    '''Determine if the SDL library is at least the given version.
    
    :Parameters:
     - `major`: int
     - `minor`: int
     - `patch`: int

    :rtype: bool
    '''
Example #12
0
'''Time management routines.
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id: $'

from ctypes import *

import dll

SDL_GetTicks = dll.function(
    'SDL_GetTicks',
    '''Get the number of milliseconds since the SDL library initialization.

    Note that this value wraps if the program runs for more than ~49 days.

    :rtype: int
    ''',
    args=[],
    arg_types=[],
    return_type=c_uint)

SDL_Delay = dll.function(
    'SDL_Delay',
    '''Wait a specified number of milliseconds before returning.

    :Parameters:
        `ms` : int
            delay in milliseconds

    ''',