mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Move everything into namespace
This commit is contained in:
parent
c2ec967a89
commit
81031c9c10
@ -11,7 +11,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
namespace components {
|
||||
namespace engine::components {
|
||||
|
||||
class ENGINE_API Camera : public Component {
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
namespace engine {
|
||||
class Window;
|
||||
class Input;
|
||||
}
|
||||
|
||||
class Object;
|
||||
class ResourceManager;
|
||||
@ -44,3 +43,5 @@ private:
|
||||
TypeEnum m_type;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
namespace components {
|
||||
namespace engine::components {
|
||||
|
||||
class ENGINE_API CustomComponent : public Component {
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace components {
|
||||
namespace engine::components {
|
||||
|
||||
class ENGINE_API Renderer : public Component {
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
namespace components {
|
||||
namespace engine::components {
|
||||
|
||||
class ENGINE_API UI : public Component {
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace gfx {
|
||||
namespace engine {
|
||||
|
||||
enum class ShaderType {
|
||||
VERTEX,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
// Keyboard scancodes, taken from SDL_scancode.h
|
||||
|
||||
namespace inputs {
|
||||
namespace engine::inputs {
|
||||
|
||||
enum class Key : int {
|
||||
UNKNOWN = 0,
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace inputs {
|
||||
namespace engine::inputs {
|
||||
|
||||
enum class MouseButton : int {
|
||||
M_LEFT,
|
||||
|
@ -15,7 +15,7 @@
|
||||
namespace engine {
|
||||
class Window;
|
||||
class Input;
|
||||
}
|
||||
|
||||
class ResourceManager;
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,8 @@
|
||||
|
||||
// Doesn't own resources, only holds weak_ptrs
|
||||
|
||||
namespace engine {
|
||||
|
||||
class ENGINE_API ResourceManager {
|
||||
|
||||
public:
|
||||
@ -79,3 +81,5 @@ std::shared_ptr<T> ResourceManager::get(const std::string& name)
|
||||
return create<T>(name);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
class ENGINE_API Font : public Resource {
|
||||
|
||||
|
@ -20,7 +20,7 @@ struct Vertex {
|
||||
glm::vec2 uv;
|
||||
};
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
class ENGINE_API Mesh : public Resource {
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
namespace engine {
|
||||
|
||||
class ENGINE_API Resource {
|
||||
|
||||
public:
|
||||
@ -22,3 +24,5 @@ private:
|
||||
const std::string m_type;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
class ENGINE_API Shader : public Resource {
|
||||
|
||||
@ -40,7 +40,7 @@ public:
|
||||
|
||||
static void invalidate()
|
||||
{
|
||||
s_activeProgram = -1;
|
||||
s_activeProgram = std::numeric_limits<GLuint>::max();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
class ENGINE_API Texture : public Resource {
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace engine {
|
||||
|
||||
// Holds everything you would expect to find in a game scene
|
||||
class ENGINE_API SceneRoot : public Object {
|
||||
|
||||
@ -27,3 +29,5 @@ private:
|
||||
std::vector<int> m_activeCameras{};
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct ENGINE_API Transform {
|
||||
|
||||
// Scale, rotate (XYZ), translate
|
||||
@ -15,3 +17,5 @@ struct ENGINE_API Transform {
|
||||
glm::vec3 scale{ 1.0f };
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -22,7 +22,7 @@ namespace engine {
|
||||
class ENGINE_API Window {
|
||||
|
||||
public:
|
||||
Window(const std::string& title);
|
||||
Window(const std::string& title, bool resizable = true);
|
||||
Window(const Window&) = delete;
|
||||
Window& operator=(const Window&) = delete;
|
||||
~Window();
|
||||
@ -52,7 +52,7 @@ namespace engine {
|
||||
// Returns true if the window should remain open
|
||||
bool isRunning() const;
|
||||
|
||||
void setFullscreen(bool fullscreen, bool exclusive = true);
|
||||
void setFullscreen(bool fullscreen, bool exclusive = false);
|
||||
void toggleFullscreen();
|
||||
|
||||
bool isFullscreen() const;
|
||||
@ -139,6 +139,8 @@ namespace engine {
|
||||
|
||||
std::string m_title;
|
||||
|
||||
bool m_resizable;
|
||||
|
||||
bool m_fullscreen = false;
|
||||
bool m_justResized = false;
|
||||
bool m_keyboardFocus = true;
|
||||
|
@ -13,7 +13,7 @@ static const std::string VIEW_MAT_UNIFORM = "viewMat";
|
||||
static const std::string PROJ_MAT_UNIFORM = "projMat";
|
||||
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};
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace engine {
|
||||
|
||||
int Component::s_next_component_id = 0;
|
||||
|
||||
Component::Component(Object* parent, TypeEnum type) :
|
||||
@ -28,3 +30,5 @@ Component::TypeEnum Component::getType()
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "components/custom.hpp"
|
||||
|
||||
namespace components {
|
||||
namespace engine::components {
|
||||
|
||||
CustomComponent::CustomComponent(Object* parent) : Component(parent, TypeEnum::CUSTOM)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace components {
|
||||
namespace engine::components {
|
||||
|
||||
Renderer::Renderer(Object* parent) : Component(parent, TypeEnum::RENDERER)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "resource_manager.hpp"
|
||||
#include "resources/texture.hpp"
|
||||
|
||||
namespace components {
|
||||
namespace engine::components {
|
||||
|
||||
UI::UI(Object* parent) : Component(parent, TypeEnum::UI)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ namespace engine {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@ -34,12 +34,7 @@ namespace engine {
|
||||
}
|
||||
|
||||
if (m_win->getKeyPress(inputs::Key::F11)) {
|
||||
if (m_win->isFullscreen()) {
|
||||
m_win->setFullscreen(false);
|
||||
}
|
||||
else {
|
||||
m_win->setFullscreen(true, false); // borderless window
|
||||
}
|
||||
m_win->toggleFullscreen();
|
||||
}
|
||||
if (m_win->getKeyPress(inputs::Key::ESCAPE)) {
|
||||
m_win->setCloseFlag();
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include <log.hpp>
|
||||
|
||||
namespace engine {
|
||||
|
||||
int Object::s_object_count = 0;
|
||||
|
||||
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++) {
|
||||
if (i + 1 == level) {
|
||||
buf += "\\_______";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
buf += " ";
|
||||
}
|
||||
}
|
||||
@ -131,3 +134,5 @@ void Object::getAllSubComponents(struct CompList& compList, glm::mat4 parentTran
|
||||
child->getAllSubComponents(compList, newTransform);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
ResourceManager::ResourceManager()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
@ -21,7 +23,8 @@ ResourceManager::ResourceManager()
|
||||
|
||||
if (std::filesystem::is_directory(cwd / "res")) {
|
||||
m_resourcesPath = cwd / "res";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
m_resourcesPath = cwd.parent_path() / "share" / "sdltest";
|
||||
}
|
||||
|
||||
@ -73,3 +76,5 @@ std::filesystem::path ResourceManager::getFilePath(const std::string& name)
|
||||
{
|
||||
return m_resourcesPath / name;
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font")
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "resources/mesh.hpp"
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
struct MeshFileHeader {
|
||||
unsigned int vertex_count;
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <log.hpp>
|
||||
|
||||
namespace engine {
|
||||
|
||||
Resource::Resource(const std::filesystem::path& resPath, const std::string& type) : m_resourcePath(resPath), m_type(type)
|
||||
{
|
||||
if (m_type != "mesh")
|
||||
@ -18,3 +20,5 @@ std::string Resource::getType()
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
}
|
@ -50,7 +50,7 @@ static GLuint compile(const char *path, GLenum type)
|
||||
} return handle;
|
||||
}
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
// I've got to do this because of GL's stupid state machine
|
||||
GLuint Shader::s_activeProgram = 0;
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace resources {
|
||||
namespace engine::resources {
|
||||
|
||||
// -1 means invalid / no bind
|
||||
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;
|
||||
}
|
||||
|
||||
const size_t size = x * y * n;
|
||||
const size_t size = (size_t)x * (size_t)y * (size_t)n;
|
||||
|
||||
texbuf.resize(size);
|
||||
memcpy(texbuf.data(), data, size);
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
SceneRoot::SceneRoot(struct GameIO things) : Object("root", nullptr, *this, things)
|
||||
{
|
||||
}
|
||||
@ -88,3 +90,5 @@ void SceneRoot::deactivateCam(int id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ const uint64_t BILLION = 1000000000;
|
||||
|
||||
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
|
||||
@ -26,13 +26,23 @@ namespace engine {
|
||||
m_lastFrameStamp = m_startTime - 1;
|
||||
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
|
||||
m_handle = SDL_CreateWindow(
|
||||
m_title.c_str(),
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
static_cast<int>(m_winSize.x),
|
||||
static_cast<int>(m_winSize.y),
|
||||
SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
|
||||
windowFlags);
|
||||
if (m_handle == NULL) {
|
||||
SDL_Quit();
|
||||
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)
|
||||
{
|
||||
if (m_resizable) {
|
||||
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");
|
||||
}
|
||||
@ -288,6 +299,7 @@ namespace engine {
|
||||
onResize(width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::toggleFullscreen()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user