1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
bool Update()
{
static float CurrentTime = DXUtil_Timer(TIMER_GETABSOLUTETIME); //chrono
if( DXUtil_Timer(TIMER_GETABSOLUTETIME)-CurrentTime>0.015f )//64 fps ( 1/fps. calculé par 1/66 mais a cause des arrondis on a 64fps)
{
srand((unsigned int)timeGetTime()); //On réinitialise le hasard.
//-----------Préparation des variables d'affichage------
static float Timer = 0.0f;
static float dwFrames = 0.0f;
CurrentTime = DXUtil_Timer(TIMER_GETABSOLUTETIME);
//-----------Préparation du device pour l'affichage-----
if( CheckDevice() != D3D_OK )
{
DXUtil_Timer(TIMER_STOP);
Sleep(100);
}
else
{
if (!g_CLM->Is_Paused())
DXUtil_Timer(TIMER_START);
g_Device->Clear(NULL,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
g_Device->BeginScene();
//-----------Acquisition des données périphériques----------
g_CIM->ActualiseState();
g_SA->m_Time = DXUtil_Timer(TIMER_GETAPPTIME);
g_SA->m_RealTime = CurrentTime;
g_SA->m_LastChar = g_CIM->GetInputChar();
g_SA->m_LeftButton = g_CIM->GetButtonsState(1);
g_SA->m_RightButton = g_CIM->GetButtonsState(2);
g_SA->m_x = g_CIM->GetBattleX();
g_SA->m_y = g_CIM->GetBattleY();
//------------Dessin et calcul d'une frame-------------
g_Cadre->Draw();
g_CLM->RenderFrame();
if (!g_CMM->RenderFrame() )
return false;
//------------Calcul des FPS
if( g_COPPtr->GetFps() )
{
dwFrames++;
PrintText(g_FPS,0,0,D3DCOLOR_ARGB(255,0,255,64),WBF_IMPACT);
}
g_Device->EndScene();
g_Device->Present(NULL,NULL,NULL,NULL);
}
//------------Libère les textures inactives-----------
if( CurrentTime - Timer > 1.0f )
{
g_CTM->Head_Reset();
for(int i=0; i<g_ListSize ; i++)
{
STexture* l_TexTmp = g_CTM->Head_GetPointer();
if( l_TexTmp && l_TexTmp->m_Loaded ) //Si texture chargée => vérifie temps
if( CurrentTime - l_TexTmp->m_LastTimeUsed > 7.0f ) //7s
g_CTM->Head_UnloadTexture();
g_CTM->Head_Next();
}
//FPS
sprintf(g_FPS,"%.2f",dwFrames / (CurrentTime - Timer));
dwFrames = 0;
Timer = CurrentTime;
}
}
return true;
} |
Partager