some more refactoring and improvements
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <cinttypes>
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include <zlib.h>
|
||||
#include "Data/Containers/Array.hpp"
|
||||
|
||||
namespace OpenVulkano
|
||||
@@ -195,25 +196,7 @@ namespace OpenVulkano
|
||||
static Array<char> ReadFile(const char (&filePath)[N], bool emptyOnMissing = false,
|
||||
bool nullTerminateString = false)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::ate | std::ios::binary);
|
||||
if (!file.is_open())
|
||||
{
|
||||
if (emptyOnMissing)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
throw std::runtime_error("Failed to open file '" + std::string(filePath) + "'!");
|
||||
}
|
||||
const size_t fileSize = static_cast<size_t>(file.tellg());
|
||||
Array<char> data(fileSize + nullTerminateString);
|
||||
file.seekg(0);
|
||||
file.read(data.Data(), fileSize);
|
||||
if (nullTerminateString)
|
||||
{
|
||||
data[fileSize] = '\0';
|
||||
}
|
||||
file.close();
|
||||
return data;
|
||||
return ReadFile(std::string(filePath), emptyOnMissing, nullTerminateString);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -222,6 +205,26 @@ namespace OpenVulkano
|
||||
static const int id = uniqueTypeID++;
|
||||
return id;
|
||||
}
|
||||
|
||||
static unsigned char* STBZlibCompressor(unsigned char* data, int data_len, int* out_len, int quality)
|
||||
{
|
||||
uLong maxCompressedSize = compressBound(data_len);
|
||||
void* outData = malloc(maxCompressedSize);
|
||||
if (!outData)
|
||||
{
|
||||
*out_len = 0;
|
||||
return nullptr;
|
||||
}
|
||||
int result = compress2(static_cast<Bytef*>(outData), &maxCompressedSize, data, data_len, Z_BEST_COMPRESSION);
|
||||
if (result != Z_OK)
|
||||
{
|
||||
free(outData);
|
||||
*out_len = 0;
|
||||
return nullptr;
|
||||
}
|
||||
*out_len = static_cast<int>(maxCompressedSize);
|
||||
return static_cast<unsigned char*>(outData);
|
||||
}
|
||||
|
||||
static std::string DemangleTypeName(const char* name);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user