Refactor tracing

This commit is contained in:
Thraix
2023-04-13 22:03:06 +02:00
parent d9e7fd7019
commit 0246e89039
31 changed files with 132 additions and 130 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ namespace Copium
Load(metaFile, str, type);
return;
}
CP_ABORT("Load : Unknown Asset type");
CP_ABORT("Unknown Asset type");
}
const std::string& AssetFile::GetPath() const
+11 -11
View File
@@ -51,13 +51,13 @@ namespace Copium
Asset& AssetManager::GetAsset(AssetHandle handle)
{
auto it = assets.find(handle);
CP_ASSERT(it != assets.end(), "GetAsset : Asset not loaded");
CP_ASSERT(it != assets.end(), "Asset not loaded");
return *it->second.get();
}
Asset& AssetManager::LoadAsset(const std::string& assetPath)
{
CP_DEBUG("LoadAsset : Loading Asset: %s", assetPath.c_str());
CP_DEBUG("Loading Asset: %s", assetPath.c_str());
for (auto& dir : assetDirs)
{
@@ -75,15 +75,15 @@ namespace Copium
{
return CreateAsset<Texture2D>(metaFile, "Texture2D");
}
CP_ABORT("LoadAsset : Unknown Asset type: %s/%s", dir.c_str(), assetPath.c_str());
CP_ABORT("Unknown Asset type: %s/%s", dir.c_str(), assetPath.c_str());
}
CP_ABORT("LoadAsset : Unknown Asset: %s", assetPath.c_str());
CP_ABORT("Unknown Asset: %s", assetPath.c_str());
}
Asset& AssetManager::LoadAsset(const UUID& uuid)
{
CP_DEBUG("LoadAsset : Loading uuid Asset: %s", uuid.ToString().c_str());
CP_DEBUG("Loading uuid Asset: %s", uuid.ToString().c_str());
for (auto&& assetFile : cachedAssetFiles)
{
if (assetFile.GetUUID() != uuid)
@@ -95,7 +95,7 @@ namespace Copium
if (assetFile.GetUUID() != uuid)
continue;
CP_DEBUG("LoadAsset : Loading Asset: %s", assetFile.GetPath().c_str());
CP_DEBUG("Loading Asset: %s", assetFile.GetPath().c_str());
auto it = pathToAssetCache.find(assetFile.GetPath());
if (it != pathToAssetCache.end())
return *assets.find(it->second)->second.get();
@@ -105,16 +105,16 @@ namespace Copium
{
return CreateAsset<Texture2D>(metaFile, "Texture2D");
}
CP_ABORT("LoadAsset : Unknown Asset type: %s", assetFile.GetPath().c_str());
CP_ABORT("Unknown Asset type: %s", assetFile.GetPath().c_str());
}
CP_ABORT("LoadAsset : Asset not found with uuid=%s", uuid.ToString().c_str());
CP_ABORT("Asset not found with uuid=%s", uuid.ToString().c_str());
// TODO: Reload the assetCache to see if a new file has appeared with that uuid
}
void AssetManager::UnloadAsset(AssetHandle handle)
{
auto it = assets.find(handle);
CP_ASSERT(it != assets.end(), "UnloadAsset : Asset not loaded");
CP_ASSERT(it != assets.end(), "Asset not loaded");
if (it->second->isRuntime())
nameToAssetCache.erase(it->second->GetName());
@@ -127,7 +127,7 @@ namespace Copium
{
if (assets.empty())
return;
CP_WARN("Cleanup : Cleaning up %d loaded assets", assets.size());
CP_WARN("Cleaning up %d loaded assets", assets.size());
assets.clear();
nameToAssetCache.clear();
pathToAssetCache.clear();
@@ -136,7 +136,7 @@ namespace Copium
Asset& AssetManager::RegisterRuntimeAsset(const std::string& name, std::unique_ptr<Asset>&& asset)
{
auto it = nameToAssetCache.find(name);
CP_ASSERT(it == nameToAssetCache.end(), "RegistedRuntimeAsset : Asset already exists: %s", name);
CP_ASSERT(it == nameToAssetCache.end(), "Asset already exists: %s", name);
AssetHandle handle = runtimeAssetHandle++;
Asset* asset2 = assets.emplace(handle, std::move(asset)).first->second.get();
+3 -3
View File
@@ -36,7 +36,7 @@ namespace Copium
static AssetT& LoadAsset(const std::string& assetPath)
{
AssetT* asset = dynamic_cast<AssetT*>(&LoadAsset(assetPath));
CP_ASSERT(asset, "LoadAsset : Invalid Asset cast");
CP_ASSERT(asset, "Invalid Asset cast");
return *asset;
}
@@ -44,7 +44,7 @@ namespace Copium
static AssetT& LoadAsset(const UUID& uuid)
{
AssetT* asset = dynamic_cast<AssetT*>(&LoadAsset(uuid));
CP_ASSERT(asset, "LoadAsset : Invalid Asset cast");
CP_ASSERT(asset, "Invalid Asset cast");
return *asset;
}
@@ -53,7 +53,7 @@ namespace Copium
{
Asset& asset = GetAsset(handle);
AssetT* assetT = dynamic_cast<AssetT*>(&asset);
CP_ASSERT(assetT, "GetAsset : Invalid Asset cast");
CP_ASSERT(assetT, "Invalid Asset cast");
return *assetT;
}
+7 -7
View File
@@ -13,7 +13,7 @@ namespace Copium
createInfo.usage = usage;
createInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
CP_VK_ASSERT(vkCreateBuffer(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Buffer : Failed to initialize buffer");
CP_VK_ASSERT(vkCreateBuffer(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Failed to initialize buffer");
VkMemoryRequirements memoryRequirements;
vkGetBufferMemoryRequirements(Vulkan::GetDevice(), handle, &memoryRequirements);
@@ -23,7 +23,7 @@ namespace Copium
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = Vulkan::GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties);
CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, &memory), "Buffer : Failed to allocate buffer memory");
CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, &memory), "Failed to allocate buffer memory");
vkBindBufferMemory(Vulkan::GetDevice(), handle, memory, 0);
}
@@ -36,7 +36,7 @@ namespace Copium
void Buffer::Update(void* indexData, int index)
{
CP_ASSERT(index >= 0 && index < count, "Update : Index is outside of the buffer");
CP_ASSERT(index >= 0 && index < count, "Index is outside of the buffer");
if (mappedData == nullptr)
{
@@ -72,14 +72,14 @@ namespace Copium
void* Buffer::Map()
{
CP_ASSERT(mappedData == nullptr, "Map : Mapping an already mapped buffer");
CP_ASSERT(mappedData == nullptr, "Mapping an already mapped buffer");
vkMapMemory(Vulkan::GetDevice(), memory, 0, size * count, 0, &mappedData);
return mappedData;
}
void Buffer::Unmap()
{
CP_ASSERT(mappedData != nullptr, "Unmap : Unmapping an already unmapped buffer");
CP_ASSERT(mappedData != nullptr, "Unmapping an already unmapped buffer");
vkUnmapMemory(Vulkan::GetDevice(), memory);
mappedData = nullptr;
@@ -97,7 +97,7 @@ namespace Copium
VkDeviceSize Buffer::GetPosition(int index) const
{
CP_ASSERT(index >= 0 && index < count, "GetPosition : Index is outside of the buffer");
CP_ASSERT(index >= 0 && index < count, "Index is outside of the buffer");
return size * (VkDeviceSize)index;
}
@@ -111,7 +111,7 @@ namespace Copium
allocateInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer;
CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, &commandBuffer), "CopyBuffer : Failed to initialize command buffer");
CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, &commandBuffer), "Failed to initialize command buffer");
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -16,7 +16,7 @@ namespace Copium
commandBuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
break;
default:
CP_ABORT("CommandBuffer : Unreachable switch case");
CP_ABORT("Unreachable switch case");
}
VkCommandBufferAllocateInfo allocateInfo{};
@@ -24,7 +24,7 @@ namespace Copium
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool();
allocateInfo.commandBufferCount = commandBuffers.size();
CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, commandBuffers.data()), "CommandBuffer : Failed to allocate CommandBuffer");
CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, commandBuffers.data()), "Failed to allocate CommandBuffer");
}
CommandBuffer::~CommandBuffer()
@@ -48,11 +48,11 @@ namespace Copium
case Type::Dynamic:
break;
default:
CP_ABORT("Begin : Unreachable switch case");
CP_ABORT("Unreachable switch case");
}
vkResetCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], 0);
CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], &beginInfo), "Begin : Failed to begin command buffer");
CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], &beginInfo), "Failed to begin command buffer");
}
void CommandBuffer::End()
@@ -168,7 +168,7 @@ namespace Copium
renderPassCreateInfo.dependencyCount = dependencies.size();
renderPassCreateInfo.pDependencies = dependencies.data();
CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "Failed to initialze render pass");
}
void Framebuffer::InitializeFramebuffers()
@@ -187,7 +187,7 @@ namespace Copium
createInfo.height = height;
createInfo.layers = 1;
CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize framebuffer");
CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "Failed to initialize framebuffer");
}
}
}
@@ -21,7 +21,7 @@ namespace Copium
void IndexBuffer::Draw(const CommandBuffer& commandBuffer, int indices)
{
CP_ASSERT(indices > 0 && indices <= indexCount, "Draw : amount of indices is out of range");
CP_ASSERT(indices > 0 && indices <= indexCount, "amount of indices is out of range");
vkCmdDrawIndexed(commandBuffer, indices, 1, 0, 0, 0);
}
}
@@ -21,49 +21,49 @@ namespace Copium
void UniformBuffer::Set(const std::string& str, const glm::mat3& data)
{
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat3, "Set : Uniform type missmatch = %s", str.c_str());
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat3, "Uniform type missmatch = %s", str.c_str());
uint32_t offset = binding.GetUniformOffset(str);
memcpy(buffer.data() + offset, &data, sizeof(glm::mat3));
}
void UniformBuffer::Set(const std::string& str, const glm::mat4& data)
{
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat4, "Set : Uniform type missmatch = %s", str.c_str());
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat4, "Uniform type missmatch = %s", str.c_str());
uint32_t offset = binding.GetUniformOffset(str);
memcpy(buffer.data() + offset, &data, sizeof(glm::mat4));
}
void UniformBuffer::Set(const std::string& str, const glm::vec2& data)
{
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec2, "Set : Uniform type missmatch = %s", str.c_str());
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec2, "Uniform type missmatch = %s", str.c_str());
uint32_t offset = binding.GetUniformOffset(str);
memcpy(buffer.data() + offset, &data, sizeof(glm::vec2));
}
void UniformBuffer::Set(const std::string& str, const glm::vec3& data)
{
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec3, "Set : Uniform type missmatch = %s", str.c_str());
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec3, "Uniform type missmatch = %s", str.c_str());
uint32_t offset = binding.GetUniformOffset(str);
memcpy(buffer.data() + offset, &data, sizeof(glm::vec3));
}
void UniformBuffer::Set(const std::string& str, const glm::vec4& data)
{
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec4, "Set : Uniform type missmatch = %s", str.c_str());
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec4, "Uniform type missmatch = %s", str.c_str());
uint32_t offset = binding.GetUniformOffset(str);
memcpy(buffer.data() + offset, &data, sizeof(glm::vec4));
}
void UniformBuffer::Set(const std::string& str, float data)
{
CP_ASSERT(binding.GetUniformType(str) == UniformType::Float, "Set : Uniform type missmatch = %s", str.c_str());
CP_ASSERT(binding.GetUniformType(str) == UniformType::Float, "Uniform type missmatch = %s", str.c_str());
uint32_t offset = binding.GetUniformOffset(str);
memcpy(buffer.data() + offset, &data, sizeof(float));
}
void UniformBuffer::Set(const std::string& str, int data)
{
CP_ASSERT(binding.GetUniformType(str) == UniformType::Int, "Set : Uniform type missmatch = %s", str.c_str());
CP_ASSERT(binding.GetUniformType(str) == UniformType::Int, "Uniform type missmatch = %s", str.c_str());
uint32_t offset = binding.GetUniformOffset(str);
memcpy(buffer.data() + offset, &data, sizeof(int));
}
@@ -18,7 +18,7 @@ namespace Copium
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
createInfo.pfnUserCallback = DebugCallback;
createInfo.pUserData = nullptr;
CP_VK_ASSERT(vkCreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger), "DebugMessenger : Failed to initialze debug messenger");
CP_VK_ASSERT(vkCreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger), "Failed to initialze debug messenger");
}
DebugMessenger::~DebugMessenger()
@@ -58,9 +58,9 @@ namespace Copium
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
{
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
CP_ABORT("DebugCallback : %s", pCallbackData->pMessage);
CP_ABORT("%s", pCallbackData->pMessage);
else
CP_WARN("DebugCallback : %s", pCallbackData->pMessage);
CP_WARN("%s", pCallbackData->pMessage);
}
return VK_FALSE;
}
+7 -7
View File
@@ -52,18 +52,18 @@ namespace Copium
if ((typeFilter & (1 << i)) && (memoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
return i;
}
CP_ABORT("FindMemoryType : Failed to find suitable memory type");
CP_ABORT("Failed to find suitable memory type");
}
void Device::SelectPhysicalDevice()
{
uint32_t deviceCount;
vkEnumeratePhysicalDevices(Vulkan::GetInstance(), &deviceCount, nullptr);
CP_ASSERT(deviceCount != 0, "SelectPhysicaDevice : No available devices support Vulkan");
CP_ASSERT(deviceCount != 0, "No available devices support Vulkan");
std::vector<VkPhysicalDevice> devices(deviceCount);
vkEnumeratePhysicalDevices(Vulkan::GetInstance(), &deviceCount, devices.data());
CP_INFO("SelectPhysicaDevice : Available devices:");
CP_INFO("Available devices:");
for (auto&& device : devices)
{
VkPhysicalDeviceProperties deviceProperties;
@@ -77,11 +77,11 @@ namespace Copium
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(device, &deviceProperties);
physicalDevice = device;
CP_INFO("SelectPhysicaDevice : Selecting device: %s", deviceProperties.deviceName);
CP_INFO("Selecting device: %s", deviceProperties.deviceName);
break;
}
}
CP_ASSERT(physicalDevice != VK_NULL_HANDLE, "SelectPhysicaDevice : Failed to find suitable GPU");
CP_ASSERT(physicalDevice != VK_NULL_HANDLE, "Failed to find suitable GPU");
}
void Device::InitializeLogicalDevice()
@@ -113,7 +113,7 @@ namespace Copium
createInfo.ppEnabledExtensionNames = deviceExtensions.data();
createInfo.enabledExtensionCount = deviceExtensions.size();
CP_VK_ASSERT(vkCreateDevice(physicalDevice, &createInfo, nullptr, &device), "InitializeLogicalDevice : Failed to initialize logical device");
CP_VK_ASSERT(vkCreateDevice(physicalDevice, &createInfo, nullptr, &device), "Failed to initialize logical device");
graphicsQueueIndex = query.graphicsFamily.value();
presentQueueIndex = query.presentFamily.value();
@@ -127,7 +127,7 @@ namespace Copium
createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
createInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
createInfo.queueFamilyIndex = graphicsQueueIndex;
CP_VK_ASSERT(vkCreateCommandPool(device, &createInfo, nullptr, &commandPool), "InitializeCommandPool : Failed to initialize command pool");
CP_VK_ASSERT(vkCreateCommandPool(device, &createInfo, nullptr, &commandPool), "Failed to initialize command pool");
}
bool Device::IsPhysicalDeviceSuitable(VkPhysicalDevice device)
+5 -5
View File
@@ -10,7 +10,7 @@ namespace Copium
timer.Start();
InitializeInstance(applicationName);
InitializeDebugMessenger();
CP_INFO("Instance : Initialized Vulkan in %f seconds", timer.Elapsed());
CP_INFO("Initialized Vulkan in %f seconds", timer.Elapsed());
}
Instance::~Instance()
@@ -41,7 +41,7 @@ namespace Copium
std::vector<VkExtensionProperties> extensions{extensionCount};
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data());
CP_INFO("InitiaizeInstace : Supported Extensions:");
CP_INFO("Supported Extensions:");
for (auto&& extension : extensions)
{
CP_INFO_CONT("\t%s", extension.extensionName);
@@ -49,7 +49,7 @@ namespace Copium
std::vector<const char*> layers{};
DebugMessenger::AddRequiredLayers(&layers);
CP_ASSERT(CheckLayerSupport(layers), "InitializeInstance : Some required layers are not supported");
CP_ASSERT(CheckLayerSupport(layers), "Some required layers are not supported");
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
@@ -58,7 +58,7 @@ namespace Copium
createInfo.ppEnabledExtensionNames = requiredExtensions.data();
createInfo.enabledLayerCount = layers.size();
createInfo.ppEnabledLayerNames = layers.data();
CP_VK_ASSERT(vkCreateInstance(&createInfo, nullptr, &instance), "InitializeInstance : Failed to create instance");
CP_VK_ASSERT(vkCreateInstance(&createInfo, nullptr, &instance), "Failed to create instance");
}
void Instance::InitializeDebugMessenger()
@@ -87,7 +87,7 @@ namespace Copium
std::vector<VkLayerProperties> availableLayers(layerCount);
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
CP_INFO("CheckLayerSupport : Supported Layers:");
CP_INFO("Supported Layers:");
for (auto&& availableLayer : availableLayers)
{
CP_INFO_CONT("\t%s", availableLayer.layerName);
+7 -7
View File
@@ -137,7 +137,7 @@ namespace Copium
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = &renderFinishedSemaphores[flightIndex];
CP_VK_ASSERT(vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), "SubmitGraphicsQueue : Failed to submit command buffer");
CP_VK_ASSERT(vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), "Failed to submit command buffer");
}
void SwapChain::EndPresent()
@@ -236,7 +236,7 @@ namespace Copium
createInfo.pQueueFamilyIndices = nullptr;
}
CP_VK_ASSERT(vkCreateSwapchainKHR(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Initialize : Failed to initialize the swapchain");
CP_VK_ASSERT(vkCreateSwapchainKHR(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Failed to initialize the swapchain");
vkGetSwapchainImagesKHR(Vulkan::GetDevice(), handle, &imageCount, nullptr);
images.resize(imageCount);
@@ -311,7 +311,7 @@ namespace Copium
renderPassCreateInfo.dependencyCount = 1;
renderPassCreateInfo.pDependencies = &dependency;
CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "Failed to initialze render pass");
}
void SwapChain::InitializeFramebuffers()
@@ -331,7 +331,7 @@ namespace Copium
createInfo.height = extent.height;
createInfo.layers = 1;
CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize swap chain framebuffer");
CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "Failed to initialize swap chain framebuffer");
}
}
@@ -344,14 +344,14 @@ namespace Copium
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i)
{
CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]), "InitializeSyncObjects : Failed to initialize available image semaphore");
CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), "InitializeSyncObjects : Failed to initialize render finished semaphore");
CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]), "Failed to initialize available image semaphore");
CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), "Failed to initialize render finished semaphore");
VkFenceCreateInfo fenceCreateInfo{};
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
CP_VK_ASSERT(vkCreateFence(Vulkan::GetDevice(), &fenceCreateInfo, nullptr, &inFlightFences[i]), "InitializeSyncObjects : Failed to initialize in flight fence");
CP_VK_ASSERT(vkCreateFence(Vulkan::GetDevice(), &fenceCreateInfo, nullptr, &inFlightFences[i]), "Failed to initialize in flight fence");
}
}
+3 -3
View File
@@ -53,10 +53,10 @@ namespace Copium
break;
}
default:
CP_ABORT("Window : Unreachable switch case");
CP_ABORT("Unreachable switch case");
}
CP_ASSERT(window, "InitializeWindow : Failed to initialize glfw window");
CP_ASSERT(window, "Failed to initialize glfw window");
glfwSetWindowUserPointer(window, this);
glfwSetFramebufferSizeCallback(window, FramebufferResizeCallback);
@@ -64,7 +64,7 @@ namespace Copium
void Window::InitializeSurface()
{
CP_VK_ASSERT(glfwCreateWindowSurface(Vulkan::GetInstance(), window, nullptr, &surface), "InitializeSurface : Failed to create Vulkan surface");
CP_VK_ASSERT(glfwCreateWindowSurface(Vulkan::GetInstance(), window, nullptr, &surface), "Failed to create Vulkan surface");
}
void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height)
+2 -2
View File
@@ -7,7 +7,7 @@
int main(int argc, char** argv)
{
CP_ASSERT(glfwInit() == GLFW_TRUE, "main : Failed to initialize the glfw context");
CP_ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize the glfw context");
for (int i = 0; i < argc; i++)
{
CP_INFO(argv[i]);
@@ -23,7 +23,7 @@ int main(int argc, char** argv)
glfwPollEvents();
if (timer.Elapsed() >= 1.0)
{
CP_DEBUG("main : %d fps", frames);
CP_DEBUG("%d fps", frames);
frames = 0;
timer.Start();
}
@@ -20,7 +20,7 @@ namespace Copium
createInfo.maxSets = DESCRIPTOR_SET_COUNT * SwapChain::MAX_FRAMES_IN_FLIGHT;
createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "DescriptorPool : Failed to initialize descriptor pool");
CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "Failed to initialize descriptor pool");
}
DescriptorPool::~DescriptorPool()
@@ -38,7 +38,7 @@ namespace Copium
allocateInfo.descriptorSetCount = descriptorSets.size();
allocateInfo.pSetLayouts = layouts.data();
CP_VK_ASSERT(vkAllocateDescriptorSets(Vulkan::GetDevice(), &allocateInfo, descriptorSets.data()), "AllocateDescriptorSets : Failed to allocate descriptor sets");
CP_VK_ASSERT(vkAllocateDescriptorSets(Vulkan::GetDevice(), &allocateInfo, descriptorSets.data()), "Failed to allocate descriptor sets");
return descriptorSets;
}
@@ -7,7 +7,7 @@ namespace Copium
DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set<ShaderBinding>& bindings)
: descriptorPool{descriptorPool}, descriptorSetLayout{descriptorSetLayout}, bindings{bindings}
{
CP_ASSERT(!bindings.empty(), "DescriptorSet : cannot initialize DescriptorSet with empty ShaderBindings");
CP_ASSERT(!bindings.empty(), "Cannot initialize DescriptorSet with empty ShaderBindings");
descriptorSets = descriptorPool.AllocateDescriptorSets(descriptorSetLayout);
for (auto& binding : bindings)
@@ -86,7 +86,7 @@ namespace Copium
UniformBuffer& DescriptorSet::GetUniformBuffer(const std::string& uniformBuffer)
{
auto it = uniformBuffers.find(uniformBuffer);
CP_ASSERT(it != uniformBuffers.end(), "GetUniformBuffer : UniformBuffer not found = %s", uniformBuffer.c_str());
CP_ASSERT(it != uniformBuffers.end(), "UniformBuffer not found = %s", uniformBuffer.c_str());
return *it->second;
}
@@ -30,7 +30,7 @@ namespace Copium
void Pipeline::SetDescriptorSet(const DescriptorSet& descriptorSet)
{
CP_ASSERT(descriptorSet.GetSetIndex() < boundDescriptorSets.size(), "SetDescriptorSet : DescriptorSet index is out of bounds");
CP_ASSERT(descriptorSet.GetSetIndex() < boundDescriptorSets.size(), "DescriptorSet index is out of bounds");
boundDescriptorSets[descriptorSet.GetSetIndex()] = descriptorSet;
}
@@ -76,7 +76,7 @@ namespace Copium
createInfo.bindingCount = layoutBindings.size();
createInfo.pBindings = layoutBindings.data();
CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), "InitializeDescriptorSetLayout : Failed to initialize descriptor set layout");
CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), "Failed to initialize descriptor set layout");
}
}
@@ -192,7 +192,7 @@ namespace Copium
pipelineLayoutCreateInfo.pushConstantRangeCount = 0;
pipelineLayoutCreateInfo.pPushConstantRanges = nullptr;
CP_VK_ASSERT(vkCreatePipelineLayout(Vulkan::GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), "InitializePipeline : Failed to initialize pipeline layout");
CP_VK_ASSERT(vkCreatePipelineLayout(Vulkan::GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), "Failed to initialize pipeline layout");
const std::vector<VkPipelineShaderStageCreateInfo>& shaderStages = shader.GetShaderStages();
VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo{};
@@ -213,6 +213,6 @@ namespace Copium
graphicsPipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE;
graphicsPipelineCreateInfo.basePipelineIndex = -1;
CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "InitializePipeline : Failed to initialize graphics pipeline");
CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "Failed to initialize graphics pipeline");
}
}
@@ -55,7 +55,7 @@ namespace Copium
case BindingType::UniformBuffer:
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
default:
CP_ABORT("GetDescriptorType : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
@@ -68,7 +68,7 @@ namespace Copium
case ShaderType::Fragment:
return VK_SHADER_STAGE_FRAGMENT_BIT;
default:
CP_ABORT("GetShaderStageFlags : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
}
+9 -8
View File
@@ -2,6 +2,7 @@
#include "copium/util/FileSystem.h"
#include "copium/core/Vulkan.h"
#include "copium/util/RuntimeException.h"
namespace Copium
{
@@ -26,7 +27,7 @@ namespace Copium
fragShaderModule = InitializeShaderModule(FileSystem::ReadFile(fragmentInput));
break;
default:
CP_ASSERT(false, "Shader : Unreachable switch case %d", (int)type);
CP_ASSERT(false, "Unreachable switch case %d", (int)type);
}
shaderStages.resize(2);
@@ -78,17 +79,17 @@ namespace Copium
{
if (FileSystem::DateModified(filename) < FileSystem::DateModified(spvFilename))
{
CP_DEBUG("InitializeShaderModuleFromGlslFile : Loading cached shader file: %s", filename.c_str());
CP_DEBUG("Loading cached shader file: %s", filename.c_str());
std::vector<uint32_t> data = FileSystem::ReadFile32(spvFilename);
return InitializeShaderModule(data.data(), data.size() * sizeof(uint32_t));
}
}
}
catch (const std::runtime_error& e)
catch (const RuntimeException& e)
{
CP_WARN("InitializeShaderModuleFromGlslFile : Cached shader file is invalid, recreating it");
CP_WARN("Cached shader file is invalid, recreating it");
}
CP_DEBUG("InitializeShaderModuleFromGlslFile : Compiling shader file: %s", filename.c_str());
CP_DEBUG("Compiling shader file: %s", filename.c_str());
shaderc::Compiler compiler;
shaderc::CompileOptions options;
@@ -96,7 +97,7 @@ namespace Copium
std::vector<char> glslCode = FileSystem::ReadFile(filename);
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(glslCode.data(), glslCode.size(), type, filename.c_str(), options);
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "InitializeShaderModuleFromGlslFile : Failed to compile shader: %s\n%s", filename.c_str(), result.GetErrorMessage().c_str());
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile shader: %s\n%s", filename.c_str(), result.GetErrorMessage().c_str());
std::vector<uint32_t> data{result.cbegin(), result.cend()};
FileSystem::WriteFile(spvFilename, (const char*)data.data(), data.size() * sizeof(uint32_t));
@@ -111,7 +112,7 @@ namespace Copium
options.SetOptimizationLevel(shaderc_optimization_level_size);
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(code.data(), type, "inline_shader_code", options);
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "InitializeShaderModuleFromGlslCode : Failed to compile inline shader code: %s", result.GetErrorMessage());
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile inline shader code: %s", result.GetErrorMessage());
std::vector<uint32_t> data{result.cbegin(), result.cend()};
return InitializeShaderModule(data.data(), data.size() * sizeof(uint32_t));
@@ -125,7 +126,7 @@ namespace Copium
createInfo.pCode = data;
VkShaderModule shaderModule;
CP_VK_ASSERT(vkCreateShaderModule(Vulkan::GetDevice(), &createInfo, nullptr, &shaderModule), "InitializeShaderModule : Failed to initialize shader module");
CP_VK_ASSERT(vkCreateShaderModule(Vulkan::GetDevice(), &createInfo, nullptr, &shaderModule), "Failed to initialize shader module");
return shaderModule;
}
@@ -21,7 +21,7 @@ namespace Copium
return offset;
offset += GetUniformTypeOffset(uniformElem.first);
}
CP_ABORT("GetUniformOffset : Uniform not found=%s", uniform);
CP_ABORT("Uniform not found=%s", uniform);
}
uint32_t ShaderBinding::GetUniformSize(const std::string& uniform) const
@@ -31,7 +31,7 @@ namespace Copium
if (uniformElem.second == uniform)
return GetUniformTypeSize(uniformElem.first);
}
CP_ABORT("GetUniformSize : Uniform not found=%s", uniform);
CP_ABORT("Uniform not found=%s", uniform);
}
UniformType ShaderBinding::GetUniformType(const std::string& uniform) const
@@ -41,12 +41,12 @@ namespace Copium
if (uniformElem.second == uniform)
return uniformElem.first;
}
CP_ABORT("GetUniformType : Uniform not found=%s", uniform);
CP_ABORT("Uniform not found=%s", uniform);
}
uint32_t ShaderBinding::GetUniformBufferSize() const
{
CP_ASSERT(bindingType == BindingType::UniformBuffer, "GetUniformBufferSize : BindingType is not UniformBuffer");
CP_ASSERT(bindingType == BindingType::UniformBuffer, "BindingType is not UniformBuffer");
uint32_t size = 0;
for (auto& uniform : uniforms)
@@ -79,7 +79,7 @@ namespace Copium
case UniformType::Float:
return 4; // float
default:
CP_ABORT("GetUniformBufferSize : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
@@ -102,7 +102,7 @@ namespace Copium
case UniformType::Float:
return 16; // alignas(16) glm::vec2
default:
CP_ABORT("GetUniformBufferSize : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
}
@@ -103,7 +103,7 @@ namespace Copium
shaderBinding.bindingType = BindingType::Sampler2D;
else
shaderBinding.bindingType = BindingType::UniformBuffer;
CP_ASSERT(bindings.emplace(shaderBinding).second, "ParseLayout : multiple layouts with the same binding");
CP_ASSERT(bindings.emplace(shaderBinding).second, "multiple layouts with the same binding");
}
std::string_view ShaderReflector::ParseWord(const std::string& str, int& index)
@@ -6,7 +6,7 @@ namespace Copium
{
void VertexDescriptor::AddAttribute(uint32_t binding, uint32_t location, VkFormat format, uint32_t offset, uint32_t size)
{
CP_ASSERT(binding <= bindings.size(), "AddAttribute : Attribute binding must less than or be equal to the amount of current bindings");
CP_ASSERT(binding <= bindings.size(), "Attribute binding must less than or be equal to the amount of current bindings");
if (binding == bindings.size())
AddLayout(binding, size);
@@ -83,7 +83,7 @@ namespace Copium
void Renderer::InitializeIndexBuffer()
{
CP_ASSERT(MAX_NUM_INDICES < std::numeric_limits<uint16_t>::max(), "Renderer : Maximum number of indices too big");
CP_ASSERT(MAX_NUM_INDICES < std::numeric_limits<uint16_t>::max(), "Maximum number of indices too big");
std::vector<uint16_t> indices;
indices.resize(MAX_NUM_INDICES);
@@ -23,7 +23,7 @@ namespace Copium
VkDescriptorImageInfo ColorAttachment::GetDescriptorImageInfo(int index) const
{
CP_ASSERT(index >= 0 && index < imageViews.size(), "GetDescriptorImageInfo : index out of bound for color attachment");
CP_ASSERT(index >= 0 && index < imageViews.size(), "index out of bound for color attachment");
VkDescriptorImageInfo imageInfo{};
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
@@ -34,7 +34,7 @@ namespace Copium
VkImageView ColorAttachment::GetImageView(int index)
{
CP_ASSERT(index >= 0 && index < imageViews.size(), "GetImageView : Index out of bound");
CP_ASSERT(index >= 0 && index < imageViews.size(), "Index out of bound");
return imageViews[index];
}
+5 -5
View File
@@ -23,7 +23,7 @@ namespace Copium
createInfo.samples = VK_SAMPLE_COUNT_1_BIT;
createInfo.flags = 0;
CP_VK_ASSERT(vkCreateImage(Vulkan::GetDevice(), &createInfo, nullptr, image), "InitializeImage : Failed to initialize image");
CP_VK_ASSERT(vkCreateImage(Vulkan::GetDevice(), &createInfo, nullptr, image), "Failed to initialize image");
VkMemoryRequirements memoryRequirements;
vkGetImageMemoryRequirements(Vulkan::GetDevice(), *image, &memoryRequirements);
@@ -33,7 +33,7 @@ namespace Copium
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = Vulkan::GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties);
CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, imageMemory), "InitializeImage : Failed to initiallizse image memory");
CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, imageMemory), "Failed to initiallizse image memory");
vkBindImageMemory(Vulkan::GetDevice(), *image, *imageMemory, 0);
}
@@ -55,7 +55,7 @@ namespace Copium
createInfo.subresourceRange.levelCount = 1;
createInfo.subresourceRange.baseArrayLayer = 0;
createInfo.subresourceRange.layerCount = 1;
CP_VK_ASSERT(vkCreateImageView(Vulkan::GetDevice(), &createInfo, nullptr, &imageView), "InitializeImageView : Failed to initialize image view");
CP_VK_ASSERT(vkCreateImageView(Vulkan::GetDevice(), &createInfo, nullptr, &imageView), "Failed to initialize image view");
return imageView;
}
@@ -121,7 +121,7 @@ namespace Copium
}
else
{
CP_ABORT("TransitioinImageLayout : Unsupported layout transition");
CP_ABORT("Unsupported layout transition");
}
vkCmdPipelineBarrier(commandBuffer, srcStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
@@ -173,6 +173,6 @@ namespace Copium
return format;
}
}
CP_ABORT("SelectSupportedFormat : Failed to select supported format");
CP_ABORT("Failed to select supported format");
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ namespace Copium
createInfo.minLod = 0.0f;
createInfo.maxLod = 0.0f;
CP_VK_ASSERT(vkCreateSampler(Vulkan::GetDevice(), &createInfo, nullptr, &sampler), "InitializeSampler : Failed to initialize texture sampler");
CP_VK_ASSERT(vkCreateSampler(Vulkan::GetDevice(), &createInfo, nullptr, &sampler), "Failed to initialize texture sampler");
}
Sampler::operator VkSampler() const
@@ -13,7 +13,7 @@ namespace Copium
: Sampler{}, Asset{AssetType::Texture2D}
{
const std::string& filepath = metaFile.GetMetaClass("Texture2D").GetValue("filepath");
CP_DEBUG("Texture2D : Loading texture file: %s", filepath.c_str());
CP_DEBUG("Loading texture file: %s", filepath.c_str());
InitializeTextureImageFromFile(filepath);
}
@@ -48,7 +48,7 @@ namespace Copium
int texChannels;
stbi_uc* pixels = stbi_load(filename.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
CP_ASSERT(pixels, "InitializeTextureImage : Failed to load texture image");
CP_ASSERT(pixels, "Failed to load texture image");
InitializeTextureImageFromData((void*)pixels, texWidth, texHeight);
+12 -11
View File
@@ -4,6 +4,7 @@
#include "copium/util/VulkanException.h"
#include <iostream>
#include <iomanip>
#define CP_TERM_RED "\x1B[31m"
#define CP_TERM_GREEN "\x1B[32m"
@@ -11,16 +12,16 @@
#define CP_TERM_GRAY "\x1B[90m"
#define CP_TERM_CLEAR "\033[0m"
#define CP_DEBUG(format, ...) std::cout << CP_TERM_GRAY << "[DBG] " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO(format, ...) std::cout << "[INF] " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN(format, ...) std::cout << CP_TERM_YELLOW << "[WRN] " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR(format, ...) std::cout << CP_TERM_RED << "[ERR] " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_DEBUG(format, ...) std::cout << CP_TERM_GRAY << "[DBG] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO(format, ...) std::cout << "[INF] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN(format, ...) std::cout << CP_TERM_YELLOW << "[WRN] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR(format, ...) std::cout << CP_TERM_RED << "[ERR] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
// Continue traces, will not print the [XXX] tag before the log
#define CP_DEBUG_CONT(format, ...) std::cout << CP_TERM_GRAY << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO_CONT(format, ...) std::cout << " " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN_CONT(format, ...) std::cout << CP_TERM_YELLOW << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR_CONT(format, ...) std::cout << CP_TERM_RED << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_DEBUG_CONT(format, ...) std::cout << CP_TERM_GRAY << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO_CONT(format, ...) std::cout << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN_CONT(format, ...) std::cout << CP_TERM_YELLOW << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR_CONT(format, ...) std::cout << CP_TERM_RED << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ABORT(format, ...) \
do \
@@ -35,7 +36,7 @@
if(!(Function)) \
{ \
CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \
CP_ERR_CONT(format, __VA_ARGS__); \
CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \
throw Copium::RuntimeException(Copium::String::Format(format, __VA_ARGS__)); \
} \
} while(false)
@@ -45,7 +46,7 @@
if(Function != VK_SUCCESS) \
{ \
CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \
CP_ERR_CONT(format, __VA_ARGS__); \
CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \
throw Copium::VulkanException(Copium::String::Format(format, __VA_ARGS__)); \
} \
} while(false)
@@ -71,7 +72,7 @@ namespace Copium
static std::string Format(const std::string& format, Args... args)
{
int size = std::snprintf(nullptr, 0, format.c_str(), args...) + 1;
CP_ASSERT(size > 0, "Format : Error during formatting");
CP_ASSERT(size > 0, "Error during formatting");
std::unique_ptr<char[]> buf(new char[size]);
std::snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1);
+7 -7
View File
@@ -5,7 +5,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(), "ReadFile : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
size_t fileSize = (size_t)file.tellg();
std::vector<char> buffer(fileSize);
@@ -19,10 +19,10 @@ 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(), "ReadFile32 : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
size_t fileSize = (size_t)file.tellg();
CP_ASSERT(fileSize % 4 == 0, "ReadFile32 : byte size is not divisible by 4");
CP_ASSERT(fileSize % 4 == 0, "byte size is not divisible by 4");
std::vector<uint32_t> buffer(fileSize / 4);
file.seekg(0);
@@ -34,7 +34,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(), "ReadFileStr : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
size_t fileSize = (size_t)file.tellg();
std::string buffer;
@@ -51,7 +51,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(), "WriteFile : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
file.write(data.c_str(), data.size());
}
@@ -61,7 +61,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(), "WriteFile : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
file.write(data, size);
}
@@ -75,7 +75,7 @@ namespace Copium
int64_t FileSystem::DateModified(const std::string& filename)
{
struct stat result;
CP_ASSERT(stat(filename.c_str(), &result) == 0, "DataModified : Cannot stat file %s", filename.c_str());
CP_ASSERT(stat(filename.c_str(), &result) == 0, "Cannot stat file %s", filename.c_str());
return (int64_t)result.st_mtime;
}
}
+9 -9
View File
@@ -23,7 +23,7 @@ namespace Copium
const std::string& MetaFileClass::GetValue(const std::string& key) const
{
auto it = values.find(key);
CP_ASSERT(it != values.end(), "GetValue : Value does not exist: %s", key.c_str());
CP_ASSERT(it != values.end(), "Value does not exist: %s", key.c_str());
return it->second;
}
@@ -52,7 +52,7 @@ namespace Copium
{
std::ifstream stream(filepath);
CP_ASSERT(stream.is_open(), "MetaFile : Could not find meta file: %s", filepath.c_str());
CP_ASSERT(stream.is_open(), "Could not find meta file: %s", filepath.c_str());
LoadMetaFile(stream);
}
@@ -69,14 +69,14 @@ namespace Copium
MetaFileClass& MetaFile::GetMetaClass(const std::string& className)
{
auto it = classes.find(className);
CP_ASSERT(it != classes.end(), "GetMetaClass : class does not exist: %s", className.c_str());
CP_ASSERT(it != classes.end(), "class does not exist: %s", className.c_str());
return it->second;
}
const MetaFileClass& MetaFile::GetMetaClass(const std::string& className) const
{
auto it = classes.find(className);
CP_ASSERT(it != classes.end(), "GetMetaClass : class does not exist: ", className.c_str());
CP_ASSERT(it != classes.end(), "class does not exist: ", className.c_str());
return it->second;
}
@@ -128,7 +128,7 @@ namespace Copium
currentClass = StringUtil::Trim(line);
currentClass = currentClass.substr(1, currentClass.size() - 2);
metaClassIt = classes.find(currentClass);
CP_ASSERT(metaClassIt == classes.end(), "LoadMetaFile : Meta file contains two of the same class: %s", currentClass.c_str());
CP_ASSERT(metaClassIt == classes.end(), "Meta file contains two of the same class: %s", currentClass.c_str());
metaClassIt = classes.emplace(currentClass, MetaFileClass{}).first;
continue;
}
@@ -136,7 +136,7 @@ namespace Copium
size_t pos = line.find("=");
if(pos == std::string::npos)
{
CP_WARN("LoadMetaFile : Meta file line does not contain \'=\'");
CP_WARN("Meta file line does not contain \'=\'");
continue;
}
@@ -144,15 +144,15 @@ namespace Copium
std::string_view value = StringUtil::Trim(std::string_view(line.c_str() + pos + 1));
if(key.length() == 0)
{
CP_WARN("LoadMetaFile : MetaFile key is empty");
CP_WARN("MetaFile key is empty");
continue;
}
CP_ASSERT(metaClassIt != classes.end(), "LoadMetaFile : No meta file header specified: ", filepath.c_str());
CP_ASSERT(metaClassIt != classes.end(), "No meta file header specified: ", filepath.c_str());
auto res = metaClassIt->second.values.emplace(key, value);
if(!res.second)
{
CP_WARN("LoadMetaFile : Meta file key is defined twice: %s", std::string(key).c_str());
CP_WARN("Meta file key is defined twice: %s", std::string(key).c_str());
}
}
}
+3 -3
View File
@@ -20,7 +20,7 @@ namespace Copium
UUID::UUID(const std::string& uuidString)
: msb{0}, lsb{0}
{
CP_ASSERT(uuidString.size() == 36, "UUID : Invalid UUID string size: %s", uuidString.c_str());
CP_ASSERT(uuidString.size() == 36, "Invalid UUID string size: %s", uuidString.c_str());
for (int i = 0; i < 18; i++)
{
if (i == 8 || i == 13) // skip "-"
@@ -81,13 +81,13 @@ namespace Copium
{
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
CP_ABORT("HexToDec : Invalid char value: %c (%d)", c, (int)c);
CP_ABORT("Invalid char value: %c (%d)", c, (int)c);
}
char UUID::DecToHex(uint8_t nibble) const
{
if (nibble >= 0 && nibble <= 9) return '0' + nibble;
if (nibble >= 10 && nibble <= 15) return 'a' + nibble - 10;
CP_ABORT("DecToHex : Invalid nibble value: %d", (int)nibble);
CP_ABORT("Invalid nibble value: %d", (int)nibble);
}
}