@@ -602,48 +602,181 @@ public DynamicBuffer<T> GetBufferIgnoreParallelSafety<T>(Entity entity) where T
602
602
}
603
603
}
604
604
605
- // Todo: These are disabled as they are not atomic
606
- //public EnabledRefRO<T> GetEnabledROIgnoreParallelSafety<T>(Entity entity) where T : unmanaged, IEnableableComponent
607
- //{
608
- // var typeIndex = TypeManager.GetTypeIndex<T>().Index;
609
- // CheckTypeIndexIsInComponentList(typeIndex);
610
- // fixed (DynamicComponentTypeHandle* c0Ptr = &c0)
611
- // {
612
- // ref var handle = ref c0Ptr[handleIndices[typeIndex].index];
613
- // if (entity == currentEntity)
614
- // {
615
- // var mask = currentChunk.GetEnabledMask(ref handle);
616
- // return mask.GetOptionalEnabledRefRO<T>(currentIndexInChunk);
617
- // }
618
- // else
619
- // {
620
- // var info = esil[entity];
621
- // var mask = info.Chunk.GetEnabledMask(ref handle);
622
- // return mask.GetOptionalEnabledRefRO<T>(info.IndexInChunk);
623
- // }
624
- // }
625
- //}
626
- //
627
- //public EnabledRefRW<T> GetEnabledRWIgnoreParallelSafety<T>(Entity entity) where T : unmanaged, IEnableableComponent
628
- //{
629
- // var typeIndex = TypeManager.GetTypeIndex<T>().Index;
630
- // CheckTypeIndexIsInComponentList(typeIndex);
631
- // fixed (DynamicComponentTypeHandle* c0Ptr = &c0)
632
- // {
633
- // ref var handle = ref c0Ptr[handleIndices[typeIndex].index];
634
- // if (entity == currentEntity)
635
- // {
636
- // var mask = currentChunk.GetEnabledMask(ref handle);
637
- // return mask.GetOptionalEnabledRefRW<T>(currentIndexInChunk);
638
- // }
639
- // else
640
- // {
641
- // var info = esil[entity];
642
- // var mask = info.Chunk.GetEnabledMask(ref handle);
643
- // return mask.GetOptionalEnabledRefRW<T>(info.IndexInChunk);
644
- // }
645
- // }
646
- //}
605
+ /// <summary>
606
+ /// Gets the readonly pointer to either the IComponentData or ISharedComponentData
607
+ /// </summary>
608
+ /// <param name="entity">The entity to get the component from</param>
609
+ /// <param name="typeIndex">The type of component to get</param>
610
+ /// <returns>A pointer to the component, or null if the component is not present</returns>
611
+ public void * GetUnsafeComponentPtrRO ( Entity entity , TypeIndex typeIndex )
612
+ {
613
+ CheckTypeIndexIsInComponentList ( typeIndex ) ;
614
+ CheckTypeNotBuffer ( typeIndex ) ;
615
+
616
+ if ( typeIndex . IsSharedComponentType )
617
+ {
618
+ fixed ( DynamicSharedComponentTypeHandle * s0Ptr = & s0 )
619
+ {
620
+ ref var handle = ref s0Ptr [ handleIndices [ typeIndex ] . index ] ;
621
+ void * ptr = default ;
622
+ if ( entity == currentEntity )
623
+ {
624
+ ptr = currentChunk . GetDynamicSharedComponentDataAddress ( ref handle ) ;
625
+ }
626
+ else
627
+ {
628
+ var info = esil [ entity ] ;
629
+ ptr = info . Chunk . GetDynamicSharedComponentDataAddress ( ref handle ) ;
630
+ }
631
+ return ptr ;
632
+ }
633
+ }
634
+
635
+ var typeSize = TypeManager . GetTypeInfo ( typeIndex ) . TypeSize ;
636
+ fixed ( DynamicComponentTypeHandle * c0Ptr = & c0 )
637
+ {
638
+ ref var handle = ref c0Ptr [ handleIndices [ typeIndex ] . index ] ;
639
+ if ( entity == currentEntity )
640
+ {
641
+ var array = currentChunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
642
+ if ( array . Length == 0 )
643
+ return null ;
644
+ return ( byte * ) array . GetUnsafeReadOnlyPtr ( ) + typeSize * currentIndexInChunk ;
645
+ }
646
+ else
647
+ {
648
+ CheckSafeAccessForForeignEntity ( ref handle ) ;
649
+ var info = esil [ entity ] ;
650
+ var array = info . Chunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
651
+ if ( array . Length == 0 )
652
+ return null ;
653
+ return ( byte * ) array . GetUnsafeReadOnlyPtr ( ) + typeSize * info . IndexInChunk ;
654
+ }
655
+ }
656
+ }
657
+
658
+ /// <summary>
659
+ /// Gets the read-write pointer to either the IComponentData or ISharedComponentData
660
+ /// </summary>
661
+ /// <param name="entity">The entity to get the component from</param>
662
+ /// <param name="typeIndex">The type of component to get</param>
663
+ /// <returns>A pointer to the component, or null if the component is not present</returns>
664
+ public void * GetUnsafeComponentPtrRW ( Entity entity , TypeIndex typeIndex )
665
+ {
666
+ CheckTypeIndexIsInComponentList ( typeIndex ) ;
667
+ CheckTypeNotBuffer ( typeIndex ) ;
668
+ CheckTypeNotShared ( typeIndex ) ;
669
+
670
+ var typeSize = TypeManager . GetTypeInfo ( typeIndex ) . TypeSize ;
671
+ fixed ( DynamicComponentTypeHandle * c0Ptr = & c0 )
672
+ {
673
+ ref var handle = ref c0Ptr [ handleIndices [ typeIndex ] . index ] ;
674
+ if ( entity == currentEntity )
675
+ {
676
+ var array = currentChunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
677
+ if ( array . Length == 0 )
678
+ return null ;
679
+ return ( byte * ) array . GetUnsafePtr ( ) + typeSize * currentIndexInChunk ;
680
+ }
681
+ else
682
+ {
683
+ CheckSafeAccessForForeignEntity ( ref handle ) ;
684
+ var info = esil [ entity ] ;
685
+ var array = info . Chunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
686
+ if ( array . Length == 0 )
687
+ return null ;
688
+ return ( byte * ) array . GetUnsafePtr ( ) + typeSize * info . IndexInChunk ;
689
+ }
690
+ }
691
+ }
692
+
693
+ /// <summary>
694
+ /// Gets the readonly pointer to either the IComponentData or ISharedComponentData,
695
+ /// ignoring parallel safety checks as if [NativeDisableParallelForRestriction] was used
696
+ /// </summary>
697
+ /// <param name="entity">The entity to get the component from</param>
698
+ /// <param name="typeIndex">The type of component to get</param>
699
+ /// <returns>A pointer to the component, or null if the component is not present</returns>
700
+ public void * GetUnsafeComponentPtrROIgnoreParallelSafety ( Entity entity , TypeIndex typeIndex )
701
+ {
702
+ CheckTypeIndexIsInComponentList ( typeIndex ) ;
703
+ CheckTypeNotBuffer ( typeIndex ) ;
704
+
705
+ if ( typeIndex . IsSharedComponentType )
706
+ {
707
+ fixed ( DynamicSharedComponentTypeHandle * s0Ptr = & s0 )
708
+ {
709
+ ref var handle = ref s0Ptr [ handleIndices [ typeIndex ] . index ] ;
710
+ void * ptr = default ;
711
+ if ( entity == currentEntity )
712
+ {
713
+ ptr = currentChunk . GetDynamicSharedComponentDataAddress ( ref handle ) ;
714
+ }
715
+ else
716
+ {
717
+ var info = esil [ entity ] ;
718
+ ptr = info . Chunk . GetDynamicSharedComponentDataAddress ( ref handle ) ;
719
+ }
720
+ return ptr ;
721
+ }
722
+ }
723
+
724
+ var typeSize = TypeManager . GetTypeInfo ( typeIndex ) . TypeSize ;
725
+ fixed ( DynamicComponentTypeHandle * c0Ptr = & c0 )
726
+ {
727
+ ref var handle = ref c0Ptr [ handleIndices [ typeIndex ] . index ] ;
728
+ if ( entity == currentEntity )
729
+ {
730
+ var array = currentChunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
731
+ if ( array . Length == 0 )
732
+ return null ;
733
+ return ( byte * ) array . GetUnsafeReadOnlyPtr ( ) + typeSize * currentIndexInChunk ;
734
+ }
735
+ else
736
+ {
737
+ var info = esil [ entity ] ;
738
+ var array = info . Chunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
739
+ if ( array . Length == 0 )
740
+ return null ;
741
+ return ( byte * ) array . GetUnsafeReadOnlyPtr ( ) + typeSize * info . IndexInChunk ;
742
+ }
743
+ }
744
+ }
745
+
746
+ /// <summary>
747
+ /// Gets the read-write pointer to either the IComponentData or ISharedComponentData,
748
+ /// ignoring parallel safety checks as if [NativeDisableParallelForRestriction] was used
749
+ /// </summary>
750
+ /// <param name="entity">The entity to get the component from</param>
751
+ /// <param name="typeIndex">The type of component to get</param>
752
+ /// <returns>A pointer to the component, or null if the component is not present</returns>
753
+ public void * GetUnsafeComponentPtrRWIgnoreParallelSafety ( Entity entity , TypeIndex typeIndex )
754
+ {
755
+ CheckTypeIndexIsInComponentList ( typeIndex ) ;
756
+ CheckTypeNotBuffer ( typeIndex ) ;
757
+ CheckTypeNotShared ( typeIndex ) ;
758
+
759
+ var typeSize = TypeManager . GetTypeInfo ( typeIndex ) . TypeSize ;
760
+ fixed ( DynamicComponentTypeHandle * c0Ptr = & c0 )
761
+ {
762
+ ref var handle = ref c0Ptr [ handleIndices [ typeIndex ] . index ] ;
763
+ if ( entity == currentEntity )
764
+ {
765
+ var array = currentChunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
766
+ if ( array . Length == 0 )
767
+ return null ;
768
+ return ( byte * ) array . GetUnsafePtr ( ) + typeSize * currentIndexInChunk ;
769
+ }
770
+ else
771
+ {
772
+ var info = esil [ entity ] ;
773
+ var array = info . Chunk . GetDynamicComponentDataArrayReinterpret < byte > ( ref handle , typeSize ) ;
774
+ if ( array . Length == 0 )
775
+ return null ;
776
+ return ( byte * ) array . GetUnsafePtr ( ) + typeSize * info . IndexInChunk ;
777
+ }
778
+ }
779
+ }
647
780
#endregion
648
781
649
782
#region Constructor, Update, and Dispose
@@ -1116,6 +1249,27 @@ void CheckSafeAccessForForeignEntity(ref DynamicComponentTypeHandle handle)
1116
1249
"Attempted to access a component from an external entity inside a parallel job. This is not thread-safe. Call SetupEntity() to specify an entity that is safe to access in a parallel job, such as one from an IJobChunk or IJobEntity" ) ;
1117
1250
#endif
1118
1251
}
1252
+
1253
+ [ Conditional ( "ENABLE_UNITY_COLLECTIONS_CHECKS" ) ]
1254
+ void CheckTypeNotBuffer ( TypeIndex typeIndex )
1255
+ {
1256
+ if ( typeIndex . IsBuffer )
1257
+ throw new System . ArgumentOutOfRangeException ( $ "The specified TypeIndex is for a DynamicBuffer, which is not supported in this operation.") ;
1258
+ }
1259
+
1260
+ [ Conditional ( "ENABLE_UNITY_COLLECTIONS_CHECKS" ) ]
1261
+ void CheckTypeNotShared ( TypeIndex typeIndex )
1262
+ {
1263
+ if ( typeIndex . IsSharedComponentType )
1264
+ throw new System . ArgumentOutOfRangeException ( $ "The specified TypeIndex is for a SharedComponent, which is not supported in this operation.") ;
1265
+ }
1266
+
1267
+ [ Conditional ( "ENABLE_UNITY_COLLECTIONS_CHECKS" ) ]
1268
+ void CheckTypeIsBuffer ( TypeIndex typeIndex )
1269
+ {
1270
+ if ( ! typeIndex . IsBuffer )
1271
+ throw new System . ArgumentOutOfRangeException ( $ "The specified TypeIndex is not for a DynamicBuffer, and a DynamicBuffer type is required for this operation.") ;
1272
+ }
1119
1273
#endregion
1120
1274
}
1121
1275
0 commit comments