@rbxts/replecs 0.2.3 → 0.3.0

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,34 +26,49 @@ 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> },
55
- },
50
+ changed: ComponentIndex<any>,
51
+ removed: ComponentIndex<any>,
52
+
53
+ -- these are just aliases for changes.changed, and changes.removed
54
+ -- changes need specific types, so you access these if you need the types, as the other ones are just arrays
55
+ tag_removed: Set<Component>,
56
+ component_removed: Set<Component>,
57
+ unreliable_removed: Set<Component>,
58
+ unreliable_pair_removed: Set<Component>,
59
+ pair_tag_removed: Set<Component>,
60
+ pair_component_removed: Set<Component>,
61
+ relation_tag_removed: { [Component]: Set<Entity> },
62
+ relation_component_removed: { [Component]: Set<Entity> },
63
+
64
+ tag_added: Set<Component>,
65
+ component_changed: Map<Component, any>,
66
+ unreliable_added: Set<Component>,
67
+ unreliable_pair_added: Set<Component>,
68
+ pair_tag_added: Set<Component>,
69
+ pair_component_changed: Map<Component, any>,
70
+ relation_tag_added: { [Component]: Set<Entity> },
71
+ relation_component_changed: { [Component]: Map<Entity, any> },
56
72
  }
57
73
 
58
74
  type PostponedList = ComponentIndex<{ filter: MemberFilter? }>
@@ -84,7 +100,7 @@ type MaskInfo = {
84
100
  members: Array<Member>,
85
101
  }
86
102
 
