Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

vsync issue work-around #197

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions com.unity.uiwidgets/Runtime/Plugins/Android/libUIWidgets.so
Git LFS file not shown
4 changes: 2 additions & 2 deletions com.unity.uiwidgets/Runtime/Plugins/ios/libUIWidgets.a
Git LFS file not shown
4 changes: 2 additions & 2 deletions com.unity.uiwidgets/Runtime/Plugins/osx/libUIWidgets.dylib
Git LFS file not shown
19 changes: 6 additions & 13 deletions engine/src/shell/platform/unity/android/uiwidgets_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ void UIWidgetsSystem::UnregisterPanel(UIWidgetsPanel* panel) {
}

void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();

std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
next_uiwidgets_event_time_ - TimePoint::clock::now());

wait_duration = std::min(max_duration, wait_duration);

//TODO: find a proper api similar to MsgWaitForMultipleObjects on Windows
// which will notify os to wait for the given period of time
//TODO zxw: Rename this function to VSync, should be done after Engine side changes land
//Process VSync at the end of this frame
for (auto* uiwidgets_panel : uiwidgets_panels_) {
uiwidgets_panel->ProcessVSync();
}
}

void UIWidgetsSystem::Update() {
Expand All @@ -46,9 +41,7 @@ void UIWidgetsSystem::Update() {
}

void UIWidgetsSystem::VSync() {
for (auto* uiwidgets_panel : uiwidgets_panels_) {
uiwidgets_panel->ProcessVSync();
}
//TODO zxw: Remove this function, should be done after Engine side changes land
}

void UIWidgetsSystem::WakeUp() {}
Expand Down
25 changes: 9 additions & 16 deletions engine/src/shell/platform/unity/darwin/ios/uiwidgets_system.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
}

void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();

std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
next_uiwidgets_event_time_ - TimePoint::clock::now());

wait_duration = std::min(max_duration, wait_duration);

//TODO: find a proper api similar to MsgWaitForMultipleObjects on Windows
// which will notify os to wait for the given period of time
//TODO zxw: Rename this function to VSync, should be done after Engine side changes land
//Process VSync at the end of this frame
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}
}

void UIWidgetsSystem::Update() {
Expand All @@ -49,12 +47,7 @@
}

void UIWidgetsSystem::VSync() {
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}
//TODO zxw: Remove this function, should be done after Engine side changes land
}

void UIWidgetsSystem::WakeUp() {}
Expand Down
25 changes: 9 additions & 16 deletions engine/src/shell/platform/unity/darwin/macos/uiwidgets_system.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
}

void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();

std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
next_uiwidgets_event_time_ - TimePoint::clock::now());

wait_duration = std::min(max_duration, wait_duration);

//TODO: find a proper api similar to MsgWaitForMultipleObjects on Windows
// which will notify os to wait for the given period of time
//TODO zxw: Rename this function to VSync, should be done after Engine side changes land
//Process VSync at the end of this frame
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}
}

void UIWidgetsSystem::Update() {
Expand All @@ -49,12 +47,7 @@
}

void UIWidgetsSystem::VSync() {
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}
//TODO zxw: Remove this function, should be done after Engine side changes land
}

void UIWidgetsSystem::WakeUp() {}
Expand Down
21 changes: 13 additions & 8 deletions engine/src/shell/platform/unity/windows/uiwidgets_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ void UIWidgetsSystem::UnregisterPanel(UIWidgetsPanel* panel) {
}

void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {
Update();
//TODO zxw: Rename this function to VSync, should be done after Engine side changes land
//Process VSync at the end of this frame
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}

//TODO zxw: Move this function to a better place
/*Update();

std::chrono::nanoseconds wait_duration =
std::max(std::chrono::nanoseconds(0),
Expand All @@ -32,7 +42,7 @@ void UIWidgetsSystem::Wait(std::chrono::nanoseconds max_duration) {

::MsgWaitForMultipleObjects(0, nullptr, FALSE,
static_cast<DWORD>(wait_duration.count() / 1000000),
QS_ALLINPUT);
QS_ALLINPUT);*/
}

void UIWidgetsSystem::Update() {
Expand All @@ -51,12 +61,7 @@ void UIWidgetsSystem::Update() {
}

void UIWidgetsSystem::VSync() {
for (auto* uiwidgets_panel : uiwidgets_panels_) {
if (!uiwidgets_panel->NeedUpdateByPlayerLoop()) {
continue;
}
uiwidgets_panel->ProcessVSync();
}
//TODO zxw: Remove this function, should be done after Engine side changes land
}

void UIWidgetsSystem::WakeUp() {}
Expand Down