58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
#include "shaders/IShaderGraphNodePort.h"
|
|
#include <assert.h>
|
|
|
|
namespace LifeGraphics
|
|
{
|
|
IShaderGraphNodePort::IShaderGraphNodePort(IShaderGraphNode* parent)
|
|
:Parent(parent)
|
|
{
|
|
assert(parent != nullptr && "Shader graph node port parent is nullptr!");
|
|
}
|
|
|
|
IShaderGraphNodePort* IShaderGraphNodePort::GetLink(size_t id)
|
|
{
|
|
return links[id];
|
|
}
|
|
size_t IShaderGraphNodePort::GetLinkCount()
|
|
{
|
|
return links.size();
|
|
}
|
|
void IShaderGraphNodePort::MakeLink(IShaderGraphNodePort* input, IShaderGraphNodePort* output)
|
|
{
|
|
// assert(target != nullptr && "Failed on add link on IShaderGraphNodePort");
|
|
if(!input->IsLinkExists(output))
|
|
input->links.push_back(output);
|
|
|
|
if(!output->IsLinkExists(input))
|
|
output->links.push_back(input);
|
|
}
|
|
bool IShaderGraphNodePort::IsLinkExists(IShaderGraphNodePort* target)
|
|
{
|
|
for(LinkCollectonItr it = links.begin(); it != links.end(); ++it)
|
|
{
|
|
if(*it == target)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
void IShaderGraphNodePort::BreakLink()
|
|
{
|
|
//remove self from remote ports
|
|
for(LinkCollectonItr it = links.begin(); it != links.end(); ++it) {
|
|
(*it)->RemoveLink(this);
|
|
}
|
|
//clear list of remote ports
|
|
links.clear();
|
|
}
|
|
void IShaderGraphNodePort::RemoveLink(IShaderGraphNodePort* target)
|
|
{
|
|
for(LinkCollectonItr it = links.begin(); it != links.end(); ++it)
|
|
{
|
|
IShaderGraphNodePort* lnk = *it;
|
|
if(lnk == target){
|
|
links.erase(it);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |