Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TypeSafeDictionaryMethods.cs 26KB

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