Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceGrid.c
Go to the documentation of this file.
1 class SCR_ResourceGridCell : Managed
2 {
3  protected int m_iIndex;
4  protected int m_iGridUpdateId = int.MIN;
5  protected ref array<SCR_ResourceComponent> m_aStaticItems = {};
6  protected ref array<SCR_ResourceComponent> m_aDynamicItems = {};
7 
8  //------------------------------------------------------------------------------------------------
9  int GetGridUpdateId()
10  {
11  return m_iGridUpdateId;
12  }
13 
14  //------------------------------------------------------------------------------------------------
15  int GetIndex()
16  {
17  return m_iIndex;
18  }
19 
20  //------------------------------------------------------------------------------------------------
21  int GetX()
22  {
23  return m_iIndex >> SCR_ResourceGrid.CELL_POWER;
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  int GetZ()
28  {
29  return m_iIndex & SCR_ResourceGrid.CELL_SIZE_MINUS_1;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  int Get(int axis)
34  {
35  if (axis == 0)
36  return m_iIndex >> SCR_ResourceGrid.CELL_POWER;
37 
38  if (axis == 2)
39  return m_iIndex & SCR_ResourceGrid.CELL_SIZE_MINUS_1;
40 
41  return 0;
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  array<SCR_ResourceComponent> GetResourceDynamicItems()
46  {
48  while (m_aDynamicItems.RemoveItem(null));
49 
50  return m_aDynamicItems;
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  array<SCR_ResourceComponent> GetResourceStaticItems()
55  {
57  while (m_aStaticItems.RemoveItemOrdered(null));
58 
59  return m_aStaticItems;
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  /*
64  array<SCR_ResourceGridSubscription> GetSubscriptions()
65  {
66  return m_aSubscriptions;
67  }
68  */
69 
70  //------------------------------------------------------------------------------------------------
71  void SetGridUpdateId(int gridUpdateId)
72  {
73  if (gridUpdateId <= m_iGridUpdateId)
74  return;
75 
76  m_iGridUpdateId = gridUpdateId;
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  int RegisterDynamicItem(notnull SCR_ResourceComponent item, int gridUpdateId)
81  {
82  if (gridUpdateId > m_iGridUpdateId)
83  m_iGridUpdateId = gridUpdateId;
84 
85  return m_aDynamicItems.Insert(item);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  bool UnregisterDynamicItem(notnull SCR_ResourceComponent item, int gridUpdateId)
90  {
91  if (gridUpdateId > m_iGridUpdateId)
92  m_iGridUpdateId = gridUpdateId;
93 
94  return m_aDynamicItems.RemoveItem(item);
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  int RegisterStaticItem(notnull SCR_ResourceComponent item, int gridUpdateId)
99  {
100  if (gridUpdateId > m_iGridUpdateId)
101  m_iGridUpdateId = gridUpdateId;
102 
103  return m_aStaticItems.Insert(item);
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  bool UnregisterStaticItem(notnull SCR_ResourceComponent item, int gridUpdateId)
108  {
109  if (gridUpdateId > m_iGridUpdateId)
110  m_iGridUpdateId = gridUpdateId;
111 
112  return m_aStaticItems.RemoveItemOrdered(item);
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  void MoveStaticItem(notnull SCR_ResourceComponent item, int gridUpdateId)
117  {
118  if (gridUpdateId > m_iGridUpdateId)
119  m_iGridUpdateId = gridUpdateId;
120 
121  m_aStaticItems.RemoveItemOrdered(item);
122  m_aStaticItems.Insert(item);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  void MoveDynamicItem(notnull SCR_ResourceComponent item, int gridUpdateId)
127  {
128  if (gridUpdateId > m_iGridUpdateId)
129  m_iGridUpdateId = gridUpdateId;
130  }
131 
132  /*
133  //------------------------------------------------------------------------------------------------
134  int Subscribe(notnull SCR_ResourceGridSubscription subscription)
135  {
136  return m_aSubscriptions.Insert(subscription);
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  bool Unsubscribe(notnull SCR_ResourceGridSubscription subscription)
141  {
142  return m_aSubscriptions.RemoveItem(subscription);
143  }
144  */
145 
146  //------------------------------------------------------------------------------------------------
147  void PromoteResourceItemToDynamic(notnull SCR_ResourceComponent item)
148  {
149  m_aStaticItems.RemoveItemOrdered(item);
150  m_aDynamicItems.Insert(item);
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  void PromoteResourceItemToStatic(notnull SCR_ResourceComponent item)
155  {
156  m_aDynamicItems.RemoveItem(item);
157  m_aStaticItems.Insert(item);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  void SCR_ResourceGridCell(int index)
162  {
163  m_iIndex = index;
164  }
165 }
166 
167 class SCR_ResourceGrid
168 {
169  static const int MAX_FRAME_BUDGET = 20;
170  static const int CELL_POWER = 4;
171  static const int CELL_SIZE_MINUS_1 = (1 << CELL_POWER) - 1;
172 
173  protected ref map<int, ref SCR_ResourceGridCell> m_Cells;
174  protected ref array<SCR_ResourceComponent> m_aFlaggedItems = {};
175  protected ref set<SCR_ResourceContainer> m_aQueriedContainers = new set<SCR_ResourceContainer>();
176  protected int m_iGridUpdateId = int.MIN;
177  protected int m_iGridPerimeter;
179  protected int m_iFrameBudget;
180 
181  //------------------------------------------------------------------------------------------------
183  {
184  return m_iGridUpdateId;
185  }
186 
187  //------------------------------------------------------------------------------------------------
189  {
190  return m_iFrameBudget;
191  }
192 
193  //------------------------------------------------------------------------------------------------
195  {
196  m_iFrameBudget = SCR_ResourceGrid.MAX_FRAME_BUDGET;
197  }
198 
199  //------------------------------------------------------------------------------------------------
200  int ComputeIndex(int x, int z)
201  {
202  return x | z << CELL_POWER;
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  int ComputeIndex(int x, int y, int z)
207  {
208  return x | z << CELL_POWER;
209  }
210 
211  //------------------------------------------------------------------------------------------------
212  int ComputeIndex(vector position)
213  {
214  return ((int)position[0] >> CELL_POWER) | ((int)position[2] >> CELL_POWER << CELL_POWER);
215  }
216 
217  //------------------------------------------------------------------------------------------------
219  {
220  if (++m_iGridUpdateId == int.MAX)
221  Debug.Error2("SCR_ResourceGrid", "Maximum grid update id has been reached.");
222 
223  return m_iGridUpdateId;
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  void FlagResourceItem(notnull SCR_ResourceComponent item)
228  {
229  m_aFlaggedItems.Insert(item);
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  void UnflagResourceItem(notnull SCR_ResourceComponent item)
234  {
235  m_aFlaggedItems.RemoveItem(item);
236  }
237 
238  //------------------------------------------------------------------------------------------------
240  {
241  if (m_aFlaggedItems.IsEmpty())
242  return;
243 
245 
246  foreach (SCR_ResourceComponent item: m_aFlaggedItems)
247  {
248  if (item)
249  ProcessResourceItem(item);
250  }
251 
252  m_aFlaggedItems.Clear();
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  void UpdateResourceStaticItem(notnull SCR_ResourceComponent item)
257  {
258  int previousMins, previousMaxs;
259 
261  item.GetGridContainersBounds(previousMins, previousMaxs);
262 
264  if (previousMins == 0xFFFFFFFF || previousMaxs == 0xFFFFFFFF)
265  return;
266 
268  int prevMinX = previousMins & CELL_SIZE_MINUS_1;
269  int prevMinY = previousMins >> CELL_POWER;
270  int prevMaxX = previousMaxs & CELL_SIZE_MINUS_1;
271  int prevMaxY = previousMaxs >> CELL_POWER;
272 
273  vector boundsMins, boundsMaxs;
274 
275  item.GetGridContainersWorldBoundingBox(boundsMins, boundsMaxs);
276 
277  int minX = (int)boundsMins[0] >> CELL_POWER;
278  int minY = (int)boundsMins[2] >> CELL_POWER;
279  int maxX = (int)boundsMaxs[0] >> CELL_POWER;
280  int maxY = (int)boundsMaxs[2] >> CELL_POWER;
281 
282  SCR_ResourceGridCell gridCell;
283 
284  for (int y = prevMinY; y <= prevMaxY; ++y)
285  {
286  for (int x = prevMinX; x <= prevMaxX; ++x)
287  {
288  gridCell = m_Cells[y << CELL_POWER | x];
289 
290  if (!gridCell)
291  continue;
292 
293  if ((x >= minX && x <= maxX) && (y >= minY && y <= maxY))
294  gridCell.MoveStaticItem(item, m_iGridUpdateId);
295  else
296  gridCell.UnregisterStaticItem(item, m_iGridUpdateId);
297  }
298  }
299 
300  int currentCellPosition;
301 
302  for (int y = minY; y <= maxY; ++y)
303  {
304  for (int x = minX; x <= maxX; ++x)
305  {
306  if (x >= prevMinX && x <= prevMaxX && y >= prevMinY && y <= prevMaxY)
307  {
308  x = prevMaxX;
309 
310  continue;
311  }
312 
313  currentCellPosition = y << CELL_POWER | x;
314  gridCell = m_Cells[currentCellPosition];
315 
316  if (!gridCell)
317  m_Cells[currentCellPosition] = new SCR_ResourceGridCell(currentCellPosition);
318 
319  m_Cells[currentCellPosition].RegisterStaticItem(item, m_iGridUpdateId);
320  }
321  }
322 
323  item.SetGridContainersBounds(minY << CELL_POWER | minX, maxY << CELL_POWER | maxX);
324  item.SetGridUpdateId(m_iGridUpdateId);
325  }
326 
327  //------------------------------------------------------------------------------------------------
328  void UpdateResourceDynamicItem(notnull SCR_ResourceComponent item)
329  {
330  int previousMins, previousMaxs;
331 
333  item.GetGridContainersBounds(previousMins, previousMaxs);
334 
336  if (previousMins == 0xFFFFFFFF || previousMaxs == 0xFFFFFFFF)
337  return;
338 
340  int prevMinX = previousMins & CELL_SIZE_MINUS_1;
341  int prevMinY = previousMins >> CELL_POWER;
342  int prevMaxX = previousMaxs & CELL_SIZE_MINUS_1;
343  int prevMaxY = previousMaxs >> CELL_POWER;
344 
345  vector boundsMins, boundsMaxs;
346 
347  item.GetGridContainersWorldBoundingBox(boundsMins, boundsMaxs);
348 
349  int minX = (int)boundsMins[0] >> CELL_POWER;
350  int minY = (int)boundsMins[2] >> CELL_POWER;
351  int maxX = (int)boundsMaxs[0] >> CELL_POWER;
352  int maxY = (int)boundsMaxs[2] >> CELL_POWER;
353 
354  SCR_ResourceGridCell gridCell;
355 
356  for (int y = prevMinY; y <= prevMaxY; ++y)
357  {
358  for (int x = prevMinX; x <= prevMaxX; ++x)
359  {
360  gridCell = m_Cells[y << CELL_POWER | x];
361 
362  if (!gridCell)
363  continue;
364 
365  if (x >= minX && x <= maxX && y >= minY && y <= maxY)
366  gridCell.MoveDynamicItem(item, m_iGridUpdateId);
367  else
368  gridCell.UnregisterDynamicItem(item, m_iGridUpdateId);
369  }
370  }
371 
372  int currentCellPosition;
373 
374  for (int y = minY; y <= maxY; ++y)
375  {
376  for (int x = minX; x <= maxX; ++x)
377  {
378  if (x >= prevMinX && x <= prevMaxX && y >= prevMinY && y <= prevMaxY)
379  {
380  x = prevMaxX;
381 
382  continue;
383  }
384 
385  currentCellPosition = y << CELL_POWER | x;
386  gridCell = m_Cells[currentCellPosition];
387 
388  if (!gridCell)
389  m_Cells[currentCellPosition] = new SCR_ResourceGridCell(currentCellPosition);
390 
391  m_Cells[currentCellPosition].RegisterDynamicItem(item, m_iGridUpdateId);
392  }
393  }
394 
395  item.SetGridContainersBounds(minY << CELL_POWER | minX, maxY << CELL_POWER | maxX);
396  item.SetGridUpdateId(m_iGridUpdateId);
397  }
398 
399  //------------------------------------------------------------------------------------------------
400  void PromoteResourceItemToDynamic(notnull SCR_ResourceComponent item)
401  {
402  array<SCR_ResourceGridCell> cells = {};
403  int mins, maxs;
404 
405  item.GetGridContainersBounds(mins, maxs);
406  QueryGridCells(mins, maxs, cells);
407 
408  foreach (SCR_ResourceGridCell cell: cells)
409  {
410  cell.PromoteResourceItemToDynamic(item);
411  }
412  }
413 
414  //------------------------------------------------------------------------------------------------
415  void PromoteResourceItemToStatic(notnull SCR_ResourceComponent item)
416  {
417  array<SCR_ResourceGridCell> cells = {};
418  int mins, maxs;
419 
420  item.GetGridContainersBounds(mins, maxs);
421  QueryGridCells(mins, maxs, cells);
422 
423  foreach (SCR_ResourceGridCell cell: cells)
424  {
425  cell.PromoteResourceItemToStatic(item);
426  }
427  }
428 
429  //------------------------------------------------------------------------------------------------
430  protected void QueryGridCells(int mins, int maxs, inout notnull array<SCR_ResourceGridCell> gridCells)
431  {
433  int minX = mins & CELL_SIZE_MINUS_1;
434  int minY = mins >> CELL_POWER;
435  int maxX = maxs & CELL_SIZE_MINUS_1;
436  int maxY = maxs >> CELL_POWER;
437 
438  SCR_ResourceGridCell gridCell;
439 
440  for (int y = minY; y <= maxY; ++y)
441  {
442  for (int x = minX; x <= maxX; ++x)
443  {
444  gridCell = m_Cells[y << CELL_POWER | x];
445 
446  if (!gridCell)
447  continue;
448 
449  gridCells.Insert(gridCell);
450  }
451  }
452  }
453 
454  //------------------------------------------------------------------------------------------------
455  void QueryContainers(vector boundsMins, vector boundsMaxs, EResourceType resourceType)
456  {
458  int minX = (int)boundsMins[0] >> CELL_POWER;
459  int minY = (int)boundsMins[2] >> CELL_POWER;
460  int maxX = (int)boundsMaxs[0] >> CELL_POWER;
461  int maxY = (int)boundsMaxs[2] >> CELL_POWER;
462 
463  SCR_ResourceGridCell gridCell;
464 
465  for (int y = minY; y <= maxY; ++y)
466  {
467  for (int x = minX; x <= maxX; ++x)
468  {
469  gridCell = m_Cells[y << CELL_POWER | x];
470 
471  if (!gridCell)
472  continue;
473 
474  foreach (SCR_ResourceComponent item: gridCell.GetResourceStaticItems())
475  {
476  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
477  }
478 
479  foreach (SCR_ResourceComponent item: gridCell.GetResourceDynamicItems())
480  {
481  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
482  }
483  }
484  }
485  }
486 
487  //------------------------------------------------------------------------------------------------
488  void QueryContainers(int mins, int maxs, EResourceType resourceType)
489  {
491  int minX = mins & CELL_SIZE_MINUS_1;
492  int minY = mins >> CELL_POWER;
493  int maxX = maxs & CELL_SIZE_MINUS_1;
494  int maxY = maxs >> CELL_POWER;
495 
496  SCR_ResourceGridCell gridCell;
497 
498  for (int y = minY; y <= maxY; ++y)
499  {
500  for (int x = minX; x <= maxX; ++x)
501  {
502  gridCell = m_Cells[y << CELL_POWER | x];
503 
504  if (!gridCell)
505  continue;
506 
507  foreach (SCR_ResourceComponent item: gridCell.GetResourceStaticItems())
508  {
509  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
510  }
511 
512  foreach (SCR_ResourceComponent item: gridCell.GetResourceDynamicItems())
513  {
514  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
515  }
516  }
517  }
518  }
519 
520  //------------------------------------------------------------------------------------------------
521  void QueryContainers(vector boundsMins, vector boundsMaxs, EResourceType resourceType, int gridUpdateId)
522  {
524  int minX = (int)boundsMins[0] >> CELL_POWER;
525  int minY = (int)boundsMins[2] >> CELL_POWER;
526  int maxX = (int)boundsMaxs[0] >> CELL_POWER;
527  int maxY = (int)boundsMaxs[2] >> CELL_POWER;
528 
529  SCR_ResourceGridCell gridCell;
530  array<SCR_ResourceComponent> gridCellItems;
531  SCR_ResourceComponent item;
532 
533  for (int y = minY; y <= maxY; ++y)
534  {
535  for (int x = minX; x <= maxX; ++x)
536  {
537  gridCell = m_Cells[y << CELL_POWER | x];
538 
539  if (!gridCell || gridCell.GetGridUpdateId() <= gridUpdateId)
540  continue;
541 
542  gridCellItems = gridCell.GetResourceStaticItems();
543 
544  for (int idx = gridCellItems.Count() - 1; idx >= 0; --idx)
545  {
546  item = gridCellItems[idx];
547 
548  if (item.IsGridUpdateIdGreaterThan(gridUpdateId))
549  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
550  else
551  break;
552  }
553 
554  gridCellItems = gridCell.GetResourceDynamicItems();
555 
556  for (int idx = gridCellItems.Count() - 1; idx >= 0; --idx)
557  {
558  item = gridCellItems[idx];
559 
560  if (item.IsGridUpdateIdGreaterThan(gridUpdateId))
561  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
562  }
563  }
564  }
565  }
566 
567  //------------------------------------------------------------------------------------------------
568  void QueryContainers(int mins, int maxs, EResourceType resourceType, int gridUpdateId)
569  {
571  int minX = mins & CELL_SIZE_MINUS_1;
572  int minY = mins >> CELL_POWER;
573  int maxX = maxs & CELL_SIZE_MINUS_1;
574  int maxY = maxs >> CELL_POWER;
575 
576  SCR_ResourceGridCell gridCell;
577  array<SCR_ResourceComponent> gridCellItems;
578  SCR_ResourceComponent item;
579 
580  for (int y = minY; y <= maxY; ++y)
581  {
582  for (int x = minX; x <= maxX; ++x)
583  {
584  gridCell = m_Cells[y << CELL_POWER | x];
585 
586  if (!gridCell || gridCell.GetGridUpdateId() <= gridUpdateId)
587  continue;
588 
589  gridCellItems = gridCell.GetResourceStaticItems();
590 
591  for (int idx = gridCellItems.Count() - 1; idx >= 0; --idx)
592  {
593  item = gridCellItems[idx];
594 
595  if (item.IsGridUpdateIdGreaterThan(gridUpdateId))
596  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
597  else
598  break;
599  }
600 
601  gridCellItems = gridCell.GetResourceDynamicItems();
602 
603  for (int idx = gridCellItems.Count() - 1; idx >= 0; --idx)
604  {
605  item = gridCellItems[idx];
606 
607  if (item.IsGridUpdateIdGreaterThan(gridUpdateId))
608  m_aQueriedContainers.Insert(item.GetContainer(resourceType));
609  }
610  }
611  }
612  }
613 
614  //------------------------------------------------------------------------------------------------
615  void UpdateInteractor(notnull SCR_ResourceInteractor interactor, bool useFrameBudget = false)
616  {
617  int gridUpdateId = interactor.GetGridUpdateId();
618  vector interactorOrigin = interactor.GetOwnerOrigin();
619  bool hasInteractorMoved = vector.DistanceSq(interactorOrigin, interactor.GetLastPosition()) > SCR_ResourceComponent.UPDATE_DISTANCE_TRESHOLD_SQUARE;
620 
621  if (!hasInteractorMoved && gridUpdateId == m_iGridUpdateId || interactor.IsIsolated())
622  return;
623 
624  float resourceGridRange = interactor.GetResourceGridRange();
625  vector boundsOffset = vector.One * resourceGridRange;
626  EResourceType resourceType = interactor.GetResourceType();
627  SCR_ResourceContainerQueueBase containerQueue = interactor.GetContainerQueue();
628  SCR_ResourceContainer container;
629 
630  if (hasInteractorMoved)
631  {
632  QueryContainers(interactorOrigin - boundsOffset, interactorOrigin + boundsOffset, resourceType);
633 
634  for (int idx = containerQueue.GetContainerCount() - 1; idx >= 0; --idx)
635  {
636  container = containerQueue.GetContainerAt(idx);
637 
638  if (!container || container.IsIsolated())
639  continue;
640 
641  m_aQueriedContainers.Insert(container);
642  }
643  }
644  else
645  {
646  QueryContainers(interactorOrigin - boundsOffset, interactorOrigin + boundsOffset, resourceType, gridUpdateId);
647 
648  for (int idx = containerQueue.GetContainerCount() - 1; idx >= 0; --idx)
649  {
650  container = containerQueue.GetContainerAt(idx);
651 
652  if (!container || container.IsIsolated())
653  continue;
654 
655  if (container.IsGridUpdateIdGreaterThan(gridUpdateId))
656  m_aQueriedContainers.Insert(container);
657  }
658  }
659 
660  m_aQueriedContainers.RemoveItem(null);
661 
662  int containerCount = m_aQueriedContainers.Count();
663 
664  if (useFrameBudget)
665  m_iFrameBudget -= containerCount;
666 
667  for (int idx = containerCount - 1; idx >= 0; --idx)
668  {
669  container = m_aQueriedContainers[idx];
670 
671  if (interactor.CanInteractWith(container) && container.IsInRange(interactorOrigin, resourceGridRange))
672  {
673  if (!container.IsInteractorLinked(interactor))
674  interactor.RegisterContainerForced(container);
675  }
676  else
677  interactor.UnregisterContainer(container);
678  }
679 
680  interactor.SetGridUpdateId(m_iGridUpdateId);
681  interactor.UpdateLastPosition();
682  m_aQueriedContainers.Clear();
683  interactor.Replicate();
684  }
685 
686  //------------------------------------------------------------------------------------------------
690  array<SCR_ResourceGenerator> QueryGenerators(float range, vector origin)
691  {
692  return null;
693  }
694 
695  //------------------------------------------------------------------------------------------------
699  array<SCR_ResourceGenerator> QueryGenerators(vector mins, vector maxs, vector transform[4])
700  {
701  return null;
702  }
703 
704  //------------------------------------------------------------------------------------------------
705  bool ProcessResourceItem(notnull SCR_ResourceComponent item)
706  {
708  if (item.GetOwner().GetOrigin() == vector.Zero)
709  return false;
710 
711  vector boundsMins, boundsMaxs;
712 
713  item.GetGridContainersWorldBoundingBox(boundsMins, boundsMaxs);
714 
715  SCR_ResourceGridCell currentCell;
716  int currentCellPosition;
717  int minX = (int)boundsMins[0] >> CELL_POWER;
718  int minY = (int)boundsMins[2] >> CELL_POWER;
719  int maxX = (int)boundsMaxs[0] >> CELL_POWER;
720  int maxY = (int)boundsMaxs[2] >> CELL_POWER;
721 
722  for (int y = minY; y <= maxY; ++y)
723  {
724  for (int x = minX; x <= maxX; ++x)
725  {
726  currentCellPosition = y << CELL_POWER | x;
727  currentCell = m_Cells[currentCellPosition];
728 
729  if (!currentCell)
730  {
731  m_Cells[currentCellPosition] = new SCR_ResourceGridCell(currentCellPosition);
732  currentCell = m_Cells[currentCellPosition];
733  }
734 
735  currentCell.RegisterStaticItem(item, m_iGridUpdateId);
736  }
737  }
738 
739  item.SetGridContainersBounds(minY << CELL_POWER | minX, maxY << CELL_POWER | maxX);
740  item.SetGridUpdateId(m_iGridUpdateId);
741 
742  return true;
743  }
744 
745  //------------------------------------------------------------------------------------------------
746  void UnregisterResourceItem(notnull SCR_ResourceComponent item)
747  {
748  SCR_ResourceGridCell gridCell;
749  int previousMins, previousMaxs;
750 
752  item.GetGridContainersBounds(previousMins, previousMaxs);
753 
755  if (previousMins == 0xFFFFFFFF || previousMaxs == 0xFFFFFFFF)
756  return;
757 
759  int prevMinX = previousMins & CELL_SIZE_MINUS_1;
760  int prevMinY = previousMins >> CELL_POWER;
761  int prevMaxX = previousMaxs & CELL_SIZE_MINUS_1;
762  int prevMaxY = previousMaxs >> CELL_POWER;
763 
765  for (int y = prevMinY; y <= prevMaxY; ++y)
766  {
767  for (int x = prevMinX; x <= prevMaxX; ++x)
768  {
769  gridCell = m_Cells[y << CELL_POWER | x];
770 
771  if (!gridCell)
772  continue;
773 
774  if (!gridCell.UnregisterStaticItem(item, m_iGridUpdateId))
775  gridCell.UnregisterDynamicItem(item, m_iGridUpdateId)
776  }
777  }
778 
780  item.SetGridContainersBounds(0xFFFFFFFF, 0xFFFFFFFF);
781  item.SetGridUpdateId(int.MIN);
782  }
783 
784  //------------------------------------------------------------------------------------------------
786  {
787  vector mins;
788  vector maxs;
789  vector coordinateSizes;
790  BaseWorld world = GetGame().GetWorld();
791  m_Cells = new map<int, ref SCR_ResourceGridCell>();
792 
793  if (world)
794  {
795  world.GetBoundBox(mins, maxs);
796 
797  coordinateSizes = maxs - mins;
798  m_iGridPerimeter = Math.Max(coordinateSizes[0], coordinateSizes[2]);
799  m_iGridPerimeter = (m_iGridPerimeter >> CELL_POWER) + 1;
800  }
801  else
802  m_iGridPerimeter = (32000 >> CELL_POWER) + 1;
803 
805  }
806 
807  //------------------------------------------------------------------------------------------------
809  {
810  m_Cells.Clear();
811  }
812 }
SCR_ResourceGrid
void SCR_ResourceGrid()
Definition: SCR_ResourceGrid.c:785
GetFrameBudget
int GetFrameBudget()
Definition: SCR_ResourceGrid.c:188
m_iFrameBudget
protected int m_iFrameBudget
Definition: SCR_ResourceGrid.c:179
QueryGridCells
protected void QueryGridCells(int mins, int maxs, inout notnull array< SCR_ResourceGridCell > gridCells)
Definition: SCR_ResourceGrid.c:430
~SCR_ResourceGrid
void ~SCR_ResourceGrid()
Definition: SCR_ResourceGrid.c:808
QueryGenerators
array< SCR_ResourceGenerator > QueryGenerators(float range, vector origin)
Definition: SCR_ResourceGrid.c:690
UnflagResourceItem
void UnflagResourceItem(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:233
PromoteResourceItemToStatic
void PromoteResourceItemToStatic(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:415
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
FlagResourceItem
void FlagResourceItem(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:227
PromoteResourceItemToDynamic
void PromoteResourceItemToDynamic(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:400
ResetFrameBudget
void ResetFrameBudget()
Definition: SCR_ResourceGrid.c:194
QueryContainers
void QueryContainers(vector boundsMins, vector boundsMaxs, EResourceType resourceType)
Definition: SCR_ResourceGrid.c:455
SCR_ResourceContainerQueueBase
Definition: SCR_ResourceContainerQueue.c:2
UpdateInteractor
void UpdateInteractor(notnull SCR_ResourceInteractor interactor, bool useFrameBudget=false)
Definition: SCR_ResourceGrid.c:615
SCR_ResourceGridCell
Definition: SCR_ResourceGrid.c:1
UpdateResourceStaticItem
void UpdateResourceStaticItem(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:256
m_aFlaggedItems
protected ref array< SCR_ResourceComponent > m_aFlaggedItems
Definition: SCR_ResourceGrid.c:174
ComputeIndex
int ComputeIndex(int x, int z)
Definition: SCR_ResourceGrid.c:200
GetGridUpdateId
int GetGridUpdateId()
Definition: SCR_ResourceGrid.c:182
UnregisterResourceItem
void UnregisterResourceItem(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:746
m_aQueriedContainers
protected ref set< SCR_ResourceContainer > m_aQueriedContainers
Definition: SCR_ResourceGrid.c:175
m_iGridPerimeter
protected int m_iGridPerimeter
Definition: SCR_ResourceGrid.c:177
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
MAX_FRAME_BUDGET
SCR_ResourceGridCell MAX_FRAME_BUDGET
m_iIndex
private int m_iIndex
Definition: SCR_StressTestGroupActivation.c:11
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
UpdateResourceDynamicItem
void UpdateResourceDynamicItem(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:328
m_Cells
protected ref map< int, ref SCR_ResourceGridCell > m_Cells
Definition: SCR_ResourceGrid.c:173
m_iGridUpdateId
protected int m_iGridUpdateId
Definition: SCR_ResourceComponent.c:50
IncreaseGridUpdateId
int IncreaseGridUpdateId()
Definition: SCR_ResourceGrid.c:218
ProcessResourceItem
bool ProcessResourceItem(notnull SCR_ResourceComponent item)
Definition: SCR_ResourceGrid.c:705
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
int
SCR_PossessingManagerComponentClass int
ProcessFlaggedItems
void ProcessFlaggedItems()
Definition: SCR_ResourceGrid.c:239
m_iGridUpdateId
protected int m_iGridUpdateId
Definition: SCR_ResourceGrid.c:176
m_iGridPerimeterMinusOne
protected int m_iGridPerimeterMinusOne
Definition: SCR_ResourceGrid.c:178