1
0
mirror of synced 2025-02-13 08:52:33 +01:00

WIP why is cereal so fucking hard to use

This commit is contained in:
Stepland 2020-03-02 02:07:29 +01:00
parent 1310886609
commit 88c655fe38
9 changed files with 41 additions and 23 deletions

View File

@ -38,6 +38,8 @@ sources = [
'src/Drawables/BlackFrame.cpp', 'src/Drawables/BlackFrame.cpp',
'src/Resources/TextureCache.cpp', 'src/Resources/TextureCache.cpp',
'src/Resources/TextureCache.hpp', 'src/Resources/TextureCache.hpp',
'src/Resources/Marker.cpp',
'src/Resources/Marker.hpp',
# 'src/Resources/CoverAtlas.hpp', # 'src/Resources/CoverAtlas.hpp',
# 'src/Resources/CoverAtlas.cpp', # 'src/Resources/CoverAtlas.cpp',
# 'src/Screens/Gameplay.hpp', # 'src/Screens/Gameplay.hpp',
@ -49,8 +51,12 @@ sources = [
'src/Screens/MusicSelect/MusicPreview.cpp', 'src/Screens/MusicSelect/MusicPreview.cpp',
'src/Screens/MusicSelect/MusicSelect.hpp', 'src/Screens/MusicSelect/MusicSelect.hpp',
'src/Screens/MusicSelect/MusicSelect.cpp', 'src/Screens/MusicSelect/MusicSelect.cpp',
'src/Screens/MusicSelect/OptionMenu.hpp',
# 'src/Screens/MusicSelect/OptionMenu.cpp',
'src/Screens/MusicSelect/Panel.hpp', 'src/Screens/MusicSelect/Panel.hpp',
'src/Screens/MusicSelect/Panel.cpp', 'src/Screens/MusicSelect/Panel.cpp',
'src/Screens/MusicSelect/PanelLayout.hpp',
'src/Screens/MusicSelect/PanelLayout.cpp',
'src/Screens/MusicSelect/Ribbon.hpp', 'src/Screens/MusicSelect/Ribbon.hpp',
'src/Screens/MusicSelect/Ribbon.cpp', 'src/Screens/MusicSelect/Ribbon.cpp',
'src/Screens/MusicSelect/SharedResources.hpp', 'src/Screens/MusicSelect/SharedResources.hpp',
@ -63,6 +69,8 @@ sources = [
'src/Toolkit/Debuggable.hpp', 'src/Toolkit/Debuggable.hpp',
'src/Toolkit/EasingFunctions.hpp', 'src/Toolkit/EasingFunctions.hpp',
'src/Toolkit/EasingFunctions.cpp', 'src/Toolkit/EasingFunctions.cpp',
'src/Toolkit/ExtraCerealTypes/GHCFilesystemPath.hpp',
'src/Toolkit/GHCFilesystemPathHash.hpp',
'src/Toolkit/HSL.hpp', 'src/Toolkit/HSL.hpp',
'src/Toolkit/HSL.cpp', 'src/Toolkit/HSL.cpp',
'src/Toolkit/NormalizedOrigin.hpp', 'src/Toolkit/NormalizedOrigin.hpp',

View File

@ -1,11 +1,12 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <ghc/filesystem.hpp>
#include <fstream> #include <fstream>
#include <cereal/archives/json.hpp> #include <cereal/archives/json.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/unordered_map.hpp> #include <cereal/types/unordered_map.hpp>
#include <ghc/filesystem.hpp>
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include "Buttons.hpp" #include "Buttons.hpp"
@ -60,7 +61,7 @@ namespace Data {
template<class Archive> template<class Archive>
void serialize(Archive & archive) { void serialize(Archive & archive) {
archive( archive(
CEREAL_NVP(marker), CEREAL_NVP(marker)
); );
} }
}; };

View File

@ -9,10 +9,6 @@
#include <cereal/archives/json.hpp> #include <cereal/archives/json.hpp>
#include "../Toolkit/GHCFilesystemPathHash.hpp"
namespace fs = ghc::filesystem;
namespace Resources { namespace Resources {
Marker::Marker(const fs::path& marker_folder) : Marker::Marker(const fs::path& marker_folder) :
@ -92,7 +88,7 @@ namespace Resources {
ss << " lasts " << metadata.count/static_cast<float>(m_metadata.fps)*1000.f << "ms"; ss << " lasts " << metadata.count/static_cast<float>(m_metadata.fps)*1000.f << "ms";
ss << " (" << metadata.count << "f @ " << m_metadata.fps << "fps)"; ss << " (" << metadata.count << "f @ " << m_metadata.fps << "fps)";
ss << " which is more than the maximum of " << 16.f/30.f*1000.f << "ms"; ss << " which is more than the maximum of " << 16.f/30.f*1000.f << "ms";
ss << ' (16f @ 30fps)'; ss << " (16f @ 30fps)";
throw std::invalid_argument(ss.str()); throw std::invalid_argument(ss.str());
} }
} }
@ -117,6 +113,8 @@ namespace Resources {
case MarkerAnimation::PERFECT: case MarkerAnimation::PERFECT:
return m_perfect; return m_perfect;
break; break;
default:
throw std::runtime_error("wtf ?");
} }
} }
@ -140,6 +138,8 @@ namespace Resources {
case MarkerAnimation::PERFECT: case MarkerAnimation::PERFECT:
return m_metadata.perfect; return m_metadata.perfect;
break; break;
default:
throw std::runtime_error("wtf ?");
} }
} }

