public static int TestSendArray(ref UdkDynamicArray wrapper) { int valuesCount = wrapper.Count * 5; //*5 => 2 int point type + 3 float from Vector struct //var intArr = new int[valuesCount]; var floatArr = new float[valuesCount]; //int and floats are assumed to be both of 32 bits (but it is not everywhere true) //Marshal.Copy(wrapper.DataPtr, intArr, 0, valuesCount); Marshal.Copy(wrapper.DataPtr, floatArr, 0, valuesCount); var cells = new List<CellInfo>(); for (int i = 0; i < valuesCount; i += 5) { var cell = new CellInfo(); cell.PointType = floatArr[i]; cell.Pitch = floatArr[i + 1]; cell.Yaw = floatArr[i + 2]; cell.Roll = floatArr[i + 3]; cell.Point.X = floatArr[i + 4]; cell.Point.Y = floatArr[i + 5]; cell.Point.Z = floatArr[i + 6]; cells.Add(cell); } //ha ha ha here we have managedArray passed from UDK return 123;//managedArray.Length; }
public static bool CommitCells(int mapId, ref UdkDynamicArray wrapper) { int valuesCount = wrapper.Count * 7; //*5 => 2 int point type + 3 float from Vector struct //var intArr = new int[valuesCount]; var floatArr = new float[valuesCount]; //int and floats are assumed to be both of 32 bits (but it is not everywhere true) //Marshal.Copy(wrapper.DataPtr, intArr, 0, valuesCount); Marshal.Copy(wrapper.DataPtr, floatArr, 0, valuesCount); var cell = new CellInfo(); // Checking the commited data for consistency for (int i = 0; i < valuesCount; i += 7) { cell.PointType = floatArr[i]; cell.Pitch = floatArr[i + 1]; cell.Yaw = floatArr[i + 2]; cell.Roll = floatArr[i + 3]; cell.Point.X = floatArr[i + 4]; cell.Point.Y = floatArr[i + 5]; cell.Point.Z = floatArr[i + 6]; if ((cell.Point.X < 0 || cell.Point.X >= Grids[mapId].SizeX) || (cell.Point.Y < 0 || cell.Point.Y >= Grids[mapId].SizeY) || (cell.Point.Z < 0 || cell.Point.Z >= Grids[mapId].SizeZ)) return false; // coordinates out of range if (cell.PointType < 0 || cell.PointType > 4) return false; if (cell.Pitch < 0) return false; if (cell.Yaw < 0) return false; if (cell.Roll < 0) return false; } // Commiting data for (int i = 0; i < valuesCount; i += 7) { cell.PointType = floatArr[i]; cell.Pitch = floatArr[i + 1]; cell.Yaw = floatArr[i + 2]; cell.Roll = floatArr[i + 3]; cell.Point.X = floatArr[i + 4]; cell.Point.Y = floatArr[i + 5]; cell.Point.Z = floatArr[i + 6]; Grids[mapId][(int)cell.Point.X, (int)cell.Point.Y, (int)cell.Point.Z].Info = UdkInterfaceUtility.GetNodeInfo(cell); } return true; }