Original Post
Comments for the article High Resolution Timing In Games
float speed = 0.1f
float speed = static_cast<float> (1.0f * m_input_timer.Elapsed());
#ifndef GAME_TIMER_H
#define GAME_TIMER_H
//-----------------------------------------------------------------------------------------------
// game_timer.h
//
// Timer object
//
// Purpose: To provide an interface for timers
//
// Christopher Pisz
// 04/27/04
//-----------------------------------------------------------------------------------------------
#include <windows.h>
class Game_Timer
{
public:
Game_Timer();
~Game_Timer();
void Start();
double Elapsed();
private:
double m_start;
double GetCurrentCount();
};
#endif // GAME_TIMER_H
//-----------------------------------------------------------------------------------------------
// game_timer.cpp
//
// Timer object
//
// Purpose: To provide an interface for game timers such as frame timer
//
//
// Christopher Pisz
// 04/27/04
//-----------------------------------------------------------------------------------------------
#include "game_timer.h"
Game_Timer::Game_Timer()
:
m_start( GetCurrentCount() )
{
}
//-----------------------------------------------------------------------------------------------
Game_Timer::~Game_Timer()
{
}
//-----------------------------------------------------------------------------------------------
void Game_Timer::Start()
{
m_start = GetCurrentCount();
}
//-----------------------------------------------------------------------------------------------
double Game_Timer::Elapsed()
{
return GetCurrentCount() - m_start;
}
//-----------------------------------------------------------------------------------------------
double Game_Timer::GetCurrentCount()
{
LARGE_INTEGER time,
frequency;
QueryPerformanceCounter(&time);
QueryPerformanceFrequency(&frequency);
return static_cast<double>(time.QuadPart) / frequency.QuadPart;
}
// Enter main event loop
while(TRUE)
{
// Test if there is a message in que, if so get it
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Test if this is a quit
if(msg.message==WM_QUIT)
break;
// Translate any accelerator keys
TranslateMessage(&msg);
// Send the message to window proc
DispatchMessage(&msg);
}
// Main processing loop
if(m_active)
{
// Process input
ProcessInput();
m_input_timer.Start();
// Perform any game logic
ProcessLogic();
//m_logic_timer.Start();
// Render
//if( m_frame_timer.Elapsed() > 0.0083333333f )
{
// m_frame_timer.Start();
RenderLoop();
}
}
}
void MyGameHost::ProcessInput()
{
float speed = static_cast<float> (1.0f * m_input_timer.Elapsed());
//float speed = 0.01f;
// Rotations /////////////////////////////////////
// If the ''a'' key is pressed look towards the left
if(m_keys[65])
m_camera.Rotate(-speed, D3DXVECTOR3(0.0f, 1.0f, 0.0f));
// If the ''d'' key is pressed look towards the right
if(m_keys[68])
m_camera.Rotate(speed, D3DXVECTOR3(0.0f, 1.0f, 0.0f));
// If the ''w'' key is pressed look up
if(m_keys[87])
m_camera.Rotate(-speed, D3DXVECTOR3(1.0f, 0.0f, 0.0f));
// If the ''x'' key is pressed look down
if(m_keys[88])
m_camera.Rotate(speed, D3DXVECTOR3(1.0f, 0.0f, 0.0f));
// If the ''e'' key is pressed roll right
if(m_keys[69])
m_camera.Rotate(-speed, D3DXVECTOR3(0.0f, 0.0f, 1.0f));
// If the ''q'' key is pressed roll left
if(m_keys[81])
m_camera.Rotate(speed, D3DXVECTOR3(0.0f, 0.0f, 1.0f));
// Translations ///////////////////////////////////
// If the ''s'' key is pressed move foward
if(m_keys[83])
m_camera.Translate(speed, D3DXVECTOR3(0.0f, 0.0f, 1.0f));
// If the ''v'' key is pressed move backward
if(m_keys[86])
m_camera.Translate(speed, D3DXVECTOR3(0.0f, 0.0f, -1.0f));
// If the ''z'' key is pressed strafe left
if(m_keys[90])
m_camera.Translate(speed, D3DXVECTOR3(-1.0f, 0.0f, 0.0f));
// If the ''c'' key is pressed strafe right
if(m_keys[67])
m_camera.Translate(speed, D3DXVECTOR3(1.0f, 0.0f, 0.0f));
// If the ''r'' key is pressed move up
if(m_keys[82])
m_camera.Translate(speed, D3DXVECTOR3(0.0f, 1.0f, 0.0f));
// If the ''f'' key is pressed move down
if(m_keys[70])
m_camera.Translate(speed, D3DXVECTOR3(0.0f, -1.0f, 0.0f));
}
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more