refactor: dir structure & fix asset baker/parser compilation

This commit is contained in:
light7734 2025-07-07 15:35:17 +03:30
parent 2c3b2a57ff
commit 83f27e12c0
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
13 changed files with 116 additions and 440 deletions

View file

@ -17,6 +17,8 @@ find_package(stb REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(EnTT REQUIRED)
find_package(opengl_system REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(lz4 REQUIRED)
add_subdirectory(./modules)
add_subdirectory(./external)

View file

@ -26,6 +26,8 @@ class LightRecipe(ConanFile):
self.requires("stb/cci.20240531")
self.requires("volk/1.3.296.0")
self.requires("yaml-cpp/0.8.0")
self.requires("nlohmann_json/3.12.0")
self.requires("lz4/1.10.0")
def layout(self):
cmake_layout(self)

View file

@ -1,2 +1,5 @@
add_subdirectory(./asset_baker)
add_subdirectory(./asset_parser)
add_subdirectory(./engine)
add_subdirectory(./mirror)

View file

@ -1,151 +0,0 @@
---
# Core
Language: Cpp
Standard: Cpp11
ColumnLimit: '80' # No limit
# Bin pack
BinPackArguments: 'false'
BinPackParameters: 'false'
# Includes
SortIncludes: 'true'
IncludeBlocks: Regroup
IncludeCategories:
# Current Project
- Regex: '"'
Priority: 001
# Custom Project Categories...
# Dependecies
- Regex: '<volk.h>'
Priority: 400
# Dependecies
- Regex: '<'
Priority: 500
# Custom Deependencies Categories...
# C++ includes
- Regex: '[^.h .hpp]>'
Priority: 998
# C includes
- Regex: '<[^/\n]+[.]h>'
Priority: 999
# Braces
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
# Indentation
UseTab: ForIndentation
TabWidth: '2'
IndentWidth: '2'
ContinuationIndentWidth: '2'
ConstructorInitializerIndentWidth: '2'
IndentCaseLabels: 'false'
IndentWrappedFunctionNames: 'true'
IndentPPDirectives: BeforeHash
NamespaceIndentation: None
AccessModifierOffset: '-2'
# Space
SpaceAfterCStyleCast: 'false'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'true'
SpaceBeforeCtorInitializerColon: 'false'
SpaceBeforeInheritanceColon: 'false'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'false'
SpacesBeforeTrailingComments: '1'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
# Alignment
PointerAlignment: Left
DerivePointerAlignment: 'false'
AlignEscapedNewlines: Left
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveDeclarations: 'false'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveMacros: 'true'
AlignOperands: 'true'
AlignTrailingComments: 'true'
# Single Line
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: 'false'
AllowShortLambdasOnASingleLine: Inline
AllowAllArgumentsOnNextLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AllowShortBlocksOnASingleLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortIfStatementsOnASingleLine: Never
# Break
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: 'false'
BreakInheritanceList: BeforeComma
BreakStringLiterals: 'false'
# Penalties
PenaltyBreakAssignment: '99999'
PenaltyBreakBeforeFirstCallParameter: '0'
PenaltyBreakComment: '0'
PenaltyBreakFirstLessLess: '0'
PenaltyBreakString: '0'
PenaltyBreakTemplateDeclaration: '0'
PenaltyExcessCharacter: '999999999'
PenaltyReturnTypeOnItsOwnLine: '999999999' # Nope
# Constructor Initializers
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
AllowAllConstructorInitializersOnNextLine: 'false'
BreakConstructorInitializers: BeforeComma
# Comments
ReflowComments: 'true'
CommentPragmas: '^ TODO@:'
FixNamespaceComments: 'true'
# Misc
Cpp11BracedListStyle: 'false'
SortUsingDeclarations: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
MaxEmptyLinesToKeep: '2'
ExperimentalAutoDetectBinPacking: false
AllowAllParametersOfDeclarationOnNextLine: false

View file

@ -1,22 +1,9 @@
add_executable(
AssetBaker
${CMAKE_CURRENT_SOURCE_DIR}/AssetBaker.cpp
)
set_target_properties(
AssetBaker PROPERTIES
CXX_STANDARD 20
)
target_include_directories(
AssetBaker
PRIVATE ${CMAKE_SOURCE_DIR}/AssetParser/
PRIVATE ${CMAKE_SOURCE_DIR}/Vendor/stb/
add_executable_module(
asset_baker baker.cpp
)
target_link_libraries(
AssetBaker
PRIVATE ${CONAN_LIBS}
PRIVATE AssetParser
asset_baker
PRIVATE asset_parser
PRIVATE stb::stb
)

View file

@ -1,40 +1,31 @@
#include <AssetParser.hpp>
#include <TextureAsset.hpp>
#include <asset_parser/assets/texture.hpp>
#include <asset_parser/parser.hpp>
#include <filesystem>
#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#define ASSERT(x, ...) \
if (!(x)) \
{ \
log(__VA_ARGS__); \
return -1; \
#define ASSERT(x, ...) \
if (!(x)) \
{ \
log(__VA_ARGS__); \
return -1; \
}
template<typename... Args>
void log(Args&&... args)
void log(Args &&...args)
{
(std::cout << ... << args);
std::cout << '\n';
}
bool convert_image(
const std::filesystem::path& input,
const std::filesystem::path& output
)
bool convert_image(const std::filesystem::path &input, const std::filesystem::path &output)
{
int width, height, channels;
stbi_uc* pixels = stbi_load(
input.string().c_str(),
&width,
&height,
&channels,
4
);
stbi_uc *pixels = stbi_load(input.string().c_str(), &width, &height, &channels, 4);
if (!pixels)
return false;
@ -59,16 +50,16 @@ bool convert_image(
return true;
}
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
std::ios_base::sync_with_stdio(false);
ASSERT(
argc == 3,
"Argc MUST be 3, 1: execution-path(implicit), 2: input-directory, 3: output-directory"
argc == 3,
"Argc MUST be 3, 1: execution-path(implicit), 2: input-directory, 3: output-directory"
);
for (auto& p : std::filesystem::directory_iterator(argv[1]))
for (auto &p : std::filesystem::directory_iterator(argv[1]))
{
if (p.path().extension() == ".png")
{

View file

@ -1,150 +0,0 @@
---
# Core
Language: Cpp
Standard: Cpp11
ColumnLimit: '80' # No limit
# Bin pack
BinPackArguments: 'false'
BinPackParameters: 'false'
# Includes
SortIncludes: 'true'
IncludeBlocks: Regroup
IncludeCategories:
# Current Project
- Regex: '"'
Priority: 001
# Custom Project Categories...
# Dependecies
- Regex: '<volk.h>'
Priority: 400
# Dependecies
- Regex: '<'
Priority: 500
# Custom Deependencies Categories...
# C++ includes
- Regex: '[^.h .hpp]>'
Priority: 998
# C includes
- Regex: '<[^/\n]+[.]h>'
Priority: 999
# Braces
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
# Indentation
UseTab: ForIndentation
TabWidth: '2'
IndentWidth: '2'
ContinuationIndentWidth: '2'
ConstructorInitializerIndentWidth: '2'
IndentCaseLabels: 'false'
IndentWrappedFunctionNames: 'true'
IndentPPDirectives: BeforeHash
NamespaceIndentation: None
AccessModifierOffset: '-2'
# Space
SpaceAfterCStyleCast: 'false'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'true'
SpaceBeforeCtorInitializerColon: 'false'
SpaceBeforeInheritanceColon: 'false'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'false'
SpacesBeforeTrailingComments: '1'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
# Alignment
PointerAlignment: Left
DerivePointerAlignment: 'false'
AlignEscapedNewlines: Left
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveDeclarations: 'false'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveMacros: 'true'
AlignOperands: 'true'
AlignTrailingComments: 'true'
# Single Line
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: 'false'
AllowShortLambdasOnASingleLine: Inline
AllowAllArgumentsOnNextLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AllowShortBlocksOnASingleLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortIfStatementsOnASingleLine: Never
# Break
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: 'false'
BreakInheritanceList: BeforeComma
BreakStringLiterals: 'false'
# Penalties
PenaltyBreakAssignment: '99999'
PenaltyBreakBeforeFirstCallParameter: '0'
PenaltyBreakComment: '0'
PenaltyBreakFirstLessLess: '0'
PenaltyBreakString: '0'
PenaltyBreakTemplateDeclaration: '0'
PenaltyExcessCharacter: '999999999'
PenaltyReturnTypeOnItsOwnLine: '999999999' # Nope
# Constructor Initializers
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
AllowAllConstructorInitializersOnNextLine: 'false'
BreakConstructorInitializers: BeforeComma
# Comments
ReflowComments: 'true'
CommentPragmas: '^ TODO@:'
FixNamespaceComments: 'true'
# Misc
Cpp11BracedListStyle: 'false'
SortUsingDeclarations: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
MaxEmptyLinesToKeep: '2'
ExperimentalAutoDetectBinPacking: false
AllowAllParametersOfDeclarationOnNextLine: false

View file

@ -1,57 +0,0 @@
#include "AssetParser.hpp"
#include <fstream>
#include <istream>
#include <ostream>
namespace Assets {
bool save_binary_file(const char* path, const AssetFile& file)
{
std::ofstream outstream(path, std::ios::binary | std::ios::out);
outstream.write((const char*)&file.version, sizeof(uint32_t));
outstream.write((const char*)&file.type, sizeof(AssetFile::Type));
uint32_t json_size = file.json.size();
uint32_t blob_size = file.blob.size();
outstream.write((const char*)&json_size, sizeof(uint32_t));
outstream.write((const char*)&blob_size, sizeof(uint32_t));
outstream.write(file.json.c_str(), json_size);
outstream.write((const char*)file.blob.data(), blob_size);
outstream.close();
outstream.close();
return true;
}
bool load_binary_file(const char* path, AssetFile& out_file)
{
std::ifstream instream(path, std::ios::binary);
instream.seekg(0ull);
if (!instream.is_open())
return false;
instream.read((char*)&out_file.version, sizeof(uint32_t));
instream.read((char*)&out_file.type, sizeof(AssetFile::Type));
uint32_t json_size;
uint32_t blob_size;
instream.read((char*)&json_size, sizeof(uint32_t));
instream.read((char*)&blob_size, sizeof(uint32_t));
out_file.json.resize(json_size);
out_file.blob.resize(blob_size);
instream.read((char*)out_file.json.data(), json_size);
instream.read((char*)out_file.blob.data(), blob_size);
instream.close();
return true;
}
} // namespace Assets

View file

@ -1,16 +1,10 @@
add_library(AssetParser
${CMAKE_CURRENT_SOURCE_DIR}/AssetParser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TextureAsset.cpp
)
target_include_directories(
AssetParser
PRIVATE ${CMAKE_SOURCE_DIR}/Vendor/nlohmann/single_include
PRIVATE ${CMAKE_SOURCE_DIR}/Vendor/lz4/lib/
add_library_module(asset_parser
parser.cpp
assets/texture.cpp
)
target_link_libraries(
AssetParser
PRIVATE lz4_static
PRIVATE nlohmann_json::nlohmann_json
asset_parser
PRIVATE LZ4::lz4_static
PRIVATE nlohmann_json::nlohmann_json
)

View file

@ -1,6 +1,6 @@
#pragma once
#include "AssetParser.hpp"
#include <asset_parser/parser.hpp>
namespace Assets {
@ -19,15 +19,15 @@ struct TextureInfo
std::string original_file;
};
TextureInfo read_texture_info(AssetFile* file);
TextureInfo read_texture_info(AssetFile *file);
void unpack_texture(
TextureInfo* info,
const void* source_buffer,
size_t source_size,
void* destination
TextureInfo *info,
const void *source_buffer,
size_t source_size,
void *destination
);
AssetFile pack_texture(TextureInfo* info, void* pixel_data);
AssetFile pack_texture(TextureInfo *info, void *pixel_data);
} // namespace Assets

View file

@ -1,5 +1,4 @@
#include "TextureAsset.hpp"
#include <asset_parser/assets/texture.hpp>
#include <lz4.h>
#include <nlohmann/json.hpp>
@ -7,7 +6,7 @@ namespace Assets {
using namespace nlohmann;
TextureInfo read_texture_info(AssetFile* file)
TextureInfo read_texture_info(AssetFile *file)
{
json texture_meta_data = json::parse(file->json);
@ -25,19 +24,19 @@ TextureInfo read_texture_info(AssetFile* file)
}
void unpack_texture(
TextureInfo* info,
const void* source_buffer,
size_t source_size,
void* destination
TextureInfo *info,
const void *source_buffer,
size_t source_size,
void *destination
)
{
if (info->compression_mode == CompressionMode::LZ4)
{
LZ4_decompress_safe(
(const char*)source_buffer,
(char*)destination,
source_size,
info->size
(const char *)source_buffer,
(char *)destination,
source_size,
info->size
);
}
else
@ -46,27 +45,27 @@ void unpack_texture(
}
}
AssetFile pack_texture(TextureInfo* info, void* pixel_data)
AssetFile pack_texture(TextureInfo *info, void *pixel_data)
{
json metadata;
metadata["format"] = info->format;
metadata["width"] = info->pixel_size[0];
metadata["height"] = info->pixel_size[1];
metadata["bufferSize"] = info->size;
metadata["format"] = info->format;
metadata["width"] = info->pixel_size[0];
metadata["height"] = info->pixel_size[1];
metadata["bufferSize"] = info->size;
metadata["originalFile"] = info->original_file;
metadata["compression"] = CompressionMode::LZ4;
metadata["compression"] = CompressionMode::LZ4;
AssetFile file;
file.type = AssetFile::Type::Texture;
file.type = AssetFile::Type::Texture;
file.version = 1u;
const int compress_staging = LZ4_compressBound(info->size);
file.blob.resize(compress_staging);
const int compression_size = LZ4_compress_default(
(const char*)pixel_data,
(char*)file.blob.data(),
info->size,
compress_staging
(const char *)pixel_data,
(char *)file.blob.data(),
info->size,
compress_staging
);
file.blob.resize(compression_size);

View file

@ -0,0 +1,56 @@
#include <asset_parser/parser.hpp>
#include <fstream>
#include <istream>
#include <ostream>
namespace Assets {
bool save_binary_file(const char *path, const AssetFile &file)
{
std::ofstream outstream(path, std::ios::binary | std::ios::out);
outstream.write((const char *)&file.version, sizeof(uint32_t));
outstream.write((const char *)&file.type, sizeof(AssetFile::Type));
uint32_t json_size = file.json.size();
uint32_t blob_size = file.blob.size();
outstream.write((const char *)&json_size, sizeof(uint32_t));
outstream.write((const char *)&blob_size, sizeof(uint32_t));
outstream.write(file.json.c_str(), json_size);
outstream.write((const char *)file.blob.data(), blob_size);
outstream.close();
outstream.close();
return true;
}
bool load_binary_file(const char *path, AssetFile &out_file)
{
std::ifstream instream(path, std::ios::binary);
instream.seekg(0ull);
if (!instream.is_open())
return false;
instream.read((char *)&out_file.version, sizeof(uint32_t));
instream.read((char *)&out_file.type, sizeof(AssetFile::Type));
uint32_t json_size;
uint32_t blob_size;
instream.read((char *)&json_size, sizeof(uint32_t));
instream.read((char *)&blob_size, sizeof(uint32_t));
out_file.json.resize(json_size);
out_file.blob.resize(blob_size);
instream.read((char *)out_file.json.data(), json_size);
instream.read((char *)out_file.blob.data(), blob_size);
instream.close();
return true;
}
} // namespace Assets