Mirror of Svelto.ECS because we're a fan of it
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

604 рядки
28KB

  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using DBC.ECS;
  4. using Svelto.Common;
  5. using Svelto.DataStructures;
  6. namespace Svelto.ECS.Internal
  7. {
  8. public static class TypeSafeDictionaryMethods
  9. {
  10. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  11. public static void AddEntitiesToDictionary<Strategy1, Strategy2, Strategy3, TValue>(
  12. in SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  13. , ITypeSafeDictionary<TValue> toDic
  14. #if SLOW_SVELTO_SUBMISSION
  15. , in EnginesRoot.EntityReferenceMap entityLocator
  16. #endif
  17. , ExclusiveGroupStruct toGroupID)
  18. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  19. where Strategy2 : struct, IBufferStrategy<TValue>
  20. where Strategy3 : struct, IBufferStrategy<int>
  21. where TValue : struct, _IInternalEntityComponent
  22. {
  23. foreach (var tuple in fromDictionary)
  24. {
  25. #if SLOW_SVELTO_SUBMISSION
  26. var egid = new EGID(tuple.key, toGroupID);
  27. if (SlowSubmissionInfo<TValue>.hasEgid)
  28. SetEGIDWithoutBoxing<TValue>.SetIDWithoutBoxing(ref tuple.value, egid);
  29. if (SlowSubmissionInfo<TValue>.hasReference)
  30. SetEGIDWithoutBoxing<TValue>.SetRefWithoutBoxing(
  31. ref tuple.value,
  32. entityLocator.GetEntityReference(egid));
  33. #endif
  34. #if DEBUG && !PROFILE_SVELTO
  35. try
  36. {
  37. #endif
  38. toDic.Add(tuple.key, tuple.value);
  39. #if DEBUG && !PROFILE_SVELTO
  40. }
  41. catch (Exception e)
  42. {
  43. Console.LogException(
  44. e,
  45. "trying to add an EntityComponent with the same ID more than once Entity: ".FastConcat(typeof(TValue).ToString())
  46. .FastConcat(", group ").FastConcat(toGroupID.ToName()).FastConcat(", id ").FastConcat(tuple.key));
  47. throw;
  48. }
  49. #endif
  50. #if PARANOID_CHECK && SLOW_SVELTO_SUBMISSION
  51. DBC.ECS.Check.Ensure(_hasEgid == false || ((INeedEGID)fromDictionary[egid.entityID]).ID == egid, "impossible situation happened during swap");
  52. #endif
  53. }
  54. }
  55. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  56. public static void ExecuteEnginesAddCallbacks<Strategy1, Strategy2, Strategy3, TValue>(
  57. ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  58. , ITypeSafeDictionary<TValue> todic, ExclusiveGroupStruct togroup
  59. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnAdd>>> entitycomponentenginesdb
  60. , in PlatformProfiler sampler)
  61. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  62. where Strategy2 : struct, IBufferStrategy<TValue>
  63. where Strategy3 : struct, IBufferStrategy<int>
  64. where TValue : struct, _IInternalEntityComponent
  65. {
  66. if (entitycomponentenginesdb.TryGetValue(
  67. ComponentTypeID<TValue>.id
  68. , out var entityComponentsEngines))
  69. {
  70. if (entityComponentsEngines.count == 0)
  71. return;
  72. var dictionaryKeyEnumerator = fromDictionary.unsafeKeys;
  73. var count = fromDictionary.count;
  74. for (var i = 0; i < count; ++i)
  75. try
  76. {
  77. var key = dictionaryKeyEnumerator[i].key;
  78. ref var entity = ref todic.GetValueByRef(key);
  79. var egid = new EGID(key, togroup);
  80. //get all the engines linked to TValue
  81. for (var j = 0; j < entityComponentsEngines.count; j++)
  82. using (sampler.Sample(entityComponentsEngines[j].name))
  83. {
  84. #pragma warning disable CS0612
  85. ((IReactOnAdd<TValue>)entityComponentsEngines[j].engine).Add(ref entity, egid);
  86. #pragma warning restore CS0612
  87. }
  88. }
  89. catch (Exception e)
  90. {
  91. Console.LogException(e, "Code crashed inside Add callback with Type ".FastConcat(TypeCache<TValue>.name));
  92. throw;
  93. }
  94. }
  95. }
  96. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  97. public static void ExecuteEnginesDisposeCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>(
  98. ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  99. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> reactiveEnginesDispose
  100. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDisposeEx>>> reactiveEnginesDisposeEx
  101. , IEntityIDs entityids, ExclusiveGroupStruct group, in PlatformProfiler sampler)
  102. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  103. where Strategy2 : struct, IBufferStrategy<TValue>
  104. where Strategy3 : struct, IBufferStrategy<int>
  105. where TValue : struct, _IInternalEntityComponent
  106. {
  107. if (reactiveEnginesDispose.TryGetValue(ComponentTypeID<TValue>.id, out var entityComponentsEngines) == true)
  108. {
  109. var resultCount = entityComponentsEngines.count;
  110. for (var i = 0; i < resultCount; i++)
  111. try
  112. {
  113. using (sampler.Sample(entityComponentsEngines[i].name))
  114. {
  115. foreach (var value in fromDictionary)
  116. {
  117. ref var entity = ref value.value;
  118. var egid = new EGID(value.key, group);
  119. #pragma warning disable CS0618
  120. var reactOnRemove = (IReactOnDispose<TValue>)entityComponentsEngines[i].engine;
  121. #pragma warning restore CS0618
  122. reactOnRemove.Remove(ref entity, egid);
  123. }
  124. }
  125. }
  126. catch
  127. {
  128. Console.LogError("Code crashed inside Remove callback ".FastConcat(entityComponentsEngines[i].name));
  129. throw;
  130. }
  131. }
  132. if (reactiveEnginesDisposeEx.TryGetValue(ComponentTypeID<TValue>.id, out var reactiveEnginesDisposeExPerType))
  133. {
  134. var count = fromDictionary.count;
  135. var enginesCount = reactiveEnginesDisposeExPerType.count;
  136. if (count > 0)
  137. {
  138. for (var i = 0; i < enginesCount; i++)
  139. {
  140. try
  141. {
  142. using (sampler.Sample(reactiveEnginesDisposeExPerType[i].name))
  143. {
  144. ((IReactOnDisposeEx<TValue>)reactiveEnginesDisposeExPerType[i].engine).Remove(
  145. (0, (uint)count)
  146. , new EntityCollection<TValue>(fromDictionary.UnsafeGetValues(out _), entityids, (uint)count), group);
  147. }
  148. }
  149. catch
  150. {
  151. Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesDisposeExPerType[i].name));
  152. throw;
  153. }
  154. }
  155. }
  156. }
  157. }
  158. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  159. public static void ExecuteEnginesRemoveCallbacks<Strategy1, Strategy2, Strategy3, TValue>(FasterList<(uint, string)> infostoprocess
  160. , ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  161. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveenginesremove
  162. , ExclusiveGroupStruct fromgroup, in PlatformProfiler profiler)
  163. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  164. where Strategy2 : struct, IBufferStrategy<TValue>
  165. where Strategy3 : struct, IBufferStrategy<int>
  166. where TValue : struct, _IInternalEntityComponent
  167. {
  168. if (reactiveenginesremove.TryGetValue(
  169. ComponentTypeID<TValue>.id
  170. , out var entityComponentsEngines))
  171. {
  172. if (entityComponentsEngines.count == 0)
  173. return;
  174. var iterations = infostoprocess.count;
  175. for (var i = 0; i < iterations; i++)
  176. {
  177. var (entityID, trace) = infostoprocess[i];
  178. try
  179. {
  180. ref var entity = ref fromDictionary.GetValueByRef(entityID);
  181. var egid = new EGID(entityID, fromgroup);
  182. for (var j = 0; j < entityComponentsEngines.count; j++)
  183. using (profiler.Sample(entityComponentsEngines[j].name))
  184. {
  185. #pragma warning disable CS0612
  186. ((IReactOnRemove<TValue>)entityComponentsEngines[j].engine).Remove(ref entity, egid);
  187. #pragma warning restore CS0612
  188. }
  189. }
  190. catch
  191. {
  192. var str = "Crash while executing Remove Entity callback on ".FastConcat(TypeCache<TValue>.name)
  193. .FastConcat(" from : ", trace);
  194. Console.LogError(str);
  195. throw;
  196. }
  197. }
  198. }
  199. }
  200. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  201. public static void ExecuteEnginesRemoveCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>(
  202. ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  203. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveenginesremove
  204. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemoveEx>>> reactiveenginesremoveex
  205. , IEntityIDs entityids, ExclusiveGroupStruct group, in PlatformProfiler sampler)
  206. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  207. where Strategy2 : struct, IBufferStrategy<TValue>
  208. where Strategy3 : struct, IBufferStrategy<int>
  209. where TValue : struct, _IInternalEntityComponent
  210. {
  211. if (reactiveenginesremove.TryGetValue(
  212. ComponentTypeID<TValue>.id
  213. , out var reactiveEnginesRemovePerType))
  214. {
  215. var enginesCount = reactiveEnginesRemovePerType.count;
  216. for (var i = 0; i < enginesCount; i++)
  217. try
  218. {
  219. foreach (var value in fromDictionary)
  220. {
  221. ref var entity = ref value.value;
  222. var egid = new EGID(value.key, group);
  223. using (sampler.Sample(reactiveEnginesRemovePerType[i].name))
  224. {
  225. #pragma warning disable CS0612
  226. ((IReactOnRemove<TValue>)reactiveEnginesRemovePerType[i].engine).Remove(
  227. #pragma warning restore CS0612
  228. ref entity, egid);
  229. }
  230. }
  231. }
  232. catch
  233. {
  234. Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemovePerType[i].name));
  235. throw;
  236. }
  237. }
  238. if (reactiveenginesremoveex.TryGetValue(
  239. ComponentTypeID<TValue>.id
  240. , out var reactiveEnginesRemoveExPerType))
  241. {
  242. var count = fromDictionary.count;
  243. var enginesCount = reactiveEnginesRemoveExPerType.count;
  244. for (var i = 0; i < enginesCount; i++)
  245. try
  246. {
  247. using (sampler.Sample(reactiveEnginesRemoveExPerType[i].name))
  248. {
  249. ((IReactOnRemoveEx<TValue>)reactiveEnginesRemoveExPerType[i].engine).Remove(
  250. (0, (uint)count)
  251. , new EntityCollection<TValue>(
  252. fromDictionary.UnsafeGetValues(out _), entityids
  253. , (uint)count), group);
  254. }
  255. }
  256. catch
  257. {
  258. Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemoveExPerType[i].name));
  259. throw;
  260. }
  261. }
  262. }
  263. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  264. public static void ExecuteEnginesSwapCallbacks<Strategy1, Strategy2, Strategy3, TValue>(FasterDictionary<uint, SwapInfo> infostoprocess
  265. , ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  266. , FasterList<ReactEngineContainer<IReactOnSwap>> reactiveenginesswap, ExclusiveGroupStruct togroup
  267. , ExclusiveGroupStruct fromgroup, in PlatformProfiler sampler)
  268. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  269. where Strategy2 : struct, IBufferStrategy<TValue>
  270. where Strategy3 : struct, IBufferStrategy<int>
  271. where TValue : struct, _IInternalEntityComponent
  272. {
  273. if (reactiveenginesswap.count == 0)
  274. return;
  275. var iterations = infostoprocess.count;
  276. var infostoprocessUnsafeValues = infostoprocess.unsafeValues;
  277. for (var i = 0; i < iterations; i++)
  278. {
  279. var (fromEntityID, toEntityID, trace) = infostoprocessUnsafeValues[i];
  280. try
  281. {
  282. ref var entityComponent = ref fromDictionary.GetValueByRef(toEntityID);
  283. var newEgid = new EGID(toEntityID, togroup);
  284. for (var j = 0; j < reactiveenginesswap.count; j++)
  285. using (sampler.Sample(reactiveenginesswap[j].name))
  286. {
  287. #pragma warning disable CS0612
  288. #pragma warning disable CS0618
  289. ((IReactOnSwap<TValue>)reactiveenginesswap[j].engine).MovedTo(
  290. #pragma warning restore CS0618
  291. #pragma warning restore CS0612
  292. ref entityComponent, fromgroup, newEgid);
  293. }
  294. }
  295. catch
  296. {
  297. var str = "Crash while executing Swap Entity callback on ".FastConcat(TypeCache<TValue>.name)
  298. .FastConcat(" from : ", trace);
  299. Console.LogError(str);
  300. throw;
  301. }
  302. }
  303. }
  304. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  305. public static void ExecuteEnginesSwapCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>(
  306. ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  307. , ITypeSafeDictionary<TValue> toDic, ExclusiveGroupStruct togroup, ExclusiveGroupStruct fromgroup
  308. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnSwap>>> reactiveenginesswap
  309. , FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnSwapEx>>> reactiveenginesswapex
  310. , IEntityIDs entityids, in PlatformProfiler sampler)
  311. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  312. where Strategy2 : struct, IBufferStrategy<TValue>
  313. where Strategy3 : struct, IBufferStrategy<int>
  314. where TValue : struct, _IInternalEntityComponent
  315. {
  316. //get all the engines linked to TValue
  317. if (!reactiveenginesswap.TryGetValue(
  318. ComponentTypeID<TValue>.id
  319. , out var reactiveEnginesSwapPerType))
  320. return;
  321. var componentsEnginesCount = reactiveEnginesSwapPerType.count;
  322. for (var i = 0; i < componentsEnginesCount; i++)
  323. try
  324. {
  325. foreach (var value in fromDictionary)
  326. {
  327. ref var entityComponent = ref toDic.GetValueByRef(value.key);
  328. var newEgid = new EGID(value.key, togroup);
  329. using (sampler.Sample(reactiveEnginesSwapPerType[i].name))
  330. {
  331. #pragma warning disable CS0612
  332. #pragma warning disable CS0618
  333. ((IReactOnSwap<TValue>)reactiveEnginesSwapPerType[i].engine).MovedTo(
  334. #pragma warning restore CS0618
  335. #pragma warning restore CS0612
  336. ref entityComponent, fromgroup, newEgid);
  337. }
  338. }
  339. }
  340. catch (Exception)
  341. {
  342. Console.LogError("Code crashed inside MoveTo callback ".FastConcat(reactiveEnginesSwapPerType[i].name));
  343. throw;
  344. }
  345. if (reactiveenginesswapex.TryGetValue(
  346. ComponentTypeID<TValue>.id
  347. , out var reactiveEnginesRemoveExPerType))
  348. {
  349. var enginesCount = reactiveEnginesRemoveExPerType.count;
  350. var count = fromDictionary.count;
  351. for (var i = 0; i < enginesCount; i++)
  352. try
  353. {
  354. using (sampler.Sample(reactiveEnginesRemoveExPerType[i].name))
  355. {
  356. ((IReactOnSwapEx<TValue>)reactiveEnginesRemoveExPerType[i].engine).MovedTo(
  357. (0, (uint)count)
  358. , new EntityCollection<TValue>(
  359. fromDictionary.UnsafeGetValues(out _), entityids
  360. , (uint)count), fromgroup, togroup);
  361. }
  362. }
  363. catch
  364. {
  365. Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemoveExPerType[i].name));
  366. throw;
  367. }
  368. }
  369. }
  370. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  371. public static void RemoveEntitiesFromDictionary<Strategy1, Strategy2, Strategy3, TValue>(FasterList<(uint, string)> infostoprocess
  372. , ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  373. , FasterDictionary<uint, uint> entityIDsAffectedByRemoveAtSwapBack)
  374. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  375. where Strategy2 : struct, IBufferStrategy<TValue>
  376. where Strategy3 : struct, IBufferStrategy<int>
  377. where TValue : struct, _IInternalEntityComponent
  378. {
  379. var iterations = infostoprocess.count;
  380. for (var i = 0; i < iterations; i++)
  381. {
  382. var (id, trace) = infostoprocess[i];
  383. #if DEBUG && !PROFILE_SVELTO
  384. try
  385. {
  386. #endif
  387. if (fromDictionary.Remove(id, out var index, out var value))
  388. {
  389. //Note I am doing this to be able to use a range of values even with the
  390. //remove Ex callbacks. Basically I am copying back the deleted value
  391. //at the end of the array, so I can use as range count, count + number of deleted entities
  392. //I need to swap the keys too to have matching EntityIDs
  393. if (index != fromDictionary.count)
  394. {
  395. fromDictionary.unsafeValues[(uint)fromDictionary.count] = value;
  396. fromDictionary.unsafeKeys[(uint)fromDictionary.count] = new SveltoDictionaryNode<uint>(id, 0);
  397. }
  398. //when a component is removed from a component array, a remove swap back happens. This means
  399. //that not only we have to remove the index of the component of the entity deleted from the array
  400. //but we need also to update the index of the component that has been swapped in the cell
  401. //of the deleted component
  402. //entityIDsAffectedByRemoval tracks all the entitiesID of the components that need to be updated
  403. //in the filters because their indices in the array changed.
  404. entityIDsAffectedByRemoveAtSwapBack[fromDictionary.unsafeKeys[index].key] = index;
  405. }
  406. #if DEBUG && !PROFILE_SVELTO
  407. }
  408. catch
  409. {
  410. var str = "Crash while executing Remove Entity operation on ".FastConcat(TypeCache<TValue>.name)
  411. .FastConcat(" from : ", trace);
  412. Console.LogError(str);
  413. throw;
  414. }
  415. #endif
  416. }
  417. }
  418. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  419. public static void SwapEntitiesBetweenDictionaries<Strategy1, Strategy2, Strategy3, TValue>(in FasterDictionary<uint, SwapInfo> entitiesIDsToSwap
  420. , ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
  421. , ITypeSafeDictionary<TValue> toDictionary, ExclusiveGroupStruct fromgroup, ExclusiveGroupStruct togroup
  422. , FasterDictionary<uint, uint> entityIDsAffectedByRemoveAtSwapBack)
  423. where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
  424. where Strategy2 : struct, IBufferStrategy<TValue>
  425. where Strategy3 : struct, IBufferStrategy<int>
  426. where TValue : struct, _IInternalEntityComponent
  427. {
  428. var iterations = entitiesIDsToSwap.count;
  429. var entitiesToSwapInfo = entitiesIDsToSwap.unsafeValues;
  430. var fromDictionaryUnsafeKeys = fromDictionary.unsafeKeys;
  431. for (var i = 0; i < iterations; i++)
  432. {
  433. ref SwapInfo swapInfo = ref entitiesToSwapInfo[i];
  434. #if DEBUG && !PROFILE_SVELTO
  435. try
  436. {
  437. #endif
  438. var fromEntityGid = new EGID(swapInfo.fromID, fromgroup);
  439. var toEntityEgid = new EGID(swapInfo.toID, togroup);
  440. Check.Require(togroup.isInvalid == false, "Invalid To Group");
  441. if (fromDictionary.Remove(fromEntityGid.entityID, out var index, out var value))
  442. entityIDsAffectedByRemoveAtSwapBack[fromDictionaryUnsafeKeys[index].key] = index; //after the removal, the entity ad index is the entity that was at the end of the buffer (swapped back).
  443. else
  444. Check.Assert(false, "Swapping an entity that doesn't exist");
  445. #if SLOW_SVELTO_SUBMISSION
  446. if (SlowSubmissionInfo<TValue>.hasEgid)
  447. SetEGIDWithoutBoxing<TValue>.SetIDWithoutBoxing(ref value, toEntityEgid);
  448. #endif
  449. swapInfo.toIndex = toDictionary.Add(toEntityEgid.entityID, value);
  450. #if PARANOID_CHECK
  451. DBC.ECS.Check.Ensure(_hasEgid == false || ((INeedEGID)toGroupCasted[toEntityEGID.entityID]).ID == toEntityEGID, "impossible situation happened during swap");
  452. #endif
  453. #if DEBUG && !PROFILE_SVELTO
  454. }
  455. catch
  456. {
  457. var str = "Crash while executing Swap Entity operation on ".FastConcat(TypeCache<TValue>.name)
  458. .FastConcat(" from : ", swapInfo.trace);
  459. Console.LogError(str);
  460. throw;
  461. }
  462. #endif
  463. }
  464. }
  465. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  466. public static void ExecuteEnginesAddEntityCallbacksFast<TValue>(
  467. FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnAddEx>>> fasterDictionary
  468. , ExclusiveGroupStruct groupId, (uint, uint) rangeTuple, IEntityIDs entityids
  469. , ITypeSafeDictionary<TValue> typeSafeDictionary, PlatformProfiler profiler)
  470. where TValue : struct, _IInternalEntityComponent
  471. {
  472. //get all the engines linked to TValue
  473. if (!fasterDictionary.TryGetValue(ComponentTypeID<TValue>.id, out var entityComponentsEngines))
  474. return;
  475. for (var i = 0; i < entityComponentsEngines.count; i++)
  476. try
  477. {
  478. using (profiler.Sample(entityComponentsEngines[i].name))
  479. {
  480. ((IReactOnAddEx<TValue>)entityComponentsEngines[i].engine).Add(
  481. rangeTuple
  482. , new EntityCollection<TValue>(typeSafeDictionary.GetValues(out var count), entityids, count)
  483. , groupId);
  484. }
  485. }
  486. catch (Exception e)
  487. {
  488. Console.LogException(e, "Code crashed inside Add callback ".FastConcat(entityComponentsEngines[i].name));
  489. throw;
  490. }
  491. }
  492. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  493. public static void ExecuteEnginesSwapCallbacksFast<TValue>(
  494. FasterList<ReactEngineContainer<IReactOnSwapEx>> callbackEngines,
  495. ExclusiveGroupStruct fromGroup, ExclusiveGroupStruct toGroup, IEntityIDs entityids, ITypeSafeDictionary<TValue> typeSafeDictionary
  496. , (uint, uint) rangeOfSubmittedEntitiesIndicies, PlatformProfiler sampler)
  497. where TValue : struct, _IInternalEntityComponent
  498. {
  499. for (var i = 0; i < callbackEngines.count; i++)
  500. try
  501. {
  502. using (sampler.Sample(callbackEngines[i].name))
  503. {
  504. var values = typeSafeDictionary.GetValues(out var count);
  505. ((IReactOnSwapEx<TValue>)callbackEngines[i].engine).MovedTo(
  506. rangeOfSubmittedEntitiesIndicies, new EntityCollection<TValue>(values, entityids, count), fromGroup, toGroup);
  507. }
  508. }
  509. catch (Exception e)
  510. {
  511. Console.LogException(e, "Code crashed inside Add callback ".FastConcat(callbackEngines[i].name));
  512. throw;
  513. }
  514. }
  515. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  516. public static void ExecuteEnginesRemoveCallbacksFast<TValue>(FasterList<ReactEngineContainer<IReactOnRemoveEx>> fasterList,
  517. ExclusiveGroupStruct exclusiveGroupStruct
  518. , (uint, uint) valueTuple, IEntityIDs entityids, ITypeSafeDictionary<TValue> typeSafeDictionary
  519. , PlatformProfiler sampler)
  520. where TValue : struct, _IInternalEntityComponent
  521. {
  522. for (var i = 0; i < fasterList.count; i++)
  523. try
  524. {
  525. using (sampler.Sample(fasterList[i].name))
  526. {
  527. ((IReactOnRemoveEx<TValue>)fasterList[i].engine).Remove(
  528. valueTuple
  529. , new EntityCollection<TValue>(typeSafeDictionary.GetValues(out var count), entityids, count)
  530. , exclusiveGroupStruct);
  531. }
  532. }
  533. catch (Exception e)
  534. {
  535. Console.LogException(e, "Code crashed inside Add callback ".FastConcat(fasterList[i].name));
  536. throw;
  537. }
  538. }
  539. }
  540. }