本文整理汇总了C++中SDL_GetPerformanceCounter函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetPerformanceCounter函数的具体用法?C++ SDL_GetPerformanceCounter怎么用?C++ SDL_GetPerformanceCounter使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_GetPerformanceCounter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: 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
}
}
示例3: 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
}
示例4: 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();
}
}
}
示例5: SDL_GetPerformanceCounter
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);
}
示例6: delay
void delay()
{
if (disabled)
return;
int64_t tickDelta = SDL_GetPerformanceCounter() - lastTickCount;
int64_t toDelay = tpf - tickDelta;
/* Compensate for the last delta
* to the ideal timestep */
toDelay -= adj.idealDiff;
if (toDelay < 0)
toDelay = 0;
delayTicks(toDelay);
uint64_t now = lastTickCount = SDL_GetPerformanceCounter();
int64_t diff = now - adj.last;
adj.last = now;
/* Recalculate our temporal position
* relative to the ideal timestep */
adj.idealDiff = diff - tpf + adj.idealDiff;
if (adj.resetFlag)
{
adj.idealDiff = 0;
adj.resetFlag = false;
}
}
示例7: Sys_Microseconds
uint64_t Sys_Microseconds( void )
{
static Uint64 base = 0;
if( !base )
base = SDL_GetPerformanceCounter();
return 1000000ULL * ( SDL_GetPerformanceCounter() - base ) / freq;
}
示例8: SDL_GetPerformanceCounter
void GameTimer::Start( )
{
m_Started = true;
m_Paused = false;
m_StartTicks = SDL_GetPerformanceCounter( );
m_LastCheckedTicks = SDL_GetPerformanceCounter( );
m_TicksPerSec = SDL_GetPerformanceFrequency( );
}
示例9: SDL_GetPerformanceCounter
void FrameCounter::TickFrame()
{
m_frameTimes[m_overwritePos] = SDL_GetPerformanceCounter() - m_startTime;
m_maxFrameTime = std::max( m_frameTimes[m_overwritePos], m_maxFrameTime );
m_nrOfFrames++;
m_nrOfFrames = std::min( m_nrOfFrames, FRAMECOUNTER_NR_OF_SAMPLES );
m_overwritePos = ( m_overwritePos + 1 ) % FRAMECOUNTER_NR_OF_SAMPLES;
m_startTime = SDL_GetPerformanceCounter();
}
示例10: FPSLimiter
FPSLimiter(uint16_t desiredFPS)
: lastTickCount(SDL_GetPerformanceCounter()),
tickFreq(SDL_GetPerformanceFrequency()),
tickFreqMS(tickFreq / 1000),
tickFreqNS((double) tickFreq / NS_PER_S),
disabled(false)
{
setDesiredFPS(desiredFPS);
adj.last = SDL_GetPerformanceCounter();
adj.idealDiff = 0;
adj.resetFlag = false;
}
示例11: 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();
}
示例12: 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;
}
示例13: updateDeltaTime
double
updateDeltaTime()
{
Uint64 curTime;
double deltaTime;
if (prevTime == 0) {
prevTime = SDL_GetPerformanceCounter();
}
curTime = SDL_GetPerformanceCounter();
deltaTime = (double) (curTime - prevTime) / (double) SDL_GetPerformanceFrequency();
prevTime = curTime;
return deltaTime;
}
示例14: 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;
}
示例15: main
int main(int _argc, char *_argv[])
{
try
{
bool quit = false;
SDLState sdl;
DispatchStack &dispatch = DispatchStack::get();
Game game;
Update update;
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
update.ticksLast = SDL_GetPerformanceCounter();
update.tickFrequency = SDL_GetPerformanceFrequency(); // Should really refresh this.
while(!quit)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(!dispatch.handleEvent(event)
&& (event.type == SDL_QUIT))
quit = true;
}
update.ticksNow = SDL_GetPerformanceCounter();
update.dt = float((update.ticksNow - update.ticksLast) / double(update.tickFrequency));
dispatch.update(update);
update.ticksLast = update.ticksNow;
dispatch.handleIdle();
SDL_Delay(0);
}
}
catch(std::exception tExc)
{
std::cerr << "An exception occurred: " << tExc.what() << std::endl;
return -1;
}
catch(...)
{
std::cerr << "An unknown exception occurred." << std::endl;
return -2;
}
}