Added compression to asset packs
This commit is contained in:
1 parent
c30f159429
commit
cdea6c4b64
7 files changed
+43
-6
No files matched your search
@@ -67,7 +67,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;Cabinet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
@@ -96,7 +96,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;Cabinet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Lib>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace nf {
|
||||
|
||||
void AssetPack::load(const char* packName) {
|
||||
std::string path = "assets/" + (std::string)packName;
|
||||
std::string packContents = readFile(path);
|
||||
std::string packContents = readFile(path, true);
|
||||
std::string packContentsOBJ = packContents;
|
||||
std::unordered_map<std::string, ACubemap*> cubemaps;
|
||||
std::unordered_map<std::string, AButton*> buttons;
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <Windows.h>
|
||||
#include <compressapi.h>
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
namespace nf {
|
||||
static DECOMPRESSOR_HANDLE s_dHandle;
|
||||
|
||||
#ifdef _DEBUG
|
||||
void Debug::LogImp(const char* in) {
|
||||
std::chrono::duration<float> time = getCurrentTime();
|
||||
@@ -93,7 +97,10 @@ namespace nf {
|
||||
out.close();
|
||||
}
|
||||
|
||||
std::string readFile(const std::string& filename) {
|
||||
std::string readFile(const std::string& filename, bool compressed) {
|
||||
if (!s_dHandle)
|
||||
CreateDecompressor(COMPRESS_ALGORITHM_XPRESS_HUFF, NULL, &s_dHandle);
|
||||
|
||||
std::ifstream in;
|
||||
in.open(filename, std::ios::binary);
|
||||
if (!in)
|
||||
@@ -101,6 +108,16 @@ namespace nf {
|
||||
std::stringstream ss;
|
||||
ss << in.rdbuf();
|
||||
std::string read(ss.str());
|
||||
|
||||
if (compressed) {
|
||||
size_t decompSize;
|
||||
Decompress(s_dHandle, &read[0], read.size(), NULL, 0, &decompSize);
|
||||
char* buff = new char[decompSize];
|
||||
Decompress(s_dHandle, &read[0], read.size(), buff, decompSize, &decompSize);
|
||||
read = std::string(buff, decompSize);
|
||||
delete[] buff;
|
||||
}
|
||||
|
||||
if (read.size() > 4 && read.substr(0, 4) == "NFEF") {
|
||||
read = read.substr(4);
|
||||
for (unsigned int i = 0; i < read.size(); i++)
|
||||
|
||||
@@ -89,5 +89,5 @@ std::exit(-1);}
|
||||
const wchar_t* toWide(const char* in);
|
||||
const wchar_t* toWide(const std::string& in);
|
||||
void writeFile(const std::string& filename, const std::string& in, bool encrypted = false);
|
||||
std::string readFile(const std::string& filename);
|
||||
std::string readFile(const std::string& filename, bool compressed = false);
|
||||
}
|
||||
Reference in new issue
Block a user