Added compression to asset packs
This commit is contained in:
parent
c30f159429
commit
cdea6c4b64
@ -67,7 +67,7 @@ void MainState::update(double deltaTime) {
|
|||||||
|
|
||||||
if (button.isClicked())
|
if (button.isClicked())
|
||||||
app->changeState("Main State");
|
app->changeState("Main State");
|
||||||
if (button2.isClicked() || app->isKeyHeld(NFI_SPACE))
|
if (button2.isClicked() || app->isKeyPressed(NFI_SPACE))
|
||||||
sound.play(true);
|
sound.play(true);
|
||||||
|
|
||||||
if (app->isKeyPressed(NFI_O))
|
if (app->isKeyPressed(NFI_O))
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>Cabinet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@ -81,6 +82,7 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>Cabinet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <compressapi.h>
|
||||||
|
|
||||||
|
#define COMPRESS 1
|
||||||
|
|
||||||
|
COMPRESSOR_HANDLE cHandle;
|
||||||
|
|
||||||
void Log(const std::string& in) {
|
void Log(const std::string& in) {
|
||||||
std::cout << "[NFPackCreator] Info: " << in << "\n";
|
std::cout << "[NFPackCreator] Info: " << in << "\n";
|
||||||
@ -60,7 +65,18 @@ void writeFile(const std::string& filename, const std::string& in, bool encrypte
|
|||||||
}
|
}
|
||||||
write.insert(0, "NFEF");
|
write.insert(0, "NFEF");
|
||||||
}
|
}
|
||||||
|
#if COMPRESS
|
||||||
|
Log("Compressing...");
|
||||||
|
size_t compSize;
|
||||||
|
Compress(cHandle, &write[0], write.size(), NULL, 0, &compSize);
|
||||||
|
char* buff = new char[compSize];
|
||||||
|
Compress(cHandle, &write[0], write.size(), buff, compSize, &compSize);
|
||||||
|
|
||||||
|
out.write(buff, compSize);
|
||||||
|
delete[] buff;
|
||||||
|
#else
|
||||||
out << write;
|
out << write;
|
||||||
|
#endif
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +109,8 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CreateCompressor(COMPRESS_ALGORITHM_XPRESS_HUFF, NULL, &cHandle);
|
||||||
|
|
||||||
std::set<std::string> extensions;
|
std::set<std::string> extensions;
|
||||||
extensions.insert({ "shader", "obj", "png", "jpg", "ttf", "wav" });
|
extensions.insert({ "shader", "obj", "png", "jpg", "ttf", "wav" });
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<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>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
@ -96,7 +96,7 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<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>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
@ -50,7 +50,7 @@ namespace nf {
|
|||||||
|
|
||||||
void AssetPack::load(const char* packName) {
|
void AssetPack::load(const char* packName) {
|
||||||
std::string path = "assets/" + (std::string)packName;
|
std::string path = "assets/" + (std::string)packName;
|
||||||
std::string packContents = readFile(path);
|
std::string packContents = readFile(path, true);
|
||||||
std::string packContentsOBJ = packContents;
|
std::string packContentsOBJ = packContents;
|
||||||
std::unordered_map<std::string, ACubemap*> cubemaps;
|
std::unordered_map<std::string, ACubemap*> cubemaps;
|
||||||
std::unordered_map<std::string, AButton*> buttons;
|
std::unordered_map<std::string, AButton*> buttons;
|
||||||
|
@ -2,11 +2,15 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <compressapi.h>
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
|
static DECOMPRESSOR_HANDLE s_dHandle;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
void Debug::LogImp(const char* in) {
|
void Debug::LogImp(const char* in) {
|
||||||
std::chrono::duration<float> time = getCurrentTime();
|
std::chrono::duration<float> time = getCurrentTime();
|
||||||
@ -93,7 +97,10 @@ namespace nf {
|
|||||||
out.close();
|
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;
|
std::ifstream in;
|
||||||
in.open(filename, std::ios::binary);
|
in.open(filename, std::ios::binary);
|
||||||
if (!in)
|
if (!in)
|
||||||
@ -101,6 +108,16 @@ namespace nf {
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << in.rdbuf();
|
ss << in.rdbuf();
|
||||||
std::string read(ss.str());
|
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") {
|
if (read.size() > 4 && read.substr(0, 4) == "NFEF") {
|
||||||
read = read.substr(4);
|
read = read.substr(4);
|
||||||
for (unsigned int i = 0; i < read.size(); i++)
|
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 char* in);
|
||||||
const wchar_t* toWide(const std::string& in);
|
const wchar_t* toWide(const std::string& in);
|
||||||
void writeFile(const std::string& filename, const std::string& in, bool encrypted = false);
|
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