Пример #1
0
void GameWindow::run()
{
    while(running)
    {
        renderWindow.setActive(true);
        renderWindow.clear();

        gamePtr->refreshInput();
        runInput();
        timer.runUpdate();
        gamePtr->onPostUpdate();

        timer.runDraw();
        renderWindow.display();

        timer.runFrameTime();
        timer.runFps();
    }
}
Пример #2
0
void run() {

    view.firstTimeStamp = view.lastRecordFrame = view.lastVideoFrame = getMS();

    view.dirty = 0;
    view.lastVideoFrameSkip=0;
    view.zoomTarget = view.zoom;
    view.zoomSpeed = 0;
    VectorCopy(view.rot, view.rotTarget);
    VectorZero(view.rotSpeed);

    while (!view.quit) {

        Uint32 ts_before, ts_after;
        Uint32 ts;
        ts_before =  getMS();

        if (state.mode & SM_RECORD) {

            view.frameSkipCounter = 0;

            //if (view.verboseMode)
            //    conAdd(LLOW, "R frame:%5i dt:%5i fs:%2i", state.totalFrames, view.deltaVideoFrame, state.historyNFrame);

            setTitle(va("%s frame: %i/%i (skip:%i)", STRING_RECORD, state.totalFrames, state.historyFrames, state.historyNFrame));

            processFrame();
            ts = getMS();
            view.deltaRecordFrame = ts - view.lastRecordFrame;
            view.lastRecordFrame = ts;

            if (state.autoSave && (state.totalFrames - state.lastSave) >= state.autoSave) {
                cmdSaveFrameDump(0);
                state.lastSave = state.totalFrames;
            }

        }

        else if (state.mode & SM_PLAY) {

            if (view.frameSkip < 0) {
                view.frameSkipCounter++;
                if (view.frameSkipCounter > -view.frameSkip) {
                    view.frameSkipCounter = 0;
                    state.currentFrame++;
                }
            } else {
                state.currentFrame++;
                state.currentFrame+=view.frameSkip;
            }

            if (state.currentFrame >= state.frame) {
                state.currentFrame = 0;
                view.frameSkipCounter = 0;
            }

            //if (view.verboseMode)
            //    conAdd(LLOW, "P frame:%5i dt:%5i fs:%2i", state.currentFrame, view.deltaVideoFrame, state.historyNFrame);

        }

        timerUpdate();

        runInput();
        if (view.quit) return;

        if (state.autoRecordNext) {
            state.autoRecordNext = 0;
            cmdRecord(0);
        }

        setColours();
        if (view.zoomFitAuto == 2) {
            cmdZoomFit(NULL);
            view.zoomTarget = view.zoom;
            view.zoomSpeed = 0;
        }

        runVideo();

        /* if we are not recording or replaying, wait a bit -- helps to cool down you laptop :-)) */
        if (((state.mode & (SM_RECORD|SM_PLAY) ) == 0) && (view.dirty < 1)) {
            ts_after =  getMS();
            if (ts_after < (ts_before + SMALL_NAP)) SDL_Delay( SMALL_NAP - (ts_after - ts_before));
        }

        /* pull the break on very fast video cards - 60fps playback is enough */
        if (((state.mode & SM_PLAY ) == SM_PLAY) || (state.mode == 0)) {
            ts_after =  getMS();
            if (ts_after < (ts_before + PLAY_MIN_TIME)) SDL_Delay(PLAY_MIN_TIME - (ts_after - ts_before));
        }

	/* if minVideoRefreshTime is set, hold the current frame a bit longer*/
	if (view.minVideoRefreshTime >= SDL_TIMESLICE) {
            ts_after =  getMS();
            if (ts_after < (ts_before + view.minVideoRefreshTime)) SDL_Delay(view.minVideoRefreshTime - (ts_after - ts_before));
        }

        // if last video frame was displayed, reset dirty flag
        if (view.lastVideoFrameSkip==0) {
            view.dirty = 0;
            if (view.drawAxis==3) view.drawAxis=1;
        }
    }

}