Compare commits
21 Commits
a0f2b128d7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1846d42401 | ||
|
|
5c6ea6c485 | ||
|
|
92179df553 | ||
|
|
172d3ea720 | ||
|
|
2ccc5c364c | ||
|
|
e306a66956 | ||
|
|
4199582a52 | ||
|
|
2784d62ec9 | ||
|
|
d304c56898 | ||
|
|
8cc1719d1b | ||
|
|
cc2c36c75d | ||
|
|
cc91b8d3b9 | ||
|
|
841778fe2f | ||
|
|
467f471390 | ||
|
|
6a6ffb6779 | ||
|
|
c1f429e916 | ||
|
|
4d15cbcc2b | ||
|
|
8c3e8956ca | ||
|
|
a147ef411a | ||
|
|
a0a4f63847 | ||
|
|
e9f95d4d0f |
39
examples/Assets/main.cpp
Normal file
39
examples/Assets/main.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include <Nazara/Audio.hpp>
|
||||||
|
#include <Nazara/Core.hpp>
|
||||||
|
#include <Nazara/Platform.hpp>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
std::filesystem::path resourceDir = "assets";
|
||||||
|
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
||||||
|
resourceDir = "../.." / resourceDir;
|
||||||
|
|
||||||
|
Nz::Application<Nz::Audio> app(argc, argv);
|
||||||
|
|
||||||
|
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
|
||||||
|
auto& fs = app.AddComponent<Nz::FilesystemAppComponent>();
|
||||||
|
fs.Mount("game:/", resourceDir);
|
||||||
|
|
||||||
|
auto& catalog = app.AddComponent<Nz::AssetCatalogAppComponent>();
|
||||||
|
catalog.AddFolder("game:/");
|
||||||
|
|
||||||
|
// Load an asset from its path
|
||||||
|
Nz::Asset<Nz::Music> music = Nz::Asset<Nz::Music>::LoadFromFile("game:/examples/Audio/file_example_MP3_700KB.nzasset");
|
||||||
|
|
||||||
|
// or by its name
|
||||||
|
music = catalog.Load<Nz::Music>("file_example_MP3_700KB");
|
||||||
|
music->Play();
|
||||||
|
|
||||||
|
Nz::Asset<Nz::Sound> sound = catalog.Load<Nz::Sound>("examples/Audio/siren");
|
||||||
|
sound->Play();
|
||||||
|
|
||||||
|
app.AddUpdaterFunc([&]
|
||||||
|
{
|
||||||
|
if (!music->IsPlaying())
|
||||||
|
app.Quit();
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
});
|
||||||
|
|
||||||
|
return app.Run();
|
||||||
|
}
|
||||||
3
examples/Assets/xmake.lua
Normal file
3
examples/Assets/xmake.lua
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
target("Assets")
|
||||||
|
add_deps("NazaraGraphics", "NazaraAudio")
|
||||||
|
add_files("main.cpp")
|
||||||
@@ -25,6 +25,8 @@ namespace Nz
|
|||||||
class NAZARA_AUDIO_API Music final : public Resource, public SoundEmitter
|
class NAZARA_AUDIO_API Music final : public Resource, public SoundEmitter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Params = SoundStreamParams;
|
||||||
|
|
||||||
Music();
|
Music();
|
||||||
Music(AudioDevice& device);
|
Music(AudioDevice& device);
|
||||||
Music(const Music&) = delete;
|
Music(const Music&) = delete;
|
||||||
@@ -46,9 +48,9 @@ namespace Nz
|
|||||||
|
|
||||||
bool IsLooping() const override;
|
bool IsLooping() const override;
|
||||||
|
|
||||||
bool OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params = SoundStreamParams());
|
static std::shared_ptr<Music> OpenFromFile(const std::filesystem::path& filePath, const Params& params = Params());
|
||||||
bool OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams());
|
static std::shared_ptr<Music> OpenFromMemory(const void* data, std::size_t size, const Params& params = Params());
|
||||||
bool OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams());
|
static std::shared_ptr<Music> OpenFromStream(Stream& stream, const Params& params = Params());
|
||||||
|
|
||||||
void Pause() override;
|
void Pause() override;
|
||||||
void Play() override;
|
void Play() override;
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ namespace Nz
|
|||||||
class NAZARA_AUDIO_API Sound final : public SoundEmitter
|
class NAZARA_AUDIO_API Sound final : public SoundEmitter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Params = SoundBufferParams;
|
||||||
|
|
||||||
using SoundEmitter::SoundEmitter;
|
using SoundEmitter::SoundEmitter;
|
||||||
Sound();
|
Sound();
|
||||||
Sound(AudioDevice& audioDevice, std::shared_ptr<SoundBuffer> soundBuffer);
|
Sound(AudioDevice& audioDevice, std::shared_ptr<SoundBuffer> soundBuffer);
|
||||||
@@ -36,9 +38,9 @@ namespace Nz
|
|||||||
bool IsLooping() const override;
|
bool IsLooping() const override;
|
||||||
bool IsPlayable() const;
|
bool IsPlayable() const;
|
||||||
|
|
||||||
bool LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params = SoundBufferParams());
|
static std::shared_ptr<Sound> LoadFromFile(const std::filesystem::path& filePath, const Params& params = {});
|
||||||
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
|
static std::shared_ptr<Sound> LoadFromMemory(const void* data, std::size_t size, const Params& params = {});
|
||||||
bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
|
static std::shared_ptr<Sound> LoadFromStream(Stream& stream, const Params& params = {});
|
||||||
|
|
||||||
void Pause() override;
|
void Pause() override;
|
||||||
void Play() override;
|
void Play() override;
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ namespace Nz
|
|||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_AUDIO_API bool Serialize(SerializationContext& context, SoundBufferParams& params, TypeTag<SoundBufferParams>);
|
||||||
|
NAZARA_AUDIO_API bool Unserialize(SerializationContext& context, SoundBufferParams* params, TypeTag<SoundBufferParams>);
|
||||||
|
|
||||||
class AudioBuffer;
|
class AudioBuffer;
|
||||||
class AudioDevice;
|
class AudioDevice;
|
||||||
class Sound;
|
class Sound;
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ namespace Nz
|
|||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_AUDIO_API bool Serialize(SerializationContext& context, SoundStreamParams& params, TypeTag<SoundStreamParams>);
|
||||||
|
NAZARA_AUDIO_API bool Unserialize(SerializationContext& context, SoundStreamParams* params, TypeTag<SoundStreamParams>);
|
||||||
|
|
||||||
class Mutex;
|
class Mutex;
|
||||||
class SoundStream;
|
class SoundStream;
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,9 @@
|
|||||||
#include <Nazara/Core/ApplicationBase.hpp>
|
#include <Nazara/Core/ApplicationBase.hpp>
|
||||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||||
#include <Nazara/Core/ApplicationUpdater.hpp>
|
#include <Nazara/Core/ApplicationUpdater.hpp>
|
||||||
|
#include <Nazara/Core/Asset.hpp>
|
||||||
|
#include <Nazara/Core/AssetDescriptor.hpp>
|
||||||
|
#include <Nazara/Core/AssetCatalogAppComponent.hpp>
|
||||||
#include <Nazara/Core/Buffer.hpp>
|
#include <Nazara/Core/Buffer.hpp>
|
||||||
#include <Nazara/Core/BufferMapper.hpp>
|
#include <Nazara/Core/BufferMapper.hpp>
|
||||||
#include <Nazara/Core/ByteArray.hpp>
|
#include <Nazara/Core/ByteArray.hpp>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace Nz
|
|||||||
constexpr UInt64 typeHash = FNV1a64(TypeName<T>());
|
constexpr UInt64 typeHash = FNV1a64(TypeName<T>());
|
||||||
|
|
||||||
auto it = m_components.find(typeHash);
|
auto it = m_components.find(typeHash);
|
||||||
if (it != m_components.end())
|
if (it == m_components.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return static_cast<T*>(it->second.get());
|
return static_cast<T*>(it->second.get());
|
||||||
@@ -109,7 +109,7 @@ namespace Nz
|
|||||||
constexpr UInt64 typeHash = FNV1a64(TypeName<T>());
|
constexpr UInt64 typeHash = FNV1a64(TypeName<T>());
|
||||||
|
|
||||||
auto it = m_components.find(typeHash);
|
auto it = m_components.find(typeHash);
|
||||||
if (it != m_components.end())
|
if (it == m_components.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return static_cast<const T*>(it->second.get());
|
return static_cast<const T*>(it->second.get());
|
||||||
|
|||||||
29
include/Nazara/Core/Asset.hpp
Normal file
29
include/Nazara/Core/Asset.hpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Nazara/Core/AssetDescriptor.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template <typename TResource>
|
||||||
|
class Asset final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const std::shared_ptr<TResource>& Get() const { return m_resource; }
|
||||||
|
explicit operator bool() const noexcept { return !!m_resource; }
|
||||||
|
|
||||||
|
TResource& operator*() { return *m_resource.get(); }
|
||||||
|
const TResource& operator*() const { return *m_resource.get(); }
|
||||||
|
TResource* operator->() { return m_resource.get(); }
|
||||||
|
const TResource* operator->() const { return m_resource.get(); }
|
||||||
|
|
||||||
|
static Asset LoadFromFile(const std::filesystem::path& path);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
AssetDescriptor<TResource> m_descriptor;
|
||||||
|
std::shared_ptr<TResource> m_resource;
|
||||||
|
|
||||||
|
friend class AssetCatalog;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/Asset.inl>
|
||||||
60
include/Nazara/Core/Asset.inl
Normal file
60
include/Nazara/Core/Asset.inl
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include <Nazara/Core/ApplicationBase.hpp>
|
||||||
|
#include <Nazara/Core/FilesystemAppComponent.hpp>
|
||||||
|
#include <Nazara/Core/JsonSerialization.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template <typename TResource>
|
||||||
|
concept IsStreamingResource = requires(TResource)
|
||||||
|
{
|
||||||
|
{ TResource::OpenFromFile({}) } -> std::same_as<std::shared_ptr<TResource>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TResource>
|
||||||
|
Asset<TResource> Asset<TResource>::LoadFromFile(const std::filesystem::path& path)
|
||||||
|
{
|
||||||
|
Asset<TResource> asset;
|
||||||
|
|
||||||
|
FilesystemAppComponent* fs = ApplicationBase::Instance()->TryGetComponent<FilesystemAppComponent>();
|
||||||
|
if (fs) // first try using a FileSystem component to load the asset
|
||||||
|
{
|
||||||
|
auto json = fs->Load<JsonSerializationContext>(std::string_view(path.string()));
|
||||||
|
if (json)
|
||||||
|
{
|
||||||
|
if (!Unserialize(*json, "", &asset.m_descriptor))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
std::string filepath = asset.m_descriptor.path.string();
|
||||||
|
if constexpr (IsStreamingResource<TResource>)
|
||||||
|
{
|
||||||
|
asset.m_resource = fs->Open<TResource>(std::string_view(filepath), asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
asset.m_resource = fs->Load<TResource>(std::string_view(filepath), asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!asset) // if it fails, use the default loader
|
||||||
|
{
|
||||||
|
JsonSerializationContext json;
|
||||||
|
if (!json.Load(path))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (!Unserialize(json, "", &asset.m_descriptor))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if constexpr (IsStreamingResource<TResource>)
|
||||||
|
{
|
||||||
|
asset.m_resource = TResource::OpenFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
asset.m_resource = TResource::LoadFromFile(asset.m_descriptor.path, asset.m_descriptor.parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
include/Nazara/Core/AssetCatalogAppComponent.hpp
Normal file
45
include/Nazara/Core/AssetCatalogAppComponent.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Nazara/Core/Asset.hpp>
|
||||||
|
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||||
|
#include <Nazara/Core/Export.hpp>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
struct AssetHeaderLite
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::filesystem::path path;
|
||||||
|
|
||||||
|
friend auto operator<=>(const AssetHeaderLite& A, const AssetHeaderLite& B)
|
||||||
|
{
|
||||||
|
return A.name <=> B.name;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NAZARA_CORE_API bool Serialize(struct SerializationContext& context, const AssetHeaderLite& header, TypeTag<AssetHeaderLite>);
|
||||||
|
NAZARA_CORE_API bool Unserialize(struct SerializationContext& context, AssetHeaderLite* header, TypeTag<AssetHeaderLite>);
|
||||||
|
|
||||||
|
|
||||||
|
class NAZARA_CORE_API AssetCatalogAppComponent
|
||||||
|
: public ApplicationComponent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline AssetCatalogAppComponent(ApplicationBase& app);
|
||||||
|
AssetCatalogAppComponent(const AssetCatalogAppComponent&) = delete;
|
||||||
|
AssetCatalogAppComponent(AssetCatalogAppComponent&&) = delete;
|
||||||
|
~AssetCatalogAppComponent() = default;
|
||||||
|
|
||||||
|
void AddFolder(std::string_view folder);
|
||||||
|
|
||||||
|
template<typename TResource>
|
||||||
|
inline Asset<TResource> Load(std::string_view name) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::set<AssetHeaderLite> m_assets;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/AssetCatalogAppComponent.inl>
|
||||||
19
include/Nazara/Core/AssetCatalogAppComponent.inl
Normal file
19
include/Nazara/Core/AssetCatalogAppComponent.inl
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
inline AssetCatalogAppComponent::AssetCatalogAppComponent(ApplicationBase& app)
|
||||||
|
: ApplicationComponent(app)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TResource>
|
||||||
|
Asset<TResource> AssetCatalogAppComponent::Load(std::string_view name) const
|
||||||
|
{
|
||||||
|
AssetHeaderLite header{ std::string(name), "" };
|
||||||
|
auto it = m_assets.find(header);
|
||||||
|
if (it == m_assets.end())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return Asset<TResource>::LoadFromFile(it->path);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
include/Nazara/Core/AssetDescriptor.hpp
Normal file
24
include/Nazara/Core/AssetDescriptor.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Nazara/Core/Serialization.hpp>
|
||||||
|
#include <NazaraUtils/TypeName.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template <typename TResource>
|
||||||
|
struct AssetDescriptor
|
||||||
|
{
|
||||||
|
constexpr static std::string_view Type = TypeName<TResource>();
|
||||||
|
|
||||||
|
int version;
|
||||||
|
std::string type;
|
||||||
|
std::string name;
|
||||||
|
std::filesystem::path path;
|
||||||
|
TResource::Params parameters;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TResource> bool Serialize(SerializationContext& context, const AssetDescriptor<TResource>& descriptor, TypeTag<AssetDescriptor<TResource>>);
|
||||||
|
template <typename TResource> bool Unserialize(SerializationContext& context, AssetDescriptor<TResource>* descriptor, TypeTag<AssetDescriptor<TResource>>);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/AssetDescriptor.inl>
|
||||||
37
include/Nazara/Core/AssetDescriptor.inl
Normal file
37
include/Nazara/Core/AssetDescriptor.inl
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template <typename TResource>
|
||||||
|
bool Serialize(SerializationContext& context, const AssetDescriptor<TResource>& descriptor, TypeTag<AssetDescriptor<TResource>>)
|
||||||
|
{
|
||||||
|
Serialize(context, "version", descriptor.version);
|
||||||
|
Serialize(context, "type", descriptor.type);
|
||||||
|
Serialize(context, "name", descriptor.name);
|
||||||
|
Serialize(context, "path", descriptor.path);
|
||||||
|
Serialize(context, "parameters", descriptor.parameters);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TResource>
|
||||||
|
bool Unserialize(SerializationContext& context, AssetDescriptor<TResource>* descriptor, TypeTag<AssetDescriptor<TResource>>)
|
||||||
|
{
|
||||||
|
if (!Unserialize(context, "version", &descriptor->version))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Unserialize(context, "type", &descriptor->type))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (AssetDescriptor<TResource>::Type != descriptor->type)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Unserialize(context, "name", &descriptor->name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Unserialize(context, "path", &descriptor->path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Unserialize(context, "parameters", &descriptor->parameters))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ namespace Nz
|
|||||||
: public SerializationContext
|
: public SerializationContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
EnumSerializationMode GetEnumSerializationMode() const override { return EnumSerializationMode::Binary; }
|
||||||
|
|
||||||
bool PushObject(std::string_view name) override;
|
bool PushObject(std::string_view name) override;
|
||||||
bool PopObject() override;
|
bool PopObject() override;
|
||||||
bool PushArray(std::string_view name) override;
|
bool PushArray(std::string_view name) override;
|
||||||
|
|||||||
64
include/Nazara/Core/EnumSerialization.hpp
Normal file
64
include/Nazara/Core/EnumSerialization.hpp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Nazara/Core/Enums.hpp>
|
||||||
|
#include <Nazara/Core/Export.hpp>
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
concept Enum = std::is_enum_v<T>;
|
||||||
|
|
||||||
|
template <Enum TEnum> TEnum EnumFromString(std::string_view) { return TEnum{}; }
|
||||||
|
|
||||||
|
#define DEF_ENUM(Type) \
|
||||||
|
NAZARA_CORE_API std::string_view EnumToString(Type t); \
|
||||||
|
NAZARA_CORE_API Type EnumFromString_##Type(std::string_view); \
|
||||||
|
template<> inline Type EnumFromString(std::string_view v) { return EnumFromString_##Type(v); }
|
||||||
|
|
||||||
|
DEF_ENUM(AnimationType);
|
||||||
|
DEF_ENUM(BlendEquation);
|
||||||
|
DEF_ENUM(BlendFunc);
|
||||||
|
DEF_ENUM(BufferAccess);
|
||||||
|
DEF_ENUM(BufferType);
|
||||||
|
DEF_ENUM(BufferUsage);
|
||||||
|
DEF_ENUM(ComponentType);
|
||||||
|
DEF_ENUM(CoordSys);
|
||||||
|
DEF_ENUM(CursorPosition);
|
||||||
|
DEF_ENUM(CubemapFace);
|
||||||
|
DEF_ENUM(DataStorage);
|
||||||
|
DEF_ENUM(ErrorMode);
|
||||||
|
DEF_ENUM(ErrorType);
|
||||||
|
DEF_ENUM(FaceFilling);
|
||||||
|
DEF_ENUM(FaceCulling);
|
||||||
|
DEF_ENUM(FrontFace);
|
||||||
|
DEF_ENUM(ImageType);
|
||||||
|
DEF_ENUM(IndexType);
|
||||||
|
DEF_ENUM(HashType);
|
||||||
|
DEF_ENUM(OpenMode);
|
||||||
|
DEF_ENUM(ParameterType);
|
||||||
|
DEF_ENUM(PixelFormatContent);
|
||||||
|
DEF_ENUM(PixelFormat);
|
||||||
|
DEF_ENUM(PixelFormatSubType);
|
||||||
|
DEF_ENUM(PixelFlipping);
|
||||||
|
DEF_ENUM(PrimitiveMode);
|
||||||
|
DEF_ENUM(PrimitiveType);
|
||||||
|
DEF_ENUM(ProcessorCap);
|
||||||
|
DEF_ENUM(ProcessorVendor);
|
||||||
|
DEF_ENUM(RendererComparison);
|
||||||
|
DEF_ENUM(ResourceLoadingError);
|
||||||
|
DEF_ENUM(SamplerFilter);
|
||||||
|
DEF_ENUM(SamplerMipmapMode);
|
||||||
|
DEF_ENUM(SamplerWrap);
|
||||||
|
DEF_ENUM(SphereType);
|
||||||
|
DEF_ENUM(StencilOperation);
|
||||||
|
DEF_ENUM(StreamOption);
|
||||||
|
DEF_ENUM(TextAlign);
|
||||||
|
DEF_ENUM(TextStyle);
|
||||||
|
DEF_ENUM(VertexComponent);
|
||||||
|
DEF_ENUM(VertexInputRate);
|
||||||
|
DEF_ENUM(VertexLayout);
|
||||||
|
|
||||||
|
#undef DEF_ENUM
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <Nazara/Core/ResourceManager.hpp>
|
#include <Nazara/Core/ResourceManager.hpp>
|
||||||
#include <Nazara/Core/ResourceParameters.hpp>
|
#include <Nazara/Core/ResourceParameters.hpp>
|
||||||
#include <Nazara/Core/ResourceSaver.hpp>
|
#include <Nazara/Core/ResourceSaver.hpp>
|
||||||
|
#include <Nazara/Core/Serialization.hpp>
|
||||||
#include <NazaraUtils/MovablePtr.hpp>
|
#include <NazaraUtils/MovablePtr.hpp>
|
||||||
#include <NazaraUtils/Signal.hpp>
|
#include <NazaraUtils/Signal.hpp>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@@ -37,6 +38,9 @@ namespace Nz
|
|||||||
void Merge(const ImageParams& params);
|
void Merge(const ImageParams& params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_CORE_API bool Serialize(SerializationContext& context, ImageParams& params, TypeTag<ImageParams>);
|
||||||
|
NAZARA_CORE_API bool Unserialize(SerializationContext& context, ImageParams* params, TypeTag<ImageParams>);
|
||||||
|
|
||||||
class Image;
|
class Image;
|
||||||
|
|
||||||
using ImageLibrary = ObjectLibrary<Image>;
|
using ImageLibrary = ObjectLibrary<Image>;
|
||||||
|
|||||||
58
include/Nazara/Core/JsonSerialization.hpp
Normal file
58
include/Nazara/Core/JsonSerialization.hpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Nazara/Core/Export.hpp>
|
||||||
|
#include <Nazara/Core/Serialization.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class NAZARA_CORE_API JsonSerializationContext
|
||||||
|
: public SerializationContext
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct Params {};
|
||||||
|
|
||||||
|
JsonSerializationContext();
|
||||||
|
~JsonSerializationContext();
|
||||||
|
|
||||||
|
bool Load(const std::filesystem::path& path);
|
||||||
|
bool Load(Stream& stream);
|
||||||
|
|
||||||
|
EnumSerializationMode GetEnumSerializationMode() const override { return EnumSerializationMode::String; }
|
||||||
|
bool PushObject(std::string_view name) override;
|
||||||
|
bool PopObject() override;
|
||||||
|
bool PushArray(std::string_view name) override;
|
||||||
|
bool PopArray() override;
|
||||||
|
|
||||||
|
bool Write(std::string_view name, bool value) override;
|
||||||
|
bool Write(std::string_view name, Nz::Int8 value) override;
|
||||||
|
bool Write(std::string_view name, Nz::Int16 value) override;
|
||||||
|
bool Write(std::string_view name, Nz::Int32 value) override;
|
||||||
|
bool Write(std::string_view name, Nz::Int64 value) override;
|
||||||
|
bool Write(std::string_view name, Nz::UInt8 value) override;
|
||||||
|
bool Write(std::string_view name, Nz::UInt16 value) override;
|
||||||
|
bool Write(std::string_view name, Nz::UInt32 value) override;
|
||||||
|
bool Write(std::string_view name, Nz::UInt64 value) override;
|
||||||
|
bool Write(std::string_view name, float value) override;
|
||||||
|
bool Write(std::string_view name, double value) override;
|
||||||
|
bool Write(std::string_view name, const std::string& value) override;
|
||||||
|
|
||||||
|
bool Read(std::string_view name, bool* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::Int8* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::Int16* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::Int32* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::Int64* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::UInt8* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::UInt16* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::UInt32* value) override;
|
||||||
|
bool Read(std::string_view name, Nz::UInt64* value) override;
|
||||||
|
bool Read(std::string_view name, float* value) override;
|
||||||
|
bool Read(std::string_view name, double* value) override;
|
||||||
|
bool Read(std::string_view name, std::string* value) override;
|
||||||
|
|
||||||
|
static std::shared_ptr<JsonSerializationContext> LoadFromStream(Stream& stream, const Params& params = {});
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<struct JsonImpl> m_impl;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
struct SerializationContext;
|
||||||
|
|
||||||
struct NAZARA_CORE_API MeshParams : ResourceParameters
|
struct NAZARA_CORE_API MeshParams : ResourceParameters
|
||||||
{
|
{
|
||||||
// How buffer will be allocated (by default in RAM)
|
// How buffer will be allocated (by default in RAM)
|
||||||
@@ -74,6 +76,9 @@ namespace Nz
|
|||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_CORE_API bool Serialize(SerializationContext& context, const MeshParams& params, TypeTag<MeshParams>);
|
||||||
|
NAZARA_CORE_API bool Unserialize(SerializationContext& context, MeshParams* params, TypeTag<MeshParams>);
|
||||||
|
|
||||||
class Mesh;
|
class Mesh;
|
||||||
struct Primitive;
|
struct Primitive;
|
||||||
class PrimitiveList;
|
class PrimitiveList;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define NAZARA_CORE_RESOURCEPARAMETERS_HPP
|
#define NAZARA_CORE_RESOURCEPARAMETERS_HPP
|
||||||
|
|
||||||
#include <Nazara/Core/ParameterList.hpp>
|
#include <Nazara/Core/ParameterList.hpp>
|
||||||
|
#include <Nazara/Core/Serialization.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,9 @@ namespace Nz
|
|||||||
|
|
||||||
ParameterList custom;
|
ParameterList custom;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_CORE_API bool Serialize(SerializationContext& context, ResourceParameters& params, TypeTag<ResourceParameters>);
|
||||||
|
NAZARA_CORE_API bool Unserialize(SerializationContext& context, ResourceParameters* params, TypeTag<ResourceParameters>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NAZARA_CORE_RESOURCEPARAMETERS_HPP
|
#endif // NAZARA_CORE_RESOURCEPARAMETERS_HPP
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define NAZARA_CORE_SERIALIZATION_HPP
|
#define NAZARA_CORE_SERIALIZATION_HPP
|
||||||
|
|
||||||
#include <NazaraUtils/Prerequisites.hpp>
|
#include <NazaraUtils/Prerequisites.hpp>
|
||||||
|
#include <Nazara/Core/EnumSerialization.hpp>
|
||||||
#include <Nazara/Core/Export.hpp>
|
#include <Nazara/Core/Export.hpp>
|
||||||
#include <Nazara/Core/Stream.hpp>
|
#include <Nazara/Core/Stream.hpp>
|
||||||
#include <NazaraUtils/Endianness.hpp>
|
#include <NazaraUtils/Endianness.hpp>
|
||||||
@@ -21,9 +22,17 @@ namespace Nz
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
concept Numeric = std::is_arithmetic<T>::value;
|
concept Numeric = std::is_arithmetic<T>::value;
|
||||||
|
|
||||||
|
enum class EnumSerializationMode
|
||||||
|
{
|
||||||
|
Binary,
|
||||||
|
String,
|
||||||
|
};
|
||||||
|
|
||||||
struct NAZARA_CORE_API SerializationContext
|
struct NAZARA_CORE_API SerializationContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual EnumSerializationMode GetEnumSerializationMode() const = 0;
|
||||||
|
|
||||||
virtual bool PushObject(std::string_view name) = 0;
|
virtual bool PushObject(std::string_view name) = 0;
|
||||||
virtual bool PopObject() = 0;
|
virtual bool PopObject() = 0;
|
||||||
virtual bool PushArray(std::string_view name) = 0;
|
virtual bool PushArray(std::string_view name) = 0;
|
||||||
@@ -67,6 +76,7 @@ namespace Nz
|
|||||||
|
|
||||||
inline bool Serialize(SerializationContext& context, std::string_view name, const bool& value, TypeTag<bool>);
|
inline bool Serialize(SerializationContext& context, std::string_view name, const bool& value, TypeTag<bool>);
|
||||||
inline bool Serialize(SerializationContext& context, std::string_view name, const std::string& value, TypeTag<std::string>);
|
inline bool Serialize(SerializationContext& context, std::string_view name, const std::string& value, TypeTag<std::string>);
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const std::filesystem::path& value, TypeTag<std::filesystem::path>);
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Serialize(SerializationContext& context, std::string_view name, const T (&values)[N]);
|
bool Serialize(SerializationContext& context, std::string_view name, const T (&values)[N]);
|
||||||
@@ -83,6 +93,12 @@ namespace Nz
|
|||||||
template<Numeric T>
|
template<Numeric T>
|
||||||
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>);
|
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>);
|
||||||
|
|
||||||
|
template<Enum T>
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const Flags<T>& flags, TypeTag<Flags<T>>);
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool Unserialize(SerializationContext&, T*, TypeTag<T>) { return false; }
|
inline bool Unserialize(SerializationContext&, T*, TypeTag<T>) { return false; }
|
||||||
@@ -93,11 +109,9 @@ namespace Nz
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
||||||
|
|
||||||
template <>
|
|
||||||
inline bool Unserialize(SerializationContext& context, std::string_view name, bool* value, TypeTag<bool>);
|
inline bool Unserialize(SerializationContext& context, std::string_view name, bool* value, TypeTag<bool>);
|
||||||
|
|
||||||
template <>
|
|
||||||
inline bool Unserialize(SerializationContext& context, std::string_view name, std::string* value, TypeTag<std::string>);
|
inline bool Unserialize(SerializationContext& context, std::string_view name, std::string* value, TypeTag<std::string>);
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, std::filesystem::path* value, TypeTag<std::filesystem::path>);
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Unserialize(SerializationContext& context, std::string_view name, T (*values)[N]);
|
bool Unserialize(SerializationContext& context, std::string_view name, T (*values)[N]);
|
||||||
@@ -113,6 +127,12 @@ namespace Nz
|
|||||||
|
|
||||||
template<Numeric T>
|
template<Numeric T>
|
||||||
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
||||||
|
|
||||||
|
template<Enum T>
|
||||||
|
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, Flags<T>* flags, TypeTag<Flags<T>>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Core/Serialization.inl>
|
#include <Nazara/Core/Serialization.inl>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Export.hpp
|
// For conditions of distribution and use, see copyright notice in Export.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/EnumSerialization.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
@@ -17,10 +18,10 @@ namespace Nz
|
|||||||
if (!context.PushObject(name))
|
if (!context.PushObject(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Serialize(context, value, TypeTag<std::decay_t<T>>()))
|
bool bRes = Serialize(context, value, TypeTag<std::decay_t<T>>());
|
||||||
return false;
|
|
||||||
|
|
||||||
return context.PopObject();
|
context.PopObject();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -51,19 +52,27 @@ namespace Nz
|
|||||||
return context.Write(name, value);
|
return context.Write(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const std::filesystem::path& value, TypeTag<std::filesystem::path>)
|
||||||
|
{
|
||||||
|
std::string str = value.string();
|
||||||
|
return context.Write(name, str);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Serialize(SerializationContext& context, std::string_view name, const T(&values)[N])
|
bool Serialize(SerializationContext& context, std::string_view name, const T(&values)[N])
|
||||||
{
|
{
|
||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (size_t i = 0; i < N; ++i)
|
for (size_t i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
if (!Serialize(context, "", values[i]))
|
if (!Serialize(context, "", values[i]))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
@@ -72,13 +81,15 @@ namespace Nz
|
|||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (auto&& value : values)
|
for (auto&& value : values)
|
||||||
{
|
{
|
||||||
if (!Serialize(context, "", value))
|
if (!Serialize(context, "", value))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -87,13 +98,15 @@ namespace Nz
|
|||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (auto&& value : values)
|
for (auto&& value : values)
|
||||||
{
|
{
|
||||||
if (!Serialize(context, "", value))
|
if (!Serialize(context, "", value))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename E, typename T>
|
template<typename E, typename T>
|
||||||
@@ -102,13 +115,15 @@ namespace Nz
|
|||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (auto&& value : values)
|
for (auto&& value : values)
|
||||||
{
|
{
|
||||||
if (!Serialize(context, "", value))
|
if (!Serialize(context, "", value))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -127,6 +142,19 @@ namespace Nz
|
|||||||
return context.Write(name, value);
|
return context.Write(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<Enum T>
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>)
|
||||||
|
{
|
||||||
|
switch (context.GetEnumSerializationMode())
|
||||||
|
{
|
||||||
|
case EnumSerializationMode::Binary:
|
||||||
|
return Serialize(context, name, std::underlying_type_t<T>(value), TypeTag<std::decay_t<std::underlying_type_t<T>>>());
|
||||||
|
case EnumSerializationMode::String:
|
||||||
|
return Serialize(context, name, std::string(EnumToString(value)), TypeTag<std::string>());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value)
|
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value)
|
||||||
@@ -140,10 +168,10 @@ namespace Nz
|
|||||||
if (!context.PushObject(name))
|
if (!context.PushObject(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Unserialize(context, value, TypeTag<T>()))
|
bool bRes = Unserialize(context, value, TypeTag<T>());
|
||||||
return false;
|
|
||||||
|
|
||||||
return context.PopObject();
|
context.PopObject();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -173,19 +201,31 @@ namespace Nz
|
|||||||
return context.Read(name, string);
|
return context.Read(name, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, std::filesystem::path* value, TypeTag<std::filesystem::path>)
|
||||||
|
{
|
||||||
|
std::string str;
|
||||||
|
if (!context.Read(name, &str))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*value = str;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Unserialize(SerializationContext& context, std::string_view name, T(*values)[N])
|
bool Unserialize(SerializationContext& context, std::string_view name, T(*values)[N])
|
||||||
{
|
{
|
||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (size_t i = 0; i < N; ++i)
|
for (size_t i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
if (!Unserialize(context, "", &(*values[i])))
|
if (!Unserialize(context, "", &(*values[i])))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
@@ -194,13 +234,15 @@ namespace Nz
|
|||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (auto&& value : *values)
|
for (auto&& value : *values)
|
||||||
{
|
{
|
||||||
if (!Unserialize(context, "", &value))
|
if (!Unserialize(context, "", &value))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -209,13 +251,15 @@ namespace Nz
|
|||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (auto&& value : *values)
|
for (auto&& value : *values)
|
||||||
{
|
{
|
||||||
if (!Unserialize(context, "", &value))
|
if (!Unserialize(context, "", &value))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename E, typename T>
|
template<typename E, typename T>
|
||||||
@@ -224,13 +268,15 @@ namespace Nz
|
|||||||
if (!context.PushArray(name))
|
if (!context.PushArray(name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool bRes = true;
|
||||||
for (auto&& value : *values)
|
for (auto&& value : *values)
|
||||||
{
|
{
|
||||||
if (!Unserialize(context, "", &value))
|
if (!Unserialize(context, "", &value))
|
||||||
return false;
|
bRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.PopArray();
|
context.PopArray();
|
||||||
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -250,5 +296,47 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
return context.Read(name, value);
|
return context.Read(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<Enum T>
|
||||||
|
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>)
|
||||||
|
{
|
||||||
|
switch (context.GetEnumSerializationMode())
|
||||||
|
{
|
||||||
|
case EnumSerializationMode::Binary:
|
||||||
|
{
|
||||||
|
std::underlying_type_t<T> v = 0;
|
||||||
|
if (!Unserialize(context, name, &v, TypeTag<std::decay_t<std::underlying_type_t<T>>>()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*value = static_cast<T>(v);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case EnumSerializationMode::String:
|
||||||
|
{
|
||||||
|
std::string str;
|
||||||
|
if (!Unserialize(context, name, &str, TypeTag<std::string>()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*value = EnumFromString<T>(str);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const Flags<T>& flags, TypeTag<Flags<T>>)
|
||||||
|
{
|
||||||
|
return Serialize(context, name, static_cast<typename Flags<T>::BitField>(flags), TypeTag<std::decay_t<typename Flags<T>::BitField>>());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, Flags<T>* flags, TypeTag<Flags<T>>)
|
||||||
|
{
|
||||||
|
typename Flags<T>::BitField v;
|
||||||
|
if (Unserialize(context, name, &v, TypeTag<std::decay_t<typename Flags<T>::BitField>>()))
|
||||||
|
*flags = v;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace Nz
|
|||||||
VertexDeclaration& operator=(VertexDeclaration&&) = delete;
|
VertexDeclaration& operator=(VertexDeclaration&&) = delete;
|
||||||
|
|
||||||
static inline const std::shared_ptr<VertexDeclaration>& Get(VertexLayout layout);
|
static inline const std::shared_ptr<VertexDeclaration>& Get(VertexLayout layout);
|
||||||
|
static inline const VertexLayout Find(const std::shared_ptr<VertexDeclaration>& declaration);
|
||||||
static bool IsTypeSupported(ComponentType type);
|
static bool IsTypeSupported(ComponentType type);
|
||||||
|
|
||||||
struct Component
|
struct Component
|
||||||
|
|||||||
@@ -75,5 +75,15 @@ namespace Nz
|
|||||||
NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum");
|
NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum");
|
||||||
return s_declarations[layout];
|
return s_declarations[layout];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const VertexLayout VertexDeclaration::Find(const std::shared_ptr<VertexDeclaration>& declaration)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < (size_t)VertexLayout::Max; ++i)
|
||||||
|
if (s_declarations[(VertexLayout)i].get() == declaration.get())
|
||||||
|
return (VertexLayout)i;
|
||||||
|
|
||||||
|
NazaraAssert(declaration, "Invalid declaration");
|
||||||
|
return VertexLayout::Max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace Nz
|
|||||||
|
|
||||||
inline bool Exists(std::string_view path);
|
inline bool Exists(std::string_view path);
|
||||||
|
|
||||||
template<typename F> void Foreach(F&& callback, bool includeDots = false);
|
template<typename F> bool Foreach(F&& callback, bool recursive = false, bool includeDots = false);
|
||||||
|
|
||||||
template<typename F> bool GetDirectoryEntry(std::string_view path, F&& callback);
|
template<typename F> bool GetDirectoryEntry(std::string_view path, F&& callback);
|
||||||
template<typename F> bool GetEntry(std::string_view path, F&& callback);
|
template<typename F> bool GetEntry(std::string_view path, F&& callback);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
void VirtualDirectory::Foreach(F&& callback, bool includeDots)
|
bool VirtualDirectory::Foreach(F&& callback, bool recursive, bool includeDots)
|
||||||
{
|
{
|
||||||
if (includeDots)
|
if (includeDots)
|
||||||
{
|
{
|
||||||
@@ -46,16 +46,26 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
Entry parentEntry = DirectoryEntry{ { parent } };
|
Entry parentEntry = DirectoryEntry{ { parent } };
|
||||||
if (!CallbackReturn(callback, std::string_view(".."), parentEntry))
|
if (!CallbackReturn(callback, std::string_view(".."), parentEntry))
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
else if (!CallbackReturn(callback, std::string_view(".."), ourselves))
|
else if (!CallbackReturn(callback, std::string_view(".."), ourselves))
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto&& entry : m_content)
|
for (auto&& entry : m_content)
|
||||||
{
|
{
|
||||||
if (!CallbackReturn(callback, std::string_view(entry.name), std::as_const(entry.entry)))
|
if (!CallbackReturn(callback, std::string_view(entry.name), std::as_const(entry.entry)))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
|
if (recursive)
|
||||||
|
{
|
||||||
|
if (std::holds_alternative<DirectoryEntry>(entry.entry))
|
||||||
|
{
|
||||||
|
DirectoryEntry& child = std::get<DirectoryEntry>(entry.entry);
|
||||||
|
if (!child.directory->Foreach(callback, recursive, includeDots))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_resolver)
|
if (m_resolver)
|
||||||
@@ -70,9 +80,22 @@ namespace Nz
|
|||||||
if (it != m_content.end() && it->name == filename)
|
if (it != m_content.end() && it->name == filename)
|
||||||
return true; //< this was already returned
|
return true; //< this was already returned
|
||||||
|
|
||||||
return CallbackReturn(callback, filename, std::move(entry));
|
if (!CallbackReturn(callback, filename, entry))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (recursive)
|
||||||
|
{
|
||||||
|
if (std::holds_alternative<DirectoryEntry>(entry))
|
||||||
|
{
|
||||||
|
DirectoryEntry& child = std::get<DirectoryEntry>(entry);
|
||||||
|
if (!child.directory->Foreach(callback, recursive, includeDots))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
|
|||||||
@@ -294,13 +294,13 @@ namespace Nz
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool Serialize(SerializationContext& context, const EulerAngles<T>& angles, TypeTag<EulerAngles<T>>)
|
bool Serialize(SerializationContext& context, const EulerAngles<T>& angles, TypeTag<EulerAngles<T>>)
|
||||||
{
|
{
|
||||||
if (!Serialize(context, "pitch", angles.pitch))
|
if (!Serialize(context, "pitch", angles.pitch.value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Serialize(context, "yaw", angles.yaw))
|
if (!Serialize(context, "yaw", angles.yaw.value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Serialize(context, "roll", angles.roll))
|
if (!Serialize(context, "roll", angles.roll.value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -316,13 +316,13 @@ namespace Nz
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool Unserialize(SerializationContext& context, EulerAngles<T>* angles, TypeTag<EulerAngles<T>>)
|
bool Unserialize(SerializationContext& context, EulerAngles<T>* angles, TypeTag<EulerAngles<T>>)
|
||||||
{
|
{
|
||||||
if (!Unserialize(context, "pitch", &angles->pitch))
|
if (!Unserialize(context, "pitch", &angles->pitch.value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Unserialize(context, "yaw", &angles->yaw))
|
if (!Unserialize(context, "yaw", &angles->yaw.value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Unserialize(context, "roll", &angles->roll))
|
if (!Unserialize(context, "roll", &angles->roll.value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/ResourceManager.hpp>
|
#include <Nazara/Core/ResourceManager.hpp>
|
||||||
|
#include <Nazara/Core/Serialization.hpp>
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
#include <Nazara/Renderer/Export.hpp>
|
#include <Nazara/Renderer/Export.hpp>
|
||||||
@@ -53,6 +54,9 @@ namespace Nz
|
|||||||
void Merge(const TextureParams& params);
|
void Merge(const TextureParams& params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_RENDERER_API bool Serialize(SerializationContext& context, TextureParams& params, TypeTag<TextureParams>);
|
||||||
|
NAZARA_RENDERER_API bool Unserialize(SerializationContext& context, TextureParams* params, TypeTag<TextureParams>);
|
||||||
|
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
using TextureLibrary = ObjectLibrary<Texture>;
|
using TextureLibrary = ObjectLibrary<Texture>;
|
||||||
|
|||||||
@@ -240,12 +240,17 @@ namespace Nz
|
|||||||
* \param filePath Path to the file
|
* \param filePath Path to the file
|
||||||
* \param params Parameters for the music
|
* \param params Parameters for the music
|
||||||
*/
|
*/
|
||||||
bool Music::OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params)
|
std::shared_ptr<Music> Music::OpenFromFile(const std::filesystem::path& filePath, const Params& params)
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<Music> music = std::make_shared<Music>();
|
||||||
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromFile(filePath, params))
|
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromFile(filePath, params))
|
||||||
return Create(std::move(soundStream));
|
{
|
||||||
else
|
std::shared_ptr<Music> music = std::make_shared<Music>();
|
||||||
return false;
|
if (music->Create(std::move(soundStream)))
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -258,12 +263,16 @@ namespace Nz
|
|||||||
*
|
*
|
||||||
* \remark The memory pointer must stay valid (accessible) as long as the music is playing
|
* \remark The memory pointer must stay valid (accessible) as long as the music is playing
|
||||||
*/
|
*/
|
||||||
bool Music::OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params)
|
std::shared_ptr<Music> Music::OpenFromMemory(const void* data, std::size_t size, const Params& params)
|
||||||
{
|
{
|
||||||
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromMemory(data, size, params))
|
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromMemory(data, size, params))
|
||||||
return Create(std::move(soundStream));
|
{
|
||||||
else
|
std::shared_ptr<Music> music = std::make_shared<Music>();
|
||||||
return false;
|
if (music->Create(std::move(soundStream)))
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -275,12 +284,16 @@ namespace Nz
|
|||||||
*
|
*
|
||||||
* \remark The stream must stay valid as long as the music is playing
|
* \remark The stream must stay valid as long as the music is playing
|
||||||
*/
|
*/
|
||||||
bool Music::OpenFromStream(Stream& stream, const SoundStreamParams& params)
|
std::shared_ptr<Music> Music::OpenFromStream(Stream& stream, const Params& params)
|
||||||
{
|
{
|
||||||
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromStream(stream, params))
|
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromStream(stream, params))
|
||||||
return Create(std::move(soundStream));
|
{
|
||||||
else
|
std::shared_ptr<Music> music = std::make_shared<Music>();
|
||||||
return false;
|
if (music->Create(std::move(soundStream)))
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -439,7 +452,7 @@ namespace Nz
|
|||||||
break; // We have reached the end of the stream, there is no use to add new buffers
|
break; // We have reached the end of the stream, there is no use to add new buffers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
err = std::current_exception();
|
err = std::current_exception();
|
||||||
|
|
||||||
|
|||||||
@@ -141,17 +141,18 @@ namespace Nz
|
|||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if loading failed
|
* \remark Produces a NazaraError if loading failed
|
||||||
*/
|
*/
|
||||||
bool Sound::LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params)
|
std::shared_ptr<Sound> Sound::LoadFromFile(const std::filesystem::path& filePath, const Params& params)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromFile(filePath, params);
|
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromFile(filePath, params);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
NazaraErrorFmt("failed to load buffer from file ({0})", filePath);
|
NazaraErrorFmt("failed to load buffer from file ({0})", filePath);
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBuffer(std::move(buffer));
|
std::shared_ptr<Sound> sound = std::make_shared<Sound>();
|
||||||
return true;
|
sound->SetBuffer(std::move(buffer));
|
||||||
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -164,17 +165,18 @@ namespace Nz
|
|||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if loading failed
|
* \remark Produces a NazaraError if loading failed
|
||||||
*/
|
*/
|
||||||
bool Sound::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params)
|
std::shared_ptr<Sound> Sound::LoadFromMemory(const void* data, std::size_t size, const Params& params)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromMemory(data, size, params);
|
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromMemory(data, size, params);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
NazaraErrorFmt("failed to load buffer from memory ({0})", PointerToString(data));
|
NazaraErrorFmt("failed to load buffer from memory ({0})", PointerToString(data));
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBuffer(std::move(buffer));
|
std::shared_ptr<Sound> sound = std::make_shared<Sound>();
|
||||||
return true;
|
sound->SetBuffer(std::move(buffer));
|
||||||
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -186,17 +188,18 @@ namespace Nz
|
|||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if loading failed
|
* \remark Produces a NazaraError if loading failed
|
||||||
*/
|
*/
|
||||||
bool Sound::LoadFromStream(Stream& stream, const SoundBufferParams& params)
|
std::shared_ptr<Sound> Sound::LoadFromStream(Stream& stream, const Params& params)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromStream(stream, params);
|
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromStream(stream, params);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
NazaraError("failed to load buffer from stream");
|
NazaraError("failed to load buffer from stream");
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBuffer(std::move(buffer));
|
std::shared_ptr<Sound> sound = std::make_shared<Sound>();
|
||||||
return true;
|
sound->SetBuffer(std::move(buffer));
|
||||||
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -32,6 +32,20 @@ namespace Nz
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Serialize(SerializationContext& context, SoundBufferParams& params, TypeTag<SoundBufferParams>)
|
||||||
|
{
|
||||||
|
Serialize(context, params, TypeTag<ResourceParameters>());
|
||||||
|
Serialize(context, "forceMono", params.forceMono);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unserialize(SerializationContext& context, SoundBufferParams* params, TypeTag<SoundBufferParams>)
|
||||||
|
{
|
||||||
|
Unserialize(context, params, TypeTag<ResourceParameters>());
|
||||||
|
Unserialize(context, "forceMono", ¶ms->forceMono);
|
||||||
|
return params->IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs a SoundBuffer object
|
* \brief Constructs a SoundBuffer object
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,6 +7,20 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
bool Serialize(SerializationContext& context, SoundStreamParams& params, TypeTag<SoundStreamParams>)
|
||||||
|
{
|
||||||
|
Serialize(context, params, TypeTag<ResourceParameters>());
|
||||||
|
Serialize(context, "forceMono", params.forceMono);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unserialize(SerializationContext& context, SoundStreamParams* params, TypeTag<SoundStreamParams>)
|
||||||
|
{
|
||||||
|
Unserialize(context, params, TypeTag<ResourceParameters>());
|
||||||
|
Unserialize(context, "forceMono", ¶ms->forceMono);
|
||||||
|
return params->IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
bool SoundStreamParams::IsValid() const
|
bool SoundStreamParams::IsValid() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
52
src/Nazara/Core/AssetCatalogAppComponent.cpp
Normal file
52
src/Nazara/Core/AssetCatalogAppComponent.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
#include <Nazara/Core/AssetCatalogAppComponent.hpp>
|
||||||
|
#include <Nazara/Core/Serialization.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
bool Serialize(SerializationContext& context, const AssetHeaderLite& header, TypeTag<AssetHeaderLite>)
|
||||||
|
{
|
||||||
|
Serialize(context, "name", header.name);
|
||||||
|
Serialize(context, "path", header.path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unserialize(SerializationContext& context, AssetHeaderLite* header, TypeTag<AssetHeaderLite>)
|
||||||
|
{
|
||||||
|
Unserialize(context, "name", &header->name);
|
||||||
|
Unserialize(context, "path", &header->path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddFile(std::set<AssetHeaderLite>& container, Nz::Stream& stream)
|
||||||
|
{
|
||||||
|
AssetHeaderLite header;
|
||||||
|
auto json = JsonSerializationContext::LoadFromStream(stream);
|
||||||
|
if (!json)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!Unserialize(*json, "", &header))
|
||||||
|
return;
|
||||||
|
|
||||||
|
header.path = stream.GetPath();
|
||||||
|
container.insert(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetCatalogAppComponent::AddFolder(std::string_view folder)
|
||||||
|
{
|
||||||
|
auto& fs = GetApp().GetComponent<FilesystemAppComponent>();
|
||||||
|
auto directory = fs.GetDirectory(folder);
|
||||||
|
if (!directory)
|
||||||
|
return;
|
||||||
|
|
||||||
|
directory->Foreach([&](std::string_view, const VirtualDirectory::Entry& entry) {
|
||||||
|
if (std::holds_alternative<VirtualDirectory::FileEntry>(entry))
|
||||||
|
{
|
||||||
|
auto& file = std::get<VirtualDirectory::FileEntry>(entry);
|
||||||
|
|
||||||
|
if (file.stream->GetPath().extension() == ".nzasset")
|
||||||
|
AddFile(m_assets, *file.stream.get());
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
501
src/Nazara/Core/EnumSerialization.cpp
Normal file
501
src/Nazara/Core/EnumSerialization.cpp
Normal file
@@ -0,0 +1,501 @@
|
|||||||
|
#include <Nazara/Core/EnumSerialization.hpp>
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template<Enum TEnum>
|
||||||
|
inline TEnum Find(const std::unordered_map<TEnum, std::string_view>& m, std::string_view v)
|
||||||
|
{
|
||||||
|
auto it = std::find_if(m.begin(), m.end(), [v](const auto& kp) { return kp.second == v; });
|
||||||
|
return it != m.end() ? it->first : TEnum{};
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_ENUM(Type) \
|
||||||
|
namespace Type ## _Generated { \
|
||||||
|
std::unordered_map<Type, std::string_view> ValuesToString = {
|
||||||
|
|
||||||
|
#define DEF_ENUM_VALUE(Type, Value) \
|
||||||
|
{ Type::Value, #Value },
|
||||||
|
|
||||||
|
#define DEF_ENUM_END(Type) \
|
||||||
|
}; \
|
||||||
|
} \
|
||||||
|
std::string_view EnumToString(Type v) { return Type ## _Generated::ValuesToString[v]; }; \
|
||||||
|
Type EnumFromString_##Type(std::string_view v) { return Find(Type ## _Generated::ValuesToString, v);}
|
||||||
|
|
||||||
|
|
||||||
|
DEF_ENUM(AnimationType)
|
||||||
|
DEF_ENUM_VALUE(AnimationType, Skeletal)
|
||||||
|
DEF_ENUM_VALUE(AnimationType, Static)
|
||||||
|
DEF_ENUM_END(AnimationType)
|
||||||
|
|
||||||
|
DEF_ENUM(BlendEquation)
|
||||||
|
DEF_ENUM_VALUE(BlendEquation, Add)
|
||||||
|
DEF_ENUM_VALUE(BlendEquation, Max)
|
||||||
|
DEF_ENUM_VALUE(BlendEquation, Min)
|
||||||
|
DEF_ENUM_VALUE(BlendEquation, ReverseSubtract)
|
||||||
|
DEF_ENUM_VALUE(BlendEquation, Subtract)
|
||||||
|
DEF_ENUM_END(BlendEquation)
|
||||||
|
|
||||||
|
DEF_ENUM(BlendFunc)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, ConstantColor)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, ConstantAlpha)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, DstAlpha)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, DstColor)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, SrcAlpha)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, SrcColor)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, InvConstantColor)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, InvConstantAlpha)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, InvDstAlpha)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, InvDstColor)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, InvSrcAlpha)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, InvSrcColor)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, One)
|
||||||
|
DEF_ENUM_VALUE(BlendFunc, Zero)
|
||||||
|
DEF_ENUM_END(BlendFunc)
|
||||||
|
|
||||||
|
DEF_ENUM(BufferAccess)
|
||||||
|
DEF_ENUM_VALUE(BufferAccess, DiscardAndWrite)
|
||||||
|
DEF_ENUM_VALUE(BufferAccess, ReadOnly)
|
||||||
|
DEF_ENUM_VALUE(BufferAccess, ReadWrite)
|
||||||
|
DEF_ENUM_VALUE(BufferAccess, WriteOnly)
|
||||||
|
DEF_ENUM_VALUE(BufferAccess, Max)
|
||||||
|
DEF_ENUM_END(BufferAccess)
|
||||||
|
|
||||||
|
DEF_ENUM(BufferType)
|
||||||
|
DEF_ENUM_VALUE(BufferType, Index)
|
||||||
|
DEF_ENUM_VALUE(BufferType, Vertex)
|
||||||
|
DEF_ENUM_VALUE(BufferType, Storage)
|
||||||
|
DEF_ENUM_VALUE(BufferType, Uniform)
|
||||||
|
DEF_ENUM_VALUE(BufferType, Upload)
|
||||||
|
DEF_ENUM_VALUE(BufferType, Max)
|
||||||
|
DEF_ENUM_END(BufferType)
|
||||||
|
|
||||||
|
DEF_ENUM(BufferUsage)
|
||||||
|
DEF_ENUM_VALUE(BufferUsage, DeviceLocal)
|
||||||
|
DEF_ENUM_VALUE(BufferUsage, DirectMapping)
|
||||||
|
DEF_ENUM_VALUE(BufferUsage, Dynamic)
|
||||||
|
DEF_ENUM_VALUE(BufferUsage, Read)
|
||||||
|
DEF_ENUM_VALUE(BufferUsage, PersistentMapping)
|
||||||
|
DEF_ENUM_VALUE(BufferUsage, Write)
|
||||||
|
DEF_ENUM_VALUE(BufferUsage, Max)
|
||||||
|
DEF_ENUM_END(BufferUsage)
|
||||||
|
|
||||||
|
DEF_ENUM(ComponentType)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Color)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Double1)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Double2)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Double3)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Double4)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Float1)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Float2)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Float3)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Float4)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Int1)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Int2)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Int3)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Int4)
|
||||||
|
DEF_ENUM_VALUE(ComponentType, Max)
|
||||||
|
DEF_ENUM_END(ComponentType)
|
||||||
|
|
||||||
|
DEF_ENUM(CoordSys)
|
||||||
|
DEF_ENUM_VALUE(CoordSys, Global)
|
||||||
|
DEF_ENUM_VALUE(CoordSys, Local)
|
||||||
|
DEF_ENUM_VALUE(CoordSys, Max)
|
||||||
|
DEF_ENUM_END(CoordSys)
|
||||||
|
|
||||||
|
DEF_ENUM(CursorPosition)
|
||||||
|
DEF_ENUM_VALUE(CursorPosition, AtBegin)
|
||||||
|
DEF_ENUM_VALUE(CursorPosition, AtCurrent)
|
||||||
|
DEF_ENUM_VALUE(CursorPosition, AtEnd)
|
||||||
|
DEF_ENUM_VALUE(CursorPosition, Max)
|
||||||
|
DEF_ENUM_END(CursorPosition)
|
||||||
|
|
||||||
|
DEF_ENUM(CubemapFace)
|
||||||
|
DEF_ENUM_VALUE(CubemapFace, PositiveX)
|
||||||
|
DEF_ENUM_VALUE(CubemapFace, PositiveY)
|
||||||
|
DEF_ENUM_VALUE(CubemapFace, PositiveZ)
|
||||||
|
DEF_ENUM_VALUE(CubemapFace, NegativeX)
|
||||||
|
DEF_ENUM_VALUE(CubemapFace, NegativeY)
|
||||||
|
DEF_ENUM_VALUE(CubemapFace, NegativeZ)
|
||||||
|
DEF_ENUM_VALUE(CubemapFace, Max)
|
||||||
|
DEF_ENUM_END(CubemapFace)
|
||||||
|
|
||||||
|
DEF_ENUM(DataStorage)
|
||||||
|
DEF_ENUM_VALUE(DataStorage, Hardware)
|
||||||
|
DEF_ENUM_VALUE(DataStorage, Software)
|
||||||
|
DEF_ENUM_VALUE(DataStorage, Max)
|
||||||
|
DEF_ENUM_END(DataStorage)
|
||||||
|
|
||||||
|
DEF_ENUM(ErrorMode)
|
||||||
|
DEF_ENUM_VALUE(ErrorMode, Silent)
|
||||||
|
DEF_ENUM_VALUE(ErrorMode, ThrowException)
|
||||||
|
DEF_ENUM_VALUE(ErrorMode, Max)
|
||||||
|
DEF_ENUM_END(ErrorMode)
|
||||||
|
|
||||||
|
DEF_ENUM(ErrorType)
|
||||||
|
DEF_ENUM_VALUE(ErrorType, AssertFailed)
|
||||||
|
DEF_ENUM_VALUE(ErrorType, Internal)
|
||||||
|
DEF_ENUM_VALUE(ErrorType, Normal)
|
||||||
|
DEF_ENUM_VALUE(ErrorType, Warning)
|
||||||
|
DEF_ENUM_VALUE(ErrorType, Max)
|
||||||
|
DEF_ENUM_END(ErrorType)
|
||||||
|
|
||||||
|
DEF_ENUM(FaceFilling)
|
||||||
|
DEF_ENUM_VALUE(FaceFilling, Fill)
|
||||||
|
DEF_ENUM_VALUE(FaceFilling, Line)
|
||||||
|
DEF_ENUM_VALUE(FaceFilling, Point)
|
||||||
|
DEF_ENUM_VALUE(FaceFilling, Max)
|
||||||
|
DEF_ENUM_END(FaceFilling)
|
||||||
|
|
||||||
|
DEF_ENUM(FaceCulling)
|
||||||
|
DEF_ENUM_VALUE(FaceCulling, None)
|
||||||
|
DEF_ENUM_VALUE(FaceCulling, Back)
|
||||||
|
DEF_ENUM_VALUE(FaceCulling, Front)
|
||||||
|
DEF_ENUM_VALUE(FaceCulling, FrontAndBack)
|
||||||
|
DEF_ENUM_VALUE(FaceCulling, Max)
|
||||||
|
DEF_ENUM_END(FaceCulling)
|
||||||
|
|
||||||
|
DEF_ENUM(FrontFace)
|
||||||
|
DEF_ENUM_VALUE(FrontFace, Clockwise)
|
||||||
|
DEF_ENUM_VALUE(FrontFace, CounterClockwise)
|
||||||
|
DEF_ENUM_VALUE(FrontFace, Max)
|
||||||
|
DEF_ENUM_END(FrontFace)
|
||||||
|
|
||||||
|
DEF_ENUM(ImageType)
|
||||||
|
DEF_ENUM_VALUE(ImageType, E1D)
|
||||||
|
DEF_ENUM_VALUE(ImageType, E1D_Array)
|
||||||
|
DEF_ENUM_VALUE(ImageType, E2D)
|
||||||
|
DEF_ENUM_VALUE(ImageType, E2D_Array)
|
||||||
|
DEF_ENUM_VALUE(ImageType, E3D)
|
||||||
|
DEF_ENUM_VALUE(ImageType, Cubemap)
|
||||||
|
DEF_ENUM_VALUE(ImageType, Max)
|
||||||
|
DEF_ENUM_END(ImageType)
|
||||||
|
|
||||||
|
DEF_ENUM(IndexType)
|
||||||
|
DEF_ENUM_VALUE(IndexType, U8)
|
||||||
|
DEF_ENUM_VALUE(IndexType, U16)
|
||||||
|
DEF_ENUM_VALUE(IndexType, U32)
|
||||||
|
DEF_ENUM_VALUE(IndexType, Max)
|
||||||
|
DEF_ENUM_END(IndexType)
|
||||||
|
|
||||||
|
DEF_ENUM(HashType)
|
||||||
|
DEF_ENUM_VALUE(HashType, CRC32)
|
||||||
|
DEF_ENUM_VALUE(HashType, CRC64)
|
||||||
|
DEF_ENUM_VALUE(HashType, Fletcher16)
|
||||||
|
DEF_ENUM_VALUE(HashType, MD5)
|
||||||
|
DEF_ENUM_VALUE(HashType, SHA1)
|
||||||
|
DEF_ENUM_VALUE(HashType, SHA224)
|
||||||
|
DEF_ENUM_VALUE(HashType, SHA256)
|
||||||
|
DEF_ENUM_VALUE(HashType, SHA384)
|
||||||
|
DEF_ENUM_VALUE(HashType, SHA512)
|
||||||
|
DEF_ENUM_VALUE(HashType, Whirlpool)
|
||||||
|
DEF_ENUM_VALUE(HashType, Max)
|
||||||
|
DEF_ENUM_END(HashType)
|
||||||
|
|
||||||
|
DEF_ENUM(OpenMode)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, NotOpen)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Append)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Defer)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Lock)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, MustExist)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Read)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Text)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Truncate)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Unbuffered)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Write)
|
||||||
|
DEF_ENUM_VALUE(OpenMode, Max)
|
||||||
|
DEF_ENUM_END(OpenMode)
|
||||||
|
|
||||||
|
DEF_ENUM(ParameterType)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, Boolean)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, Color)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, Double)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, Integer)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, None)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, Pointer)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, String)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, Userdata)
|
||||||
|
DEF_ENUM_VALUE(ParameterType, Max)
|
||||||
|
DEF_ENUM_END(ParameterType)
|
||||||
|
|
||||||
|
DEF_ENUM(PixelFormatContent)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatContent, Undefined)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatContent, ColorRGBA)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatContent, Depth)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatContent, DepthStencil)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatContent, Stencil)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatContent, Max)
|
||||||
|
DEF_ENUM_END(PixelFormatContent)
|
||||||
|
|
||||||
|
DEF_ENUM(PixelFormat)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Undefined)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, A8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, BGR8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, BGR8_SRGB)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, BGRA8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, BGRA8_SRGB)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, DXT1)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, DXT3)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, DXT5)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, L8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, LA8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R8I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R8UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R16)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R16F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R16I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R16UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R32F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R32I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, R32UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG8I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG8UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG16)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG16F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG16I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG16UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG32F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG32I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RG32UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB5A1)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB8_SRGB)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB16F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB16I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB16UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB32F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB32I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGB32UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA4)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA8_SRGB)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA16F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA16I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA16UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA32F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA32I)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, RGBA32UI)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Depth16)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Depth16Stencil8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Depth24)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Depth24Stencil8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Depth32F)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Depth32FStencil8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Stencil1)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Stencil4)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Stencil8)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Stencil16)
|
||||||
|
DEF_ENUM_VALUE(PixelFormat, Max)
|
||||||
|
DEF_ENUM_END(PixelFormat)
|
||||||
|
|
||||||
|
|
||||||
|
DEF_ENUM(PixelFormatSubType)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatSubType, Compressed)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatSubType, Double)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatSubType, Float)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatSubType, Half)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatSubType, Int)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatSubType, Unsigned)
|
||||||
|
DEF_ENUM_VALUE(PixelFormatSubType, Max)
|
||||||
|
DEF_ENUM_END(PixelFormatSubType)
|
||||||
|
|
||||||
|
DEF_ENUM(PixelFlipping)
|
||||||
|
DEF_ENUM_VALUE(PixelFlipping, Horizontally)
|
||||||
|
DEF_ENUM_VALUE(PixelFlipping, Vertically)
|
||||||
|
DEF_ENUM_VALUE(PixelFlipping, Max)
|
||||||
|
DEF_ENUM_END(PixelFlipping)
|
||||||
|
|
||||||
|
DEF_ENUM(PrimitiveMode)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveMode, LineList)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveMode, LineStrip)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveMode, PointList)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveMode, TriangleList)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveMode, TriangleStrip)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveMode, TriangleFan)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveMode, Max)
|
||||||
|
DEF_ENUM_END(PrimitiveMode)
|
||||||
|
|
||||||
|
DEF_ENUM(PrimitiveType)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveType, Box)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveType, Cone)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveType, Plane)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveType, Sphere)
|
||||||
|
DEF_ENUM_VALUE(PrimitiveType, Max)
|
||||||
|
DEF_ENUM_END(PrimitiveType)
|
||||||
|
|
||||||
|
DEF_ENUM(ProcessorCap)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, x64)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, AES)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, AVX)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, FMA3)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, FMA4)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, MMX)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, Popcnt)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, RDRAND)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, XOP)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, SSE)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, SSE2)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, SSE3)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, SSSE3)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, SSE41)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, SSE42)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, SSE4a)
|
||||||
|
DEF_ENUM_VALUE(ProcessorCap, Max)
|
||||||
|
DEF_ENUM_END(ProcessorCap)
|
||||||
|
|
||||||
|
DEF_ENUM(ProcessorVendor)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Unknown)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, ACRN)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, AMD)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Ao486)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, AppleRosetta2)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Bhyve)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Centaur)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Cyrix)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Elbrus)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Hygon)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, HyperV)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Intel)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, KVM)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, MicrosoftXTA)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, NSC)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, NexGen)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Parallels)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, QEMU)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, QNX)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Rise)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, SIS)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Transmeta)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, UMC)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, VIA)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, VMware)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Vortex)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, XenHVM)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Zhaoxin)
|
||||||
|
DEF_ENUM_VALUE(ProcessorVendor, Max)
|
||||||
|
DEF_ENUM_END(ProcessorVendor)
|
||||||
|
|
||||||
|
DEF_ENUM(RendererComparison)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, Always)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, Equal)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, Greater)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, GreaterOrEqual)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, Less)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, LessOrEqual)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, Never)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, NotEqual)
|
||||||
|
DEF_ENUM_VALUE(RendererComparison, Max)
|
||||||
|
DEF_ENUM_END(RendererComparison)
|
||||||
|
|
||||||
|
DEF_ENUM(ResourceLoadingError)
|
||||||
|
DEF_ENUM_VALUE(ResourceLoadingError, DecodingError)
|
||||||
|
DEF_ENUM_VALUE(ResourceLoadingError, FailedToOpenFile)
|
||||||
|
DEF_ENUM_VALUE(ResourceLoadingError, Internal)
|
||||||
|
DEF_ENUM_VALUE(ResourceLoadingError, Unsupported)
|
||||||
|
DEF_ENUM_VALUE(ResourceLoadingError, Unrecognized)
|
||||||
|
DEF_ENUM_END(ResourceLoadingError)
|
||||||
|
|
||||||
|
DEF_ENUM(SamplerFilter)
|
||||||
|
DEF_ENUM_VALUE(SamplerFilter, Linear)
|
||||||
|
DEF_ENUM_VALUE(SamplerFilter, Nearest)
|
||||||
|
DEF_ENUM_VALUE(SamplerFilter, Max)
|
||||||
|
DEF_ENUM_END(SamplerFilter)
|
||||||
|
|
||||||
|
DEF_ENUM(SamplerMipmapMode)
|
||||||
|
DEF_ENUM_VALUE(SamplerMipmapMode, Linear)
|
||||||
|
DEF_ENUM_VALUE(SamplerMipmapMode, Nearest)
|
||||||
|
DEF_ENUM_VALUE(SamplerMipmapMode, Max)
|
||||||
|
DEF_ENUM_END(SamplerMipmapMode)
|
||||||
|
|
||||||
|
DEF_ENUM(SamplerWrap)
|
||||||
|
DEF_ENUM_VALUE(SamplerWrap, Clamp)
|
||||||
|
DEF_ENUM_VALUE(SamplerWrap, MirroredRepeat)
|
||||||
|
DEF_ENUM_VALUE(SamplerWrap, Repeat)
|
||||||
|
DEF_ENUM_VALUE(SamplerWrap, Max)
|
||||||
|
DEF_ENUM_END(SamplerWrap)
|
||||||
|
|
||||||
|
DEF_ENUM(SphereType)
|
||||||
|
DEF_ENUM_VALUE(SphereType, Cubic)
|
||||||
|
DEF_ENUM_VALUE(SphereType, Ico)
|
||||||
|
DEF_ENUM_VALUE(SphereType, UV)
|
||||||
|
DEF_ENUM_VALUE(SphereType, Max)
|
||||||
|
DEF_ENUM_END(SphereType)
|
||||||
|
|
||||||
|
DEF_ENUM(StencilOperation)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, Decrement)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, DecrementNoClamp)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, Increment)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, IncrementNoClamp)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, Invert)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, Keep)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, Replace)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, Zero)
|
||||||
|
DEF_ENUM_VALUE(StencilOperation, Max)
|
||||||
|
DEF_ENUM_END(StencilOperation)
|
||||||
|
|
||||||
|
DEF_ENUM(StreamOption)
|
||||||
|
DEF_ENUM_VALUE(StreamOption, None)
|
||||||
|
DEF_ENUM_VALUE(StreamOption, MemoryMapped)
|
||||||
|
DEF_ENUM_VALUE(StreamOption, Sequential)
|
||||||
|
DEF_ENUM_VALUE(StreamOption, Text)
|
||||||
|
DEF_ENUM_VALUE(StreamOption, Unbuffered)
|
||||||
|
DEF_ENUM_VALUE(StreamOption, Max)
|
||||||
|
DEF_ENUM_END(StreamOption)
|
||||||
|
|
||||||
|
DEF_ENUM(TextAlign)
|
||||||
|
DEF_ENUM_VALUE(TextAlign, Left)
|
||||||
|
DEF_ENUM_VALUE(TextAlign, Middle)
|
||||||
|
DEF_ENUM_VALUE(TextAlign, Right)
|
||||||
|
DEF_ENUM_VALUE(TextAlign, Max)
|
||||||
|
DEF_ENUM_END(TextAlign)
|
||||||
|
|
||||||
|
DEF_ENUM(TextStyle)
|
||||||
|
DEF_ENUM_VALUE(TextStyle, Bold)
|
||||||
|
DEF_ENUM_VALUE(TextStyle, Italic)
|
||||||
|
DEF_ENUM_VALUE(TextStyle, StrikeThrough)
|
||||||
|
DEF_ENUM_VALUE(TextStyle, Underlined)
|
||||||
|
DEF_ENUM_VALUE(TextStyle, Max)
|
||||||
|
DEF_ENUM_END(TextStyle)
|
||||||
|
|
||||||
|
DEF_ENUM(VertexComponent)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, Unused)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, Color)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, JointIndices)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, JointWeights)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, Normal)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, Position)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, SizeSinCos)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, Tangent)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, TexCoord)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, Userdata)
|
||||||
|
DEF_ENUM_VALUE(VertexComponent, Max)
|
||||||
|
DEF_ENUM_END(VertexComponent)
|
||||||
|
|
||||||
|
DEF_ENUM(VertexInputRate)
|
||||||
|
DEF_ENUM_VALUE(VertexInputRate, Instance)
|
||||||
|
DEF_ENUM_VALUE(VertexInputRate, Vertex)
|
||||||
|
DEF_ENUM_END(VertexInputRate)
|
||||||
|
|
||||||
|
DEF_ENUM(VertexLayout)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, UV_SizeSinCos)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XY)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XY_Color)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XY_UV)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ_Color)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ_Color_UV)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ_Normal)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ_Normal_UV)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ_Normal_UV_Tangent)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ_Normal_UV_Tangent_Skinning)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, UV_SizeSinCos_Color)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, XYZ_UV)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, Matrix4)
|
||||||
|
DEF_ENUM_VALUE(VertexLayout, Max)
|
||||||
|
DEF_ENUM_END(VertexLayout)
|
||||||
|
}
|
||||||
@@ -45,6 +45,22 @@ namespace Nz
|
|||||||
loadFormat = params.loadFormat;
|
loadFormat = params.loadFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Serialize(SerializationContext& context, ImageParams& params, TypeTag<ImageParams>)
|
||||||
|
{
|
||||||
|
Serialize(context, params, TypeTag<ResourceParameters>());
|
||||||
|
|
||||||
|
Serialize(context, "loadFormat", params.loadFormat);
|
||||||
|
Serialize(context, "levelCount", params.levelCount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unserialize(SerializationContext& context, ImageParams* params, TypeTag<ImageParams>)
|
||||||
|
{
|
||||||
|
Unserialize(context, params, TypeTag<ResourceParameters>());
|
||||||
|
Unserialize(context, "loadFormat", ¶ms->loadFormat);
|
||||||
|
Unserialize(context, "levelCount", ¶ms->levelCount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Image::Image() :
|
Image::Image() :
|
||||||
m_sharedImage(&emptyImage)
|
m_sharedImage(&emptyImage)
|
||||||
|
|||||||
149
src/Nazara/Core/JsonSerialization.cpp
Normal file
149
src/Nazara/Core/JsonSerialization.cpp
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#include <Nazara/Core/JsonSerialization.hpp>
|
||||||
|
#include <Nazara/Core/FilesystemAppComponent.hpp>
|
||||||
|
#include <Nazara/Core/ApplicationBase.hpp>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
struct JsonImpl
|
||||||
|
{
|
||||||
|
|
||||||
|
nlohmann::json& Top() { return *stack.top(); }
|
||||||
|
|
||||||
|
bool Pop()
|
||||||
|
{
|
||||||
|
if (stack.empty())
|
||||||
|
{
|
||||||
|
NazaraAssert(stack.empty(), "Stack is empty");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stack.pop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json json;
|
||||||
|
std::stack<nlohmann::json*> stack;
|
||||||
|
};
|
||||||
|
|
||||||
|
JsonSerializationContext::JsonSerializationContext()
|
||||||
|
: m_impl(std::make_unique<JsonImpl>())
|
||||||
|
{}
|
||||||
|
|
||||||
|
JsonSerializationContext::~JsonSerializationContext() {}
|
||||||
|
|
||||||
|
bool JsonSerializationContext::Load(const std::filesystem::path& path)
|
||||||
|
{
|
||||||
|
Nz::File file(path, Nz::OpenMode::Read);
|
||||||
|
return Load(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonSerializationContext::Load(Stream& stream)
|
||||||
|
{
|
||||||
|
if (!stream.IsReadable())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto size = stream.GetSize();
|
||||||
|
std::vector<char> content(size);
|
||||||
|
stream.Read(content.data(), content.size());
|
||||||
|
|
||||||
|
m_impl->json = nlohmann::json::parse(content.begin(), content.end());
|
||||||
|
m_impl->stack.push(&m_impl->json);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonSerializationContext::PushObject(std::string_view name)
|
||||||
|
{
|
||||||
|
if (name.empty()) // special case if name is empty, don't push
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!m_impl->Top().contains(name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!m_impl->Top()[name].is_object())
|
||||||
|
{
|
||||||
|
NazaraAssert(m_impl->Top()[name].is_object(), "Value is not an object");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_impl->stack.push(&m_impl->Top()[name]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonSerializationContext::PopObject()
|
||||||
|
{
|
||||||
|
return m_impl->Pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonSerializationContext::PushArray(std::string_view name)
|
||||||
|
{
|
||||||
|
if (!m_impl->Top()[name].is_array())
|
||||||
|
{
|
||||||
|
NazaraAssert(m_impl->Top()[name].is_array(), "Value is not an array");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_impl->stack.push(&m_impl->Top()[name]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonSerializationContext::PopArray()
|
||||||
|
{
|
||||||
|
return m_impl->Pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_SERIALIZE(Type, cond) \
|
||||||
|
bool JsonSerializationContext::Write(std::string_view name, Type value) \
|
||||||
|
{ \
|
||||||
|
m_impl->Top()[name] = value; \
|
||||||
|
return true; \
|
||||||
|
} \
|
||||||
|
bool JsonSerializationContext::Read(std::string_view name, Type* value) \
|
||||||
|
{ \
|
||||||
|
if (!m_impl->Top()[name].cond()) \
|
||||||
|
{ \
|
||||||
|
/*NazaraAssert(m_impl->Top()[name].cond(), "Value failed check: " #cond "()");*/\
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
*value = m_impl->Top()[name].get<Type>(); \
|
||||||
|
return true; \
|
||||||
|
} \
|
||||||
|
|
||||||
|
DEF_SERIALIZE(bool, is_boolean);
|
||||||
|
DEF_SERIALIZE(Nz::Int8, is_number);
|
||||||
|
DEF_SERIALIZE(Nz::Int16, is_number);
|
||||||
|
DEF_SERIALIZE(Nz::Int32, is_number);
|
||||||
|
DEF_SERIALIZE(Nz::Int64, is_number);
|
||||||
|
DEF_SERIALIZE(Nz::UInt8, is_number);
|
||||||
|
DEF_SERIALIZE(Nz::UInt16, is_number);
|
||||||
|
DEF_SERIALIZE(Nz::UInt32, is_number);
|
||||||
|
DEF_SERIALIZE(Nz::UInt64, is_number);
|
||||||
|
DEF_SERIALIZE(float, is_number);
|
||||||
|
DEF_SERIALIZE(double, is_number);
|
||||||
|
#undef DEF_SERIALIZE
|
||||||
|
|
||||||
|
bool JsonSerializationContext::Write(std::string_view name, const std::string& value)
|
||||||
|
{
|
||||||
|
m_impl->Top()[name] = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonSerializationContext::Read(std::string_view name, std::string* value)
|
||||||
|
{
|
||||||
|
if (!m_impl->Top()[name].is_string())
|
||||||
|
{
|
||||||
|
NazaraAssert(m_impl->Top()[name].is_string(), "Value failed check: is_string()");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*value = m_impl->Top()[name].get<std::string>();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<JsonSerializationContext> JsonSerializationContext::LoadFromStream(Stream& stream, const JsonSerializationContext::Params&)
|
||||||
|
{
|
||||||
|
std::shared_ptr<JsonSerializationContext> context = std::make_shared<JsonSerializationContext>();
|
||||||
|
if (context->Load(stream))
|
||||||
|
return context;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <Nazara/Core/StringExt.hpp>
|
#include <Nazara/Core/StringExt.hpp>
|
||||||
#include <Nazara/Core/SubMesh.hpp>
|
#include <Nazara/Core/SubMesh.hpp>
|
||||||
#include <Nazara/Core/VertexMapper.hpp>
|
#include <Nazara/Core/VertexMapper.hpp>
|
||||||
|
#include <Nazara/Core/Serialization.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -39,6 +40,50 @@ namespace Nz
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Serialize(SerializationContext& context, const MeshParams& params, TypeTag<MeshParams>)
|
||||||
|
{
|
||||||
|
Serialize(context, "indexBufferFlags", params.indexBufferFlags);
|
||||||
|
Serialize(context, "vertexBufferFlags", params.vertexBufferFlags);
|
||||||
|
Serialize(context, "vertexOffset", params.vertexOffset);
|
||||||
|
|
||||||
|
Nz::EulerAnglesf rot = params.vertexRotation;
|
||||||
|
Serialize(context, "vertexRotation", rot);
|
||||||
|
|
||||||
|
Serialize(context, "vertexScale", params.vertexScale);
|
||||||
|
Serialize(context, "texCoordOffset", params.texCoordOffset);
|
||||||
|
Serialize(context, "texCoordScale", params.texCoordScale);
|
||||||
|
Serialize(context, "animated", params.animated);
|
||||||
|
Serialize(context, "center", params.center);
|
||||||
|
Serialize(context, "optimizeIndexBuffers", params.optimizeIndexBuffers);
|
||||||
|
|
||||||
|
Serialize(context, "vertexDeclaration", VertexDeclaration::Find(params.vertexDeclaration));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unserialize(SerializationContext& context, MeshParams* params, TypeTag<MeshParams>)
|
||||||
|
{
|
||||||
|
Unserialize(context, "indexBufferFlags", ¶ms->indexBufferFlags);
|
||||||
|
Unserialize(context, "vertexBufferFlags", ¶ms->vertexBufferFlags);
|
||||||
|
Unserialize(context, "vertexOffset", ¶ms->vertexOffset);
|
||||||
|
|
||||||
|
Nz::EulerAnglesf rot;
|
||||||
|
if (Unserialize(context, "vertexRotation", &rot))
|
||||||
|
params->vertexRotation = rot;
|
||||||
|
|
||||||
|
Unserialize(context, "vertexScale", ¶ms->vertexScale);
|
||||||
|
Unserialize(context, "texCoordOffset", ¶ms->texCoordOffset);
|
||||||
|
Unserialize(context, "texCoordScale", ¶ms->texCoordScale);
|
||||||
|
Unserialize(context, "animated", ¶ms->animated);
|
||||||
|
Unserialize(context, "center", ¶ms->center);
|
||||||
|
Unserialize(context, "optimizeIndexBuffers", ¶ms->optimizeIndexBuffers);
|
||||||
|
|
||||||
|
VertexLayout layout;
|
||||||
|
if (Unserialize(context, "vertexDeclaration", &layout))
|
||||||
|
params->vertexDeclaration = VertexDeclaration::Get(layout);
|
||||||
|
|
||||||
|
return params->IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Mesh::AddSubMesh(std::shared_ptr<SubMesh> subMesh)
|
void Mesh::AddSubMesh(std::shared_ptr<SubMesh> subMesh)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,4 +7,18 @@
|
|||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
ResourceParameters::~ResourceParameters() = default;
|
ResourceParameters::~ResourceParameters() = default;
|
||||||
|
|
||||||
|
bool Serialize(SerializationContext& context, ResourceParameters& params, TypeTag<ResourceParameters>)
|
||||||
|
{
|
||||||
|
NazaraUnused(context);
|
||||||
|
NazaraUnused(params);
|
||||||
|
return true;// Serialize(context, "custom", descriptor.custom);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unserialize(SerializationContext& context, ResourceParameters* params, TypeTag<ResourceParameters>)
|
||||||
|
{
|
||||||
|
NazaraUnused(context);
|
||||||
|
NazaraUnused(params);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,28 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
bool Serialize(SerializationContext& context, TextureParams& params, TypeTag<TextureParams>)
|
||||||
|
{
|
||||||
|
Serialize(context, params, TypeTag<ImageParams>());
|
||||||
|
|
||||||
|
int v = int(params.usageFlags);
|
||||||
|
Serialize(context, "usageFlags", v);
|
||||||
|
Serialize(context, "buildMipmaps", params.buildMipmaps);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unserialize(SerializationContext& context, TextureParams* params, TypeTag<TextureParams>)
|
||||||
|
{
|
||||||
|
Unserialize(context, params, TypeTag<ImageParams>());
|
||||||
|
|
||||||
|
int usageFlags = 0;
|
||||||
|
if (Unserialize(context, "usageFlags", &usageFlags))
|
||||||
|
params->usageFlags = usageFlags;
|
||||||
|
|
||||||
|
Unserialize(context, "buildMipmaps", ¶ms->buildMipmaps);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Texture::~Texture() = default;
|
Texture::~Texture() = default;
|
||||||
|
|
||||||
bool TextureParams::IsValid() const
|
bool TextureParams::IsValid() const
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ TEST_CASE("VirtualDirectory", "[Core][VirtualDirectory]")
|
|||||||
}
|
}
|
||||||
if (name != "." && name != "..")
|
if (name != "." && name != "..")
|
||||||
FAIL("Got file " << name);
|
FAIL("Got file " << name);
|
||||||
}, true);
|
}, false, true);
|
||||||
|
|
||||||
CHECK(dot);
|
CHECK(dot);
|
||||||
CHECK(dotDot);
|
CHECK(dotDot);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ local modules = {
|
|||||||
remove_files("src/Nazara/Core/Posix/TimeImpl.cpp")
|
remove_files("src/Nazara/Core/Posix/TimeImpl.cpp")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Packages = { "concurrentqueue", "entt", "frozen", "ordered_map", "stb", "utfcpp" },
|
Packages = { "concurrentqueue", "entt", "frozen", "ordered_map", "stb", "utfcpp", "nlohmann_json" },
|
||||||
PublicPackages = { "nazarautils" }
|
PublicPackages = { "nazarautils" }
|
||||||
},
|
},
|
||||||
Graphics = {
|
Graphics = {
|
||||||
@@ -284,7 +284,8 @@ add_requires(
|
|||||||
"ordered_map",
|
"ordered_map",
|
||||||
"nazarautils >=2024.01.25",
|
"nazarautils >=2024.01.25",
|
||||||
"stb",
|
"stb",
|
||||||
"utfcpp"
|
"utfcpp",
|
||||||
|
"nlohmann_json"
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Don't link with system-installed libs on CI
|
-- Don't link with system-installed libs on CI
|
||||||
|
|||||||
Reference in New Issue
Block a user