示例#1
0
RefreshResult
FrameAnimator::RequestRefresh(AnimationState& aState, const TimeStamp& aTime)
{
  // only advance the frame if the current time is greater than or
  // equal to the current frame's end time.
  TimeStamp currentFrameEndTime = GetCurrentImgFrameEndTime(aState);

  // By default, an empty RefreshResult.
  RefreshResult ret;

  while (currentFrameEndTime <= aTime) {
    TimeStamp oldFrameEndTime = currentFrameEndTime;

    RefreshResult frameRes = AdvanceFrame(aState, aTime);

    // Accumulate our result for returning to callers.
    ret.Accumulate(frameRes);

    currentFrameEndTime = GetCurrentImgFrameEndTime(aState);

    // If we didn't advance a frame, and our frame end time didn't change,
    // then we need to break out of this loop & wait for the frame(s)
    // to finish downloading.
    if (!frameRes.mFrameAdvanced && (currentFrameEndTime == oldFrameEndTime)) {
      break;
    }
  }

  return ret;
}
示例#2
0
void GameCamera::Initialize(const GameCameraState& state,
                            motive::MotiveEngine* engine) {
  engine_ = engine;
  start_ = state;
  end_ = state;
  percent_.Invalidate();
  movements_ = std::queue<GameCameraMovement>();
  AdvanceFrame(0);
}
示例#3
0
void DemoState::Run() {
  Uint32 previous_time = 0;
  Uint32 time = 0;
  while (!quit_) {
    previous_time = time;
    time = SDL_GetTicks();
    float delta_time = (time - previous_time) / 1000.0f;
    AdvanceFrame(delta_time);
  }
}
示例#4
0
AnimatedLabel::AnimatedLabel(QWidget *parent) :
    QLabel(parent)
{
    currentAnimation = 0;
    currentImage = 0;
    currentFrame = 0;

    playing = true;

    //advance the frame when the timer expires
    connect(&frameTimer, SIGNAL(timeout()), this, SLOT(AdvanceFrame()));

    frameTimer.start(100);
}
示例#5
0
int CToon::AdvanceToon(bool force)
{
    RECT disp, screen;
    int newx, newy;
    int status = TOON_OK;

    CMainWnd::dskWnd.GetClientRect(&disp);

    newx = m_x + m_u;
    newy = m_y + m_v;

    if (newx < 0) {
        newx = 0;
        status = TOON_PARTIALMOVE;
    } else if (newx + penguin_data[m_bmpIndex].width > disp.right) {
        newx = disp.right - penguin_data[m_bmpIndex].width;
        status = TOON_PARTIALMOVE;
    }
    if (newy < 0) {
        newy = 0;
        status = TOON_PARTIALMOVE;
    } else if (newy + penguin_data[m_bmpIndex].height > disp.bottom) {
        if (!force) {
            newy = disp.bottom - penguin_data[m_bmpIndex].height;
            status = TOON_PARTIALMOVE;
        }
    }

    RECT rt;
    int move_ahead = 1;
    CMainWnd::dskWnd.GetWindowRect(&screen);
    GetRect(rt, newx + screen.left, newy + screen.top);

    if (CMainWnd::wndRgn->RectInRegion(&rt) && !force) {
        int tryx, tryy, step = 1;

        move_ahead = 0;
        status = TOON_BLOCKED;

        if (abs(m_v) < abs(m_u)) {
            if (newx > m_x) {
                step = -1;
            }

            for (tryx = newx + step; tryx != m_x; tryx += step) {
                tryy = m_y + ((tryx - m_x)*m_v)/m_u;

                GetRect(rt, tryx + screen.left, tryy + screen.top);
                if (!CMainWnd::wndRgn->RectInRegion(&rt)) {
                    newx = tryx;
                    newy = tryy;
                    status = TOON_PARTIALMOVE;
                    move_ahead = 1;
                    break;
                }
            }
        } else {
            if (newy > m_y) {
                step = -1;
            }

            for (tryy = newy + step; tryy != m_y; tryy += step) {
                tryx = m_x + ((tryy - m_y)*m_u)/m_v;

                GetRect(rt, tryx + screen.left, tryy + screen.top);
                if (!CMainWnd::wndRgn->RectInRegion(&rt)) {
                    newx = tryx;
                    newy = tryy;
                    status = TOON_PARTIALMOVE;
                    move_ahead = 1;
                    break;
                }
            }
        }

    }

    if (move_ahead) {
        m_x = newx;
        m_y = newy;
    }

    if (move_ahead || m_bmpIndex >= PENGUIN_BOMBER) {
        AdvanceFrame();
    }

    if (m_y + penguin_data[m_bmpIndex].height > disp.bottom) {
        ExplodeAni();
    }


    return status;
}
示例#6
0
int main(int argc, char *argv[])
{
#ifdef PARSEC_VERSION
#define __PARSEC_STRING(x) #x
#define __PARSEC_XSTRING(x) __PARSEC_STRING(x)
        std::cout << "PARSEC Benchmark Suite Version "__PARSEC_XSTRING(PARSEC_VERSION) << std::endl << std::flush;
#else
        std::cout << "PARSEC Benchmark Suite" << std::endl << std::flush;
#endif //PARSEC_VERSION
#ifdef ENABLE_PARSEC_HOOKS
  __parsec_bench_begin(__parsec_fluidanimate);
#endif

  if(argc < 4 || argc >= 6)
  {
    std::cout << "Usage: " << argv[0] << " <threadnum> <framenum> <.fluid input file> [.fluid output file]" << std::endl;
    return -1;
  }

  int threadnum = atoi(argv[1]);
  int framenum = atoi(argv[2]);

  //Check arguments
  if(threadnum != 1) {
    std::cerr << "<threadnum> must be 1 (serial version)" << std::endl;
    return -1;
  }
  if(framenum < 1) {
    std::cerr << "<framenum> must at least be 1" << std::endl;
    return -1;
  }

#ifdef ENABLE_CFL_CHECK
  std::cout << "WARNING: Check for Courant–Friedrichs–Lewy condition enabled. Do not use for performance measurements." << std::endl;
#endif

  InitSim(argv[3]);
#ifdef ENABLE_VISUALIZATION
  InitVisualizationMode(&argc, argv, &AdvanceFrame, &numCells, &cells, &cnumPars);
#endif

#ifndef ENABLE_VISUALIZATION

//core of benchmark program (the Region-of-Interest)
#ifdef ENABLE_PARSEC_HOOKS
  __parsec_roi_begin();
#endif
  for(int i = 0; i < framenum; ++i) {
    AdvanceFrame();
  }
#ifdef ENABLE_PARSEC_HOOKS
  __parsec_roi_end();
#endif

#else //ENABLE_VISUALIZATION
  Visualize();
#endif //ENABLE_VISUALIZATION

  if(argc > 4)
    SaveFile(argv[4]);
  CleanUpSim();

#ifdef ENABLE_PARSEC_HOOKS
  __parsec_bench_end();
#endif

  return 0;
}
示例#7
0
inline HRESULT CGifSmileyCtrl::FireViewChange()
{
	if (m_bInPlaceActive)
	{
		// Active
		if (m_hWndCD != NULL)
			::InvalidateRect(m_hWndCD, NULL, m_bTransparent); // Window based
		else if (m_bWndLess && m_spInPlaceSite != NULL)
			m_spInPlaceSite->InvalidateRect(NULL, m_bTransparent); // Windowless
	}
	else if (!m_hwndParent)
	{
		SendOnViewChange(DVASPECT_CONTENT);
	}
	else
	{ 

		COLORREF oldColor=m_clrBackColor;
		BOOL     fOldTransparent= m_bTransparent;
		HWND     hwndOld=m_hwndParent; 
		FVCNDATA_NMHDR nmhdr={0};

		nmhdr.cbSize=sizeof(FVCNDATA_NMHDR);
		nmhdr.hwndFrom=hwndOld;
		nmhdr.code=NM_FIREVIEWCHANGE;
		nmhdr.clrBackground=oldColor;
		nmhdr.fTransparent=fOldTransparent;
		nmhdr.bAction= m_bPaintValid ? (fOldTransparent ? FVCA_INVALIDATE : FVCA_DRAW ) : FVCA_SENDVIEWCHANGE;
		nmhdr.rcRect=m_rectPos;
		//SendPrePaintEvent
		nmhdr.bEvent=FVCN_PREFIRE;
		
		//set members
		m_clrBackColor=nmhdr.clrBackground;
		m_bTransparent=nmhdr.fTransparent;
		m_hwndParent=nmhdr.hwndFrom;
		switch (nmhdr.bAction)
		{
		case FVCA_SKIPDRAW:
			AdvanceFrame();
			break;
		case FVCA_SENDVIEWCHANGE:
			SendOnViewChange(DVASPECT_CONTENT);
			::SendMessage(m_hwndParent, WM_PAINT, NULL, NULL);
			break;
		case FVCA_INVALIDATE:
			::InvalidateRect(m_hwndParent, &(nmhdr.rcRect), FALSE);
			break;
		case FVCA_DRAW:
		case FVCA_CUSTOMDRAW:
			ATL_DRAWINFO di;
			memset(&di,0,sizeof(ATL_DRAWINFO));
			di.cbSize=sizeof(ATL_DRAWINFO);
			di.dwDrawAspect=DVASPECT_CONTENT;
			if (nmhdr.bAction==FVCA_DRAW)
				di.hdcDraw=::GetWindowDC(m_hwndParent);
			else
				di.hdcDraw=nmhdr.hDC;
			RECTL rcl={nmhdr.rcRect.left, nmhdr.rcRect.top, nmhdr.rcRect.right, nmhdr.rcRect.bottom};
			di.prcBounds=&rcl;
			OnDrawSmiley(di,nmhdr.bAction==FVCA_DRAW);
			if (nmhdr.bAction==FVCA_DRAW)
				::ReleaseDC(m_hwndParent, di.hdcDraw);
			break;
		}
		//SendPostPaintEvent
		nmhdr.bEvent=FVCN_POSTFIRE;
		
		//restore members
		m_clrBackColor=oldColor;
		m_bTransparent=fOldTransparent;
		m_hwndParent=hwndOld;
	}

	return S_OK;
} 
示例#8
0
HRESULT CGifSmileyCtrl::OnDrawSmiley(ATL_DRAWINFO& di, bool bCustom=false)
{
	USES_CONVERSION;
	if (di.dwDrawAspect != DVASPECT_CONTENT)
	{
		return E_FAIL;
	}
	if ( bCustom && !IsVisible(di))
	{
		return S_OK;
	}
	if (!m_pGifImage)
	{
		return E_FAIL;
	}
	RECT& rc = *(RECT*)di.prcBounds;

	HRGN hOldRgn, hNewRgn;

	if (!IsRectEmpty(&m_rectPos))
	{   //strange workaround for drawing zoom out smileys (look MS calculate it one pix larger than exactly)
		if (rc.bottom-rc.top-1 == m_rectPos.bottom-m_rectPos.top 
			&& rc.right-rc.left== m_rectPos.right-m_rectPos.left)
			rc.top+=1;
	}

	if ( bCustom )SelectSmileyClipRgn(di.hdcDraw, rc, hOldRgn, hNewRgn, TRUE);

	InflateRect(&rc,-1,0); //border offset to fix blinked cursor painting
	if ( (m_dwFlags&REO_INVERTEDSELECT) == 0 || !bCustom || m_bTransparent)
		DoDrawSmiley(di.hdcDraw, rc, rc.right-rc.left,rc.bottom-rc.top, m_nFrameSize.Width, m_nFrameSize.Height);
	else
	{
		Bitmap bmp(rc.right-rc.left,rc.bottom-rc.top, PixelFormat32bppARGB);
		Graphics g(&bmp);
		COLORREF col=(COLORREF)(m_clrBackColor);
		SolidBrush brush(Color(GetRValue(col),GetGValue(col),GetBValue(col)));
		g.FillRectangle( &brush, 0 ,0, rc.right-rc.left, rc.bottom-rc.top);
		HDC hdc=g.GetHDC();
		RECT mrc={0};
		mrc.right=rc.right-rc.left;
		mrc.bottom=rc.bottom-rc.top;
		DoDrawSmiley(hdc, mrc, mrc.right-mrc.left,mrc.bottom-mrc.top, m_nFrameSize.Width, m_nFrameSize.Height);
		InvertRect(hdc, &mrc);
		BitBlt(di.hdcDraw, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, SRCCOPY );
		g.ReleaseHDC(hdc);       
	}
	if ((m_dwFlags&REO_SELECTED) == REO_SELECTED && bCustom)
	{
		//Draw frame around
		HBRUSH oldBrush=(HBRUSH)SelectObject(di.hdcDraw, GetStockObject(NULL_BRUSH)); 
		HPEN oldPen=(HPEN)SelectObject(di.hdcDraw, GetStockObject(BLACK_PEN));
		::Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom );
		SelectObject(di.hdcDraw, oldBrush);
		SelectObject(di.hdcDraw, oldPen);
	}
	AdvanceFrame();
	if (!bCustom) 
		m_bPaintValid=false;
	ResetClip(di.hdcDraw, hOldRgn, hNewRgn);

	return S_OK;
}
//-----------------------------------------------------------------------------
// Render a frame
//-----------------------------------------------------------------------------
void CIHVTestApp::RenderFrame( void )
{
	VPROF( "RenderFrame" );
	IHVTestModel *pModel = NULL;
	static int currentRun = 0;
	static int currentFrame = 0;
	static int currentLightCombo = 0;
	int modelAlternator = 0;

	if (g_bInError)
	{
		// error context is active
		// error may be renderer based, avoid re-entrant render to fatal crash
		return;
	}

	if( g_BenchMode )
	{
		if( currentFrame > g_BenchRuns[currentRun].numFrames )
		{
			currentLightCombo++;
			if( currentLightCombo >= LIGHTING_COMBINATION_COUNT )
			{
				currentRun++;
				currentLightCombo = 0;
				if( currentRun >= NUM_BENCH_RUNS )
				{
					g_BenchFinished = true;
					return;
				}
			}
			currentFrame = 0;
		}
	}
	if( g_BenchMode )
	{
		pModel = &g_BenchModels[currentRun][0];		
		g_NumCols = g_BenchRuns[currentRun].cols;
		g_NumRows = g_BenchRuns[currentRun].rows;
	}
	else
	{
		pModel = m_pIHVTestModel;
	}
	Assert( pModel );
	
	g_EngineStats.BeginFrame();

	g_pMaterialSystem->BeginFrame( 0 );
	g_pStudioRender->BeginFrame();

	CMatRenderContextPtr pRenderContext( g_pMaterialSystem );

	pRenderContext->ClearColor3ub( 0, 0, 0 );
	pRenderContext->ClearBuffers( true, true );

	pRenderContext->Viewport( 0, 0, g_RenderWidth, g_RenderHeight );

	pRenderContext->MatrixMode( MATERIAL_PROJECTION );
	pRenderContext->LoadIdentity();
	pRenderContext->PerspectiveX( 90.0f, ( g_RenderWidth / g_RenderHeight), 1.0f, 500000.0f );

	pRenderContext->MatrixMode( MATERIAL_VIEW );
	pRenderContext->LoadIdentity();
	if( g_BenchMode )
	{
		pRenderContext->Translate( 0.0f, 0.0f, ( float )-( g_NumCols  * g_BenchRuns[currentRun].modelSize * 0.6f ) );
	}
	else
	{
		pRenderContext->Translate( 0.0f, 0.0f, ( float )-( g_NumCols  * 80.0f * 0.5f ) );
	}

	pRenderContext->MatrixMode( MATERIAL_MODEL );
	pRenderContext->LoadIdentity();

	QAngle angles;
	angles[YAW] = -90.0f;
	angles[PITCH] = -90.0f;
	angles[ROLL] = 0.0f;

	matrix3x4_t cameraMatrix;
	AngleMatrix( angles, cameraMatrix );

	int r, c;
	int trisRendered = 0;
	float boneSetupTime = 0.0f;
	for( r = 0; r < g_NumRows; r++ )
	{
		for( c = 0; c < g_NumCols; c++ )
		{
			// If we are alternating models, select the next valid model.			
			if( g_BenchMode )
			{
				do
				{
					// If I pass my maximum number of models, wrap around to model 0, which must always be valid.
					if( ++modelAlternator >= g_nMaxModels )
					{
						modelAlternator = 0;
						break;
					}
				}
				while( !g_BenchRuns[currentRun].pModelName[modelAlternator] );

				pModel = &g_BenchModels[currentRun][modelAlternator];
				Assert( pModel );
			}

			if( g_BenchMode )
			{
				cameraMatrix[0][3] = ( ( c + 0.5f ) - ( g_NumCols * .5f ) ) * g_BenchRuns[currentRun].modelSize;
				cameraMatrix[1][3] = ( ( float )r - ( g_NumCols * .5f ) ) * g_BenchRuns[currentRun].modelSize;
			}
			else
			{
				cameraMatrix[0][3] = ( ( c + 0.5f ) - ( g_NumCols * .5f ) ) * 75.0f;
				cameraMatrix[1][3] = ( ( float )r - ( g_NumCols * .5f ) ) * 75.0f;
			}
			
			Vector modelOrigin( cameraMatrix[0][3], cameraMatrix[1][3], 0.0f );
			Vector lightOffset( cameraMatrix[0][3], cameraMatrix[1][3], 0.0f );

			if (g_LightingCombination < 0)
			{
				SetupLighting( g_BenchMode ? currentLightCombo : 0, lightOffset );
			}
			else
			{
				SetupLighting( g_LightingCombination, lightOffset );
			}

			float startBoneSetupTime = Sys_FloatTime();
			int lod = g_LOD;
			lod = clamp( lod, pModel->pHardwareData->m_RootLOD, pModel->pHardwareData->m_NumLODs-1 );

			int boneMask = BONE_USED_BY_VERTEX_AT_LOD( lod );
			matrix3x4_t *pBoneToWorld = SetUpBones( pModel->pStudioHdr, cameraMatrix, currentRun, modelAlternator, boneMask );
			boneSetupTime += Sys_FloatTime() - startBoneSetupTime;
			
			pRenderContext->MatrixMode( MATERIAL_MODEL );
			pRenderContext->PushMatrix();

			DrawModelInfo_t modelInfo;
			memset( &modelInfo, 0, sizeof( modelInfo ) );
			modelInfo.m_pStudioHdr = pModel->pStudioHdr;
			modelInfo.m_pHardwareData = pModel->pHardwareData;
			modelInfo.m_Decals = STUDIORENDER_DECAL_INVALID;
			modelInfo.m_Skin = 0;
			modelInfo.m_Body = g_BodyGroup;
			modelInfo.m_HitboxSet = 0;
			modelInfo.m_pClientEntity = NULL;
			modelInfo.m_Lod = lod;
			modelInfo.m_pColorMeshes = NULL;
			g_pStudioRender->DrawModel( NULL, modelInfo, pBoneToWorld, NULL, NULL, modelOrigin );

			DrawModelResults_t results;
			g_pStudioRender->GetPerfStats( &results, modelInfo, NULL );
			trisRendered += results.m_ActualTriCount;

			pRenderContext->MatrixMode( MATERIAL_MODEL );
			pRenderContext->PopMatrix();
		}
	}

	pRenderContext->Flush( true );
	g_EngineStats.EndFrame();

	g_pStudioRender->EndFrame();
	g_pMaterialSystem->EndFrame();

	// hack - don't count the first frame in case there are any state
	// transitions computed on that frame.
	if( currentFrame != 0 )
	{
		g_BenchResults[currentRun][currentLightCombo].totalTime += g_EngineStats.GetCurrentSystemFrameTime();
		g_BenchResults[currentRun][currentLightCombo].totalTris += trisRendered;
	}

	for ( int model = 0; model < g_nMaxModels; ++model )
	{
		CStudioHdr studioHdr( g_BenchModels[currentRun][model].pStudioHdr, g_pMDLCache );
		AdvanceFrame( &studioHdr, currentRun, model, g_EngineStats.GetCurrentSystemFrameTime() );
	}

	g_pMaterialSystem->SwapBuffers();

#ifdef USE_VPROF
	g_VProfCurrentProfile.MarkFrame();
	static bool bBeenHere = false;
	if( !bBeenHere )
	{
		bBeenHere = true;
		g_VProfCurrentProfile.Reset();
	}
#endif
	currentFrame++;
}