Example #1
0
	void cFPSCounter::AddFrame()
	{
		mlFramecounter++;

		mfFrametime = (((float)GetApplicationTime()) / 1000.0f) - mfFrametimestart;
		
		// update the timer
		if (mfFrametime >= mfUpdateRate)
		{
			mfFPS = ((float)mlFramecounter)/mfFrametime;
			mlFramecounter = 0;
			mfFrametimestart = ((float)GetApplicationTime()) / 1000.0f; 
		}
	}
Example #2
0
	bool cLogicTimer::WantUpdate()
	{
		++m_lUdpateCount;
		if (m_lUdpateCount > m_lMaxUpdates)
			return false;

		if (m_fLocalTime < (double)GetApplicationTime())
		{
			Update();
			return true;
		}
		return false;
	}
Example #3
0
	cFPSCounter::cFPSCounter(iLowLevelSystem* apLowLevelSystem)
	{
		mfFPS = 60;

		mlFramecounter=0;
		mfFrametimestart=0;
		mfFrametime=0;
	
		mfUpdateRate = 1;

		mpLowLevelSystem = apLowLevelSystem;

		mfFrametimestart = ((float)GetApplicationTime()) / 1000.0f; 
	}
Example #4
0
	void cGame::Run()
	{
		//Log line that ends user init.
		Log("--------------------------------------------------------\n\n");
		
		bool bDone = false;
		double fNumOfTimes=0;
		double fMediumTime=0;

		mpUpdater->OnStart();
		
		mpLogicTimer->Reset();

		//Loop the game... fix the var...
		unsigned long lTempTime = GetApplicationTime();
		
		//reset the mouse, really reset the damn thing :P
		for(int i=0;i<10;i++) mpInput->GetMouse()->Reset();
		
		
		Log("Game Running\n");
		Log("--------------------------------------------------------\n");

		mfFrameTime = 0;
		unsigned long lTempFrameTime = GetApplicationTime();
		
		bool mbIsUpdated = true;
		
		//cMemoryManager::SetLogCreation(true);

		while(!mbGameIsDone)
		{
			//Log("-----------------\n");
			//////////////////////////
			//Update logic.
			while(mpLogicTimer->WantUpdate() && !mbGameIsDone)
			{
				unsigned int lUpdateTime = GetApplicationTime();
				
				mpUpdater->Update(GetStepSize());
				
				unsigned int lDeltaTime = GetApplicationTime() - lUpdateTime;
				mfUpdateTime = (float)(lDeltaTime) / 1000.0f;

				mbIsUpdated = true;

				glClearUpdateCheck++;
				if(glClearUpdateCheck % 500 == 0)
				{
					if(mpUpdater->GetCurrentContainerName() == "Default") ClearUpdateLogFile();
				}

				mfGameTime += GetStepSize();
			}
			mpLogicTimer->EndUpdateLoop();

			
			//If not making a single rendering is better to use gpu and 
			//cpu at the same time and make query checks etc after logic update.
			//If any delete has occured in the update this might crash. so skip it for now.
			/*if(mbRenderOnce==false)	{
				mpGraphics->GetRenderer3D()->FetchOcclusionQueries();
				mpUpdater->OnPostBufferSwap();
			}*/
			
			//Draw graphics!
			if(mbRenderOnce && bDone)continue;
			if(mbRenderOnce)bDone = true;
			
			
			if(mbIsUpdated)
			{
				mpScene->UpdateRenderList(mfFrameTime);
				if(mbLimitFPS==false) mbIsUpdated = false;
			}
			
			if(mbLimitFPS==false || mbIsUpdated)
			{
				//LogUpdate("----------- RENDER GFX START --------------\n");

				mbIsUpdated = false;

           		//Get the the from the last frame.
				mfFrameTime = ((float)(GetApplicationTime() - lTempFrameTime))/1000;
				lTempFrameTime = GetApplicationTime();
				
				//Draw this frame
				//unsigned long lFTime = GetApplicationTime();
				mpUpdater->OnDraw();
				mpScene->Render(mpUpdater,mfFrameTime);
				//if(mpScene->GetDrawScene()) LogUpdate("FrameTime: %d ms\n", GetApplicationTime() - lFTime);
				
				//Update fps counter.
				mpFPSCounter->AddFrame();
	           	
				//Update the screen.
				mpGraphics->GetLowLevel()->SwapBuffers();
				//Log("Swap done: %d\n", GetApplicationTime());
				//if(mbRenderOnce)
				{
					mpScene->FetchOcclusionQueries();
					mpUpdater->OnPostBufferSwap();
				}
				
				fNumOfTimes++;
			}

			//if(cMemoryManager::GetLogCreation())
			//{
				//cMemoryManager::SetLogCreation(false);
				//Log("----\nCreations made: %d\n------\n",cMemoryManager::GetCreationCount());
			//}
		}
		Log("--------------------------------------------------------\n\n");
	
		Log("Statistics\n");
		Log("--------------------------------------------------------\n");

		unsigned long lTime = GetApplicationTime() - lTempTime;
		fMediumTime = fNumOfTimes/(((double)lTime)/1000);
		
		Log(" Medium framerate: %f\n", fMediumTime);
		Log("--------------------------------------------------------\n\n");

		Log("User Exit\n");
		Log("--------------------------------------------------------\n");
		
		mpUpdater->OnExit();
	}
	void iPhysicsWorld::Update(float afTimeStep)
	{
		//Clear all contact points.
		mvContactPoints.clear();

		////////////////////////////////////
		//Update controllers
		tPhysicsControllerListIt CtrlIt = mlstControllers.begin();
		for(; CtrlIt != mlstControllers.end(); ++CtrlIt)
		{
			iPhysicsController *pCtrl = *CtrlIt;

			pCtrl->Update(afTimeStep);
		}


		////////////////////////////////////
		//Update character bodies
		unsigned int lTime = GetApplicationTime();
		tCharacterBodyListIt CharIt = mlstCharBodies.begin();
		for(; CharIt != mlstCharBodies.end(); ++CharIt)
		{
			iCharacterBody *pBody = *CharIt;

			//for(int i=0; i<20; ++i)
			{
				pBody->Update(afTimeStep);//20.0f);
			}
		}
		//LogUpdate(" Updating chars took %d ms\n",mpWorld3D->GetSystem()->GetLowLevel()->GetTime() - lTime);


		////////////////////////////////////
		//Update the rigid bodies before simulation.
		tPhysicsBodyListIt BodyIt = mlstBodies.begin();
		for(; BodyIt != mlstBodies.end(); ++BodyIt)
		{
			iPhysicsBody *pBody = *BodyIt;

			pBody->UpdateBeforeSimulate(afTimeStep);

		}

		////////////////////////////////////
		//Simulate the physics
		lTime = GetApplicationTime();
		Simulate(afTimeStep);
		//LogUpdate(" Updating lowlevel physics took %d ms\n",mpWorld3D->GetSystem()->GetLowLevel()->GetTime() - lTime);

		////////////////////////////////////
		//Update the joints after simulation.
		tPhysicsJointListIt JointIt = mlstJoints.begin();
		for(; JointIt != mlstJoints.end(); )
		{
			iPhysicsJoint *pJoint = *JointIt;

			pJoint->OnPhysicsUpdate();

			if(pJoint->CheckBreakage())
			{
				JointIt = mlstJoints.erase(JointIt);
				hplDelete(pJoint);
			}
			else
			{
				++JointIt;
			}
		}
		////////////////////////////////////
		//Update the rigid bodies after simulation.
		BodyIt = mlstBodies.begin();
		for(; BodyIt != mlstBodies.end(); ++BodyIt)
		{
			iPhysicsBody *pBody = *BodyIt;

			pBody->UpdateAfterSimulate(afTimeStep);
		}
	}
Example #6
0
	void cLogicTimer::Reset()
	{
		m_fLocalTime = (double)GetApplicationTime();
	}