struct GridWalkerState
{
ULONG m_nRandomSequencePosition;
ULONG m_nCurrentStep;
LONG m_nCurrentPositionX, m_nCurrentPositionY;
LONG m_nDirectionX, m_nDirectionY;
GridWalkerState()
{
m_nRandomSequencePosition = 0;
m_nCurrentStep = 0;
m_nCurrentPositionX = 0;
m_nCurrentPositionY = 0;
m_nDirectionX = 0;
m_nDirectionY = 0;
}
GridWalkerState( ULONG in_nRandomSequencePosition,
ULONG in_nCurrentStep,
ULONG in_nCurrentPositionX,
ULONG in_nCurrentPositionY,
ULONG in_nDirectionX,
ULONG in_nDirectionY)
{
m_nRandomSequencePosition = in_nRandomSequencePosition;
m_nCurrentStep = in_nCurrentStep;
m_nCurrentPositionX = in_nCurrentPositionX;
m_nCurrentPositionY = in_nCurrentPositionY;
m_nDirectionX = in_nDirectionX;
m_nDirectionY = in_nDirectionY;
}
const GridWalkerState& operator=(const GridWalkerState& other)
{
m_nRandomSequencePosition = other.m_nRandomSequencePosition;
m_nCurrentStep = other.m_nCurrentStep;
m_nCurrentPositionX = other.m_nCurrentPositionX;
m_nCurrentPositionY = other.m_nCurrentPositionY;
m_nDirectionX = other.m_nDirectionX;
m_nDirectionY = other.m_nDirectionY;
return *this;
}
operator CString() const
{
CString result;
result = L"[";
result += L"Random Sequence Pos:";
result += CString(m_nRandomSequencePosition) + CString(L", ");
result += L"Step:";
result += CString(m_nCurrentStep) + L", ";
result += L"X:";
result += CString(m_nCurrentPositionX) + L", ";
result += L"Y:";
result += CString(m_nCurrentPositionY) + L", ";
result += L"Dir X:";
result += CString(m_nDirectionX) + L", ";
result += L"Dir Y:";
result += CString(m_nDirectionY);
result += L"]";
return result;
}
};
template < class CustomType >
class CICEAttributeDataLoggerCustomType
{
public:
static void Log( ICEAttribute& attr )
{
CICEAttributeDataArrayCustomType data;
attr.GetDataArray( data );
Application xsi;
for( ULONG i=0; i<data.GetCount( ); i++ )
{
CustomType val;
const CICEAttributeDataArrayCustomType::TData* addr = NULL;
ULONG size=0;
data.GetData(i, &addr, size);
if (addr != NULL && size>0)
{
val = *(CustomType*)addr;
xsi.LogMessage( CString(val) );
}
}
}
};
Application app;
CString strWrkgrp = CUtils::BuildPath( app.GetInstallationPath(siFactoryPath ), "..", "..", "Rayflex", "Sdk", "examples", "workgroup" );
app.AddWorkgroup( strWrkgrp );
CValueArray args(2);
CValue retval;
args[0] = CUtils::BuildPath( strWrkgrp, "Addons", "CustomICENodes", "Data", "Project", "Scenes", "GridWalker" ) + ".scn";
args[1] = false;
app.ExecuteCommand( "OpenScene", args, retval );
CStringArray strNoFamily;
CString strNoType;
Geometry geom( app.GetActiveSceneRoot().FindChild("grid", strNoType, strNoFamily).GetActivePrimitive().GetGeometry() );
ICEAttribute attr = geom.GetICEAttributeFromName( "GridWalkerState" );
{
typedef GridWalkerState* CustomTypePtr;
CICEAttributeDataArrayCustomType data;
attr.GetDataArray( data );
CICEAttributeDataLoggerCustomType<GridWalkerState>::Log( attr );
ULONG l_nbElem = attr.GetElementCount();
{
CustomTypePtr* l_Values = new CustomTypePtr[l_nbElem];
for (ULONG i=0; i<l_nbElem; i++)
{
if (i%2==0)
l_Values[i] = new GridWalkerState(0, 0, 0, 0, 0, 0);
else
l_Values[i] = new GridWalkerState(1, 1, 1, 1, 1, 1);
}
data.SetArray((const unsigned char**)l_Values, l_nbElem, sizeof(GridWalkerState));
CICEAttributeDataLoggerCustomType<GridWalkerState>::Log( attr );
for (ULONG i=0; i<l_nbElem; i++)
{
delete l_Values[i];
}
delete[] l_Values;
}
{
const ULONG CHUNK_SIZE = 10;
CustomTypePtr* l_Values = new CustomTypePtr[CHUNK_SIZE];
for (ULONG i=0; i<CHUNK_SIZE; i++)
{
l_Values[i] = new GridWalkerState(i + 2, i + 2, i + 2, i + 2, i + 2, i + 2);
}
CICEAttributeDataArrayCustomType dataChunk;
attr.GetDataArrayChunk(2, CHUNK_SIZE, dataChunk);
data.SetArray((const unsigned char**)l_Values, CHUNK_SIZE, sizeof(GridWalkerState));
CICEAttributeDataLoggerCustomType<GridWalkerState>::Log( attr );
for (ULONG i=0; i<CHUNK_SIZE; i++)
{
delete l_Values[i];
}
delete[] l_Values;
}
}