Move everything into namespace

This commit is contained in:
Bailey Harrison 2022-10-06 11:30:44 +01:00
parent c2ec967a89
commit 81031c9c10
33 changed files with 581 additions and 531 deletions

View File

@ -11,7 +11,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/ext.hpp> #include <glm/ext.hpp>
namespace components { namespace engine::components {
class ENGINE_API Camera : public Component { class ENGINE_API Camera : public Component {

View File

@ -5,7 +5,6 @@
namespace engine { namespace engine {
class Window; class Window;
class Input; class Input;
}
class Object; class Object;
class ResourceManager; class ResourceManager;
@ -44,3 +43,5 @@ private:
TypeEnum m_type; TypeEnum m_type;
}; };
}

View File

@ -6,7 +6,7 @@
#include <glm/mat4x4.hpp> #include <glm/mat4x4.hpp>
namespace components { namespace engine::components {
class ENGINE_API CustomComponent : public Component { class ENGINE_API CustomComponent : public Component {

View File

@ -12,7 +12,7 @@
#include <string> #include <string>
#include <memory> #include <memory>
namespace components { namespace engine::components {
class ENGINE_API Renderer : public Component { class ENGINE_API Renderer : public Component {

View File

@ -9,7 +9,7 @@
#include <glm/mat4x4.hpp> #include <glm/mat4x4.hpp>
namespace components { namespace engine::components {
class ENGINE_API UI : public Component { class ENGINE_API UI : public Component {

View File

@ -3,7 +3,7 @@
#include <cstdint> #include <cstdint>
#include <cstddef> #include <cstddef>
namespace gfx { namespace engine {
enum class ShaderType { enum class ShaderType {
VERTEX, VERTEX,

View File

@ -2,7 +2,7 @@
// Keyboard scancodes, taken from SDL_scancode.h // Keyboard scancodes, taken from SDL_scancode.h
namespace inputs { namespace engine::inputs {
enum class Key : int { enum class Key : int {
UNKNOWN = 0, UNKNOWN = 0,

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
namespace inputs { namespace engine::inputs {
enum class MouseButton : int { enum class MouseButton : int {
M_LEFT, M_LEFT,

View File

@ -15,7 +15,7 @@
namespace engine { namespace engine {
class Window; class Window;
class Input; class Input;
}
class ResourceManager; class ResourceManager;
class SceneRoot; class SceneRoot;
@ -140,3 +140,5 @@ template<class T> void Object::deleteComponent()
} }
throw std::runtime_error("deleteComponent() error: attempt to delete component that is not present."); throw std::runtime_error("deleteComponent() error: attempt to delete component that is not present.");
} }
}

View File

@ -9,6 +9,8 @@
// Doesn't own resources, only holds weak_ptrs // Doesn't own resources, only holds weak_ptrs
namespace engine {
class ENGINE_API ResourceManager { class ENGINE_API ResourceManager {
public: public:
@ -79,3 +81,5 @@ std::shared_ptr<T> ResourceManager::get(const std::string& name)
return create<T>(name); return create<T>(name);
} }
}

View File

@ -10,7 +10,7 @@
#include <map> #include <map>
namespace resources { namespace engine::resources {
class ENGINE_API Font : public Resource { class ENGINE_API Font : public Resource {

View File

@ -20,7 +20,7 @@ struct Vertex {
glm::vec2 uv; glm::vec2 uv;
}; };
namespace resources { namespace engine::resources {
class ENGINE_API Mesh : public Resource { class ENGINE_API Mesh : public Resource {

View File

@ -5,6 +5,8 @@
#include <string> #include <string>
#include <filesystem> #include <filesystem>
namespace engine {
class ENGINE_API Resource { class ENGINE_API Resource {
public: public:
@ -22,3 +24,5 @@ private:
const std::string m_type; const std::string m_type;
}; };
}

View File

@ -11,7 +11,7 @@
#include <string> #include <string>
#include <map> #include <map>
namespace resources { namespace engine::resources {
class ENGINE_API Shader : public Resource { class ENGINE_API Shader : public Resource {
@ -40,7 +40,7 @@ public:
static void invalidate() static void invalidate()
{ {
s_activeProgram = -1; s_activeProgram = std::numeric_limits<GLuint>::max();
} }
private: private:

View File

@ -6,7 +6,7 @@
#include <glad/glad.h> #include <glad/glad.h>
namespace resources { namespace engine::resources {
class ENGINE_API Texture : public Resource { class ENGINE_API Texture : public Resource {

View File

@ -6,6 +6,8 @@
#include <filesystem> #include <filesystem>
namespace engine {
// Holds everything you would expect to find in a game scene // Holds everything you would expect to find in a game scene
class ENGINE_API SceneRoot : public Object { class ENGINE_API SceneRoot : public Object {
@ -27,3 +29,5 @@ private:
std::vector<int> m_activeCameras{}; std::vector<int> m_activeCameras{};
}; };
}

View File

@ -6,6 +6,8 @@
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
#include <glm/ext/quaternion_float.hpp> #include <glm/ext/quaternion_float.hpp>
namespace engine {
struct ENGINE_API Transform { struct ENGINE_API Transform {
// Scale, rotate (XYZ), translate // Scale, rotate (XYZ), translate
@ -15,3 +17,5 @@ struct ENGINE_API Transform {
glm::vec3 scale{ 1.0f }; glm::vec3 scale{ 1.0f };
}; };
}

View File

@ -22,7 +22,7 @@ namespace engine {
class ENGINE_API Window { class ENGINE_API Window {
public: public:
Window(const std::string& title); Window(const std::string& title, bool resizable = true);
Window(const Window&) = delete; Window(const Window&) = delete;
Window& operator=(const Window&) = delete; Window& operator=(const Window&) = delete;
~Window(); ~Window();
@ -52,7 +52,7 @@ namespace engine {
// Returns true if the window should remain open // Returns true if the window should remain open
bool isRunning() const; bool isRunning() const;
void setFullscreen(bool fullscreen, bool exclusive = true); void setFullscreen(bool fullscreen, bool exclusive = false);
void toggleFullscreen(); void toggleFullscreen();
bool isFullscreen() const; bool isFullscreen() const;
@ -139,6 +139,8 @@ namespace engine {
std::string m_title; std::string m_title;
bool m_resizable;
bool m_fullscreen = false; bool m_fullscreen = false;
bool m_justResized = false; bool m_justResized = false;
bool m_keyboardFocus = true; bool m_keyboardFocus = true;

View File

@ -13,7 +13,7 @@ static const std::string VIEW_MAT_UNIFORM = "viewMat";
static const std::string PROJ_MAT_UNIFORM = "projMat"; static const std::string PROJ_MAT_UNIFORM = "projMat";
static const std::string WINDOW_SIZE_UNIFORM = "windowSize"; static const std::string WINDOW_SIZE_UNIFORM = "windowSize";
namespace components { namespace engine::components {
glm::vec4 Camera::s_clearColor{-999.0f, -999.0f, -999.0f, -999.0f}; glm::vec4 Camera::s_clearColor{-999.0f, -999.0f, -999.0f, -999.0f};

View File

@ -4,6 +4,8 @@
#include <iostream> #include <iostream>
namespace engine {
int Component::s_next_component_id = 0; int Component::s_next_component_id = 0;
Component::Component(Object* parent, TypeEnum type) : Component::Component(Object* parent, TypeEnum type) :
@ -28,3 +30,5 @@ Component::TypeEnum Component::getType()
{ {
return m_type; return m_type;
} }
}

View File

@ -1,6 +1,6 @@
#include "components/custom.hpp" #include "components/custom.hpp"
namespace components { namespace engine::components {
CustomComponent::CustomComponent(Object* parent) : Component(parent, TypeEnum::CUSTOM) CustomComponent::CustomComponent(Object* parent) : Component(parent, TypeEnum::CUSTOM)
{ {

View File

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
namespace components { namespace engine::components {
Renderer::Renderer(Object* parent) : Component(parent, TypeEnum::RENDERER) Renderer::Renderer(Object* parent) : Component(parent, TypeEnum::RENDERER)
{ {

View File

@ -4,7 +4,7 @@
#include "resource_manager.hpp" #include "resource_manager.hpp"
#include "resources/texture.hpp" #include "resources/texture.hpp"
namespace components { namespace engine::components {
UI::UI(Object* parent) : Component(parent, TypeEnum::UI) UI::UI(Object* parent) : Component(parent, TypeEnum::UI)
{ {

View File

@ -7,7 +7,7 @@ namespace engine {
Application::Application(const char* appName, const char* appVersion) Application::Application(const char* appName, const char* appVersion)
{ {
m_win = std::make_unique<Window>(appName); m_win = std::make_unique<Window>(appName, true);
m_gfx = std::make_unique<GFXDevice>(appName, appVersion, m_win->getHandle()); m_gfx = std::make_unique<GFXDevice>(appName, appVersion, m_win->getHandle());
} }
@ -34,12 +34,7 @@ namespace engine {
} }
if (m_win->getKeyPress(inputs::Key::F11)) { if (m_win->getKeyPress(inputs::Key::F11)) {
if (m_win->isFullscreen()) { m_win->toggleFullscreen();
m_win->setFullscreen(false);
}
else {
m_win->setFullscreen(true, false); // borderless window
}
} }
if (m_win->getKeyPress(inputs::Key::ESCAPE)) { if (m_win->getKeyPress(inputs::Key::ESCAPE)) {
m_win->setCloseFlag(); m_win->setCloseFlag();

View File

@ -7,6 +7,8 @@
#include <log.hpp> #include <log.hpp>
namespace engine {
int Object::s_object_count = 0; int Object::s_object_count = 0;
Object::Object(std::string name, Object* parent, SceneRoot& root, struct GameIO things) Object::Object(std::string name, Object* parent, SceneRoot& root, struct GameIO things)
@ -78,7 +80,8 @@ void Object::printTree(int level)
for (int i = 0; i < level; i++) { for (int i = 0; i < level; i++) {
if (i + 1 == level) { if (i + 1 == level) {
buf += "\\_______"; buf += "\\_______";
} else { }
else {
buf += " "; buf += " ";
} }
} }
@ -131,3 +134,5 @@ void Object::getAllSubComponents(struct CompList& compList, glm::mat4 parentTran
child->getAllSubComponents(compList, newTransform); child->getAllSubComponents(compList, newTransform);
} }
} }
}

View File

@ -8,6 +8,8 @@
#include "log.hpp" #include "log.hpp"
namespace engine {
ResourceManager::ResourceManager() ResourceManager::ResourceManager()
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
@ -21,7 +23,8 @@ ResourceManager::ResourceManager()
if (std::filesystem::is_directory(cwd / "res")) { if (std::filesystem::is_directory(cwd / "res")) {
m_resourcesPath = cwd / "res"; m_resourcesPath = cwd / "res";
} else { }
else {
m_resourcesPath = cwd.parent_path() / "share" / "sdltest"; m_resourcesPath = cwd.parent_path() / "share" / "sdltest";
} }
@ -73,3 +76,5 @@ std::filesystem::path ResourceManager::getFilePath(const std::string& name)
{ {
return m_resourcesPath / name; return m_resourcesPath / name;
} }
}

View File

@ -3,7 +3,7 @@
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
namespace resources { namespace engine::resources {
Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font") Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font")
{ {

View File

@ -1,6 +1,6 @@
#include "resources/mesh.hpp" #include "resources/mesh.hpp"
namespace resources { namespace engine::resources {
struct MeshFileHeader { struct MeshFileHeader {
unsigned int vertex_count; unsigned int vertex_count;

View File

@ -2,6 +2,8 @@
#include <log.hpp> #include <log.hpp>
namespace engine {
Resource::Resource(const std::filesystem::path& resPath, const std::string& type) : m_resourcePath(resPath), m_type(type) Resource::Resource(const std::filesystem::path& resPath, const std::string& type) : m_resourcePath(resPath), m_type(type)
{ {
if (m_type != "mesh") if (m_type != "mesh")
@ -18,3 +20,5 @@ std::string Resource::getType()
{ {
return m_type; return m_type;
} }
}

View File

@ -50,7 +50,7 @@ static GLuint compile(const char *path, GLenum type)
} return handle; } return handle;
} }
namespace resources { namespace engine::resources {
// I've got to do this because of GL's stupid state machine // I've got to do this because of GL's stupid state machine
GLuint Shader::s_activeProgram = 0; GLuint Shader::s_activeProgram = 0;

View File

@ -7,7 +7,7 @@
#include <vector> #include <vector>
namespace resources { namespace engine::resources {
// -1 means invalid / no bind // -1 means invalid / no bind
GLuint Texture::s_binded_texture = -1; GLuint Texture::s_binded_texture = -1;
@ -28,7 +28,7 @@ static bool readPNG(const std::string& path, std::vector<uint8_t>& texbuf, int *
return false; return false;
} }
const size_t size = x * y * n; const size_t size = (size_t)x * (size_t)y * (size_t)n;
texbuf.resize(size); texbuf.resize(size);
memcpy(texbuf.data(), data, size); memcpy(texbuf.data(), data, size);

View File

@ -14,6 +14,8 @@
#include "log.hpp" #include "log.hpp"
namespace engine {
SceneRoot::SceneRoot(struct GameIO things) : Object("root", nullptr, *this, things) SceneRoot::SceneRoot(struct GameIO things) : Object("root", nullptr, *this, things)
{ {
} }
@ -88,3 +90,5 @@ void SceneRoot::deactivateCam(int id)
} }
} }
} }
}

View File

@ -9,7 +9,7 @@ const uint64_t BILLION = 1000000000;
namespace engine { namespace engine {
Window::Window(const std::string& title) : m_title(title) Window::Window(const std::string& title, bool resizable) : m_title(title), m_resizable(resizable)
{ {
// init SDL // init SDL
@ -26,13 +26,23 @@ namespace engine {
m_lastFrameStamp = m_startTime - 1; m_lastFrameStamp = m_startTime - 1;
m_avgFpsStart = m_startTime; m_avgFpsStart = m_startTime;
Uint32 windowFlags = SDL_WINDOW_SHOWN;
#ifdef ENGINE_BUILD_VULKAN
windowFlags |= SDL_WINDOW_VULKAN;
#endif
if (m_resizable) {
windowFlags |= SDL_WINDOW_RESIZABLE;
}
// create the window // create the window
m_handle = SDL_CreateWindow( m_handle = SDL_CreateWindow(
m_title.c_str(), m_title.c_str(),
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
static_cast<int>(m_winSize.x), static_cast<int>(m_winSize.x),
static_cast<int>(m_winSize.y), static_cast<int>(m_winSize.y),
SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN); windowFlags);
if (m_handle == NULL) { if (m_handle == NULL) {
SDL_Quit(); SDL_Quit();
throw std::runtime_error("Unable to create window: " + std::string(SDL_GetError())); throw std::runtime_error("Unable to create window: " + std::string(SDL_GetError()));
@ -278,6 +288,7 @@ namespace engine {
void Window::setFullscreen(bool fullscreen, bool exclusive) void Window::setFullscreen(bool fullscreen, bool exclusive)
{ {
if (m_resizable) {
if (SDL_SetWindowFullscreen(m_handle, fullscreen ? (exclusive ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP) : 0) != 0) { if (SDL_SetWindowFullscreen(m_handle, fullscreen ? (exclusive ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP) : 0) != 0) {
throw std::runtime_error("Unable to set window to fullscreen/windowed"); throw std::runtime_error("Unable to set window to fullscreen/windowed");
} }
@ -288,6 +299,7 @@ namespace engine {
onResize(width, height); onResize(width, height);
} }
} }
}
void Window::toggleFullscreen() void Window::toggleFullscreen()
{ {