Esempio n. 1
0
int TitleScene::exec()
{
    LoopTiming times;
    times.start_common = SDL_GetTicks();
    bool frameSkip = g_AppSettings.frameSkip;
    menustates.clear();
    menuChain.clear();
    //Set black color clearer
    GlRenderer::setClearColor(0.f, 0.f, 0.f, 1.0f);

    for(int i = menuFirst; i < menuLast; i++)
        menustates[static_cast<CurrentMenu>(i)] = menustate(0, 0);

    setMenu(menu_main);
    //Hide mouse cursor
    PGE_Window::setCursorVisibly(false);

    while(m_isRunning)
    {
        //Refresh frameskip flag
        frameSkip = g_AppSettings.frameSkip;
        times.start_common = SDL_GetTicks();
        processEvents();
        processMenu();
        update();
        times.stop_render = 0;
        times.start_render = 0;

        /**********************Process rendering of stuff****************************/
        if((PGE_Window::vsync) || (times.doUpdate_render <= 0.0))
        {
            times.start_render = SDL_GetTicks();
            /**********************Render everything***********************/
            render();

            if(!m_doExit) renderMouse();

            GlRenderer::flush();
            GlRenderer::repaint();
            times.stop_render = SDL_GetTicks();
            times.doUpdate_render = frameSkip ? uTickf + (times.stop_render - times.start_render) : 0;
        }

        times.doUpdate_render -= uTickf;

        if(times.stop_render < times.start_render)
        {
            times.stop_render = 0;
            times.start_render = 0;
        }

        /****************************************************************************/

        if((!PGE_Window::vsync) && (uTick > times.passedCommonTime()))
            SDL_Delay(uTick - times.passedCommonTime());
    }

    menu.clear();
    PGE_Window::clean();
    //Show mouse cursor
    PGE_Window::setCursorVisibly(true);
    return ret;
}
Esempio n. 2
0
int main(int argc, char *argv[]) {
    GFraMe_ret rv;
    GFraMe_save sv, *pSv;
    GFraMe_wndext ext;
    int zoom, lang;
    state st;
    
    ext.atlas = "atlas";
    ext.atlasWidth = 256;
    ext.atlasHeight = 256;
    ext.flags = GFraMe_wndext_none;
	//ext.flags = GFraMe_wndext_scanline;
    
    rv = GFraMe_init
            (
             SCR_W,
             SCR_H,
             WND_W,
             WND_H,
             ORG,
             NAME,
             GFraMe_window_none, // GFraMe_window_fullscreen
             &ext,
             FPS,
             1, // Log to file
             0  // Log append
            );
    GFraMe_assertRet(rv == GFraMe_ret_ok, "Init failed", __ret);
    
    setIcon();
    
    // Set the bg color
    GFraMe_set_bg_color(0x22, 0x20, 0x34, 0xff);
    // Set the actual game dimensions
    pSv = 0;
    rv = GFraMe_save_bind(&sv, CONFFILE);
    GFraMe_assertRet(rv == GFraMe_ret_ok, "Error opening file", __ret);
    pSv = &sv;
    rv = GFraMe_save_read_int(&sv, "zoom", &zoom);
    if (rv == GFraMe_ret_ok) {
        // Switch the resolution
        if (zoom != 0 && zoom != 2) {
            GFraMe_ret rv;
            
            rv = GFraMe_screen_set_window_size(SCR_W*zoom, SCR_H*zoom);
            if (rv == GFraMe_ret_ok)
                GFraMe_screen_set_pixel_perfect(0, 1);
        }
        else if (zoom == 0) {
            GFraMe_ret rv;
            
            rv = GFraMe_screen_setFullscreen();
            if (rv == GFraMe_ret_ok)
                GFraMe_screen_set_pixel_perfect(0, 1);
        }
    }
    // Check if the language was stored (and load it)
    rv = GFraMe_save_read_int(&sv, "lang", &lang);
    if (rv == GFraMe_ret_ok) {
        if (lang == EN_US) {
            gl_lang = EN_US;
        }
        else if (lang == PT_BR) {
            gl_lang = PT_BR;
        }
    }
    else {
        gl_lang = EN_US;
    }
    GFraMe_save_close(&sv);
    pSv = 0;
    
    rv = GFraMe_audio_player_init();
    GFraMe_assertRet(rv == GFraMe_ret_ok, "Audio player init failed", __ret);
    
    rv = gl_init();
    GFraMe_assertRet(rv == GFraMe_ret_ok, "global init failed", __ret);
    
    GFraMe_controller_init(1);
    
    st = MENUSTATE;
    // st = CREDITS;
    while (gl_running) {
        switch (st) {
            case     MENUSTATE: st = menustate(); break;
            case NEW_PLAYSTATE: st = playstate(0); break;
            case CNT_PLAYSTATE: st = playstate(1); break;
            case       OPTIONS: st = options(); break;
            case          DEMO: st = demo(); break;
            case       CREDITS: st = credits(); break;
            default: rv = 123; GFraMe_assertRet(0, "Invalid state!", __ret);
        }
    }
    
    rv = 0;
__ret:
    if (pSv)
        GFraMe_save_close(pSv);
    GFraMe_audio_player_pause();
    GFraMe_audio_player_clear();
    gl_clean();
    GFraMe_controller_close();
    GFraMe_quit();
    
    return rv;
}