Work on scene

This commit is contained in:
bailwillharr 2022-11-30 10:36:50 +00:00
parent dc2cb22eb8
commit 7788a86c2f
10 changed files with 288 additions and 263 deletions

View File

@ -10,7 +10,7 @@ project(engine LANGUAGES CXX
)
set(SRC_FILES
"src/engine.cpp"
"src/application.cpp"
"src/window.cpp"
"src/input_manager.cpp"
"src/scene_manager.cpp"
@ -24,7 +24,7 @@ set(SRC_FILES
set(INCLUDE_FILES
"include/engine_api.h"
"include/engine.hpp"
"include/application.hpp"
"include/util.hpp"
"include/log.hpp"
"include/logger.hpp"

View File

@ -5,7 +5,7 @@
namespace engine::inputs {
enum class Key : int {
UNKNOWN = 0,
K_UNKNOWN = 0,
/**
* \name Usage page 0x07
@ -14,55 +14,55 @@ enum class Key : int {
*/
/* @{ */
A = 4,
B = 5,
C = 6,
D = 7,
E = 8,
F = 9,
G = 10,
H = 11,
I = 12,
J = 13,
K = 14,
L = 15,
M = 16,
N = 17,
O = 18,
P = 19,
Q = 20,
R = 21,
S = 22,
T = 23,
U = 24,
V = 25,
W = 26,
X = 27,
Y = 28,
Z = 29,
K_A = 4,
K_B = 5,
K_C = 6,
K_D = 7,
K_E = 8,
K_F = 9,
K_G = 10,
K_H = 11,
K_I = 12,
K_J = 13,
K_K = 14,
K_L = 15,
K_M = 16,
K_N = 17,
K_O = 18,
K_P = 19,
K_Q = 20,
K_R = 21,
K_S = 22,
K_T = 23,
K_U = 24,
K_V = 25,
K_W = 26,
K_X = 27,
K_Y = 28,
K_Z = 29,
N1 = 30,
N2 = 31,
N3 = 32,
N4 = 33,
N5 = 34,
N6 = 35,
N7 = 36,
N8 = 37,
N9 = 38,
N0 = 39,
K_1 = 30,
K_2 = 31,
K_3 = 32,
K_4 = 33,
K_5 = 34,
K_6 = 35,
K_7 = 36,
K_8 = 37,
K_9 = 38,
K_0 = 39,
RETURN = 40,
ESCAPE = 41,
BACKSPACE = 42,
TAB = 43,
SPACE = 44,
K_RETURN = 40,
K_ESCAPE = 41,
K_BACKSPACE = 42,
K_TAB = 43,
K_SPACE = 44,
MINUS = 45,
EQUALS = 46,
LEFTBRACKET = 47,
RIGHTBRACKET = 48,
BACKSLASH = 49, /**< Located at the lower left of the return
K_MINUS = 45,
K_EQUALS = 46,
K_LEFTBRACKET = 47,
K_RIGHTBRACKET = 48,
K_BACKSLASH = 49, /**< Located at the lower left of the return
* key on ISO keyboards and at the right end
* of the QWERTY row on ANSI keyboards.
* Produces REVERSE SOLIDUS (backslash) and
@ -76,7 +76,7 @@ enum class Key : int {
* layout, and ASTERISK and MICRO SIGN in a
* French Windows layout.
*/
NONUSHASH = 50, /**< ISO USB keyboards actually use this code
K_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
* instead of 49 for the same key, but all
* OSes I've seen treat the two codes
* identically. So, as an implementor, unless
@ -88,9 +88,9 @@ enum class Key : int {
* will never generate it with most (all?)
* keyboards.
*/
SEMICOLON = 51,
APOSTROPHE = 52,
GRAVE = 53, /**< Located in the top left corner (on both ANSI
K_SEMICOLON = 51,
K_APOSTROPHE = 52,
K_GRAVE = 53, /**< Located in the top left corner (on both ANSI
* and ISO keyboards). Produces GRAVE ACCENT and
* TILDE in a US Windows layout and in US and UK
* Mac layouts on ANSI keyboards, GRAVE ACCENT
@ -107,60 +107,60 @@ enum class Key : int {
* SIGN in a Swiss German, German, or French Mac
* layout on ANSI keyboards.
*/
COMMA = 54,
PERIOD = 55,
SLASH = 56,
K_COMMA = 54,
K_PERIOD = 55,
K_SLASH = 56,
CAPSLOCK = 57,
K_CAPSLOCK = 57,
F1 = 58,
F2 = 59,
F3 = 60,
F4 = 61,
F5 = 62,
F6 = 63,
F7 = 64,
F8 = 65,
F9 = 66,
F10 = 67,
F11 = 68,
F12 = 69,
K_F1 = 58,
K_F2 = 59,
K_F3 = 60,
K_F4 = 61,
K_F5 = 62,
K_F6 = 63,
K_F7 = 64,
K_F8 = 65,
K_F9 = 66,
K_F10 = 67,
K_F11 = 68,
K_F12 = 69,
PRINTSCREEN = 70,
SCROLLLOCK = 71,
PAUSE = 72,
INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
K_PRINTSCREEN = 70,
K_SCROLLLOCK = 71,
K_PAUSE = 72,
K_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
does send code 73, not 117) */
HOME = 74,
PAGEUP = 75,
DELETE = 76,
END = 77,
PAGEDOWN = 78,
RIGHT = 79,
LEFT = 80,
DOWN = 81,
UP = 82,
K_HOME = 74,
K_PAGEUP = 75,
K_DELETE = 76,
K_END = 77,
K_PAGEDOWN = 78,
K_RIGHT = 79,
K_LEFT = 80,
K_DOWN = 81,
K_UP = 82,
NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
K_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
*/
KP_DIVIDE = 84,
KP_MULTIPLY = 85,
KP_MINUS = 86,
KP_PLUS = 87,
KP_ENTER = 88,
KP_1 = 89,
KP_2 = 90,
KP_3 = 91,
KP_4 = 92,
KP_5 = 93,
KP_6 = 94,
KP_7 = 95,
KP_8 = 96,
KP_9 = 97,
KP_0 = 98,
KP_PERIOD = 99,
K_KP_DIVIDE = 84,
K_KP_MULTIPLY = 85,
K_KP_MINUS = 86,
K_KP_PLUS = 87,
K_KP_ENTER = 88,
K_KP_1 = 89,
K_KP_2 = 90,
K_KP_3 = 91,
K_KP_4 = 92,
K_KP_5 = 93,
K_KP_6 = 94,
K_KP_7 = 95,
K_KP_8 = 96,
K_KP_9 = 97,
K_KP_0 = 98,
K_KP_PERIOD = 99,
NONUSBACKSLASH = 100, /**< This is the additional key that ISO
K_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
* keyboards have over ANSI ones,
* located between left shift and Y.
* Produces GRAVE ACCENT and TILDE in a
@ -170,134 +170,134 @@ enum class Key : int {
* LESS-THAN SIGN and GREATER-THAN SIGN
* in a Swiss German, German, or French
* layout. */
APPLICATION = 101, /**< windows contextual menu, compose */
POWER = 102, /**< The USB document says this is a status flag,
K_APPLICATION = 101, /**< windows contextual menu, compose */
K_POWER = 102, /**< The USB document says this is a status flag,
* not a physical key - but some Mac keyboards
* do have a power key. */
KP_EQUALS = 103,
F13 = 104,
F14 = 105,
F15 = 106,
F16 = 107,
F17 = 108,
F18 = 109,
F19 = 110,
F20 = 111,
F21 = 112,
F22 = 113,
F23 = 114,
F24 = 115,
EXECUTE = 116,
HELP = 117,
MENU = 118,
SELECT = 119,
STOP = 120,
AGAIN = 121, /**< redo */
UNDO = 122,
CUT = 123,
COPY = 124,
PASTE = 125,
FIND = 126,
MUTE = 127,
VOLUMEUP = 128,
VOLUMEDOWN = 129,
K_KP_EQUALS = 103,
K_F13 = 104,
K_F14 = 105,
K_F15 = 106,
K_F16 = 107,
K_F17 = 108,
K_F18 = 109,
K_F19 = 110,
K_F20 = 111,
K_F21 = 112,
K_F22 = 113,
K_F23 = 114,
K_F24 = 115,
K_EXECUTE = 116,
K_HELP = 117,
K_MENU = 118,
K_SELECT = 119,
K_STOP = 120,
K_AGAIN = 121, /**< redo */
K_UNDO = 122,
K_CUT = 123,
K_COPY = 124,
K_PASTE = 125,
K_FIND = 126,
K_MUTE = 127,
K_VOLUMEUP = 128,
K_VOLUMEDOWN = 129,
/* not sure whether there's a reason to enable these */
/* LOCKINGCAPSLOCK = 130, */
/* LOCKINGNUMLOCK = 131, */
/* LOCKINGSCROLLLOCK = 132, */
KP_COMMA = 133,
KP_EQUALSAS400 = 134,
K_KP_COMMA = 133,
K_KP_EQUALSAS400 = 134,
INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
K_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
footnotes in USB doc */
INTERNATIONAL2 = 136,
INTERNATIONAL3 = 137, /**< Yen */
INTERNATIONAL4 = 138,
INTERNATIONAL5 = 139,
INTERNATIONAL6 = 140,
INTERNATIONAL7 = 141,
INTERNATIONAL8 = 142,
INTERNATIONAL9 = 143,
LANG1 = 144, /**< Hangul/English toggle */
LANG2 = 145, /**< Hanja conversion */
LANG3 = 146, /**< Katakana */
LANG4 = 147, /**< Hiragana */
LANG5 = 148, /**< Zenkaku/Hankaku */
LANG6 = 149, /**< reserved */
LANG7 = 150, /**< reserved */
LANG8 = 151, /**< reserved */
LANG9 = 152, /**< reserved */
K_INTERNATIONAL2 = 136,
K_INTERNATIONAL3 = 137, /**< Yen */
K_INTERNATIONAL4 = 138,
K_INTERNATIONAL5 = 139,
K_INTERNATIONAL6 = 140,
K_INTERNATIONAL7 = 141,
K_INTERNATIONAL8 = 142,
K_INTERNATIONAL9 = 143,
K_LANG1 = 144, /**< Hangul/English toggle */
K_LANG2 = 145, /**< Hanja conversion */
K_LANG3 = 146, /**< Katakana */
K_LANG4 = 147, /**< Hiragana */
K_LANG5 = 148, /**< Zenkaku/Hankaku */
K_LANG6 = 149, /**< reserved */
K_LANG7 = 150, /**< reserved */
K_LANG8 = 151, /**< reserved */
K_LANG9 = 152, /**< reserved */
ALTERASE = 153, /**< Erase-Eaze */
SYSREQ = 154,
CANCEL = 155,
CLEAR = 156,
PRIOR = 157,
RETURN2 = 158,
SEPARATOR = 159,
OUT = 160,
OPER = 161,
CLEARAGAIN = 162,
CRSEL = 163,
EXSEL = 164,
K_ALTERASE = 153, /**< Erase-Eaze */
K_SYSREQ = 154,
K_CANCEL = 155,
K_CLEAR = 156,
K_PRIOR = 157,
K_RETURN2 = 158,
K_SEPARATOR = 159,
K_OUT = 160,
K_OPER = 161,
K_CLEARAGAIN = 162,
K_CRSEL = 163,
K_EXSEL = 164,
KP_00 = 176,
KP_000 = 177,
THOUSANDSSEPARATOR = 178,
DECIMALSEPARATOR = 179,
CURRENCYUNIT = 180,
CURRENCYSUBUNIT = 181,
KP_LEFTPAREN = 182,
KP_RIGHTPAREN = 183,
KP_LEFTBRACE = 184,
KP_RIGHTBRACE = 185,
KP_TAB = 186,
KP_BACKSPACE = 187,
KP_A = 188,
KP_B = 189,
KP_C = 190,
KP_D = 191,
KP_E = 192,
KP_F = 193,
KP_XOR = 194,
KP_POWER = 195,
KP_PERCENT = 196,
KP_LESS = 197,
KP_GREATER = 198,
KP_AMPERSAND = 199,
KP_DBLAMPERSAND = 200,
KP_VERTICALBAR = 201,
KP_DBLVERTICALBAR = 202,
KP_COLON = 203,
KP_HASH = 204,
KP_SPACE = 205,
KP_AT = 206,
KP_EXCLAM = 207,
KP_MEMSTORE = 208,
KP_MEMRECALL = 209,
KP_MEMCLEAR = 210,
KP_MEMADD = 211,
KP_MEMSUBTRACT = 212,
KP_MEMMULTIPLY = 213,
KP_MEMDIVIDE = 214,
KP_PLUSMINUS = 215,
KP_CLEAR = 216,
KP_CLEARENTRY = 217,
KP_BINARY = 218,
KP_OCTAL = 219,
KP_DECIMAL = 220,
KP_HEXADECIMAL = 221,
K_KP_00 = 176,
K_KP_000 = 177,
K_THOUSANDSSEPARATOR = 178,
K_DECIMALSEPARATOR = 179,
K_CURRENCYUNIT = 180,
K_CURRENCYSUBUNIT = 181,
K_KP_LEFTPAREN = 182,
K_KP_RIGHTPAREN = 183,
K_KP_LEFTBRACE = 184,
K_KP_RIGHTBRACE = 185,
K_KP_TAB = 186,
K_KP_BACKSPACE = 187,
K_KP_A = 188,
K_KP_B = 189,
K_KP_C = 190,
K_KP_D = 191,
K_KP_E = 192,
K_KP_F = 193,
K_KP_XOR = 194,
K_KP_POWER = 195,
K_KP_PERCENT = 196,
K_KP_LESS = 197,
K_KP_GREATER = 198,
K_KP_AMPERSAND = 199,
K_KP_DBLAMPERSAND = 200,
K_KP_VERTICALBAR = 201,
K_KP_DBLVERTICALBAR = 202,
K_KP_COLON = 203,
K_KP_HASH = 204,
K_KP_SPACE = 205,
K_KP_AT = 206,
K_KP_EXCLAM = 207,
K_KP_MEMSTORE = 208,
K_KP_MEMRECALL = 209,
K_KP_MEMCLEAR = 210,
K_KP_MEMADD = 211,
K_KP_MEMSUBTRACT = 212,
K_KP_MEMMULTIPLY = 213,
K_KP_MEMDIVIDE = 214,
K_KP_PLUSMINUS = 215,
K_KP_CLEAR = 216,
K_KP_CLEARENTRY = 217,
K_KP_BINARY = 218,
K_KP_OCTAL = 219,
K_KP_DECIMAL = 220,
K_KP_HEXADECIMAL = 221,
LCTRL = 224,
LSHIFT = 225,
LALT = 226, /**< alt, option */
LGUI = 227, /**< windows, command (apple), meta */
RCTRL = 228,
RSHIFT = 229,
RALT = 230, /**< alt gr, option */
RGUI = 231, /**< windows, command (apple), meta */
K_LCTRL = 224,
K_LSHIFT = 225,
K_LALT = 226, /**< alt, option */
K_LGUI = 227, /**< windows, command (apple), meta */
K_RCTRL = 228,
K_RSHIFT = 229,
K_RALT = 230, /**< alt gr, option */
K_RGUI = 231, /**< windows, command (apple), meta */
MODE = 257, /**< I'm not sure if this is really not covered
K_MODE = 257, /**< I'm not sure if this is really not covered
* by any of the above, but since there's a
* special KMOD_MODE for it I'm adding it here
*/
@ -311,23 +311,23 @@ enum class Key : int {
*/
/* @{ */
AUDIONEXT = 258,
AUDIOPREV = 259,
AUDIOSTOP = 260,
AUDIOPLAY = 261,
AUDIOMUTE = 262,
MEDIASELECT = 263,
WWW = 264,
MAIL = 265,
CALCULATOR = 266,
COMPUTER = 267,
AC_SEARCH = 268,
AC_HOME = 269,
AC_BACK = 270,
AC_FORWARD = 271,
AC_STOP = 272,
AC_REFRESH = 273,
AC_BOOKMARKS = 274,
K_AUDIONEXT = 258,
K_AUDIOPREV = 259,
K_AUDIOSTOP = 260,
K_AUDIOPLAY = 261,
K_AUDIOMUTE = 262,
K_MEDIASELECT = 263,
K_WWW = 264,
K_MAIL = 265,
K_CALCULATOR = 266,
K_COMPUTER = 267,
K_AC_SEARCH = 268,
K_AC_HOME = 269,
K_AC_BACK = 270,
K_AC_FORWARD = 271,
K_AC_STOP = 272,
K_AC_REFRESH = 273,
K_AC_BOOKMARKS = 274,
/* @} *//* Usage page 0x0C */
@ -338,18 +338,18 @@ enum class Key : int {
*/
/* @{ */
BRIGHTNESSDOWN = 275,
BRIGHTNESSUP = 276,
DISPLAYSWITCH = 277, /**< display mirroring/dual display
K_BRIGHTNESSDOWN = 275,
K_BRIGHTNESSUP = 276,
K_DISPLAYSWITCH = 277, /**< display mirroring/dual display
switch, video mode switch */
KBDILLUMTOGGLE = 278,
KBDILLUMDOWN = 279,
KBDILLUMUP = 280,
EJECT = 281,
SLEEP = 282,
K_KBDILLUMTOGGLE = 278,
K_KBDILLUMDOWN = 279,
K_KBDILLUMUP = 280,
K_EJECT = 281,
K_SLEEP = 282,
APP1 = 283,
APP2 = 284,
K_APP1 = 283,
K_APP2 = 284,
/* @} *//* Walther keys */
@ -360,8 +360,8 @@ enum class Key : int {
*/
/* @{ */
AUDIOREWIND = 285,
AUDIOFASTFORWARD = 286,
K_AUDIOREWIND = 285,
K_AUDIOFASTFORWARD = 286,
/* @} *//* Usage page 0x0C (additional media keys) */

View File

@ -10,7 +10,7 @@ namespace engine {
Scene();
Scene(const Scene&) = delete;
Scene& operator=(const Scene&) = delete;
~Scene() = delete;
~Scene();
private:

View File

@ -1,6 +1,6 @@
#pragma once
#include <list>
#include <vector>
#include <memory>
namespace engine {
@ -15,9 +15,13 @@ namespace engine {
SceneManager(const SceneManager&) = delete;
SceneManager& operator=(const SceneManager&) = delete;
void createScene(std::unique_ptr<Scene>&& scene);
void updateActiveScene();
private:
std::list<std::unique_ptr<Scene>> m_scenes;
std::list<std::unique_ptr<Scene>>::iterator m_activeScene{};
std::vector<std::unique_ptr<Scene>> m_scenes;
int m_activeSceneIndex = -1;
};

View File

@ -1,4 +1,4 @@
#include "engine.hpp"
#include "application.hpp"
#include "log.hpp"
@ -7,6 +7,8 @@
#include "input_manager.hpp"
#include "scene_manager.hpp"
#include "scene.hpp"
// To allow the FPS-limiter to put the thread to sleep
#include <thread>
@ -14,10 +16,13 @@ namespace engine {
Application::Application(const char* appName, const char* appVersion)
{
m_window = std::make_unique<Window>(appName, true, true);
m_window = std::make_unique<Window>(appName, true, false);
m_gfx = std::make_unique<GFXDevice>(appName, appVersion, m_window->getHandle());
m_inputManager = std::make_unique<InputManager>(window());
m_sceneManager = std::make_unique<SceneManager>();
auto myScene = std::make_unique<Scene>();
m_sceneManager->createScene(std::move(myScene));
}
Application::~Application() {}
@ -35,6 +40,7 @@ namespace engine {
while (m_window->isRunning()) {
/* logic */
m_sceneManager->updateActiveScene();
/* draw */
m_gfx->renderFrame();

View File

@ -489,13 +489,13 @@ namespace engine {
vkGetPhysicalDeviceProperties(physicalDevice, &physicalDeviceProperties);
VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts & physicalDeviceProperties.limits.framebufferDepthSampleCounts;
//counts %= VK_SAMPLE_COUNT_8_BIT; // restricts it to 8
if (counts & VK_SAMPLE_COUNT_64_BIT) { INFO("64"); return VK_SAMPLE_COUNT_64_BIT; }
if (counts & VK_SAMPLE_COUNT_32_BIT) { INFO("32"); return VK_SAMPLE_COUNT_32_BIT; }
if (counts & VK_SAMPLE_COUNT_16_BIT) { INFO("16"); return VK_SAMPLE_COUNT_16_BIT; }
if (counts & VK_SAMPLE_COUNT_8_BIT) { INFO("8"); return VK_SAMPLE_COUNT_8_BIT; }
if (counts & VK_SAMPLE_COUNT_4_BIT) { INFO("4"); return VK_SAMPLE_COUNT_4_BIT; }
if (counts & VK_SAMPLE_COUNT_2_BIT) { INFO("2"); return VK_SAMPLE_COUNT_2_BIT; }
counts %= VK_SAMPLE_COUNT_8_BIT; // restricts it to 8
if (counts & VK_SAMPLE_COUNT_64_BIT) { return VK_SAMPLE_COUNT_64_BIT; }
if (counts & VK_SAMPLE_COUNT_32_BIT) { return VK_SAMPLE_COUNT_32_BIT; }
if (counts & VK_SAMPLE_COUNT_16_BIT) { return VK_SAMPLE_COUNT_16_BIT; }
if (counts & VK_SAMPLE_COUNT_8_BIT) { return VK_SAMPLE_COUNT_8_BIT; }
if (counts & VK_SAMPLE_COUNT_4_BIT) { return VK_SAMPLE_COUNT_4_BIT; }
if (counts & VK_SAMPLE_COUNT_2_BIT) { return VK_SAMPLE_COUNT_2_BIT; }
return VK_SAMPLE_COUNT_1_BIT;
}

View File

@ -8,4 +8,6 @@ namespace engine {
}
Scene::~Scene() {}
}

View File

@ -1,15 +1,28 @@
#include "scene_manager.hpp"
#include "scene.hpp"
#include "log.hpp"
namespace engine {
class Scene {};
SceneManager::SceneManager()
{
m_scenes.emplace_back(std::make_unique<Scene>());
m_activeScene = m_scenes.begin();
}
SceneManager::~SceneManager() {}
void SceneManager::createScene(std::unique_ptr<Scene>&& scene)
{
m_scenes.emplace_back(std::move(scene));
}
void SceneManager::updateActiveScene()
{
if (m_activeSceneIndex >= 0) {
INFO("updating scene: {}", m_scenes[m_activeSceneIndex]->name);
}
}
}

View File

@ -1,6 +1,6 @@
#include "config.h"
#include "engine.hpp"
#include "application.hpp"
#include "window.hpp"
void playGame()