How would this code be better?

#1
Hi, sometimes [ex: when I use "Time" node by connecting into "RayCastCamera" node's input in Flowgraph] I want to get the output If It has changed. Sometimes there is no reason to take the same output every frame and also it is an optimization problem as far as I observe.
So, keeping in mind that I'm a coder who is met with Visual Studio very close time ago and I wrote a code like that by the permission of ALLAH and yes, I guess maybe there are many problems but, If you would tell me that how can I make It better in terms of optimization and etc...
It could be good. I can build the project.
But, I would like to know that are there many problems in my code or not?
If there are errors in my text, just don't care :)

Here:

Code: Select all

#include "StdAfx.h"
#include <CryFlowGraph/IFlowBaseNode.h>

class CFlowNode_OnChangeString : public CFlowBaseNode<eNCT_Singleton>
{
protected:
   float checkTriggerCount = 0;
   string checkAlwaysValue = "";
   string checkFirstValue = "";
   string checkSecondValue = "";
public:
   CFlowNode_OnChangeString(SActivationInfo* pActInfo)
   {
   };
   ~CFlowNode_OnChangeString() {};

   enum
   {
      EIP_Check = 0,
      EIP_String,
      EIP_Reset,
   };
   enum
   {
      EOP_Out = 0,
      EOP_Result,
      EOP_Reset,
   };

   virtual void GetConfiguration(SFlowNodeConfig& config) override
   {

      static const SInputPortConfig inputPorts[] =
      {
         InputPortConfig_Void("Check",_HELP("")),
         InputPortConfig<string>("String",_HELP("")),
         InputPortConfig_Void("Reset",_HELP("")),
         {0}
      };

      static const SOutputPortConfig outputPorts[] =
      {
         OutputPortConfig_Void("Out",_HELP("")),
         OutputPortConfig_Void("Reset",_HELP("")),
         {0}
      };

      config.pInputPorts = inputPorts;
      config.pOutputPorts = outputPorts;
      config.sDescription = "";
      config.SetCategory(EFLN_APPROVED);

   };

   virtual void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo) override
   {
      switch (event)
      {
      case eFE_Activate:
      {


         if (IsPortActive(pActInfo, EIP_Check))
         {

            checkAlwaysValue = GetPortString(pActInfo, EIP_String);

            if (checkTriggerCount == 0)
            {

               checkTriggerCount = 1;

               checkFirstValue = checkAlwaysValue;
               
            };

            if (checkTriggerCount == 1)
            {

               if (checkAlwaysValue != checkFirstValue)
               {
                  ActivateOutput(pActInfo, EOP_Out, true);

                  checkSecondValue = checkAlwaysValue;
                  checkTriggerCount = 2;

               };
            };

            if (checkTriggerCount == 2)
            {

               if (checkAlwaysValue != checkSecondValue)
               {

                  ActivateOutput(pActInfo, EOP_Out, true);

                  checkFirstValue = checkAlwaysValue;

                  checkTriggerCount = 1;
               };

            };

         };


         if (IsPortActive(pActInfo, EIP_Reset))
         {
            checkTriggerCount = 0;
            checkAlwaysValue = "";
            checkFirstValue = "";
            checkSecondValue = "";
            ActivateOutput(pActInfo, EOP_Reset, true);
         };


      }break;


      case eFE_Initialize:
      {

         checkTriggerCount = 0;
         checkAlwaysValue = "";
         checkFirstValue = "";
         checkSecondValue = "";

      }break;
      };

   };

   virtual void GetMemoryUsage(ICrySizer* s) const
   {
      s->Add(*this);
   }
};

REGISTER_FLOW_NODE("Logic:OnChangeString", CFlowNode_OnChangeString);

Who is online

Users browsing this forum: Bing [Bot] and 2 guests