78 lines
3.8 KiB
C++
78 lines
3.8 KiB
C++
#pragma once
|
|
#include "../src/gui/startup_intro.h"
|
|
|
|
inline void test_startup_intro() {
|
|
using startup_intro::stage;
|
|
float progress=startup_intro::completion(stage::hooks,0,0);
|
|
for(unsigned i=0;i<=36;++i) {
|
|
const float next=startup_intro::completion(stage::modules,i,36);
|
|
assert(next>=progress && next<1);progress=next;
|
|
}
|
|
for(auto phase:{stage::input,stage::profile,stage::hud,stage::ready}) {
|
|
const float next=startup_intro::completion(phase,36,36);
|
|
assert(next>=progress && next<=1);progress=next;
|
|
}
|
|
assert(progress==1 && startup_intro::completion(stage::modules,100,36)==.75f);
|
|
assert(startup_intro::completion(stage::modules,0,0)==.35f);
|
|
|
|
using startup_intro::playback;
|
|
playback clock;
|
|
assert(clock.step(0,false)==0); // No startup delay.
|
|
for(int i=1;i<=600;++i) {
|
|
const auto age=clock.step(i/60.0,false);
|
|
assert(age>=0 && age<=startup_intro::hold_age && !clock.finished);
|
|
}
|
|
assert(clock.age==startup_intro::hold_age);
|
|
double now=10;
|
|
assert(clock.step(now+=.1,true)>startup_intro::hold_age);
|
|
for(int i=0;i<200;++i)clock.step(now+=1.0/60,true);
|
|
assert(clock.finished && clock.step(now+1,true)<0);
|
|
|
|
playback startup_stall;
|
|
startup_stall.step(0,true);
|
|
const float before=startup_stall.step(.1,true);
|
|
assert(startup_stall.step(8,true)<before+.02f); // Stall doesn't skip animation.
|
|
playback skipped;
|
|
assert(skipped.step(0,false,true)==startup_intro::hold_age && !skipped.finished);
|
|
assert(skipped.step(20,false,true)==startup_intro::hold_age && !skipped.finished);
|
|
now=20;
|
|
for(int i=0;i<100;++i)skipped.step(now+=1.0/60,true,true);
|
|
assert(skipped.finished); // Skip cannot bypass the readiness gate.
|
|
|
|
ImGui::CreateContext();auto& io=ImGui::GetIO();
|
|
io.DisplaySize={1280,720};io.DeltaTime=.016f;
|
|
io.Fonts->AddFontDefault();unsigned char* pixels;int width,height;
|
|
io.Fonts->GetTexDataAsRGBA32(&pixels,&width,&height);
|
|
Microsoft::WRL::ComPtr<ID3D11Device> device;
|
|
assert(SUCCEEDED(D3D11CreateDevice(nullptr,D3D_DRIVER_TYPE_WARP,nullptr,0,nullptr,0,
|
|
D3D11_SDK_VERSION,&device,nullptr,nullptr)));
|
|
startup_intro::initialize_texture(device.Get());assert(startup_intro::texture);
|
|
for(ImVec2 screen : {ImVec2{320,240},ImVec2{1280,720},ImVec2{3440,1440}}) {
|
|
io.DisplaySize=screen;
|
|
for(float age : {-1.f,0.f,.15f,.5f,1.25f,2.3f,2.7f,2.8f,5.f}) {
|
|
ImGui::NewFrame();startup_intro::render(age,screen,.5f,"loading modules",age);ImGui::Render();
|
|
auto* data=ImGui::GetDrawData();
|
|
if(age<0 || age>=startup_intro::duration)assert(data->TotalVtxCount==0);
|
|
else assert(data->TotalVtxCount>0);
|
|
if(age==0) {
|
|
// The first frame already covers gameplay with opaque pixels.
|
|
const auto* list=data->CmdLists[0];
|
|
for(int i=0;i<4;++i)assert((list->VtxBuffer[i].col>>IM_COL32_A_SHIFT)==255);
|
|
}
|
|
assert(data->TotalVtxCount<8000);
|
|
for(int i=0;i<data->CmdListsCount;++i)
|
|
for(const auto& vertex:data->CmdLists[i]->VtxBuffer)
|
|
assert(std::isfinite(vertex.pos.x) && std::isfinite(vertex.pos.y));
|
|
}
|
|
}
|
|
ImVec2 texture_position[2];
|
|
for(int i=0;i<2;++i) {
|
|
ImGui::NewFrame();startup_intro::render(startup_intro::hold_age,io.DisplaySize,.5f,"loading modules",double(i));ImGui::Render();
|
|
texture_position[i]=ImGui::GetDrawData()->CmdLists[0]->VtxBuffer[4].pos;
|
|
}
|
|
assert(texture_position[0].x!=texture_position[1].x || texture_position[0].y!=texture_position[1].y);
|
|
startup_intro::texture.Reset();
|
|
ImGui::DestroyContext();
|
|
std::cout<<"PASS: opaque readiness-gated intro, real loading-stage progress, GPU grain texture/motion and responsive geometry\n";
|
|
}
|