mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
finish reformatting header files
This commit is contained in:
parent
3ad0b8b6f8
commit
e1b0b79d32
@ -1,25 +1,28 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_COMPONENTS_COLLIDER_H_
|
||||||
|
#define ENGINE_INCLUDE_COMPONENTS_COLLIDER_H_
|
||||||
|
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
struct AABB {
|
struct AABB {
|
||||||
glm::vec3 pos1;
|
glm::vec3 pos1;
|
||||||
glm::vec3 pos2;
|
glm::vec3 pos2;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PhysicsSystem;
|
class PhysicsSystem;
|
||||||
|
|
||||||
struct ColliderComponent {
|
struct ColliderComponent {
|
||||||
friend PhysicsSystem;
|
friend PhysicsSystem;
|
||||||
|
|
||||||
bool isStatic = true;
|
bool is_static = true;
|
||||||
bool isTrigger = false; // entity receives an event on collision enter and exit
|
bool is_trigger =
|
||||||
AABB aabb{}; // broad phase
|
false; // entity receives an event on collision enter and exit
|
||||||
|
AABB aabb{}; // broad phase
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
} // namespace engine
|
||||||
};
|
|
||||||
|
|
||||||
}
|
#endif
|
@ -1,18 +1,19 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_COMPONENTS_RENDERABLE_H_
|
||||||
|
#define ENGINE_INCLUDE_COMPONENTS_RENDERABLE_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "resources/material.hpp"
|
||||||
|
#include "resources/mesh.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
namespace resources {
|
struct RenderableComponent {
|
||||||
class Mesh;
|
std::shared_ptr<resources::Mesh> mesh;
|
||||||
class Material;
|
std::shared_ptr<resources::Material> material;
|
||||||
}
|
bool shown = true;
|
||||||
|
};
|
||||||
|
|
||||||
struct RenderableComponent {
|
} // namespace engine
|
||||||
std::shared_ptr<resources::Mesh> mesh;
|
|
||||||
std::shared_ptr<resources::Material> material;
|
|
||||||
bool shown = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
#endif
|
@ -1,22 +1,25 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||||
|
#define ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||||
|
|
||||||
#include <glm/vec3.hpp>
|
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <glm/mat4x4.hpp>
|
#include <glm/mat4x4.hpp>
|
||||||
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
struct TransformComponent {
|
struct TransformComponent {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::vec3 scale;
|
glm::vec3 scale;
|
||||||
|
|
||||||
glm::mat4 worldMatrix;
|
glm::mat4 world_matrix;
|
||||||
|
|
||||||
std::string tag;
|
std::string tag;
|
||||||
uint32_t parent;
|
uint32_t parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -1,9 +1,12 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_COMPONENTS_UI_ELEMENT_H_
|
||||||
|
#define ENGINE_INCLUDE_COMPONENTS_UI_ELEMENT_H_
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
struct UIElementComponent {
|
struct UIElementComponent {
|
||||||
int n;
|
int n;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -1,374 +1,379 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
|
||||||
|
#define ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
|
||||||
|
|
||||||
// Keyboard scancodes, taken from SDL_scancode.h
|
// Keyboard scancodes, taken from SDL_scancode.h
|
||||||
|
|
||||||
namespace engine::inputs {
|
namespace engine {
|
||||||
|
namespace inputs {
|
||||||
|
|
||||||
enum class Key : int {
|
enum class Key : int {
|
||||||
K_UNKNOWN = 0,
|
K_UNKNOWN = 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \name Usage page 0x07
|
* \name Usage page 0x07
|
||||||
*
|
*
|
||||||
* These values are from usage page 0x07 (USB keyboard page).
|
* These values are from usage page 0x07 (USB keyboard page).
|
||||||
*/
|
*/
|
||||||
/* @{ */
|
/* @{ */
|
||||||
|
|
||||||
K_A = 4,
|
K_A = 4,
|
||||||
K_B = 5,
|
K_B = 5,
|
||||||
K_C = 6,
|
K_C = 6,
|
||||||
K_D = 7,
|
K_D = 7,
|
||||||
K_E = 8,
|
K_E = 8,
|
||||||
K_F = 9,
|
K_F = 9,
|
||||||
K_G = 10,
|
K_G = 10,
|
||||||
K_H = 11,
|
K_H = 11,
|
||||||
K_I = 12,
|
K_I = 12,
|
||||||
K_J = 13,
|
K_J = 13,
|
||||||
K_K = 14,
|
K_K = 14,
|
||||||
K_L = 15,
|
K_L = 15,
|
||||||
K_M = 16,
|
K_M = 16,
|
||||||
K_N = 17,
|
K_N = 17,
|
||||||
K_O = 18,
|
K_O = 18,
|
||||||
K_P = 19,
|
K_P = 19,
|
||||||
K_Q = 20,
|
K_Q = 20,
|
||||||
K_R = 21,
|
K_R = 21,
|
||||||
K_S = 22,
|
K_S = 22,
|
||||||
K_T = 23,
|
K_T = 23,
|
||||||
K_U = 24,
|
K_U = 24,
|
||||||
K_V = 25,
|
K_V = 25,
|
||||||
K_W = 26,
|
K_W = 26,
|
||||||
K_X = 27,
|
K_X = 27,
|
||||||
K_Y = 28,
|
K_Y = 28,
|
||||||
K_Z = 29,
|
K_Z = 29,
|
||||||
|
|
||||||
K_1 = 30,
|
K_1 = 30,
|
||||||
K_2 = 31,
|
K_2 = 31,
|
||||||
K_3 = 32,
|
K_3 = 32,
|
||||||
K_4 = 33,
|
K_4 = 33,
|
||||||
K_5 = 34,
|
K_5 = 34,
|
||||||
K_6 = 35,
|
K_6 = 35,
|
||||||
K_7 = 36,
|
K_7 = 36,
|
||||||
K_8 = 37,
|
K_8 = 37,
|
||||||
K_9 = 38,
|
K_9 = 38,
|
||||||
K_0 = 39,
|
K_0 = 39,
|
||||||
|
|
||||||
K_RETURN = 40,
|
K_RETURN = 40,
|
||||||
K_ESCAPE = 41,
|
K_ESCAPE = 41,
|
||||||
K_BACKSPACE = 42,
|
K_BACKSPACE = 42,
|
||||||
K_TAB = 43,
|
K_TAB = 43,
|
||||||
K_SPACE = 44,
|
K_SPACE = 44,
|
||||||
|
|
||||||
K_MINUS = 45,
|
K_MINUS = 45,
|
||||||
K_EQUALS = 46,
|
K_EQUALS = 46,
|
||||||
K_LEFTBRACKET = 47,
|
K_LEFTBRACKET = 47,
|
||||||
K_RIGHTBRACKET = 48,
|
K_RIGHTBRACKET = 48,
|
||||||
K_BACKSLASH = 49, /**< Located at the lower left of the return
|
K_BACKSLASH = 49, /**< Located at the lower left of the return
|
||||||
* key on ISO keyboards and at the right end
|
* key on ISO keyboards and at the right end
|
||||||
* of the QWERTY row on ANSI keyboards.
|
* of the QWERTY row on ANSI keyboards.
|
||||||
* Produces REVERSE SOLIDUS (backslash) and
|
* Produces REVERSE SOLIDUS (backslash) and
|
||||||
* VERTICAL LINE in a US layout, REVERSE
|
* VERTICAL LINE in a US layout, REVERSE
|
||||||
* SOLIDUS and VERTICAL LINE in a UK Mac
|
* SOLIDUS and VERTICAL LINE in a UK Mac
|
||||||
* layout, NUMBER SIGN and TILDE in a UK
|
* layout, NUMBER SIGN and TILDE in a UK
|
||||||
* Windows layout, DOLLAR SIGN and POUND SIGN
|
* Windows layout, DOLLAR SIGN and POUND SIGN
|
||||||
* in a Swiss German layout, NUMBER SIGN and
|
* in a Swiss German layout, NUMBER SIGN and
|
||||||
* APOSTROPHE in a German layout, GRAVE
|
* APOSTROPHE in a German layout, GRAVE
|
||||||
* ACCENT and POUND SIGN in a French Mac
|
* ACCENT and POUND SIGN in a French Mac
|
||||||
* layout, and ASTERISK and MICRO SIGN in a
|
* layout, and ASTERISK and MICRO SIGN in a
|
||||||
* French Windows layout.
|
* French Windows layout.
|
||||||
*/
|
*/
|
||||||
K_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
|
* instead of 49 for the same key, but all
|
||||||
* OSes I've seen treat the two codes
|
* OSes I've seen treat the two codes
|
||||||
* identically. So, as an implementor, unless
|
* identically. So, as an implementor, unless
|
||||||
* your keyboard generates both of those
|
* your keyboard generates both of those
|
||||||
* codes and your OS treats them differently,
|
* codes and your OS treats them differently,
|
||||||
* you should generate BACKSLASH
|
* you should generate BACKSLASH
|
||||||
* instead of this code. As a user, you
|
* instead of this code. As a user, you
|
||||||
* should not rely on this code because SDL
|
* should not rely on this code because SDL
|
||||||
* will never generate it with most (all?)
|
* will never generate it with most (all?)
|
||||||
* keyboards.
|
* keyboards.
|
||||||
*/
|
*/
|
||||||
K_SEMICOLON = 51,
|
K_SEMICOLON = 51,
|
||||||
K_APOSTROPHE = 52,
|
K_APOSTROPHE = 52,
|
||||||
K_GRAVE = 53, /**< Located in the top left corner (on both ANSI
|
K_GRAVE = 53, /**< Located in the top left corner (on both ANSI
|
||||||
* and ISO keyboards). Produces GRAVE ACCENT and
|
* and ISO keyboards). Produces GRAVE ACCENT and
|
||||||
* TILDE in a US Windows layout and in US and UK
|
* TILDE in a US Windows layout and in US and UK
|
||||||
* Mac layouts on ANSI keyboards, GRAVE ACCENT
|
* Mac layouts on ANSI keyboards, GRAVE ACCENT
|
||||||
* and NOT SIGN in a UK Windows layout, SECTION
|
* and NOT SIGN in a UK Windows layout, SECTION
|
||||||
* SIGN and PLUS-MINUS SIGN in US and UK Mac
|
* SIGN and PLUS-MINUS SIGN in US and UK Mac
|
||||||
* layouts on ISO keyboards, SECTION SIGN and
|
* layouts on ISO keyboards, SECTION SIGN and
|
||||||
* DEGREE SIGN in a Swiss German layout (Mac:
|
* DEGREE SIGN in a Swiss German layout (Mac:
|
||||||
* only on ISO keyboards), CIRCUMFLEX ACCENT and
|
* only on ISO keyboards), CIRCUMFLEX ACCENT and
|
||||||
* DEGREE SIGN in a German layout (Mac: only on
|
* DEGREE SIGN in a German layout (Mac: only on
|
||||||
* ISO keyboards), SUPERSCRIPT TWO and TILDE in a
|
* ISO keyboards), SUPERSCRIPT TWO and TILDE in a
|
||||||
* French Windows layout, COMMERCIAL AT and
|
* French Windows layout, COMMERCIAL AT and
|
||||||
* NUMBER SIGN in a French Mac layout on ISO
|
* NUMBER SIGN in a French Mac layout on ISO
|
||||||
* keyboards, and LESS-THAN SIGN and GREATER-THAN
|
* keyboards, and LESS-THAN SIGN and GREATER-THAN
|
||||||
* SIGN in a Swiss German, German, or French Mac
|
* SIGN in a Swiss German, German, or French Mac
|
||||||
* layout on ANSI keyboards.
|
* layout on ANSI keyboards.
|
||||||
*/
|
*/
|
||||||
K_COMMA = 54,
|
K_COMMA = 54,
|
||||||
K_PERIOD = 55,
|
K_PERIOD = 55,
|
||||||
K_SLASH = 56,
|
K_SLASH = 56,
|
||||||
|
|
||||||
K_CAPSLOCK = 57,
|
K_CAPSLOCK = 57,
|
||||||
|
|
||||||
K_F1 = 58,
|
K_F1 = 58,
|
||||||
K_F2 = 59,
|
K_F2 = 59,
|
||||||
K_F3 = 60,
|
K_F3 = 60,
|
||||||
K_F4 = 61,
|
K_F4 = 61,
|
||||||
K_F5 = 62,
|
K_F5 = 62,
|
||||||
K_F6 = 63,
|
K_F6 = 63,
|
||||||
K_F7 = 64,
|
K_F7 = 64,
|
||||||
K_F8 = 65,
|
K_F8 = 65,
|
||||||
K_F9 = 66,
|
K_F9 = 66,
|
||||||
K_F10 = 67,
|
K_F10 = 67,
|
||||||
K_F11 = 68,
|
K_F11 = 68,
|
||||||
K_F12 = 69,
|
K_F12 = 69,
|
||||||
|
|
||||||
K_PRINTSCREEN = 70,
|
K_PRINTSCREEN = 70,
|
||||||
K_SCROLLLOCK = 71,
|
K_SCROLLLOCK = 71,
|
||||||
K_PAUSE = 72,
|
K_PAUSE = 72,
|
||||||
K_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
|
K_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
|
||||||
does send code 73, not 117) */
|
does send code 73, not 117) */
|
||||||
K_HOME = 74,
|
K_HOME = 74,
|
||||||
K_PAGEUP = 75,
|
K_PAGEUP = 75,
|
||||||
K_DELETE = 76,
|
K_DELETE = 76,
|
||||||
K_END = 77,
|
K_END = 77,
|
||||||
K_PAGEDOWN = 78,
|
K_PAGEDOWN = 78,
|
||||||
K_RIGHT = 79,
|
K_RIGHT = 79,
|
||||||
K_LEFT = 80,
|
K_LEFT = 80,
|
||||||
K_DOWN = 81,
|
K_DOWN = 81,
|
||||||
K_UP = 82,
|
K_UP = 82,
|
||||||
|
|
||||||
K_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
|
K_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
|
||||||
*/
|
*/
|
||||||
K_KP_DIVIDE = 84,
|
K_KP_DIVIDE = 84,
|
||||||
K_KP_MULTIPLY = 85,
|
K_KP_MULTIPLY = 85,
|
||||||
K_KP_MINUS = 86,
|
K_KP_MINUS = 86,
|
||||||
K_KP_PLUS = 87,
|
K_KP_PLUS = 87,
|
||||||
K_KP_ENTER = 88,
|
K_KP_ENTER = 88,
|
||||||
K_KP_1 = 89,
|
K_KP_1 = 89,
|
||||||
K_KP_2 = 90,
|
K_KP_2 = 90,
|
||||||
K_KP_3 = 91,
|
K_KP_3 = 91,
|
||||||
K_KP_4 = 92,
|
K_KP_4 = 92,
|
||||||
K_KP_5 = 93,
|
K_KP_5 = 93,
|
||||||
K_KP_6 = 94,
|
K_KP_6 = 94,
|
||||||
K_KP_7 = 95,
|
K_KP_7 = 95,
|
||||||
K_KP_8 = 96,
|
K_KP_8 = 96,
|
||||||
K_KP_9 = 97,
|
K_KP_9 = 97,
|
||||||
K_KP_0 = 98,
|
K_KP_0 = 98,
|
||||||
K_KP_PERIOD = 99,
|
K_KP_PERIOD = 99,
|
||||||
|
|
||||||
K_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
|
K_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
|
||||||
* keyboards have over ANSI ones,
|
* keyboards have over ANSI ones,
|
||||||
* located between left shift and Y.
|
* located between left shift and Y.
|
||||||
* Produces GRAVE ACCENT and TILDE in a
|
* Produces GRAVE ACCENT and TILDE in a
|
||||||
* US or UK Mac layout, REVERSE SOLIDUS
|
* US or UK Mac layout, REVERSE SOLIDUS
|
||||||
* (backslash) and VERTICAL LINE in a
|
* (backslash) and VERTICAL LINE in a
|
||||||
* US or UK Windows layout, and
|
* US or UK Windows layout, and
|
||||||
* LESS-THAN SIGN and GREATER-THAN SIGN
|
* LESS-THAN SIGN and GREATER-THAN SIGN
|
||||||
* in a Swiss German, German, or French
|
* in a Swiss German, German, or French
|
||||||
* layout. */
|
* layout. */
|
||||||
K_APPLICATION = 101, /**< windows contextual menu, compose */
|
K_APPLICATION = 101, /**< windows contextual menu, compose */
|
||||||
K_POWER = 102, /**< The USB document says this is a status flag,
|
K_POWER = 102, /**< The USB document says this is a status flag,
|
||||||
* not a physical key - but some Mac keyboards
|
* not a physical key - but some Mac keyboards
|
||||||
* do have a power key. */
|
* do have a power key. */
|
||||||
K_KP_EQUALS = 103,
|
K_KP_EQUALS = 103,
|
||||||
K_F13 = 104,
|
K_F13 = 104,
|
||||||
K_F14 = 105,
|
K_F14 = 105,
|
||||||
K_F15 = 106,
|
K_F15 = 106,
|
||||||
K_F16 = 107,
|
K_F16 = 107,
|
||||||
K_F17 = 108,
|
K_F17 = 108,
|
||||||
K_F18 = 109,
|
K_F18 = 109,
|
||||||
K_F19 = 110,
|
K_F19 = 110,
|
||||||
K_F20 = 111,
|
K_F20 = 111,
|
||||||
K_F21 = 112,
|
K_F21 = 112,
|
||||||
K_F22 = 113,
|
K_F22 = 113,
|
||||||
K_F23 = 114,
|
K_F23 = 114,
|
||||||
K_F24 = 115,
|
K_F24 = 115,
|
||||||
K_EXECUTE = 116,
|
K_EXECUTE = 116,
|
||||||
K_HELP = 117,
|
K_HELP = 117,
|
||||||
K_MENU = 118,
|
K_MENU = 118,
|
||||||
K_SELECT = 119,
|
K_SELECT = 119,
|
||||||
K_STOP = 120,
|
K_STOP = 120,
|
||||||
K_AGAIN = 121, /**< redo */
|
K_AGAIN = 121, /**< redo */
|
||||||
K_UNDO = 122,
|
K_UNDO = 122,
|
||||||
K_CUT = 123,
|
K_CUT = 123,
|
||||||
K_COPY = 124,
|
K_COPY = 124,
|
||||||
K_PASTE = 125,
|
K_PASTE = 125,
|
||||||
K_FIND = 126,
|
K_FIND = 126,
|
||||||
K_MUTE = 127,
|
K_MUTE = 127,
|
||||||
K_VOLUMEUP = 128,
|
K_VOLUMEUP = 128,
|
||||||
K_VOLUMEDOWN = 129,
|
K_VOLUMEDOWN = 129,
|
||||||
/* not sure whether there's a reason to enable these */
|
/* not sure whether there's a reason to enable these */
|
||||||
/* LOCKINGCAPSLOCK = 130, */
|
/* LOCKINGCAPSLOCK = 130, */
|
||||||
/* LOCKINGNUMLOCK = 131, */
|
/* LOCKINGNUMLOCK = 131, */
|
||||||
/* LOCKINGSCROLLLOCK = 132, */
|
/* LOCKINGSCROLLLOCK = 132, */
|
||||||
K_KP_COMMA = 133,
|
K_KP_COMMA = 133,
|
||||||
K_KP_EQUALSAS400 = 134,
|
K_KP_EQUALSAS400 = 134,
|
||||||
|
|
||||||
K_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
|
K_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
|
||||||
footnotes in USB doc */
|
footnotes in USB doc */
|
||||||
K_INTERNATIONAL2 = 136,
|
K_INTERNATIONAL2 = 136,
|
||||||
K_INTERNATIONAL3 = 137, /**< Yen */
|
K_INTERNATIONAL3 = 137, /**< Yen */
|
||||||
K_INTERNATIONAL4 = 138,
|
K_INTERNATIONAL4 = 138,
|
||||||
K_INTERNATIONAL5 = 139,
|
K_INTERNATIONAL5 = 139,
|
||||||
K_INTERNATIONAL6 = 140,
|
K_INTERNATIONAL6 = 140,
|
||||||
K_INTERNATIONAL7 = 141,
|
K_INTERNATIONAL7 = 141,
|
||||||
K_INTERNATIONAL8 = 142,
|
K_INTERNATIONAL8 = 142,
|
||||||
K_INTERNATIONAL9 = 143,
|
K_INTERNATIONAL9 = 143,
|
||||||
K_LANG1 = 144, /**< Hangul/English toggle */
|
K_LANG1 = 144, /**< Hangul/English toggle */
|
||||||
K_LANG2 = 145, /**< Hanja conversion */
|
K_LANG2 = 145, /**< Hanja conversion */
|
||||||
K_LANG3 = 146, /**< Katakana */
|
K_LANG3 = 146, /**< Katakana */
|
||||||
K_LANG4 = 147, /**< Hiragana */
|
K_LANG4 = 147, /**< Hiragana */
|
||||||
K_LANG5 = 148, /**< Zenkaku/Hankaku */
|
K_LANG5 = 148, /**< Zenkaku/Hankaku */
|
||||||
K_LANG6 = 149, /**< reserved */
|
K_LANG6 = 149, /**< reserved */
|
||||||
K_LANG7 = 150, /**< reserved */
|
K_LANG7 = 150, /**< reserved */
|
||||||
K_LANG8 = 151, /**< reserved */
|
K_LANG8 = 151, /**< reserved */
|
||||||
K_LANG9 = 152, /**< reserved */
|
K_LANG9 = 152, /**< reserved */
|
||||||
|
|
||||||
K_ALTERASE = 153, /**< Erase-Eaze */
|
K_ALTERASE = 153, /**< Erase-Eaze */
|
||||||
K_SYSREQ = 154,
|
K_SYSREQ = 154,
|
||||||
K_CANCEL = 155,
|
K_CANCEL = 155,
|
||||||
K_CLEAR = 156,
|
K_CLEAR = 156,
|
||||||
K_PRIOR = 157,
|
K_PRIOR = 157,
|
||||||
K_RETURN2 = 158,
|
K_RETURN2 = 158,
|
||||||
K_SEPARATOR = 159,
|
K_SEPARATOR = 159,
|
||||||
K_OUT = 160,
|
K_OUT = 160,
|
||||||
K_OPER = 161,
|
K_OPER = 161,
|
||||||
K_CLEARAGAIN = 162,
|
K_CLEARAGAIN = 162,
|
||||||
K_CRSEL = 163,
|
K_CRSEL = 163,
|
||||||
K_EXSEL = 164,
|
K_EXSEL = 164,
|
||||||
|
|
||||||
K_KP_00 = 176,
|
K_KP_00 = 176,
|
||||||
K_KP_000 = 177,
|
K_KP_000 = 177,
|
||||||
K_THOUSANDSSEPARATOR = 178,
|
K_THOUSANDSSEPARATOR = 178,
|
||||||
K_DECIMALSEPARATOR = 179,
|
K_DECIMALSEPARATOR = 179,
|
||||||
K_CURRENCYUNIT = 180,
|
K_CURRENCYUNIT = 180,
|
||||||
K_CURRENCYSUBUNIT = 181,
|
K_CURRENCYSUBUNIT = 181,
|
||||||
K_KP_LEFTPAREN = 182,
|
K_KP_LEFTPAREN = 182,
|
||||||
K_KP_RIGHTPAREN = 183,
|
K_KP_RIGHTPAREN = 183,
|
||||||
K_KP_LEFTBRACE = 184,
|
K_KP_LEFTBRACE = 184,
|
||||||
K_KP_RIGHTBRACE = 185,
|
K_KP_RIGHTBRACE = 185,
|
||||||
K_KP_TAB = 186,
|
K_KP_TAB = 186,
|
||||||
K_KP_BACKSPACE = 187,
|
K_KP_BACKSPACE = 187,
|
||||||
K_KP_A = 188,
|
K_KP_A = 188,
|
||||||
K_KP_B = 189,
|
K_KP_B = 189,
|
||||||
K_KP_C = 190,
|
K_KP_C = 190,
|
||||||
K_KP_D = 191,
|
K_KP_D = 191,
|
||||||
K_KP_E = 192,
|
K_KP_E = 192,
|
||||||
K_KP_F = 193,
|
K_KP_F = 193,
|
||||||
K_KP_XOR = 194,
|
K_KP_XOR = 194,
|
||||||
K_KP_POWER = 195,
|
K_KP_POWER = 195,
|
||||||
K_KP_PERCENT = 196,
|
K_KP_PERCENT = 196,
|
||||||
K_KP_LESS = 197,
|
K_KP_LESS = 197,
|
||||||
K_KP_GREATER = 198,
|
K_KP_GREATER = 198,
|
||||||
K_KP_AMPERSAND = 199,
|
K_KP_AMPERSAND = 199,
|
||||||
K_KP_DBLAMPERSAND = 200,
|
K_KP_DBLAMPERSAND = 200,
|
||||||
K_KP_VERTICALBAR = 201,
|
K_KP_VERTICALBAR = 201,
|
||||||
K_KP_DBLVERTICALBAR = 202,
|
K_KP_DBLVERTICALBAR = 202,
|
||||||
K_KP_COLON = 203,
|
K_KP_COLON = 203,
|
||||||
K_KP_HASH = 204,
|
K_KP_HASH = 204,
|
||||||
K_KP_SPACE = 205,
|
K_KP_SPACE = 205,
|
||||||
K_KP_AT = 206,
|
K_KP_AT = 206,
|
||||||
K_KP_EXCLAM = 207,
|
K_KP_EXCLAM = 207,
|
||||||
K_KP_MEMSTORE = 208,
|
K_KP_MEMSTORE = 208,
|
||||||
K_KP_MEMRECALL = 209,
|
K_KP_MEMRECALL = 209,
|
||||||
K_KP_MEMCLEAR = 210,
|
K_KP_MEMCLEAR = 210,
|
||||||
K_KP_MEMADD = 211,
|
K_KP_MEMADD = 211,
|
||||||
K_KP_MEMSUBTRACT = 212,
|
K_KP_MEMSUBTRACT = 212,
|
||||||
K_KP_MEMMULTIPLY = 213,
|
K_KP_MEMMULTIPLY = 213,
|
||||||
K_KP_MEMDIVIDE = 214,
|
K_KP_MEMDIVIDE = 214,
|
||||||
K_KP_PLUSMINUS = 215,
|
K_KP_PLUSMINUS = 215,
|
||||||
K_KP_CLEAR = 216,
|
K_KP_CLEAR = 216,
|
||||||
K_KP_CLEARENTRY = 217,
|
K_KP_CLEARENTRY = 217,
|
||||||
K_KP_BINARY = 218,
|
K_KP_BINARY = 218,
|
||||||
K_KP_OCTAL = 219,
|
K_KP_OCTAL = 219,
|
||||||
K_KP_DECIMAL = 220,
|
K_KP_DECIMAL = 220,
|
||||||
K_KP_HEXADECIMAL = 221,
|
K_KP_HEXADECIMAL = 221,
|
||||||
|
|
||||||
K_LCTRL = 224,
|
K_LCTRL = 224,
|
||||||
K_LSHIFT = 225,
|
K_LSHIFT = 225,
|
||||||
K_LALT = 226, /**< alt, option */
|
K_LALT = 226, /**< alt, option */
|
||||||
K_LGUI = 227, /**< windows, command (apple), meta */
|
K_LGUI = 227, /**< windows, command (apple), meta */
|
||||||
K_RCTRL = 228,
|
K_RCTRL = 228,
|
||||||
K_RSHIFT = 229,
|
K_RSHIFT = 229,
|
||||||
K_RALT = 230, /**< alt gr, option */
|
K_RALT = 230, /**< alt gr, option */
|
||||||
K_RGUI = 231, /**< windows, command (apple), meta */
|
K_RGUI = 231, /**< windows, command (apple), meta */
|
||||||
|
|
||||||
K_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
|
* by any of the above, but since there's a
|
||||||
* special KMOD_MODE for it I'm adding it here
|
* special KMOD_MODE for it I'm adding it here
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @} *//* Usage page 0x07 */
|
/* @} */ /* Usage page 0x07 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \name Usage page 0x0C
|
* \name Usage page 0x0C
|
||||||
*
|
*
|
||||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||||
*/
|
*/
|
||||||
/* @{ */
|
/* @{ */
|
||||||
|
|
||||||
K_AUDIONEXT = 258,
|
K_AUDIONEXT = 258,
|
||||||
K_AUDIOPREV = 259,
|
K_AUDIOPREV = 259,
|
||||||
K_AUDIOSTOP = 260,
|
K_AUDIOSTOP = 260,
|
||||||
K_AUDIOPLAY = 261,
|
K_AUDIOPLAY = 261,
|
||||||
K_AUDIOMUTE = 262,
|
K_AUDIOMUTE = 262,
|
||||||
K_MEDIASELECT = 263,
|
K_MEDIASELECT = 263,
|
||||||
K_WWW = 264,
|
K_WWW = 264,
|
||||||
K_MAIL = 265,
|
K_MAIL = 265,
|
||||||
K_CALCULATOR = 266,
|
K_CALCULATOR = 266,
|
||||||
K_COMPUTER = 267,
|
K_COMPUTER = 267,
|
||||||
K_AC_SEARCH = 268,
|
K_AC_SEARCH = 268,
|
||||||
K_AC_HOME = 269,
|
K_AC_HOME = 269,
|
||||||
K_AC_BACK = 270,
|
K_AC_BACK = 270,
|
||||||
K_AC_FORWARD = 271,
|
K_AC_FORWARD = 271,
|
||||||
K_AC_STOP = 272,
|
K_AC_STOP = 272,
|
||||||
K_AC_REFRESH = 273,
|
K_AC_REFRESH = 273,
|
||||||
K_AC_BOOKMARKS = 274,
|
K_AC_BOOKMARKS = 274,
|
||||||
|
|
||||||
/* @} *//* Usage page 0x0C */
|
/* @} */ /* Usage page 0x0C */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \name Walther keys
|
* \name Walther keys
|
||||||
*
|
*
|
||||||
* These are values that Christian Walther added (for mac keyboard?).
|
* These are values that Christian Walther added (for mac keyboard?).
|
||||||
*/
|
*/
|
||||||
/* @{ */
|
/* @{ */
|
||||||
|
|
||||||
K_BRIGHTNESSDOWN = 275,
|
K_BRIGHTNESSDOWN = 275,
|
||||||
K_BRIGHTNESSUP = 276,
|
K_BRIGHTNESSUP = 276,
|
||||||
K_DISPLAYSWITCH = 277, /**< display mirroring/dual display
|
K_DISPLAYSWITCH = 277, /**< display mirroring/dual display
|
||||||
switch, video mode switch */
|
switch, video mode switch */
|
||||||
K_KBDILLUMTOGGLE = 278,
|
K_KBDILLUMTOGGLE = 278,
|
||||||
K_KBDILLUMDOWN = 279,
|
K_KBDILLUMDOWN = 279,
|
||||||
K_KBDILLUMUP = 280,
|
K_KBDILLUMUP = 280,
|
||||||
K_EJECT = 281,
|
K_EJECT = 281,
|
||||||
K_SLEEP = 282,
|
K_SLEEP = 282,
|
||||||
|
|
||||||
K_APP1 = 283,
|
K_APP1 = 283,
|
||||||
K_APP2 = 284,
|
K_APP2 = 284,
|
||||||
|
|
||||||
/* @} *//* Walther keys */
|
/* @} */ /* Walther keys */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \name Usage page 0x0C (additional media keys)
|
* \name Usage page 0x0C (additional media keys)
|
||||||
*
|
*
|
||||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||||
*/
|
*/
|
||||||
/* @{ */
|
/* @{ */
|
||||||
|
|
||||||
K_AUDIOREWIND = 285,
|
K_AUDIOREWIND = 285,
|
||||||
K_AUDIOFASTFORWARD = 286,
|
K_AUDIOFASTFORWARD = 286,
|
||||||
|
|
||||||
/* @} *//* Usage page 0x0C (additional media keys) */
|
/* @} */ /* Usage page 0x0C (additional media keys) */
|
||||||
|
|
||||||
/* Add any other keys here. */
|
/* Add any other keys here. */
|
||||||
|
|
||||||
NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
|
NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
|
||||||
for array bounds */
|
for array bounds */
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace inputs
|
||||||
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -1,22 +1,22 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_INPUTS_MOUSE_H_
|
||||||
|
#define ENGINE_INCLUDE_INPUTS_MOUSE_H_
|
||||||
|
|
||||||
namespace engine::inputs {
|
namespace engine {
|
||||||
|
namespace inputs {
|
||||||
|
|
||||||
enum class MouseButton : int {
|
enum class MouseButton : int {
|
||||||
M_LEFT,
|
M_LEFT,
|
||||||
M_MIDDLE,
|
M_MIDDLE,
|
||||||
M_RIGHT,
|
M_RIGHT,
|
||||||
M_X1,
|
M_X1,
|
||||||
M_X2,
|
M_X2,
|
||||||
M_INVALID=7,
|
M_INVALID = 7,
|
||||||
M_SIZE=7
|
M_SIZE = 7
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class MouseAxis : int {
|
enum class MouseAxis : int { X, Y, X_SCR, Y_SCR };
|
||||||
X,
|
|
||||||
Y,
|
|
||||||
X_SCR,
|
|
||||||
Y_SCR
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
} // namespace inputs
|
||||||
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -4,11 +4,11 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "log.hpp"
|
||||||
|
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
// To be executed in the target application, NOT engine.dll
|
// To be executed in the target application, NOT engine.dll
|
||||||
|
@ -1,28 +1,31 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
|
||||||
|
#define ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace engine::resources {
|
#include "resources/shader.hpp"
|
||||||
|
#include "resources/texture.hpp"
|
||||||
|
|
||||||
class Shader;
|
namespace engine {
|
||||||
class Texture;
|
namespace resources {
|
||||||
|
|
||||||
// copyable
|
// copyable
|
||||||
class Material {
|
class Material {
|
||||||
|
public:
|
||||||
|
Material(std::shared_ptr<Shader> shader);
|
||||||
|
~Material() = default;
|
||||||
|
Material(const Material&);
|
||||||
|
Material& operator=(const Material&) = delete;
|
||||||
|
|
||||||
public:
|
auto GetShader() { return shader_.get(); }
|
||||||
Material(std::shared_ptr<Shader> shader);
|
|
||||||
~Material() = default;
|
|
||||||
Material(const Material&);
|
|
||||||
Material& operator=(const Material&) = delete;
|
|
||||||
|
|
||||||
auto getShader() { return m_shader.get(); }
|
std::shared_ptr<Texture> texture_;
|
||||||
|
|
||||||
std::shared_ptr<Texture> m_texture;
|
private:
|
||||||
|
const std::shared_ptr<Shader> shader_;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
} // namespace resources
|
||||||
const std::shared_ptr<Shader> m_shader;
|
} // namespace engine
|
||||||
|
|
||||||
};
|
#endif
|
||||||
|
|
||||||
}
|
|
@ -1,51 +1,54 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||||
|
#define ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||||
#include "gfx.hpp"
|
|
||||||
|
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "gfx.hpp"
|
||||||
|
#include "gfx_device.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
class GFXDevice;
|
struct Vertex {
|
||||||
|
glm::vec3 pos;
|
||||||
struct Vertex {
|
glm::vec3 norm;
|
||||||
glm::vec3 pos;
|
glm::vec2 uv;
|
||||||
glm::vec3 norm;
|
|
||||||
glm::vec2 uv;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace engine::resources {
|
|
||||||
|
|
||||||
class Mesh {
|
|
||||||
|
|
||||||
public:
|
|
||||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices);
|
|
||||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
|
||||||
: m_gfx(gfx)
|
|
||||||
{
|
|
||||||
initMesh(vertices, indices);
|
|
||||||
}
|
|
||||||
~Mesh();
|
|
||||||
Mesh(const Mesh&) = delete;
|
|
||||||
Mesh& operator=(const Mesh&) = delete;
|
|
||||||
|
|
||||||
const gfx::Buffer* getVB();
|
|
||||||
const gfx::Buffer* getIB();
|
|
||||||
uint32_t getCount();
|
|
||||||
|
|
||||||
private:
|
|
||||||
GFXDevice* const m_gfx;
|
|
||||||
|
|
||||||
const gfx::Buffer* m_vb;
|
|
||||||
const gfx::Buffer* m_ib;
|
|
||||||
uint32_t m_count;
|
|
||||||
|
|
||||||
void initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace engine
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
namespace resources {
|
||||||
|
|
||||||
|
class Mesh {
|
||||||
|
public:
|
||||||
|
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices);
|
||||||
|
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices,
|
||||||
|
const std::vector<uint32_t>& indices)
|
||||||
|
: gfx_(gfx) {
|
||||||
|
InitMesh(vertices, indices);
|
||||||
|
}
|
||||||
|
~Mesh();
|
||||||
|
Mesh(const Mesh&) = delete;
|
||||||
|
Mesh& operator=(const Mesh&) = delete;
|
||||||
|
|
||||||
|
const gfx::Buffer* GetVB();
|
||||||
|
const gfx::Buffer* GetIB();
|
||||||
|
uint32_t GetCount();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GFXDevice* const gfx_;
|
||||||
|
|
||||||
|
const gfx::Buffer* vb_;
|
||||||
|
const gfx::Buffer* ib_;
|
||||||
|
uint32_t count_;
|
||||||
|
|
||||||
|
void InitMesh(const std::vector<Vertex>& vertices,
|
||||||
|
const std::vector<uint32_t>& indices);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace resources
|
||||||
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -1,37 +1,38 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_RESOURCES_SHADER_H_
|
||||||
|
#define ENGINE_INCLUDE_RESOURCES_SHADER_H_
|
||||||
|
|
||||||
|
#include "application.hpp"
|
||||||
#include "gfx.hpp"
|
#include "gfx.hpp"
|
||||||
|
#include "gfx_device.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
class GFXDevice;
|
namespace resources {
|
||||||
struct RenderData;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace engine::resources {
|
|
||||||
|
|
||||||
class Shader {
|
class Shader {
|
||||||
|
public:
|
||||||
|
// defines what vertex inputs are defined, position is always vec3
|
||||||
|
struct VertexParams {
|
||||||
|
bool has_normal; // vec3
|
||||||
|
bool has_tangent; // vec3
|
||||||
|
bool has_color; // vec3
|
||||||
|
bool has_uv0; // vec2
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
Shader(RenderData* render_data, const char* vert_path, const char* frag_path,
|
||||||
|
const VertexParams& vertex_params, bool alpha_blending,
|
||||||
|
bool cull_backface);
|
||||||
|
~Shader();
|
||||||
|
Shader(const Shader&) = delete;
|
||||||
|
Shader& operator=(const Shader&) = delete;
|
||||||
|
|
||||||
// defines what vertex inputs are defined, position is always vec3
|
const gfx::Pipeline* GetPipeline();
|
||||||
struct VertexParams {
|
|
||||||
bool hasNormal; // vec3
|
|
||||||
bool hasTangent; // vec3
|
|
||||||
bool hasColor; // vec3
|
|
||||||
bool hasUV0; // vec2
|
|
||||||
};
|
|
||||||
|
|
||||||
Shader(RenderData* renderData, const char* vertPath, const char* fragPath, const VertexParams& vertexParams, bool alphaBlending, bool cullBackFace);
|
|
||||||
~Shader();
|
|
||||||
Shader(const Shader&) = delete;
|
|
||||||
Shader& operator=(const Shader&) = delete;
|
|
||||||
|
|
||||||
const gfx::Pipeline* getPipeline();
|
|
||||||
|
|
||||||
private:
|
|
||||||
GFXDevice* const m_gfx;
|
|
||||||
const gfx::Pipeline* m_pipeline;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
GFXDevice* const gfx_;
|
||||||
|
const gfx::Pipeline* pipeline_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace resources
|
||||||
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -1,37 +1,39 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
|
||||||
|
#define ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
|
||||||
#include "gfx_device.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace engine {
|
#include "application.hpp"
|
||||||
struct RenderData;
|
#include "gfx_device.hpp"
|
||||||
}
|
|
||||||
|
|
||||||
namespace engine::resources {
|
namespace engine {
|
||||||
|
namespace resources {
|
||||||
|
|
||||||
class Texture {
|
class Texture {
|
||||||
|
public:
|
||||||
|
enum class Filtering {
|
||||||
|
kOff,
|
||||||
|
kBilinear,
|
||||||
|
kTrilinear,
|
||||||
|
kAnisotropic,
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
Texture(RenderData* render_data, const std::string& path,
|
||||||
enum class Filtering {
|
Filtering filtering);
|
||||||
OFF,
|
~Texture();
|
||||||
BILINEAR,
|
Texture(const Texture&) = delete;
|
||||||
TRILINEAR,
|
Texture& operator=(const Texture&) = delete;
|
||||||
ANISOTROPIC,
|
|
||||||
};
|
|
||||||
|
|
||||||
Texture(RenderData* renderData, const std::string& path, Filtering filtering);
|
const gfx::Image* GetImage() { return image_; }
|
||||||
~Texture();
|
const gfx::DescriptorSet* GetDescriptorSet() { return descriptor_set_; }
|
||||||
Texture(const Texture&) = delete;
|
|
||||||
Texture& operator=(const Texture&) = delete;
|
|
||||||
|
|
||||||
const gfx::Image* getImage() { return m_image; }
|
private:
|
||||||
const gfx::DescriptorSet* getDescriptorSet() { return m_descriptorSet; }
|
GFXDevice* gfx_;
|
||||||
|
const gfx::Image* image_;
|
||||||
private:
|
const gfx::DescriptorSet* descriptor_set_;
|
||||||
GFXDevice* m_gfxDevice;
|
|
||||||
const gfx::Image* m_image;
|
|
||||||
const gfx::DescriptorSet* m_descriptorSet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace resources
|
||||||
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -1,60 +1,61 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
|
||||||
|
#define ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <glm/mat4x4.hpp>
|
#include <glm/mat4x4.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "components/collider.hpp"
|
#include "components/collider.hpp"
|
||||||
#include "ecs_system.hpp"
|
#include "ecs_system.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
class PhysicsSystem : public System {
|
class PhysicsSystem : public System {
|
||||||
|
public:
|
||||||
|
PhysicsSystem(Scene* scene);
|
||||||
|
|
||||||
public:
|
void OnUpdate(float ts) override;
|
||||||
PhysicsSystem(Scene* scene);
|
|
||||||
|
|
||||||
void OnUpdate(float ts) override;
|
void OnComponentInsert(uint32_t entity) override;
|
||||||
|
|
||||||
void OnComponentInsert(uint32_t entity) override;
|
struct CollisionEvent {
|
||||||
|
bool is_collision_enter; // false == collision exit
|
||||||
|
uint32_t collided_entity; // the entity that this entity collided with
|
||||||
|
glm::vec3 normal; // the normal of the surface this entity collided with;
|
||||||
|
// ignored on collision exit
|
||||||
|
glm::vec3 point; // where the collision was detected
|
||||||
|
};
|
||||||
|
|
||||||
struct CollisionEvent {
|
private:
|
||||||
bool isCollisionEnter; // false == collision exit
|
// dynamic arrays to avoid realloc on every frame
|
||||||
uint32_t collidedEntity; // the entity that this entity collided with
|
|
||||||
glm::vec3 normal; // the normal of the surface this entity collided with; ignored on collision exit
|
|
||||||
glm::vec3 point; // where the collision was detected
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// dynamic arrays to avoid realloc on every frame
|
// entity, aabb, is_trigger
|
||||||
|
std::vector<std::tuple<uint32_t, AABB, bool>> static_aabbs_{};
|
||||||
|
std::vector<std::tuple<uint32_t, AABB, bool>> dynamic_aabbs_{};
|
||||||
|
|
||||||
// entity, aabb, isTrigger
|
struct PossibleCollision {
|
||||||
std::vector<std::tuple<uint32_t, AABB, bool>> m_staticAABBs{};
|
PossibleCollision(uint32_t static_entity, AABB static_aabb,
|
||||||
std::vector<std::tuple<uint32_t, AABB, bool>> m_dynamicAABBs{};
|
bool static_trigger, uint32_t dynamic_entity,
|
||||||
|
AABB dynamic_aabb, bool dynamic_trigger)
|
||||||
|
: static_entity(static_entity),
|
||||||
|
static_aabb(static_aabb),
|
||||||
|
static_trigger(static_trigger),
|
||||||
|
dynamic_entity(dynamic_entity),
|
||||||
|
dynamic_aabb(dynamic_aabb),
|
||||||
|
dynamic_trigger(dynamic_trigger) {}
|
||||||
|
|
||||||
struct PossibleCollision {
|
uint32_t static_entity;
|
||||||
|
AABB static_aabb;
|
||||||
|
bool static_trigger;
|
||||||
|
uint32_t dynamic_entity;
|
||||||
|
AABB dynamic_aabb;
|
||||||
|
bool dynamic_trigger;
|
||||||
|
};
|
||||||
|
std::vector<PossibleCollision> possible_collisions_{};
|
||||||
|
std::vector<std::pair<uint32_t, CollisionEvent>>
|
||||||
|
collision_infos_{}; // target entity, event info
|
||||||
|
};
|
||||||
|
|
||||||
PossibleCollision(uint32_t staticEntity, AABB staticAABB, bool staticTrigger, uint32_t dynamicEntity, AABB dynamicAABB, bool dynamicTrigger) :
|
} // namespace engine
|
||||||
staticEntity(staticEntity),
|
|
||||||
staticAABB(staticAABB),
|
|
||||||
staticTrigger(staticTrigger),
|
|
||||||
dynamicEntity(dynamicEntity),
|
|
||||||
dynamicAABB(dynamicAABB),
|
|
||||||
dynamicTrigger(dynamicTrigger) {}
|
|
||||||
|
|
||||||
uint32_t staticEntity;
|
|
||||||
AABB staticAABB;
|
|
||||||
bool staticTrigger;
|
|
||||||
uint32_t dynamicEntity;
|
|
||||||
AABB dynamicAABB;
|
|
||||||
bool dynamicTrigger;
|
|
||||||
};
|
|
||||||
std::vector<PossibleCollision> m_possibleCollisions{};
|
|
||||||
std::vector<std::pair<uint32_t, CollisionEvent>> m_collisionInfos{}; // target entity, event info
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,43 +1,39 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_SYSTEMS_RENDER_H_
|
||||||
|
#define ENGINE_INCLUDE_SYSTEMS_RENDER_H_
|
||||||
|
|
||||||
#include "ecs_system.hpp"
|
|
||||||
#include "scene.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
|
|
||||||
#include "components/transform.hpp"
|
|
||||||
#include "components/renderable.hpp"
|
#include "components/renderable.hpp"
|
||||||
|
#include "components/transform.hpp"
|
||||||
|
#include "ecs_system.hpp"
|
||||||
#include "gfx.hpp"
|
#include "gfx.hpp"
|
||||||
#include "gfx_device.hpp"
|
#include "gfx_device.hpp"
|
||||||
|
#include "log.hpp"
|
||||||
|
#include "scene.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
class RenderSystem : public System {
|
class RenderSystem : public System {
|
||||||
|
public:
|
||||||
|
RenderSystem(Scene* scene);
|
||||||
|
~RenderSystem();
|
||||||
|
|
||||||
public:
|
void OnUpdate(float ts) override;
|
||||||
RenderSystem(Scene* scene);
|
|
||||||
~RenderSystem();
|
|
||||||
|
|
||||||
void OnUpdate(float ts) override;
|
void SetCameraEntity(uint32_t entity);
|
||||||
|
|
||||||
void setCameraEntity(uint32_t entity);
|
private:
|
||||||
|
GFXDevice* const gfx_;
|
||||||
|
|
||||||
private:
|
struct {
|
||||||
GFXDevice* const m_gfx;
|
// only uses transform component, which is required for all entities anyway
|
||||||
|
uint32_t cam_entity = 0;
|
||||||
|
float vertical_fov_degrees = 70.0f;
|
||||||
|
float clip_near = 0.5f;
|
||||||
|
float clip_far = 10000.0f;
|
||||||
|
} camera_;
|
||||||
|
|
||||||
struct {
|
float viewport_aspect_ratio_ = 1.0f;
|
||||||
// only uses transform component, which is required for all entities anyway
|
};
|
||||||
uint32_t camEntity = 0;
|
|
||||||
float verticalFovDegrees = 70.0f;
|
|
||||||
float clipNear = 0.5f;
|
|
||||||
float clipFar = 10000.0f;
|
|
||||||
} m_camera;
|
|
||||||
|
|
||||||
float m_viewportAspectRatio = 1.0f;
|
} // namespace engine
|
||||||
|
|
||||||
float m_value = 0.0f;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,20 +1,20 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_SYSTEMS_RENDER2D_H_
|
||||||
|
#define ENGINE_INCLUDE_SYSTEMS_RENDER2D_H_
|
||||||
|
|
||||||
#include "ecs_system.hpp"
|
#include "ecs_system.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
class Render2DSystem : public System {
|
class Render2DSystem : public System {
|
||||||
|
public:
|
||||||
|
Render2DSystem(Scene* scene);
|
||||||
|
~Render2DSystem();
|
||||||
|
|
||||||
public:
|
void OnUpdate(float ts) override;
|
||||||
Render2DSystem(Scene* scene);
|
|
||||||
~Render2DSystem();
|
|
||||||
|
|
||||||
void OnUpdate(float ts) override;
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
} // namespace engine
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
|
||||||
|
#define ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
|
||||||
|
|
||||||
#include "ecs_system.hpp"
|
#include "ecs_system.hpp"
|
||||||
|
|
||||||
@ -11,9 +12,10 @@ namespace engine {
|
|||||||
|
|
||||||
void OnUpdate(float ts) override;
|
void OnUpdate(float ts) override;
|
||||||
|
|
||||||
uint32_t getChildEntity(uint32_t parent, const std::string& tag);
|
uint32_t GetChildEntity(uint32_t parent, const std::string& tag);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,19 +1,19 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_SYSTEMS_UI_H_
|
||||||
|
#define ENGINE_INCLUDE_SYSTEMS_UI_H_
|
||||||
|
|
||||||
#include "ecs_system.hpp"
|
#include "ecs_system.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
class UISystem : public System {
|
class UISystem : public System {
|
||||||
|
public:
|
||||||
|
UISystem(Scene* scene);
|
||||||
|
|
||||||
public:
|
void OnUpdate(float ts) override;
|
||||||
UISystem(Scene* scene);
|
|
||||||
|
|
||||||
void OnUpdate(float ts) override;
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
} // namespace engine
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,16 +1,22 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_UTIL_FILES_H_
|
||||||
|
#define ENGINE_INCLUDE_UTIL_FILES_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace engine::util {
|
namespace engine {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
std::unique_ptr<std::vector<char>> readTextFile(const std::string& path);
|
std::unique_ptr<std::vector<char>> ReadTextFile(const std::string& path);
|
||||||
std::unique_ptr<std::vector<uint8_t>> readBinaryFile(const std::string& path);
|
std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path);
|
||||||
|
|
||||||
// Read an image file into a vector byte buffer. PNG and JPG support at a minimum.
|
// Read an image file into a vector byte buffer. PNG and JPG support at a
|
||||||
// Output format is R8G8B8A8_UINT
|
// minimum. Output format is R8G8B8A8_UINT
|
||||||
std::unique_ptr<std::vector<uint8_t>> readImageFile(const std::string& path, int *width, int *height);
|
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path,
|
||||||
|
int* width, int* height);
|
||||||
|
|
||||||
}
|
} // namespace util
|
||||||
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -1,13 +1,16 @@
|
|||||||
#pragma once
|
#ifndef ENGINE_INCLUDE_UTIL_MODEL_LOADER_H_
|
||||||
|
#define ENGINE_INCLUDE_UTIL_MODEL_LOADER_H_
|
||||||
#include "scene.hpp"
|
|
||||||
|
|
||||||
#include "resources/shader.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace engine::util {
|
#include "scene.hpp"
|
||||||
|
|
||||||
uint32_t loadMeshFromFile(Scene* parent, const std::string& path);
|
namespace engine {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
}
|
uint32_t LoadMeshFromFile(Scene* parent, const std::string& path);
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace engine
|
||||||
|
|
||||||
|
#endif
|
@ -116,8 +116,8 @@ namespace engine {
|
|||||||
// default resources
|
// default resources
|
||||||
{
|
{
|
||||||
resources::Shader::VertexParams vertParams{};
|
resources::Shader::VertexParams vertParams{};
|
||||||
vertParams.hasNormal = true;
|
vertParams.has_normal = true;
|
||||||
vertParams.hasUV0 = true;
|
vertParams.has_uv0 = true;
|
||||||
auto texturedShader = std::make_unique<resources::Shader>(
|
auto texturedShader = std::make_unique<resources::Shader>(
|
||||||
&render_data_,
|
&render_data_,
|
||||||
GetResourcePath("engine/shaders/standard.vert").c_str(),
|
GetResourcePath("engine/shaders/standard.vert").c_str(),
|
||||||
@ -130,8 +130,8 @@ namespace engine {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
resources::Shader::VertexParams vertParams{};
|
resources::Shader::VertexParams vertParams{};
|
||||||
vertParams.hasNormal = true;
|
vertParams.has_normal = true;
|
||||||
vertParams.hasUV0 = true;
|
vertParams.has_uv0 = true;
|
||||||
auto skyboxShader = std::make_unique<resources::Shader>(
|
auto skyboxShader = std::make_unique<resources::Shader>(
|
||||||
&render_data_,
|
&render_data_,
|
||||||
GetResourcePath("engine/shaders/skybox.vert").c_str(),
|
GetResourcePath("engine/shaders/skybox.vert").c_str(),
|
||||||
@ -146,7 +146,7 @@ namespace engine {
|
|||||||
auto whiteTexture = std::make_unique<resources::Texture>(
|
auto whiteTexture = std::make_unique<resources::Texture>(
|
||||||
&render_data_,
|
&render_data_,
|
||||||
GetResourcePath("engine/textures/white.png"),
|
GetResourcePath("engine/textures/white.png"),
|
||||||
resources::Texture::Filtering::OFF
|
resources::Texture::Filtering::kOff
|
||||||
);
|
);
|
||||||
GetResourceManager<resources::Texture>()->AddPersistent("builtin.white", std::move(whiteTexture));
|
GetResourceManager<resources::Texture>()->AddPersistent("builtin.white", std::move(whiteTexture));
|
||||||
}
|
}
|
||||||
|
@ -832,8 +832,8 @@ namespace engine {
|
|||||||
|
|
||||||
gfx::Pipeline* pipeline = new gfx::Pipeline;
|
gfx::Pipeline* pipeline = new gfx::Pipeline;
|
||||||
|
|
||||||
auto vertShaderCode = util::readTextFile(info.vert_shader_path);
|
auto vertShaderCode = util::ReadTextFile(info.vert_shader_path);
|
||||||
auto fragShaderCode = util::readTextFile(info.frag_shader_path);
|
auto fragShaderCode = util::ReadTextFile(info.frag_shader_path);
|
||||||
|
|
||||||
VkShaderModule vertShaderModule = compileShader(pimpl->device.device, shaderc_vertex_shader, vertShaderCode->data(), info.vert_shader_path);
|
VkShaderModule vertShaderModule = compileShader(pimpl->device.device, shaderc_vertex_shader, vertShaderCode->data(), info.vert_shader_path);
|
||||||
VkShaderModule fragShaderModule = compileShader(pimpl->device.device, shaderc_fragment_shader, fragShaderCode->data(), info.frag_shader_path);
|
VkShaderModule fragShaderModule = compileShader(pimpl->device.device, shaderc_fragment_shader, fragShaderCode->data(), info.frag_shader_path);
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
namespace engine::resources {
|
namespace engine::resources {
|
||||||
|
|
||||||
Material::Material(std::shared_ptr<Shader> shader)
|
Material::Material(std::shared_ptr<Shader> shader)
|
||||||
: m_shader(shader)
|
: shader_(shader)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Material::Material(const Material& original)
|
Material::Material(const Material& original)
|
||||||
: m_texture(original.m_texture), m_shader(original.m_shader)
|
: texture_(original.texture_), shader_(original.shader_)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,41 +6,41 @@
|
|||||||
namespace engine::resources {
|
namespace engine::resources {
|
||||||
|
|
||||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices)
|
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices)
|
||||||
: m_gfx(gfx)
|
: gfx_(gfx)
|
||||||
{
|
{
|
||||||
std::vector<uint32_t> indices(vertices.size());
|
std::vector<uint32_t> indices(vertices.size());
|
||||||
for (uint32_t i = 0; i < indices.size(); i++) {
|
for (uint32_t i = 0; i < indices.size(); i++) {
|
||||||
indices[i] = i;
|
indices[i] = i;
|
||||||
}
|
}
|
||||||
initMesh(vertices, indices);
|
InitMesh(vertices, indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh::~Mesh()
|
Mesh::~Mesh()
|
||||||
{
|
{
|
||||||
m_gfx->DestroyBuffer(m_ib);
|
gfx_->DestroyBuffer(ib_);
|
||||||
m_gfx->DestroyBuffer(m_vb);
|
gfx_->DestroyBuffer(vb_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const gfx::Buffer* Mesh::getVB()
|
const gfx::Buffer* Mesh::GetVB()
|
||||||
{
|
{
|
||||||
return m_vb;
|
return vb_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gfx::Buffer* Mesh::getIB()
|
const gfx::Buffer* Mesh::GetIB()
|
||||||
{
|
{
|
||||||
return m_ib;
|
return ib_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Mesh::getCount()
|
uint32_t Mesh::GetCount()
|
||||||
{
|
{
|
||||||
return m_count;
|
return count_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
void Mesh::InitMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||||
{
|
{
|
||||||
m_vb = m_gfx->CreateBuffer(gfx::BufferType::kVertex, vertices.size() * sizeof(Vertex), vertices.data());
|
vb_ = gfx_->CreateBuffer(gfx::BufferType::kVertex, vertices.size() * sizeof(Vertex), vertices.data());
|
||||||
m_ib = m_gfx->CreateBuffer(gfx::BufferType::kIndex, indices.size() * sizeof(uint32_t), indices.data());
|
ib_ = gfx_->CreateBuffer(gfx::BufferType::kIndex, indices.size() * sizeof(uint32_t), indices.data());
|
||||||
m_count = (uint32_t)indices.size();
|
count_ = (uint32_t)indices.size();
|
||||||
LOG_INFO("Loaded mesh, vertices: {}, indices: {}", vertices.size(), indices.size());
|
LOG_INFO("Loaded mesh, vertices: {}, indices: {}", vertices.size(), indices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ namespace engine::resources {
|
|||||||
|
|
||||||
|
|
||||||
Shader::Shader(RenderData* renderData, const char* vertPath, const char* fragPath, const VertexParams& vertexParams, bool alphaBlending, bool cullBackFace)
|
Shader::Shader(RenderData* renderData, const char* vertPath, const char* fragPath, const VertexParams& vertexParams, bool alphaBlending, bool cullBackFace)
|
||||||
: m_gfx(renderData->gfxdev.get())
|
: gfx_(renderData->gfxdev.get())
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
@ -20,19 +20,19 @@ namespace engine::resources {
|
|||||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat3, stride);
|
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat3, stride);
|
||||||
stride += 3 * sizeof(float);
|
stride += 3 * sizeof(float);
|
||||||
|
|
||||||
if (vertexParams.hasNormal) {
|
if (vertexParams.has_normal) {
|
||||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat3, stride);
|
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat3, stride);
|
||||||
stride += 3 * sizeof(float);
|
stride += 3 * sizeof(float);
|
||||||
}
|
}
|
||||||
if (vertexParams.hasTangent) {
|
if (vertexParams.has_tangent) {
|
||||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat4, stride);
|
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat4, stride);
|
||||||
stride += 4 * sizeof(float);
|
stride += 4 * sizeof(float);
|
||||||
}
|
}
|
||||||
if (vertexParams.hasColor) {
|
if (vertexParams.has_color) {
|
||||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat4, stride);
|
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat4, stride);
|
||||||
stride += 4 * sizeof(float);
|
stride += 4 * sizeof(float);
|
||||||
}
|
}
|
||||||
if (vertexParams.hasUV0) {
|
if (vertexParams.has_uv0) {
|
||||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat2, stride);
|
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat2, stride);
|
||||||
stride += 2 * sizeof(float);
|
stride += 2 * sizeof(float);
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ namespace engine::resources {
|
|||||||
info.descriptor_set_layouts.push_back(renderData->frame_set_layout);
|
info.descriptor_set_layouts.push_back(renderData->frame_set_layout);
|
||||||
info.descriptor_set_layouts.push_back(renderData->material_set_layout);
|
info.descriptor_set_layouts.push_back(renderData->material_set_layout);
|
||||||
|
|
||||||
m_pipeline = m_gfx->CreatePipeline(info);
|
pipeline_ = gfx_->CreatePipeline(info);
|
||||||
|
|
||||||
LOG_INFO("Loaded shader: {}, vertex attribs: {}", vertPath, vertFormat.attribute_descriptions.size());
|
LOG_INFO("Loaded shader: {}, vertex attribs: {}", vertPath, vertFormat.attribute_descriptions.size());
|
||||||
|
|
||||||
@ -56,12 +56,12 @@ namespace engine::resources {
|
|||||||
|
|
||||||
Shader::~Shader()
|
Shader::~Shader()
|
||||||
{
|
{
|
||||||
m_gfx->DestroyPipeline(m_pipeline);
|
gfx_->DestroyPipeline(pipeline_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const gfx::Pipeline* Shader::getPipeline()
|
const gfx::Pipeline* Shader::GetPipeline()
|
||||||
{
|
{
|
||||||
return m_pipeline;
|
return pipeline_;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,45 +9,45 @@
|
|||||||
namespace engine::resources {
|
namespace engine::resources {
|
||||||
|
|
||||||
Texture::Texture(RenderData* renderData, const std::string& path, Filtering filtering)
|
Texture::Texture(RenderData* renderData, const std::string& path, Filtering filtering)
|
||||||
: m_gfxDevice(renderData->gfxdev.get())
|
: gfx_(renderData->gfxdev.get())
|
||||||
{
|
{
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
std::unique_ptr<std::vector<uint8_t>> texbuf = util::readImageFile(path, &width, &height);
|
std::unique_ptr<std::vector<uint8_t>> texbuf = util::ReadImageFile(path, &width, &height);
|
||||||
|
|
||||||
gfx::SamplerInfo samplerInfo{};
|
gfx::SamplerInfo samplerInfo{};
|
||||||
|
|
||||||
samplerInfo.magnify = gfx::Filter::kLinear;
|
samplerInfo.magnify = gfx::Filter::kLinear;
|
||||||
|
|
||||||
switch (filtering) {
|
switch (filtering) {
|
||||||
case Filtering::OFF:
|
case Filtering::kOff:
|
||||||
samplerInfo.minify = gfx::Filter::kNearest;
|
samplerInfo.minify = gfx::Filter::kNearest;
|
||||||
samplerInfo.mipmap = gfx::Filter::kNearest;
|
samplerInfo.mipmap = gfx::Filter::kNearest;
|
||||||
samplerInfo.anisotropic_filtering = false;
|
samplerInfo.anisotropic_filtering = false;
|
||||||
break;
|
break;
|
||||||
case Filtering::BILINEAR:
|
case Filtering::kBilinear:
|
||||||
samplerInfo.minify = gfx::Filter::kLinear;
|
samplerInfo.minify = gfx::Filter::kLinear;
|
||||||
samplerInfo.mipmap = gfx::Filter::kNearest;
|
samplerInfo.mipmap = gfx::Filter::kNearest;
|
||||||
samplerInfo.anisotropic_filtering = false;
|
samplerInfo.anisotropic_filtering = false;
|
||||||
break;
|
break;
|
||||||
case Filtering::TRILINEAR:
|
case Filtering::kTrilinear:
|
||||||
samplerInfo.minify = gfx::Filter::kLinear;
|
samplerInfo.minify = gfx::Filter::kLinear;
|
||||||
samplerInfo.mipmap = gfx::Filter::kLinear;
|
samplerInfo.mipmap = gfx::Filter::kLinear;
|
||||||
samplerInfo.anisotropic_filtering = false;
|
samplerInfo.anisotropic_filtering = false;
|
||||||
break;
|
break;
|
||||||
case Filtering::ANISOTROPIC:
|
case Filtering::kAnisotropic:
|
||||||
samplerInfo.minify = gfx::Filter::kLinear;
|
samplerInfo.minify = gfx::Filter::kLinear;
|
||||||
samplerInfo.mipmap = gfx::Filter::kLinear;
|
samplerInfo.mipmap = gfx::Filter::kLinear;
|
||||||
samplerInfo.anisotropic_filtering = true;
|
samplerInfo.anisotropic_filtering = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderData->samplers.contains(samplerInfo) == false) {
|
if (renderData->samplers.contains(samplerInfo) == false) {
|
||||||
renderData->samplers.insert(std::make_pair(samplerInfo, m_gfxDevice->CreateSampler(samplerInfo)));
|
renderData->samplers.insert(std::make_pair(samplerInfo, gfx_->CreateSampler(samplerInfo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_image = m_gfxDevice->CreateImage(width, height, texbuf->data());
|
image_ = gfx_->CreateImage(width, height, texbuf->data());
|
||||||
m_descriptorSet = m_gfxDevice->AllocateDescriptorSet(renderData->material_set_layout);
|
descriptor_set_ = gfx_->AllocateDescriptorSet(renderData->material_set_layout);
|
||||||
m_gfxDevice->UpdateDescriptorCombinedImageSampler(m_descriptorSet, 0, m_image, renderData->samplers.at(samplerInfo));
|
gfx_->UpdateDescriptorCombinedImageSampler(descriptor_set_, 0, image_, renderData->samplers.at(samplerInfo));
|
||||||
|
|
||||||
LOG_INFO("Loaded texture: {}, width: {} height: {}", path, width, height);
|
LOG_INFO("Loaded texture: {}, width: {} height: {}", path, width, height);
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ Texture::Texture(RenderData* renderData, const std::string& path, Filtering filt
|
|||||||
|
|
||||||
Texture::~Texture()
|
Texture::~Texture()
|
||||||
{
|
{
|
||||||
m_gfxDevice->DestroyImage(m_image);
|
gfx_->DestroyImage(image_);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace engine {
|
|||||||
|
|
||||||
uint32_t Scene::getEntity(const std::string& tag, uint32_t parent)
|
uint32_t Scene::getEntity(const std::string& tag, uint32_t parent)
|
||||||
{
|
{
|
||||||
return GetSystem<TransformSystem>()->getChildEntity(parent, tag);
|
return GetSystem<TransformSystem>()->GetChildEntity(parent, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Scene::GetComponentSignaturePosition(size_t hash)
|
size_t Scene::GetComponentSignaturePosition(size_t hash)
|
||||||
|
@ -75,10 +75,10 @@ namespace engine {
|
|||||||
{
|
{
|
||||||
(void)entity;
|
(void)entity;
|
||||||
const size_t size = entities_.size();
|
const size_t size = entities_.size();
|
||||||
m_staticAABBs.reserve(size);
|
static_aabbs_.reserve(size);
|
||||||
m_dynamicAABBs.reserve(size);
|
dynamic_aabbs_.reserve(size);
|
||||||
m_possibleCollisions.reserve(size);
|
possible_collisions_.reserve(size);
|
||||||
m_collisionInfos.reserve(size);
|
collision_infos_.reserve(size);
|
||||||
LOG_TRACE("added entity {} to collider system", entity);
|
LOG_TRACE("added entity {} to collider system", entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,16 +86,16 @@ namespace engine {
|
|||||||
{
|
{
|
||||||
(void)ts;
|
(void)ts;
|
||||||
|
|
||||||
m_staticAABBs.clear();
|
static_aabbs_.clear();
|
||||||
m_dynamicAABBs.clear();
|
dynamic_aabbs_.clear();
|
||||||
m_possibleCollisions.clear();
|
possible_collisions_.clear();
|
||||||
m_collisionInfos.clear();
|
collision_infos_.clear();
|
||||||
|
|
||||||
for (uint32_t entity : entities_) {
|
for (uint32_t entity : entities_) {
|
||||||
const auto t = scene_->GetComponent<TransformComponent>(entity);
|
const auto t = scene_->GetComponent<TransformComponent>(entity);
|
||||||
const auto c = scene_->GetComponent<ColliderComponent>(entity);
|
const auto c = scene_->GetComponent<ColliderComponent>(entity);
|
||||||
|
|
||||||
const glm::vec3 globalPosition = t->worldMatrix[3];
|
const glm::vec3 globalPosition = t->world_matrix[3];
|
||||||
const AABB localBoundingBox = c->aabb;
|
const AABB localBoundingBox = c->aabb;
|
||||||
AABB globalBoundingBox{};
|
AABB globalBoundingBox{};
|
||||||
globalBoundingBox.pos1 = globalPosition + localBoundingBox.pos1;
|
globalBoundingBox.pos1 = globalPosition + localBoundingBox.pos1;
|
||||||
@ -106,10 +106,10 @@ namespace engine {
|
|||||||
if (a.pos1.y > a.pos2.y) std::swap(a.pos1.y, a.pos2.y);
|
if (a.pos1.y > a.pos2.y) std::swap(a.pos1.y, a.pos2.y);
|
||||||
if (a.pos1.z > a.pos2.z) std::swap(a.pos1.z, a.pos2.z);
|
if (a.pos1.z > a.pos2.z) std::swap(a.pos1.z, a.pos2.z);
|
||||||
|
|
||||||
if (c->isStatic) {
|
if (c->is_static) {
|
||||||
m_staticAABBs.emplace_back(std::make_tuple(entity, globalBoundingBox, c->isTrigger));
|
static_aabbs_.emplace_back(std::make_tuple(entity, globalBoundingBox, c->is_trigger));
|
||||||
} else {
|
} else {
|
||||||
m_dynamicAABBs.emplace_back(std::make_tuple(entity, globalBoundingBox, c->isTrigger));
|
dynamic_aabbs_.emplace_back(std::make_tuple(entity, globalBoundingBox, c->is_trigger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,11 +117,11 @@ namespace engine {
|
|||||||
|
|
||||||
// Check every static collider against every dynamic collider, and every dynamic collider against every other one
|
// Check every static collider against every dynamic collider, and every dynamic collider against every other one
|
||||||
// This technique is inefficient for many entities.
|
// This technique is inefficient for many entities.
|
||||||
for (const auto& [staticEntity, staticAABB, staticTrigger] : m_staticAABBs) {
|
for (const auto& [staticEntity, staticAABB, staticTrigger] : static_aabbs_) {
|
||||||
for (const auto& [dynamicEntity, dynamicAABB, dynamicTrigger] : m_dynamicAABBs) {
|
for (const auto& [dynamicEntity, dynamicAABB, dynamicTrigger] : dynamic_aabbs_) {
|
||||||
if (checkCollisionFast(staticAABB, dynamicAABB)) {
|
if (checkCollisionFast(staticAABB, dynamicAABB)) {
|
||||||
if (staticTrigger || dynamicTrigger) { // only check collisions involved with triggers
|
if (staticTrigger || dynamicTrigger) { // only check collisions involved with triggers
|
||||||
m_possibleCollisions.emplace_back(
|
possible_collisions_.emplace_back(
|
||||||
staticEntity, staticAABB, staticTrigger,
|
staticEntity, staticAABB, staticTrigger,
|
||||||
dynamicEntity, dynamicAABB, dynamicTrigger
|
dynamicEntity, dynamicAABB, dynamicTrigger
|
||||||
);
|
);
|
||||||
@ -131,32 +131,32 @@ namespace engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get collision details and submit events
|
// get collision details and submit events
|
||||||
for (const auto& possibleCollision : m_possibleCollisions) {
|
for (const auto& possibleCollision : possible_collisions_) {
|
||||||
if (possibleCollision.staticTrigger) {
|
if (possibleCollision.static_trigger) {
|
||||||
CollisionEvent info{};
|
CollisionEvent info{};
|
||||||
info.isCollisionEnter = true;
|
info.is_collision_enter = true;
|
||||||
info.collidedEntity = possibleCollision.dynamicEntity;
|
info.collided_entity = possibleCollision.dynamic_entity;
|
||||||
info.normal = getAABBNormal(possibleCollision.staticAABB, possibleCollision.dynamicAABB);
|
info.normal = getAABBNormal(possibleCollision.static_aabb, possibleCollision.dynamic_aabb);
|
||||||
|
|
||||||
AABB object = possibleCollision.dynamicAABB;
|
AABB object = possibleCollision.dynamic_aabb;
|
||||||
info.point = object.pos2;
|
info.point = object.pos2;
|
||||||
|
|
||||||
m_collisionInfos.emplace_back(possibleCollision.staticEntity, info);
|
collision_infos_.emplace_back(possibleCollision.static_entity, info);
|
||||||
}
|
}
|
||||||
if (possibleCollision.dynamicTrigger) {
|
if (possibleCollision.dynamic_trigger) {
|
||||||
CollisionEvent info{};
|
CollisionEvent info{};
|
||||||
info.isCollisionEnter = true;
|
info.is_collision_enter = true;
|
||||||
info.collidedEntity = possibleCollision.staticEntity;
|
info.collided_entity = possibleCollision.static_entity;
|
||||||
info.normal = getAABBNormal(possibleCollision.dynamicAABB, possibleCollision.staticAABB);
|
info.normal = getAABBNormal(possibleCollision.dynamic_aabb, possibleCollision.static_aabb);
|
||||||
|
|
||||||
AABB object = possibleCollision.staticAABB;
|
AABB object = possibleCollision.static_aabb;
|
||||||
info.point = object.pos2;
|
info.point = object.pos2;
|
||||||
|
|
||||||
m_collisionInfos.emplace_back(possibleCollision.dynamicEntity, info);
|
collision_infos_.emplace_back(possibleCollision.dynamic_entity, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& [entity, info] : m_collisionInfos) {
|
for (const auto& [entity, info] : collision_infos_) {
|
||||||
scene_->event_system()->QueueEvent<CollisionEvent>(EventSubscriberKind::kEntity, entity, info);
|
scene_->event_system()->QueueEvent<CollisionEvent>(EventSubscriberKind::kEntity, entity, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace engine {
|
|||||||
|
|
||||||
RenderSystem::RenderSystem(Scene* scene)
|
RenderSystem::RenderSystem(Scene* scene)
|
||||||
: System(scene, { typeid(TransformComponent).hash_code(), typeid(RenderableComponent).hash_code() }),
|
: System(scene, { typeid(TransformComponent).hash_code(), typeid(RenderableComponent).hash_code() }),
|
||||||
m_gfx(scene_->app()->gfxdev())
|
gfx_(scene_->app()->gfxdev())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,30 +31,30 @@ namespace engine {
|
|||||||
RenderData& renderData = scene_->app()->render_data_;
|
RenderData& renderData = scene_->app()->render_data_;
|
||||||
|
|
||||||
/* camera stuff */
|
/* camera stuff */
|
||||||
const auto cameraTransform = scene_->GetComponent<TransformComponent>(m_camera.camEntity);
|
const auto cameraTransform = scene_->GetComponent<TransformComponent>(camera_.cam_entity);
|
||||||
|
|
||||||
// do not render if camera is not set
|
// do not render if camera is not set
|
||||||
if (cameraTransform == nullptr) return;
|
if (cameraTransform == nullptr) return;
|
||||||
|
|
||||||
glm::mat4 viewMatrix = glm::inverse(cameraTransform->worldMatrix);
|
glm::mat4 viewMatrix = glm::inverse(cameraTransform->world_matrix);
|
||||||
|
|
||||||
if (scene_->app()->window()->GetWindowResized()) {
|
if (scene_->app()->window()->GetWindowResized()) {
|
||||||
uint32_t w, h;
|
uint32_t w, h;
|
||||||
m_gfx->GetViewportSize(&w, &h);
|
gfx_->GetViewportSize(&w, &h);
|
||||||
m_viewportAspectRatio = (float)w / (float)h;
|
viewport_aspect_ratio_ = (float)w / (float)h;
|
||||||
const float verticalFovRadians = glm::radians(m_camera.verticalFovDegrees);
|
const float verticalFovRadians = glm::radians(camera_.vertical_fov_degrees);
|
||||||
const glm::mat4 projMatrix = glm::perspectiveZO(verticalFovRadians, m_viewportAspectRatio, m_camera.clipNear, m_camera.clipFar);
|
const glm::mat4 projMatrix = glm::perspectiveZO(verticalFovRadians, viewport_aspect_ratio_, camera_.clip_near, camera_.clip_far);
|
||||||
/* update SET 0 */
|
/* update SET 0 */
|
||||||
RenderData::GlobalSetUniformBuffer globalSetUniformBuffer{
|
RenderData::GlobalSetUniformBuffer globalSetUniformBuffer{
|
||||||
.proj = projMatrix
|
.proj = projMatrix
|
||||||
};
|
};
|
||||||
m_gfx->WriteUniformBuffer(renderData.global_set_uniform_buffer, 0, sizeof(RenderData::GlobalSetUniformBuffer), &globalSetUniformBuffer);
|
gfx_->WriteUniformBuffer(renderData.global_set_uniform_buffer, 0, sizeof(RenderData::GlobalSetUniformBuffer), &globalSetUniformBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderData::FrameSetUniformBuffer frameSetUniformBuffer{
|
RenderData::FrameSetUniformBuffer frameSetUniformBuffer{
|
||||||
.view = viewMatrix
|
.view = viewMatrix
|
||||||
};
|
};
|
||||||
m_gfx->WriteUniformBuffer(renderData.frame_set_uniform_buffer, 0, sizeof(RenderData::FrameSetUniformBuffer), &frameSetUniformBuffer);
|
gfx_->WriteUniformBuffer(renderData.frame_set_uniform_buffer, 0, sizeof(RenderData::FrameSetUniformBuffer), &frameSetUniformBuffer);
|
||||||
|
|
||||||
/* render all renderable entities */
|
/* render all renderable entities */
|
||||||
|
|
||||||
@ -76,52 +76,52 @@ namespace engine {
|
|||||||
auto r = scene_->GetComponent<RenderableComponent>(entity);
|
auto r = scene_->GetComponent<RenderableComponent>(entity);
|
||||||
assert(r != nullptr);
|
assert(r != nullptr);
|
||||||
assert(r->material != nullptr);
|
assert(r->material != nullptr);
|
||||||
assert(r->material->m_texture != nullptr);
|
assert(r->material->texture_ != nullptr);
|
||||||
assert(r->mesh != nullptr);
|
assert(r->mesh != nullptr);
|
||||||
if (r->shown == false) continue;
|
if (r->shown == false) continue;
|
||||||
|
|
||||||
auto t = scene_->GetComponent<TransformComponent>(entity);
|
auto t = scene_->GetComponent<TransformComponent>(entity);
|
||||||
assert(t != nullptr);
|
assert(t != nullptr);
|
||||||
|
|
||||||
const gfx::Pipeline* pipeline = r->material->getShader()->getPipeline();
|
const gfx::Pipeline* pipeline = r->material->GetShader()->GetPipeline();
|
||||||
DrawCallData data{};
|
DrawCallData data{};
|
||||||
data.vb = r->mesh->getVB();
|
data.vb = r->mesh->GetVB();
|
||||||
data.ib = r->mesh->getIB();
|
data.ib = r->mesh->GetIB();
|
||||||
data.materialSet = r->material->m_texture->getDescriptorSet();
|
data.materialSet = r->material->texture_->GetDescriptorSet();
|
||||||
data.indexCount = r->mesh->getCount();
|
data.indexCount = r->mesh->GetCount();
|
||||||
data.pushConsts.model = t->worldMatrix;
|
data.pushConsts.model = t->world_matrix;
|
||||||
|
|
||||||
pipelineDrawCalls[pipeline].push_back(data);
|
pipelineDrawCalls[pipeline].push_back(data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* begin rendering */
|
/* begin rendering */
|
||||||
renderData.draw_buffer = m_gfx->BeginRender();
|
renderData.draw_buffer = gfx_->BeginRender();
|
||||||
|
|
||||||
/* these descriptor set bindings should persist across pipeline changes */
|
/* these descriptor set bindings should persist across pipeline changes */
|
||||||
const gfx::Pipeline* firstPipeline = pipelineDrawCalls.begin()->first;
|
const gfx::Pipeline* firstPipeline = pipelineDrawCalls.begin()->first;
|
||||||
m_gfx->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.global_set, 0);
|
gfx_->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.global_set, 0);
|
||||||
m_gfx->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.frame_set, 1);
|
gfx_->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.frame_set, 1);
|
||||||
|
|
||||||
for (const auto& [pipeline, drawCalls] : pipelineDrawCalls) {
|
for (const auto& [pipeline, drawCalls] : pipelineDrawCalls) {
|
||||||
m_gfx->CmdBindPipeline(renderData.draw_buffer, pipeline);
|
gfx_->CmdBindPipeline(renderData.draw_buffer, pipeline);
|
||||||
for (const auto& drawCall : drawCalls) {
|
for (const auto& drawCall : drawCalls) {
|
||||||
m_gfx->CmdBindDescriptorSet(renderData.draw_buffer, pipeline, drawCall.materialSet, 2);
|
gfx_->CmdBindDescriptorSet(renderData.draw_buffer, pipeline, drawCall.materialSet, 2);
|
||||||
m_gfx->CmdPushConstants(renderData.draw_buffer, pipeline, 0, sizeof(PushConstants), &drawCall.pushConsts);
|
gfx_->CmdPushConstants(renderData.draw_buffer, pipeline, 0, sizeof(PushConstants), &drawCall.pushConsts);
|
||||||
m_gfx->CmdBindVertexBuffer(renderData.draw_buffer, 0, drawCall.vb);
|
gfx_->CmdBindVertexBuffer(renderData.draw_buffer, 0, drawCall.vb);
|
||||||
m_gfx->CmdBindIndexBuffer(renderData.draw_buffer, drawCall.ib);
|
gfx_->CmdBindIndexBuffer(renderData.draw_buffer, drawCall.ib);
|
||||||
m_gfx->CmdDrawIndexed(renderData.draw_buffer, drawCall.indexCount, 1, 0, 0, 0);
|
gfx_->CmdDrawIndexed(renderData.draw_buffer, drawCall.indexCount, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draw */
|
/* draw */
|
||||||
m_gfx->FinishRender(renderData.draw_buffer);
|
gfx_->FinishRender(renderData.draw_buffer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::setCameraEntity(uint32_t entity)
|
void RenderSystem::SetCameraEntity(uint32_t entity)
|
||||||
{
|
{
|
||||||
m_camera.camEntity = entity;
|
camera_.cam_entity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,14 @@ namespace engine {
|
|||||||
transform = glm::scale(transform, t->scale);
|
transform = glm::scale(transform, t->scale);
|
||||||
|
|
||||||
if (t->parent != 0) {
|
if (t->parent != 0) {
|
||||||
transform = scene_->GetComponent<TransformComponent>(t->parent)->worldMatrix * transform;
|
transform = scene_->GetComponent<TransformComponent>(t->parent)->world_matrix * transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->worldMatrix = transform;
|
t->world_matrix = transform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t TransformSystem::getChildEntity(uint32_t parent, const std::string& tag)
|
uint32_t TransformSystem::GetChildEntity(uint32_t parent, const std::string& tag)
|
||||||
{
|
{
|
||||||
for (uint32_t entity : entities_) {
|
for (uint32_t entity : entities_) {
|
||||||
auto t = scene_->GetComponent<TransformComponent>(entity);
|
auto t = scene_->GetComponent<TransformComponent>(entity);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace engine::util {
|
namespace engine::util {
|
||||||
|
|
||||||
std::unique_ptr<std::vector<char>> readTextFile(const std::string& path)
|
std::unique_ptr<std::vector<char>> ReadTextFile(const std::string& path)
|
||||||
{
|
{
|
||||||
auto buffer = std::make_unique<std::vector<char>>();
|
auto buffer = std::make_unique<std::vector<char>>();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ namespace engine::util {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::vector<uint8_t>> readBinaryFile(const std::string& path)
|
std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path)
|
||||||
{
|
{
|
||||||
std::ifstream file(path, std::ios::ate | std::ios::binary);
|
std::ifstream file(path, std::ios::ate | std::ios::binary);
|
||||||
if (file.is_open() == false) {
|
if (file.is_open() == false) {
|
||||||
@ -51,7 +51,7 @@ namespace engine::util {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::vector<uint8_t>> readImageFile(const std::string& path, int *width, int *height)
|
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path, int *width, int *height)
|
||||||
{
|
{
|
||||||
int x, y, n;
|
int x, y, n;
|
||||||
unsigned char *data = stbi_load(path.c_str(), &x, &y, &n, STBI_rgb_alpha);
|
unsigned char *data = stbi_load(path.c_str(), &x, &y, &n, STBI_rgb_alpha);
|
||||||
|
@ -79,9 +79,9 @@ namespace engine::util {
|
|||||||
childRenderer->mesh = meshes[parentNode->mMeshes[i]];
|
childRenderer->mesh = meshes[parentNode->mMeshes[i]];
|
||||||
childRenderer->material = std::make_shared<resources::Material>(scene->app()->GetResource<resources::Shader>("builtin.standard"));
|
childRenderer->material = std::make_shared<resources::Material>(scene->app()->GetResource<resources::Shader>("builtin.standard"));
|
||||||
if (textures.contains(meshTextureIndices[parentNode->mMeshes[i]])) {
|
if (textures.contains(meshTextureIndices[parentNode->mMeshes[i]])) {
|
||||||
childRenderer->material->m_texture = textures.at(meshTextureIndices[parentNode->mMeshes[i]]);
|
childRenderer->material->texture_ = textures.at(meshTextureIndices[parentNode->mMeshes[i]]);
|
||||||
} else {
|
} else {
|
||||||
childRenderer->material->m_texture = scene->app()->GetResource<resources::Texture>("builtin.white");
|
childRenderer->material->texture_ = scene->app()->GetResource<resources::Texture>("builtin.white");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ namespace engine::util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t loadMeshFromFile(Scene* parent, const std::string& path)
|
uint32_t LoadMeshFromFile(Scene* parent, const std::string& path)
|
||||||
{
|
{
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ namespace engine::util {
|
|||||||
try {
|
try {
|
||||||
textures[i] = std::make_shared<resources::Texture>(
|
textures[i] = std::make_shared<resources::Texture>(
|
||||||
&parent->app()->render_data_, absPath.string(),
|
&parent->app()->render_data_, absPath.string(),
|
||||||
resources::Texture::Filtering::TRILINEAR);
|
resources::Texture::Filtering::kTrilinear);
|
||||||
} catch (const std::runtime_error&) {
|
} catch (const std::runtime_error&) {
|
||||||
textures[i] = parent->app()->GetResource<resources::Texture>("builtin.white");
|
textures[i] = parent->app()->GetResource<resources::Texture>("builtin.white");
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ void CameraControllerSystem::OnUpdate(float ts)
|
|||||||
// called once per frame
|
// called once per frame
|
||||||
void CameraControllerSystem::OnEvent(engine::PhysicsSystem::CollisionEvent info)
|
void CameraControllerSystem::OnEvent(engine::PhysicsSystem::CollisionEvent info)
|
||||||
{
|
{
|
||||||
c->justCollided = info.isCollisionEnter;
|
c->justCollided = info.is_collision_enter;
|
||||||
c->lastCollisionNormal = info.normal;
|
c->lastCollisionNormal = info.normal;
|
||||||
c->lastCollisionPoint = info.point;
|
c->lastCollisionPoint = info.point;
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ void playGame(GameSettings settings)
|
|||||||
auto camera = myScene->CreateEntity("camera");
|
auto camera = myScene->CreateEntity("camera");
|
||||||
myScene->GetComponent<engine::TransformComponent>(camera)->position = { 0.0f, 10.0f, 0.0f };
|
myScene->GetComponent<engine::TransformComponent>(camera)->position = { 0.0f, 10.0f, 0.0f };
|
||||||
auto cameraCollider = myScene->AddComponent<engine::ColliderComponent>(camera);
|
auto cameraCollider = myScene->AddComponent<engine::ColliderComponent>(camera);
|
||||||
cameraCollider->isStatic = false;
|
cameraCollider->is_static = false;
|
||||||
cameraCollider->isTrigger = true;
|
cameraCollider->is_trigger = true;
|
||||||
cameraCollider->aabb = { { -0.2f, -1.5f, -0.2f }, { 0.2f, 0.2f, 0.2f} }; // Origin is at eye level
|
cameraCollider->aabb = { { -0.2f, -1.5f, -0.2f }, { 0.2f, 0.2f, 0.2f} }; // Origin is at eye level
|
||||||
myScene->AddComponent<CameraControllerComponent>(camera);
|
myScene->AddComponent<CameraControllerComponent>(camera);
|
||||||
myScene->event_system()->SubscribeToEventType<engine::PhysicsSystem::CollisionEvent>(
|
myScene->event_system()->SubscribeToEventType<engine::PhysicsSystem::CollisionEvent>(
|
||||||
@ -79,19 +79,19 @@ void playGame(GameSettings settings)
|
|||||||
);
|
);
|
||||||
|
|
||||||
auto renderSystem = myScene->GetSystem<engine::RenderSystem>();
|
auto renderSystem = myScene->GetSystem<engine::RenderSystem>();
|
||||||
renderSystem->setCameraEntity(camera);
|
renderSystem->SetCameraEntity(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* shared resources */
|
/* shared resources */
|
||||||
auto grassTexture = std::make_shared<engine::resources::Texture>(
|
auto grassTexture = std::make_shared<engine::resources::Texture>(
|
||||||
&app.render_data_,
|
&app.render_data_,
|
||||||
app.GetResourcePath("textures/grass.jpg"),
|
app.GetResourcePath("textures/grass.jpg"),
|
||||||
engine::resources::Texture::Filtering::ANISOTROPIC
|
engine::resources::Texture::Filtering::kAnisotropic
|
||||||
);
|
);
|
||||||
auto spaceTexture = std::make_shared<engine::resources::Texture>(
|
auto spaceTexture = std::make_shared<engine::resources::Texture>(
|
||||||
&app.render_data_,
|
&app.render_data_,
|
||||||
app.GetResourcePath("textures/space2.png"),
|
app.GetResourcePath("textures/space2.png"),
|
||||||
engine::resources::Texture::Filtering::ANISOTROPIC
|
engine::resources::Texture::Filtering::kAnisotropic
|
||||||
);
|
);
|
||||||
|
|
||||||
/* cube */
|
/* cube */
|
||||||
@ -100,10 +100,10 @@ void playGame(GameSettings settings)
|
|||||||
myScene->GetComponent<engine::TransformComponent>(cube)->position = glm::vec3{ -0.5f + 5.0f, -0.5f + 5.0f, -0.5f + 5.0f };
|
myScene->GetComponent<engine::TransformComponent>(cube)->position = glm::vec3{ -0.5f + 5.0f, -0.5f + 5.0f, -0.5f + 5.0f };
|
||||||
auto cubeRenderable = myScene->AddComponent<engine::RenderableComponent>(cube);
|
auto cubeRenderable = myScene->AddComponent<engine::RenderableComponent>(cube);
|
||||||
cubeRenderable->material = std::make_shared<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.standard"));
|
cubeRenderable->material = std::make_shared<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.standard"));
|
||||||
cubeRenderable->material->m_texture = app.GetResource<engine::resources::Texture>("builtin.white");
|
cubeRenderable->material->texture_ = app.GetResource<engine::resources::Texture>("builtin.white");
|
||||||
cubeRenderable->mesh = genCuboidMesh(app.gfxdev(), 1.0f, 1.0f, 1.0f, 1);
|
cubeRenderable->mesh = genCuboidMesh(app.gfxdev(), 1.0f, 1.0f, 1.0f, 1);
|
||||||
auto cubeCollider = myScene->AddComponent<engine::ColliderComponent>(cube);
|
auto cubeCollider = myScene->AddComponent<engine::ColliderComponent>(cube);
|
||||||
cubeCollider->isStatic = true;
|
cubeCollider->is_static = true;
|
||||||
cubeCollider->aabb = { { 0.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f } };
|
cubeCollider->aabb = { { 0.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f } };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,22 +113,22 @@ void playGame(GameSettings settings)
|
|||||||
myScene->GetComponent<engine::TransformComponent>(floor)->position = glm::vec3{-5000.0f, -1.0f, -5000.0f};
|
myScene->GetComponent<engine::TransformComponent>(floor)->position = glm::vec3{-5000.0f, -1.0f, -5000.0f};
|
||||||
auto floorRenderable = myScene->AddComponent<engine::RenderableComponent>(floor);
|
auto floorRenderable = myScene->AddComponent<engine::RenderableComponent>(floor);
|
||||||
floorRenderable->material = std::make_shared<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.standard"));
|
floorRenderable->material = std::make_shared<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.standard"));
|
||||||
floorRenderable->material->m_texture = grassTexture;
|
floorRenderable->material->texture_ = grassTexture;
|
||||||
floorRenderable->mesh = genCuboidMesh(app.gfxdev(), 10000.0f, 1.0f, 10000.0f, 5000.0f);
|
floorRenderable->mesh = genCuboidMesh(app.gfxdev(), 10000.0f, 1.0f, 10000.0f, 5000.0f);
|
||||||
floorRenderable->shown = true;
|
floorRenderable->shown = true;
|
||||||
auto floorCollider = myScene->AddComponent<engine::ColliderComponent>(floor);
|
auto floorCollider = myScene->AddComponent<engine::ColliderComponent>(floor);
|
||||||
floorCollider->isStatic = true;
|
floorCollider->is_static = true;
|
||||||
floorCollider->aabb = { { 0.0f, 0.0f, 0.0f }, { 10000.0f, 1.0f, 10000.0f } };
|
floorCollider->aabb = { { 0.0f, 0.0f, 0.0f }, { 10000.0f, 1.0f, 10000.0f } };
|
||||||
}
|
}
|
||||||
|
|
||||||
//engine::util::loadMeshFromFile(myScene, app.GetResourcePath("models/astronaut/astronaut.dae"));
|
//engine::util::LoadMeshFromFile(myScene, app.GetResourcePath("models/astronaut/astronaut.dae"));
|
||||||
|
|
||||||
/* skybox */
|
/* skybox */
|
||||||
{
|
{
|
||||||
uint32_t skybox = myScene->CreateEntity("skybox");
|
uint32_t skybox = myScene->CreateEntity("skybox");
|
||||||
auto skyboxRenderable = myScene->AddComponent<engine::RenderableComponent>(skybox);
|
auto skyboxRenderable = myScene->AddComponent<engine::RenderableComponent>(skybox);
|
||||||
skyboxRenderable->material = std::make_unique<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.skybox"));
|
skyboxRenderable->material = std::make_unique<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.skybox"));
|
||||||
skyboxRenderable->material->m_texture = spaceTexture;
|
skyboxRenderable->material->texture_ = spaceTexture;
|
||||||
skyboxRenderable->mesh = genCuboidMesh(app.gfxdev(), 10.0f, 10.0f, 10.0f, 1.0f, true);
|
skyboxRenderable->mesh = genCuboidMesh(app.gfxdev(), 10.0f, 10.0f, 10.0f, 1.0f, true);
|
||||||
myScene->GetComponent<engine::TransformComponent>(skybox)->position = { -5.0f, -5.0f, -5.0f };
|
myScene->GetComponent<engine::TransformComponent>(skybox)->position = { -5.0f, -5.0f, -5.0f };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user