better imgui key handling

This commit is contained in:
Green Sky 2024-03-10 13:42:58 +01:00
parent 1dc4c850f4
commit b6ab400943
No known key found for this signature in database
2 changed files with 9 additions and 17 deletions

View File

@ -27,12 +27,6 @@ void my_doom_gettime(int* sec, int* usec) {
} }
} }
//static const char* doom_argv[] {
//"self.exe",
//"-timedemo",
//"",
//};
Doom::Doom( Doom::Doom(
TextureUploaderI& tu TextureUploaderI& tu
) : _tu(tu) { ) : _tu(tu) {
@ -56,8 +50,6 @@ Doom::Doom(
// does not actually work // does not actually work
doom_set_resolution(_width, _height); doom_set_resolution(_width, _height);
// HATE
//doom_init(2, const_cast<char**>(doom_argv), 0);
doom_init(0, nullptr, 0); doom_init(0, nullptr, 0);
std::vector<uint8_t> tmp_vec(4 * _width * _height, 0x00); // the api requires data for texture creation std::vector<uint8_t> tmp_vec(4 * _width * _height, 0x00); // the api requires data for texture creation
@ -75,9 +67,11 @@ float Doom::render(float time_delta) {
doom_update(); doom_update();
// TODO: use RGB instead?
const uint8_t* new_image = doom_get_framebuffer(4); const uint8_t* new_image = doom_get_framebuffer(4);
_tu.updateRGBA(_render_texture, new_image, 4 * _width * _height); _tu.updateRGBA(_render_texture, new_image, 4 * _width * _height);
// TODO: allow more?
return 1.f/60.f; return 1.f/60.f;
} }

View File

@ -93,15 +93,13 @@ float DoomIMGUI::render(float time_delta) {
if (ImGui::Begin("doom", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { if (ImGui::Begin("doom", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("scale", &_size_scaler, 1.f, 5.f); ImGui::SliderFloat("scale", &_size_scaler, 1.f, 5.f);
if (ImGui::IsWindowFocused()) { const bool window_focused = ImGui::IsWindowFocused();
for (const auto& [imkey, dokey] : g_all_keys) { for (const auto& [imkey, dokey] : g_all_keys) {
// TODO: unpress all keys on focus loss if (window_focused && ImGui::IsKeyPressed(imkey, false)) {
if (ImGui::IsKeyPressed(imkey, false)) { _doom.doomKeyDown(dokey);
_doom.doomKeyDown(dokey); }
} if (ImGui::IsKeyReleased(imkey)) {
if (ImGui::IsKeyReleased(imkey)) { _doom.doomKeyUp(dokey);
_doom.doomKeyUp(dokey);
}
} }
} }