diff --git a/README.md b/README.md index 5a30cee..1519ef2 100644 --- a/README.md +++ b/README.md @@ -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) @@ -57,4 +55,6 @@ 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. \ No newline at end of file +Added static soft shadows. + +Sort out LOG_X calls and ensure DEBUG, TRACE, INFO, etc are being used appropriately \ No newline at end of file diff --git a/include/application.h b/include/application.h index 2ba1539..fb4b133 100644 --- a/include/application.h +++ b/include/application.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_APPLICATION_H_ -#define ENGINE_INCLUDE_APPLICATION_H_ +#pragma once #include #include @@ -95,6 +94,4 @@ class Application { } }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/components/custom.h b/include/components/custom.h index 285d6c1..9f2fbd7 100644 --- a/include/components/custom.h +++ b/include/components/custom.h @@ -1,15 +1,12 @@ -#ifndef ENGINE_INCLUDE_COMPONENTS_CUSTOM_H_ -#define ENGINE_INCLUDE_COMPONENTS_CUSTOM_H_ +#pragma once #include namespace engine { struct CustomComponent { - std::function onInit; // void onInit(void); - std::function onUpdate; // void onUpdate(float ts); + std::function onInit; // void onInit(void); + std::function onUpdate; // void onUpdate(float ts); }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/components/mesh_renderable.h b/include/components/mesh_renderable.h index 5b5a761..d94b467 100644 --- a/include/components/mesh_renderable.h +++ b/include/components/mesh_renderable.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_COMPONENTS_MESH_RENDERABLE_H_ -#define ENGINE_INCLUDE_COMPONENTS_MESH_RENDERABLE_H_ +#pragma once #include @@ -9,11 +8,9 @@ namespace engine { struct MeshRenderableComponent { - std::shared_ptr mesh; - std::shared_ptr material; - bool visible = true; // for static meshes, changes to this may require the static render list to be rebuilt + std::shared_ptr mesh; + std::shared_ptr material; + bool visible = true; // for static meshes, changes to this may require the static render list to be rebuilt }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/components/transform.h b/include/components/transform.h index 99f4e64..e6a2168 100644 --- a/include/components/transform.h +++ b/include/components/transform.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_ -#define ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_ +#pragma once #include @@ -12,19 +11,17 @@ namespace engine { struct TransformComponent { - std::string tag; + std::string tag; - glm::mat4 world_matrix; + glm::mat4 world_matrix; - glm::quat rotation; - glm::vec3 position; - glm::vec3 scale; + glm::quat rotation; + glm::vec3 position; + glm::vec3 scale; - Entity parent; + Entity parent; - bool is_static; + bool is_static; }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/components/ui_renderable.h b/include/components/ui_renderable.h index 982e4b0..f532b03 100644 --- a/include/components/ui_renderable.h +++ b/include/components/ui_renderable.h @@ -2,8 +2,8 @@ namespace engine { - struct UIRenderableComponent { - int x; - }; +struct UIRenderableComponent { + int x; +}; -} // namespace engine \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/ecs.h b/include/ecs.h index 85bb895..890f544 100644 --- a/include/ecs.h +++ b/include/ecs.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_ECS_H_ -#define ENGINE_INCLUDE_ECS_H_ +#pragma once #include #include @@ -18,54 +17,55 @@ using Entity = uint32_t; // ECS entity constexpr size_t kMaxComponents = 10; class IComponentArray { - public: - virtual ~IComponentArray() = default; + public: + virtual ~IComponentArray() = default; }; template class ComponentArray : public IComponentArray { - public: - void InsertData(Entity entity, const T& component) { - if (component_array_.size() < entity + 1) { - component_array_.resize(entity + 1); + public: + void InsertData(Entity entity, const T& component) + { + if (component_array_.size() < entity + 1) { + component_array_.resize(entity + 1); + } + // bounds checking here as not performance critical + component_array_.at(entity) = component; } - // bounds checking here as not performance critical - component_array_.at(entity) = component; - } - void DeleteData(Entity entity) { - (void)entity; // TODO - } + void DeleteData(Entity entity) + { + (void)entity; // TODO + } - T* GetData(Entity entity) { - assert(entity < component_array_.size()); - return &component_array_[entity]; - } + T* GetData(Entity entity) + { + assert(entity < component_array_.size()); + return &component_array_[entity]; + } - private: - std::vector component_array_{}; + private: + std::vector component_array_{}; }; class System { - public: - System(Scene* scene, std::set required_component_hashes); - virtual ~System() {} - System(const System&) = delete; - System& operator=(const System&) = delete; + public: + System(Scene* scene, std::set required_component_hashes); + virtual ~System() {} + System(const System&) = delete; + System& operator=(const System&) = delete; - virtual void OnUpdate(float ts) = 0; + virtual void OnUpdate(float ts) = 0; - virtual void OnComponentInsert(Entity) {} - virtual void OnComponentRemove(Entity) {} + virtual void OnComponentInsert(Entity) {} + virtual void OnComponentRemove(Entity) {} - Scene* const scene_; + Scene* const scene_; - std::bitset signature_; + std::bitset signature_; - // entities that contain the needed components - std::set entities_{}; + // entities that contain the needed components + std::set entities_{}; }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/engine_api.h b/include/engine_api.h index 272a0f8..dd45887 100644 --- a/include/engine_api.h +++ b/include/engine_api.h @@ -1,6 +1,4 @@ -#ifndef ENGINE_INCLUDE_ENGINE_API_H_ -#define ENGINE_INCLUDE_ENGINE_API_H_ - +#pragma once /* #ifndef ENGINE_API # ifdef _MSC_VER @@ -15,6 +13,4 @@ #endif */ -#define ENGINE_API - -#endif \ No newline at end of file +#define ENGINE_API \ No newline at end of file diff --git a/include/event_system.h b/include/event_system.h index 83ab08b..128deb6 100644 --- a/include/event_system.h +++ b/include/event_system.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_EVENT_SYSTEM_H_ -#define ENGINE_INCLUDE_EVENT_SYSTEM_H_ +#pragma once #include #include @@ -10,115 +9,110 @@ namespace engine { enum class EventSubscriberKind { - kEntity, + kEntity, }; // Event handler base-class template class EventHandler { - public: - virtual void OnEvent(T data) = 0; + public: + virtual void OnEvent(T data) = 0; }; // Event queue interface to allow for different type queues to be in the map class IEventQueue { - public: - virtual ~IEventQueue() {} - virtual void DespatchEvents() = 0; + public: + virtual ~IEventQueue() {} + virtual void DespatchEvents() = 0; }; template class EventQueue : public IEventQueue { - // holds events of type T and subscribers to those events + // holds events of type T and subscribers to those events - public: - void Subscribe(EventSubscriberKind kind, uint32_t id, - EventHandler* 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!"); - subscribers_.emplace(id, handler); - } - - 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!"); - EventHandler* handler = subscribers_.at(id); - event_queue_.emplace(handler, event); - } - - void DespatchEvents() override { - while (event_queue_.empty() == false) { - auto [handler, event] = event_queue_.front(); - handler->OnEvent(event); - event_queue_.pop(); + public: + void Subscribe(EventSubscriberKind kind, uint32_t id, EventHandler* 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!"); + subscribers_.emplace(id, handler); } - } - private: - std::unordered_map*> subscribers_; + 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!"); + EventHandler* handler = subscribers_.at(id); + event_queue_.emplace(handler, event); + } - struct QueuedEvent { - QueuedEvent(EventHandler* handler, T event) - : handler(handler), event(event) {} + void DespatchEvents() override + { + while (event_queue_.empty() == false) { + auto [handler, event] = event_queue_.front(); + handler->OnEvent(event); + event_queue_.pop(); + } + } - EventHandler* handler; - T event; - }; - std::queue event_queue_{}; + private: + std::unordered_map*> subscribers_; + + struct QueuedEvent { + QueuedEvent(EventHandler* handler, T event) : handler(handler), event(event) {} + + EventHandler* handler; + T event; + }; + std::queue event_queue_{}; }; class EventSystem { - public: - EventSystem() {} - EventSystem(const EventSystem&) = delete; - EventSystem& operator=(const EventSystem&) = delete; - ~EventSystem() {} + public: + EventSystem() {} + EventSystem(const EventSystem&) = delete; + EventSystem& operator=(const EventSystem&) = delete; + ~EventSystem() {} - template - void RegisterEventType() { - size_t hash = typeid(T).hash_code(); - assert(event_queues_.contains(hash) == false && - "Registering an event queue more than once!"); - event_queues_.emplace(hash, std::make_unique>()); - } - - template - void SubscribeToEventType(EventSubscriberKind kind, uint32_t id, - EventHandler* handler) { - size_t hash = typeid(T).hash_code(); - assert(event_queues_.contains(hash) && - "Subscribing to event type that isn't registered!"); - EventQueue* queue = - dynamic_cast*>(event_queues_.at(hash).get()); - assert(queue != nullptr && "This cast should work?!! wot"); - queue->Subscribe(kind, id, handler); - } - - template - 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* queue = - dynamic_cast*>(event_queues_.at(hash).get()); - assert(queue != nullptr && "This cast should work?!! wot"); - queue->QueueEvent(kind, subscriber_id, event); - } - - void DespatchEvents() { - for (auto& [hash, queue] : event_queues_) { - queue->DespatchEvents(); + template + void RegisterEventType() + { + size_t hash = typeid(T).hash_code(); + assert(event_queues_.contains(hash) == false && "Registering an event queue more than once!"); + event_queues_.emplace(hash, std::make_unique>()); } - } - private: - std::unordered_map> event_queues_{}; + template + void SubscribeToEventType(EventSubscriberKind kind, uint32_t id, EventHandler* handler) + { + size_t hash = typeid(T).hash_code(); + assert(event_queues_.contains(hash) && "Subscribing to event type that isn't registered!"); + EventQueue* queue = dynamic_cast*>(event_queues_.at(hash).get()); + assert(queue != nullptr && "This cast should work?!! wot"); + queue->Subscribe(kind, id, handler); + } + + template + 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* queue = dynamic_cast*>(event_queues_.at(hash).get()); + assert(queue != nullptr && "This cast should work?!! wot"); + queue->QueueEvent(kind, subscriber_id, event); + } + + void DespatchEvents() + { + for (auto& [hash, queue] : event_queues_) { + queue->DespatchEvents(); + } + } + + private: + std::unordered_map> event_queues_{}; }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/gfx.h b/include/gfx.h index 8404041..2571cee 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_GFX_H_ -#define ENGINE_INCLUDE_GFX_H_ +#pragma once #include #include @@ -123,7 +122,7 @@ struct PipelineInfo { CullMode face_cull_mode; bool alpha_blending; bool write_z; - bool line_primitives; // false for triangles, true for lines + bool line_primitives; // false for triangles, true for lines bool depth_attachment_only; // false 99% of the time std::vector descriptor_set_layouts; }; @@ -168,6 +167,4 @@ struct hash { } }; -} // namespace std - -#endif \ No newline at end of file +} // namespace std \ No newline at end of file diff --git a/include/gfx_device.h b/include/gfx_device.h index f14d208..063810d 100644 --- a/include/gfx_device.h +++ b/include/gfx_device.h @@ -1,133 +1,108 @@ -#ifndef ENGINE_INCLUDE_GFX_DEVICE_H_ -#define ENGINE_INCLUDE_GFX_DEVICE_H_ +#pragma once #include #include "gfx.h" -struct SDL_Window; // -struct ImDrawData; // "imgui/imgui.h" +struct SDL_Window; // +struct ImDrawData; // "imgui/imgui.h" namespace engine { class GFXDevice { - public: - GFXDevice(const char* app_name, const char* app_version, SDL_Window* window, - gfx::GraphicsSettings settings); + public: + GFXDevice(const char* app_name, const char* app_version, SDL_Window* window, gfx::GraphicsSettings settings); - GFXDevice(const GFXDevice&) = delete; - GFXDevice& operator=(const GFXDevice&) = delete; - ~GFXDevice(); + GFXDevice(const GFXDevice&) = delete; + GFXDevice& operator=(const GFXDevice&) = delete; + ~GFXDevice(); - void GetViewportSize(uint32_t* w, uint32_t* h); + void GetViewportSize(uint32_t* w, uint32_t* h); - void SetupImguiBackend(); - void ShutdownImguiBackend(); - void CmdRenderImguiDrawData(gfx::DrawBuffer* draw_buffer, ImDrawData* draw_data); + void SetupImguiBackend(); + void ShutdownImguiBackend(); + void CmdRenderImguiDrawData(gfx::DrawBuffer* draw_buffer, ImDrawData* draw_data); - gfx::DrawBuffer* BeginRender(); + gfx::DrawBuffer* BeginRender(); - /* - draw_buffer MUST be a valid pointer returned by BeginRender(). - - draw_buffer is invalid after this function has been called. */ - void FinishRender(gfx::DrawBuffer* draw_buffer); + /* - draw_buffer MUST be a valid pointer returned by BeginRender(). + - draw_buffer is invalid after this function has been called. */ + void FinishRender(gfx::DrawBuffer* draw_buffer); - gfx::Image* CreateShadowmapImage(); - gfx::DrawBuffer* BeginShadowmapRender(gfx::Image* image); - void FinishShadowmapRender(gfx::DrawBuffer* draw_buffer, gfx::Image* image); + gfx::Image* CreateShadowmapImage(); + gfx::DrawBuffer* BeginShadowmapRender(gfx::Image* image); + void FinishShadowmapRender(gfx::DrawBuffer* draw_buffer, gfx::Image* image); - /* - 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); + /* - 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); - /* - 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); + /* - 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); - /* - 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); + /* - 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 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 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, - uint32_t first_instance); + void CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance); - void CmdPushConstants(gfx::DrawBuffer* draw_buffer, - const gfx::Pipeline* pipeline, uint32_t offset, - uint32_t size, const void* data); + 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); + 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); + gfx::Pipeline* CreatePipeline(const gfx::PipelineInfo& info); - void DestroyPipeline(const gfx::Pipeline* pipeline); + void DestroyPipeline(const gfx::Pipeline* pipeline); - gfx::DescriptorSetLayout* CreateDescriptorSetLayout( - const std::vector& bindings); + gfx::DescriptorSetLayout* CreateDescriptorSetLayout(const std::vector& bindings); - void DestroyDescriptorSetLayout(const gfx::DescriptorSetLayout* layout); + 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); + 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); + // 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 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 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); + // 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); - void DestroyBuffer(const gfx::Buffer* buffer); + void DestroyBuffer(const gfx::Buffer* buffer); - gfx::Image* CreateImage(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const void* image_data); + gfx::Image* CreateImage(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const void* image_data); - gfx::Image* CreateImageCubemap(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const std::array& image_data); + gfx::Image* CreateImageCubemap(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const std::array& image_data); - void DestroyImage(const gfx::Image* image); + void DestroyImage(const gfx::Image* image); - const gfx::Sampler* CreateSampler(const gfx::SamplerInfo& info); + const gfx::Sampler* CreateSampler(const gfx::SamplerInfo& info); - void DestroySampler(const gfx::Sampler* sampler); + void DestroySampler(const gfx::Sampler* sampler); - uint64_t GetFrameCount(); + uint64_t GetFrameCount(); - void LogPerformanceInfo(); + void LogPerformanceInfo(); - // wait until all the active GPU queues have finished working - void WaitIdle(); + // wait until all the active GPU queues have finished working + void WaitIdle(); - private: - struct Impl; - std::unique_ptr pimpl; + private: + struct Impl; + std::unique_ptr pimpl; }; -} // namespace engine - -#endif +} // namespace engine \ No newline at end of file diff --git a/include/input_manager.h b/include/input_manager.h index d2c3247..38f216c 100644 --- a/include/input_manager.h +++ b/include/input_manager.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_INPUT_MANAGER_H_ -#define ENGINE_INCLUDE_INPUT_MANAGER_H_ +#pragma once #include #include @@ -15,130 +14,113 @@ enum class InputDevice : int { kMouse, kKeyboard, kController, kSize }; // This class should be used to get platform/input-device independent input 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) { - assert(win != nullptr); - enabled_devices_.fill(true); - } - InputManager(const InputManager&) = delete; - - InputManager& operator=(const InputManager&) = delete; - - ~InputManager() {} - - void AddInputButton(const std::string& name, inputs::MouseButton button) { - AddInputDeviceButton(name, InputDevice::kMouse, static_cast(button)); - } - - void AddInputButton(const std::string& name, inputs::Key button) { - AddInputDeviceButton(name, InputDevice::kKeyboard, - static_cast(button)); - } - - void AddInputAxis(const std::string& name, inputs::MouseAxis axis) { - AddInputDeviceAxis(name, InputDevice::kMouse, static_cast(axis)); - } - - void AddInputButtonAsAxis(const std::string& name, inputs::MouseButton high, - inputs::MouseButton low) { - AddInputDeviceButtonAsAxis(name, InputDevice::kMouse, - static_cast(high), static_cast(low)); - } - - void AddInputButtonAsAxis(const std::string& name, inputs::Key high, - inputs::Key low) { - AddInputDeviceButtonAsAxis(name, InputDevice::kKeyboard, - static_cast(high), static_cast(low)); - } - - void DelInputButton(int index) { - std::vector::iterator it = button_entries_.begin(); - std::advance(it, index); - button_entries_.erase(it); - } - - void DelInputAxis(int index) { - std::vector::iterator it = axis_entries_.begin(); - std::advance(it, index); - axis_entries_.erase(it); - } - - void SetDeviceActive(enum InputDevice device, bool active) { - enabled_devices_[static_cast(device)] = active; - } - - bool GetDeviceActive(enum InputDevice device) const { - return enabled_devices_[static_cast(device)]; - } - - float GetAxis(const std::string& axis_name) const; - - bool GetButton(const std::string& button_name) const; - - bool GetButtonPress(const std::string& button_name) const; - - bool GetButtonRelease(const std::string& button_name) const; - - private: - struct ButtonEntry { - std::string name; - enum InputDevice device; - int button; // enumeration of device buttons or axes - }; - - struct AxisEntry { - std::string name; - enum InputDevice device; - int axis; - bool is_button_axis; - int high; - int low; - }; - - const Window* win_; - - std::vector button_entries_; - std::vector axis_entries_; - - std::array(InputDevice::kSize)> enabled_devices_; - - // private methods - - float GetDeviceAxis(enum InputDevice device, int axis) const; - - bool GetDeviceButton(enum InputDevice device, int button) const; - - bool getDeviceButtonDown(enum InputDevice device, int button) const; - - bool GetDeviceButtonUp(enum InputDevice device, int button) 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) { - if (GetDeviceButton(device, low)) value += -1.0f; + 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) + { + assert(win != nullptr); + enabled_devices_.fill(true); } - return value; - } + InputManager(const InputManager&) = delete; - void AddInputDeviceButton(const std::string& name, InputDevice device, - int button) { - button_entries_.push_back({name, device, button}); - } + InputManager& operator=(const InputManager&) = delete; - void AddInputDeviceAxis(const std::string& name, InputDevice device, - int axis) { - axis_entries_.push_back({name, device, axis, false, 0, 0}); - } + ~InputManager() {} - void AddInputDeviceButtonAsAxis(const std::string& name, InputDevice device, - int high, int low) { - axis_entries_.push_back({name, device, 0, true, high, low}); - } + void AddInputButton(const std::string& name, inputs::MouseButton button) { AddInputDeviceButton(name, InputDevice::kMouse, static_cast(button)); } + + void AddInputButton(const std::string& name, inputs::Key button) { AddInputDeviceButton(name, InputDevice::kKeyboard, static_cast(button)); } + + void AddInputAxis(const std::string& name, inputs::MouseAxis axis) { AddInputDeviceAxis(name, InputDevice::kMouse, static_cast(axis)); } + + void AddInputButtonAsAxis(const std::string& name, inputs::MouseButton high, inputs::MouseButton low) + { + AddInputDeviceButtonAsAxis(name, InputDevice::kMouse, static_cast(high), static_cast(low)); + } + + void AddInputButtonAsAxis(const std::string& name, inputs::Key high, inputs::Key low) + { + AddInputDeviceButtonAsAxis(name, InputDevice::kKeyboard, static_cast(high), static_cast(low)); + } + + void DelInputButton(int index) + { + std::vector::iterator it = button_entries_.begin(); + std::advance(it, index); + button_entries_.erase(it); + } + + void DelInputAxis(int index) + { + std::vector::iterator it = axis_entries_.begin(); + std::advance(it, index); + axis_entries_.erase(it); + } + + void SetDeviceActive(enum InputDevice device, bool active) { enabled_devices_[static_cast(device)] = active; } + + bool GetDeviceActive(enum InputDevice device) const { return enabled_devices_[static_cast(device)]; } + + float GetAxis(const std::string& axis_name) const; + + bool GetButton(const std::string& button_name) const; + + bool GetButtonPress(const std::string& button_name) const; + + bool GetButtonRelease(const std::string& button_name) const; + + private: + struct ButtonEntry { + std::string name; + enum InputDevice device; + int button; // enumeration of device buttons or axes + }; + + struct AxisEntry { + std::string name; + enum InputDevice device; + int axis; + bool is_button_axis; + int high; + int low; + }; + + const Window* win_; + + std::vector button_entries_; + std::vector axis_entries_; + + std::array(InputDevice::kSize)> enabled_devices_; + + // private methods + + float GetDeviceAxis(enum InputDevice device, int axis) const; + + bool GetDeviceButton(enum InputDevice device, int button) const; + + bool getDeviceButtonDown(enum InputDevice device, int button) const; + + bool GetDeviceButtonUp(enum InputDevice device, int button) 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) { + if (GetDeviceButton(device, low)) value += -1.0f; + } + return value; + } + + 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 AddInputDeviceButtonAsAxis(const std::string& name, InputDevice device, int high, int low) + { + axis_entries_.push_back({name, device, 0, true, high, low}); + } }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/inputs/keyboard.h b/include/inputs/keyboard.h index bc275b3..85b4ccc 100644 --- a/include/inputs/keyboard.h +++ b/include/inputs/keyboard.h @@ -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 @@ -7,373 +6,371 @@ namespace engine { namespace inputs { enum class Key : int { - K_UNKNOWN = 0, + K_UNKNOWN = 0, - /** - * \name Usage page 0x07 - * - * These values are from usage page 0x07 (USB keyboard page). - */ - /* @{ */ + /** + * \name Usage page 0x07 + * + * These values are from usage page 0x07 (USB keyboard page). + */ + /* @{ */ - K_A = 4, - K_B = 5, - K_C = 6, - K_D = 7, - K_E = 8, - K_F = 9, - K_G = 10, - K_H = 11, - K_I = 12, - K_J = 13, - K_K = 14, - K_L = 15, - K_M = 16, - K_N = 17, - K_O = 18, - K_P = 19, - K_Q = 20, - K_R = 21, - K_S = 22, - K_T = 23, - K_U = 24, - K_V = 25, - K_W = 26, - K_X = 27, - K_Y = 28, - K_Z = 29, + K_A = 4, + K_B = 5, + K_C = 6, + K_D = 7, + K_E = 8, + K_F = 9, + K_G = 10, + K_H = 11, + K_I = 12, + K_J = 13, + K_K = 14, + K_L = 15, + K_M = 16, + K_N = 17, + K_O = 18, + K_P = 19, + K_Q = 20, + K_R = 21, + K_S = 22, + K_T = 23, + K_U = 24, + K_V = 25, + K_W = 26, + K_X = 27, + K_Y = 28, + K_Z = 29, - K_1 = 30, - K_2 = 31, - K_3 = 32, - K_4 = 33, - K_5 = 34, - K_6 = 35, - K_7 = 36, - K_8 = 37, - K_9 = 38, - K_0 = 39, + K_1 = 30, + K_2 = 31, + K_3 = 32, + K_4 = 33, + K_5 = 34, + K_6 = 35, + K_7 = 36, + K_8 = 37, + K_9 = 38, + K_0 = 39, - K_RETURN = 40, - K_ESCAPE = 41, - K_BACKSPACE = 42, - K_TAB = 43, - K_SPACE = 44, + K_RETURN = 40, + K_ESCAPE = 41, + K_BACKSPACE = 42, + K_TAB = 43, + K_SPACE = 44, - K_MINUS = 45, - K_EQUALS = 46, - K_LEFTBRACKET = 47, - K_RIGHTBRACKET = 48, - K_BACKSLASH = 49, /**< Located at the lower left of the return - * key on ISO keyboards and at the right end - * of the QWERTY row on ANSI keyboards. - * Produces REVERSE SOLIDUS (backslash) and - * VERTICAL LINE in a US layout, REVERSE - * SOLIDUS and VERTICAL LINE in a UK Mac - * layout, NUMBER SIGN and TILDE in a UK - * Windows layout, DOLLAR SIGN and POUND SIGN - * in a Swiss German layout, NUMBER SIGN and - * APOSTROPHE in a German layout, GRAVE - * ACCENT and POUND SIGN in a French Mac - * layout, and ASTERISK and MICRO SIGN in a - * French Windows layout. - */ - K_NONUSHASH = 50, /**< ISO USB keyboards actually use this code - * instead of 49 for the same key, but all - * OSes I've seen treat the two codes - * identically. So, as an implementor, unless - * your keyboard generates both of those - * codes and your OS treats them differently, - * you should generate BACKSLASH - * instead of this code. As a user, you - * should not rely on this code because SDL - * will never generate it with most (all?) - * keyboards. - */ - K_SEMICOLON = 51, - K_APOSTROPHE = 52, - K_GRAVE = 53, /**< Located in the top left corner (on both ANSI - * and ISO keyboards). Produces GRAVE ACCENT and - * TILDE in a US Windows layout and in US and UK - * Mac layouts on ANSI keyboards, GRAVE ACCENT - * and NOT SIGN in a UK Windows layout, SECTION - * SIGN and PLUS-MINUS SIGN in US and UK Mac - * layouts on ISO keyboards, SECTION SIGN and - * DEGREE SIGN in a Swiss German layout (Mac: - * only on ISO keyboards), CIRCUMFLEX ACCENT and - * DEGREE SIGN in a German layout (Mac: only on - * ISO keyboards), SUPERSCRIPT TWO and TILDE in a - * French Windows layout, COMMERCIAL AT and - * NUMBER SIGN in a French Mac layout on ISO - * keyboards, and LESS-THAN SIGN and GREATER-THAN - * SIGN in a Swiss German, German, or French Mac - * layout on ANSI keyboards. - */ - K_COMMA = 54, - K_PERIOD = 55, - K_SLASH = 56, + K_MINUS = 45, + K_EQUALS = 46, + K_LEFTBRACKET = 47, + K_RIGHTBRACKET = 48, + K_BACKSLASH = 49, /**< Located at the lower left of the return + * key on ISO keyboards and at the right end + * of the QWERTY row on ANSI keyboards. + * Produces REVERSE SOLIDUS (backslash) and + * VERTICAL LINE in a US layout, REVERSE + * SOLIDUS and VERTICAL LINE in a UK Mac + * layout, NUMBER SIGN and TILDE in a UK + * Windows layout, DOLLAR SIGN and POUND SIGN + * in a Swiss German layout, NUMBER SIGN and + * APOSTROPHE in a German layout, GRAVE + * ACCENT and POUND SIGN in a French Mac + * layout, and ASTERISK and MICRO SIGN in a + * French Windows layout. + */ + K_NONUSHASH = 50, /**< ISO USB keyboards actually use this code + * instead of 49 for the same key, but all + * OSes I've seen treat the two codes + * identically. So, as an implementor, unless + * your keyboard generates both of those + * codes and your OS treats them differently, + * you should generate BACKSLASH + * instead of this code. As a user, you + * should not rely on this code because SDL + * will never generate it with most (all?) + * keyboards. + */ + K_SEMICOLON = 51, + K_APOSTROPHE = 52, + K_GRAVE = 53, /**< Located in the top left corner (on both ANSI + * and ISO keyboards). Produces GRAVE ACCENT and + * TILDE in a US Windows layout and in US and UK + * Mac layouts on ANSI keyboards, GRAVE ACCENT + * and NOT SIGN in a UK Windows layout, SECTION + * SIGN and PLUS-MINUS SIGN in US and UK Mac + * layouts on ISO keyboards, SECTION SIGN and + * DEGREE SIGN in a Swiss German layout (Mac: + * only on ISO keyboards), CIRCUMFLEX ACCENT and + * DEGREE SIGN in a German layout (Mac: only on + * ISO keyboards), SUPERSCRIPT TWO and TILDE in a + * French Windows layout, COMMERCIAL AT and + * NUMBER SIGN in a French Mac layout on ISO + * keyboards, and LESS-THAN SIGN and GREATER-THAN + * SIGN in a Swiss German, German, or French Mac + * layout on ANSI keyboards. + */ + K_COMMA = 54, + K_PERIOD = 55, + K_SLASH = 56, - K_CAPSLOCK = 57, + K_CAPSLOCK = 57, - K_F1 = 58, - K_F2 = 59, - K_F3 = 60, - K_F4 = 61, - K_F5 = 62, - K_F6 = 63, - K_F7 = 64, - K_F8 = 65, - K_F9 = 66, - K_F10 = 67, - K_F11 = 68, - K_F12 = 69, + K_F1 = 58, + K_F2 = 59, + K_F3 = 60, + K_F4 = 61, + K_F5 = 62, + K_F6 = 63, + K_F7 = 64, + K_F8 = 65, + K_F9 = 66, + K_F10 = 67, + K_F11 = 68, + K_F12 = 69, - K_PRINTSCREEN = 70, - K_SCROLLLOCK = 71, - K_PAUSE = 72, - K_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but - does send code 73, not 117) */ - K_HOME = 74, - K_PAGEUP = 75, - K_DELETE = 76, - K_END = 77, - K_PAGEDOWN = 78, - K_RIGHT = 79, - K_LEFT = 80, - K_DOWN = 81, - K_UP = 82, + K_PRINTSCREEN = 70, + K_SCROLLLOCK = 71, + K_PAUSE = 72, + K_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but + does send code 73, not 117) */ + K_HOME = 74, + K_PAGEUP = 75, + K_DELETE = 76, + K_END = 77, + K_PAGEDOWN = 78, + K_RIGHT = 79, + K_LEFT = 80, + K_DOWN = 81, + K_UP = 82, - K_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards - */ - K_KP_DIVIDE = 84, - K_KP_MULTIPLY = 85, - K_KP_MINUS = 86, - K_KP_PLUS = 87, - K_KP_ENTER = 88, - K_KP_1 = 89, - K_KP_2 = 90, - K_KP_3 = 91, - K_KP_4 = 92, - K_KP_5 = 93, - K_KP_6 = 94, - K_KP_7 = 95, - K_KP_8 = 96, - K_KP_9 = 97, - K_KP_0 = 98, - K_KP_PERIOD = 99, + K_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards + */ + K_KP_DIVIDE = 84, + K_KP_MULTIPLY = 85, + K_KP_MINUS = 86, + K_KP_PLUS = 87, + K_KP_ENTER = 88, + K_KP_1 = 89, + K_KP_2 = 90, + K_KP_3 = 91, + K_KP_4 = 92, + K_KP_5 = 93, + K_KP_6 = 94, + K_KP_7 = 95, + K_KP_8 = 96, + K_KP_9 = 97, + K_KP_0 = 98, + K_KP_PERIOD = 99, - K_NONUSBACKSLASH = 100, /**< This is the additional key that ISO - * keyboards have over ANSI ones, - * located between left shift and Y. - * Produces GRAVE ACCENT and TILDE in a - * US or UK Mac layout, REVERSE SOLIDUS - * (backslash) and VERTICAL LINE in a - * US or UK Windows layout, and - * LESS-THAN SIGN and GREATER-THAN SIGN - * in a Swiss German, German, or French - * layout. */ - K_APPLICATION = 101, /**< windows contextual menu, compose */ - K_POWER = 102, /**< The USB document says this is a status flag, - * not a physical key - but some Mac keyboards - * do have a power key. */ - K_KP_EQUALS = 103, - K_F13 = 104, - K_F14 = 105, - K_F15 = 106, - K_F16 = 107, - K_F17 = 108, - K_F18 = 109, - K_F19 = 110, - K_F20 = 111, - K_F21 = 112, - K_F22 = 113, - K_F23 = 114, - K_F24 = 115, - K_EXECUTE = 116, - K_HELP = 117, - K_MENU = 118, - K_SELECT = 119, - K_STOP = 120, - K_AGAIN = 121, /**< redo */ - K_UNDO = 122, - K_CUT = 123, - K_COPY = 124, - K_PASTE = 125, - K_FIND = 126, - K_MUTE = 127, - K_VOLUMEUP = 128, - K_VOLUMEDOWN = 129, - /* not sure whether there's a reason to enable these */ - /* LOCKINGCAPSLOCK = 130, */ - /* LOCKINGNUMLOCK = 131, */ - /* LOCKINGSCROLLLOCK = 132, */ - K_KP_COMMA = 133, - K_KP_EQUALSAS400 = 134, + K_NONUSBACKSLASH = 100, /**< This is the additional key that ISO + * keyboards have over ANSI ones, + * located between left shift and Y. + * Produces GRAVE ACCENT and TILDE in a + * US or UK Mac layout, REVERSE SOLIDUS + * (backslash) and VERTICAL LINE in a + * US or UK Windows layout, and + * LESS-THAN SIGN and GREATER-THAN SIGN + * in a Swiss German, German, or French + * layout. */ + K_APPLICATION = 101, /**< windows contextual menu, compose */ + K_POWER = 102, /**< The USB document says this is a status flag, + * not a physical key - but some Mac keyboards + * do have a power key. */ + K_KP_EQUALS = 103, + K_F13 = 104, + K_F14 = 105, + K_F15 = 106, + K_F16 = 107, + K_F17 = 108, + K_F18 = 109, + K_F19 = 110, + K_F20 = 111, + K_F21 = 112, + K_F22 = 113, + K_F23 = 114, + K_F24 = 115, + K_EXECUTE = 116, + K_HELP = 117, + K_MENU = 118, + K_SELECT = 119, + K_STOP = 120, + K_AGAIN = 121, /**< redo */ + K_UNDO = 122, + K_CUT = 123, + K_COPY = 124, + K_PASTE = 125, + K_FIND = 126, + K_MUTE = 127, + K_VOLUMEUP = 128, + K_VOLUMEDOWN = 129, + /* not sure whether there's a reason to enable these */ + /* LOCKINGCAPSLOCK = 130, */ + /* LOCKINGNUMLOCK = 131, */ + /* LOCKINGSCROLLLOCK = 132, */ + K_KP_COMMA = 133, + K_KP_EQUALSAS400 = 134, - K_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see - footnotes in USB doc */ - K_INTERNATIONAL2 = 136, - K_INTERNATIONAL3 = 137, /**< Yen */ - K_INTERNATIONAL4 = 138, - K_INTERNATIONAL5 = 139, - K_INTERNATIONAL6 = 140, - K_INTERNATIONAL7 = 141, - K_INTERNATIONAL8 = 142, - K_INTERNATIONAL9 = 143, - K_LANG1 = 144, /**< Hangul/English toggle */ - K_LANG2 = 145, /**< Hanja conversion */ - K_LANG3 = 146, /**< Katakana */ - K_LANG4 = 147, /**< Hiragana */ - K_LANG5 = 148, /**< Zenkaku/Hankaku */ - K_LANG6 = 149, /**< reserved */ - K_LANG7 = 150, /**< reserved */ - K_LANG8 = 151, /**< reserved */ - K_LANG9 = 152, /**< reserved */ + K_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see + footnotes in USB doc */ + K_INTERNATIONAL2 = 136, + K_INTERNATIONAL3 = 137, /**< Yen */ + K_INTERNATIONAL4 = 138, + K_INTERNATIONAL5 = 139, + K_INTERNATIONAL6 = 140, + K_INTERNATIONAL7 = 141, + K_INTERNATIONAL8 = 142, + K_INTERNATIONAL9 = 143, + K_LANG1 = 144, /**< Hangul/English toggle */ + K_LANG2 = 145, /**< Hanja conversion */ + K_LANG3 = 146, /**< Katakana */ + K_LANG4 = 147, /**< Hiragana */ + K_LANG5 = 148, /**< Zenkaku/Hankaku */ + K_LANG6 = 149, /**< reserved */ + K_LANG7 = 150, /**< reserved */ + K_LANG8 = 151, /**< reserved */ + K_LANG9 = 152, /**< reserved */ - K_ALTERASE = 153, /**< Erase-Eaze */ - K_SYSREQ = 154, - K_CANCEL = 155, - K_CLEAR = 156, - K_PRIOR = 157, - K_RETURN2 = 158, - K_SEPARATOR = 159, - K_OUT = 160, - K_OPER = 161, - K_CLEARAGAIN = 162, - K_CRSEL = 163, - K_EXSEL = 164, + K_ALTERASE = 153, /**< Erase-Eaze */ + K_SYSREQ = 154, + K_CANCEL = 155, + K_CLEAR = 156, + K_PRIOR = 157, + K_RETURN2 = 158, + K_SEPARATOR = 159, + K_OUT = 160, + K_OPER = 161, + K_CLEARAGAIN = 162, + K_CRSEL = 163, + K_EXSEL = 164, - K_KP_00 = 176, - K_KP_000 = 177, - K_THOUSANDSSEPARATOR = 178, - K_DECIMALSEPARATOR = 179, - K_CURRENCYUNIT = 180, - K_CURRENCYSUBUNIT = 181, - K_KP_LEFTPAREN = 182, - K_KP_RIGHTPAREN = 183, - K_KP_LEFTBRACE = 184, - K_KP_RIGHTBRACE = 185, - K_KP_TAB = 186, - K_KP_BACKSPACE = 187, - K_KP_A = 188, - K_KP_B = 189, - K_KP_C = 190, - K_KP_D = 191, - K_KP_E = 192, - K_KP_F = 193, - K_KP_XOR = 194, - K_KP_POWER = 195, - K_KP_PERCENT = 196, - K_KP_LESS = 197, - K_KP_GREATER = 198, - K_KP_AMPERSAND = 199, - K_KP_DBLAMPERSAND = 200, - K_KP_VERTICALBAR = 201, - K_KP_DBLVERTICALBAR = 202, - K_KP_COLON = 203, - K_KP_HASH = 204, - K_KP_SPACE = 205, - K_KP_AT = 206, - K_KP_EXCLAM = 207, - K_KP_MEMSTORE = 208, - K_KP_MEMRECALL = 209, - K_KP_MEMCLEAR = 210, - K_KP_MEMADD = 211, - K_KP_MEMSUBTRACT = 212, - K_KP_MEMMULTIPLY = 213, - K_KP_MEMDIVIDE = 214, - K_KP_PLUSMINUS = 215, - K_KP_CLEAR = 216, - K_KP_CLEARENTRY = 217, - K_KP_BINARY = 218, - K_KP_OCTAL = 219, - K_KP_DECIMAL = 220, - K_KP_HEXADECIMAL = 221, + K_KP_00 = 176, + K_KP_000 = 177, + K_THOUSANDSSEPARATOR = 178, + K_DECIMALSEPARATOR = 179, + K_CURRENCYUNIT = 180, + K_CURRENCYSUBUNIT = 181, + K_KP_LEFTPAREN = 182, + K_KP_RIGHTPAREN = 183, + K_KP_LEFTBRACE = 184, + K_KP_RIGHTBRACE = 185, + K_KP_TAB = 186, + K_KP_BACKSPACE = 187, + K_KP_A = 188, + K_KP_B = 189, + K_KP_C = 190, + K_KP_D = 191, + K_KP_E = 192, + K_KP_F = 193, + K_KP_XOR = 194, + K_KP_POWER = 195, + K_KP_PERCENT = 196, + K_KP_LESS = 197, + K_KP_GREATER = 198, + K_KP_AMPERSAND = 199, + K_KP_DBLAMPERSAND = 200, + K_KP_VERTICALBAR = 201, + K_KP_DBLVERTICALBAR = 202, + K_KP_COLON = 203, + K_KP_HASH = 204, + K_KP_SPACE = 205, + K_KP_AT = 206, + K_KP_EXCLAM = 207, + K_KP_MEMSTORE = 208, + K_KP_MEMRECALL = 209, + K_KP_MEMCLEAR = 210, + K_KP_MEMADD = 211, + K_KP_MEMSUBTRACT = 212, + K_KP_MEMMULTIPLY = 213, + K_KP_MEMDIVIDE = 214, + K_KP_PLUSMINUS = 215, + K_KP_CLEAR = 216, + K_KP_CLEARENTRY = 217, + K_KP_BINARY = 218, + K_KP_OCTAL = 219, + K_KP_DECIMAL = 220, + K_KP_HEXADECIMAL = 221, - K_LCTRL = 224, - K_LSHIFT = 225, - K_LALT = 226, /**< alt, option */ - K_LGUI = 227, /**< windows, command (apple), meta */ - K_RCTRL = 228, - K_RSHIFT = 229, - K_RALT = 230, /**< alt gr, option */ - K_RGUI = 231, /**< windows, command (apple), meta */ + K_LCTRL = 224, + K_LSHIFT = 225, + K_LALT = 226, /**< alt, option */ + K_LGUI = 227, /**< windows, command (apple), meta */ + K_RCTRL = 228, + K_RSHIFT = 229, + K_RALT = 230, /**< alt gr, option */ + K_RGUI = 231, /**< windows, command (apple), meta */ - K_MODE = 257, /**< I'm not sure if this is really not covered - * by any of the above, but since there's a - * special KMOD_MODE for it I'm adding it here - */ + K_MODE = 257, /**< I'm not sure if this is really not covered + * by any of the above, but since there's a + * special KMOD_MODE for it I'm adding it here + */ - /* @} */ /* Usage page 0x07 */ + /* @} */ /* Usage page 0x07 */ - /** - * \name Usage page 0x0C - * - * These values are mapped from usage page 0x0C (USB consumer page). - */ - /* @{ */ + /** + * \name Usage page 0x0C + * + * These values are mapped from usage page 0x0C (USB consumer page). + */ + /* @{ */ - K_AUDIONEXT = 258, - K_AUDIOPREV = 259, - K_AUDIOSTOP = 260, - K_AUDIOPLAY = 261, - K_AUDIOMUTE = 262, - K_MEDIASELECT = 263, - K_WWW = 264, - K_MAIL = 265, - K_CALCULATOR = 266, - K_COMPUTER = 267, - K_AC_SEARCH = 268, - K_AC_HOME = 269, - K_AC_BACK = 270, - K_AC_FORWARD = 271, - K_AC_STOP = 272, - K_AC_REFRESH = 273, - K_AC_BOOKMARKS = 274, + K_AUDIONEXT = 258, + K_AUDIOPREV = 259, + K_AUDIOSTOP = 260, + K_AUDIOPLAY = 261, + K_AUDIOMUTE = 262, + K_MEDIASELECT = 263, + K_WWW = 264, + K_MAIL = 265, + K_CALCULATOR = 266, + K_COMPUTER = 267, + K_AC_SEARCH = 268, + K_AC_HOME = 269, + K_AC_BACK = 270, + K_AC_FORWARD = 271, + K_AC_STOP = 272, + K_AC_REFRESH = 273, + K_AC_BOOKMARKS = 274, - /* @} */ /* Usage page 0x0C */ + /* @} */ /* Usage page 0x0C */ - /** - * \name Walther keys - * - * These are values that Christian Walther added (for mac keyboard?). - */ - /* @{ */ + /** + * \name Walther keys + * + * These are values that Christian Walther added (for mac keyboard?). + */ + /* @{ */ - K_BRIGHTNESSDOWN = 275, - K_BRIGHTNESSUP = 276, - K_DISPLAYSWITCH = 277, /**< display mirroring/dual display - switch, video mode switch */ - K_KBDILLUMTOGGLE = 278, - K_KBDILLUMDOWN = 279, - K_KBDILLUMUP = 280, - K_EJECT = 281, - K_SLEEP = 282, + K_BRIGHTNESSDOWN = 275, + K_BRIGHTNESSUP = 276, + K_DISPLAYSWITCH = 277, /**< display mirroring/dual display + switch, video mode switch */ + K_KBDILLUMTOGGLE = 278, + K_KBDILLUMDOWN = 279, + K_KBDILLUMUP = 280, + K_EJECT = 281, + K_SLEEP = 282, - K_APP1 = 283, - K_APP2 = 284, + K_APP1 = 283, + K_APP2 = 284, - /* @} */ /* Walther keys */ + /* @} */ /* Walther keys */ - /** - * \name Usage page 0x0C (additional media keys) - * - * These values are mapped from usage page 0x0C (USB consumer page). - */ - /* @{ */ + /** + * \name Usage page 0x0C (additional media keys) + * + * These values are mapped from usage page 0x0C (USB consumer page). + */ + /* @{ */ - K_AUDIOREWIND = 285, - K_AUDIOFASTFORWARD = 286, + K_AUDIOREWIND = 285, + K_AUDIOFASTFORWARD = 286, - /* @} */ /* Usage page 0x0C (additional media keys) */ + /* @} */ /* Usage page 0x0C (additional media keys) */ - /* Add any other keys here. */ + /* Add any other keys here. */ - NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes - for array bounds */ + NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes + for array bounds */ }; -} // namespace inputs -} // namespace engine - -#endif \ No newline at end of file +} // namespace inputs +} // namespace engine \ No newline at end of file diff --git a/include/inputs/mouse.h b/include/inputs/mouse.h index ccc20e8..e5db720 100644 --- a/include/inputs/mouse.h +++ b/include/inputs/mouse.h @@ -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 \ No newline at end of file +} // namespace inputs +} // namespace engine \ No newline at end of file diff --git a/include/log.h b/include/log.h index 8cd8ef5..77a787d 100644 --- a/include/log.h +++ b/include/log.h @@ -1,11 +1,10 @@ -#ifndef ENGINE_INCLUDE_LOG_H_ -#define ENGINE_INCLUDE_LOG_H_ +#pragma once #ifdef NDEBUG -#define SPDLOG_ACTIVE_LEVEL 2 // info, warn, error, critical -//#define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical +#define SPDLOG_ACTIVE_LEVEL 2 // info, warn, error, critical +// #define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical #else -#define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical +#define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical #endif #include @@ -15,6 +14,4 @@ #define LOG_INFO SPDLOG_INFO #define LOG_WARN SPDLOG_WARN #define LOG_ERROR SPDLOG_ERROR -#define LOG_CRITICAL SPDLOG_CRITICAL - -#endif \ No newline at end of file +#define LOG_CRITICAL SPDLOG_CRITICAL \ No newline at end of file diff --git a/include/logger.h b/include/logger.h index af36dc2..f412d1d 100644 --- a/include/logger.h +++ b/include/logger.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_LOGGER_H_ -#define ENGINE_INCLUDE_LOGGER_H_ +#pragma once #include #include @@ -12,40 +11,36 @@ namespace engine { // To be executed in the target application, NOT engine.dll -void SetupLog(const char* appName) { - const std::string LOG_FILENAME{std::string(appName) + ".log"}; +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}; + // RELEASE + const std::filesystem::path log_path{std::filesystem::temp_directory_path() / LOG_FILENAME}; #else - // DEBUG - const std::filesystem::path log_path{LOG_FILENAME}; + // DEBUG + const std::filesystem::path log_path{LOG_FILENAME}; #endif - std::vector sinks; + std::vector sinks; - sinks.emplace_back(std::make_shared( - log_path.string(), true)); - sinks.back()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v"); + sinks.emplace_back(std::make_shared(log_path.string(), true)); + sinks.back()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v"); - sinks.emplace_back(std::make_shared()); - sinks.back()->set_pattern("[%H:%M:%S.%e] [%l] %v"); + sinks.emplace_back(std::make_shared()); + sinks.back()->set_pattern("[%H:%M:%S.%e] [%l] %v"); - auto logger = - std::make_shared(appName, sinks.begin(), sinks.end()); + auto logger = std::make_shared(appName, sinks.begin(), sinks.end()); - // Logs below INFO are ignored through macros in release (see log.hpp) - logger->set_level(spdlog::level::trace); + // Logs below INFO are ignored through macros in release (see log.hpp) + logger->set_level(spdlog::level::trace); - spdlog::register_logger(logger); - spdlog::set_default_logger(logger); - spdlog::flush_every(std::chrono::seconds(60)); + spdlog::register_logger(logger); + spdlog::set_default_logger(logger); + spdlog::flush_every(std::chrono::seconds(60)); - LOG_INFO("Created log with path: {}", log_path.string()); + LOG_INFO("Created log with path: {}", log_path.string()); } -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/renderer.h b/include/renderer.h index eda62d4..ca97f6f 100644 --- a/include/renderer.h +++ b/include/renderer.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_RENDERER_H_ -#define ENGINE_INCLUDE_RENDERER_H_ +#pragma once #include #include @@ -90,7 +89,7 @@ class Renderer : private ApplicationComponent { glm::mat4 lightSpaceMatrix; }; UniformDescriptor global_uniform; // rarely updates; set 0 binding 0 - UniformDescriptor frame_uniform; // updates once per frame; set 1 binding 0 + UniformDescriptor frame_uniform; // updates once per frame; set 1 binding 0 // in fragment shader const gfx::DescriptorSetLayout* material_set_layout; // set 2; set bound per material @@ -119,6 +118,4 @@ class Renderer : private ApplicationComponent { void DrawRenderList(gfx::DrawBuffer* draw_buffer, const RenderList& render_list); }; -} // namespace engine - -#endif +} // namespace engine \ No newline at end of file diff --git a/include/resource_manager.h b/include/resource_manager.h index 2b43d25..1c94b31 100644 --- a/include/resource_manager.h +++ b/include/resource_manager.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_RESOURCE_MANAGER_H_ -#define ENGINE_INCLUDE_RESOURCE_MANAGER_H_ +#pragma once #include #include @@ -15,52 +14,49 @@ namespace engine { class IResourceManager { - public: - virtual ~IResourceManager(){}; + public: + virtual ~IResourceManager(){}; }; template class ResourceManager : public IResourceManager { - public: - ~ResourceManager() override { - LOG_DEBUG("Destroying resource manager... '{}'", typeid(T).name()); - } + public: + ~ResourceManager() override { LOG_DEBUG("Destroying resource manager... '{}'", typeid(T).name()); } - std::shared_ptr Add(const std::string& name, - std::unique_ptr&& resource) { - if (resources_.contains(name) == false) { - std::shared_ptr resource_shared(std::move(resource)); - resources_.emplace(name, resource_shared); - return resource_shared; - } else { - throw std::runtime_error("Cannot add a resource which already exists"); + std::shared_ptr Add(const std::string& name, std::unique_ptr&& resource) + { + if (resources_.contains(name) == false) { + std::shared_ptr resource_shared(std::move(resource)); + resources_.emplace(name, resource_shared); + return resource_shared; + } + else { + throw std::runtime_error("Cannot add a resource which already exists"); + } } - } - void AddPersistent(const std::string& name, std::unique_ptr&& resource) { - persistent_resources_.push_back(Add(name, std::move(resource))); - } + void AddPersistent(const std::string& name, std::unique_ptr&& resource) { persistent_resources_.push_back(Add(name, std::move(resource))); } - std::shared_ptr Get(const std::string& name) { - if (resources_.contains(name)) { - std::weak_ptr ptr = resources_.at(name); - if (ptr.expired() == false) { - return ptr.lock(); - } else { - resources_.erase(name); - } + std::shared_ptr Get(const std::string& name) + { + if (resources_.contains(name)) { + std::weak_ptr ptr = resources_.at(name); + if (ptr.expired() == false) { + return ptr.lock(); + } + else { + resources_.erase(name); + } + } + // resource doesn't exist: + throw std::runtime_error("Resource doesn't exist: " + name); + return {}; } - // resource doesn't exist: - throw std::runtime_error("Resource doesn't exist: " + name); - return {}; - } - private: - std::unordered_map> resources_{}; - // This array owns persistent resources - std::vector> persistent_resources_{}; + private: + std::unordered_map> resources_{}; + // This array owns persistent resources + std::vector> persistent_resources_{}; }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/resources/font.h b/include/resources/font.h index f6321f1..abac082 100644 --- a/include/resources/font.h +++ b/include/resources/font.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_RESOURCES_FONT_H_ -#define ENGINE_INCLUDE_RESOURCES_FONT_H_ +#pragma once #include #include @@ -11,25 +10,20 @@ namespace engine { class Font { - public: - Font(const std::string& path); - ~Font(); - Font(const Font&) = delete; - Font& operator=(const Font&) = delete; + public: + Font(const std::string& path); + ~Font(); + Font(const Font&) = delete; + Font& operator=(const Font&) = delete; - std::unique_ptr> GetTextBitmap(const std::string& text, - float height_px, - int& width_out, - int& height_out); + std::unique_ptr> GetTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out); - private: - std::unique_ptr font_info_{}; - std::unique_ptr> font_buffer_{}; - std::map unicode_to_glyph_{}; + private: + std::unique_ptr font_info_{}; + std::unique_ptr> font_buffer_{}; + std::map unicode_to_glyph_{}; - int GetGlyphIndex(int unicode_codepoint); + int GetGlyphIndex(int unicode_codepoint); }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/resources/material.h b/include/resources/material.h index 2520cff..b035720 100644 --- a/include/resources/material.h +++ b/include/resources/material.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_RESOURCES_MATERIAL_H_ -#define ENGINE_INCLUDE_RESOURCES_MATERIAL_H_ +#pragma once #include @@ -35,6 +34,4 @@ class Material { Renderer* const renderer_; }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/resources/mesh.h b/include/resources/mesh.h index 57183b8..ad23244 100644 --- a/include/resources/mesh.h +++ b/include/resources/mesh.h @@ -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 #include @@ -46,6 +44,4 @@ class Mesh { void InitMesh(const std::vector& vertices, const std::vector& indices); }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/resources/shader.h b/include/resources/shader.h index 50737f0..f67a221 100644 --- a/include/resources/shader.h +++ b/include/resources/shader.h @@ -7,38 +7,37 @@ namespace engine { class Shader { - public: - // defines what vertex inputs are defined, position is always vec3 - struct VertexParams { - bool has_normal; // vec3 - bool has_tangent; // vec3 - bool has_color; // vec3 - bool has_uv0; // vec2 - }; + public: + // defines what vertex inputs are defined, position is always vec3 + struct VertexParams { + bool has_normal; // vec3 + bool has_tangent; // vec3 + bool has_color; // vec3 + bool has_uv0; // vec2 + }; - struct ShaderSettings { - VertexParams vertexParams; - bool alpha_blending; - bool cull_backface; - bool write_z; - int render_order; - }; + struct ShaderSettings { + VertexParams vertexParams; + bool alpha_blending; + bool cull_backface; + bool write_z; + int render_order; + }; - static constexpr int kHighestRenderOrder = 1; + static constexpr int kHighestRenderOrder = 1; - 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; + 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; - const gfx::Pipeline* GetPipeline(); - int GetRenderOrder() { return render_order_; } + const gfx::Pipeline* GetPipeline(); + int GetRenderOrder() { return render_order_; } - private: - GFXDevice* const gfx_; - const gfx::Pipeline* pipeline_; - const int render_order_; + private: + GFXDevice* const gfx_; + const gfx::Pipeline* pipeline_; + const int render_order_; }; -} // namespace engine \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/resources/texture.h b/include/resources/texture.h index 093ea36..15388bc 100644 --- a/include/resources/texture.h +++ b/include/resources/texture.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_RESOURCES_TEXTURE_H_ -#define ENGINE_INCLUDE_RESOURCES_TEXTURE_H_ +#pragma once #include @@ -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(); @@ -28,6 +26,4 @@ class Texture { std::unique_ptr LoadTextureFromFile(const std::string& path, gfx::SamplerInfo samplerInfo, Renderer* renderer, bool srgb = true); -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/scene.h b/include/scene.h index a7d288b..6218012 100644 --- a/include/scene.h +++ b/include/scene.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_SCENE_H_ -#define ENGINE_INCLUDE_SCENE_H_ +#pragma once #include #include @@ -70,21 +69,13 @@ class Scene { } // because GetComponent(entity); - } + TransformComponent* GetTransform(Entity entity) { return GetComponent(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 T* AddComponent(Entity entity, const T& comp = T{}) @@ -173,6 +164,4 @@ class Scene { std::unique_ptr event_system_{}; }; -} // namespace engine - -#endif +} // namespace engine \ No newline at end of file diff --git a/include/scene_manager.h b/include/scene_manager.h index 2f7df02..3a479d2 100644 --- a/include/scene_manager.h +++ b/include/scene_manager.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_SCENE_MANAGER_H_ -#define ENGINE_INCLUDE_SCENE_MANAGER_H_ +#pragma once #include #include @@ -56,6 +55,4 @@ class SceneManager { int active_scene_index_ = -1; }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/systems/collisions.h b/include/systems/collisions.h index 7c76ea8..7d54c20 100644 --- a/include/systems/collisions.h +++ b/include/systems/collisions.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_ -#define ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_ +#pragma once #include #include @@ -74,6 +73,4 @@ class CollisionSystem : public System { static int BuildNode(std::vector& prims, std::vector& tree_nodes); }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/systems/custom_behaviour.h b/include/systems/custom_behaviour.h index 14bc0e7..4bc045a 100644 --- a/include/systems/custom_behaviour.h +++ b/include/systems/custom_behaviour.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_CUSTOM_BEHAVIOUR_H_ -#define ENGINE_INCLUDE_CUSTOM_BEHAVIOUR_H_ +#pragma once #include @@ -11,17 +10,15 @@ namespace engine { class CustomBehaviourSystem : public System { - public: - CustomBehaviourSystem(Scene* scene); - ~CustomBehaviourSystem(); + public: + CustomBehaviourSystem(Scene* scene); + ~CustomBehaviourSystem(); - void OnUpdate(float ts) override; - void OnComponentInsert(Entity entity) override; + void OnUpdate(float ts) override; + void OnComponentInsert(Entity entity) override; - private: - std::unordered_map entity_is_initialised_{}; + private: + std::unordered_map entity_is_initialised_{}; }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/systems/mesh_render_system.h b/include/systems/mesh_render_system.h index 3728b6d..f86bc0f 100644 --- a/include/systems/mesh_render_system.h +++ b/include/systems/mesh_render_system.h @@ -9,37 +9,36 @@ namespace engine { struct RenderListEntry { - const gfx::Pipeline* pipeline; - const gfx::Buffer* vertex_buffer; - const gfx::Buffer* index_buffer; - const gfx::DescriptorSet* material_set; - glm::mat4 model_matrix; - uint32_t index_count; + const gfx::Pipeline* pipeline; + const gfx::Buffer* vertex_buffer; + const gfx::Buffer* index_buffer; + const gfx::DescriptorSet* material_set; + glm::mat4 model_matrix; + uint32_t index_count; }; using RenderList = std::vector; class MeshRenderSystem : public System { - public: - MeshRenderSystem(Scene* scene); - ~MeshRenderSystem(); + public: + MeshRenderSystem(Scene* scene); + ~MeshRenderSystem(); - void RebuildStaticRenderList(); - const RenderList* GetStaticRenderList() const { return &static_render_list_; } - const RenderList* GetDynamicRenderList() const { return &dynamic_render_list_; } + void RebuildStaticRenderList(); + const RenderList* GetStaticRenderList() const { return &static_render_list_; } + const RenderList* GetDynamicRenderList() const { return &dynamic_render_list_; } - void OnComponentInsert(Entity entity) override; - void OnUpdate(float ts) override; + void OnComponentInsert(Entity entity) override; + void OnUpdate(float ts) override; - private: - RenderList static_render_list_; - RenderList dynamic_render_list_; - bool list_needs_rebuild_ = false; - - // 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); + private: + RenderList static_render_list_; + RenderList dynamic_render_list_; + bool list_needs_rebuild_ = false; + // 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 \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/systems/transform.h b/include/systems/transform.h index a0baf34..328710a 100644 --- a/include/systems/transform.h +++ b/include/systems/transform.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_ -#define ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_ +#pragma once #include "ecs.h" @@ -12,13 +11,11 @@ class TransformSystem : public System { void OnUpdate(float ts) override; - /* + /* * Linear-searches for an entity that matches the arguments' criteria. * Take care not to create multiple entities under a parent with the same tag, as this search will only find the first in the list. */ Entity GetChildEntity(Entity parent, const std::string& tag); }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/systems/ui_render_system.h b/include/systems/ui_render_system.h index 06936d6..31c7791 100644 --- a/include/systems/ui_render_system.h +++ b/include/systems/ui_render_system.h @@ -8,16 +8,15 @@ namespace engine { - class UIRenderSystem : public System { - public: - UIRenderSystem(Scene* scene); - ~UIRenderSystem(); +class UIRenderSystem : public System { + public: + UIRenderSystem(Scene* scene); + ~UIRenderSystem(); - void OnComponentInsert(Entity entity) override; - void OnUpdate(float ts) override; + void OnComponentInsert(Entity entity) override; + void OnUpdate(float ts) override; - private: - - }; + private: +}; -} // namespace engine +} // namespace engine diff --git a/include/util.h b/include/util.h index 276fb97..9830f21 100644 --- a/include/util.h +++ b/include/util.h @@ -1,22 +1,20 @@ -#ifndef ENGINE_INCLUDE_UTIL_H_ -#define ENGINE_INCLUDE_UTIL_H_ +#pragma once #include namespace engine { -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 { - return true; - } +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 { + return true; + } } -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/include/util/files.h b/include/util/files.h index d6a49f7..6039f5a 100644 --- a/include/util/files.h +++ b/include/util/files.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_UTIL_FILES_H_ -#define ENGINE_INCLUDE_UTIL_FILES_H_ +#pragma once #include #include @@ -13,10 +12,7 @@ std::unique_ptr> 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> ReadImageFile(const std::string& path, - int& width, int& height); +std::unique_ptr> ReadImageFile(const std::string& path, int& width, int& height); -} // namespace util -} // namespace engine - -#endif \ No newline at end of file +} // namespace util +} // namespace engine \ No newline at end of file diff --git a/include/util/gltf_loader.h b/include/util/gltf_loader.h index 4a94e4f..578d8eb 100644 --- a/include/util/gltf_loader.h +++ b/include/util/gltf_loader.h @@ -10,11 +10,11 @@ namespace engine::util { * Loads the default scene found in a glTF file into 'scene'. * 'isStatic' will mark every transform as static to aid rendering optimisation. * Returns the top-level glTF node as an engine entity. - * + * * Loader limitations: * - Can only load .glb files * - glTF files must contain all textures */ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic = false); -} \ No newline at end of file +} // namespace engine::util \ No newline at end of file diff --git a/include/window.h b/include/window.h index f2ecc42..f47551f 100644 --- a/include/window.h +++ b/include/window.h @@ -1,5 +1,4 @@ -#ifndef ENGINE_INCLUDE_WINDOW_H_ -#define ENGINE_INCLUDE_WINDOW_H_ +#pragma once #include #include @@ -13,180 +12,177 @@ namespace engine { class Window { - public: - Window(const std::string& title, bool resizable = true, - bool fullscreen = true); - Window(const Window&) = delete; - Window& operator=(const Window&) = delete; - ~Window(); + public: + Window(const std::string& title, bool resizable = true, bool fullscreen = true); + Window(const Window&) = delete; + Window& operator=(const Window&) = delete; + ~Window(); - SDL_Window* GetHandle() const; + SDL_Window* GetHandle() const; - // Return the title name - std::string GetTitle() const; + // Return the title name + std::string GetTitle() const; - // Update the window state to capture any events that have occurred. - // Run this on every frame. - void GetInputAndEvents(); + // Update the window state to capture any events that have occurred. + // Run this on every frame. + void GetInputAndEvents(); - void SetTitle(std::string title); + void SetTitle(std::string title); - // Hides the window (it will appear closed to the user). - void Hide(); - // Shows the window again. - void Show(); - // Raises the window above other windows and sets the input focus - void Focus(); - // Returns true if the window has focus - bool HasFocus() const; + // Hides the window (it will appear closed to the user). + void Hide(); + // Shows the window again. + void Show(); + // Raises the window above other windows and sets the input focus + void Focus(); + // Returns true if the window has focus + bool HasFocus() const; - // Sets the close flag, check this with shouldClose() - void SetCloseFlag(); - // Returns true if the window should remain open - bool IsRunning() const; + // Sets the close flag, check this with shouldClose() + void SetCloseFlag(); + // Returns true if the window should remain open + bool IsRunning() const; - void SetFullscreen(bool fullscreen, bool exclusive = false); - void ToggleFullscreen(); + void SetFullscreen(bool fullscreen, bool exclusive = false); + void ToggleFullscreen(); - bool IsFullscreen() const; + bool IsFullscreen() const; - // Relative mouse mode captures the cursor for FPS style use. - // Returns false if unsupported. - bool SetRelativeMouseMode(bool enabled); + // Relative mouse mode captures the cursor for FPS style use. + // Returns false if unsupported. + bool SetRelativeMouseMode(bool enabled); - // returns true if relative mouse mode is enabled - bool MouseCaptured(); + // returns true if relative mouse mode is enabled + bool MouseCaptured(); - // window events + // window events - // Returns true if the window was just resized during the previous frame - bool GetWindowResized() const; - // Set the window resized flag (to recalculate aspect ratios and such) - void SetResizedFlag(); + // Returns true if the window was just resized during the previous frame + bool GetWindowResized() const; + // Set the window resized flag (to recalculate aspect ratios and such) + void SetResizedFlag(); - // keyboard events + // keyboard events - // returns true if key is down - bool GetKey(inputs::Key key) const; - // returns true if key was just pressed - bool GetKeyPress(inputs::Key key) const; - // returns true if key was just released - bool GetKeyRelease(inputs::Key key) const; + // returns true if key is down + bool GetKey(inputs::Key key) const; + // returns true if key was just pressed + bool GetKeyPress(inputs::Key key) const; + // returns true if key was just released + bool GetKeyRelease(inputs::Key key) const; - // mouse events + // mouse events - // returns true if button is down - bool GetButton(inputs::MouseButton button) const; - // returns true if button was just pressed - bool GetButtonPress(inputs::MouseButton button) const; - // returns true if button was just released - bool GetButtonRelease(inputs::MouseButton button) const; + // returns true if button is down + bool GetButton(inputs::MouseButton button) const; + // returns true if button was just pressed + bool GetButtonPress(inputs::MouseButton button) const; + // returns true if button was just released + bool GetButtonRelease(inputs::MouseButton button) const; - // retrieves x coordinate of the mouse - int GetMouseX() const; - // retrieves y coordinate of the mouse - int GetMouseY() const; - // retrieves mouse x coordinate normalised for OpenGL - float GetMouseNormX() const; - // retrieves mouse y coordinate normalised for OpenGL - float GetMouseNormY() const; - // retrieves dx of the mouse since the last frame - int GetMouseDX() const; - // retrieves dy of the mouse since the last frame - int GetMouseDY() const; - // retrieves amount scrolled vertically - float GetMouseScrollX() const; - // retrieves amount scrolled horizontally - float GetMouseScrollY() const; + // retrieves x coordinate of the mouse + int GetMouseX() const; + // retrieves y coordinate of the mouse + int GetMouseY() const; + // retrieves mouse x coordinate normalised for OpenGL + float GetMouseNormX() const; + // retrieves mouse y coordinate normalised for OpenGL + float GetMouseNormY() const; + // retrieves dx of the mouse since the last frame + int GetMouseDX() const; + // retrieves dy of the mouse since the last frame + int GetMouseDY() const; + // retrieves amount scrolled vertically + float GetMouseScrollX() const; + // retrieves amount scrolled horizontally + float GetMouseScrollY() const; - // joystick/gamepad events (maybe), other misc events + // joystick/gamepad events (maybe), other misc events - // returns the performance counter value in nanoseconds; - uint64_t GetNanos() const; - // get the time recorded at the end of the last frame - uint64_t GetLastFrameStamp() const; + // returns the performance counter value in nanoseconds; + uint64_t GetNanos() const; + // get the time recorded at the end of the last frame + uint64_t GetLastFrameStamp() const; - // returns the number of frames elapsed since window creation - uint64_t GetFrameCount() const; - uint64_t GetStartTime() const; - float dt() const; // returns delta time in seconds - uint64_t GetFPS() const; - uint64_t GetAvgFPS() const; + // returns the number of frames elapsed since window creation + uint64_t GetFrameCount() const; + uint64_t GetStartTime() const; + float dt() const; // returns delta time in seconds + uint64_t GetFPS() const; + uint64_t GetAvgFPS() const; - void ResetAvgFPS(); + void ResetAvgFPS(); - bool InfoBox(const std::string& title, const std::string& msg); + bool InfoBox(const std::string& title, const std::string& msg); - /* STATIC METHODS */ - static void ErrorBox(const std::string& message); + /* STATIC METHODS */ + static void ErrorBox(const std::string& message); - private: - SDL_Window* handle_; + private: + SDL_Window* handle_; - bool should_close_ = false; + bool should_close_ = false; - std::string title_; + std::string title_; - bool resizable_; + bool resizable_; - bool fullscreen_ = false; - bool just_resized_ = false; - bool keyboard_focus_ = true; + bool fullscreen_ = false; + bool just_resized_ = false; + bool keyboard_focus_ = true; - // size in screen coordinates - glm::ivec2 win_size_ = glm::vec2(1024, 768); + // size in screen coordinates + glm::ivec2 win_size_ = glm::vec2(1024, 768); - // performance counter frequency - uint64_t counter_freq_; + // performance counter frequency + uint64_t counter_freq_; - // number of frames swapped - uint64_t frames_ = 0; - // frame count offset for fpsAvg - uint64_t avg_fps_start_count_ = 0; - // in nanoseconds - uint64_t start_time_; - // in nanoseconds - uint64_t last_frame_stamp_; - // in nanoseconds; elapsed time between frames - uint64_t last_frame_time_ = 1; // not 0 to avoid division by zero - // in nanoseconds - uint64_t avg_fps_start_; + // number of frames swapped + uint64_t frames_ = 0; + // frame count offset for fpsAvg + uint64_t avg_fps_start_count_ = 0; + // in nanoseconds + uint64_t start_time_; + // in nanoseconds + uint64_t last_frame_stamp_; + // in nanoseconds; elapsed time between frames + uint64_t last_frame_time_ = 1; // not 0 to avoid division by zero + // in nanoseconds + uint64_t avg_fps_start_; - // input stuff + // input stuff - enum class ButtonDelta { kSame = 0, kPressed, kReleased }; + enum class ButtonDelta { kSame = 0, kPressed, kReleased }; - struct { - std::array keys; - std::array deltas; - } keyboard_{}; + struct { + std::array keys; + std::array deltas; + } keyboard_{}; - struct { - std::array(inputs::MouseButton::M_SIZE)> buttons; - std::array deltas; - Sint32 x; - Sint32 y; - Sint32 dx; - Sint32 dy; - float xscroll; - float yscroll; - bool captured = false; - } mouse_{}; + struct { + std::array(inputs::MouseButton::M_SIZE)> buttons; + std::array deltas; + Sint32 x; + Sint32 y; + Sint32 dx; + Sint32 dy; + float xscroll; + float yscroll; + bool captured = false; + } mouse_{}; - // private methods + // private methods - void OnResize(Sint32 width, Sint32 height); - void ResetInputDeltas(); + void OnResize(Sint32 width, Sint32 height); + void ResetInputDeltas(); - // event methods (like callbacks) + // event methods (like callbacks) - void OnWindowEvent(SDL_WindowEvent& e); - void OnKeyEvent(SDL_KeyboardEvent& e); - void OnMouseButtonEvent(SDL_MouseButtonEvent& e); - void OnMouseMotionEvent(SDL_MouseMotionEvent& e); - void OnMouseWheelEvent(SDL_MouseWheelEvent& e); + void OnWindowEvent(SDL_WindowEvent& e); + void OnKeyEvent(SDL_KeyboardEvent& e); + void OnMouseButtonEvent(SDL_MouseButtonEvent& e); + void OnMouseMotionEvent(SDL_MouseMotionEvent& e); + void OnMouseWheelEvent(SDL_MouseWheelEvent& e); }; -} // namespace engine - -#endif \ No newline at end of file +} // namespace engine \ No newline at end of file diff --git a/res/engine/shaders/fancy.frag b/res/engine/shaders/fancy.frag index 5cc8122..54b5d7b 100644 --- a/res/engine/shaders/fancy.frag +++ b/res/engine/shaders/fancy.frag @@ -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)); diff --git a/res/engine/shaders/quad.frag b/res/engine/shaders/quad.frag deleted file mode 100644 index a635654..0000000 --- a/res/engine/shaders/quad.frag +++ /dev/null @@ -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); -} - diff --git a/res/engine/shaders/quad.vert b/res/engine/shaders/quad.vert deleted file mode 100644 index 36e5f72..0000000 --- a/res/engine/shaders/quad.vert +++ /dev/null @@ -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]; -} diff --git a/res/engine/shaders/showNormals.frag b/res/engine/shaders/showNormals.frag deleted file mode 100644 index fb9dfad..0000000 --- a/res/engine/shaders/showNormals.frag +++ /dev/null @@ -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); -} - diff --git a/res/engine/shaders/showNormals.vert b/res/engine/shaders/showNormals.vert deleted file mode 100644 index 47125e7..0000000 --- a/res/engine/shaders/showNormals.vert +++ /dev/null @@ -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; -} diff --git a/res/engine/shaders/showUVs.frag b/res/engine/shaders/showUVs.frag deleted file mode 100644 index 3d32e8f..0000000 --- a/res/engine/shaders/showUVs.frag +++ /dev/null @@ -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); -} - diff --git a/res/engine/shaders/showUVs.vert b/res/engine/shaders/showUVs.vert deleted file mode 100644 index f166abb..0000000 --- a/res/engine/shaders/showUVs.vert +++ /dev/null @@ -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; -} diff --git a/res/engine/shaders/standard.frag b/res/engine/shaders/standard.frag deleted file mode 100644 index bc8acd4..0000000 --- a/res/engine/shaders/standard.frag +++ /dev/null @@ -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)); -} - diff --git a/res/engine/shaders/standard.vert b/res/engine/shaders/standard.vert deleted file mode 100644 index d318cb3..0000000 --- a/res/engine/shaders/standard.vert +++ /dev/null @@ -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; -} diff --git a/src/vulkan/instance.cpp b/src/vulkan/instance.cpp index fd0222e..e5b802c 100644 --- a/src/vulkan/instance.cpp +++ b/src/vulkan/instance.cpp @@ -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); diff --git a/src/vulkan/swapchain.cpp b/src/vulkan/swapchain.cpp index 06ff960..1c367b8 100644 --- a/src/vulkan/swapchain.cpp +++ b/src/vulkan/swapchain.cpp @@ -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; diff --git a/test/src/camera_controller.cpp b/test/src/camera_controller.cpp index e4b98ff..753c90d 100644 --- a/test/src/camera_controller.cpp +++ b/test/src/camera_controller.cpp @@ -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(); c->yaw = 0.0f; diff --git a/test/src/camera_controller.hpp b/test/src/camera_controller.hpp index 23b6a1e..ce78fe3 100644 --- a/test/src/camera_controller.hpp +++ b/test/src/camera_controller.hpp @@ -1,5 +1,4 @@ -#ifndef ENGINE_TEST_SRC_CAMERA_CONTROLLER_H_ -#define ENGINE_TEST_SRC_CAMERA_CONTROLLER_H_ +#pragma once #include @@ -20,13 +19,13 @@ struct CameraControllerComponent { static constexpr float kJumpHeight = /*4.4f*/ 8.8f; // collision - static constexpr float kPlayerHeight = 2.0f; // 71.0f * 25.4f / 1000.0f; + static constexpr float kPlayerHeight = 2.0f; // 71.0f * 25.4f / 1000.0f; static constexpr float kPlayerCollisionRadius = 0.2f; // this should be greater than z_near static constexpr float kMaxStairHeight = 0.2f; 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; @@ -49,6 +48,4 @@ class CameraControllerSystem : public engine::System { CameraControllerComponent* c = nullptr; engine::Scene* next_scene_ = nullptr; -}; - -#endif \ No newline at end of file +}; \ No newline at end of file diff --git a/test/src/game.cpp b/test/src/game.cpp index 3d8935e..adf9d43 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -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; diff --git a/test/src/game.hpp b/test/src/game.hpp index 0b5864d..cad49cb 100644 --- a/test/src/game.hpp +++ b/test/src/game.hpp @@ -1,11 +1,8 @@ -#ifndef ENGINE_TEST_SRC_GAME_H_ -#define ENGINE_TEST_SRC_GAME_H_ +#pragma once struct GameSettings { - bool enable_frame_limiter; - bool enable_validation; + bool enable_frame_limiter; + bool enable_validation; }; -void PlayGame(GameSettings settings); - -#endif \ No newline at end of file +void PlayGame(GameSettings settings); \ No newline at end of file diff --git a/test/src/meshgen.hpp b/test/src/meshgen.hpp index 4e53e4b..c9e32d1 100644 --- a/test/src/meshgen.hpp +++ b/test/src/meshgen.hpp @@ -1,16 +1,9 @@ -#ifndef ENGINE_TEST_SRC_MESHGEN_H_ -#define ENGINE_TEST_SRC_MESHGEN_H_ +#pragma once #include #include "resources/mesh.h" -std::unique_ptr GenSphereMesh( - engine::GFXDevice* gfx, float r, int detail, bool wind_inside = false, - bool flip_normals = false); +std::unique_ptr GenSphereMesh(engine::GFXDevice* gfx, float r, int detail, bool wind_inside = false, bool flip_normals = false); -std::unique_ptr GenCuboidMesh( - engine::GFXDevice* gfx, float x, float y, float z, float tiling = 1.0f, - bool wind_inside = false); - -#endif \ No newline at end of file +std::unique_ptr GenCuboidMesh(engine::GFXDevice* gfx, float x, float y, float z, float tiling = 1.0f, bool wind_inside = false); \ No newline at end of file