@@ -29,7 +29,7 @@ public class ExternalDecision<TS, TA> : IAgentDecision<TS, TA>
2929 private const int ACTUATOR_DATA_POSITION = 100001 ;
3030
3131
32- private float [ ] actuatorData = new float [ 0 ] ;
32+ private TA [ ] actuatorData = new TA [ 0 ] ;
3333
3434
3535
@@ -58,15 +58,21 @@ public ExternalDecision()
5858 Debug . Log ( "Is Ready to Communicate" ) ;
5959 }
6060
61- public void BatchProcess ( ref NativeArray < TS > sensors , ref NativeArray < TA > actuators )
61+ public void BatchProcess ( ref NativeArray < TS > sensors , ref NativeArray < TA > actuators , int offset = 0 , int size = - 1 )
6262 {
63- Profiler . BeginSample ( "Communicating " ) ;
63+ Profiler . BeginSample ( "__Communicating " ) ;
6464
65+ Profiler . BeginSample ( "__TypeCheck" ) ;
6566 VerifySensor ( typeof ( TS ) ) ;
6667 VerifyActuator ( typeof ( TA ) ) ;
68+ if ( size == - 1 ) {
69+ size = sensors . Length - offset ;
70+ }
71+ Profiler . EndSample ( ) ;
6772
68- int batch = sensors . Length ;
69- if ( batch != actuators . Length )
73+ Profiler . BeginSample ( "__VerifyLength" ) ;
74+ int batch = size ;
75+ if ( sensors . Length != actuators . Length )
7076 {
7177 throw new Exception ( "Error in the length of the sensors and actuators" ) ;
7278 }
@@ -78,21 +84,23 @@ public void BatchProcess(ref NativeArray<TS> sensors, ref NativeArray<TA> actuat
7884
7985 if ( actuatorData . Length < _actuatorSize * batch )
8086 {
81- actuatorData = new float [ _actuatorSize * batch ] ;
87+ actuatorData = new TA [ batch ] ;
8288 }
89+ Profiler . EndSample ( ) ;
8390
84-
91+ Profiler . BeginSample ( "__Write" ) ;
8592 accessor . Write ( NUMBER_AGENTS_POSITION , batch ) ;
8693 accessor . Write ( SENSOR_SIZE_POSITION , _sensorSize ) ;
8794 accessor . Write ( ACTUATOR_SIZE_POSITION , _actuatorSize ) ;
8895
89- accessor . WriteArray ( SENSOR_DATA_POSITION , sensors . ToArray ( ) , 0 , batch ) ;
96+ accessor . WriteArray ( SENSOR_DATA_POSITION , sensors . Slice ( offset , batch ) . ToArray ( ) , 0 , batch ) ;
9097
9198 accessor . Write ( PYTHON_READY_POSITION , false ) ;
9299
93100 accessor . Write ( UNITY_READY_POSITION , true ) ;
101+ Profiler . EndSample ( ) ;
94102
95-
103+ Profiler . BeginSample ( "__Wait" ) ;
96104 var readyToContinue = false ;
97105 int loopIter = 0 ;
98106 while ( ! readyToContinue )
@@ -105,22 +113,20 @@ public void BatchProcess(ref NativeArray<TS> sensors, ref NativeArray<TA> actuat
105113 Debug . Log ( "Missed Communication" ) ;
106114 }
107115 }
116+ Profiler . EndSample ( ) ;
108117
109- accessor . ReadArray ( ACTUATOR_DATA_POSITION , actuatorData , 0 , batch * _actuatorSize ) ;
118+ Profiler . BeginSample ( "__Read" ) ;
119+ accessor . ReadArray ( ACTUATOR_DATA_POSITION , actuatorData , 0 , batch ) ;
110120
111- // actuator .CopyFrom(actuatorData);
121+ actuators . Slice ( offset , batch ) . CopyFrom ( actuatorData ) ;
112122
113- var tmpA = new NativeArray < float > ( batch * _actuatorSize , Allocator . Persistent ) ;
114- tmpA . CopyFrom ( actuatorData ) ;
115- for ( var i = 0 ; i < batch ; i ++ ) {
116- var act = new TA ( ) ;
117- TensorUtility . CopyFromNativeArray ( tmpA , out act , i * _sensorSize * 4 ) ;
118- actuators [ i ] = act ;
119- }
120- tmpA . Dispose ( ) ;
123+ // for(var i = 0; i< batch; i++){
124+ // actuators[i] = actuatorData[i];
125+ // }
121126
127+ Profiler . EndSample ( ) ;
128+ Profiler . EndSample ( ) ;
122129
123- Profiler . BeginSample ( "Communicating" ) ;
124130 }
125131
126132 private void VerifySensor ( System . Type t ) {
0 commit comments