Use pre-allocated buffer in UDP server

This commit is contained in:
Travis Nickles 2019-07-02 02:06:32 -05:00
parent 827fe7c507
commit 1c869647ab
2 changed files with 10 additions and 4 deletions

View File

@ -58,6 +58,12 @@ namespace DS4Windows
}
private X360Data[] processingData = new X360Data[4];
private byte[][] udpOutBuffers = new byte[4][]
{
new byte[100], new byte[100],
new byte[100], new byte[100]
};
void GetPadDetailForIdx(int padIdx, ref DualShockPadMeta meta)
{
@ -474,7 +480,7 @@ namespace DS4Windows
{
DualShockPadMeta padDetail = new DualShockPadMeta();
GetPadDetailForIdx(tempIdx, ref padDetail);
_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx], udpOutBuffers[tempIdx]);
};
device.MotionEvent = tempEvnt;
@ -696,7 +702,7 @@ namespace DS4Windows
{
DualShockPadMeta padDetail = new DualShockPadMeta();
GetPadDetailForIdx(tempIdx, ref padDetail);
_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx], udpOutBuffers[tempIdx]);
};
device.MotionEvent = tempEvnt;

View File

@ -581,7 +581,7 @@ namespace DS4Windows
return true;
}
public void NewReportIncoming(ref DualShockPadMeta padMeta, DS4State hidReport)
public void NewReportIncoming(ref DualShockPadMeta padMeta, DS4State hidReport, byte[] outputData)
{
if (!running)
return;
@ -647,7 +647,7 @@ namespace DS4Windows
unchecked
{
byte[] outputData = new byte[100];
//byte[] outputData = new byte[100];
int outIdx = BeginPacket(outputData, 1001);
Array.Copy(BitConverter.GetBytes((uint)MessageType.DSUS_PadDataRsp), 0, outputData, outIdx, 4);
outIdx += 4;