finish reformatting header files

This commit is contained in:
Bailey Harrison 2023-05-01 13:55:49 +01:00
parent 3ad0b8b6f8
commit e1b0b79d32
32 changed files with 776 additions and 744 deletions

View File

@ -1,6 +1,8 @@
#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 {
@ -15,11 +17,12 @@ namespace engine {
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 =
false; // entity receives an event on collision enter and exit
AABB aabb{}; // broad phase AABB aabb{}; // broad phase
private:
}; };
} } // namespace engine
#endif

View File

@ -1,13 +1,12 @@
#pragma once #ifndef ENGINE_INCLUDE_COMPONENTS_RENDERABLE_H_
#define ENGINE_INCLUDE_COMPONENTS_RENDERABLE_H_
#include <memory> #include <memory>
namespace engine { #include "resources/material.hpp"
#include "resources/mesh.hpp"
namespace resources { namespace engine {
class Mesh;
class Material;
}
struct RenderableComponent { struct RenderableComponent {
std::shared_ptr<resources::Mesh> mesh; std::shared_ptr<resources::Mesh> mesh;
@ -15,4 +14,6 @@ namespace engine {
bool shown = true; bool shown = true;
}; };
} } // namespace engine
#endif

View File

@ -1,8 +1,9 @@
#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>
@ -13,10 +14,12 @@ namespace engine {
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

View File

@ -1,4 +1,5 @@
#pragma once #ifndef ENGINE_INCLUDE_COMPONENTS_UI_ELEMENT_H_
#define ENGINE_INCLUDE_COMPONENTS_UI_ELEMENT_H_
namespace engine { namespace engine {
@ -6,4 +7,6 @@ namespace engine {
int n; int n;
}; };
} } // namespace engine
#endif

View File

@ -1,8 +1,10 @@
#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,
@ -371,4 +373,7 @@ enum class Key : int {
for array bounds */ for array bounds */
}; };
} } // namespace inputs
} // namespace engine
#endif

View File

@ -1,6 +1,8 @@
#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,
@ -12,11 +14,9 @@ enum class MouseButton : int {
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

View File

@ -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

View File

@ -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: public:
Material(std::shared_ptr<Shader> shader); Material(std::shared_ptr<Shader> shader);
~Material() = default; ~Material() = default;
Material(const Material&); Material(const Material&);
Material& operator=(const Material&) = delete; Material& operator=(const Material&) = delete;
auto getShader() { return m_shader.get(); } auto GetShader() { return shader_.get(); }
std::shared_ptr<Texture> m_texture; std::shared_ptr<Texture> texture_;
private: private:
const std::shared_ptr<Shader> m_shader; const std::shared_ptr<Shader> shader_;
}; };
} } // namespace resources
} // namespace engine
#endif

View File

@ -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>
namespace engine { #include "gfx.hpp"
#include "gfx_device.hpp"
class GFXDevice; namespace engine {
struct Vertex { struct Vertex {
glm::vec3 pos; glm::vec3 pos;
glm::vec3 norm; glm::vec3 norm;
glm::vec2 uv; glm::vec2 uv;
}; };
}
namespace engine::resources { } // namespace engine
namespace engine {
namespace resources {
class Mesh { class Mesh {
public: public:
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices); Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices);
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices) Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices,
: m_gfx(gfx) const std::vector<uint32_t>& indices)
{ : gfx_(gfx) {
initMesh(vertices, indices); InitMesh(vertices, indices);
} }
~Mesh(); ~Mesh();
Mesh(const Mesh&) = delete; Mesh(const Mesh&) = delete;
Mesh& operator=(const Mesh&) = delete; Mesh& operator=(const Mesh&) = delete;
const gfx::Buffer* getVB(); const gfx::Buffer* GetVB();
const gfx::Buffer* getIB(); const gfx::Buffer* GetIB();
uint32_t getCount(); uint32_t GetCount();
private: private:
GFXDevice* const m_gfx; GFXDevice* const gfx_;
const gfx::Buffer* m_vb; const gfx::Buffer* vb_;
const gfx::Buffer* m_ib; const gfx::Buffer* ib_;
uint32_t m_count; uint32_t count_;
void initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
void InitMesh(const std::vector<Vertex>& vertices,
const std::vector<uint32_t>& indices);
}; };
} } // namespace resources
} // namespace engine
#endif

View File

@ -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: public:
// defines what vertex inputs are defined, position is always vec3 // defines what vertex inputs are defined, position is always vec3
struct VertexParams { struct VertexParams {
bool hasNormal; // vec3 bool has_normal; // vec3
bool hasTangent; // vec3 bool has_tangent; // vec3
bool hasColor; // vec3 bool has_color; // vec3
bool hasUV0; // vec2 bool has_uv0; // vec2
}; };
Shader(RenderData* renderData, const char* vertPath, const char* fragPath, const VertexParams& vertexParams, bool alphaBlending, bool cullBackFace); Shader(RenderData* render_data, const char* vert_path, const char* frag_path,
const VertexParams& vertex_params, bool alpha_blending,
bool cull_backface);
~Shader(); ~Shader();
Shader(const Shader&) = delete; Shader(const Shader&) = delete;
Shader& operator=(const Shader&) = delete; Shader& operator=(const Shader&) = delete;
const gfx::Pipeline* getPipeline(); const gfx::Pipeline* GetPipeline();
private: private:
GFXDevice* const m_gfx; GFXDevice* const gfx_;
const gfx::Pipeline* m_pipeline; const gfx::Pipeline* pipeline_;
}; };
} } // namespace resources
} // namespace engine
#endif

View File

