MCPcopy Create free account
hub / github.com/crownengine/crown / frame

Method frame

src/device/device.cpp:466–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

464}
465
466bool Device::frame()
467{
468 if (CE_UNLIKELY(process_events() || _quit != 0))
469 return true;
470
471 if (CE_UNLIKELY(_paused == 0 && _last_paused == 1)) {
472 _last_paused = 0;
473 logi(DEVICE, "Resumed");
474 } else if (CE_UNLIKELY(_paused == 1 && _last_paused == 0)) {
475 _last_paused = 1;
476 logi(DEVICE, "Paused");
477
478 // Having the cursor hidden while the game is paused
479 // is confusing and should be avoided.
480 if (_window)
481 _window->set_cursor_mode(CursorMode::NORMAL);
482 }
483
484 if (CE_UNLIKELY(_width != _prev_width || _height != _prev_height)) {
485 _prev_width = _width;
486 _prev_height = _height;
487 bgfx::reset(_width, _height, (_boot_config.vsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE));
488 _pipeline->reset(_width, _height);
489
490 // Force pipeline reset in one cycle.
491 bgfx::frame();
492 bgfx::frame();
493
494 // Force redraw.
495 ++_needs_draw;
496 }
497
498 // Only block if redraw is not needed.
499 const bool sync = !_needs_draw;
500#if !CROWN_PLATFORM_EMSCRIPTEN
501 _console_server->execute_message_handlers(sync);
502#endif
503
504 if (CE_UNLIKELY(!_needs_draw))
505 return false;
506
507 const s64 time = time::now();
508 const s64 raw_dt_ticks = time - _last_time;
509 const f32 raw_dt = f32(time::seconds(raw_dt_ticks));
510 _last_time = time;
511
512 profiler_globals::clear();
513 RECORD_FLOAT("device.dt", raw_dt);
514 RECORD_FLOAT("device.fps", 1.0f/raw_dt);
515
516 f32 dt;
517 if (_timestep_policy == TimestepPolicy::SMOOTHED) {
518 f32 smoothed_dt = _delta_time_filter.filter(raw_dt_ticks);
519 RECORD_FLOAT("device.smoothed_dt", smoothed_dt);
520 RECORD_FLOAT("device.smoothed_fps", 1.0f/smoothed_dt);
521 dt = smoothed_dt;
522 } else {
523 dt = raw_dt;

Callers 1

main_loopMethod · 0.45

Calls 15

frameFunction · 0.85
nowFunction · 0.85
secondsFunction · 0.85
getStatsFunction · 0.85
flushFunction · 0.85
draw_allFunction · 0.85
filterMethod · 0.80
complete_requestsMethod · 0.80
call_globalMethod · 0.80
reset_temporariesMethod · 0.80
resetFunction · 0.50

Tested by

no test coverage detected