Skip to content

Commit

Permalink
improve:adjust xr begin/end render frame call's position (cocos#16021)
Browse files Browse the repository at this point in the history
(Calculate the correct delta time)
  • Loading branch information
oahc09 authored Aug 18, 2023
1 parent 92c37fc commit 56417f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions native/cocos/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ void Engine::destroy() {

int32_t Engine::run() {
BasePlatform *platform = BasePlatform::getPlatform();
_xr = CC_GET_XR_INTERFACE();
platform->runInPlatformThread([&]() {
tick();
});
Expand Down Expand Up @@ -284,15 +285,15 @@ void Engine::tick() {
#endif

prevTime = std::chrono::steady_clock::now();

if (_xr) _xr->beginRenderFrame();
_scheduler->update(dt);

se::ScriptEngine::getInstance()->handlePromiseExceptions();
events::Tick::broadcast(dt);
se::ScriptEngine::getInstance()->mainLoopUpdate();

cc::DeferredReleasePool::clear();

if (_xr) _xr->endRenderFrame();
now = std::chrono::steady_clock::now();
dtNS = dtNS * 0.1 + 0.9 * static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(now - prevTime).count());
dt = static_cast<float>(dtNS) / NANOSECONDS_PER_SECOND;
Expand Down
3 changes: 3 additions & 0 deletions native/cocos/engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DebugRenderer;
class Profiler;
class BuiltinResMgr;
class ProgramLib;
class IXRInterface;

#define NANOSECONDS_PER_SECOND 1000000000
#define NANOSECONDS_60FPS 16666667L
Expand Down Expand Up @@ -132,6 +133,8 @@ class CC_DLL Engine : public BaseEngine {
events::WindowEvent::Listener _windowEventListener;

CC_DISALLOW_COPY_MOVE_ASSIGN(Engine);

IXRInterface *_xr{nullptr};
};

} // namespace cc
2 changes: 0 additions & 2 deletions native/cocos/platform/android/AndroidPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,7 @@ int32_t AndroidPlatform::loop() {
if (xr && !xr->platformLoopStart()) continue;
_inputProxy->handleInput();
if (_inputProxy->isAnimating() && (xr ? xr->getXRConfig(xr::XRConfigKey::SESSION_RUNNING).getBool() : true)) {
if (xr) xr->beginRenderFrame();
runTask();
if (xr) xr->endRenderFrame();
if (_inputProxy->isActive()) {
flushTasksOnGameThreadAtForegroundJNI();
}
Expand Down

0 comments on commit 56417f3

Please sign in to comment.