FPS Mode (gamer moment)

This commit is contained in:
Ben Kyd
2022-10-25 23:43:11 +01:00
parent 670a2b3ca5
commit e22d070b16
8 changed files with 51 additions and 38 deletions

View File

@@ -5,7 +5,7 @@ namespace inferno {
enum ACCEL_TYPE
{
RAY_TRI_ONLY,
ACCEL_TYPE_RAY_TRI_ONLY,
};
class Accelerator

View File

@@ -42,7 +42,4 @@ private:
};
}

View File

@@ -4,7 +4,6 @@
#include "gui/layout.hpp"
#include "window.hpp"
#include <graphics.hpp>
#include <spdlog/spdlog.h>
#include <iostream>
@@ -13,7 +12,7 @@
namespace inferno {
Inferno::Inferno(int argc, char** argv)
Inferno::Inferno()
{
// MOTD
spdlog::info("INFERNO HART v" INFERNO_VERSION);
@@ -48,9 +47,12 @@ int Inferno::run()
{
mWin->setKeyCallback(&handleKbd);
mWin->setMouseCallback(&handlePtr);
mWin->setFPSMode();
while (true) {
if (!mWin->newFrame()) { break; }
// UI
ImGuiID dockspace_id = ImGui::GetID("main");
// set the main window to the dockspace and then on the first launch set the preset
@@ -58,28 +60,10 @@ int Inferno::run()
if (ImGui::DockBuilderGetNode(dockspace_id) == NULL) { this->uiPreset(); }
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
// Menu Bar
// if (ImGui::BeginMenuBar())
// {
// if (ImGui::BeginMenu("Menu"))
// {
// if (ImGui::MenuItem("New")) {}
// if (ImGui::MenuItem("Open", "Ctrl+O")) {}
// if (ImGui::BeginMenu("Open Recent"))
// {
// ImGui::EndMenu();
// }
// if (ImGui::MenuItem("Save", "Ctrl+S")) {}
// if (ImGui::MenuItem("Save As..")) {}
// KBD & MOUSE
std::cout << mouseDelta.x << " " << mouseDelta.y << std::endl;
// ImGui::Separator();
// if (ImGui::BeginMenu("Options"))
// {
// ImGui::EndMenu();
// }
// }
// ImGui::EndMenuBar();
// }
ImGui::Begin("Preview");
ImGui::End();
@@ -119,7 +103,13 @@ void handleKbd(int key, int scan, int action, int mod)
void handlePtr(double x, double y)
{
int iX = floor(x);
int iY = floor(x);
static int oX, oY;
glm::vec2 mouseDelta = { iX - oX, iY - oY };
Inferno::GetInstance().mouseDelta = mouseDelta;
oX = iX;
oY = iY;
}
}

View File

@@ -1,27 +1,30 @@
#pragma once
#include "graphics.hpp"
#include <singleton.hpp>
namespace inferno {
class Window;
class GLFWwindow;
class RasterizeRenderer;
class Scene;
class Inferno
class Inferno : public helpers::Singleton<Inferno>
{
public:
Inferno(int argc, char** argv);
Inferno();
~Inferno();
void uiPreset();
int run();
public:
glm::vec2 mouseDelta;
glm::vec3 kbdDelta;
private:
double mLastMouseX, mLastMouseY;
friend void handleKbd(int key, int scan, int action, int mod);
friend void handlePtr(double x, double y);

View File

@@ -7,8 +7,7 @@ int main(int argc, char** argv)
{
try
{
inferno::Inferno inferno(argc, argv);
return inferno.run();
return inferno::Inferno::GetInstance().run();
}
catch (std::exception e)
{

View File

@@ -1,2 +1,3 @@
#pragma once
#define INFERNO_VERSION "3.0.1_alpha"
#define INFERNO_VERSION "3.0.1_alpha"

View File

@@ -55,6 +55,12 @@ void Window::getPos(int& x, int& y)
glfwGetWindowPos(window, &x, &y);
}
void Window::setFPSMode()
{
mWinMode = WIN_MODE_FPS;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
}
void Window::setKeyCallback(KeyCallback callback)
{
mKeyCallback = callback;
@@ -98,6 +104,12 @@ bool Window::newFrame()
void Window::render()
{
if (mWinMode == WIN_MODE_FPS)
{
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwSetCursorPos(window, (double)width / 2, (double)height / 2);
}
ImGui::End();
ImGui::Render();
auto io = ImGui::GetIO();

View File

@@ -12,6 +12,12 @@ namespace inferno {
typedef void (*KeyCallback)(int key, int scan, int action, int mod);
typedef void (*MouseCallback)(double x, double y);
enum WINDOW_MODE
{
WIN_MODE_DEFAULT,
WIN_MODE_FPS,
};
class Window : public helpers::Singleton<Window>
{
public:
@@ -31,11 +37,16 @@ public:
void getPos(int& x, int& y);
GLFWwindow* getGLFWWindow() { return window; }
void setFPSMode();
void setKeyCallback(KeyCallback callback);
void setMouseCallback(MouseCallback callback);
KeyCallback getKeyCallback();
MouseCallback getMouseCallback();
private:
WINDOW_MODE mWinMode = WIN_MODE_DEFAULT;
private:
void setupGLFW(std::string title);
void setupImGui();
@@ -47,12 +58,12 @@ private:
KeyCallback mKeyCallback = nullptr;
MouseCallback mMouseCallback = nullptr;
private:
static void glfwErrorCallback(int error, const char* description);
int width, height;
const char* glslVersion;
GLFWwindow* window;
};
}
}