Shifted to console variables instead of commands, added frametime to allow for movement calculations later, and an adjustable fps cap

This commit is contained in:
connellpaxton 2024-02-21 14:00:13 -05:00
parent 5ffdc17d79
commit dc24036efb
5 changed files with 52 additions and 31 deletions

View File

@ -105,7 +105,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
const auto raster_info = vk::PipelineRasterizationStateCreateInfo {
.depthClampEnable = vk::False,
.polygonMode = vk::PolygonMode::eFill,
.polygonMode = type == eBOX ? vk::PolygonMode::eLine : vk::PolygonMode::eFill,
.cullMode = type == eBOX ? vk::CullModeFlagBits::eNone : vk::CullModeFlagBits::eBack,
.frontFace = vk::FrontFace::eCounterClockwise,
.depthBiasEnable = type == eBOX,

View File

@ -355,9 +355,11 @@ void Renderer::draw() {
n_indices = bsp->indices.size();
if (show_bboxes) {
command_buffer->bind(*box_pipeline);
command_buffer->bind(*box_buffer);
command_buffer->draw(box_buffer->buffer->size / sizeof(BoxVertex), 1);
}
/* draw User Interface stuff */
ui->newFrame();
@ -407,7 +409,7 @@ void Renderer::present() {
}
frame++;
time += 0.0167f * speed * static_cast<float>(!paused);
time += frametime / 1000.0 * speed * static_cast<float>(!paused);
}
Renderer::~Renderer() {

View File

@ -75,6 +75,8 @@ struct Renderer {
float speed = 1.0;
bool paused = false;
bool visibility_testing = false;
bool show_bboxes = false;
bool should_close = false;
size_t n_indices;
@ -83,4 +85,7 @@ struct Renderer {
float tess_factor = 1.8f;
float tess_edge_size = 20.0f;
float frametime = 0.0;
float max_fps = 120.0;
};

View File

@ -105,11 +105,28 @@ UI::UI(Renderer* ren) : ren(ren), dev(ren->dev) {
console->System().Log(csys::ItemType::eINFO) << "Paused: " << (this->ren->paused? "True" : "False") << csys::endl;
});
console->System().RegisterCommand("toggle-visibility-testing", "Toggles visibility testings (using clusters and frustum culling)", [this]() {
this->ren->visibility_testing = !this->ren->visibility_testing;
console->System().Log(csys::ItemType::eINFO) << "Visibility Testing: " << (this->ren->visibility_testing? "Enabled" : "Disabled") << csys::endl;
console->System().RegisterCommand("quit", "Quits the engine", [this]() {
this->ren->should_close = true;
console->System().Log(csys::ItemType::eINFO) << "Quitting..." << csys::endl;
});
console->System().RegisterCommand("list-vars", "List variables accessible from developer console", [this]() {
const std::vector<std::string> names = {
"show_bboxes",
"visibility_testing",
"speed",
"flycam",
};
for(const auto& name : names)
console->System().Log(csys::ItemType::eINFO) << name << csys::endl;
});
console->System().RegisterVariable("show_bboxes", ren->show_bboxes, csys::Arg<bool>("value"));
console->System().RegisterVariable("visibility_testing", ren->visibility_testing, csys::Arg<bool>("value"));
console->System().RegisterVariable("speed", ren->speed, csys::Arg<float>("value"));
console->System().RegisterVariable("flycam", ren->flycam, csys::Arg<bool>("value"));
console->System().Log(csys::ItemType::eINFO) << "Welcome to Pleascach!" << csys::endl;
}
@ -119,7 +136,7 @@ void UI::newFrame() {
ImGui::NewFrame();
ImGui::SetNextWindowBgAlpha(0.5f);
ImGui::Begin("Rendering Info", nullptr);
ImGui::Begin("Rendering Info", nullptr, ImGuiWindowFlags_::ImGuiWindowFlags_NoFocusOnAppearing);
ImGui::Text("# of Indices: %zu", ren->n_indices);
ImGui::Text("FPS: %f", ren->fps);

View File

@ -20,8 +20,11 @@ int main(int argc, char* argv[]) {
auto in = win.getInput();
Renderer ren(win);
in->setCursor(false);
while (!in->shouldClose()) {
bool should_close = false;
while (!in->shouldClose() || ren.should_close) {
Timer frame_timer;
in->poll();
in->handleMovementKeys(ren);
@ -59,22 +62,11 @@ int main(int argc, char* argv[]) {
if (event.key.key == GLFW_KEY_ESCAPE && event.key.state == GLFW_PRESS) {
ren.in_menu = !ren.in_menu;
in->setCursor(ren.in_menu);
break;
} else if (event.key.key == GLFW_KEY_Q && event.key.state == GLFW_PRESS) {
if (!ren.in_menu) {
ren.should_close = true;
goto quit;
}
if (ren.in_menu)
break;
if (event.key.key == GLFW_KEY_Q) {
return 0;
} else if (event.key.key == GLFW_KEY_R && event.key.state == GLFW_PRESS) {
ren.time = 0;
} else if (event.key.key == GLFW_KEY_C && event.key.state == GLFW_PRESS) {
ren.flycam = !ren.flycam;
} else if (event.key.key == GLFW_KEY_T && event.key.state == GLFW_PRESS) {
ren.speed *= 10.0;
} else if (event.key.key == GLFW_KEY_Y && event.key.state == GLFW_PRESS) {
ren.speed /= 10.0;
}
break;
}
@ -82,14 +74,19 @@ int main(int argc, char* argv[]) {
ren.draw();
ren.present();
const auto t = frame_timer.read();
ren.fps = 1000.0f / t;
ren.frametime = frame_timer.read();
ren.fps = 1000.0f / ren.frametime;
while (frame_timer.read() < 16.60)
while (frame_timer.read() < 1000 / ren.max_fps)
;
ren.frametime = frame_timer.read();
}
} catch (const std::string& e) {
std::cerr << "Exception: " << e << std::endl;
}
quit:
Log::info("Quitting");
}