diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp
index 70d308b..534bc2e 100644
--- a/Game/src/MainState.cpp
+++ b/Game/src/MainState.cpp
@@ -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))
diff --git a/NFPackCreator/NFPackCreator.vcxproj b/NFPackCreator/NFPackCreator.vcxproj
index 539fe17..fed90fa 100644
--- a/NFPackCreator/NFPackCreator.vcxproj
+++ b/NFPackCreator/NFPackCreator.vcxproj
@@ -64,6 +64,7 @@
Console
true
+ Cabinet.lib;%(AdditionalDependencies)
@@ -81,6 +82,7 @@
true
true
true
+ Cabinet.lib;%(AdditionalDependencies)
diff --git a/NFPackCreator/src/main.cpp b/NFPackCreator/src/main.cpp
index f6e73c5..cd0beee 100644
--- a/NFPackCreator/src/main.cpp
+++ b/NFPackCreator/src/main.cpp
@@ -6,6 +6,11 @@
#include
#include
#include
+#include
+
+#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 extensions;
extensions.insert({ "shader", "obj", "png", "jpg", "ttf", "wav" });
diff --git a/NothinFancy/NothinFancy.vcxproj b/NothinFancy/NothinFancy.vcxproj
index 61da889..233df84 100644
--- a/NothinFancy/NothinFancy.vcxproj
+++ b/NothinFancy/NothinFancy.vcxproj
@@ -67,7 +67,7 @@
true
- glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;%(AdditionalDependencies)
+ glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;Cabinet.lib;%(AdditionalDependencies)
$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)
@@ -96,7 +96,7 @@
true
- glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;%(AdditionalDependencies)
+ glew32s.lib;opengl32.lib;freetype.lib;xaudio2.lib;Cabinet.lib;%(AdditionalDependencies)
$(ProjectDir)dep\lib\;%(AdditionalLibraryDirectories)
diff --git a/NothinFancy/src/Assets.cpp b/NothinFancy/src/Assets.cpp
index 90f5706..f7982d3 100644
--- a/NothinFancy/src/Assets.cpp
+++ b/NothinFancy/src/Assets.cpp
@@ -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 cubemaps;
std::unordered_map buttons;
diff --git a/NothinFancy/src/Utility.cpp b/NothinFancy/src/Utility.cpp
index 932a904..95b3df5 100644
--- a/NothinFancy/src/Utility.cpp
+++ b/NothinFancy/src/Utility.cpp
@@ -2,11 +2,15 @@
#include
#include
#include
+#include
+#include
#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 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++)
diff --git a/NothinFancy/src/include/Utility.h b/NothinFancy/src/include/Utility.h
index 6532022..5e09b36 100644
--- a/NothinFancy/src/include/Utility.h
+++ b/NothinFancy/src/include/Utility.h
@@ -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);
}
\ No newline at end of file