update client visuals, performance and diagnostics
This commit is contained in:
1 parent
361892bf0b
commit
875bab0310
155 files changed
+40855
-421
No files matched your search
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
#include "../src/window_branding.h"
|
||||
#include <future>
|
||||
|
||||
inline LRESULT CALLBACK branding_test_proc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) {
|
||||
if(window_branding::handle_message(hwnd,msg,wp,lp))return 0;
|
||||
return DefWindowProcW(hwnd,msg,wp,lp);
|
||||
}
|
||||
inline void pump_branding_messages() {
|
||||
MSG message{};
|
||||
while(PeekMessageW(&message,nullptr,0,0,PM_REMOVE))DispatchMessageW(&message);
|
||||
}
|
||||
|
||||
inline void test_window_branding() {
|
||||
PACKAGE_VERSION version{};version.Major=1;version.Minor=26;version.Build=5203;
|
||||
assert(window_branding::display_version(version)==L"26.52");
|
||||
version.Minor=21;version.Build=11401;
|
||||
assert(window_branding::display_version(version)==L"1.21.114");
|
||||
const auto module=GetModuleHandleW(nullptr);
|
||||
WNDCLASSW wc{};wc.hInstance=module;wc.lpfnWndProc=branding_test_proc;wc.lpszClassName=L"AmnesiaBrandingTest";
|
||||
assert(RegisterClassW(&wc));
|
||||
HWND hwnd=CreateWindowExW(0,wc.lpszClassName,L"Original Minecraft title",WS_OVERLAPPEDWINDOW,
|
||||
0,0,300,200,nullptr,nullptr,module,nullptr);
|
||||
assert(hwnd);
|
||||
auto original_small=LoadIcon(nullptr,IDI_WARNING),original_large=LoadIcon(nullptr,IDI_ERROR);
|
||||
SendMessageW(hwnd,WM_SETICON,ICON_SMALL,reinterpret_cast<LPARAM>(original_small));
|
||||
SendMessageW(hwnd,WM_SETICON,ICON_BIG,reinterpret_cast<LPARAM>(original_large));
|
||||
for(int i=0;i<2;++i) {
|
||||
// Simulate Present running while the UI thread cannot pump messages.
|
||||
// Scheduling must finish without waiting for any UI response.
|
||||
auto render=std::async(std::launch::async,[=] {
|
||||
window_branding::install(hwnd,module);
|
||||
window_branding::next_check=0;window_branding::tick();
|
||||
});
|
||||
assert(render.wait_for(std::chrono::milliseconds(500))==std::future_status::ready);
|
||||
render.get();assert(!window_branding::window);
|
||||
pump_branding_messages();
|
||||
assert(window_branding::icon_small && window_branding::icon_large);
|
||||
assert(window_branding::window_title(hwnd).find(L"amnesia // minecraft")==0);
|
||||
assert(reinterpret_cast<HICON>(SendMessageW(hwnd,WM_GETICON,ICON_SMALL,0))==window_branding::icon_small);
|
||||
SetWindowTextW(hwnd,L"Game changed title");
|
||||
SendMessageW(hwnd,WM_SETICON,ICON_BIG,0);
|
||||
window_branding::next_check=0;window_branding::tick();
|
||||
pump_branding_messages();
|
||||
assert(window_branding::window_title(hwnd)==window_branding::title);
|
||||
assert(reinterpret_cast<HICON>(SendMessageW(hwnd,WM_GETICON,ICON_BIG,0))==window_branding::icon_large);
|
||||
auto unload=std::async(std::launch::async,[] {window_branding::shutdown();});
|
||||
const auto deadline=GetTickCount64()+2000;
|
||||
while(unload.wait_for(std::chrono::milliseconds(0))!=std::future_status::ready && GetTickCount64()<deadline) {
|
||||
pump_branding_messages();Sleep(1);
|
||||
}
|
||||
assert(unload.wait_for(std::chrono::milliseconds(0))==std::future_status::ready);unload.get();
|
||||
assert(window_branding::window_title(hwnd)==L"Original Minecraft title");
|
||||
assert(reinterpret_cast<HICON>(SendMessageW(hwnd,WM_GETICON,ICON_SMALL,0))==original_small);
|
||||
assert(reinterpret_cast<HICON>(SendMessageW(hwnd,WM_GETICON,ICON_BIG,0))==original_large);
|
||||
assert(!window_branding::window && !window_branding::icon_small && !window_branding::icon_large);
|
||||
}
|
||||
// An unload before the first posted update must not brand the window later.
|
||||
window_branding::install(hwnd,module);window_branding::shutdown();pump_branding_messages();
|
||||
assert(window_branding::window_title(hwnd)==L"Original Minecraft title" && !window_branding::window);
|
||||
DestroyWindow(hwnd);window_branding::shutdown();UnregisterClassW(wc.lpszClassName,module);
|
||||
std::cout<<"PASS: asynchronous window branding without a pumping UI thread, embedded icons and unload restoration\n";
|
||||
}
|
||||
Reference in new issue
Block a user