@rbxts/replecs 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,12 @@
1
1
  --!native
2
2
  --!optimize 2
3
3
 
4
- local jecs = require "../jecs"
5
- local utils = require "./utils"
6
- local mask_generator = require "@self/mask_generator"
4
+ local common = require (script.Parent:WaitForChild('common'))
5
+ local utils = require (script.Parent:WaitForChild('utils'))
6
+ local mask_generator = require (script:WaitForChild('mask_generator'))
7
7
 
8
- type Entity<T = any> = jecs.Entity<T>
8
+ type Entity = common.Entity
9
+ type Component<T = any> = common.Component<T>
9
10
 
10
11
  type Bitmask = utils.Bitmask
11
12
  type MaskGenerator = mask_generator.MaskGenerator
@@ -25,33 +26,46 @@ export type FunctionFilter = (player: Player) -> boolean
25
26
  export type ComponentIndex<T> = {
26
27
  [number]: { [Entity]: T },
27
28
  }
29
+
28
30
  export type EntityComponentIndex<T> = {
29
31
  [Entity]: ComponentIndex<T>,
30
32
  }
31
33
 
32
- type Lookup = {
34
+ export type Lookup = {
33
35
  generator: MaskGenerator,
34
36
  filter: MemberFilter?,
35
37
  storage_group: StorageGroup,
36
38
  }
37
39
 
38
- type ComponentLookup = Lookup & {
40
+ export type ComponentLookup = Lookup & {
39
41
  band_generator: MaskGenerator,
40
42
  }
41
43
 
42
- type EntityLookup = Lookup & {
44
+ export type EntityLookup = Lookup & {
43
45
  filtered_components: ComponentIndex<ComponentLookup>,
44
46
  components: ComponentIndex<true>,
45
47
  }
46
48
 
47
49
  export type EntityChanges = {
48
- tagged: { [Entity]: boolean },
49
- component: { [Entity]: any },
50
- removed: { [Entity]: boolean },
51
- pairs: { [Entity]: Set<Entity> },
52
- pairs_values: {
53
- changed: { [Entity]: Map<Entity, any> },
54
- removed: { [Entity]: Set<Entity> },
50
+ tagged: Set<Component>,
51
+ component: Map<Component, any>,
52
+ removed: {
53
+ component: Set<Component>,
54
+ tag: Set<Component>,
55
+ },
56
+
57
+ pair_changed: Map<Component, any>,
58
+ pair_added: Set<Component>,
59
+ pair_removed: {
60
+ component: Set<Component>,
61
+ tag: Set<Component>,
62
+ },
63
+
64
+ relation_added: { [Component]: Set<Entity> },
65
+ relation_value: { [Component]: Map<Entity, any> },
66
+ relation_removed: {
67
+ component: { [Component]: Set<Entity> },
68
+ tag: { [Component]: Set<Entity> },
55
69
  },
56
70
  }
57
71
 
@@ -84,7 +98,7 @@ type MaskInfo = {
84
98
  members: Array<Member>,
85
99
  }
86
100
 
87
- type StorageGroup = {
101
+ export type StorageGroup = {
88
102
  mask: MaskInfo,
89
103
  shared_with: EntityComponentIndex<boolean>,
90
104
  is_empty: boolean,
@@ -109,7 +123,7 @@ type Storages = {
109
123
  [MaskHash]: StorageGroup,
110
124
  }
111
125
 
112
- export type MaskingController = {
126
+ export type MaskingControllerClass = {
113
127
  member_count: number,
114
128
 
115
129
  client_indexes: { [Member]: number },
@@ -125,103 +139,26 @@ export type MaskingController = {
125
139
 
126
140
  storages: Storages,
127
141
  lookups: LookupsList,
128
-
129
- register_mask_group: (self: MaskingController, group: Member) -> (),
130
- unregister_mask_group: (self: MaskingController, group: Member) -> (),
131
- register_client: (self: MaskingController, member: Member) -> (),
132
- unregister_client: (self: MaskingController, member: Member) -> (),
133
- activate_client: (self: MaskingController, member: Member) -> (),
134
- member_is_active: (self: MaskingController, member: Member) -> boolean,
135
-
136
- register_stop_entity: (self: MaskingController, entity: Entity) -> (),
137
- register_stop_component: (
138
- self: MaskingController,
139
- entity: Entity,
140
- component: Entity,
141
- component_type: number
142
- ) -> (),
143
- register_component_addition: (
144
- self: MaskingController,
145
- entity: Entity,
146
- component: Entity,
147
- component_type: number
148
- ) -> (),
149
- unregister_component_addition: (
150
- self: MaskingController,
151
- entity: Entity,
152
- component: Entity,
153
- component_type: number
154
- ) -> (),
155
- unregister_stop_entity: (self: MaskingController, entity: Entity) -> (),
156
- unregister_stop_component: (
157
- self: MaskingController,
158
- entity: Entity,
159
- component: Entity,
160
- component_type: number
161
- ) -> (),
162
-
163
- propagate_entity_addition: (self: MaskingController, entity: Entity) -> (),
164
-
165
- start_entity: (self: MaskingController, entity: Entity, filter: GivenFilter?) -> (),
166
- set_entity: (self: MaskingController, entity: Entity, filter: GivenFilter?) -> (),
167
- stop_entity: (self: MaskingController, entity: Entity) -> (),
168
- cleanup_entity: (self: MaskingController, entity: Entity) -> (),
169
-
170
- start_component: (
171
- self: MaskingController,
172
- entity: Entity,
173
- component: Entity,
174
- component_type: number,
175
- filter: GivenFilter?
176
- ) -> (),
177
- set_component: (
178
- self: MaskingController,
179
- entity: Entity,
180
- component: Entity,
181
- component_type: number,
182
- filter: GivenFilter?
183
- ) -> (),
184
- stop_component: (self: MaskingController, entity: Entity, component: Entity, component_type: number) -> (),
185
-
186
- allocate_entity_addition: (
187
- self: MaskingController,
188
- entity: Entity,
189
- component: Entity,
190
- component_type: number
191
- ) -> (),
192
-
193
- allocate_component_change: (self: MaskingController, entity: Entity, component: Entity, value: any) -> (),
194
- allocate_pair_value_change: (
195
- self: MaskingController,
196
- entity: Entity,
197
- relation: Entity,
198
- target: Entity,
199
- value: any
200
- ) -> (),
201
-
202
- allocate_tag_addition: (self: MaskingController, entity: Entity, tag: Entity) -> (),
203
- allocate_pair_addition: (self: MaskingController, entity: Entity, relation: Entity, target: Entity) -> (),
204
-
205
- allocate_component_removal: (self: MaskingController, entity: Entity, component: Entity) -> (),
206
- allocate_pair_value_removal: (self: MaskingController, entity: Entity, relation: Entity, target: Entity) -> (),
207
- allocate_tag_removal: (self: MaskingController, entity: Entity, tag: Entity) -> (),
208
- allocate_pair_removal: (self: MaskingController, entity: Entity, relation: Entity, target: Entity) -> (),
209
142
  }
210
143
 
211
144
  local COMPONENT_TYPES = {
212
- component = 1,
213
- tag = 2,
214
- pair = 3,
215
- pair_value = 4,
216
- unreliable = 5,
145
+ tag = 1,
146
+ component = 2,
147
+ pair_tag = 3,
148
+ pair_component = 4,
149
+ relation = 5,
150
+ relation_value = 6,
151
+ unreliable = 7,
217
152
  }
218
153
 
154
+ local COMPONENT_TYPES_COUNT = COMPONENT_TYPES.unreliable
155
+
219
156
  local masking_controller = {}
220
157
  masking_controller.__index = masking_controller
221
158
 
222
- export type MaskingInternal = MaskingController & typeof(masking_controller)
159
+ export type MaskingController = MaskingControllerClass & typeof(masking_controller)
223
160
 
224
- function masking_controller.get_clients_from_bitmask(controller: MaskingInternal, bitmask: Bitmask): Array<Member>
161
+ function masking_controller.get_clients_from_bitmask(controller: MaskingController, bitmask: Bitmask): Array<Member>
225
162
  local members: { Member } = {}
226
163
  for player, index in controller.client_indexes do
227
164
  if bitmask:get(index) then
@@ -243,25 +180,41 @@ local function get_usable_filter(filter: (MemberFilter | any)?): MemberFilter?
243
180
  end
244
181
  end
245
182
 
246
- local function create_component_indexes<T>()
247
- return { {}, {}, {}, {}, {} } :: ComponentIndex<any>
183
+ local function create_component_indexes<T>(): ComponentIndex<T>
184
+ local indexes = {}
185
+ for i = 1, COMPONENT_TYPES_COUNT do
186
+ indexes[i] = {}
187
+ end
188
+ return indexes
248
189
  end
249
190
 
250
191
  local function create_entity_changes(): EntityChanges
251
192
  return {
252
193
  tagged = {},
253
194
  component = {},
254
- removed = {},
255
- pairs = {},
256
- pairs_values = {
257
- changed = {},
258
- removed = {},
195
+ removed = {
196
+ component = {},
197
+ tag = {},
198
+ },
199
+
200
+ pair_added = {},
201
+ pair_changed = {},
202
+ pair_removed = {
203
+ component = {},
204
+ tag = {},
205
+ },
206
+
207
+ relation_added = {},
208
+ relation_value = {},
209
+ relation_removed = {
210
+ component = {},
211
+ tag = {},
259
212
  },
260
213
  }
261
214
  end
262
215
 
263
216
  function masking_controller.create_new_storage(
264
- controller: MaskingInternal,
217
+ controller: MaskingController,
265
218
  bitmask: Bitmask,
266
219
  hash: string?,
267
220
  members: Array<Member>?
@@ -313,7 +266,7 @@ end
313
266
  local function get_component_index_entry<T>(
314
267
  index: EntityComponentIndex<T>,
315
268
  entity: Entity,
316
- component: Entity,
269
+ component: Component,
317
270
  component_type: number
318
271
  ): T?
319
272
  local entity_index = index[entity]
@@ -328,7 +281,7 @@ end
328
281
  local function set_component_index_entry<T>(
329
282
  index: EntityComponentIndex<T>,
330
283
  entity: Entity,
331
- component: Entity,
284
+ component: Component,
332
285
  component_type: number,
333
286
  value: T
334
287
  )
@@ -343,7 +296,7 @@ end
343
296
  local function remove_component_index_entry(
344
297
  index: EntityComponentIndex<any>,
345
298
  entity: Entity,
346
- component: Entity,
299
+ component: Component,
347
300
  component_type: number
348
301
  )
349
302
  local entity_index = index[entity]
@@ -415,10 +368,10 @@ local function remove_active(storage: StorageGroup, entity: Entity): ActiveEntit
415
368
  -- todo: check if empty
416
369
  return active
417
370
  end
418
- return utils.logerror "attempted to remove an entity that wasn't active"
371
+ return common.log_error "attempted to remove an entity that wasn't active"
419
372
  end
420
373
 
421
- local function get_or_set_component_active(active: ActiveEntity, component: Entity, component_type: number)
374
+ local function get_or_set_component_active(active: ActiveEntity, component: Component, component_type: number)
422
375
  local components = active.components[component_type]
423
376
  if components[component] == nil then
424
377
  components[component] = true
@@ -426,7 +379,12 @@ local function get_or_set_component_active(active: ActiveEntity, component: Enti
426
379
  end
427
380
  end
428
381
 
429
- local function remove_component_active(storage: StorageGroup, entity: Entity, component: Entity, component_type: number)
382
+ local function remove_component_active(
383
+ storage: StorageGroup,
384
+ entity: Entity,
385
+ component: Component,
386
+ component_type: number
387
+ )
430
388
  local active = storage.active[entity]
431
389
  if not active then
432
390
  return
@@ -443,7 +401,7 @@ local function remove_component_active(storage: StorageGroup, entity: Entity, co
443
401
  end
444
402
  end
445
403
 
446
- function masking_controller.get_or_create_storage_group(masking: MaskingInternal, bitmask: Bitmask): StorageGroup
404
+ function masking_controller.get_or_create_storage_group(masking: MaskingController, bitmask: Bitmask): StorageGroup
447
405
  local hash = bitmask:tostring()
448
406
  local storage = masking.storages[hash]
449
407
 
@@ -455,12 +413,16 @@ function masking_controller.get_or_create_storage_group(masking: MaskingInternal
455
413
  end
456
414
 
457
415
  function masking_controller.get_component_lookup(
458
- masking: MaskingInternal,
416
+ masking: MaskingController,
459
417
  entity: Entity,
460
- component: Entity,
418
+ component: Component,
461
419
  component_type: number
462
420
  ): (ComponentLookup, EntityLookup)
463
421
  local entity_lookup = masking.lookups.entities[entity]
422
+ if not entity_lookup then
423
+ return nil :: any
424
+ end
425
+
464
426
  return entity_lookup.filtered_components[component_type][component], entity_lookup
465
427
  end
466
428
 
@@ -505,48 +467,127 @@ end
505
467
  local function dissect_component_changes(changes: EntityChanges, shared_index: ComponentIndex<boolean>)
506
468
  local new_changes: EntityChanges
507
469
 
470
+ -- COMPONENTS
471
+
472
+ local shared_component = shared_index[COMPONENT_TYPES.component]
473
+ local shared_tag = shared_index[COMPONENT_TYPES.tag]
474
+
508
475
  for component, change in changes.component do
509
- local is_shared = shared_index[COMPONENT_TYPES.component] and shared_index[COMPONENT_TYPES.component][component]
476
+ local is_shared = shared_component and shared_component[component]
510
477
  if is_shared then
511
478
  new_changes = new_changes or create_entity_changes()
512
479
  new_changes.component[component] = change
513
480
  changes.component[component] = nil
514
481
  end
515
482
  end
516
- for entity, entity_changes in changes.tagged do
517
- local is_shared = shared_index[COMPONENT_TYPES.tag] and shared_index[COMPONENT_TYPES.tag][entity]
483
+ for tag in changes.tagged do
484
+ local is_shared = shared_tag and shared_tag[tag]
485
+ if is_shared then
486
+ new_changes = new_changes or create_entity_changes()
487
+ new_changes.tagged[tag] = true
488
+ changes.tagged[tag] = nil
489
+ end
490
+ end
491
+
492
+ local removed_changes = changes.removed
493
+ for component in removed_changes.component do
494
+ local is_shared = shared_component and shared_component[component]
495
+ if is_shared then
496
+ new_changes = new_changes or create_entity_changes()
497
+ new_changes.removed.component[component] = true
498
+ removed_changes.component[component] = nil
499
+ end
500
+ end
501
+ for component in removed_changes.tag do
502
+ local is_shared = shared_tag and shared_tag[component]
503
+ if is_shared then
504
+ new_changes = new_changes or create_entity_changes()
505
+ new_changes.removed.tag[component] = true
506
+ removed_changes.tag[component] = nil
507
+ end
508
+ end
509
+
510
+ -- PAIRS
511
+
512
+ local shared_pair_component = shared_index[COMPONENT_TYPES.pair_component]
513
+ local shared_pair_tag = shared_index[COMPONENT_TYPES.pair_tag]
514
+
515
+ for id, change in changes.pair_changed do
516
+ local is_shared = shared_pair_component and shared_pair_component[id]
517
+ if is_shared then
518
+ new_changes = new_changes or create_entity_changes()
519
+ new_changes.pair_changed[id] = change
520
+ changes.pair_changed[id] = nil
521
+ end
522
+ end
523
+ for id in changes.pair_added do
524
+ local is_shared = shared_pair_tag and shared_pair_tag[id]
525
+ if is_shared then
526
+ new_changes = new_changes or create_entity_changes()
527
+ new_changes.pair_added[id] = true
528
+ changes.pair_added[id] = nil
529
+ end
530
+ end
531
+
532
+ local removed_pairs = changes.pair_removed
533
+ for id in removed_pairs.component do
534
+ local is_shared = shared_pair_component and shared_pair_component[id]
535
+ if is_shared then
536
+ new_changes = new_changes or create_entity_changes()
537
+ new_changes.pair_removed.component[id] = true
538
+ removed_pairs.component[id] = nil
539
+ end
540
+ end
541
+ for id in removed_pairs.tag do
542
+ local is_shared = shared_pair_tag and shared_pair_tag[id]
543
+ if is_shared then
544
+ new_changes = new_changes or create_entity_changes()
545
+ new_changes.pair_removed.tag[id] = true
546
+ removed_pairs.tag[id] = nil
547
+ end
548
+ end
549
+
550
+ -- RELATIONS
551
+
552
+ local shared_relation_value = shared_index[COMPONENT_TYPES.relation_value]
553
+ local shared_relation = shared_index[COMPONENT_TYPES.relation]
554
+
555
+ for relation, target_values in changes.relation_value do
556
+ local is_shared = shared_relation_value and shared_relation_value[relation]
557
+
518
558
  if is_shared then
519
559
  new_changes = new_changes or create_entity_changes()
520
- new_changes.tagged[entity] = entity_changes
521
- changes.tagged[entity] = nil
560
+ new_changes.relation_value[relation] = target_values
561
+ changes.relation_value[relation] = nil
522
562
  end
523
563
  end
524
- for relation, entity_changes in changes.pairs do
525
- local is_shared = shared_index[COMPONENT_TYPES.pair] and shared_index[COMPONENT_TYPES.pair][relation]
564
+ for relation, targets_added in changes.relation_added do
565
+ local is_shared = shared_relation and shared_relation[relation]
566
+
526
567
  if is_shared then
527
568
  new_changes = new_changes or create_entity_changes()
528
- new_changes.pairs[relation] = entity_changes
529
- changes.pairs[relation] = nil
569
+ new_changes.relation_added[relation] = targets_added
570
+ changes.relation_added[relation] = nil
530
571
  end
531
572
  end
532
- for relation, entity_changes in changes.pairs_values.changed do
533
- local is_shared = shared_index[COMPONENT_TYPES.pair_value]
534
- and shared_index[COMPONENT_TYPES.pair_value][relation]
573
+
574
+ local removed_relations = changes.relation_removed
575
+ for relation, targets_removed in removed_relations.component do
576
+ local is_shared = shared_relation and shared_relation[relation]
535
577
 
536
578
  if is_shared then
537
579
  new_changes = new_changes or create_entity_changes()
538
- new_changes.pairs_values.changed[relation] = entity_changes
539
- changes.pairs_values.changed[relation] = nil
580
+ new_changes.relation_removed.component[relation] = targets_removed
581
+ removed_relations.component[relation] = nil
540
582
  end
541
583
  end
542
- for relation, entity_changes in changes.pairs_values.removed do
543
- local is_shared = shared_index[COMPONENT_TYPES.pair_value]
544
- and shared_index[COMPONENT_TYPES.pair_value][relation]
584
+ for relation, targets_removed in removed_relations.tag do
585
+ local is_shared = shared_relation and shared_relation[relation]
545
586
 
546
587
  if is_shared then
547
588
  new_changes = new_changes or create_entity_changes()
548
- new_changes.pairs_values.removed[relation] = entity_changes
549
- changes.pairs_values.removed[relation] = nil
589
+ new_changes.relation_removed.tag[relation] = targets_removed
590
+ removed_relations.tag[relation] = nil
550
591
  end
551
592
  end
552
593
 
@@ -569,27 +610,68 @@ local function merge_component_additions(current: ComponentIndex<boolean>, targe
569
610
  end
570
611
  end
571
612
 
572
- local function merge_component_changes(current: EntityChanges, target: EntityChanges)
613
+ local function merge_component_changes(current: EntityChanges, destination: EntityChanges)
614
+ -- COMPONENTS/TAGS
615
+
573
616
  for component, change in current.component do
574
- target.component[component] = change
617
+ destination.component[component] = change
575
618
  end
576
- for entity, entity_changes in current.tagged do
577
- target.tagged[entity] = entity_changes
619
+ for tag in current.tagged do
620
+ destination.tagged[tag] = true
578
621
  end
579
- for entity, entity_changes in current.pairs do
580
- target.pairs[entity] = entity_changes
622
+
623
+ local components_removed = current.removed
624
+ for tag in components_removed.component do
625
+ destination.removed.component[tag] = true
626
+ end
627
+ for tag in components_removed.tag do
628
+ destination.removed.tag[tag] = true
629
+ end
630
+
631
+ -- PAIRS
632
+
633
+ for id, change in current.pair_changed do
634
+ destination.pair_changed[id] = change
635
+ end
636
+ for id in current.pair_added do
637
+ destination.pair_added[id] = true
638
+ end
639
+
640
+ local pairs_removed = current.pair_removed
641
+ for id in pairs_removed.component do
642
+ destination.pair_removed.component[id] = true
643
+ end
644
+ for id in pairs_removed.tag do
645
+ destination.pair_removed.tag[id] = true
646
+ end
647
+
648
+ -- RELATIONS
649
+
650
+ for relation, target_values in current.relation_value do
651
+ destination.relation_value[relation] = target_values
652
+ end
653
+ for relation, added_targets in current.relation_added do
654
+ destination.relation_added[relation] = added_targets
655
+ end
656
+
657
+ local relation_removed = current.relation_removed
658
+ for relation, removed_targets in relation_removed.component do
659
+ destination.relation_removed.component[relation] = removed_targets
660
+ end
661
+ for relation, removed_targets in relation_removed.tag do
662
+ destination.relation_removed.tag[relation] = removed_targets
581
663
  end
582
664
  end
583
665
 
584
666
  function masking_controller.merge_component_filter(
585
- masking: MaskingInternal,
667
+ masking: MaskingController,
586
668
  entity: Entity,
587
- component: Entity,
669
+ component: Component,
588
670
  component_type: number
589
671
  )
590
672
  local component_lookup, entity_lookup = masking:get_component_lookup(entity, component, component_type)
591
673
  if not entity_lookup then
592
- utils.logerror "attempted to merge a component filter to an unactive entity"
674
+ common.log_error "attempted to merge a component filter to an unactive entity"
593
675
  end
594
676
 
595
677
  if component_lookup ~= nil then
@@ -609,19 +691,19 @@ function masking_controller.merge_component_filter(
609
691
  end
610
692
 
611
693
  function masking_controller.move_entity_storage(
612
- masking: MaskingInternal,
694
+ masking: MaskingController,
613
695
  entity: Entity,
614
696
  storage: StorageGroup,
615
- target: Bitmask
697
+ destination: Bitmask
616
698
  )
617
- local target_storage = masking:get_or_create_storage_group(target)
618
- if target_storage == storage then
699
+ local destination_storage = masking:get_or_create_storage_group(destination)
700
+ if destination_storage == storage then
619
701
  return storage
620
702
  end
621
703
  local shared_with = storage.shared_with[entity]
622
704
 
623
705
  local old_active = storage.active[entity]
624
- local new_active = get_or_set_active(target_storage, entity, old_active)
706
+ local new_active = get_or_set_active(destination_storage, entity, old_active)
625
707
 
626
708
  new_active.is_entity_mask = true
627
709
 
@@ -642,7 +724,7 @@ function masking_controller.move_entity_storage(
642
724
 
643
725
  local old_component_added = storage.changes.added_components[entity]
644
726
  if old_component_added then
645
- local new_component_added = get_or_set_component_added(target_storage, entity, old_component_added)
727
+ local new_component_added = get_or_set_component_added(destination_storage, entity, old_component_added)
646
728
 
647
729
  if shared_with then
648
730
  local dissected_added = dissect_component_additions(old_component_added, shared_with)
@@ -660,7 +742,7 @@ function masking_controller.move_entity_storage(
660
742
 
661
743
  local old_changes = storage.changes.changed[entity]
662
744
  if old_changes then
663
- local new_changes = get_or_set_changed(target_storage, entity, old_changes)
745
+ local new_changes = get_or_set_changed(destination_storage, entity, old_changes)
664
746
 
665
747
  if shared_with then
666
748
  local dissected_changes = dissect_component_changes(old_changes, shared_with)
@@ -677,78 +759,90 @@ function masking_controller.move_entity_storage(
677
759
  end
678
760
 
679
761
  if storage.changes.added[entity] then
680
- target_storage.changes.added[entity] = true
762
+ destination_storage.changes.added[entity] = true
681
763
  storage.changes.added[entity] = nil
682
764
  end
683
765
 
684
- return target_storage
766
+ return destination_storage
685
767
  end
686
768
 
687
769
  function masking_controller.move_component_storage(
688
- masking: MaskingInternal,
770
+ masking: MaskingController,
689
771
  entity: Entity,
690
- component: Entity,
772
+ component: Component,
691
773
  component_type: number,
692
774
  storage: StorageGroup,
693
- target: Bitmask
775
+ destination: Bitmask
694
776
  )
695
- local target_storage = masking:get_or_create_storage_group(target)
696
- if target_storage == storage then
777
+ local destination_storage = masking:get_or_create_storage_group(destination)
778
+ if destination_storage == storage then
697
779
  return storage
698
780
  end
699
781
 
700
- local new_active = get_or_set_active(target_storage, entity)
782
+ local new_active = get_or_set_active(destination_storage, entity)
701
783
 
702
784
  remove_component_active(storage, entity, component, component_type)
703
785
  get_or_set_component_active(new_active, component, component_type)
704
786
 
705
- set_component_index_entry(target_storage.shared_with, entity, component, component_type, true)
787
+ set_component_index_entry(destination_storage.shared_with, entity, component, component_type, true)
706
788
  remove_component_index_entry(storage.shared_with, entity, component, component_type)
707
789
 
708
790
  local component_added =
709
791
  get_component_index_entry(storage.changes.added_components, entity, component, component_type)
710
792
  if component_added then
711
793
  remove_component_index_entry(storage.changes.added_components, entity, component, component_type)
712
- set_component_index_entry(target_storage.changes.added_components, entity, component, component_type, true)
794
+ set_component_index_entry(destination_storage.changes.added_components, entity, component, component_type, true)
713
795
  end
714
796
 
715
797
  local changes = storage.changes.changed[entity]
716
798
  if changes then
717
- local target_changes = get_or_set_changed(target_storage, entity)
799
+ local destination_changes = get_or_set_changed(destination_storage, entity)
718
800
  if component_type == COMPONENT_TYPES.tag then
719
- target_changes.tagged[component] = changes.tagged[component]
720
- target_changes.removed[component] = changes.removed[component]
801
+ destination_changes.tagged[component] = changes.tagged[component]
802
+ destination_changes.removed.tag[component] = changes.removed.tag[component]
721
803
 
722
804
  changes.tagged[component] = nil
723
- changes.removed[component] = nil
805
+ changes.removed.tag[component] = nil
724
806
  elseif component_type == COMPONENT_TYPES.component then
725
- target_changes.component[component] = changes.component[component]
726
- target_changes.removed[component] = changes.removed[component]
807
+ destination_changes.component[component] = changes.component[component]
808
+ destination_changes.removed.component[component] = changes.removed.component[component]
727
809
 
728
810
  changes.component[component] = nil
729
- changes.removed[component] = nil
730
- elseif component_type == COMPONENT_TYPES.pair then
731
- target_changes.pairs[component] = changes.pairs[component]
732
- changes.pairs[component] = nil
733
- elseif component_type == COMPONENT_TYPES.pair_value then
734
- local target_pairs = target_changes.pairs_values
735
- local pairs = changes.pairs_values
736
-
737
- target_pairs.changed[component] = pairs.changed[component]
738
- target_pairs.removed[component] = pairs.removed[component]
739
-
740
- pairs.changed[component] = nil
741
- pairs.removed[component] = nil
811
+ changes.removed.component[component] = nil
812
+ elseif component_type == COMPONENT_TYPES.pair_tag then
813
+ destination_changes.pair_added[component] = changes.pair_added[component]
814
+ destination_changes.pair_removed.tag[component] = changes.pair_removed.tag[component]
815
+
816
+ changes.pair_added[component] = nil
817
+ changes.pair_removed.tag[component] = nil
818
+ elseif component_type == COMPONENT_TYPES.pair_component then
819
+ destination_changes.pair_changed[component] = changes.pair_changed[component]
820
+ destination_changes.pair_removed.component[component] = changes.pair_removed.component[component]
821
+
822
+ changes.pair_changed[component] = nil
823
+ changes.pair_removed.component[component] = nil
824
+ elseif component_type == COMPONENT_TYPES.relation then
825
+ destination_changes.relation_added[component] = changes.relation_added[component]
826
+ destination_changes.relation_removed.tag[component] = changes.relation_removed.tag[component]
827
+
828
+ changes.relation_added[component] = nil
829
+ changes.relation_removed.tag[component] = nil
830
+ elseif component_type == COMPONENT_TYPES.relation_value then
831
+ destination_changes.relation_value[component] = changes.relation_value[component]
832
+ destination_changes.relation_removed.component[component] = changes.relation_removed.component[component]
833
+
834
+ changes.relation_value[component] = nil
835
+ changes.relation_removed.component[component] = nil
742
836
  end
743
837
  end
744
838
 
745
- return target_storage
839
+ return destination_storage
746
840
  end
747
841
 
748
842
  function masking_controller.bind_component_generator(
749
- masking: MaskingInternal,
843
+ masking: MaskingController,
750
844
  entity: Entity,
751
- component: Entity,
845
+ component: Component,
752
846
  component_type: number,
753
847
  base_generator: MaskGenerator
754
848
  )
@@ -776,7 +870,7 @@ function masking_controller.bind_component_generator(
776
870
  return generator
777
871
  end
778
872
 
779
- function masking_controller.rebind_component_generators(masking: MaskingInternal, entity: Entity)
873
+ function masking_controller.rebind_component_generators(masking: MaskingController, entity: Entity)
780
874
  local entity_lookup = masking.lookups.entities[entity]
781
875
  if entity_lookup then
782
876
  for component_type, lookups in entity_lookup.filtered_components do
@@ -793,9 +887,9 @@ function masking_controller.rebind_component_generators(masking: MaskingInternal
793
887
  end
794
888
 
795
889
  function masking_controller.get_or_postpone_entity_lookup(
796
- masking: MaskingInternal,
890
+ masking: MaskingController,
797
891
  entity: Entity,
798
- component: Entity,
892
+ component: Component,
799
893
  component_type: number,
800
894
  filter: MemberFilter?
801
895
  ): EntityLookup?
@@ -813,116 +907,8 @@ function masking_controller.get_or_postpone_entity_lookup(
813
907
  return nil
814
908
  end
815
909
 
816
- function masking_controller.register_stop_entity(masking: MaskingInternal, entity: Entity)
817
- local lookup = masking.lookups.entities[entity]
818
- if not lookup then
819
- return
820
- end
821
- local storage = lookup.storage_group
822
-
823
- if storage.deletions.entities[entity] then
824
- return
825
- end
826
- storage.deletions.entities[entity] = true
827
- end
828
-
829
- function masking_controller.register_stop_component(
830
- masking: MaskingInternal,
831
- entity: Entity,
832
- component: Entity,
833
- component_type: number
834
- )
835
- local storage = masking:get_component_storage_group(entity, component, component_type) :: StorageGroup
836
- if not storage then
837
- return
838
- end
839
-
840
- local deletions = storage.deletions.components[entity]
841
- if deletions == nil then
842
- deletions = create_component_indexes() :: ComponentIndex<boolean>
843
- deletions[component_type][component] = true
844
- storage.deletions.components[entity] = deletions
845
- else
846
- if deletions[component_type][component] then
847
- return
848
- end
849
- deletions[component_type][component] = true
850
- end
851
- end
852
-
853
- function masking_controller.register_component_addition(
854
- masking: MaskingInternal,
855
- entity: Entity,
856
- component: Entity,
857
- component_type: number
858
- )
859
- local storage = masking:get_component_storage_group(entity, component, component_type)
860
- local additions = get_or_set_component_added(storage, entity)
861
- additions[component_type][component] = true
862
- end
863
-
864
- function masking_controller.unregister_stop_entity(masking: MaskingInternal, entity: Entity)
865
- local deletion_lookup = masking.lookups.deletions.entities[entity]
866
- if not deletion_lookup then
867
- return
868
- end
869
- local storage = deletion_lookup.storage_group
870
-
871
- if storage.deletions.entities[entity] then
872
- storage.deletions.entities[entity] = nil
873
- storage.deletions_count -= 1
874
- end
875
- end
876
-
877
- function masking_controller.unregister_stop_component(
878
- masking: MaskingInternal,
879
- entity: Entity,
880
- component: Entity,
881
- component_type: number
882
- )
883
- local deletion_lookup =
884
- get_component_index_entry(masking.lookups.deletions.components, entity, component, component_type)
885
- if deletion_lookup == nil then
886
- return
887
- end
888
- local storage = deletion_lookup.storage_group
889
-
890
- local deletions = storage.deletions.components[entity]
891
- if deletions then
892
- if deletions[component_type][component] then
893
- deletions[component_type][component] = nil
894
- end
895
- end
896
- end
897
-
898
- function masking_controller.unregister_component_addition(
899
- masking: MaskingInternal,
900
- entity: Entity,
901
- component: Entity,
902
- component_type: number
903
- )
904
- local storage: StorageGroup = masking:get_component_storage_group(entity, component, component_type)
905
- local additions = storage.changes.added_components[entity]
906
- if additions then
907
- additions[component_type][component] = nil
908
- end
909
- end
910
-
911
- function masking_controller.propagate_entity_addition(masking: MaskingInternal, entity: Entity)
912
- local entity_lookup = masking.lookups.entities[entity]
913
- if entity_lookup then
914
- entity_lookup.storage_group.changes.added[entity] = true
915
-
916
- for _, lookups in entity_lookup.filtered_components do
917
- for _, lookup in lookups do
918
- lookup.storage_group.changes.added[entity] = true
919
- end
920
- end
921
- end
922
- end
923
-
924
910
  function masking_controller.update_entity_filter(
925
- masking: MaskingInternal,
911
+ masking: MaskingController,
926
912
  entity: Entity,
927
913
  filter: MemberFilter?
928
914
  ): MaskGenerator
@@ -948,7 +934,7 @@ function masking_controller.update_entity_filter(
948
934
  return generator
949
935
  end
950
936
 
951
- function masking_controller.start_entity(masking: MaskingInternal, entity: Entity, given_filter: GivenFilter?)
937
+ function masking_controller.start_entity(masking: MaskingController, entity: Entity, given_filter: GivenFilter?)
952
938
  local filter = get_usable_filter(given_filter)
953
939
  local generator = masking:update_entity_filter(entity, filter)
954
940
 
@@ -960,8 +946,8 @@ function masking_controller.start_entity(masking: MaskingInternal, entity: Entit
960
946
  generator = generator,
961
947
  filter = filter,
962
948
  storage_group = storage_group,
963
- filtered_components = create_component_indexes(),
964
- components = create_component_indexes(),
949
+ filtered_components = create_component_indexes() :: ComponentIndex<ComponentLookup>,
950
+ components = create_component_indexes() :: ComponentIndex<true>,
965
951
  }
966
952
  masking.lookups.entities[entity] = new_lookup
967
953
 
@@ -976,11 +962,11 @@ function masking_controller.start_entity(masking: MaskingInternal, entity: Entit
976
962
  end
977
963
  end
978
964
 
979
- function masking_controller.set_entity(masking: MaskingInternal, entity: Entity, given_filter: GivenFilter?)
965
+ function masking_controller.set_entity(masking: MaskingController, entity: Entity, given_filter: GivenFilter?)
980
966
  local filter = get_usable_filter(given_filter)
981
967
  local lookup = masking.lookups.entities[entity]
982
968
  if not lookup then
983
- utils.logerror "attempted to modify the filter of an unactive entity"
969
+ common.log_error "attempted to modify the filter of an unactive entity"
984
970
  end
985
971
  lookup.generator:destroy()
986
972
 
@@ -993,10 +979,10 @@ function masking_controller.set_entity(masking: MaskingInternal, entity: Entity,
993
979
  masking:rebind_component_generators(entity)
994
980
  end
995
981
 
996
- function masking_controller.stop_entity(masking: MaskingInternal, entity: Entity)
982
+ function masking_controller.stop_entity(masking: MaskingController, entity: Entity)
997
983
  local lookup = masking.lookups.entities[entity]
998
984
  if not lookup then
999
- utils.logerror "attemped to stop an unactive entity"
985
+ common.log_error "attemped to stop an unactive entity"
1000
986
  end
1001
987
 
1002
988
  local postponed = masking.lookups.postponed[entity]
@@ -1039,7 +1025,7 @@ function masking_controller.stop_entity(masking: MaskingInternal, entity: Entity
1039
1025
  masking.lookups.entities[entity] = nil
1040
1026
  end
1041
1027
 
1042
- function masking_controller.cleanup_entity(masking: MaskingInternal, entity: Entity)
1028
+ function masking_controller.cleanup_entity(masking: MaskingController, entity: Entity)
1043
1029
  masking.lookups.entities[entity] = nil
1044
1030
  masking.lookups.postponed[entity] = nil
1045
1031
  masking.lookups.deletions.entities[entity] = nil
@@ -1047,9 +1033,9 @@ function masking_controller.cleanup_entity(masking: MaskingInternal, entity: Ent
1047
1033
  end
1048
1034
 
1049
1035
  function masking_controller.update_component_filter(
1050
- masking: MaskingInternal,
1036
+ masking: MaskingController,
1051
1037
  entity: Entity,
1052
- component: Entity,
1038
+ component: Component,
1053
1039
  component_type: number,
1054
1040
  filter: MemberFilter
1055
1041
  )
@@ -1059,9 +1045,9 @@ function masking_controller.update_component_filter(
1059
1045
  end
1060
1046
 
1061
1047
  function masking_controller.start_component(
1062
- masking: MaskingInternal,
1048
+ masking: MaskingController,
1063
1049
  entity: Entity,
1064
- component: Entity,
1050
+ component: Component,
1065
1051
  component_type: number,
1066
1052
  given_filter: GivenFilter?
1067
1053
  )
@@ -1094,9 +1080,9 @@ function masking_controller.start_component(
1094
1080
  end
1095
1081
 
1096
1082
  function masking_controller.set_component(
1097
- masking: MaskingInternal,
1083
+ masking: MaskingController,
1098
1084
  entity: Entity,
1099
- component: Entity,
1085
+ component: Component,
1100
1086
  component_type: number,
1101
1087
  given_filter: GivenFilter?
1102
1088
  )
@@ -1156,9 +1142,9 @@ function masking_controller.set_component(
1156
1142
  end
1157
1143
 
1158
1144
  function masking_controller.stop_component(
1159
- masking: MaskingInternal,
1145
+ masking: MaskingController,
1160
1146
  entity: Entity,
1161
- component: Entity,
1147
+ component: Component,
1162
1148
  component_type: number
1163
1149
  )
1164
1150
  local component_lookup, entity_lookup = masking:get_component_lookup(entity, component, component_type)
@@ -1180,9 +1166,9 @@ function masking_controller.stop_component(
1180
1166
  end
1181
1167
 
1182
1168
  function masking_controller.get_component_storage_group(
1183
- masking: MaskingInternal,
1169
+ masking: MaskingController,
1184
1170
  entity: Entity,
1185
- component: Entity,
1171
+ component: Component,
1186
1172
  component_type: number
1187
1173
  ): StorageGroup
1188
1174
  local component_lookup, entity_lookup = masking:get_component_lookup(entity, component, component_type)
@@ -1196,10 +1182,23 @@ function masking_controller.get_component_storage_group(
1196
1182
  end
1197
1183
  end
1198
1184
 
1199
- function masking_controller.allocate_entity_addition(
1200
- masking: MaskingInternal,
1185
+ function masking_controller.allocate_propagated_entity_start(masking: MaskingController, entity: Entity)
1186
+ local entity_lookup = masking.lookups.entities[entity]
1187
+ if entity_lookup then
1188
+ entity_lookup.storage_group.changes.added[entity] = true
1189
+
1190
+ for _, lookups in entity_lookup.filtered_components do
1191
+ for _, lookup in lookups do
1192
+ lookup.storage_group.changes.added[entity] = true
1193
+ end
1194
+ end
1195
+ end
1196
+ end
1197
+
1198
+ function masking_controller.allocate_shared_entity_start(
1199
+ masking: MaskingController,
1201
1200
  entity: Entity,
1202
- component: Entity,
1201
+ component: Component,
1203
1202
  component_type: number
1204
1203
  )
1205
1204
  local lookup = masking:get_component_lookup(entity, component, component_type)
@@ -1208,113 +1207,249 @@ function masking_controller.allocate_entity_addition(
1208
1207
  end
1209
1208
  end
1210
1209
 
1210
+ function masking_controller.allocate_entity_stop(masking: MaskingController, entity: Entity)
1211
+ local lookup = masking.lookups.entities[entity]
1212
+ if not lookup then
1213
+ return
1214
+ end
1215
+ local storage = lookup.storage_group
1216
+
1217
+ if storage.deletions.entities[entity] then
1218
+ return
1219
+ end
1220
+ storage.deletions.entities[entity] = true
1221
+ end
1222
+
1223
+ function masking_controller.allocate_component_start(
1224
+ masking: MaskingController,
1225
+ entity: Entity,
1226
+ component: Component,
1227
+ component_type: number
1228
+ )
1229
+ local storage = masking:get_component_storage_group(entity, component, component_type)
1230
+ local additions = get_or_set_component_added(storage, entity)
1231
+ additions[component_type][component] = true
1232
+ end
1233
+
1234
+ function masking_controller.allocate_component_stop(
1235
+ masking: MaskingController,
1236
+ entity: Entity,
1237
+ component: Component,
1238
+ component_type: number
1239
+ )
1240
+ local storage = masking:get_component_storage_group(entity, component, component_type) :: StorageGroup
1241
+ if not storage then
1242
+ return
1243
+ end
1244
+
1245
+ local deletions = storage.deletions.components[entity]
1246
+ if deletions == nil then
1247
+ deletions = create_component_indexes() :: ComponentIndex<boolean>
1248
+ deletions[component_type][component] = true
1249
+ storage.deletions.components[entity] = deletions
1250
+ else
1251
+ deletions[component_type][component] = true
1252
+ end
1253
+ end
1254
+
1255
+ function masking_controller.deallocate_component_start(
1256
+ masking: MaskingController,
1257
+ entity: Entity,
1258
+ component: Component,
1259
+ component_type: number
1260
+ )
1261
+ local storage: StorageGroup = masking:get_component_storage_group(entity, component, component_type)
1262
+ local additions = storage.changes.added_components[entity]
1263
+ if additions then
1264
+ additions[component_type][component] = nil
1265
+ end
1266
+ end
1267
+
1268
+ function masking_controller.deallocate_entity_stop(masking: MaskingController, entity: Entity)
1269
+ local deletion_lookup = masking.lookups.deletions.entities[entity]
1270
+ if not deletion_lookup then
1271
+ return
1272
+ end
1273
+ local storage = deletion_lookup.storage_group
1274
+
1275
+ if storage.deletions.entities[entity] then
1276
+ storage.deletions.entities[entity] = nil
1277
+ storage.deletions_count -= 1
1278
+ end
1279
+ end
1280
+
1281
+ function masking_controller.deallocate_component_stop(
1282
+ masking: MaskingController,
1283
+ entity: Entity,
1284
+ component: Component,
1285
+ component_type: number
1286
+ )
1287
+ local deletion_lookup =
1288
+ get_component_index_entry(masking.lookups.deletions.components, entity, component, component_type)
1289
+ if deletion_lookup == nil then
1290
+ return
1291
+ end
1292
+ local storage = deletion_lookup.storage_group
1293
+
1294
+ local deletions = storage.deletions.components[entity]
1295
+ if deletions then
1296
+ if deletions[component_type][component] then
1297
+ deletions[component_type][component] = nil
1298
+ end
1299
+ end
1300
+ end
1301
+
1211
1302
  function masking_controller.allocate_component_change(
1212
- masking: MaskingInternal,
1303
+ masking: MaskingController,
1213
1304
  entity: Entity,
1214
- component: Entity,
1305
+ component: Component,
1215
1306
  value: any
1216
1307
  )
1217
1308
  local storage = masking:get_component_storage_group(entity, component, COMPONENT_TYPES.component)
1218
1309
  local changes = get_or_set_changed(storage, entity)
1310
+
1219
1311
  changes.component[component] = value
1220
- changes.removed[component] = nil
1312
+ changes.removed.component[component] = nil
1221
1313
  end
1222
1314
 
1223
- function masking_controller.allocate_pair_value_change(
1224
- masking: MaskingInternal,
1315
+ function masking_controller.allocate_tag_addition(masking: MaskingController, entity: Entity, tag: Component)
1316
+ local storage = masking:get_component_storage_group(entity, tag, COMPONENT_TYPES.tag)
1317
+ local changes = get_or_set_changed(storage, entity)
1318
+
1319
+ changes.tagged[tag] = true
1320
+ changes.removed.tag[tag] = nil
1321
+ end
1322
+
1323
+ function masking_controller.allocate_pair_change(masking: MaskingController, entity: Entity, id: Component, value: any)
1324
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_component)
1325
+ local changes = get_or_set_changed(storage, entity)
1326
+
1327
+ changes.pair_removed.component[id] = nil
1328
+ changes.pair_changed[id] = value
1329
+ end
1330
+
1331
+ function masking_controller.allocate_pair_addition(masking: MaskingController, entity: Entity, id: Component)
1332
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_tag)
1333
+ local changes = get_or_set_changed(storage, entity)
1334
+
1335
+ changes.pair_removed.tag[id] = nil
1336
+ changes.pair_added[id] = true
1337
+ end
1338
+
1339
+ function masking_controller.allocate_relation_value_change(
1340
+ masking: MaskingController,
1225
1341
  entity: Entity,
1226
- relation: Entity,
1342
+ relation: Component,
1227
1343
  target: Entity,
1228
1344
  value: any
1229
1345
  )
1230
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair_value)
1346
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation_value)
1231
1347
  local changes = get_or_set_changed(storage, entity)
1232
- local values = changes.pairs_values.changed[relation]
1348
+ local values = changes.relation_value[relation]
1233
1349
  if values == nil then
1234
1350
  values = {}
1235
- changes.pairs_values.changed[relation] = values
1351
+ changes.relation_value[relation] = values
1236
1352
  end
1237
1353
  values[target] = value
1238
1354
 
1239
- local removed = changes.pairs_values.removed[relation]
1355
+ local removed = changes.relation_removed.component[relation]
1240
1356
  if removed ~= nil then
1241
1357
  removed[target] = nil
1242
1358
  end
1243
1359
  end
1244
1360
 
1245
- function masking_controller.allocate_tag_addition(masking: MaskingInternal, entity: Entity, tag: Entity)
1246
- local storage = masking:get_component_storage_group(entity, tag, COMPONENT_TYPES.tag)
1247
- local changes = get_or_set_changed(storage, entity)
1248
- changes.tagged[tag] = true
1249
- changes.removed[tag] = nil
1250
- end
1251
-
1252
- function masking_controller.allocate_pair_addition(
1253
- masking: MaskingInternal,
1361
+ function masking_controller.allocate_relation_addition(
1362
+ masking: MaskingController,
1254
1363
  entity: Entity,
1255
- relation: Entity,
1364
+ relation: Component,
1256
1365
  target: Entity
1257
1366
  )
1258
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair)
1367
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation)
1259
1368
  local changes = get_or_set_changed(storage, entity)
1260
- local targets = changes.pairs[relation]
1369
+ local targets = changes.relation_added[relation]
1261
1370
  if targets == nil then
1262
1371
  targets = {}
1263
- changes.pairs[relation] = targets
1372
+ changes.relation_added[relation] = targets
1264
1373
  end
1265
1374
  targets[target] = true
1375
+
1376
+ local removed = changes.relation_removed.tag[relation]
1377
+ if removed then
1378
+ removed[target] = nil
1379
+ end
1266
1380
  end
1267
1381
 
1268
- function masking_controller.allocate_component_removal(masking: MaskingInternal, entity: Entity, component: Entity)
1382
+ function masking_controller.allocate_component_removal(masking: MaskingController, entity: Entity, component: Component)
1269
1383
  local storage = masking:get_component_storage_group(entity, component, COMPONENT_TYPES.component)
1270
1384
  local changes = get_or_set_changed(storage, entity)
1271
1385
 
1272
1386
  changes.component[component] = nil
1273
- changes.removed[component] = true
1387
+ changes.removed.component[component] = true
1274
1388
  end
1275
1389
 
1276
- function masking_controller.allocate_tag_removal(masking: MaskingInternal, entity: Entity, tag: Entity)
1390
+ function masking_controller.allocate_tag_removal(masking: MaskingController, entity: Entity, tag: Component)
1277
1391
  local storage = masking:get_component_storage_group(entity, tag, COMPONENT_TYPES.tag)
1278
1392
  local changes = get_or_set_changed(storage, entity)
1279
1393
 
1280
1394
  changes.tagged[tag] = nil
1281
- changes.removed[tag] = true
1395
+ changes.removed.tag[tag] = true
1282
1396
  end
1283
1397
 
1284
- function masking_controller.allocate_pair_removal(
1285
- masking: MaskingInternal,
1398
+ function masking_controller.allocate_pair_tag_removal(masking: MaskingController, entity: Entity, id: Component)
1399
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_tag)
1400
+ local changes = get_or_set_changed(storage, entity)
1401
+
1402
+ changes.pair_added[id] = nil
1403
+ changes.pair_removed.tag[id] = true
1404
+ end
1405
+
1406
+ function masking_controller.allocate_pair_component_removal(masking: MaskingController, entity: Entity, id: Component)
1407
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_component)
1408
+ local changes = get_or_set_changed(storage, entity)
1409
+
1410
+ changes.pair_changed[id] = nil
1411
+ changes.pair_removed.component[id] = true
1412
+ end
1413
+
1414
+ function masking_controller.allocate_relation_value_removal(
1415
+ masking: MaskingController,
1286
1416
  entity: Entity,
1287
- relation: Entity,
1417
+ relation: Component,
1288
1418
  target: Entity
1289
1419
  )
1290
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair)
1420
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation)
1291
1421
  local changes = get_or_set_changed(storage, entity)
1292
- local targets = changes.pairs[relation]
1422
+ local targets = changes.relation_removed.component[relation]
1293
1423
  if targets == nil then
1294
1424
  targets = {}
1295
- changes.pairs[relation] = targets
1425
+ changes.relation_removed.component[relation] = targets
1426
+ end
1427
+ targets[target] = true
1428
+
1429
+ local values = changes.relation_value[relation]
1430
+ if values then
1431
+ values[target] = nil
1296
1432
  end
1297
- targets[target] = false
1298
1433
  end
1299
1434
 
1300
- function masking_controller.allocate_pair_value_removal(
1301
- masking: MaskingInternal,
1435
+ function masking_controller.allocate_relation_removal(
1436
+ masking: MaskingController,
1302
1437
  entity: Entity,
1303
- relation: Entity,
1438
+ relation: Component,
1304
1439
  target: Entity
1305
1440
  )
1306
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair_value)
1441
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation)
1307
1442
  local changes = get_or_set_changed(storage, entity)
1308
- local removed = changes.pairs_values.removed[relation]
1309
- if removed == nil then
1310
- removed = {}
1311
- changes.pairs_values.removed[relation] = removed
1443
+ local targets = changes.relation_removed.tag[relation]
1444
+ if targets == nil then
1445
+ targets = {}
1446
+ changes.relation_removed.tag[relation] = targets
1312
1447
  end
1313
- removed[target] = true
1448
+ targets[target] = true
1314
1449
 
1315
- local values = changes.pairs_values.changed[relation]
1316
- if values ~= nil then
1317
- values[target] = nil
1450
+ local added = changes.relation_added[relation]
1451
+ if added then
1452
+ added[target] = nil
1318
1453
  end
1319
1454
  end
1320
1455
 
@@ -1339,12 +1474,12 @@ local function remap_bitmask(
1339
1474
  return result
1340
1475
  end
1341
1476
 
1342
- local function bitmask_from_set(masking: MaskingInternal, member_set: { [Member]: boolean }): utils.Bitmask
1477
+ local function bitmask_from_set(masking: MaskingController, member_set: { [Member]: boolean }): utils.Bitmask
1343
1478
  local new_bitmask = utils.bitmask.create(masking.member_count)
1344
1479
  for member: Member in member_set do
1345
1480
  local index = masking.client_indexes[member]
1346
1481
  if not index then
1347
- local alias = masking.client_indexes[masking.client_aliases[member]]
1482
+ local alias = masking.client_indexes[masking.client_aliases[member] ]
1348
1483
  if alias then
1349
1484
  if utils.is_client_valid(alias) then
1350
1485
  index = alias
@@ -1362,7 +1497,7 @@ local function bitmask_from_set(masking: MaskingInternal, member_set: { [Member]
1362
1497
  end
1363
1498
 
1364
1499
  function masking_controller.merge_storages(
1365
- masking: MaskingInternal,
1500
+ masking: MaskingController,
1366
1501
  old_storage: StorageGroup,
1367
1502
  new_storage: StorageGroup
1368
1503
  )
@@ -1414,7 +1549,7 @@ function masking_controller.merge_storages(
1414
1549
  end
1415
1550
  end
1416
1551
 
1417
- function masking_controller.compact_members(masking: MaskingInternal)
1552
+ function masking_controller.compact_members(masking: MaskingController)
1418
1553
  -- we dont recompute as nothing should've changed
1419
1554
  -- so this should be hopefully quite cheap
1420
1555
  local old_indexes = masking.client_indexes
@@ -1444,8 +1579,7 @@ function masking_controller.compact_members(masking: MaskingInternal)
1444
1579
  if component_bitmask then
1445
1580
  component_generator.bitmask = remap_bitmask(component_bitmask, old_indexes, new_indexes, new_count)
1446
1581
  end
1447
- component_generator.result =
1448
- remap_bitmask(component_generator.result, old_indexes, new_indexes, new_count)
1582
+ component_generator.result = remap_bitmask(component_generator.result, old_indexes, new_indexes, new_count)
1449
1583
 
1450
1584
  local band_generator = component_lookup.band_generator
1451
1585
  local band_bitmask = band_generator.bitmask
@@ -1486,7 +1620,10 @@ function masking_controller.compact_members(masking: MaskingInternal)
1486
1620
  masking.storages = new_storages
1487
1621
  end
1488
1622
 
1489
- function masking_controller.create_generator_from_filter(masking: MaskingInternal, filter: MemberFilter): MaskGenerator
1623
+ function masking_controller.create_generator_from_filter(
1624
+ masking: MaskingController,
1625
+ filter: MemberFilter
1626
+ ): MaskGenerator
1490
1627
  local is_include = is_include_filter(filter)
1491
1628
  if is_include then
1492
1629
  return masking:create_include_generator(filter) :: MaskGenerator
@@ -1495,7 +1632,7 @@ function masking_controller.create_generator_from_filter(masking: MaskingInterna
1495
1632
  end
1496
1633
  end
1497
1634
 
1498
- function masking_controller.create_exclude_generator(masking: MaskingInternal, exclude: MemberFilter)
1635
+ function masking_controller.create_exclude_generator(masking: MaskingController, exclude: MemberFilter)
1499
1636
  local bitmask = bitmask_from_set(masking, exclude)
1500
1637
  local active_members = masking.active_members_generator
1501
1638
 
@@ -1509,7 +1646,7 @@ function masking_controller.create_exclude_generator(masking: MaskingInternal, e
1509
1646
  end
1510
1647
 
1511
1648
  -- TODO: check for players existing and register them if they don't
1512
- function masking_controller.create_include_generator(masking: MaskingInternal, include: MemberFilter): MaskGenerator
1649
+ function masking_controller.create_include_generator(masking: MaskingController, include: MemberFilter): MaskGenerator
1513
1650
  local bitmask = bitmask_from_set(masking, include)
1514
1651
  local active_members = masking.active_members_generator
1515
1652
 
@@ -1522,7 +1659,7 @@ function masking_controller.create_include_generator(masking: MaskingInternal, i
1522
1659
  return new_generator
1523
1660
  end
1524
1661
 
1525
- function masking_controller.create_all_members_generator(masking: MaskingInternal)
1662
+ function masking_controller.create_all_members_generator(masking: MaskingController)
1526
1663
  local filter: MemberFilter = {}
1527
1664
  for member in masking.client_indexes do
1528
1665
  filter[member] = true
@@ -1547,11 +1684,11 @@ function masking_controller.create_active_generator(masking: MaskingController):
1547
1684
  return new_generator
1548
1685
  end
1549
1686
 
1550
- --function masking_controller.register_mask_group(masking: MaskingInternal, group: Member) end
1687
+ --function masking_controller.register_mask_group(masking: MaskingController, group: Member) end
1551
1688
 
1552
- --function masking_controller.unregister_mask_group(masking: MaskingInternal, group: Member) end
1689
+ --function masking_controller.unregister_mask_group(masking: MaskingController, group: Member) end
1553
1690
 
1554
- function masking_controller.register_client(masking: MaskingInternal, member: Member)
1691
+ function masking_controller.register_client(masking: MaskingController, member: Member)
1555
1692
  if masking.client_indexes[member] then
1556
1693
  return
1557
1694
  end
@@ -1570,7 +1707,7 @@ function masking_controller.register_client(masking: MaskingInternal, member: Me
1570
1707
  end
1571
1708
  end
1572
1709
 
1573
- function masking_controller.unregister_client(masking: MaskingInternal, member: Member)
1710
+ function masking_controller.unregister_client(masking: MaskingController, member: Member)
1574
1711
  local index = masking.client_indexes[member]
1575
1712
  if index == nil then
1576
1713
  return
@@ -1580,7 +1717,7 @@ function masking_controller.unregister_client(masking: MaskingInternal, member:
1580
1717
  masking.active_members_generator:compute()
1581
1718
  end
1582
1719
 
1583
- function masking_controller.activate_client(masking: MaskingInternal, member: Member)
1720
+ function masking_controller.activate_client(masking: MaskingController, member: Member)
1584
1721
  local index = masking.client_indexes[member]
1585
1722
 
1586
1723
  masking.unreplicated[member] = nil
@@ -1588,7 +1725,7 @@ function masking_controller.activate_client(masking: MaskingInternal, member: Me
1588
1725
  masking.active_members_generator:compute()
1589
1726
  end
1590
1727
 
1591
- function masking_controller.member_is_active(masking: MaskingInternal, member: Member): boolean
1728
+ function masking_controller.member_is_active(masking: MaskingController, member: Member): boolean
1592
1729
  local index = masking.client_indexes[member]
1593
1730
  if index == nil then
1594
1731
  return false
@@ -1598,7 +1735,7 @@ function masking_controller.member_is_active(masking: MaskingInternal, member: M
1598
1735
  end
1599
1736
 
1600
1737
  local function create(): MaskingController
1601
- local self = {} :: MaskingInternal
1738
+ local self = {} :: MaskingController
1602
1739
 
1603
1740
  self.client_indexes = {}
1604
1741
  self.group_indexes = {}