Merge branch 'develop' of https://github.com/antopilo/Nuake into develop
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Directory containing the files
|
||||
input_directory="Resources"
|
||||
|
||||
# Output C++ header file for variable declarations
|
||||
output_header="Nuake/src/Resource/StaticResources.h"
|
||||
|
||||
# Output C++ source file for data storage
|
||||
output_source="Nuake/src/Resource/StaticResources.cpp"
|
||||
|
||||
# Remove existing header and source files (if any)
|
||||
rm -f "$output_header" "$output_source"
|
||||
|
||||
# Create the C++ header file with an initial guard
|
||||
echo "#ifndef FILES_DATA_H" >> "$output_header"
|
||||
echo "#define FILES_DATA_H" >> "$output_header"
|
||||
|
||||
echo "#include <string> " >> "$output_header"
|
||||
|
||||
echo "namespace Nuake { " >> "$output_header"
|
||||
echo " namespace StaticResources { " >> "$output_header"
|
||||
|
||||
# Create the C++ source file
|
||||
echo "#include \"StaticResources.h\"" >> "$output_source"
|
||||
|
||||
echo "namespace Nuake { " >> "$output_source"
|
||||
echo " namespace StaticResources { " >> "$output_source"
|
||||
# Use find to search for files in the directory and its subdirectories
|
||||
find "$input_directory" -type f -print0 | while IFS= read -r -d $'\0' file_path; do
|
||||
# Get the relative path of the file within the input_directory
|
||||
relative_path="${file_path/}"
|
||||
|
||||
# Sanitize the relative path to make it suitable for C++ variable names
|
||||
sanitized_path="${relative_path//[^[:alnum:]_]/_}"
|
||||
|
||||
# Generate C++ variable declarations for file path and size
|
||||
echo "extern const std::string ${sanitized_path}_path;" >> "$output_header"
|
||||
echo "extern unsigned int ${sanitized_path}_len;" >> "$output_header"
|
||||
echo "extern unsigned char ${sanitized_path}[];" >> "$output_header"
|
||||
|
||||
# Append C++ code to the source file for storing file data
|
||||
echo -e "\n// Data for file: ${sanitized_path}_path" >> "$output_source"
|
||||
echo "const std::string ${sanitized_path}_path = R\"(${relative_path})\";" >> "$output_source"
|
||||
|
||||
xxd -i "$file_path" | sed -e 's/^/ /' >> "$output_source"
|
||||
done
|
||||
|
||||
echo " }" >> "$output_source"
|
||||
echo "}">> "$output_source"
|
||||
|
||||
echo " }" >> "$output_header"
|
||||
echo "}">> "$output_header"
|
||||
|
||||
# Close the header file guard
|
||||
echo "#endif // FILES_DATA_H" >> "$output_header"
|
||||
|
||||
echo "Header file '$output_header' generated with variable declarations."
|
||||
echo "Source file '$output_source' generated with file data."
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -864,3 +864,4 @@ Nuake/dependencies/glad/glad.vcxproj.filters
|
||||
*.csproj
|
||||
*.filters
|
||||
cloc.exe
|
||||
Nuake/src/Modules/Modules.cpp
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "src/Scripting/ScriptingEngine.h"
|
||||
#include "src/Scripting/ScriptingEngineNet.h"
|
||||
#include "src/Threading/JobSystem.h"
|
||||
|
||||
#include "src/Modules/Modules.h"
|
||||
|
||||
#include <imgui/imgui_impl_glfw.h>
|
||||
#include <imgui/imgui_impl_opengl3.h>
|
||||
@@ -43,6 +43,8 @@ namespace Nuake
|
||||
Input::Init();
|
||||
Renderer2D::Init();
|
||||
Logger::Log("Engine initialized");
|
||||
|
||||
Modules::StartupModules();
|
||||
}
|
||||
|
||||
void Engine::Tick()
|
||||
|
||||
11
Nuake/src/Modules/Modules.h
Normal file
11
Nuake/src/Modules/Modules.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class Modules
|
||||
{
|
||||
public:
|
||||
static void StartupModules();
|
||||
static void ShutdownModules();
|
||||
};
|
||||
}
|
||||
74
Nuake/src/Modules/Modules.lua
Normal file
74
Nuake/src/Modules/Modules.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
-- Function to scan the "Modules" directory and load all module definitions
|
||||
function loadModules(modulesDir)
|
||||
local modules = {}
|
||||
|
||||
-- Get all folders in the Modules directory
|
||||
local dirs = os.matchdirs(path.join(modulesDir, "*"))
|
||||
|
||||
for _, dir in ipairs(dirs) do
|
||||
local moduleName = path.getname(dir)
|
||||
local moduleFile = path.join(dir, "Module.lua")
|
||||
|
||||
if os.isfile(moduleFile) then
|
||||
-- Load the module data
|
||||
local moduleData = dofile(moduleFile)
|
||||
|
||||
-- Set the module name from the directory
|
||||
moduleData._name = moduleName
|
||||
|
||||
print("Found module \"".. moduleData.name .."\" (".. moduleData._name ..")")
|
||||
|
||||
table.insert(modules, moduleData)
|
||||
end
|
||||
end
|
||||
|
||||
return modules
|
||||
end
|
||||
|
||||
-- Function to generate the final C++ file with startup and shutdown functions
|
||||
function generateModulesFile(modules, outputFilePath, sourceDir)
|
||||
local outputFile = io.open(outputFilePath, "w")
|
||||
|
||||
if not outputFile then
|
||||
print("Error: Could not write to file ".. outputFilePath)
|
||||
return
|
||||
end
|
||||
|
||||
outputFile:write("// Auto-generated modules management file\n")
|
||||
outputFile:write("#include \"Modules.h\"\n\n")
|
||||
|
||||
-- Include module header files
|
||||
for _, module in ipairs(modules) do
|
||||
outputFile:write("#include \"".. module._name .."/".. module.module_header .."\"\n")
|
||||
end
|
||||
outputFile:write("\n")
|
||||
|
||||
outputFile:write("#include \"src/Core/Logger.h\"\n\n")
|
||||
|
||||
-- Generate StartupModules function
|
||||
outputFile:write("void Nuake::Modules::StartupModules()\n{\n")
|
||||
for _, module in ipairs(modules) do
|
||||
outputFile:write(" Logger::Log(\"Starting ".. module._name .."\", \"modules\");\n")
|
||||
outputFile:write(" Module_".. module._name .."_Startup();\n")
|
||||
end
|
||||
outputFile:write("}\n\n")
|
||||
|
||||
-- Generate ShutdownModules function
|
||||
outputFile:write("void Nuake::Modules::ShutdownModules()\n{\n")
|
||||
for _, module in ipairs(modules) do
|
||||
outputFile:write(" Logger::Log(\"Shutting down ".. module._name .."\", \"modules\");\n")
|
||||
outputFile:write(" Module_".. module._name .."_Shutdown();\n")
|
||||
end
|
||||
outputFile:write("}\n")
|
||||
|
||||
outputFile:close()
|
||||
|
||||
local sources = {}
|
||||
for _, module in ipairs(modules) do
|
||||
table.insert(sources, sourceDir .. "/" .. module._name .. "/" .. module.module_header)
|
||||
for _, v in ipairs(module.sources) do
|
||||
table.insert(sources, sourceDir .. "/" .. module._name .. "/" .. v)
|
||||
end
|
||||
end
|
||||
return sources
|
||||
end
|
||||
104
build/BuildAssets.lua
Normal file
104
build/BuildAssets.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
local padding = " "
|
||||
|
||||
-- Function to convert a file to a C++ byte array representation
|
||||
local function fileToByteArray(file_path)
|
||||
local file = io.open(file_path, "rb") -- Open file in binary mode
|
||||
if not file then
|
||||
print("Error: Could not open file " .. file_path)
|
||||
return nil
|
||||
end
|
||||
|
||||
local byte_array = {}
|
||||
local byte_count = 0
|
||||
|
||||
for byte in file:read("*a"):gmatch(".") do
|
||||
table.insert(byte_array, string.format("0x%02X", string.byte(byte)))
|
||||
byte_count = byte_count + 1
|
||||
if byte_count % 12 == 0 then
|
||||
table.insert(byte_array, ",\n".. padding) -- Insert newline after the comma
|
||||
else
|
||||
table.insert(byte_array, ", ") -- Insert comma between bytes
|
||||
end
|
||||
end
|
||||
|
||||
file:close()
|
||||
return table.concat(byte_array)
|
||||
end
|
||||
|
||||
-- Lua function to generate C++ header and source files from files in a directory
|
||||
function generateStaticResources(input_directory, output_header, output_source)
|
||||
-- Remove existing header and source files (if any)
|
||||
os.remove(output_header)
|
||||
os.remove(output_source)
|
||||
|
||||
-- Open the header file for writing
|
||||
local header_file = io.open(output_header, "w")
|
||||
local source_file = io.open(output_source, "w")
|
||||
|
||||
-- Error handling
|
||||
if not header_file then
|
||||
print("Error: Could not open header file " .. output_header)
|
||||
return
|
||||
end
|
||||
|
||||
if not source_file then
|
||||
print("Error: Could not open source file " .. output_source)
|
||||
header_file:close()
|
||||
return
|
||||
end
|
||||
|
||||
-- Write initial guard and includes to header file
|
||||
header_file:write("#ifndef FILES_DATA_H\n")
|
||||
header_file:write("#define FILES_DATA_H\n\n")
|
||||
header_file:write("#include <string>\n\n")
|
||||
header_file:write("namespace Nuake {\n")
|
||||
header_file:write(" namespace StaticResources {\n")
|
||||
|
||||
-- Write includes and namespace to source file
|
||||
source_file:write("#include \"StaticResources.h\"\n\n")
|
||||
source_file:write("namespace Nuake {\n")
|
||||
source_file:write(" namespace StaticResources {\n")
|
||||
|
||||
-- Iterate over all files in the input directory and its subdirectories
|
||||
for _, file_path in ipairs(os.matchfiles(path.join(input_directory, "**"))) do
|
||||
-- Get the relative path of the file
|
||||
local relative_path = file_path
|
||||
|
||||
-- Sanitize the relative path to make it suitable for C++ variable names
|
||||
local sanitized_path = relative_path:gsub("[^%w_]", "_")
|
||||
|
||||
-- Generate C++ variable declarations for file path, size, and data
|
||||
header_file:write(" extern const std::string " .. sanitized_path .. "_path;\n")
|
||||
header_file:write(" extern unsigned int " .. sanitized_path .. "_len;\n")
|
||||
header_file:write(" extern unsigned char " .. sanitized_path .. "[];\n")
|
||||
|
||||
-- Append C++ code to the source file for storing file data
|
||||
source_file:write("\n // Data for file: " .. sanitized_path .. "_path\n")
|
||||
source_file:write(" const std::string " .. sanitized_path .. "_path = R\"(" .. relative_path .. ")\";\n")
|
||||
|
||||
-- Convert file content to a C++ byte array
|
||||
local byte_array = fileToByteArray(file_path)
|
||||
if byte_array then
|
||||
source_file:write(" unsigned char " .. sanitized_path .. "[] = {\n".. padding .. byte_array .. "\n };\n")
|
||||
source_file:write(" unsigned int " .. sanitized_path .. "_len = sizeof(" .. sanitized_path .. ");\n")
|
||||
else
|
||||
print("Error: Could not convert file to byte array " .. file_path)
|
||||
end
|
||||
end
|
||||
|
||||
-- Close namespaces and guard in header file
|
||||
header_file:write(" }\n")
|
||||
header_file:write("}\n\n")
|
||||
header_file:write("#endif // FILES_DATA_H\n")
|
||||
|
||||
-- Close namespaces in source file
|
||||
source_file:write(" }\n")
|
||||
source_file:write("}\n")
|
||||
|
||||
-- Close the files
|
||||
header_file:close()
|
||||
source_file:close()
|
||||
|
||||
print("Header file '" .. output_header .. "' generated with variable declarations.")
|
||||
print("Source file '" .. output_source .. "' generated with file data.")
|
||||
end
|
||||
69
premake5.lua
69
premake5.lua
@@ -1,3 +1,20 @@
|
||||
-- ╔═══════════════════════════════════════╗
|
||||
-- ║ ACTIONS ║
|
||||
-- ╚═══════════════════════════════════════╝
|
||||
|
||||
include "build/BuildAssets.lua"
|
||||
newaction {
|
||||
trigger = "build-assets",
|
||||
description = "",
|
||||
execute = function ()
|
||||
generateStaticResources("Resources", "Nuake/src/Resource/StaticResources.h", "Nuake/src/Resource/StaticResources.cpp")
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
-- ╔═══════════════════════════════════════╗
|
||||
-- ║ WORKSPACE ║
|
||||
-- ╚═══════════════════════════════════════╝
|
||||
workspace "Nuake"
|
||||
conformancemode "On"
|
||||
configurations
|
||||
@@ -39,6 +56,7 @@ group ""
|
||||
|
||||
include "NuakeNet/premake5.lua"
|
||||
include "EditorNet/premake5.lua"
|
||||
include "Nuake/src/Modules/Modules.lua"
|
||||
|
||||
project "Nuake"
|
||||
location "Nuake"
|
||||
@@ -47,6 +65,17 @@ project "Nuake"
|
||||
|
||||
language "C++"
|
||||
cppdialect "C++20"
|
||||
|
||||
local moduleSources = {}
|
||||
|
||||
if _ACTION then
|
||||
local modulesDir = "Nuake/src/Modules"
|
||||
local outputFilePath = path.join(modulesDir, "Modules.cpp")
|
||||
|
||||
-- Load and generate the modules file
|
||||
local modules = loadModules(modulesDir)
|
||||
moduleSources = generateModulesFile(modules, outputFilePath, "Nuake/src/Modules")
|
||||
end
|
||||
|
||||
defines
|
||||
{
|
||||
@@ -59,10 +88,37 @@ project "Nuake"
|
||||
|
||||
files
|
||||
{
|
||||
-- Main Sources
|
||||
"%{prj.name}/Engine.h",
|
||||
"%{prj.name}/Engine.cpp",
|
||||
"%{prj.name}/src/**.h",
|
||||
"%{prj.name}/src/**.cpp",
|
||||
"%{prj.name}/src/*.h",
|
||||
"%{prj.name}/src/*.cpp",
|
||||
"%{prj.name}/src/AI/**.h",
|
||||
"%{prj.name}/src/AI/**.cpp",
|
||||
"%{prj.name}/src/Application/**.h",
|
||||
"%{prj.name}/src/Application/**.cpp",
|
||||
"%{prj.name}/src/Audio/**.h",
|
||||
"%{prj.name}/src/Audio/**.cpp",
|
||||
"%{prj.name}/src/Core/**.h",
|
||||
"%{prj.name}/src/Core/**.cpp",
|
||||
"%{prj.name}/src/Physics/**.h",
|
||||
"%{prj.name}/src/Physics/**.cpp",
|
||||
"%{prj.name}/src/Rendering/**.h",
|
||||
"%{prj.name}/src/Rendering/**.cpp",
|
||||
"%{prj.name}/src/Resource/**.h",
|
||||
"%{prj.name}/src/Resource/**.cpp",
|
||||
"%{prj.name}/src/Scene/**.h",
|
||||
"%{prj.name}/src/Scene/**.cpp",
|
||||
"%{prj.name}/src/Scripting/**.h",
|
||||
"%{prj.name}/src/Scripting/**.cpp",
|
||||
"%{prj.name}/src/Threading/**.h",
|
||||
"%{prj.name}/src/Threading/**.cpp",
|
||||
"%{prj.name}/src/UI/**.h",
|
||||
"%{prj.name}/src/UI/**.cpp",
|
||||
"%{prj.name}/src/Vendors/**.h",
|
||||
"%{prj.name}/src/Vendors/**.cpp",
|
||||
|
||||
-- Vendor Sources
|
||||
"%{prj.name}/src/Vendors/libmap/h/*.h",
|
||||
"%{prj.name}/src/Vendors/libmap/c/*.c",
|
||||
"%{prj.name}/src/Vendors/wren/src/vm/*.h",
|
||||
@@ -71,7 +127,12 @@ project "Nuake"
|
||||
"%{prj.name}/src/Vendors/katana-parser/*.c",
|
||||
"%{prj.name}/src/Vendors/incbin/*.c",
|
||||
"%{prj.name}/src/Vendors/incbin/*.h",
|
||||
"%{prj.name}/src/Vendors/filewatch/*.hpp"
|
||||
"%{prj.name}/src/Vendors/filewatch/*.hpp",
|
||||
|
||||
-- Modules System
|
||||
"%{prj.name}/src/Modules/Modules.h",
|
||||
"%{prj.name}/src/Modules/Modules.cpp",
|
||||
table.unpack(moduleSources)
|
||||
}
|
||||
|
||||
includedirs
|
||||
@@ -93,7 +154,7 @@ project "Nuake"
|
||||
"%{prj.name}/dependencies/recastnavigation/DetourTileCache/Include",
|
||||
"%{prj.name}/dependencies/recastnavigation/Recast/Include"
|
||||
}
|
||||
|
||||
|
||||
links
|
||||
{
|
||||
"soloud"
|
||||
|
||||
Reference in New Issue
Block a user