87
- type StorageGroup = {
103
+ export type StorageGroup = {
88
104
  mask: MaskInfo,
89
105
  shared_with: EntityComponentIndex<boolean>,
90
106
  is_empty: boolean,
@@ -109,7 +125,7 @@ type Storages = {
109
125
  [MaskHash]: StorageGroup,
110
126
  }
111
127
 
112
- export type MaskingController = {
128
+ export type MaskingControllerClass = {
113
129
  member_count: number,
114
130
 
115
131
  client_indexes: { [Member]: number },
@@ -125,103 +141,27 @@ export type MaskingController = {
125
141
 
126
142
  storages: Storages,
127
143
  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
144
  }
210
145
 
211
146
  local COMPONENT_TYPES = {
212
- component = 1,
213
- tag = 2,
214
- pair = 3,
215
- pair_value = 4,
216
- unreliable = 5,
147
+ tag = 1,
148
+ component = 2,
149
+ pair_tag = 3,
150
+ pair_component = 4,
151
+ relation = 5,
152
+ relation_component = 6,
153
+ unreliable = 7,
154
+ unreliable_pair = 8,
217
155
  }
218
156
 
157
+ local COMPONENT_TYPES_COUNT = COMPONENT_TYPES.unreliable
158
+
219
159
  local masking_controller = {}
220
160
  masking_controller.__index = masking_controller
221
161
 
222
- export type MaskingInternal = MaskingController & typeof(masking_controller)
162
+ export type MaskingController = MaskingControllerClass & typeof(masking_controller)
223
163
 
224
- function masking_controller.get_clients_from_bitmask(controller: MaskingInternal, bitmask: Bitmask): Array<Member>
164
+ function masking_controller.get_clients_from_bitmask(controller: MaskingController, bitmask: Bitmask): Array<Member>
225
165
  local members: { Member } = {}
226
166
  for player, index in controller.client_indexes do
227
167
  if bitmask:get(index) then
@@ -243,25 +183,86 @@ local function get_usable_filter(filter: (MemberFilter | any)?): MemberFilter?
243
183
  end
244
184
  end
245
185
 
246
- local function create_component_indexes<T>()
247
- return { {}, {}, {}, {}, {} } :: ComponentIndex<any>
186
+ local function create_component_indexes<T>(): ComponentIndex<T>
187
+ local indexes = {}
188
+ for i = 1, COMPONENT_TYPES_COUNT do
189
+ indexes[i] = {}
190
+ end
191
+ return indexes
248
192
  end
249
193
 
250
194
  local function create_entity_changes(): EntityChanges
195
+ local tag_removed = {}
196
+ local component_removed = {}
197
+ local unreliable_removed = {}
198
+ local unreliable_pair_removed = {}
199
+ local pair_tag_removed = {}
200
+ local pair_component_removed = {}
201
+ local relation_tag_removed = {}
202
+ local relation_component_removed = {}
203
+
204
+ local tag_added = {}
205
+ local component_changed = {}
206
+ local unreliable_added = {}
207
+ local unreliable_pair_added = {}
208
+ local pair_tag_added = {}
209
+ local pair_component_changed = {}
210
+ local relation_tag_added = {}
211
+ local relation_component_changed = {}
212
+
213
+ local changed_changes = create_component_indexes() :: ComponentIndex<any>
214
+ local removed_changes = create_component_indexes() :: ComponentIndex<any>
215
+
216
+ changed_changes[COMPONENT_TYPES.tag] = tag_added
217
+ changed_changes[COMPONENT_TYPES.component] = component_changed
218
+
219
+ changed_changes[COMPONENT_TYPES.unreliable] = unreliable_added
220
+ changed_changes[COMPONENT_TYPES.unreliable_pair] = unreliable_pair_added
221
+
222
+ changed_changes[COMPONENT_TYPES.pair_tag] = pair_tag_added
223
+ changed_changes[COMPONENT_TYPES.pair_component] = pair_component_changed
224
+
225
+ changed_changes[COMPONENT_TYPES.relation] = relation_tag_added
226
+ changed_changes[COMPONENT_TYPES.relation_component] = relation_component_changed
227
+
228
+ removed_changes[COMPONENT_TYPES.tag] = tag_removed
229
+ removed_changes[COMPONENT_TYPES.component] = component_removed
230
+
231
+ removed_changes[COMPONENT_TYPES.unreliable] = unreliable_removed
232
+ removed_changes[COMPONENT_TYPES.unreliable_pair] = unreliable_pair_removed
233
+
234
+ removed_changes[COMPONENT_TYPES.pair_tag] = pair_tag_removed
235
+ removed_changes[COMPONENT_TYPES.pair_component] = pair_component_removed
236
+
237
+ removed_changes[COMPONENT_TYPES.relation] = relation_tag_removed
238
+ removed_changes[COMPONENT_TYPES.relation_component] = relation_component_removed
239
+
251
240
  return {
252
- tagged = {},
253
- component = {},
254
- removed = {},
255
- pairs = {},
256
- pairs_values = {
257
- changed = {},
258
- removed = {},
259
- },
241
+ removed = removed_changes,
242
+ changed = changed_changes,
243
+
244
+ tag_removed = tag_removed,
245
+ component_removed = component_removed,
246
+ unreliable_removed = unreliable_removed,
247
+ unreliable_pair_removed = unreliable_pair_removed,
248
+ pair_tag_removed = pair_tag_removed,
249
+ pair_component_removed = pair_component_removed,
250
+ relation_tag_removed = relation_tag_removed,
251
+ relation_component_removed = relation_component_removed,
252
+
253
+ tag_added = tag_added,
254
+ component_changed = component_changed,
255
+ unreliable_added = unreliable_added,
256
+ unreliable_pair_added = unreliable_pair_added,
257
+ pair_tag_added = pair_tag_added,
258
+ pair_component_changed = pair_component_changed,
259
+ relation_tag_added = relation_tag_added,
260
+ relation_component_changed = relation_component_changed,
260
261
  }
261
262
  end
262
263
 
263
264
  function masking_controller.create_new_storage(
264
- controller: MaskingInternal,
265
+ controller: MaskingController,
265
266
  bitmask: Bitmask,
266
267
  hash: string?,
267
268
  members: Array<Member>?
@@ -313,7 +314,7 @@ end
313
314
  local function get_component_index_entry<T>(
314
315
  index: EntityComponentIndex<T>,
315
316
  entity: Entity,
316
- component: Entity,
317
+ component: Component,
317
318
  component_type: number
318
319
  ): T?
319
320
  local entity_index = index[entity]
@@ -328,7 +329,7 @@ end
328
329
  local function set_component_index_entry<T>(
329
330
  index: EntityComponentIndex<T>,
330
331
  entity: Entity,
331
- component: Entity,
332
+ component: Component,
332
333
  component_type: number,
333
334
  value: T
334
335
  )
@@ -343,7 +344,7 @@ end
343
344
  local function remove_component_index_entry(
344
345
  index: EntityComponentIndex<any>,
345
346
  entity: Entity,
346
- component: Entity,
347
+ component: Component,
347
348
  component_type: number
348
349
  )
349
350
  local entity_index = index[entity]
@@ -415,10 +416,10 @@ local function remove_active(storage: StorageGroup, entity: Entity): ActiveEntit
415
416
  -- todo: check if empty
416
417
  return active
417
418
  end
418
- return utils.logerror "attempted to remove an entity that wasn't active"
419
+ return common.log_error "attempted to remove an entity that wasn't active"
419
420
  end
420
421
 
421
- local function get_or_set_component_active(active: ActiveEntity, component: Entity, component_type: number)
422
+ local function set_component_active(active: ActiveEntity, component: Component, component_type: number)
422
423
  local components = active.components[component_type]
423
424
  if components[component] == nil then
424
425
  components[component] = true
@@ -426,7 +427,12 @@ local function get_or_set_component_active(active: ActiveEntity, component: Enti
426
427
  end
427
428
  end
428
429
 
429
- local function remove_component_active(storage: StorageGroup, entity: Entity, component: Entity, component_type: number)
430
+ local function remove_component_active(
431
+ storage: StorageGroup,
432
+ entity: Entity,
433
+ component: Component,
434
+ component_type: number
435
+ )
430
436
  local active = storage.active[entity]
431
437
  if not active then
432
438
  return
@@ -443,7 +449,7 @@ local function remove_component_active(storage: StorageGroup, entity: Entity, co
443
449
  end
444
450
  end
445
451
 
446
- function masking_controller.get_or_create_storage_group(masking: MaskingInternal, bitmask: Bitmask): StorageGroup
452
+ function masking_controller.get_or_create_storage_group(masking: MaskingController, bitmask: Bitmask): StorageGroup
447
453
  local hash = bitmask:tostring()
448
454
  local storage = masking.storages[hash]
449
455
 
@@ -455,12 +461,16 @@ function masking_controller.get_or_create_storage_group(masking: MaskingInternal
455
461
  end
456
462
 
457
463
  function masking_controller.get_component_lookup(
458
- masking: MaskingInternal,
464
+ masking: MaskingController,
459
465
  entity: Entity,
460
- component: Entity,
466
+ component: Component,
461
467
  component_type: number
462
468
  ): (ComponentLookup, EntityLookup)
463
469
  local entity_lookup = masking.lookups.entities[entity]
470
+ if not entity_lookup then
471
+ return nil :: any
472
+ end
473
+
464
474
  return entity_lookup.filtered_components[component_type][component], entity_lookup
465
475
  end
466
476
 
@@ -478,7 +488,7 @@ local function dissect_component_actives(
478
488
  if is_shared then
479
489
  new_active = new_active or create_new_active()
480
490
 
481
- get_or_set_component_active(new_active, component, component_type)
491
+ set_component_active(new_active, component, component_type)
482
492
  remove_component_active(storage, entity, component, component_type)
483
493
  end
484
494
  end
@@ -502,61 +512,56 @@ local function dissect_component_additions(added: ComponentIndex<boolean>, share
502
512
  return new_added
503
513
  end
504
514
 
505
- local function dissect_component_changes(changes: EntityChanges, shared_index: ComponentIndex<boolean>)
506
- local new_changes: EntityChanges
507
-
508
- for component, change in changes.component do
509
- local is_shared = shared_index[COMPONENT_TYPES.component] and shared_index[COMPONENT_TYPES.component][component]
510
- if is_shared then
511
- new_changes = new_changes or create_entity_changes()
512
- new_changes.component[component] = change
513
- changes.component[component] = nil
514
- end
515
- 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]
518
- if is_shared then
519
- new_changes = new_changes or create_entity_changes()
520
- new_changes.tagged[entity] = entity_changes
521
- changes.tagged[entity] = nil
522
- end
523
- 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]
526
- if is_shared then
527
- new_changes = new_changes or create_entity_changes()
528
- new_changes.pairs[relation] = entity_changes
529
- changes.pairs[relation] = nil
515
+ local function dissect_component_changes(
516
+ entity_changes: EntityChanges,
517
+ shared_index: ComponentIndex<boolean>
518
+ ): EntityChanges
519
+ local new_entity_changes: EntityChanges = nil :: any
520
+ local new_removed: ComponentIndex<boolean> = nil :: any
521
+ local new_changed: ComponentIndex<any> = nil :: any
522
+
523
+ for component_type, components_changed in entity_changes.changed do
524
+ local shared_set = shared_index[component_type]
525
+ for component, change in components_changed do
526
+ local is_shared = shared_set and shared_set[component]
527
+ if is_shared then
528
+ if new_changed then
529
+ new_changed[component_type][component] = change
530
+ components_changed[component] = nil
531
+ else
532
+ new_entity_changes = create_entity_changes()
533
+ new_changed = new_entity_changes.changed
534
+ new_removed = new_entity_changes.removed
535
+ end
536
+ end
530
537
  end
531
538
  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]
535
539
 
536
- if is_shared then
537
- new_changes = new_changes or create_entity_changes()
538
- new_changes.pairs_values.changed[relation] = entity_changes
539
- changes.pairs_values.changed[relation] = nil
540
- end
541
- 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]
540
+ for component_type, components_removed in entity_changes.removed do
541
+ local shared_set = shared_index[component_type]
542
+ for component in components_removed do
543
+ local is_shared = shared_set and shared_set[component]
545
544
 
546
- if is_shared then
547
- new_changes = new_changes or create_entity_changes()
548
- new_changes.pairs_values.removed[relation] = entity_changes
549
- changes.pairs_values.removed[relation] = nil
545
+ if is_shared then
546
+ if new_removed then
547
+ new_removed[component_type][component] = true
548
+ components_removed[component] = nil
549
+ else
550
+ new_entity_changes = create_entity_changes()
551
+ new_changed = new_entity_changes.changed
552
+ new_removed = new_entity_changes.removed
553
+ end
554
+ end
550
555
  end
551
556
  end
552
557
 
553
- return new_changes
558
+ return new_entity_changes
554
559
  end
555
560
 
556
561
  local function merge_component_actives(current: ActiveEntity, target: ActiveEntity)
557
562
  for component_type, components in current.components do
558
563
  for component in components do
559
- get_or_set_component_active(target, component, component_type)
564
+ set_component_active(target, component, component_type)
560
565
  end
561
566
  end
562
567
  end
@@ -569,27 +574,35 @@ local function merge_component_additions(current: ComponentIndex<boolean>, targe
569
574
  end
570
575
  end
571
576
 
572
- local function merge_component_changes(current: EntityChanges, target: EntityChanges)
573
- for component, change in current.component do
574
- target.component[component] = change
575
- end
576
- for entity, entity_changes in current.tagged do
577
- target.tagged[entity] = entity_changes
577
+ local function merge_component_changes(current: EntityChanges, destination: EntityChanges)
578
+ -- COMPONENTS/TAGS
579
+ local destination_changed = destination.changed
580
+ local destination_removed = destination.removed
581
+
582
+ for component_type, components_changed in current.changed do
583
+ local destination_components = destination_changed[component_type]
584
+ for component, change in components_changed do
585
+ destination_components[component] = change
586
+ end
578
587
  end
579
- for entity, entity_changes in current.pairs do
580
- target.pairs[entity] = entity_changes
588
+
589
+ for component_type, components_removed in current.removed do
590
+ local destination_components = destination_removed[component_type]
591
+ for component, change in components_removed do
592
+ destination_components[component] = change
593
+ end
581
594
  end
582
595
  end
583
596
 
584
597
  function masking_controller.merge_component_filter(
585
- masking: MaskingInternal,
598
+ masking: MaskingController,
586
599
  entity: Entity,
587
- component: Entity,
600
+ component: Component,
588
601
  component_type: number
589
602
  )
590
603
  local component_lookup, entity_lookup = masking:get_component_lookup(entity, component, component_type)
591
604
  if not entity_lookup then
592
- utils.logerror "attempted to merge a component filter to an unactive entity"
605
+ common.log_error "attempted to merge a component filter to an unactive entity"
593
606
  end
594
607
 
595
608
  if component_lookup ~= nil then
@@ -603,25 +616,25 @@ function masking_controller.merge_component_filter(
603
616
  entity_lookup.filtered_components[component_type][component] = nil
604
617
  remove_component_index_entry(new_storage.shared_with, entity, component, component_type)
605
618
  else
606
- get_or_set_component_active(entity_lookup.storage_group.active[entity], component, component_type)
619
+ set_component_active(entity_lookup.storage_group.active[entity], component, component_type)
607
620
  end
608
621
  entity_lookup.components[component_type][component] = true
609
622
  end
610
623
 
611
624
  function masking_controller.move_entity_storage(
612
- masking: MaskingInternal,
625
+ masking: MaskingController,
613
626
  entity: Entity,
614
627
  storage: StorageGroup,
615
- target: Bitmask
628
+ destination: Bitmask
616
629
  )
617
- local target_storage = masking:get_or_create_storage_group(target)
618
- if target_storage == storage then
630
+ local destination_storage = masking:get_or_create_storage_group(destination)
631
+ if destination_storage == storage then
619
632
  return storage
620
633
  end
621
634
  local shared_with = storage.shared_with[entity]
622
635
 
623
636
  local old_active = storage.active[entity]
624
- local new_active = get_or_set_active(target_storage, entity, old_active)
637
+ local new_active = get_or_set_active(destination_storage, entity, old_active)
625
638
 
626
639
  new_active.is_entity_mask = true
627
640
 
@@ -642,7 +655,7 @@ function masking_controller.move_entity_storage(
642
655
 
643
656
  local old_component_added = storage.changes.added_components[entity]
644
657
  if old_component_added then
645
- local new_component_added = get_or_set_component_added(target_storage, entity, old_component_added)
658
+ local new_component_added = get_or_set_component_added(destination_storage, entity, old_component_added)
646
659
 
647
660
  if shared_with then
648
661
  local dissected_added = dissect_component_additions(old_component_added, shared_with)
@@ -660,7 +673,7 @@ function masking_controller.move_entity_storage(
660
673
 
661
674
  local old_changes = storage.changes.changed[entity]
662
675
  if old_changes then
663
- local new_changes = get_or_set_changed(target_storage, entity, old_changes)
676
+ local new_changes = get_or_set_changed(destination_storage, entity, old_changes)
664
677
 
665
678
  if shared_with then
666
679
  local dissected_changes = dissect_component_changes(old_changes, shared_with)
@@ -677,78 +690,58 @@ function masking_controller.move_entity_storage(
677
690
  end
678
691
 
679
692
  if storage.changes.added[entity] then
680
- target_storage.changes.added[entity] = true
693
+ destination_storage.changes.added[entity] = true
681
694
  storage.changes.added[entity] = nil
682
695
  end
683
696
 
684
- return target_storage
697
+ return destination_storage
685
698
  end
686
699
 
687
700
  function masking_controller.move_component_storage(
688
- masking: MaskingInternal,
701
+ masking: MaskingController,
689
702
  entity: Entity,
690
- component: Entity,
703
+ component: Component,
691
704
  component_type: number,
692
705
  storage: StorageGroup,
693
- target: Bitmask
706
+ destination: Bitmask
694
707
  )
695
- local target_storage = masking:get_or_create_storage_group(target)
696
- if target_storage == storage then
708
+ local destination_storage = masking:get_or_create_storage_group(destination)
709
+ if destination_storage == storage then
697
710
  return storage
698
711
  end
699
712
 
700
- local new_active = get_or_set_active(target_storage, entity)
713
+ local new_active = get_or_set_active(destination_storage, entity)
701
714
 
702
715
  remove_component_active(storage, entity, component, component_type)
703
- get_or_set_component_active(new_active, component, component_type)
716
+ set_component_active(new_active, component, component_type)
704
717
 
705
- set_component_index_entry(target_storage.shared_with, entity, component, component_type, true)
718
+ set_component_index_entry(destination_storage.shared_with, entity, component, component_type, true)
706
719
  remove_component_index_entry(storage.shared_with, entity, component, component_type)
707
720
 
708
721
  local component_added =
709
722
  get_component_index_entry(storage.changes.added_components, entity, component, component_type)
710
723
  if component_added then
711
724
  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)
725
+ set_component_index_entry(destination_storage.changes.added_components, entity, component, component_type, true)
713
726
  end
714
727
 
715
728
  local changes = storage.changes.changed[entity]
716
729
  if changes then
717
- local target_changes = get_or_set_changed(target_storage, entity)
718
- if component_type == COMPONENT_TYPES.tag then
719
- target_changes.tagged[component] = changes.tagged[component]
720
- target_changes.removed[component] = changes.removed[component]
721
-
722
- changes.tagged[component] = nil
723
- changes.removed[component] = nil
724
- elseif component_type == COMPONENT_TYPES.component then
725
- target_changes.component[component] = changes.component[component]
726
- target_changes.removed[component] = changes.removed[component]
727
-
728
- 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
742
- end
730
+ local destination_changes = get_or_set_changed(destination_storage, entity)
731
+ destination_changes.changed[component_type][component] = changes.changed[component_type][component]
732
+ destination_changes.removed[component_type][component] = changes.removed[component_type][component]
733
+
734
+ changes.changed[component_type][component] = nil
735
+ changes.removed[component_type][component] = nil
743
736
  end
744
737
 
745
- return target_storage
738
+ return destination_storage
746
739
  end
747
740
 
748
741
  function masking_controller.bind_component_generator(
749
- masking: MaskingInternal,
742
+ masking: MaskingController,
750
743
  entity: Entity,
751
- component: Entity,
744
+ component: Component,
752
745
  component_type: number,
753
746
  base_generator: MaskGenerator
754
747
  )
@@ -776,7 +769,7 @@ function masking_controller.bind_component_generator(
776
769
  return generator
777
770
  end
778
771
 
779
- function masking_controller.rebind_component_generators(masking: MaskingInternal, entity: Entity)
772
+ function masking_controller.rebind_component_generators(masking: MaskingController, entity: Entity)
780
773
  local entity_lookup = masking.lookups.entities[entity]
781
774
  if entity_lookup then
782
775
  for component_type, lookups in entity_lookup.filtered_components do
@@ -793,9 +786,9 @@ function masking_controller.rebind_component_generators(masking: MaskingInternal
793
786
  end
794
787
 
795
788
  function masking_controller.get_or_postpone_entity_lookup(
796
- masking: MaskingInternal,
789
+ masking: MaskingController,
797
790
  entity: Entity,
798
- component: Entity,
791
+ component: Component,
799
792
  component_type: number,
800
793
  filter: MemberFilter?
801
794
  ): EntityLookup?
@@ -813,116 +806,8 @@ function masking_controller.get_or_postpone_entity_lookup(
813
806
  return nil
814
807
  end
815
808
 
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
809
  function masking_controller.update_entity_filter(
925
- masking: MaskingInternal,
810
+ masking: MaskingController,
926
811
  entity: Entity,
927
812
  filter: MemberFilter?
928
813
  ): MaskGenerator
@@ -948,7 +833,7 @@ function masking_controller.update_entity_filter(
948
833
  return generator
949
834
  end
950
835
 
951
- function masking_controller.start_entity(masking: MaskingInternal, entity: Entity, given_filter: GivenFilter?)
836
+ function masking_controller.start_entity(masking: MaskingController, entity: Entity, given_filter: GivenFilter?)
952
837
  local filter = get_usable_filter(given_filter)
953
838
  local generator = masking:update_entity_filter(entity, filter)
954
839
 
@@ -960,8 +845,8 @@ function masking_controller.start_entity(masking: MaskingInternal, entity: Entit
960
845
  generator = generator,
961
846
  filter = filter,
962
847
  storage_group = storage_group,
963
- filtered_components = create_component_indexes(),
964
- components = create_component_indexes(),
848
+ filtered_components = create_component_indexes() :: ComponentIndex<ComponentLookup>,
849
+ components = create_component_indexes() :: ComponentIndex<true>,
965
850
  }
966
851
  masking.lookups.entities[entity] = new_lookup
967
852
 
@@ -976,11 +861,11 @@ function masking_controller.start_entity(masking: MaskingInternal, entity: Entit
976
861
  end
977
862
  end
978
863
 
979
- function masking_controller.set_entity(masking: MaskingInternal, entity: Entity, given_filter: GivenFilter?)
864
+ function masking_controller.set_entity(masking: MaskingController, entity: Entity, given_filter: GivenFilter?)
980
865
  local filter = get_usable_filter(given_filter)
981
866
  local lookup = masking.lookups.entities[entity]
982
867
  if not lookup then
983
- utils.logerror "attempted to modify the filter of an unactive entity"
868
+ common.log_error "attempted to modify the filter of an unactive entity"
984
869
  end
985
870
  lookup.generator:destroy()
986
871
 
@@ -993,10 +878,10 @@ function masking_controller.set_entity(masking: MaskingInternal, entity: Entity,
993
878
  masking:rebind_component_generators(entity)
994
879
  end
995
880
 
996
- function masking_controller.stop_entity(masking: MaskingInternal, entity: Entity)
881
+ function masking_controller.stop_entity(masking: MaskingController, entity: Entity)
997
882
  local lookup = masking.lookups.entities[entity]
998
883
  if not lookup then
999
- utils.logerror "attemped to stop an unactive entity"
884
+ common.log_error "attemped to stop an unactive entity"
1000
885
  end
1001
886
 
1002
887
  local postponed = masking.lookups.postponed[entity]
@@ -1039,7 +924,7 @@ function masking_controller.stop_entity(masking: MaskingInternal, entity: Entity
1039
924
  masking.lookups.entities[entity] = nil
1040
925
  end
1041
926
 
1042
- function masking_controller.cleanup_entity(masking: MaskingInternal, entity: Entity)
927
+ function masking_controller.cleanup_entity(masking: MaskingController, entity: Entity)
1043
928
  masking.lookups.entities[entity] = nil
1044
929
  masking.lookups.postponed[entity] = nil
1045
930
  masking.lookups.deletions.entities[entity] = nil
@@ -1047,9 +932,9 @@ function masking_controller.cleanup_entity(masking: MaskingInternal, entity: Ent
1047
932
  end
1048
933
 
1049
934
  function masking_controller.update_component_filter(
1050
- masking: MaskingInternal,
935
+ masking: MaskingController,
1051
936
  entity: Entity,
1052
- component: Entity,
937
+ component: Component,
1053
938
  component_type: number,
1054
939
  filter: MemberFilter
1055
940
  )
@@ -1059,9 +944,9 @@ function masking_controller.update_component_filter(
1059
944
  end
1060
945
 
1061
946
  function masking_controller.start_component(
1062
- masking: MaskingInternal,
947
+ masking: MaskingController,
1063
948
  entity: Entity,
1064
- component: Entity,
949
+ component: Component,
1065
950
  component_type: number,
1066
951
  given_filter: GivenFilter?
1067
952
  )
@@ -1073,7 +958,7 @@ function masking_controller.start_component(
1073
958
 
1074
959
  if filter == nil then
1075
960
  lookup.components[component_type][component] = true
1076
- get_or_set_component_active(lookup.storage_group.active[entity], component, component_type)
961
+ set_component_active(lookup.storage_group.active[entity], component, component_type)
1077
962
  return
1078
963
  end
1079
964
 
@@ -1081,7 +966,7 @@ function masking_controller.start_component(
1081
966
  local storage_group = masking:get_or_create_storage_group(band_generator.result)
1082
967
  local active = get_or_set_active(storage_group, entity)
1083
968
 
1084
- get_or_set_component_active(active, component, component_type)
969
+ set_component_active(active, component, component_type)
1085
970
  set_component_index_entry(storage_group.shared_with, entity, component, component_type, true)
1086
971
 
1087
972
  local component_lookup: ComponentLookup = {
@@ -1094,9 +979,9 @@ function masking_controller.start_component(
1094
979
  end
1095
980
 
1096
981
  function masking_controller.set_component(
1097
- masking: MaskingInternal,
982
+ masking: MaskingController,
1098
983
  entity: Entity,
1099
- component: Entity,
984
+ component: Component,
1100
985
  component_type: number,
1101
986
  given_filter: GivenFilter?
1102
987
  )
@@ -1156,9 +1041,9 @@ function masking_controller.set_component(
1156
1041
  end
1157
1042
 
1158
1043
  function masking_controller.stop_component(
1159
- masking: MaskingInternal,
1044
+ masking: MaskingController,
1160
1045
  entity: Entity,
1161
- component: Entity,
1046
+ component: Component,
1162
1047
  component_type: number
1163
1048
  )
1164
1049
  local component_lookup, entity_lookup = masking:get_component_lookup(entity, component, component_type)
@@ -1180,9 +1065,9 @@ function masking_controller.stop_component(
1180
1065
  end
1181
1066
 
1182
1067
  function masking_controller.get_component_storage_group(
1183
- masking: MaskingInternal,
1068
+ masking: MaskingController,
1184
1069
  entity: Entity,
1185
- component: Entity,
1070
+ component: Component,
1186
1071
  component_type: number
1187
1072
  ): StorageGroup
1188
1073
  local component_lookup, entity_lookup = masking:get_component_lookup(entity, component, component_type)
@@ -1196,10 +1081,23 @@ function masking_controller.get_component_storage_group(
1196
1081
  end
1197
1082
  end
1198
1083
 
1199
- function masking_controller.allocate_entity_addition(
1200
- masking: MaskingInternal,
1084
+ function masking_controller.allocate_propagated_entity_start(masking: MaskingController, entity: Entity)
1085
+ local entity_lookup = masking.lookups.entities[entity]
1086
+ if entity_lookup then
1087
+ entity_lookup.storage_group.changes.added[entity] = true
1088
+
1089
+ for _, lookups in entity_lookup.filtered_components do
1090
+ for _, lookup in lookups do
1091
+ lookup.storage_group.changes.added[entity] = true
1092
+ end
1093
+ end
1094
+ end
1095
+ end
1096
+
1097
+ function masking_controller.allocate_shared_entity_start(
1098
+ masking: MaskingController,
1201
1099
  entity: Entity,
1202
- component: Entity,
1100
+ component: Component,
1203
1101
  component_type: number
1204
1102
  )
1205
1103
  local lookup = masking:get_component_lookup(entity, component, component_type)
@@ -1208,112 +1106,277 @@ function masking_controller.allocate_entity_addition(
1208
1106
  end
1209
1107
  end
1210
1108
 
1109
+ function masking_controller.allocate_entity_stop(masking: MaskingController, entity: Entity)
1110
+ local lookup = masking.lookups.entities[entity]
1111
+ if not lookup then
1112
+ return
1113
+ end
1114
+ local storage = lookup.storage_group
1115
+
1116
+ if storage.deletions.entities[entity] then
1117
+ return
1118
+ end
1119
+ storage.deletions.entities[entity] = true
1120
+ end
1121
+
1122
+ function masking_controller.allocate_component_start(
1123
+ masking: MaskingController,
1124
+ entity: Entity,
1125
+ component: Component,
1126
+ component_type: number
1127
+ )
1128
+ local storage = masking:get_component_storage_group(entity, component, component_type)
1129
+ local additions = get_or_set_component_added(storage, entity)
1130
+ additions[component_type][component] = true
1131
+ end
1132
+
1133
+ function masking_controller.allocate_component_stop(
1134
+ masking: MaskingController,
1135
+ entity: Entity,
1136
+ component: Component,
1137
+ component_type: number
1138
+ )
1139
+ local storage = masking:get_component_storage_group(entity, component, component_type) :: StorageGroup
1140
+ if not storage then
1141
+ return
1142
+ end
1143
+
1144
+ local deletions = storage.deletions.components[entity]
1145
+ if deletions == nil then
1146
+ deletions = create_component_indexes() :: ComponentIndex<boolean>
1147
+ deletions[component_type][component] = true
1148
+ storage.deletions.components[entity] = deletions
1149
+ else
1150
+ deletions[component_type][component] = true
1151
+ end
1152
+ end
1153
+
1154
+ function masking_controller.deallocate_entity_stop(masking: MaskingController, entity: Entity)
1155
+ local deletion_lookup = masking.lookups.deletions.entities[entity]
1156
+ if not deletion_lookup then
1157
+ return
1158
+ end
1159
+ local storage = deletion_lookup.storage_group
1160
+
1161
+ if storage.deletions.entities[entity] then
1162
+ storage.deletions.entities[entity] = nil
1163
+ storage.deletions_count -= 1
1164
+ end
1165
+ end
1166
+
1167
+ function masking_controller.deallocate_component_start(
1168
+ masking: MaskingController,
1169
+ entity: Entity,
1170
+ component: Component,
1171
+ component_type: number
1172
+ )
1173
+ local storage: StorageGroup = masking:get_component_storage_group(entity, component, component_type)
1174
+ local additions = storage.changes.added_components[entity]
1175
+ if additions then
1176
+ additions[component_type][component] = nil
1177
+ end
1178
+ end
1179
+
1180
+ function masking_controller.deallocate_component_stop(
1181
+ masking: MaskingController,
1182
+ entity: Entity,
1183
+ component: Component,
1184
+ component_type: number
1185
+ )
1186
+ local deletion_lookup =
1187
+ get_component_index_entry(masking.lookups.deletions.components, entity, component, component_type)
1188
+ if deletion_lookup == nil then
1189
+ return
1190
+ end
1191
+ local storage = deletion_lookup.storage_group
1192
+
1193
+ local deletions = storage.deletions.components[entity]
1194
+ if deletions then
1195
+ if deletions[component_type][component] then
1196
+ deletions[component_type][component] = nil
1197
+ end
1198
+ end
1199
+ end
1200
+
1201
+ function masking_controller.allocate_tag_addition(masking: MaskingController, entity: Entity, tag: Component)
1202
+ local storage = masking:get_component_storage_group(entity, tag, COMPONENT_TYPES.tag)
1203
+ local changes = get_or_set_changed(storage, entity)
1204
+
1205
+ changes.tag_added[tag] = true
1206
+ changes.tag_removed[tag] = nil
1207
+ end
1208
+
1211
1209
  function masking_controller.allocate_component_change(
1212
- masking: MaskingInternal,
1210
+ masking: MaskingController,
1213
1211
  entity: Entity,
1214
- component: Entity,
1212
+ component: Component,
1215
1213
  value: any
1216
1214
  )
1217
1215
  local storage = masking:get_component_storage_group(entity, component, COMPONENT_TYPES.component)
1218
1216
  local changes = get_or_set_changed(storage, entity)
1219
- changes.component[component] = value
1220
- changes.removed[component] = nil
1217
+
1218
+ changes.component_changed[component] = value
1219
+ changes.component_removed[component] = nil
1220
+ end
1221
+
1222
+ function masking_controller.allocate_unreliable_addition(
1223
+ masking: MaskingController,
1224
+ entity: Entity,
1225
+ component: Component
1226
+ )
1227
+ local storage = masking:get_component_storage_group(entity, component, COMPONENT_TYPES.unreliable)
1228
+ local changes = get_or_set_changed(storage, entity)
1229
+
1230
+ changes.unreliable_added[component] = true
1231
+ changes.unreliable_removed[component] = nil
1232
+ end
1233
+
1234
+ function masking_controller.allocate_pair_tag_addition(masking: MaskingController, entity: Entity, id: Component)
1235
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_tag)
1236
+ local changes = get_or_set_changed(storage, entity)
1237
+
1238
+ changes.pair_tag_added[id] = true
1239
+ changes.pair_tag_removed[id] = nil
1240
+ end
1241
+
1242
+ function masking_controller.allocate_pair_component_change(
1243
+ masking: MaskingController,
1244
+ entity: Entity,
1245
+ id: Component,
1246
+ value: any
1247
+ )
1248
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_component)
1249
+ local changes = get_or_set_changed(storage, entity)
1250
+
1251
+ changes.pair_component_changed[id] = value
1252
+ changes.pair_component_removed[id] = nil
1221
1253
  end
1222
1254
 
1223
- function masking_controller.allocate_pair_value_change(
1224
- masking: MaskingInternal,
1255
+ function masking_controller.allocate_relation_component_change(
1256
+ masking: MaskingController,
1225
1257
  entity: Entity,
1226
- relation: Entity,
1258
+ relation: Component,
1227
1259
  target: Entity,
1228
1260
  value: any
1229
1261
  )
1230
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair_value)
1262
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation_component)
1231
1263
  local changes = get_or_set_changed(storage, entity)
1232
- local values = changes.pairs_values.changed[relation]
1264
+ local values = changes.relation_component_changed[relation]
1233
1265
  if values == nil then
1234
1266
  values = {}
1235
- changes.pairs_values.changed[relation] = values
1267
+ changes.relation_component_changed[relation] = values
1236
1268
  end
1237
1269
  values[target] = value
1238
1270
 
1239
- local removed = changes.pairs_values.removed[relation]
1271
+ local removed = changes.relation_component_removed[relation]
1240
1272
  if removed ~= nil then
1241
1273
  removed[target] = nil
1242
1274
  end
1243
1275
  end
1244
1276
 
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,
1277
+ function masking_controller.allocate_relation_tag_addition(
1278
+ masking: MaskingController,
1254
1279
  entity: Entity,
1255
- relation: Entity,
1280
+ relation: Component,
1256
1281
  target: Entity
1257
1282
  )
1258
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair)
1283
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation)
1259
1284
  local changes = get_or_set_changed(storage, entity)
1260
- local targets = changes.pairs[relation]
1285
+ local targets = changes.relation_tag_added[relation]
1261
1286
  if targets == nil then
1262
1287
  targets = {}
1263
- changes.pairs[relation] = targets
1288
+ changes.relation_tag_added[relation] = targets
1264
1289
  end
1265
1290
  targets[target] = true
1291
+
1292
+ local removed = changes.relation_tag_removed[relation]
1293
+ if removed then
1294
+ removed[target] = nil
1295
+ end
1266
1296
  end
1267
1297
 
1268
- function masking_controller.allocate_component_removal(masking: MaskingInternal, entity: Entity, component: Entity)
1298
+ function masking_controller.allocate_tag_removal(masking: MaskingController, entity: Entity, tag: Component)
1299
+ local storage = masking:get_component_storage_group(entity, tag, COMPONENT_TYPES.tag)
1300
+ local changes = get_or_set_changed(storage, entity)
1301
+
1302
+ changes.tag_added[tag] = nil
1303
+ changes.tag_removed[tag] = true
1304
+ end
1305
+
1306
+ function masking_controller.allocate_component_removal(masking: MaskingController, entity: Entity, component: Component)
1269
1307
  local storage = masking:get_component_storage_group(entity, component, COMPONENT_TYPES.component)
1270
1308
  local changes = get_or_set_changed(storage, entity)
1271
1309
 
1272
- changes.component[component] = nil
1273
- changes.removed[component] = true
1310
+ changes.component_changed[component] = nil
1311
+ changes.component_removed[component] = true
1274
1312
  end
1275
1313
 
1276
- function masking_controller.allocate_tag_removal(masking: MaskingInternal, entity: Entity, tag: Entity)
1277
- local storage = masking:get_component_storage_group(entity, tag, COMPONENT_TYPES.tag)
1314
+ function masking_controller.allocate_unreliable_removal(
1315
+ masking: MaskingController,
1316
+ entity: Entity,
1317
+ component: Component
1318
+ )
1319
+ local storage = masking:get_component_storage_group(entity, component, COMPONENT_TYPES.unreliable)
1320
+ local changes = get_or_set_changed(storage, entity)
1321
+
1322
+ changes.unreliable_added[component] = nil
1323
+ changes.unreliable_removed[component] = true
1324
+ end
1325
+
1326
+ function masking_controller.allocate_pair_tag_removal(masking: MaskingController, entity: Entity, id: Component)
1327
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_tag)
1328
+ local changes = get_or_set_changed(storage, entity)
1329
+
1330
+ changes.pair_tag_added[id] = nil
1331
+ changes.pair_tag_removed[id] = true
1332
+ end
1333
+
1334
+ function masking_controller.allocate_pair_component_removal(masking: MaskingController, entity: Entity, id: Component)
1335
+ local storage = masking:get_component_storage_group(entity, id, COMPONENT_TYPES.pair_component)
1278
1336
  local changes = get_or_set_changed(storage, entity)
1279
1337
 
1280
- changes.tagged[tag] = nil
1281
- changes.removed[tag] = true
1338
+ changes.pair_component_changed[id] = nil
1339
+ changes.pair_component_removed[id] = true
1282
1340
  end
1283
1341
 
1284
- function masking_controller.allocate_pair_removal(
1285
- masking: MaskingInternal,
1342
+ function masking_controller.allocate_relation_tag_removal(
1343
+ masking: MaskingController,
1286
1344
  entity: Entity,
1287
- relation: Entity,
1345
+ relation: Component,
1288
1346
  target: Entity
1289
1347
  )
1290
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair)
1348
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation)
1291
1349
  local changes = get_or_set_changed(storage, entity)
1292
- local targets = changes.pairs[relation]
1350
+ local targets = changes.relation_tag_removed[relation]
1293
1351
  if targets == nil then
1294
1352
  targets = {}
1295
- changes.pairs[relation] = targets
1353
+ changes.relation_tag_removed[relation] = targets
1354
+ end
1355
+ targets[target] = true
1356
+
1357
+ local added = changes.relation_tag_added[relation]
1358
+ if added then
1359
+ added[target] = nil
1296
1360
  end
1297
- targets[target] = false
1298
1361
  end
1299
1362
 
1300
- function masking_controller.allocate_pair_value_removal(
1301
- masking: MaskingInternal,
1363
+ function masking_controller.allocate_relation_component_removal(
1364
+ masking: MaskingController,
1302
1365
  entity: Entity,
1303
- relation: Entity,
1366
+ relation: Component,
1304
1367
  target: Entity
1305
1368
  )
1306
- local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.pair_value)
1369
+ local storage = masking:get_component_storage_group(entity, relation, COMPONENT_TYPES.relation_component)
1307
1370
  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
1371
+ local targets = changes.relation_component_removed[relation]
1372
+ if targets == nil then
1373
+ targets = {}
1374
+ changes.relation_component_removed[relation] = targets
1312
1375
  end
1313
- removed[target] = true
1376
+ targets[target] = true
1314
1377
 
1315
- local values = changes.pairs_values.changed[relation]
1316
- if values ~= nil then
1378
+ local values = changes.relation_component_changed[relation]
1379
+ if values then
1317
1380
  values[target] = nil
1318
1381
  end
1319
1382
  end
@@ -1339,12 +1402,12 @@ local function remap_bitmask(
1339
1402
  return result
1340
1403
  end
1341
1404
 
1342
- local function bitmask_from_set(masking: MaskingInternal, member_set: { [Member]: boolean }): utils.Bitmask
1405
+ local function bitmask_from_set(masking: MaskingController, member_set: { [Member]: boolean }): utils.Bitmask
1343
1406
  local new_bitmask = utils.bitmask.create(masking.member_count)
1344
1407
  for member: Member in member_set do
1345
1408
  local index = masking.client_indexes[member]
1346
1409
  if not index then
1347
- local alias = masking.client_indexes[masking.client_aliases[member]]
1410
+ local alias = masking.client_indexes[masking.client_aliases[member] ]
1348
1411
  if alias then
1349
1412
  if utils.is_client_valid(alias) then
1350
1413
  index = alias
@@ -1362,7 +1425,7 @@ local function bitmask_from_set(masking: MaskingInternal, member_set: { [Member]
1362
1425
  end
1363
1426
 
1364
1427
  function masking_controller.merge_storages(
1365
- masking: MaskingInternal,
1428
+ masking: MaskingController,
1366
1429
  old_storage: StorageGroup,
1367
1430
  new_storage: StorageGroup
1368
1431
  )
@@ -1414,7 +1477,7 @@ function masking_controller.merge_storages(
1414
1477
  end
1415
1478
  end
1416
1479
 
1417
- function masking_controller.compact_members(masking: MaskingInternal)
1480
+ function masking_controller.compact_members(masking: MaskingController)
1418
1481
  -- we dont recompute as nothing should've changed
1419
1482
  -- so this should be hopefully quite cheap
1420
1483
  local old_indexes = masking.client_indexes
@@ -1444,8 +1507,7 @@ function masking_controller.compact_members(masking: MaskingInternal)
1444
1507
  if component_bitmask then
1445
1508
  component_generator.bitmask = remap_bitmask(component_bitmask, old_indexes, new_indexes, new_count)
1446
1509
  end
1447
- component_generator.result =
1448
- remap_bitmask(component_generator.result, old_indexes, new_indexes, new_count)
1510
+ component_generator.result = remap_bitmask(component_generator.result, old_indexes, new_indexes, new_count)
1449
1511
 
1450
1512
  local band_generator = component_lookup.band_generator
1451
1513
  local band_bitmask = band_generator.bitmask
@@ -1486,7 +1548,10 @@ function masking_controller.compact_members(masking: MaskingInternal)
1486
1548
  masking.storages = new_storages
1487
1549
  end
1488
1550
 
1489
- function masking_controller.create_generator_from_filter(masking: MaskingInternal, filter: MemberFilter): MaskGenerator
1551
+ function masking_controller.create_generator_from_filter(
1552
+ masking: MaskingController,
1553
+ filter: MemberFilter
1554
+ ): MaskGenerator
1490
1555
  local is_include = is_include_filter(filter)
1491
1556
  if is_include then
1492
1557
  return masking:create_include_generator(filter) :: MaskGenerator
@@ -1495,7 +1560,7 @@ function masking_controller.create_generator_from_filter(masking: MaskingInterna
1495
1560
  end
1496
1561
  end
1497
1562
 
1498
- function masking_controller.create_exclude_generator(masking: MaskingInternal, exclude: MemberFilter)
1563
+ function masking_controller.create_exclude_generator(masking: MaskingController, exclude: MemberFilter)
1499
1564
  local bitmask = bitmask_from_set(masking, exclude)
1500
1565
  local active_members = masking.active_members_generator
1501
1566
 
@@ -1509,7 +1574,7 @@ function masking_controller.create_exclude_generator(masking: MaskingInternal, e
1509
1574
  end
1510
1575
 
1511
1576
  -- TODO: check for players existing and register them if they don't
1512
- function masking_controller.create_include_generator(masking: MaskingInternal, include: MemberFilter): MaskGenerator
1577
+ function masking_controller.create_include_generator(masking: MaskingController, include: MemberFilter): MaskGenerator
1513
1578
  local bitmask = bitmask_from_set(masking, include)
1514
1579
  local active_members = masking.active_members_generator
1515
1580
 
@@ -1522,7 +1587,7 @@ function masking_controller.create_include_generator(masking: MaskingInternal, i
1522
1587
  return new_generator
1523
1588
  end
1524
1589
 
1525
- function masking_controller.create_all_members_generator(masking: MaskingInternal)
1590
+ function masking_controller.create_all_members_generator(masking: MaskingController)
1526
1591
  local filter: MemberFilter = {}
1527
1592
  for member in masking.client_indexes do
1528
1593
  filter[member] = true
@@ -1547,11 +1612,11 @@ function masking_controller.create_active_generator(masking: MaskingController):
1547
1612
  return new_generator
1548
1613
  end
1549
1614
 
1550
- --function masking_controller.register_mask_group(masking: MaskingInternal, group: Member) end
1615
+ --function masking_controller.register_mask_group(masking: MaskingController, group: Member) end
1551
1616
 
1552
- --function masking_controller.unregister_mask_group(masking: MaskingInternal, group: Member) end
1617
+ --function masking_controller.unregister_mask_group(masking: MaskingController, group: Member) end
1553
1618
 
1554
- function masking_controller.register_client(masking: MaskingInternal, member: Member)
1619
+ function masking_controller.register_client(masking: MaskingController, member: Member)
1555
1620
  if masking.client_indexes[member] then
1556
1621
  return
1557
1622
  end
@@ -1570,7 +1635,7 @@ function masking_controller.register_client(masking: MaskingInternal, member: Me
1570
1635
  end
1571
1636
  end
1572
1637
 
1573
- function masking_controller.unregister_client(masking: MaskingInternal, member: Member)
1638
+ function masking_controller.unregister_client(masking: MaskingController, member: Member)
1574
1639
  local index = masking.client_indexes[member]
1575
1640
  if index == nil then
1576
1641
  return
@@ -1580,7 +1645,7 @@ function masking_controller.unregister_client(masking: MaskingInternal, member:
1580
1645
  masking.active_members_generator:compute()
1581
1646
  end
1582
1647
 
1583
- function masking_controller.activate_client(masking: MaskingInternal, member: Member)
1648
+ function masking_controller.activate_client(masking: MaskingController, member: Member)
1584
1649
  local index = masking.client_indexes[member]
1585
1650
 
1586
1651
  masking.unreplicated[member] = nil
@@ -1588,7 +1653,7 @@ function masking_controller.activate_client(masking: MaskingInternal, member: Me
1588
1653
  masking.active_members_generator:compute()
1589
1654
  end
1590
1655
 
1591
- function masking_controller.member_is_active(masking: MaskingInternal, member: Member): boolean
1656
+ function masking_controller.member_is_active(masking: MaskingController, member: Member): boolean
1592
1657
  local index = masking.client_indexes[member]
1593
1658
  if index == nil then
1594
1659
  return false
@@ -1598,7 +1663,7 @@ function masking_controller.member_is_active(masking: MaskingInternal, member: M
1598
1663
  end
1599
1664
 
1600
1665
  local function create(): MaskingController
1601
- local self = {} :: MaskingInternal
1666
+ local self = {} :: MaskingController
1602
1667
 
1603
1668
  self.client_indexes = {}
1604
1669
  self.group_indexes = {}