diff --git a/DevScreenshots/2. Textured Quad with Transformations.png b/DevScreenshots/2. Textured Quad with Transformations.png new file mode 100644 index 0000000..e651644 Binary files /dev/null and b/DevScreenshots/2. Textured Quad with Transformations.png differ diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index de3235c..9059d0b 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -108,6 +108,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + @@ -131,6 +134,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + @@ -150,6 +156,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + @@ -173,6 +182,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + diff --git a/NFPackCreator/NFPackCreator.rc b/NFPackCreator/NFPackCreator.rc new file mode 100644 index 0000000..d44f749 --- /dev/null +++ b/NFPackCreator/NFPackCreator.rc @@ -0,0 +1,100 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Grayson Riffe" + VALUE "FileDescription", "Nothin' Fancy Asset Pack Creator" + VALUE "FileVersion", "1.0" + VALUE "InternalName", "NFPackCreator.exe" + VALUE "LegalCopyright", "Copyright (C) 2021 Grayson Riffe" + VALUE "OriginalFilename", "NFPackCreator.exe" + VALUE "ProductName", "Nothin' Fancy Asset Pack Creator" + VALUE "ProductVersion", "1.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/NFPackCreator/NFPackCreator.vcxproj b/NFPackCreator/NFPackCreator.vcxproj new file mode 100644 index 0000000..1959143 --- /dev/null +++ b/NFPackCreator/NFPackCreator.vcxproj @@ -0,0 +1,98 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + 16.0 + Win32Proj + {771b4aee-e2c6-4745-ac40-1ef57149612e} + NFPackCreator + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + true + $(ProjectDir)bin\$(Platform)$(Configuration)\ + $(ProjectDir)int\$(Platform)$(Configuration)\ + + + false + $(ProjectDir)bin\$(Platform)$(Configuration)\ + $(ProjectDir)int\$(Platform)$(Configuration)\ + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NFPackCreator/NFPackCreator.vcxproj.filters b/NFPackCreator/NFPackCreator.vcxproj.filters new file mode 100644 index 0000000..61fce6a --- /dev/null +++ b/NFPackCreator/NFPackCreator.vcxproj.filters @@ -0,0 +1,32 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/NFPackCreator/NFPackCreator.vcxproj.user b/NFPackCreator/NFPackCreator.vcxproj.user new file mode 100644 index 0000000..5e75a14 --- /dev/null +++ b/NFPackCreator/NFPackCreator.vcxproj.user @@ -0,0 +1,16 @@ + + + + true + + + $(OutDir) + WindowsLocalDebugger + -h + + + $(OutDir) + WindowsLocalDebugger + -h + + \ No newline at end of file diff --git a/NFPackCreator/resource.h b/NFPackCreator/resource.h new file mode 100644 index 0000000..a2d92eb --- /dev/null +++ b/NFPackCreator/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by NFPackCreator.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/NFPackCreator/src/main.cpp b/NFPackCreator/src/main.cpp new file mode 100644 index 0000000..ebbed33 --- /dev/null +++ b/NFPackCreator/src/main.cpp @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +void Log(const std::string& in) { + std::cout << "[NFPackCreator] Info: " << in << "\n"; +} + +void Log(const char* in) { + std::cout << "[NFPackCreator] Info: " << in << "\n"; +} + +__declspec(noreturn) void Error(const std::string& in) { + HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(cmd, FOREGROUND_RED); + std::cout << "[NFPackCreator] Error: " + in + "\n"; + SetConsoleTextAttribute(cmd, 7); + std::this_thread::sleep_for(std::chrono::seconds(3)); + std::exit(-1); +} + +void Success(const std::string& in) { + HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(cmd, FOREGROUND_GREEN); + std::cout << "[NFPackCreator] Success: " + in + "\n"; + SetConsoleTextAttribute(cmd, 7); +} + +std::string readFile(const std::string& filename) { + std::ifstream in; + in.open(filename); + if (!in) + Error("File \"" + (std::string)filename + (std::string)"\" could not be read!"); + std::stringstream ss; + ss << in.rdbuf(); + std::string read(ss.str()); + if (read.size() > 4 && read.substr(0, 4) == "NFEF") { + read = read.substr(4); + for (unsigned int i = 0; i < read.size(); i++) + read[i] = read[i] - 100; + } + return read; +} + +void writeFile(const std::string& filename, const std::string& in, bool encrypted) { + std::ofstream out; + out.open(filename); + if (!out) + Error("File \"" + (std::string)filename + (std::string)"\" could not be written!"); + std::string write(in); + if (encrypted) { + for (unsigned int i = 0; i < write.size(); i++) + write[i] = write[i] + 100; + write.insert(0, "NFEF"); + } + out << write; + out.close(); +} + +int main(int argc, char* argv[]) { + Log("Starting up"); + + if (argc > 1) { + if ((std::string)argv[1] == "-h") { + Log("Nothin' Fancy Asset Pack Creator\nThis tool creates .nfpack files for the NF engine to load at runtime.\nA pack gets created for each directory in the working directory if there are only compatible files inside.\nSubdirectories are not ignored."); + return 0; + } + } + + std::set extensions; + extensions.insert({ "obj", "png" }); + + unsigned int dirCount = 0; + const std::filesystem::path workingDir = std::filesystem::current_path(); + for (const auto& currDir : std::filesystem::directory_iterator(std::filesystem::current_path())) { + if (!currDir.is_directory()) + continue; + std::string filename = currDir.path().filename().string().append(".nfpack"); + Log("Creating pack \"" + filename + (std::string)"\""); + std::ifstream in; + std::stringstream out; + unsigned int fileCount = 0; + for (const auto& curr : std::filesystem::recursive_directory_iterator(currDir)) { + if (curr.is_directory()) + continue; + std::filesystem::path relative = std::filesystem::relative(curr, currDir); + if (extensions.find(relative.extension().string().substr(1)) == extensions.end()) + Error("File \"" + relative.string() + (std::string)"\" is not of supported type!"); + Log("Current file: " + relative.string()); + + in.open(curr.path(), std::ios::binary); + if (!in) + Error("Couldn't open \"" + relative.string() + (std::string)"\"!"); + if (out.rdbuf()->in_avail() != 0) + out << "\n"; + out << "#NFASSET " + curr.path().filename().string(); + out << "\n"; + out << in.rdbuf(); + in.close(); + fileCount++; + } + if (fileCount == 0) { + Log("No files found inside of \"" + currDir.path().filename().string() + (std::string)"\". No pack written."); + continue; + } + writeFile(filename, out.str(), true); + Success("Wrote \"" + filename + (std::string)"\" containing " + std::to_string(fileCount) + (std::string)" files."); + dirCount++; + } + if (dirCount > 0) + Log("Wrote " + std::to_string(dirCount) + (std::string)" asset pack(s)."); + Log("Done"); + std::this_thread::sleep_for(std::chrono::seconds(2)); + return 0; +} \ No newline at end of file diff --git a/NothinFancy/src/Assets.cpp b/NothinFancy/src/Assets.cpp index f06dfef..f7eecba 100644 --- a/NothinFancy/src/Assets.cpp +++ b/NothinFancy/src/Assets.cpp @@ -23,7 +23,7 @@ namespace nf { void AssetPack::load(const char* packName) { std::string path = "assets/" + (std::string)packName + ".nfpack"; - std::string contents = readFile(path.c_str(), true); + std::string contents = readFile(path); } AssetPack::~AssetPack() { diff --git a/NothinFancy/src/Utility.cpp b/NothinFancy/src/Utility.cpp index bc6d6bf..859c525 100644 --- a/NothinFancy/src/Utility.cpp +++ b/NothinFancy/src/Utility.cpp @@ -35,7 +35,7 @@ namespace nf { SetConsoleTextAttribute(cmd, FOREGROUND_RED); std::printf("[%.4f] Error (%s, %i): %s\n", time.count(), filename, line, in); SetConsoleTextAttribute(cmd, 7); - CloseHandle(cmd); + FindClose(cmd); } void Debug::ErrorImp(const std::string& in, const char* filename, int line) { @@ -45,7 +45,7 @@ namespace nf { std::printf("[%.4f] Error (%s, %i): ", time.count(), filename, line); std::cout << in << "\n"; SetConsoleTextAttribute(cmd, 7); - CloseHandle(cmd); + FindClose(cmd); } std::chrono::duration Debug::getCurrentTime() { @@ -82,11 +82,10 @@ namespace nf { return out; } - bool writeFile(const char* filename, const std::string& in, bool encrypted) { - std::string file(filename); - if (file.find('/') != std::string::npos || file.find('\\') != std::string::npos) { - int pos = file.find_last_of("/\\"); - std::string temp = file.substr(0, pos); + void writeFile(const std::string& filename, const std::string& in, bool encrypted) { + if (filename.find('/') != std::string::npos || filename.find('\\') != std::string::npos) { + int pos = filename.find_last_of("/\\"); + std::string temp = filename.substr(0, pos); std::wstring folders(temp.begin(), temp.end()); WCHAR exe[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), exe, MAX_PATH); @@ -104,21 +103,23 @@ namespace nf { if (encrypted) { for (unsigned int i = 0; i < write.size(); i++) write[i] = write[i] + 100; + write.insert(0, "NFEF"); } out << write; out.close(); - return true; } - std::string readFile(const char* filename, bool encrypted) { + std::string readFile(const std::string& filename) { std::ifstream in; - in.open(filename); + in.open(filename, std::ios::binary); + //TODO: Test this change if (!in) Error("File \"" + (std::string)filename + (std::string)"\" could not be read!"); std::stringstream ss; ss << in.rdbuf(); std::string read(ss.str()); - if (encrypted) { + if (read.size() > 4 && read.substr(0, 4) == "NFEF" ){ + read = read.substr(4); for (unsigned int i = 0; i < read.size(); i++) read[i] = read[i] - 100; } diff --git a/NothinFancy/src/include/Utility.h b/NothinFancy/src/include/Utility.h index 609e841..66d7d90 100644 --- a/NothinFancy/src/include/Utility.h +++ b/NothinFancy/src/include/Utility.h @@ -46,7 +46,7 @@ std::exit(-1);} const wchar_t* toWide(const char* in); const wchar_t* toWide(const std::string& in); - bool writeFile(const char* filename, const std::string& in, bool encrypted = false); - std::string readFile(const char* filename, bool encrypted = false); + void writeFile(const std::string& filename, const std::string& in, bool encrypted = false); + std::string readFile(const std::string& filename); } \ No newline at end of file diff --git a/STEMSln.sln b/STEMSln.sln index bc4469b..035a62f 100644 --- a/STEMSln.sln +++ b/STEMSln.sln @@ -6,6 +6,11 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NothinFancy", "NothinFancy\NothinFancy.vcxproj", "{1B9C5361-E301-41BF-97E7-56D65F11E2BB}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Game", "Game\Game.vcxproj", "{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}" + ProjectSection(ProjectDependencies) = postProject + {771B4AEE-E2C6-4745-AC40-1EF57149612E} = {771B4AEE-E2C6-4745-AC40-1EF57149612E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NFPackCreator", "NFPackCreator\NFPackCreator.vcxproj", "{771B4AEE-E2C6-4745-AC40-1EF57149612E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +32,12 @@ Global {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x64.ActiveCfg = Release|x64 {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x86.ActiveCfg = Release|Win32 {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x86.Build.0 = Release|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Debug|x64.ActiveCfg = Debug|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Debug|x86.ActiveCfg = Debug|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Debug|x86.Build.0 = Debug|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Release|x64.ActiveCfg = Release|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Release|x86.ActiveCfg = Release|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE