Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New propagation, including N-1 splitters and mergers and locking, mostly done #10

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions ficsit-companion/include/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,51 @@ class App
/// @brief Save current session (should NOT require an active ImGui context)
void SaveSession();

private:
/// @brief Used in saved files to track when format change. Used to update files saved with previous versions
static constexpr int SAVE_VERSION = 2;

/// @brief Window id used for the Add Node popup
static constexpr std::string_view add_node_popup_id = "Add Node";
/// @brief Folder to save/load the serialized graph
static constexpr std::string_view save_folder = "saved";
/// @brief Path used to save current session file
static constexpr std::string_view session_file = "last_session.fcs";


/// @brief Version of the game the items/recipes are from
std::string recipes_version;
/// @brief All known items
std::unordered_map<std::string, std::unique_ptr<Item>> items;
/// @brief All known recipes
std::vector<Recipe> recipes;

/// @brief All nodes currently in the graph view
std::vector<std::unique_ptr<Node>> nodes;
/// @brief All links currently in the graph view
std::vector<std::unique_ptr<Link>> links;

ax::NodeEditor::Config config;
ax::NodeEditor::EditorContext* context;

/// @brief Next available id for a node/link in the graph view
unsigned long long int next_id;

double last_time_saved_session;

/* Values used during the rendering pass to save UI state between frames */
std::string save_name;
std::vector<std::pair<std::string, size_t>> file_suggestions;
bool popup_opened;
ImVec2 new_node_position;
Pin* new_node_pin;
std::string recipe_filter;
std::vector<std::string> frame_tooltips;

enum class Constraint { None, Weak, Strong };
/// @brief All pins which had their value changed and need to propagate updates
std::queue<std::pair<const Pin*, Constraint>> updating_pins;

private:
/// @brief Load saved session if present
void LoadSession();
Expand Down Expand Up @@ -93,49 +138,4 @@ class App
/// @brief React to app-specific key pressed
void CustomKeyControl();

private:
/// @brief Used in saved files to track when format change. Used to update files saved with previous versions
static constexpr int SAVE_VERSION = 2;

/// @brief Window id used for the Add Node popup
static constexpr std::string_view add_node_popup_id = "Add Node";
/// @brief Folder to save/load the serialized graph
static constexpr std::string_view save_folder = "saved";
/// @brief Path used to save current session file
static constexpr std::string_view session_file = "last_session.fcs";


/// @brief Version of the game the items/recipes are from
std::string recipes_version;
/// @brief All known items
std::unordered_map<std::string, std::unique_ptr<Item>> items;
/// @brief All known recipes
std::vector<Recipe> recipes;

/// @brief All nodes currently in the graph view
std::vector<std::unique_ptr<Node>> nodes;
/// @brief All links currently in the graph view
std::vector<std::unique_ptr<Link>> links;

ax::NodeEditor::Config config;
ax::NodeEditor::EditorContext* context;

/// @brief Next available id for a node/link in the graph view
unsigned long long int next_id;

double last_time_saved_session;

/* Values used during the rendering pass to save UI state between frames */
std::string save_name;
std::vector<std::pair<std::string, size_t>> file_suggestions;
bool popup_opened;
ImVec2 new_node_position;
Pin* new_node_pin;
std::string recipe_filter;
std::vector<std::string> frame_tooltips;

enum class Constraint { None, Weak, Strong };
/// @brief All pins which had their value changed and need to propagate updates
std::queue<std::pair<const Pin*, Constraint>> updating_pins;

};
11 changes: 11 additions & 0 deletions ficsit-companion/include/link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <imgui_node_editor.h>

struct Pin;
struct MetaPin;

struct Link
{
Expand All @@ -25,3 +26,13 @@ struct Link

std::optional<ax::NodeEditor::FlowDirection> flow;
};

struct MetaLink : public Link
{
MetaLink(const ax::NodeEditor::LinkId id, MetaPin* start, MetaPin* end);
~MetaLink();

MetaPin* start;
MetaPin* end;

};
19 changes: 15 additions & 4 deletions ficsit-companion/include/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
struct Item;
struct Pin;
struct Recipe;
struct MetaPin;

struct Node
{
enum class Kind
{
Craft,
Splitter,
Merger
Merger,
Meta
};

Node(const ax::NodeEditor::NodeId id);
Expand All @@ -32,7 +34,7 @@ struct Node
virtual bool IsMerger() const;
virtual bool IsSplitter() const;
virtual Json::Value Serialize() const;
virtual bool Deserialize(const Json::Value& v);
virtual bool Deserialize(const Json::Value& v, const std::function<unsigned long long int()>& id_generator);

const ax::NodeEditor::NodeId id;

Expand All @@ -49,7 +51,7 @@ struct CraftNode : public Node
virtual Kind GetKind() const override;
virtual bool IsCraft() const override;
virtual Json::Value Serialize() const override;
virtual bool Deserialize(const Json::Value& v) override;
virtual bool Deserialize(const Json::Value& v, const std::function<unsigned long long int()>& id_generator) override;

const Recipe* recipe;
FractionalNumber current_rate;
Expand All @@ -61,7 +63,7 @@ struct OrganizerNode : public Node
virtual ~OrganizerNode();
virtual bool IsOrganizer() const override;
virtual Json::Value Serialize() const override;
virtual bool Deserialize(const Json::Value& v) override;
virtual bool Deserialize(const Json::Value& v, const std::function<unsigned long long int()>& id_generator) override;

void ChangeItem(const Item* item);
void RemoveItemIfNotForced();
Expand All @@ -87,3 +89,12 @@ struct MergerNode : public OrganizerNode

virtual Kind GetKind() const override;
};

struct MetaNode : public Node
{
MetaNode(const ax::NodeEditor::NodeId id);
virtual ~MetaNode();
virtual Kind GetKind() const override;
std::vector<std::unique_ptr<MetaPin>> ins;
std::vector<std::unique_ptr<MetaPin>> outs;
};
15 changes: 15 additions & 0 deletions ficsit-companion/include/pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct Node;
struct Item;
struct Link;
struct CountedItem;
struct MetaNode;
struct MetaLink;

struct Pin
{
Expand All @@ -22,6 +24,19 @@ struct Pin
const FractionalNumber base_rate;
// A pin can have at most one link
Link* link;
bool locked;

FractionalNumber current_rate;
};

struct MetaPin : public Pin
{
MetaPin(const ax::NodeEditor::PinId id, const ax::NodeEditor::PinKind direction,
MetaNode* node, Pin* pin, FractionalNumber& meta_rate = FractionalNumber(0, 1));
~MetaPin();

FractionalNumber meta_rate;
Pin* pin;
MetaNode* node;
MetaLink* link;
};
Loading
Loading