refactor: dir structure & fix asset baker/parser compilation
This commit is contained in:
parent
2c3b2a57ff
commit
83f27e12c0
13 changed files with 116 additions and 440 deletions
|
@ -17,6 +17,8 @@ find_package(stb REQUIRED)
|
||||||
find_package(yaml-cpp REQUIRED)
|
find_package(yaml-cpp REQUIRED)
|
||||||
find_package(EnTT REQUIRED)
|
find_package(EnTT REQUIRED)
|
||||||
find_package(opengl_system REQUIRED)
|
find_package(opengl_system REQUIRED)
|
||||||
|
find_package(nlohmann_json REQUIRED)
|
||||||
|
find_package(lz4 REQUIRED)
|
||||||
|
|
||||||
add_subdirectory(./modules)
|
add_subdirectory(./modules)
|
||||||
add_subdirectory(./external)
|
add_subdirectory(./external)
|
||||||
|
|
|
@ -26,6 +26,8 @@ class LightRecipe(ConanFile):
|
||||||
self.requires("stb/cci.20240531")
|
self.requires("stb/cci.20240531")
|
||||||
self.requires("volk/1.3.296.0")
|
self.requires("volk/1.3.296.0")
|
||||||
self.requires("yaml-cpp/0.8.0")
|
self.requires("yaml-cpp/0.8.0")
|
||||||
|
self.requires("nlohmann_json/3.12.0")
|
||||||
|
self.requires("lz4/1.10.0")
|
||||||
|
|
||||||
def layout(self):
|
def layout(self):
|
||||||
cmake_layout(self)
|
cmake_layout(self)
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
|
add_subdirectory(./asset_baker)
|
||||||
|
add_subdirectory(./asset_parser)
|
||||||
|
|
||||||
add_subdirectory(./engine)
|
add_subdirectory(./engine)
|
||||||
add_subdirectory(./mirror)
|
add_subdirectory(./mirror)
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,9 @@
|
||||||
add_executable(
|
add_executable_module(
|
||||||
AssetBaker
|
asset_baker baker.cpp
|
||||||
|
|
||||||
${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/
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
AssetBaker
|
asset_baker
|
||||||
PRIVATE ${CONAN_LIBS}
|
PRIVATE asset_parser
|
||||||
PRIVATE AssetParser
|
PRIVATE stb::stb
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <AssetParser.hpp>
|
#include <asset_parser/assets/texture.hpp>
|
||||||
#include <TextureAsset.hpp>
|
#include <asset_parser/parser.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -21,20 +21,11 @@ void log(Args&&... args)
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool convert_image(
|
bool convert_image(const std::filesystem::path &input, const std::filesystem::path &output)
|
||||||
const std::filesystem::path& input,
|
|
||||||
const std::filesystem::path& output
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int width, height, channels;
|
int width, height, channels;
|
||||||
|
|
||||||
stbi_uc* pixels = stbi_load(
|
stbi_uc *pixels = stbi_load(input.string().c_str(), &width, &height, &channels, 4);
|
||||||
input.string().c_str(),
|
|
||||||
&width,
|
|
||||||
&height,
|
|
||||||
&channels,
|
|
||||||
4
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!pixels)
|
if (!pixels)
|
||||||
return false;
|
return false;
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
|
@ -1,16 +1,10 @@
|
||||||
add_library(AssetParser
|
add_library_module(asset_parser
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/AssetParser.cpp
|
parser.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/TextureAsset.cpp
|
assets/texture.cpp
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
AssetParser
|
|
||||||
PRIVATE ${CMAKE_SOURCE_DIR}/Vendor/nlohmann/single_include
|
|
||||||
PRIVATE ${CMAKE_SOURCE_DIR}/Vendor/lz4/lib/
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
AssetParser
|
asset_parser
|
||||||
PRIVATE lz4_static
|
PRIVATE LZ4::lz4_static
|
||||||
PRIVATE nlohmann_json::nlohmann_json
|
PRIVATE nlohmann_json::nlohmann_json
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AssetParser.hpp"
|
#include <asset_parser/parser.hpp>
|
||||||
|
|
||||||
namespace Assets {
|
namespace Assets {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "TextureAsset.hpp"
|
#include <asset_parser/assets/texture.hpp>
|
||||||
|
|
||||||
#include <lz4.h>
|
#include <lz4.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
56
modules/asset_parser/src/parser.cpp
Normal file
56
modules/asset_parser/src/parser.cpp
Normal 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
|
Loading…
Add table
Reference in a new issue