Fix varius minor issues

- Asset will now generate a uuid if it is not inside the meta file
- Device cleanup/idling improved
- FileSystem now prints which file failed to open
- Renderer header file now has the same parameter names as the source file
This commit is contained in:
Thraix
2025-08-10 20:18:41 +02:00
parent 4d2dfce31c
commit aca495960f
7 changed files with 35 additions and 18 deletions
+11 -2
View File
@@ -2,6 +2,8 @@
#include "copium/util/FileSystem.h"
#include <fstream>
namespace Copium
{
std::vector<std::string> AssetFile::assetTypes;
@@ -41,9 +43,16 @@ namespace Copium
return uuid;
}
void AssetFile::Load(const MetaFile& metaFile, const std::string& className)
void AssetFile::Load(MetaFile& metaFile, const std::string& className)
{
const MetaFileClass& metaClass = metaFile.GetMetaClass(className);
MetaFileClass& metaClass = metaFile.GetMetaClass(className);
if (!metaClass.HasValue("uuid"))
{
CP_WARN("Asset (%s) has no UUID assigned, generating new one", path.c_str());
metaClass.AddValue("uuid", Uuid{}.ToString());
std::fstream file{path};
file << metaFile;
}
uuid = Uuid{metaClass.GetValue("uuid")};
dateModified = FileSystem::DateModified(path);
}
+1 -1
View File
@@ -23,7 +23,7 @@ namespace Copium
const std::string& GetPath() const;
Uuid GetUuid() const;
private:
void Load(const MetaFile& metaFile, const std::string& className);
void Load(MetaFile& metaFile, const std::string& className);
static void RegisterAssetType(const std::string& assetType);
};
}
+12 -6
View File
@@ -12,6 +12,7 @@ namespace Copium
InitializeLogicalDevice();
InitializeCommandPool();
}
Device::~Device()
{
vkDestroyCommandPool(device, commandPool, nullptr);
@@ -34,7 +35,7 @@ namespace Copium
return graphicsQueue;
}
VkQueue Device::GetPresentQueue() const
VkQueue Device::GetPresentQueue() const
{
return presentQueue;
}
@@ -69,11 +70,7 @@ namespace Copium
void Device::WaitIdle()
{
vkDeviceWaitIdle(device);
while (!idleCommands.empty())
{
idleCommands.front()();
idleCommands.pop();
}
CleanupIdleQueue();
}
void Device::WaitIdleIfCommandQueued()
@@ -84,6 +81,15 @@ namespace Copium
}
}
void Device::CleanupIdleQueue()
{
while (!idleCommands.empty())
{
idleCommands.front()();
idleCommands.pop();
}
}
void Device::QueueIdleCommand(std::function<void()> idleCommand)
{
idleCommands.emplace(idleCommand);
+1 -1
View File
@@ -26,6 +26,7 @@ namespace Copium
uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
void WaitIdle();
void WaitIdleIfCommandQueued();
void CleanupIdleQueue();
void QueueIdleCommand(std::function<void()> idleCommand);
private:
@@ -41,7 +42,6 @@ namespace Copium
std::queue<std::function<void()>> idleCommands;
// TODO end
private:
void SelectPhysicalDevice();
void InitializeLogicalDevice();
+2 -1
View File
@@ -55,8 +55,9 @@ namespace Copium
AssetManager::UnregisterAssetDir("assets/");
AssetManager::Cleanup();
imGuiInstance.reset();
swapChain.reset();
device->WaitIdle();
swapChain.reset();
device->CleanupIdleQueue();
device.reset();
window.reset();
instance.reset();
+3 -2
View File
@@ -28,11 +28,12 @@ namespace Copium
int quadCount;
int textureCount;
void* mappedVertexBuffer;
std::map<int, std::unique_ptr<DescriptorSet>> descriptorSets;
public:
Renderer(const AssetRef<Pipeline>& pipeline);
void Quad(const glm::vec2& from, const glm::vec2& to, const glm::vec3& color = glm::vec3{1, 1, 1});
void Quad(const glm::vec2& from, const glm::vec2& to, const Sampler& sampler, const glm::vec2& texCoord1 = glm::vec2{0, 0}, const glm::vec2& texCoord2 = glm::vec2{1, 1});
void Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color = glm::vec3{1, 1, 1});
void Quad(const glm::vec2& pos, const glm::vec2& size, const Sampler& sampler, const glm::vec2& texCoord1 = glm::vec2{0, 0}, const glm::vec2& texCoord2 = glm::vec2{1, 1});
// Returns the position where the text rendering ended
glm::vec2 Text(const std::string& str, const glm::vec2& position, const Font& font, float size, const glm::vec3& color = glm::vec3(1, 1, 1));
+5 -5
View File
@@ -10,7 +10,7 @@ namespace Copium
std::vector<char> FileSystem::ReadFile(const std::string& filename)
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
CP_ASSERT(file.is_open(), "Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str());
size_t fileSize = (size_t)file.tellg();
std::vector<char> buffer(fileSize);
@@ -24,7 +24,7 @@ namespace Copium
std::vector<uint32_t> FileSystem::ReadFile32(const std::string& filename)
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
CP_ASSERT(file.is_open(), "Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str());
size_t fileSize = (size_t)file.tellg();
CP_ASSERT(fileSize % 4 == 0, "byte size is not divisible by 4");
@@ -39,7 +39,7 @@ namespace Copium
std::string FileSystem::ReadFileStr(const std::string& filename)
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
CP_ASSERT(file.is_open(), "Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str());
size_t fileSize = (size_t)file.tellg();
std::string buffer;
@@ -56,7 +56,7 @@ namespace Copium
std::filesystem::path path{filename};
std::filesystem::create_directories(path.parent_path());
std::ofstream file(filename, std::ios::binary);
CP_ASSERT(file.is_open(), "Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str());
file.write(data.c_str(), data.size());
}
@@ -66,7 +66,7 @@ namespace Copium
std::filesystem::path path{filename};
std::filesystem::create_directories(path.parent_path());
std::ofstream file(filename, std::ios::binary);
CP_ASSERT(file.is_open(), "Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str());
file.write(data, size);
}