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:
parent
5ffdc17d79
commit
dc24036efb
@ -105,7 +105,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
|
|||||||
|
|
||||||
const auto raster_info = vk::PipelineRasterizationStateCreateInfo {
|
const auto raster_info = vk::PipelineRasterizationStateCreateInfo {
|
||||||
.depthClampEnable = vk::False,
|
.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,
|
.cullMode = type == eBOX ? vk::CullModeFlagBits::eNone : vk::CullModeFlagBits::eBack,
|
||||||
.frontFace = vk::FrontFace::eCounterClockwise,
|
.frontFace = vk::FrontFace::eCounterClockwise,
|
||||||
.depthBiasEnable = type == eBOX,
|
.depthBiasEnable = type == eBOX,
|
||||||
|
|||||||
@ -355,9 +355,11 @@ void Renderer::draw() {
|
|||||||
|
|
||||||
n_indices = bsp->indices.size();
|
n_indices = bsp->indices.size();
|
||||||
|
|
||||||
command_buffer->bind(*box_pipeline);
|
if (show_bboxes) {
|
||||||
command_buffer->bind(*box_buffer);
|
command_buffer->bind(*box_pipeline);
|
||||||
command_buffer->draw(box_buffer->buffer->size / sizeof(BoxVertex), 1);
|
command_buffer->bind(*box_buffer);
|
||||||
|
command_buffer->draw(box_buffer->buffer->size / sizeof(BoxVertex), 1);
|
||||||
|
}
|
||||||
|
|
||||||
/* draw User Interface stuff */
|
/* draw User Interface stuff */
|
||||||
ui->newFrame();
|
ui->newFrame();
|
||||||
@ -407,7 +409,7 @@ void Renderer::present() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
frame++;
|
frame++;
|
||||||
time += 0.0167f * speed * static_cast<float>(!paused);
|
time += frametime / 1000.0 * speed * static_cast<float>(!paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer() {
|
Renderer::~Renderer() {
|
||||||
|
|||||||
@ -75,6 +75,8 @@ struct Renderer {
|
|||||||
float speed = 1.0;
|
float speed = 1.0;
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
bool visibility_testing = false;
|
bool visibility_testing = false;
|
||||||
|
bool show_bboxes = false;
|
||||||
|
bool should_close = false;
|
||||||
|
|
||||||
size_t n_indices;
|
size_t n_indices;
|
||||||
|
|
||||||
@ -83,4 +85,7 @@ struct Renderer {
|
|||||||
|
|
||||||
float tess_factor = 1.8f;
|
float tess_factor = 1.8f;
|
||||||
float tess_edge_size = 20.0f;
|
float tess_edge_size = 20.0f;
|
||||||
|
|
||||||
|
float frametime = 0.0;
|
||||||
|
float max_fps = 120.0;
|
||||||
};
|
};
|
||||||
|
|||||||
25
UI/UI.cpp
25
UI/UI.cpp
@ -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().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]() {
|
console->System().RegisterCommand("quit", "Quits the engine", [this]() {
|
||||||
this->ren->visibility_testing = !this->ren->visibility_testing;
|
this->ren->should_close = true;
|
||||||
console->System().Log(csys::ItemType::eINFO) << "Visibility Testing: " << (this->ren->visibility_testing? "Enabled" : "Disabled") << csys::endl;
|
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;
|
console->System().Log(csys::ItemType::eINFO) << "Welcome to Pleascach!" << csys::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +136,7 @@ void UI::newFrame() {
|
|||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
ImGui::SetNextWindowBgAlpha(0.5f);
|
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("# of Indices: %zu", ren->n_indices);
|
||||||
ImGui::Text("FPS: %f", ren->fps);
|
ImGui::Text("FPS: %f", ren->fps);
|
||||||
|
|||||||
@ -20,8 +20,11 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
auto in = win.getInput();
|
auto in = win.getInput();
|
||||||
Renderer ren(win);
|
Renderer ren(win);
|
||||||
|
in->setCursor(false);
|
||||||
|
|
||||||
while (!in->shouldClose()) {
|
bool should_close = false;
|
||||||
|
|
||||||
|
while (!in->shouldClose() || ren.should_close) {
|
||||||
Timer frame_timer;
|
Timer frame_timer;
|
||||||
in->poll();
|
in->poll();
|
||||||
in->handleMovementKeys(ren);
|
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) {
|
if (event.key.key == GLFW_KEY_ESCAPE && event.key.state == GLFW_PRESS) {
|
||||||
ren.in_menu = !ren.in_menu;
|
ren.in_menu = !ren.in_menu;
|
||||||
in->setCursor(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;
|
||||||
if (ren.in_menu)
|
goto quit;
|
||||||
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;
|
break;
|
||||||
}
|
}
|
||||||
@ -82,14 +74,19 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
ren.draw();
|
ren.draw();
|
||||||
ren.present();
|
ren.present();
|
||||||
const auto t = frame_timer.read();
|
ren.frametime = frame_timer.read();
|
||||||
ren.fps = 1000.0f / t;
|
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) {
|
} catch (const std::string& e) {
|
||||||
std::cerr << "Exception: " << e << std::endl;
|
std::cerr << "Exception: " << e << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quit:
|
||||||
|
Log::info("Quitting");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user