Added compression to asset packs
This commit is contained in:
parent
c30f159429
commit
cdea6c4b64
Game/src
NFPackCreator
NothinFancy
@ -67,7 +67,7 @@ void MainState::update(double deltaTime) {
|
||||
|
||||
if (button.isClicked())
|
||||
app->changeState("Main State");
|
||||
if (button2.isClicked() || app->isKeyHeld(NFI_SPACE))
|
||||
if (button2.isClicked() || app->isKeyPressed(NFI_SPACE))
|
||||
sound.play(true);
|
||||
|
||||
if (app->isKeyPressed(NFI_O))
|
||||
|
@ -64,6 +64,7 @@
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>Cabinet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@ -81,6 +82,7 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>Cabinet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
@ -6,6 +6,11 @@
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
#include <Windows.h>
|
||||
#include <compressapi.h>
|
||||
|
||||
#define COMPRESS 1
|
||||
|
||||
COMPRESSOR_HANDLE cHandle;
|
||||
|
||||
void Log(const std::string& in) {
|
||||
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");
|
||||
}
|
||||
#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;
|
||||
#endif
|
||||
out.close();
|
||||
}
|
||||
|
||||
@ -93,6 +109,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
CreateCompressor(COMPRESS_ALGORITHM_XPRESS_HUFF, NULL, &cHandle);
|
||||
|
||||
std::set<std::string> extensions;
|
||||
extensions.insert({ "shader", "obj", "png", "jpg", "ttf", "wav" });
|
||||
|
||||
|
@ -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