began new infrastructure

Yep, this is another one of my "famous" sweeping rewrites. Expect things to break.

Goals for this are:
- Greatly simplify node connections (particularly with arrays) so the code requires less maintenance/is more stable
- Redesign node structure to address issues where UI would stall for lengthy periods of time
- Less reliance on shared ptrs/greater reliance on QObject system for inheritance/memory management
- General code cleanup and improvements
This commit is contained in:
itsmattkc
2021-01-05 11:20:38 +11:00
parent 19eabf2830
commit 181235f6ce
152 changed files with 3932 additions and 8166 deletions
+18 -119
View File
@@ -24,87 +24,50 @@
namespace olive {
NodeEdgeAddCommand::NodeEdgeAddCommand(NodeOutput *output, NodeInput *input, QUndoCommand *parent) :
NodeEdgeAddCommand::NodeEdgeAddCommand(Node *output, NodeInput *input, int element, QUndoCommand *parent) :
UndoCommand(parent),
output_(output),
input_(input),
old_edge_(nullptr),
done_(false)
element_(element)
{
}
void NodeEdgeAddCommand::redo_internal()
{
if (done_) {
return;
}
old_edge_ = NodeParam::DisconnectForNewOutput(input_);
NodeParam::ConnectEdge(output_, input_);
done_ = true;
Node::ConnectEdge(output_, input_, element_);
}
void NodeEdgeAddCommand::undo_internal()
{
if (!done_) {
return;
}
NodeParam::DisconnectEdge(output_, input_);
if (old_edge_ != nullptr) {
NodeParam::ConnectEdge(old_edge_->output(), old_edge_->input());
}
done_ = false;
Node::DisconnectEdge(output_, input_, element_);
}
Project *NodeEdgeAddCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(output_->parentNode()->parent())->project();
return output_->parent()->project();
}
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(NodeOutput *output, NodeInput *input, QUndoCommand *parent) :
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(Node *output, NodeInput *input, int element, QUndoCommand *parent) :
UndoCommand(parent),
output_(output),
input_(input),
done_(false)
{
}
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(NodeEdgePtr edge, QUndoCommand *parent) :
UndoCommand(parent),
output_(edge->output()),
input_(edge->input()),
done_(false)
element_(element)
{
}
void NodeEdgeRemoveCommand::redo_internal()
{
if (done_) {
return;
}
NodeParam::DisconnectEdge(output_, input_);
done_ = true;
Node::DisconnectEdge(output_, input_, element_);
}
void NodeEdgeRemoveCommand::undo_internal()
{
if (!done_) {
return;
}
NodeParam::ConnectEdge(output_, input_);
done_ = false;
Node::ConnectEdge(output_, input_, element_);
}
Project *NodeEdgeRemoveCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(output_->parentNode()->parent())->project();
return output_->parent()->project();
}
NodeAddCommand::NodeAddCommand(NodeGraph *graph, Node *node, QUndoCommand *parent) :
@@ -118,75 +81,34 @@ NodeAddCommand::NodeAddCommand(NodeGraph *graph, Node *node, QUndoCommand *paren
void NodeAddCommand::redo_internal()
{
graph_->AddNode(node_);
node_->setParent(graph_);
}
void NodeAddCommand::undo_internal()
{
graph_->TakeNode(node_, &memory_manager_);
node_->setParent(&memory_manager_);
}
Project *NodeAddCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(graph_)->project();
return graph_->project();
}
NodeRemoveCommand::NodeRemoveCommand(NodeGraph *graph, const QVector<Node *> &nodes, QUndoCommand *parent) :
NodeRemoveCommand::NodeRemoveCommand(Node *node, QUndoCommand *parent) :
UndoCommand(parent),
graph_(graph),
nodes_(nodes)
graph_(node->parent()),
node_(node)
{
}
void NodeRemoveCommand::redo_internal()
{
// Cache edges for undoing
foreach (Node* n, nodes_) {
foreach (NodeParam* param, n->parameters()) {
foreach (NodeEdgePtr edge, param->edges()) {
// Ensures the same edge isn't added twice (prevents double connecting when undoing)
if (!edges_.contains(edge)) {
edges_.append(edge);
}
}
}
}
// Take nodes from graph (TakeNode() will automatically disconnect edges)
foreach (Node* n, nodes_) {
// If the node is a block, unlink any linked blocks before removing
if (n->IsBlock()) {
Block *b = static_cast<Block *>(n);
if (b->HasLinks()) {
BlockUnlinkAllCommand *unlink_command = new BlockUnlinkAllCommand(b);
unlink_command->redo();
block_unlink_commands_.append(unlink_command);
}
}
graph_->TakeNode(n, &memory_manager_);
}
node_->setParent(&memory_manager_);
}
void NodeRemoveCommand::undo_internal()
{
// Re-add nodes to graph
foreach (Node* n, nodes_) {
graph_->AddNode(n);
}
// Relink any blocks that were unlinked
foreach(BlockUnlinkAllCommand* command, block_unlink_commands_) {
command->undo();
delete command;
}
// Re-connect edges
foreach (NodeEdgePtr edge, edges_) {
NodeParam::ConnectEdge(edge->output(), edge->input());
}
edges_.clear();
block_unlink_commands_.clear();
node_->setParent(graph_);
}
Project *NodeRemoveCommand::GetRelevantProject() const
@@ -194,21 +116,6 @@ Project *NodeRemoveCommand::GetRelevantProject() const
return static_cast<Sequence*>(graph_)->project();
}
NodeRemoveWithExclusiveDeps::NodeRemoveWithExclusiveDeps(NodeGraph *graph, Node *node, QUndoCommand *parent) :
UndoCommand(parent)
{
QVector<Node*> node_and_its_deps;
node_and_its_deps.append(node);
node_and_its_deps.append(node->GetExclusiveDependencies());
remove_command_ = new NodeRemoveCommand(graph, node_and_its_deps, this);
}
Project *NodeRemoveWithExclusiveDeps::GetRelevantProject() const
{
return remove_command_->GetRelevantProject();
}
NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, bool include_connections, QUndoCommand *parent) :
QUndoCommand(parent),
src_(src),
@@ -217,14 +124,6 @@ NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, bool include
{
}
NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, QUndoCommand *parent) :
QUndoCommand(parent),
src_(src),
dest_(dest),
include_connections_(true)
{
}
void NodeCopyInputsCommand::redo()
{
Node::CopyInputs(src_, dest_, include_connections_);