@ -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: public:
enum class Filtering { enum class Filtering {
OFF, kOff,
BILINEAR, kBilinear,
TRILINEAR, kTrilinear,
ANISOTROPIC, kAnisotropic,
}; };
Texture(RenderData* renderData, const std::string& path, Filtering filtering); Texture(RenderData* render_data, const std::string& path,
Filtering filtering);
~Texture(); ~Texture();
Texture(const Texture&) = delete; Texture(const Texture&) = delete;
Texture& operator=(const Texture&) = delete; Texture& operator=(const Texture&) = delete;
const gfx::Image* getImage() { return m_image; } const gfx::Image* GetImage() { return image_; }
const gfx::DescriptorSet* getDescriptorSet() { return m_descriptorSet; } const gfx::DescriptorSet* GetDescriptorSet() { return descriptor_set_; }
private: private:
GFXDevice* m_gfxDevice; GFXDevice* gfx_;
const gfx::Image* m_image; const gfx::Image* image_;
const gfx::DescriptorSet* m_descriptorSet; const gfx::DescriptorSet* descriptor_set_;
}; };
} } // namespace resources
} // namespace engine
#endif

View File

@ -1,9 +1,9 @@
#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"
@ -11,7 +11,6 @@
namespace engine { namespace engine {
class PhysicsSystem : public System { class PhysicsSystem : public System {
public: public:
PhysicsSystem(Scene* scene); PhysicsSystem(Scene* scene);
@ -20,41 +19,43 @@ namespace engine {
void OnComponentInsert(uint32_t entity) override; void OnComponentInsert(uint32_t entity) override;
struct CollisionEvent { struct CollisionEvent {
bool isCollisionEnter; // false == collision exit bool is_collision_enter; // false == collision exit
uint32_t collidedEntity; // the entity that this entity collided with 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 normal; // the normal of the surface this entity collided with;
// ignored on collision exit
glm::vec3 point; // where the collision was detected glm::vec3 point; // where the collision was detected
}; };
private: private:
// dynamic arrays to avoid realloc on every frame // dynamic arrays to avoid realloc on every frame
// entity, aabb, isTrigger // entity, aabb, is_trigger
std::vector<std::tuple<uint32_t, AABB, bool>> m_staticAABBs{}; std::vector<std::tuple<uint32_t, AABB, bool>> static_aabbs_{};
std::vector<std::tuple<uint32_t, AABB, bool>> m_dynamicAABBs{}; std::vector<std::tuple<uint32_t, AABB, bool>> dynamic_aabbs_{};
struct PossibleCollision { struct PossibleCollision {
PossibleCollision(uint32_t static_entity, AABB static_aabb,
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) {}
PossibleCollision(uint32_t staticEntity, AABB staticAABB, bool staticTrigger, uint32_t dynamicEntity, AABB dynamicAABB, bool dynamicTrigger) : uint32_t static_entity;
staticEntity(staticEntity), AABB static_aabb;
staticAABB(staticAABB), bool static_trigger;
staticTrigger(staticTrigger), uint32_t dynamic_entity;
dynamicEntity(dynamicEntity), AABB dynamic_aabb;
dynamicAABB(dynamicAABB), bool dynamic_trigger;
dynamicTrigger(dynamicTrigger) {}
uint32_t staticEntity;
AABB staticAABB;
bool staticTrigger;
uint32_t dynamicEntity;
AABB dynamicAABB;
bool dynamicTrigger;
}; };
std::vector<PossibleCollision> m_possibleCollisions{}; std::vector<PossibleCollision> possible_collisions_{};
std::vector<std::pair<uint32_t, CollisionEvent>> m_collisionInfos{}; // target entity, event info std::vector<std::pair<uint32_t, CollisionEvent>>
collision_infos_{}; // target entity, event info
}; };
} } // namespace engine
#endif

View File

@ -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: public:
RenderSystem(Scene* scene); RenderSystem(Scene* scene);
~RenderSystem(); ~RenderSystem();
void OnUpdate(float ts) override; void OnUpdate(float ts) override;
void setCameraEntity(uint32_t entity); void SetCameraEntity(uint32_t entity);
private: private:
GFXDevice* const m_gfx; GFXDevice* const gfx_;
struct { struct {
// only uses transform component, which is required for all entities anyway // only uses transform component, which is required for all entities anyway
uint32_t camEntity = 0; uint32_t cam_entity = 0;
float verticalFovDegrees = 70.0f; float vertical_fov_degrees = 70.0f;
float clipNear = 0.5f; float clip_near = 0.5f;
float clipFar = 10000.0f; float clip_far = 10000.0f;
} m_camera; } camera_;
float m_viewportAspectRatio = 1.0f;
float m_value = 0.0f;
float viewport_aspect_ratio_ = 1.0f;
}; };
} } // namespace engine
#endif

View File

@ -1,11 +1,11 @@
#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: public:
Render2DSystem(Scene* scene); Render2DSystem(Scene* scene);
~Render2DSystem(); ~Render2DSystem();
@ -13,8 +13,8 @@ namespace engine {
void OnUpdate(float ts) override; void OnUpdate(float ts) override;
private: private:
}; };
} } // namespace engine
#endif

View File

@ -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

View File

@ -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: public:
UISystem(Scene* scene); UISystem(Scene* scene);
void OnUpdate(float ts) override; void OnUpdate(float ts) override;
private: private:
}; };
} } // namespace engine
#endif

View File

@ -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

View File

@ -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

View File

@ -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));
} }

View File

@ -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);

View File

@ -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_)
{ {
} }

View File

@ -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());
} }

View File

@ -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_;
} }
} }

View File

@ -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_);
} }
} }

View File

@ -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)

View File

@ -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);
} }
} }

View File

@ -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;
} }
} }

View File

@ -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);

View File

@ -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);

View File

@ -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");
} }

View File

@ -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;
} }

View File

@ -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 };
} }