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:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "copium/util/FileSystem.h"
|
#include "copium/util/FileSystem.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
std::vector<std::string> AssetFile::assetTypes;
|
std::vector<std::string> AssetFile::assetTypes;
|
||||||
@@ -41,9 +43,16 @@ namespace Copium
|
|||||||
return uuid;
|
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")};
|
uuid = Uuid{metaClass.GetValue("uuid")};
|
||||||
dateModified = FileSystem::DateModified(path);
|
dateModified = FileSystem::DateModified(path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Copium
|
|||||||
const std::string& GetPath() const;
|
const std::string& GetPath() const;
|
||||||
Uuid GetUuid() const;
|
Uuid GetUuid() const;
|
||||||
private:
|
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);
|
static void RegisterAssetType(const std::string& assetType);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace Copium
|
|||||||
InitializeLogicalDevice();
|
InitializeLogicalDevice();
|
||||||
InitializeCommandPool();
|
InitializeCommandPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device()
|
Device::~Device()
|
||||||
{
|
{
|
||||||
vkDestroyCommandPool(device, commandPool, nullptr);
|
vkDestroyCommandPool(device, commandPool, nullptr);
|
||||||
@@ -69,11 +70,7 @@ namespace Copium
|
|||||||
void Device::WaitIdle()
|
void Device::WaitIdle()
|
||||||
{
|
{
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
while (!idleCommands.empty())
|
CleanupIdleQueue();
|
||||||
{
|
|
||||||
idleCommands.front()();
|
|
||||||
idleCommands.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::WaitIdleIfCommandQueued()
|
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)
|
void Device::QueueIdleCommand(std::function<void()> idleCommand)
|
||||||
{
|
{
|
||||||
idleCommands.emplace(idleCommand);
|
idleCommands.emplace(idleCommand);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace Copium
|
|||||||
uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
||||||
void WaitIdle();
|
void WaitIdle();
|
||||||
void WaitIdleIfCommandQueued();
|
void WaitIdleIfCommandQueued();
|
||||||
|
void CleanupIdleQueue();
|
||||||
void QueueIdleCommand(std::function<void()> idleCommand);
|
void QueueIdleCommand(std::function<void()> idleCommand);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -41,7 +42,6 @@ namespace Copium
|
|||||||
std::queue<std::function<void()>> idleCommands;
|
std::queue<std::function<void()>> idleCommands;
|
||||||
// TODO end
|
// TODO end
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SelectPhysicalDevice();
|
void SelectPhysicalDevice();
|
||||||
void InitializeLogicalDevice();
|
void InitializeLogicalDevice();
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ namespace Copium
|
|||||||
AssetManager::UnregisterAssetDir("assets/");
|
AssetManager::UnregisterAssetDir("assets/");
|
||||||
AssetManager::Cleanup();
|
AssetManager::Cleanup();
|
||||||
imGuiInstance.reset();
|
imGuiInstance.reset();
|
||||||
swapChain.reset();
|
|
||||||
device->WaitIdle();
|
device->WaitIdle();
|
||||||
|
swapChain.reset();
|
||||||
|
device->CleanupIdleQueue();
|
||||||
device.reset();
|
device.reset();
|
||||||
window.reset();
|
window.reset();
|
||||||
instance.reset();
|
instance.reset();
|
||||||
|
|||||||
@@ -28,11 +28,12 @@ namespace Copium
|
|||||||
int quadCount;
|
int quadCount;
|
||||||
int textureCount;
|
int textureCount;
|
||||||
void* mappedVertexBuffer;
|
void* mappedVertexBuffer;
|
||||||
|
std::map<int, std::unique_ptr<DescriptorSet>> descriptorSets;
|
||||||
public:
|
public:
|
||||||
Renderer(const AssetRef<Pipeline>& pipeline);
|
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& pos, const glm::vec2& size, 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 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
|
// 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));
|
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));
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Copium
|
|||||||
std::vector<char> FileSystem::ReadFile(const std::string& filename)
|
std::vector<char> FileSystem::ReadFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::ifstream file(filename, std::ios::ate | std::ios::binary);
|
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();
|
size_t fileSize = (size_t)file.tellg();
|
||||||
std::vector<char> buffer(fileSize);
|
std::vector<char> buffer(fileSize);
|
||||||
@@ -24,7 +24,7 @@ namespace Copium
|
|||||||
std::vector<uint32_t> FileSystem::ReadFile32(const std::string& filename)
|
std::vector<uint32_t> FileSystem::ReadFile32(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::ifstream file(filename, std::ios::ate | std::ios::binary);
|
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();
|
size_t fileSize = (size_t)file.tellg();
|
||||||
CP_ASSERT(fileSize % 4 == 0, "byte size is not divisible by 4");
|
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::string FileSystem::ReadFileStr(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::ifstream file(filename, std::ios::ate | std::ios::binary);
|
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();
|
size_t fileSize = (size_t)file.tellg();
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
@@ -56,7 +56,7 @@ namespace Copium
|
|||||||
std::filesystem::path path{filename};
|
std::filesystem::path path{filename};
|
||||||
std::filesystem::create_directories(path.parent_path());
|
std::filesystem::create_directories(path.parent_path());
|
||||||
std::ofstream file(filename, std::ios::binary);
|
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());
|
file.write(data.c_str(), data.size());
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ namespace Copium
|
|||||||
std::filesystem::path path{filename};
|
std::filesystem::path path{filename};
|
||||||
std::filesystem::create_directories(path.parent_path());
|
std::filesystem::create_directories(path.parent_path());
|
||||||
std::ofstream file(filename, std::ios::binary);
|
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);
|
file.write(data, size);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user