Регистрация своего flowgraph нода

Материал из CryWiki Russia

Перейти к: навигация, поиск



Пошаговое руководств по примеру C++

Создайте в своем проекте новый cpp файл (например "MyCryNode.cpp"), добавьте туда данный код, скомпилируйте проект.

|

C++ (SimpleCryNode.cpp)

 
 
/*************************************************************************
-------------------------------------------------------------------------
History:
 
- 08.02.2015   13:03 : Created by AfroStalin(chernecoff)
-------------------------------------------------------------------------
 
*************************************************************************/
 
#include "StdAfx.h"
#include "Nodes/G2FlowBaseNode.h"
 
// CFlowNode_Название_Вашего_Нода p.s. Можете любое имя использовать для класса, но лучше используйте что-то понятное
class CFlowNode_SimpleCryNode : public CFlowBaseNode<eNCT_Instanced>
{
	// Ввод
	enum INPUTS 
	{
		EIP_Test = 0,
		EIP_String,
		EIP_Int,
		EIP_Vec3,
	};
 
	// Вывод
	enum OUTPUTS
	{
		EOP_String = 0,
		EOP_Int,
		EOP_Vec3,
	};
 
public:
	CFlowNode_SimpleCryNode( SActivationInfo * pActInfo )
	{
	}
 
	~CFlowNode_SimpleCryNode()
	{
	}
 
	IFlowNodePtr Clone(SActivationInfo* pActInfo)
	{
		return new CFlowNode_SimpleCryNode(pActInfo);
	}
 
	virtual void GetMemoryUsage(ICrySizer * s) const
	{
		s->Add(*this);
	}
 
	void GetConfiguration( SFlowNodeConfig& config )
	{
		// Ввод
		static const SInputPortConfig in_ports[] = 
		{
			// InputPortConfig<ТИП>("НАЗВАНИЕ_ПОРТА", _HELP("ОПИСАНИЕ НОДА"))
			InputPortConfig_Void( "TestFunc", _HELP("Test function")),
			InputPortConfig<string>("String", _HELP("String input")),
			InputPortConfig<int>("Int", _HELP("Int input")),
			InputPortConfig<Vec3>("Vec3", _HELP("Vec3 input")),
			{0}
		};
		// Вывод
		static const SOutputPortConfig out_ports[] = 
		{
			// OutputPortConfig<ТИП>("НАЗВАНИЕ_ПОРТА", _HELP("ОПИСАНИЕ НОДА"))
			OutputPortConfig<string>("String", _HELP("String out")),
			OutputPortConfig<int>("Int", _HELP("Int out")),
			OutputPortConfig<Vec3>("Vec3", _HELP("Vec3 out")),
			{0}
		};
		config.pInputPorts = in_ports;
		config.pOutputPorts = out_ports;
		config.sDescription = _HELP("SimpleCryNode"); // Общее описание нода
		config.SetCategory(EFLN_APPROVED);
	}
 
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Initialize:
			{
				m_actInfo = *pActInfo;
			}
			break;
		case eFE_Activate:
			{
				// Ecли активирован порт "Test" - получаем данные из входящих портов, вызываем функцию и выводим что то
				if(IsPortActive(pActInfo, EIP_Test))
				{
					// Получаем данные GetPortТип(pActInfo, номер порта входящих данных). Если у нас есть пустой вход без приема данных он не учитывается! 
					const string& string_input = GetPortString(pActInfo, 1);
					const int& int_input = GetPortInt(pActInfo, 2);
					const Vec3& vec3_input = GetPortVec3(pActInfo,3);
 
 
					// Вызываем функцию, передаем полученные данные
					TestFunction(string_input,int_input,vec3_input);
				}
			}
			break;
		}
	}
 
	// Просто выводим полученные данные через выходные порты
	void TestFunction(string string_input,int int_input, Vec3 vec3_input)
	{
		// ActivateOutput(&m_actInfo, НАЗВАНИЕ_ПОРТА_ВЫВОДА, ДАННЫЕ);
		ActivateOutput(&m_actInfo, EOP_String, string_input);
		ActivateOutput(&m_actInfo, EOP_Int, int_input);
		ActivateOutput(&m_actInfo, EOP_Vec3, vec3_input);
	}
 
protected:
	SActivationInfo m_actInfo;
};
 
// Регистрируем наш нод
//REGISTER_FLOW_NODE("КАТЕГОРИЯ:НАЗВАНИЕ_НОДА",	CFlowNode_НАЗВАНИЕ_ВАШЕГО_НОДА);
REGISTER_FLOW_NODE("SimplesNodes:SimpleCryNode",	CFlowNode_SimpleCryNode);

Об этом примере

Название

Простой flowgraph нод на c++

Создатель

AfroStalin (chernecoff)

Описание

Данный код позволяет создать и зарегистрировать свой собственный flowgraph нод.

» Другие примеры C++

» Вернуться к примерам кода