Make all header files use #pragma once

This commit is contained in:
bailehuni 2024-03-31 11:11:22 +01:00
parent 16357675a7
commit d2223a7b45
50 changed files with 993 additions and 1389 deletions

View File

@ -10,8 +10,6 @@ a random game engine thing. Now finally with ECS!
- Support dynamic shadow mapping (at least for shadows cast from the scene's sun)
- Sort out LOG_X calls and ensure DEBUG, TRACE, INFO, etc are being used appropriately
## Medium priority (next week)
- UI generator exposed at the Application level (Scene UI Systems could use this to draw menus every frame)
@ -58,3 +56,5 @@ Added the BVH AABB tree made in Summer to start a much better Collision system.
The CameraControllerSystem now uses raycasting to enable FPS-style player movement.
Added static soft shadows.
Sort out LOG_X calls and ensure DEBUG, TRACE, INFO, etc are being used appropriately

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_APPLICATION_H_
#define ENGINE_INCLUDE_APPLICATION_H_
#pragma once
#include <filesystem>
#include <memory>
@ -96,5 +95,3 @@ class Application {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_COMPONENTS_CUSTOM_H_
#define ENGINE_INCLUDE_COMPONENTS_CUSTOM_H_
#pragma once
#include <functional>
@ -11,5 +10,3 @@ struct CustomComponent {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_COMPONENTS_MESH_RENDERABLE_H_
#define ENGINE_INCLUDE_COMPONENTS_MESH_RENDERABLE_H_
#pragma once
#include <memory>
@ -15,5 +14,3 @@ struct MeshRenderableComponent {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
#define ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
#pragma once
#include <string>
@ -26,5 +25,3 @@ struct TransformComponent {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_ECS_H_
#define ENGINE_INCLUDE_ECS_H_
#pragma once
#include <bitset>
#include <cassert>
@ -25,7 +24,8 @@ class IComponentArray {
template <typename T>
class ComponentArray : public IComponentArray {
public:
void InsertData(Entity entity, const T& component) {
void InsertData(Entity entity, const T& component)
{
if (component_array_.size() < entity + 1) {
component_array_.resize(entity + 1);
}
@ -33,11 +33,13 @@ class ComponentArray : public IComponentArray {
component_array_.at(entity) = component;
}
void DeleteData(Entity entity) {
void DeleteData(Entity entity)
{
(void)entity; // TODO
}
T* GetData(Entity entity) {
T* GetData(Entity entity)
{
assert(entity < component_array_.size());
return &component_array_[entity];
}
@ -67,5 +69,3 @@ class System {
};
} // namespace engine
#endif

View File

@ -1,6 +1,4 @@
#ifndef ENGINE_INCLUDE_ENGINE_API_H_
#define ENGINE_INCLUDE_ENGINE_API_H_
#pragma once
/*
#ifndef ENGINE_API
# ifdef _MSC_VER
@ -16,5 +14,3 @@
*/
#define ENGINE_API
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_EVENT_SYSTEM_H_
#define ENGINE_INCLUDE_EVENT_SYSTEM_H_
#pragma once
#include <cstddef>
#include <cstdint>
@ -32,25 +31,25 @@ class EventQueue : public IEventQueue {
// holds events of type T and subscribers to those events
public:
void Subscribe(EventSubscriberKind kind, uint32_t id,
EventHandler<T>* handler) {
void Subscribe(EventSubscriberKind kind, uint32_t id, EventHandler<T>* handler)
{
// For the time being, ignore kind (TODO)
(void)kind;
assert(subscribers_.contains(id) == false &&
"subscribing to an event with ID that's already in use!");
assert(subscribers_.contains(id) == false && "subscribing to an event with ID that's already in use!");
subscribers_.emplace(id, handler);
}
void QueueEvent(EventSubscriberKind kind, uint32_t id, T event) {
void QueueEvent(EventSubscriberKind kind, uint32_t id, T event)
{
// For the time being, ignore kind (TODO)
(void)kind;
assert(subscribers_.contains(id) &&
"Attempt to submit event to non-existing subscriber!");
assert(subscribers_.contains(id) && "Attempt to submit event to non-existing subscriber!");
EventHandler<T>* handler = subscribers_.at(id);
event_queue_.emplace(handler, event);
}
void DespatchEvents() override {
void DespatchEvents() override
{
while (event_queue_.empty() == false) {
auto [handler, event] = event_queue_.front();
handler->OnEvent(event);
@ -62,8 +61,7 @@ class EventQueue : public IEventQueue {
std::unordered_map<uint32_t, EventHandler<T>*> subscribers_;
struct QueuedEvent {
QueuedEvent(EventHandler<T>* handler, T event)
: handler(handler), event(event) {}
QueuedEvent(EventHandler<T>* handler, T event) : handler(handler), event(event) {}
EventHandler<T>* handler;
T event;
@ -79,37 +77,35 @@ class EventSystem {
~EventSystem() {}
template <typename T>
void RegisterEventType() {
void RegisterEventType()
{
size_t hash = typeid(T).hash_code();
assert(event_queues_.contains(hash) == false &&
"Registering an event queue more than once!");
assert(event_queues_.contains(hash) == false && "Registering an event queue more than once!");
event_queues_.emplace(hash, std::make_unique<EventQueue<T>>());
}
template <typename T>
void SubscribeToEventType(EventSubscriberKind kind, uint32_t id,
EventHandler<T>* handler) {
void SubscribeToEventType(EventSubscriberKind kind, uint32_t id, EventHandler<T>* handler)
{
size_t hash = typeid(T).hash_code();
assert(event_queues_.contains(hash) &&
"Subscribing to event type that isn't registered!");
EventQueue<T>* queue =
dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
assert(event_queues_.contains(hash) && "Subscribing to event type that isn't registered!");
EventQueue<T>* queue = dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
assert(queue != nullptr && "This cast should work?!! wot");
queue->Subscribe(kind, id, handler);
}
template <typename T>
void QueueEvent(EventSubscriberKind kind, uint32_t subscriber_id, T event) {
void QueueEvent(EventSubscriberKind kind, uint32_t subscriber_id, T event)
{
size_t hash = typeid(T).hash_code();
assert(event_queues_.contains(hash) &&
"Subscribing to event type that isn't registered!");
EventQueue<T>* queue =
dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
assert(event_queues_.contains(hash) && "Subscribing to event type that isn't registered!");
EventQueue<T>* queue = dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
assert(queue != nullptr && "This cast should work?!! wot");
queue->QueueEvent(kind, subscriber_id, event);
}
void DespatchEvents() {
void DespatchEvents()
{
for (auto& [hash, queue] : event_queues_) {
queue->DespatchEvents();
}
@ -120,5 +116,3 @@ class EventSystem {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_GFX_H_
#define ENGINE_INCLUDE_GFX_H_
#pragma once
#include <cstdint>
#include <functional>
@ -169,5 +168,3 @@ struct hash<engine::gfx::SamplerInfo> {
};
} // namespace std
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_GFX_DEVICE_H_
#define ENGINE_INCLUDE_GFX_DEVICE_H_
#pragma once
#include <memory>
@ -12,8 +11,7 @@ namespace engine {
class GFXDevice {
public:
GFXDevice(const char* app_name, const char* app_version, SDL_Window* window,
gfx::GraphicsSettings settings);
GFXDevice(const char* app_name, const char* app_version, SDL_Window* window, gfx::GraphicsSettings settings);
GFXDevice(const GFXDevice&) = delete;
GFXDevice& operator=(const GFXDevice&) = delete;
@ -37,72 +35,51 @@ class GFXDevice {
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- pipeline MUST be a valid pointer returned by CreatePipeline() */
void CmdBindPipeline(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline);
void CmdBindPipeline(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline);
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding,
const gfx::Buffer* buffer);
void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding, const gfx::Buffer* buffer);
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer,
const gfx::Buffer* buffer);
void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer, const gfx::Buffer* buffer);
void CmdDrawIndexed(gfx::DrawBuffer* draw_buffer, uint32_t index_count,
uint32_t instance_count, uint32_t first_index,
int32_t vertex_offset, uint32_t first_instance);
void CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count,
uint32_t instance_count, uint32_t first_vertex,
void CmdDrawIndexed(gfx::DrawBuffer* draw_buffer, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t vertex_offset,
uint32_t first_instance);
void CmdPushConstants(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline, uint32_t offset,
uint32_t size, const void* data);
void CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance);
void CmdBindDescriptorSet(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline,
const gfx::DescriptorSet* set, uint32_t set_number);
void CmdPushConstants(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline, uint32_t offset, uint32_t size, const void* data);
void CmdBindDescriptorSet(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline, const gfx::DescriptorSet* set, uint32_t set_number);
gfx::Pipeline* CreatePipeline(const gfx::PipelineInfo& info);
void DestroyPipeline(const gfx::Pipeline* pipeline);
gfx::DescriptorSetLayout* CreateDescriptorSetLayout(
const std::vector<gfx::DescriptorSetLayoutBinding>& bindings);
gfx::DescriptorSetLayout* CreateDescriptorSetLayout(const std::vector<gfx::DescriptorSetLayoutBinding>& bindings);
void DestroyDescriptorSetLayout(const gfx::DescriptorSetLayout* layout);
gfx::DescriptorSet* AllocateDescriptorSet(
const gfx::DescriptorSetLayout* layout);
gfx::DescriptorSet* AllocateDescriptorSet(const gfx::DescriptorSetLayout* layout);
void FreeDescriptorSet(const gfx::DescriptorSet* set);
// This updates all copies of the descriptor.
// This cannot be used after any frames have been renderered
void UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set,
uint32_t binding,
const gfx::UniformBuffer* buffer,
size_t offset, size_t range);
void UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set, uint32_t binding, const gfx::UniformBuffer* buffer, size_t offset, size_t range);
void UpdateDescriptorCombinedImageSampler(const gfx::DescriptorSet* set,
uint32_t binding,
const gfx::Image* image,
const gfx::Sampler* sampler);
void UpdateDescriptorCombinedImageSampler(const gfx::DescriptorSet* set, uint32_t binding, const gfx::Image* image, const gfx::Sampler* sampler);
gfx::UniformBuffer* CreateUniformBuffer(uint64_t size,
const void* initial_data);
gfx::UniformBuffer* CreateUniformBuffer(uint64_t size, const void* initial_data);
void DestroyUniformBuffer(const gfx::UniformBuffer* descriptor_buffer);
void WriteUniformBuffer(gfx::UniformBuffer* buffer, uint64_t offset,
uint64_t size, const void* data);
void WriteUniformBuffer(gfx::UniformBuffer* buffer, uint64_t offset, uint64_t size, const void* data);
// Loads data into staging buffer and copies that into a single GPU buffer.
gfx::Buffer* CreateBuffer(gfx::BufferType type, uint64_t size,
const void* data);
gfx::Buffer* CreateBuffer(gfx::BufferType type, uint64_t size, const void* data);
void DestroyBuffer(const gfx::Buffer* buffer);
@ -129,5 +106,3 @@ class GFXDevice {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_INPUT_MANAGER_H_
#define ENGINE_INCLUDE_INPUT_MANAGER_H_
#pragma once
#include <array>
#include <string>
@ -18,7 +17,8 @@ class InputManager {
public:
/* The Window object here is stored for the duration of the InputManager.
* 'win' must point to a valid Window object. */
InputManager(const Window* win) : win_(win) {
InputManager(const Window* win) : win_(win)
{
assert(win != nullptr);
enabled_devices_.fill(true);
}
@ -28,50 +28,39 @@ class InputManager {
~InputManager() {}
void AddInputButton(const std::string& name, inputs::MouseButton button) {
AddInputDeviceButton(name, InputDevice::kMouse, static_cast<int>(button));
void AddInputButton(const std::string& name, inputs::MouseButton button) { AddInputDeviceButton(name, InputDevice::kMouse, static_cast<int>(button)); }
void AddInputButton(const std::string& name, inputs::Key button) { AddInputDeviceButton(name, InputDevice::kKeyboard, static_cast<int>(button)); }
void AddInputAxis(const std::string& name, inputs::MouseAxis axis) { AddInputDeviceAxis(name, InputDevice::kMouse, static_cast<int>(axis)); }
void AddInputButtonAsAxis(const std::string& name, inputs::MouseButton high, inputs::MouseButton low)
{
AddInputDeviceButtonAsAxis(name, InputDevice::kMouse, static_cast<int>(high), static_cast<int>(low));
}
void AddInputButton(const std::string& name, inputs::Key button) {
AddInputDeviceButton(name, InputDevice::kKeyboard,
static_cast<int>(button));
void AddInputButtonAsAxis(const std::string& name, inputs::Key high, inputs::Key low)
{
AddInputDeviceButtonAsAxis(name, InputDevice::kKeyboard, static_cast<int>(high), static_cast<int>(low));
}
void AddInputAxis(const std::string& name, inputs::MouseAxis axis) {
AddInputDeviceAxis(name, InputDevice::kMouse, static_cast<int>(axis));
}
void AddInputButtonAsAxis(const std::string& name, inputs::MouseButton high,
inputs::MouseButton low) {
AddInputDeviceButtonAsAxis(name, InputDevice::kMouse,
static_cast<int>(high), static_cast<int>(low));
}
void AddInputButtonAsAxis(const std::string& name, inputs::Key high,
inputs::Key low) {
AddInputDeviceButtonAsAxis(name, InputDevice::kKeyboard,
static_cast<int>(high), static_cast<int>(low));
}
void DelInputButton(int index) {
void DelInputButton(int index)
{
std::vector<struct ButtonEntry>::iterator it = button_entries_.begin();
std::advance(it, index);
button_entries_.erase(it);
}
void DelInputAxis(int index) {
void DelInputAxis(int index)
{
std::vector<struct AxisEntry>::iterator it = axis_entries_.begin();
std::advance(it, index);
axis_entries_.erase(it);
}
void SetDeviceActive(enum InputDevice device, bool active) {
enabled_devices_[static_cast<int>(device)] = active;
}
void SetDeviceActive(enum InputDevice device, bool active) { enabled_devices_[static_cast<int>(device)] = active; }
bool GetDeviceActive(enum InputDevice device) const {
return enabled_devices_[static_cast<int>(device)];
}
bool GetDeviceActive(enum InputDevice device) const { return enabled_devices_[static_cast<int>(device)]; }
float GetAxis(const std::string& axis_name) const;
@ -114,7 +103,8 @@ class InputManager {
bool GetDeviceButtonUp(enum InputDevice device, int button) const;
float GetButtonAxis(enum InputDevice device, int high, int low) const {
float GetButtonAxis(enum InputDevice device, int high, int low) const
{
float value = 0.0f;
if (GetDeviceButton(device, high)) value += 1.0f;
if (low != 0) {
@ -123,22 +113,14 @@ class InputManager {
return value;
}
void AddInputDeviceButton(const std::string& name, InputDevice device,
int button) {
button_entries_.push_back({name, device, button});
}
void AddInputDeviceButton(const std::string& name, InputDevice device, int button) { button_entries_.push_back({name, device, button}); }
void AddInputDeviceAxis(const std::string& name, InputDevice device,
int axis) {
axis_entries_.push_back({name, device, axis, false, 0, 0});
}
void AddInputDeviceAxis(const std::string& name, InputDevice device, int axis) { axis_entries_.push_back({name, device, axis, false, 0, 0}); }
void AddInputDeviceButtonAsAxis(const std::string& name, InputDevice device,
int high, int low) {
void AddInputDeviceButtonAsAxis(const std::string& name, InputDevice device, int high, int low)
{
axis_entries_.push_back({name, device, 0, true, high, low});
}
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
#define ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
#pragma once
// Keyboard scancodes, taken from SDL_scancode.h
@ -375,5 +374,3 @@ enum class Key : int {
} // namespace inputs
} // namespace engine
#endif

View File

@ -1,22 +1,11 @@
#ifndef ENGINE_INCLUDE_INPUTS_MOUSE_H_
#define ENGINE_INCLUDE_INPUTS_MOUSE_H_
#pragma once
namespace engine {
namespace inputs {
enum class MouseButton : int {
M_LEFT,
M_MIDDLE,
M_RIGHT,
M_X1,
M_X2,
M_INVALID = 7,
M_SIZE = 7
};
enum class MouseButton : int { M_LEFT, M_MIDDLE, M_RIGHT, M_X1, M_X2, M_INVALID = 7, M_SIZE = 7 };
enum class MouseAxis : int { X, Y, X_SCR, Y_SCR };
} // namespace inputs
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_LOG_H_
#define ENGINE_INCLUDE_LOG_H_
#pragma once
#ifdef NDEBUG
#define SPDLOG_ACTIVE_LEVEL 2 // info, warn, error, critical
@ -16,5 +15,3 @@
#define LOG_WARN SPDLOG_WARN
#define LOG_ERROR SPDLOG_ERROR
#define LOG_CRITICAL SPDLOG_CRITICAL
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_LOGGER_H_
#define ENGINE_INCLUDE_LOGGER_H_
#pragma once
#include <filesystem>
#include <memory>
@ -12,13 +11,13 @@
namespace engine {
// To be executed in the target application, NOT engine.dll
void SetupLog(const char* appName) {
void SetupLog(const char* appName)
{
const std::string LOG_FILENAME{std::string(appName) + ".log"};
#ifdef NDEBUG
// RELEASE
const std::filesystem::path log_path{std::filesystem::temp_directory_path() /
LOG_FILENAME};
const std::filesystem::path log_path{std::filesystem::temp_directory_path() / LOG_FILENAME};
#else
// DEBUG
const std::filesystem::path log_path{LOG_FILENAME};
@ -26,15 +25,13 @@ void SetupLog(const char* appName) {
std::vector<spdlog::sink_ptr> sinks;
sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(
log_path.string(), true));
sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(log_path.string(), true));
sinks.back()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
sinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
sinks.back()->set_pattern("[%H:%M:%S.%e] [%l] %v");
auto logger =
std::make_shared<spdlog::logger>(appName, sinks.begin(), sinks.end());
auto logger = std::make_shared<spdlog::logger>(appName, sinks.begin(), sinks.end());
// Logs below INFO are ignored through macros in release (see log.hpp)
logger->set_level(spdlog::level::trace);
@ -47,5 +44,3 @@ void SetupLog(const char* appName) {
}
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_RENDERER_H_
#define ENGINE_INCLUDE_RENDERER_H_
#pragma once
#include <memory>
#include <unordered_map>
@ -120,5 +119,3 @@ class Renderer : private ApplicationComponent {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_RESOURCE_MANAGER_H_
#define ENGINE_INCLUDE_RESOURCE_MANAGER_H_
#pragma once
#include <memory>
#include <stdexcept>
@ -22,31 +21,30 @@ class IResourceManager {
template <class T>
class ResourceManager : public IResourceManager {
public:
~ResourceManager() override {
LOG_DEBUG("Destroying resource manager... '{}'", typeid(T).name());
}
~ResourceManager() override { LOG_DEBUG("Destroying resource manager... '{}'", typeid(T).name()); }
std::shared_ptr<T> Add(const std::string& name,
std::unique_ptr<T>&& resource) {
std::shared_ptr<T> Add(const std::string& name, std::unique_ptr<T>&& resource)
{
if (resources_.contains(name) == false) {
std::shared_ptr<T> resource_shared(std::move(resource));
resources_.emplace(name, resource_shared);
return resource_shared;
} else {
}
else {
throw std::runtime_error("Cannot add a resource which already exists");
}
}
void AddPersistent(const std::string& name, std::unique_ptr<T>&& resource) {
persistent_resources_.push_back(Add(name, std::move(resource)));
}
void AddPersistent(const std::string& name, std::unique_ptr<T>&& resource) { persistent_resources_.push_back(Add(name, std::move(resource))); }
std::shared_ptr<T> Get(const std::string& name) {
std::shared_ptr<T> Get(const std::string& name)
{
if (resources_.contains(name)) {
std::weak_ptr<T> ptr = resources_.at(name);
if (ptr.expired() == false) {
return ptr.lock();
} else {
}
else {
resources_.erase(name);
}
}
@ -62,5 +60,3 @@ class ResourceManager : public IResourceManager {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_RESOURCES_FONT_H_
#define ENGINE_INCLUDE_RESOURCES_FONT_H_
#pragma once
#include <string>
#include <map>
@ -17,10 +16,7 @@ class Font {
Font(const Font&) = delete;
Font& operator=(const Font&) = delete;
std::unique_ptr<std::vector<uint8_t>> GetTextBitmap(const std::string& text,
float height_px,
int& width_out,
int& height_out);
std::unique_ptr<std::vector<uint8_t>> GetTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out);
private:
std::unique_ptr<stbtt_fontinfo> font_info_{};
@ -31,5 +27,3 @@ class Font {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
#define ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
#pragma once
#include <memory>
@ -36,5 +35,3 @@ class Material {
};
} // namespace engine
#endif

View File

@ -1,6 +1,4 @@
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
#define ENGINE_INCLUDE_RESOURCES_MESH_H_
#pragma once
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
@ -47,5 +45,3 @@ class Mesh {
};
} // namespace engine
#endif

View File

@ -26,8 +26,7 @@ class Shader {
static constexpr int kHighestRenderOrder = 1;
Shader(Renderer* renderer, const std::string& vert_path, const std::string& frag_path,
const ShaderSettings& settings);
Shader(Renderer* renderer, const std::string& vert_path, const std::string& frag_path, const ShaderSettings& settings);
~Shader();
Shader(const Shader&) = delete;
Shader& operator=(const Shader&) = delete;

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
#define ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
#pragma once
#include <string>
@ -10,7 +9,6 @@ namespace engine {
class Texture {
public:
Texture(Renderer* renderer, const uint8_t* bitmap, int width, int height, gfx::SamplerInfo samplerInfo, bool srgb);
~Texture();
@ -29,5 +27,3 @@ class Texture {
std::unique_ptr<Texture> LoadTextureFromFile(const std::string& path, gfx::SamplerInfo samplerInfo, Renderer* renderer, bool srgb = true);
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_SCENE_H_
#define ENGINE_INCLUDE_SCENE_H_
#pragma once
#include <cassert>
#include <cstdint>
@ -70,21 +69,13 @@ class Scene {
}
// because GetComponent<Transformzzzzzz takes too long
TransformComponent* GetTransform(Entity entity) {
return GetComponent<TransformComponent>(entity);
}
TransformComponent* GetTransform(Entity entity) { return GetComponent<TransformComponent>(entity); }
glm::vec3& GetPosition(Entity entity) {
return GetTransform(entity)->position;
}
glm::vec3& GetPosition(Entity entity) { return GetTransform(entity)->position; }
glm::quat& GetRotation(Entity entity) {
return GetTransform(entity)->rotation;
}
glm::quat& GetRotation(Entity entity) { return GetTransform(entity)->rotation; }
glm::vec3& GetScale(Entity entity) {
return GetTransform(entity)->scale;
}
glm::vec3& GetScale(Entity entity) { return GetTransform(entity)->scale; }
template <typename T>
T* AddComponent(Entity entity, const T& comp = T{})
@ -174,5 +165,3 @@ class Scene {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_SCENE_MANAGER_H_
#define ENGINE_INCLUDE_SCENE_MANAGER_H_
#pragma once
#include <memory>
#include <vector>
@ -57,5 +56,3 @@ class SceneManager {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
#define ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
#pragma once
#include <cstdint>
#include <vector>
@ -75,5 +74,3 @@ class CollisionSystem : public System {
};
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_CUSTOM_BEHAVIOUR_H_
#define ENGINE_INCLUDE_CUSTOM_BEHAVIOUR_H_
#pragma once
#include <unordered_map>
@ -23,5 +22,3 @@ class CustomBehaviourSystem : public System {
};
} // namespace engine
#endif

View File

@ -39,7 +39,6 @@ class MeshRenderSystem : public System {
// with_static_entities = false, build list of dynamic meshes
// with_static_entities = true, build list of static meshes
void BuildRenderList(RenderList& render_list, bool with_static_entities);
};
} // namespace engine

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
#define ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
#pragma once
#include "ecs.h"
@ -20,5 +19,3 @@ class TransformSystem : public System {
};
} // namespace engine
#endif

View File

@ -17,7 +17,6 @@ namespace engine {
void OnUpdate(float ts) override;
private:
};
} // namespace engine

View File

@ -1,22 +1,20 @@
#ifndef ENGINE_INCLUDE_UTIL_H_
#define ENGINE_INCLUDE_UTIL_H_
#pragma once
#include <cstdio>
namespace engine {
inline bool VersionFromCharArray(const char* version, int* major, int* minor,
int* patch) {
inline bool VersionFromCharArray(const char* version, int* major, int* minor, int* patch)
{
if (sscanf(version, "%d.%d.%d", major, minor, patch) != 3) {
*major = 0;
*minor = 0;
*patch = 0;
return false;
} else {
}
else {
return true;
}
}
} // namespace engine
#endif

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_UTIL_FILES_H_
#define ENGINE_INCLUDE_UTIL_FILES_H_
#pragma once
#include <memory>
#include <string>
@ -13,10 +12,7 @@ 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. 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

@ -17,4 +17,4 @@ namespace engine::util {
*/
engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic = false);
}
} // namespace engine::util

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_INCLUDE_WINDOW_H_
#define ENGINE_INCLUDE_WINDOW_H_
#pragma once
#include <array>
#include <string>
@ -14,8 +13,7 @@ namespace engine {
class Window {
public:
Window(const std::string& title, bool resizable = true,
bool fullscreen = true);
Window(const std::string& title, bool resizable = true, bool fullscreen = true);
Window(const Window&) = delete;
Window& operator=(const Window&) = delete;
~Window();
@ -188,5 +186,3 @@ class Window {
};
} // namespace engine
#endif

View File

@ -49,7 +49,7 @@ float InterleavedGradientNoise(vec2 position_screen)
void main() {
const vec4 albedo_alpha = texture(materialSetAlbedoSampler, fragUV);
if (albedo_alpha.a < 0.9) discard; // discard fragments without alpha = 1.0
if (albedo_alpha.a < 0.9) discard;
const vec3 albedo = albedo_alpha.xyz;
const vec3 occlusion_roughness_metallic = vec3(texture(materialSetOcclusionRoughnessMetallic, fragUV));

View File

@ -1,13 +0,0 @@
#version 450
layout(set = 2, binding = 0) uniform sampler2D materialSetSampler;
layout(location = 0) in vec2 fragUV;
layout(location = 0) out vec4 outColor;
void main() {
outColor = texture(materialSetSampler, fragUV);
}

View File

@ -1,43 +0,0 @@
#version 450
layout(set = 0, binding = 0) uniform GlobalSetUniformBuffer {
mat4 proj;
} globalSetUniformBuffer;
layout(set = 1, binding = 0) uniform FrameSetUniformBuffer {
mat4 view;
} frameSetUniformBuffer;
layout( push_constant ) uniform Constants {
mat4 model;
} constants;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNorm;
layout(location = 2) in vec4 inTangent;
layout(location = 3) in vec2 inUV;
layout(location = 0) out vec2 fragUV;
vec2 positions[6] = vec2[](
vec2( 1.0, 1.0),
vec2(-1.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, -1.0)
);
vec2 uvs[6] = vec2[](
vec2(1.0, 0.0),
vec2(0.0, 0.0),
vec2(0.0, 1.0),
vec2(1.0, 0.0),
vec2(0.0, 1.0),
vec2(1.0, 1.0)
);
void main() {
gl_Position = constants.model * vec4(positions[gl_VertexIndex], 0.0, 1.0);
fragUV = uvs[gl_VertexIndex];
}

View File

@ -1,25 +0,0 @@
#version 450
layout(set = 2, binding = 0) uniform sampler2D materialSetAlbedoSampler;
layout(set = 2, binding = 1) uniform sampler2D materialSetNormalSampler;
layout(set = 2, binding = 2) uniform sampler2D materialSetOcclusionSampler;
layout(set = 2, binding = 3) uniform sampler2D materialSetMetallicRoughnessSampler;
layout(location = 0) in vec2 fragUV;
layout(location = 1) in vec3 fragPosTangentSpace;
layout(location = 2) in vec3 fragViewPosTangentSpace;
layout(location = 3) in vec3 fragLightPosTangentSpace;
layout(location = 0) out vec4 outColor;
void main() {
vec3 norm = vec3(texture(materialSetNormalSampler, fragUV));
//norm.y = 1.0 - norm.y;
norm = normalize(norm * 2.0 - 1.0);
norm.b = 0.0;
norm *= 100.0;
norm = clamp(norm, 0.0, 1.0);
outColor = vec4(norm, 1.0);
}

View File

@ -1,40 +0,0 @@
#version 450
layout(set = 0, binding = 0) uniform GlobalSetUniformBuffer {
mat4 proj;
} globalSetUniformBuffer;
layout(set = 1, binding = 0) uniform FrameSetUniformBuffer {
mat4 view;
} frameSetUniformBuffer;
layout( push_constant ) uniform Constants {
mat4 model;
} constants;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNorm;
layout(location = 2) in vec4 inTangent;
layout(location = 3) in vec2 inUV;
layout(location = 0) out vec2 fragUV;
layout(location = 1) out vec3 fragPosTangentSpace;
layout(location = 2) out vec3 fragViewPosTangentSpace;
layout(location = 3) out vec3 fragLightPosTangentSpace;
void main() {
vec4 worldPosition = constants.model * vec4(inPosition, 1.0);
gl_Position = globalSetUniformBuffer.proj * frameSetUniformBuffer.view * worldPosition;
vec3 T = normalize(vec3(constants.model * vec4(inTangent.xyz, 0.0)));
vec3 N = normalize(vec3(constants.model * vec4(inNorm, 0.0)));
vec3 B = cross(T, N) * inTangent.w;
mat3 worldToTangentSpace = transpose(mat3(T, B, N));
fragUV = inUV;
fragPosTangentSpace = worldToTangentSpace * vec3(worldPosition);
fragViewPosTangentSpace = worldToTangentSpace * vec3(inverse(frameSetUniformBuffer.view) * vec4(0.0, 0.0, 0.0, 1.0));
fragLightPosTangentSpace = worldToTangentSpace * vec3(59000.0, 0000.0, 10000.0);
gl_Position.y *= -1.0;
}

View File

@ -1,11 +0,0 @@
#version 450
layout(location = 0) in vec2 fragUV;
layout(location = 0) out vec4 outColor;
void main() {
vec3 baseColor = vec3(fragUV, 0.0);
outColor = vec4(baseColor, 1.0);
}

View File

@ -1,23 +0,0 @@
#version 450
layout( push_constant ) uniform Constants {
mat4 model;
mat4 view;
} constants;
layout(set = 0, binding = 0) uniform SetZeroBuffer {
mat4 proj;
vec2 myValue;
} setZeroBuffer;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNorm;
layout(location = 2) in vec4 inTangent;
layout(location = 3) in vec2 inUV;
layout(location = 0) out vec2 fragUV;
void main() {
gl_Position = setZeroBuffer.proj * constants.view * constants.model * vec4(inPosition, 1.0);
fragUV = inUV;
}

View File

@ -1,41 +0,0 @@
#version 450
layout(set = 2, binding = 0) uniform sampler2D materialSetAlbedoSampler;
layout(set = 2, binding = 1) uniform sampler2D materialSetNormalSampler;
layout(set = 2, binding = 2) uniform sampler2D materialSetOcclusionSampler;
layout(set = 2, binding = 3) uniform sampler2D materialSetMetallicRoughnessSampler;
layout(location = 0) in vec3 fragPos;
layout(location = 1) in vec3 fragNorm;
layout(location = 2) in vec2 fragUV;
layout(location = 3) in vec3 fragLightPos;
layout(location = 0) out vec4 outColor;
void main() {
// constants
vec3 lightColor = vec3(1.0, 1.0, 1.0);
vec3 ambientColor = vec3(1.0, 1.0, 1.0);
float ambientStrength = 0.05;
vec3 baseColor = vec3(texture(materialSetAlbedoSampler, fragUV));
vec3 emission = vec3(0.0, 0.0, 0.0);
// code
vec3 norm = normalize(fragNorm);
vec3 lightDir = normalize(fragLightPos - fragPos);
vec3 diffuse = max(dot(norm, lightDir), 0.0) * lightColor;
vec3 ambient = ambientColor * ambientStrength;
vec3 viewDir = normalize(-fragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
vec3 specular = 0.5 * spec * lightColor;
vec3 lighting = min(diffuse + ambient + specular, 1.0);
outColor = min( ( vec4(baseColor, 1.0) ) * vec4(lighting + emission, 1.0), vec4(1.0));
}

View File

@ -1,36 +0,0 @@
#version 450
layout(set = 0, binding = 0) uniform GlobalSetUniformBuffer {
mat4 proj;
} globalSetUniformBuffer;
layout(set = 1, binding = 0) uniform FrameSetUniformBuffer {
mat4 view;
} frameSetUniformBuffer;
layout( push_constant ) uniform Constants {
mat4 model;
} constants;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNorm;
layout(location = 2) in vec4 inTangent;
layout(location = 3) in vec2 inUV;
layout(location = 0) out vec3 fragPos;
layout(location = 1) out vec3 fragNorm;
layout(location = 2) out vec2 fragUV;
layout(location = 3) out vec3 fragLightPos;
void main() {
gl_Position = globalSetUniformBuffer.proj * frameSetUniformBuffer.view * constants.model * vec4(inPosition, 1.0);
fragPos = vec3(frameSetUniformBuffer.view * constants.model * vec4(inPosition, 1.0));
fragNorm = mat3(transpose(inverse(frameSetUniformBuffer.view * constants.model))) * inNorm;
fragUV = inUV;
vec3 lightPos = vec3(5900.0, -2000.0, 1000.0);
fragLightPos = vec3(frameSetUniformBuffer.view * vec4(lightPos, 1.0));
gl_Position.y *= -1.0;
}

View File

@ -75,7 +75,7 @@ namespace engine {
LOG_DEBUG("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
break;
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
LOG_INFO("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
LOG_TRACE("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
break;
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
LOG_WARN("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);

View File

@ -19,7 +19,7 @@ namespace engine {
sc->device = info.device;
sc->allocator = info.allocator;
LOG_INFO("Recreating swapchain!\n");
LOG_DEBUG("Recreating swapchain!\n");
// get surface caps and features
VkResult res;

View File

@ -184,7 +184,7 @@ void CameraControllerSystem::OnUpdate(float ts)
/* user interface inputs */
if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_R) || glm::length(t->position) > CameraControllerComponent::kMaxDistanceFromOrigin) {
t->position = {0.0f, 0.0f, 100.0f};
t->position = {0.0f, 0.0f, 10.0f};
c->vel = {0.0f, 0.0f, 0.0f};
c->pitch = glm::half_pi<float>();
c->yaw = 0.0f;

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_TEST_SRC_CAMERA_CONTROLLER_H_
#define ENGINE_TEST_SRC_CAMERA_CONTROLLER_H_
#pragma once
#include <glm/vec3.hpp>
@ -26,7 +25,7 @@ struct CameraControllerComponent {
static constexpr size_t kNumHorizontalRays = 20;
static constexpr float kGravAccel = -9.81f;
static constexpr float kMaxDistanceFromOrigin = 1000.0f;
static constexpr float kMaxDistanceFromOrigin = 200.0f;
bool noclip = false;
@ -50,5 +49,3 @@ class CameraControllerSystem : public engine::System {
engine::Scene* next_scene_ = nullptr;
};
#endif

View File

@ -16,7 +16,6 @@
#include "systems/mesh_render_system.h"
#include "systems/transform.h"
#include "util/gltf_loader.h"
#include "util/model_loader.h"
#include "log.h"
#include "window.h"
@ -47,8 +46,8 @@ void PlayGame(GameSettings settings)
engine::gfx::GraphicsSettings graphics_settings{};
graphics_settings.enable_validation = settings.enable_validation;
graphics_settings.vsync = true;
graphics_settings.wait_for_present = true;
graphics_settings.vsync = false;
graphics_settings.wait_for_present = false;
graphics_settings.msaa_level = engine::gfx::MSAALevel::kOff;
graphics_settings.enable_anisotropy = true;

View File

@ -1,5 +1,4 @@
#ifndef ENGINE_TEST_SRC_GAME_H_
#define ENGINE_TEST_SRC_GAME_H_
#pragma once
struct GameSettings {
bool enable_frame_limiter;
@ -7,5 +6,3 @@ struct GameSettings {
};
void PlayGame(GameSettings settings);
#endif

View File

@ -1,16 +1,9 @@
#ifndef ENGINE_TEST_SRC_MESHGEN_H_
#define ENGINE_TEST_SRC_MESHGEN_H_
#pragma once
#include <memory>
#include "resources/mesh.h"
std::unique_ptr<engine::Mesh> GenSphereMesh(
engine::GFXDevice* gfx, float r, int detail, bool wind_inside = false,
bool flip_normals = false);
std::unique_ptr<engine::Mesh> GenSphereMesh(engine::GFXDevice* gfx, float r, int detail, bool wind_inside = false, bool flip_normals = false);
std::unique_ptr<engine::Mesh> GenCuboidMesh(
engine::GFXDevice* gfx, float x, float y, float z, float tiling = 1.0f,
bool wind_inside = false);
#endif
std::unique_ptr<engine::Mesh> GenCuboidMesh(engine::GFXDevice* gfx, float x, float y, float z, float tiling = 1.0f, bool wind_inside = false);