View File

@ -7,7 +7,17 @@
#include <ghc/filesystem.hpp> #include <ghc/filesystem.hpp>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include "../Toolkit/ExtraCerealTypes/GHCFilesystemPath.hpp" namespace fs = ghc::filesystem;
template <class Archive>
std::string save_minimal(const Archive &, ghc::filesystem::path& p) {
return p.string();
}
template <class Archive>
void load_minimal(const Archive &, ghc::filesystem::path& p, const std::string& value) {
p = fs::path{value};
}
namespace Resources { namespace Resources {
enum class MarkerAnimation { enum class MarkerAnimation {
@ -26,11 +36,11 @@ namespace Resources {
std::size_t rows; // how many vertically std::size_t rows; // how many vertically
template<class Archive> template<class Archive>
void serialize(Archive & archive) const { void serialize(Archive& archive) {
archive( archive(
CEREAL_NVP(sprite_sheet), CEREAL_NVP(sprite_sheet),
CEREAL_NVP(count), CEREAL_NVP(count),
CEREAL_NVP(column), CEREAL_NVP(columns),
CEREAL_NVP(rows) CEREAL_NVP(rows)
); );
} }
@ -49,7 +59,7 @@ namespace Resources {
MarkerAnimationMetadata perfect; MarkerAnimationMetadata perfect;
template<class Archive> template<class Archive>
void serialize(Archive & archive) const { void serialize(Archive & archive) {
archive( archive(
CEREAL_NVP(name), CEREAL_NVP(name),
CEREAL_NVP(size), CEREAL_NVP(size),
@ -65,7 +75,7 @@ namespace Resources {
}; };
struct Marker { struct Marker {
explicit Marker(const ghc::filesystem::path& marker_folder); Marker(const fs::path& marker_folder);
std::optional<sf::Sprite> get_sprite(const MarkerAnimation& state, const float& seconds); std::optional<sf::Sprite> get_sprite(const MarkerAnimation& state, const float& seconds);
std::optional<sf::Sprite> get_sprite(const MarkerAnimation& state, const std::size_t frame); std::optional<sf::Sprite> get_sprite(const MarkerAnimation& state, const std::size_t frame);
void load_and_check(sf::Texture& spritesheet, const MarkerAnimationMetadata& metadata); void load_and_check(sf::Texture& spritesheet, const MarkerAnimationMetadata& metadata);

View File

@ -11,7 +11,7 @@
#include "../../Drawables/BlackFrame.hpp" #include "../../Drawables/BlackFrame.hpp"
#include "../../Resources/Marker.hpp" #include "../../Resources/Marker.hpp"
#include "../../Toolkit/AffineTransform.hpp" #include "../../Toolkit/AffineTransform.hpp"
#include "SongListRibbon.hpp" #include "Ribbon.hpp"
#include "SongInfo.hpp" #include "SongInfo.hpp"
#include "SharedResources.hpp" #include "SharedResources.hpp"
#include "ButtonHighlight.hpp" #include "ButtonHighlight.hpp"
@ -39,7 +39,7 @@ namespace MusicSelect {
Resources::Markers markers; Resources::Markers markers;
// State // State
SongListRibbon ribbon; Ribbon ribbon;
SongInfo song_info; SongInfo song_info;
std::optional<std::reference_wrapper<SongPanel>> selected_panel; std::optional<std::reference_wrapper<SongPanel>> selected_panel;
ButtonHighlight button_highlight; ButtonHighlight button_highlight;

View File

@ -18,5 +18,5 @@ namespace MusicSelect {
void click(const Data::Button& button); void click(const Data::Button& button);
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states); void draw(sf::RenderTarget& target, sf::RenderStates states);
} };
} }

View File

@ -76,7 +76,7 @@ namespace MusicSelect {
return (m_position + (Data::button_to_index(button) % 4)) % m_layout.size(); return (m_position + (Data::button_to_index(button) % 4)) % m_layout.size();
} }
jbcoe::polymorphic_value<Panel>& Ribbon::get_panel_under_button(const Data::Button& button) const { jbcoe::polymorphic_value<Panel>& Ribbon::get_panel_under_button(const Data::Button& button) {
auto button_index = Data::button_to_index(button); auto button_index = Data::button_to_index(button);
return ( return (
m_layout m_layout
@ -116,7 +116,7 @@ namespace MusicSelect {
if (std::any_of( if (std::any_of(
column.begin(), column.begin(),
column.end(), column.end(),
[](std::shared_ptr<Panel> panel) -> bool { [](jbcoe::polymorphic_value<Panel> panel) -> bool {
return (std::dynamic_pointer_cast<CategoryPanel>(panel).get() != nullptr); return (std::dynamic_pointer_cast<CategoryPanel>(panel).get() != nullptr);
} }
)) { )) {

View File

@ -40,7 +40,7 @@ namespace MusicSelect {
class Ribbon : public sf::Drawable, public sf::Transformable, public HoldsSharedResources, public Toolkit::Debuggable { class Ribbon : public sf::Drawable, public sf::Transformable, public HoldsSharedResources, public Toolkit::Debuggable {
public: public:
Ribbon(PanelLayout layout, SharedResources& t_resources); Ribbon(PanelLayout layout, SharedResources& t_resources);
jbcoe::polymorphic_value<Panel>& get_panel_under_button(const Data::Button& button) const; jbcoe::polymorphic_value<Panel>& get_panel_under_button(const Data::Button& button);
void click_on(const Data::Button& button); void click_on(const Data::Button& button);
void move_right(); void move_right();
void move_left(); void move_left();

View File

@ -2,13 +2,12 @@
#include <string> #include <string>
#include <cereal/cereal.hpp> #include <cereal/details/traits.hpp>
#include <cereal/types/string.hpp>
#include <ghc/filesystem.hpp> #include <ghc/filesystem.hpp>
template <class Archive> template <class Archive>
std::string save_minimal(const Archive &, const ghc::filesystem::path & p) { std::string save_minimal(const Archive &, ghc::filesystem::path& p) {
return p.string(); return p.string();
} }