本文整理汇总了C++中SDL_GetPerformanceFrequency函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetPerformanceFrequency函数的具体用法?C++ SDL_GetPerformanceFrequency怎么用?C++ SDL_GetPerformanceFrequency使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_GetPerformanceFrequency函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
TankGame game;
float tick_duration = 1000.0f / SDL_GetPerformanceFrequency();
float frame_ticks = SDL_GetPerformanceFrequency() * 1.0f / 60.0f;
auto timer = SDL_GetPerformanceCounter();
if (game.initialize(false))
{
game.loadLevel01();
for (int i = 0; i < 500; ++i)
{
if (game.getPlayerTank())
{
game.getPlayerTank()->turnTurret(0.02);
if (i % 4 == 0) game.getPlayerTank()->fireBullet(5.0f);
}
game.updateLogic(1.0f/60.0);
game.render();
auto now = SDL_GetPerformanceCounter();
float delay = frame_ticks - (float)(now - timer);
if (delay > 0)
{
SDL_Delay(delay * tick_duration);
}
timer = SDL_GetPerformanceCounter();
}
}
}
示例2: DEBUGPRINTF
void Clock::Initialize()
{
DEBUGPRINTF( "Initializing Clock\n" );
ShutDown();
#if BUILD_WINDOWS_NO_SDL
LARGE_INTEGER Frequency;
LARGE_INTEGER Counter;
QueryPerformanceFrequency( &Frequency );
QueryPerformanceCounter( &Counter );
m_Resolution = 1.0 / (double)Frequency.QuadPart;
m_PhysicalBaseTime = Counter.QuadPart;
#endif
#if BUILD_SDL
Uint64 Frequency = SDL_GetPerformanceFrequency();
Uint64 Counter = SDL_GetPerformanceCounter();
m_Resolution = 1.0 / static_cast<double>( Frequency );
m_PhysicalBaseTime = Counter;
#endif
m_PhysicalDeltaTime = 0;
m_MachineDeltaTime = 0.0f;
m_GameDeltaTime = 0.0f;
m_PhysicalCurrentTime = 0;
m_MachineCurrentTime = 0.0f;
m_GameCurrentTime = 0.0f;
m_TickCount = 0;
}
示例3: SDL_GetPerformanceCounter
void app::perf::dump(bool log)
{
// Sample the timer.
Uint64 current = SDL_GetPerformanceCounter();
Uint64 persec = SDL_GetPerformanceFrequency();
// Calculate the timings.
double d1 = double(current - local_start) / double(persec);
double dn = double(current - total_start) / double(persec);
double m1 = 1000.0 * d1 / local_frames;
double mn = 1000.0 * dn / total_frames;
int fps = int(ceil(local_frames / d1));
local_start = current;
// Report to a string. Set the window title and log.
std::ostringstream str;
str << std::fixed << std::setprecision(1) << m1 << "ms "
<< "(" << mn << "ms) "
<< fps << "fps";
SDL_SetWindowTitle(window, str.str().c_str());
if (log) std::cout << str.str() << std::endl;
}
示例4: SDL_GetPerformanceFrequency
void Core::run()
{
uint64_t frequency = SDL_GetPerformanceFrequency();
uint64_t fixedStep = frequency / static_cast<uint64_t>(kStepRate);
uint64_t maxTotalDelta = fixedStep * 6;
uint64_t stepTime = SDL_GetPerformanceCounter();
while(!done_)
{
uint64_t loopTime = SDL_GetPerformanceCounter();
if(loopTime > stepTime + maxTotalDelta)
{
stepTime = loopTime - maxTotalDelta;
}
while(loopTime >= stepTime + fixedStep)
{
handleEvents();
sessionManager_->handleBlobs();
step(fp_t(1.0) / kStepRate);
stepTime += fixedStep;
}
#ifndef HEADLESS
fp_t interp = static_cast<fp_t>(loopTime - stepTime) / static_cast<fp_t>(frequency);
renderer_->render(interp);
#else
// simulate ~83 without game logic
SDL_Delay(12);
#endif
}
}
示例5: ImGui_ImplSDL2_NewFrame
void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer back-end. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplOpenGL3_NewFrame().");
// Setup display size (every frame to accommodate for window resizing)
int w, h;
int display_w, display_h;
SDL_GetWindowSize(window, &w, &h);
SDL_GL_GetDrawableSize(window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)w, (float)h);
if (w > 0 && h > 0)
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
static Uint64 frequency = SDL_GetPerformanceFrequency();
Uint64 current_time = SDL_GetPerformanceCounter();
io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
g_Time = current_time;
ImGui_ImplSDL2_UpdateMousePosAndButtons();
ImGui_ImplSDL2_UpdateMouseCursor();
// Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads();
}
示例6: UpdateCamera
void OpenGlCamera::UpdateCamera(const Uint8 *keyboard_state, int *x, int *y) {
double render_time = (SDL_GetPerformanceCounter() - last_call_time_) / (double)SDL_GetPerformanceFrequency();
last_call_time_ = SDL_GetPerformanceCounter();
// the mouse movement doesn't depend on the render_time (fps)
this->camera_data_->AddRot((-*y) * 0.001f * this->camera_data_->camera_sensitivity, (-*x) * 0.001f * this->camera_data_->camera_sensitivity, 0.0f);
/*if (keyboard_state[SDL_SCANCODE_Q])
this->camera_data->AddRot(0.0f, 0.0f, +render_time * this->camera_data_->speed * 0.1f);
if (keyboard_state[SDL_SCANCODE_E])
this->camera_data->AddRot(0.0f, 0.0f, -render_time * this->camera_data_->speed * 0.1f);*/
// Movement
if (keyboard_state[SDL_SCANCODE_Q])
this->camera_data_->AddPos(0.0f, 0.0f, -render_time * this->camera_data_->camera_speed);
if (keyboard_state[SDL_SCANCODE_E])
this->camera_data_->AddPos(0.0f, 0.0f, +render_time * this->camera_data_->camera_speed);
if (keyboard_state[SDL_SCANCODE_W] || keyboard_state[SDL_SCANCODE_UP])
this->camera_data_->AddPos(+render_time * this->camera_data_->camera_speed, 0.0f, 0.0f);
if (keyboard_state[SDL_SCANCODE_A] || keyboard_state[SDL_SCANCODE_LEFT])
this->camera_data_->AddPos(0.0f, +render_time * this->camera_data_->camera_speed, 0.0f);
if (keyboard_state[SDL_SCANCODE_S] || keyboard_state[SDL_SCANCODE_DOWN])
this->camera_data_->AddPos(-render_time * this->camera_data_->camera_speed, 0.0f, 0.0f);
if (keyboard_state[SDL_SCANCODE_D] || keyboard_state[SDL_SCANCODE_RIGHT])
this->camera_data_->AddPos(0.0f, -render_time * this->camera_data_->camera_speed, 0.0f);
}
示例7: SDL_Init
bool Engine::Initialize() {
// We will initialize all SDL subsystems one by one
SDL_Init( 0 );
// Profiler needs the timer subsystem
if ( SDL_InitSubSystem( SDL_INIT_TIMER ) != 0 ) {
Logger::Log( "Failed to initialize SDL timer subsystem", "SDL", LogSeverity::ERROR_MSG );
assert( false );
}
g_Profiler.SetFrequency( SDL_GetPerformanceFrequency() );
// Several systems need the event system
if ( SDL_InitSubSystem( SDL_INIT_EVENTS ) != 0 ) {
Logger::Log( "Failed to initialize SDL event subsystem", "SDL", LogSeverity::ERROR_MSG );
assert( false );
}
g_SubsystemBank.Initialize();
InitializeComponentSystem();
g_InputState.Initialize();
g_Input.Initialize();
g_TextInput.Initialize();
m_SubsystemCollection.InitializeGameMode( ( 1 << g_SubsystemBank.GetNrOfSubsystems() ) - 1 );
return true;
}
示例8: Sys_DoubleTime
/*
================
Sys_DoubleTime
================
*/
double Sys_DoubleTime( void )
{
static longtime_t g_PerformanceFrequency;
static longtime_t g_ClockStart;
longtime_t CurrentTime;
#ifdef XASH_SDL
if( !g_PerformanceFrequency )
{
g_PerformanceFrequency = SDL_GetPerformanceFrequency();
g_ClockStart = SDL_GetPerformanceCounter();
}
CurrentTime = SDL_GetPerformanceCounter();
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
#elif _WIN32
if( !g_PerformanceFrequency )
{
g_PerformanceFrequency = GetPerformanceFrequency();
g_ClockStart = GetPerformanceCounter();
}
CurrentTime = GetPerformanceCounter();
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
#else
struct timespec ts;
if( !g_PerformanceFrequency )
{
struct timespec res;
if( !clock_getres(CLOCK_MONOTONIC, &res) )
g_PerformanceFrequency = 1000000000LL/res.tv_nsec;
}
clock_gettime(CLOCK_MONOTONIC, &ts);
return (double) ts.tv_sec + (double) ts.tv_nsec/1000000000.0;
#endif
}
示例9: executeStack
void executeStack(StateStack& stack, SDL_Window& window, bool* pTerminator)
{
std::vector<const SDL_Event> events;
SDL_Event e;
bool localRunning = true;
bool& running = pTerminator ? *pTerminator : localRunning;
Uint64 t0 = SDL_GetPerformanceCounter();
while (!stack.empty() && running == true)
{
while (SDL_PollEvent(&e) != 0)
{
if (e.type == SDL_QUIT)
{
running = false;
}
events.push_back(e);
}
Uint64 now = SDL_GetPerformanceCounter();
float dt = (float)(now - t0) / SDL_GetPerformanceFrequency();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
tickStack(stack, events, dt);
events.clear();
SDL_GL_SwapWindow(&window);
t0 = now;
}
}
示例10: SDL_GetPerformanceCounter
// ------------------------------------------------------------------------------------------------
// Timer Class
// ------------------------------------------------------------------------------------------------
cTimer::cTimer(const cTimer::timerState_t tState) {
state = tState;
dt = 0.0;
now = SDL_GetPerformanceCounter();
prev = now;
cpuFreq = SDL_GetPerformanceFrequency();
}
示例11: SDL_GetPerformanceCounter
void SimKit::FPSTimeline::log_frame_end() {
this->frame_end = SDL_GetPerformanceCounter();
this->frame_recorded = true;
this->past_frames[this->past_frames_ctr % SimKit::FPSTimeline::NUM_PAST_FRAMES] =
((float)(this->frame_end - this->frame_begin) / (float)SDL_GetPerformanceFrequency()) * MICROSECONDS_PER_SECOND;
this->past_frames_ctr++;
};
示例12: SDL_GetPerformanceCounter
void GameTimer::Start( )
{
m_Started = true;
m_Paused = false;
m_StartTicks = SDL_GetPerformanceCounter( );
m_LastCheckedTicks = SDL_GetPerformanceCounter( );
m_TicksPerSec = SDL_GetPerformanceFrequency( );
}
示例13: CPUTimer
CPUTimer(int iter)
: iter(iter),
acc(0),
counter(0),
ticks(0)
{
perfFreq = SDL_GetPerformanceFrequency();
}
示例14: SDL_GetPerformanceFrequency
float FrameCounter::GetAverageFPS() const
{
uint64_t total = 0;
for ( unsigned int i = 0; i < m_nrOfFrames; ++i )
{
total += m_frameTimes[i];
}
return SDL_GetPerformanceFrequency() * m_nrOfFrames / ( total * 1.0f );
}
示例15: TimeCounterGetMsec
uint32_t TimeCounterGetMsec()
{
uint64_t perfCounter = SDL_GetPerformanceCounter();
uint64_t perfFreq = SDL_GetPerformanceFrequency();
uint32_t msec = ( uint32_t )( 1000000 * perfCounter / perfFreq );
return msec;
}