示例#1
0
//////////////////////////////////////////
////
//// GW_PlatformSDL_Image
////
//////////////////////////////////////////
GW_PlatformSDL_Image::GW_PlatformSDL_Image(SDL_Renderer *renderer, const string &filename, GW_Platform_RGB *tcolor)
{
    SDL_Surface* _surface;
#ifndef GW_USE_ZDATA
    _surface = SDL_LoadBMP( filename.c_str() );
#else
    SDL_RWops *l = SDL_RWFromZZIP( filename.c_str(), "rb" );
    if (l)
        _surface = SDL_LoadBMP_RW( l, 1 );
    else
        _surface = NULL;
    //SDL_FreeRW(l);
#endif

    if (!_surface)
        throw GW_Exception(string("Unable to load image "+filename+": "+string(SDL_GetError())));
    if (tcolor)
        SDL_SetColorKey(_surface, SDL_TRUE, SDL_MapRGB(_surface->format, tcolor->r, tcolor->g, tcolor->b));

    texture_ = SDL_CreateTextureFromSurface(renderer, _surface);
    if (!texture_)
        throw GW_Exception(string("Unable to load image "+filename+": "+string(SDL_GetError())));
    SDL_QueryTexture(texture_, NULL, NULL, &w_, &h_);

    // Cleanup ...
    SDL_FreeSurface(_surface);
#ifdef GW_DEBUG
    GWDBG_FVOUTPUT("\tGW_PlatformSDL_Image(file %s, texture %p, width %i, height %i)\n", filename.c_str(), texture_, w_, h_);
#endif
}
示例#2
0
void GW_PlatformWIZ::custom_initialize()
{
    SDL_Joystick *joystick = SDL_JoystickOpen(0); // initialize the joystick and buttons.  Number '0' is the only one.
	if (!joystick) // should not happen
        throw GW_Exception(string("Unable to open joystick: "+string(SDL_GetError())));


    m_MEM = open("/dev/mem", O_RDWR );
    if (m_MEM<0)
        throw GW_Exception(string("/dev/mem open failed."));

    MEMREGS32 = (volatile uint32_t*)mmap(0,MEM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, m_MEM, MEM_BASE);
    if (MEMREGS32==MAP_FAILED)
        throw GW_Exception(string("mmap failed."));

    MEMREGS16 = (volatile uint16_t*)MEMREGS32;

    /* start timer */
    TIMER_REG(0x44) = 0x922;
    TIMER_REG(0x40) = 0x0c;
    TIMER_REG(0x08) = 0x6b;
}
示例#3
0
//////////////////////////////////////////
////
//// GW_PlatformSDL_Sound
////
//////////////////////////////////////////
GW_PlatformSDL_Sound::GW_PlatformSDL_Sound(const string &filename)
{
#ifndef GW_NO_SDL_MIXER

#ifndef GW_USE_ZDATA
    sample_ = Mix_LoadWAV( filename.c_str() );
#else
    SDL_RWops *l = SDL_RWFromZZIP( filename.c_str(), "rb" );
    if (l)
        sample_ = Mix_LoadWAV_RW( l, 1 );
    else
        sample_=NULL;
    //SDL_FreeRW(l);
#endif

    if (!sample_)
        throw GW_Exception(string("Unable to load sound sample "+filename+": "+string(Mix_GetError())));
#endif
}
示例#4
0
void GW_PlatformSDL::initialize()
{
    if (!initialized_)
    {
        GWDBG_OUTPUT("SDL: Initialize");

        // initialize SDL video
        if ( SDL_Init( sdlinit(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) ) < 0 )
            throw GW_Exception(string("Unable to init SDL: "+string(SDL_GetError())));

#ifndef GW_NO_SDL_MIXER
        if ( Mix_OpenAudio(22050, AUDIO_S16SYS, 1, audiobufsize_get()) < 0)
            throw GW_Exception(string("Unable to init SDL_mixer: "+string(Mix_GetError())));
#endif

#ifndef GW_NO_SDL_TTF
        if ( TTF_Init() < 0 )
            throw GW_Exception(string("Unable to init SDL_ttf: "+string(TTF_GetError())));
#endif

#ifndef GW_NO_SDL_MIXER
        Mix_AllocateChannels(6);
        sound_volume(75);
#endif

        custom_initialize();

        // make sure SDL cleans up before exit
        atexit(SDL_Quit);

        // set application icon
        plat_init();

        // create a new window
        window_ = SDL_CreateWindow("Game & Watch simulator - by Hitnrun / ZsoltK & Madrigal",
                                   SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                   width_, height_,
                                   fullscreen_ ?  SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_SHOWN);
        if ( !window_ )
            throw GW_Exception(string("Unable to allocate game window: " + string(SDL_GetError())));

        renderer_ = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED);
        if ( !renderer_ )
            throw GW_Exception(string("Unable to allocate renderer: " + string(SDL_GetError())));


        // Let SDL & GPU do the scaling
        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
        SDL_RenderSetLogicalSize(renderer_, width_, height_);

        SDL_ShowCursor(SDL_DISABLE);

#ifndef GW_NO_SDL_TTF
        // load font
        //font_=TTF_OpenFont( bf::path( bf::path(platformdata_get() ) / "andalemo.ttf" ).string().c_str(), fontsize_get() );
        string pfont(platformdata_get() + "/" + "andalemo.ttf" );
        font_=TTF_OpenFont( pfont.c_str(), fontsize_get() );
        if (!font_)
            throw GW_Exception(string("Unable to load font: "+string(TTF_GetError())));
#endif

        initialized_=true;
    }
}