@rbxts/replecs 0.1.0-alpha9-test5 → 0.1.0-alpha9

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.
@@ -19,19 +19,12 @@ type Disconnect = () -> ()
19
19
  type HookMethod =
20
20
  & ((
21
21
  self: Client,
22
- entity: Entity,
23
- action: "change",
24
- relation: Entity,
22
+ action: "changed",
23
+ relation: Id,
25
24
  callback: (entity: Entity, id: Id, value: any) -> ()
26
25
  ) -> Disconnect)
27
- & ((
28
- self: Client,
29
- entity: Entity,
30
- action: "removed",
31
- relation: Entity,
32
- callback: (entity: Entity, id: Id) -> ()
33
- ) -> Disconnect)
34
- & (self: Client, entity: Entity, action: "deleted", callback: (entity: Entity) -> ()) -> Disconnect
26
+ & ((self: Client, action: "removed", relation: Id, callback: (entity: Entity, id: Id) -> ()) -> Disconnect)
27
+ & (self: Client, action: "deleted", entity: Entity, callback: (entity: Entity) -> ()) -> Disconnect
35
28
 
36
29
  type ChangedHooksEntry = {
37
30
  overrides: boolean,
@@ -77,12 +70,10 @@ export type Client = {
77
70
  hook: HookMethod,
78
71
  override: HookMethod,
79
72
  addition_hooks: Array<(entity: Entity) -> ()>,
80
- entity_hooks: {
81
- [Entity]: {
82
- changed: Map<Entity, ChangedHooksEntry>,
83
- removed: Map<Entity, RemovedHooksEntry>,
84
- deleted: DeletedHookEntry?,
85
- },
73
+ network_hooks: {
74
+ deleted: { [Entity]: DeletedHookEntry },
75
+ changed: { [Id]: ChangedHooksEntry },
76
+ removed: { [Id]: RemovedHooksEntry },
86
77
  },
87
78
 
88
79
  encode_component: (self: Client, component: Entity) -> number,
@@ -326,17 +317,11 @@ local function process_entity_id(client: Client, c: Cursor, variants: { any }?)
326
317
  end
327
318
  end
328
319
 
329
- local function process_entity_relations(
330
- client: Client,
331
- entity: jecs.Entity,
332
- changed_hooks: Map<Entity, ChangedHooksEntry>?,
333
- c: Cursor,
334
- variants: { any }?
335
- )
320
+ local function process_entity_relations(client: Client, entity: jecs.Entity, c: Cursor, variants: { any }?)
336
321
  local components = client.components
337
322
  local relation = read_component_id(client, c)
338
323
  local total_targets = cursor.read_vlq(c)
339
- local pair_hooks = changed_hooks and changed_hooks[PAIR(components.pair, relation)]
324
+ local pair_hooks = client.network_hooks.changed[PAIR(components.pair, relation)]
340
325
 
341
326
  for _ = 1, total_targets do
342
327
  local target = process_entity_id(client, c, variants)
@@ -344,17 +329,11 @@ local function process_entity_relations(
344
329
  end
345
330
  end
346
331
 
347
- local function process_entity_relation_values(
348
- client: Client,
349
- entity: jecs.Entity,
350
- changed_hooks: Map<Entity, ChangedHooksEntry>?,
351
- c: Cursor,
352
- variants: { any }?
353
- )
332
+ local function process_entity_relation_values(client: Client, entity: jecs.Entity, c: Cursor, variants: { any }?)
354
333
  local relation = read_component_id(client, c)
355
334
  local total_targets = cursor.read_vlq(c)
356
335
  local components = client.components
357
- local pair_hooks = changed_hooks and changed_hooks[PAIR(components.pair, relation)]
336
+ local pair_hooks = client.network_hooks.changed[PAIR(components.pair, relation)]
358
337
 
359
338
  for _ = 1, total_targets do
360
339
  local value = read_component_value(client, relation, c, variants)
@@ -365,32 +344,31 @@ end
365
344
 
366
345
  local function process_entity(client: Client, c: Cursor, variants: { any }?)
367
346
  local entity = process_entity_id(client, c, variants)
368
- local entity_hooks = client.entity_hooks[entity]
369
- local changed_hooks = entity_hooks and entity_hooks.changed
347
+ local changed_hooks = client.network_hooks.changed
370
348
  local components = client.components
371
349
 
372
350
  local total_tags = cursor.read_vlq(c)
373
351
  for _ = 1, total_tags do
374
352
  local tag = read_component_id(client, c)
375
- local tag_hooks = changed_hooks and changed_hooks[PAIR(components.reliable, tag)]
353
+ local tag_hooks = changed_hooks[PAIR(components.reliable, tag)]
376
354
  network_entity_add(client, entity, tag, tag_hooks)
377
355
  end
378
356
 
379
357
  local total_components = cursor.read_vlq(c)
380
358
  for _ = 1, total_components do
381
359
  local component, value = read_component(client, c, variants)
382
- local component_hooks = changed_hooks and changed_hooks[PAIR(components.reliable, component)]
360
+ local component_hooks = changed_hooks[PAIR(components.reliable, component)]
383
361
  network_entity_set(client, entity, component, value, component_hooks)
384
362
  end
385
363
 
386
364
  local total_pairs = cursor.read_vlq(c)
387
365
  for _ = 1, total_pairs do
388
- process_entity_relations(client, entity, changed_hooks, c, variants)
366
+ process_entity_relations(client, entity, c, variants)
389
367
  end
390
368
 
391
369
  local total_pairs_values = cursor.read_vlq(c)
392
370
  for _ = 1, total_pairs_values do
393
- process_entity_relation_values(client, entity, changed_hooks, c, variants)
371
+ process_entity_relation_values(client, entity, c, variants)
394
372
  end
395
373
  end
396
374
 
@@ -442,6 +420,9 @@ local function apply_updates(client: Client, buf: buffer, all_variants: { { any
442
420
  local components = client.components
443
421
  local total_packets = cursor.read_vlq(c)
444
422
  local variant_start = (all_variants and #all_variants + 1) :: number
423
+ local changed_hooks = client.network_hooks.changed
424
+ local removed_hooks = client.network_hooks.removed
425
+ local deleted_hooks = client.network_hooks.deleted
445
426
 
446
427
  for a = 1, total_packets do
447
428
  local variants = all_variants and all_variants[variant_start - a]
@@ -457,31 +438,28 @@ local function apply_updates(client: Client, buf: buffer, all_variants: { { any
457
438
  local entity = process_entity_id(client, c, variants)
458
439
  local added_mask = cursor.readu8(c)
459
440
 
460
- local entity_hooks = client.entity_hooks[entity]
461
- local changed_hooks = entity_hooks and entity_hooks.changed
462
-
463
441
  local total_tags = read_vlq_bitmask(c, added_mask, 0)
464
442
  for _ = 1, total_tags do
465
443
  local tag = read_component_id(client, c)
466
- local tag_hooks = changed_hooks and changed_hooks[PAIR(components.reliable, tag)]
444
+ local tag_hooks = changed_hooks[PAIR(components.reliable, tag)]
467
445
  network_entity_add(client, entity, tag, tag_hooks)
468
446
  end
469
447
 
470
448
  local total_components = read_vlq_bitmask(c, added_mask, 1)
471
449
  for _ = 1, total_components do
472
450
  local component, value = read_component(client, c, variants)
473
- local component_hooks = changed_hooks and changed_hooks[PAIR(components.reliable, component)]
451
+ local component_hooks = changed_hooks[PAIR(components.reliable, component)]
474
452
  network_entity_set(client, entity, component, value, component_hooks)
475
453
  end
476
454
 
477
455
  local total_pairs = read_vlq_bitmask(c, added_mask, 2)
478
456
  for _ = 1, total_pairs do
479
- process_entity_relations(client, entity, changed_hooks, c, variants)
457
+ process_entity_relations(client, entity, c, variants)
480
458
  end
481
459
 
482
460
  local total_pairs_values = read_vlq_bitmask(c, added_mask, 3)
483
461
  for _ = 1, total_pairs_values do
484
- process_entity_relation_values(client, entity, changed_hooks, c, variants)
462
+ process_entity_relation_values(client, entity, c, variants)
485
463
  end
486
464
  end
487
465
 
@@ -490,36 +468,32 @@ local function apply_updates(client: Client, buf: buffer, all_variants: { { any
490
468
  local entity = process_entity_id(client, c, variants)
491
469
  local changed_mask = cursor.readu8(c)
492
470
 
493
- local entity_hooks = client.entity_hooks[entity]
494
- local changed_hooks = entity_hooks and entity_hooks.changed
495
- local removed_hooks = entity_hooks and entity_hooks.removed
496
-
497
471
  local total_tagged = read_vlq_bitmask(c, changed_mask, 0)
498
472
  for _ = 1, total_tagged do
499
473
  local tag = read_component_id(client, c)
500
- local tag_hooks = changed_hooks and changed_hooks[PAIR(components.reliable, tag)]
474
+ local tag_hooks = changed_hooks[PAIR(components.reliable, tag)]
501
475
  network_entity_add(client, entity, tag, tag_hooks)
502
476
  end
503
477
 
504
478
  local total_components = read_vlq_bitmask(c, changed_mask, 1)
505
479
  for _ = 1, total_components do
506
480
  local component, value = read_component(client, c, variants)
507
- local component_hooks = changed_hooks and changed_hooks[PAIR(components.reliable, component)]
481
+ local component_hooks = changed_hooks[PAIR(components.reliable, component)]
508
482
  network_entity_set(client, entity, component, value, component_hooks)
509
483
  end
510
484
 
511
485
  local total_removed = read_vlq_bitmask(c, changed_mask, 2)
512
486
  for _ = 1, total_removed do
513
487
  local component = read_component_id(client, c)
514
- local component_hooks = removed_hooks and removed_hooks[PAIR(components.reliable, component)]
488
+ local component_hooks = removed_hooks[PAIR(components.reliable, component)]
515
489
  network_entity_remove(client, entity, component, component_hooks)
516
490
  end
517
491
 
518
492
  local total_pairs = read_vlq_bitmask(c, changed_mask, 3)
519
493
  for _ = 1, total_pairs do
520
494
  local relation = read_component_id(client, c)
521
- local pair_changed_hooks = changed_hooks and changed_hooks[PAIR(components.pair, relation)]
522
- local pair_removed_hooks = removed_hooks and removed_hooks[PAIR(components.pair, relation)]
495
+ local pair_changed_hooks = changed_hooks[PAIR(components.pair, relation)]
496
+ local pair_removed_hooks = removed_hooks[PAIR(components.pair, relation)]
523
497
  local total_targets = cursor.read_vlq(c)
524
498
 
525
499
  for _ = 1, total_targets do
@@ -540,7 +514,7 @@ local function apply_updates(client: Client, buf: buffer, all_variants: { { any
540
514
  local total_pairs_values_removed = read_vlq_bitmask(c, changed_mask, 4)
541
515
  for _ = 1, total_pairs_values_removed do
542
516
  local relation = read_component_id(client, c)
543
- local pair_hooks = removed_hooks and removed_hooks[PAIR(components.pair, relation)]
517
+ local pair_hooks = removed_hooks[PAIR(components.pair, relation)]
544
518
  local total_targets = cursor.read_vlq(c)
545
519
 
546
520
  for _ = 1, total_targets do
@@ -554,7 +528,7 @@ local function apply_updates(client: Client, buf: buffer, all_variants: { { any
554
528
  local total_pairs_values = read_vlq_bitmask(c, changed_mask, 5)
555
529
  for _ = 1, total_pairs_values do
556
530
  local relation = read_component_id(client, c)
557
- local pair_hooks = changed_hooks and changed_hooks[PAIR(components.pair, relation)]
531
+ local pair_hooks = changed_hooks[PAIR(components.pair, relation)]
558
532
  local total_targets = cursor.read_vlq(c)
559
533
 
560
534
  for _ = 1, total_targets do
@@ -568,20 +542,18 @@ local function apply_updates(client: Client, buf: buffer, all_variants: { { any
568
542
  local total_component_deletions = read_vlq_bitmask(c, storage_mask, 3)
569
543
  for _ = 1, total_component_deletions do
570
544
  local entity = process_entity_id(client, c, variants)
571
- local entity_hooks = client.entity_hooks[entity]
572
- local removed_hooks = entity_hooks and entity_hooks.removed
573
545
 
574
546
  local total_removed = cursor.read_vlq(c)
575
547
  for _ = 1, total_removed do
576
548
  local component = read_component_id(client, c)
577
- local component_hooks = removed_hooks and removed_hooks[PAIR(components.reliable, component)]
549
+ local component_hooks = removed_hooks[PAIR(components.reliable, component)]
578
550
  network_entity_remove(client, entity, component, component_hooks)
579
551
  end
580
552
 
581
553
  local total_pairs = cursor.read_vlq(c)
582
554
  for _ = 1, total_pairs do
583
555
  local relation = read_component_id(client, c)
584
- local pair_hooks = removed_hooks and removed_hooks[PAIR(components.pair, relation)]
556
+ local pair_hooks = removed_hooks[PAIR(components.pair, relation)]
585
557
  network_entity_remove_relations(client, entity, relation, pair_hooks)
586
558
  end
587
559
  end
@@ -590,13 +562,12 @@ local function apply_updates(client: Client, buf: buffer, all_variants: { { any
590
562
  for _ = 1, total_deleted do
591
563
  local entity, server_id = read_entity_id(client, c, variants)
592
564
  if entity then
593
- local entity_hooks = client.entity_hooks[entity]
594
- local deleted_hooks = entity_hooks and entity_hooks.deleted
595
- if deleted_hooks then
596
- for _, callback in deleted_hooks.callbacks do
565
+ local deleted_hook = deleted_hooks[entity]
566
+ if deleted_hook then
567
+ for _, callback in deleted_hook.callbacks do
597
568
  callback(entity)
598
569
  end
599
- if not deleted_hooks.overrides then
570
+ if not deleted_hook.overrides then
600
571
  client.world:delete(entity)
601
572
  end
602
573
  else
@@ -621,6 +592,7 @@ local function apply_unreliable(client: Client, buf: buffer, all_variants: { { a
621
592
  local components = client.components
622
593
  local total_packets = cursor.read_vlq(c)
623
594
  local variant_start = (all_variants and #all_variants + 1) :: number
595
+ local changed_hooks = client.network_hooks.changed
624
596
 
625
597
  for a = 1, total_packets do
626
598
  local total_entities = cursor.read_vlq(c)
@@ -632,12 +604,9 @@ local function apply_unreliable(client: Client, buf: buffer, all_variants: { { a
632
604
  local total_unreliable = cursor.read_vlq(c)
633
605
 
634
606
  if entity then
635
- local entity_hooks = client.entity_hooks[entity]
636
- local changed_hooks = entity_hooks and entity_hooks.changed
637
-
638
607
  for _ = 1, total_unreliable do
639
608
  local component_id, value = read_component(client, c, variants)
640
- local unreliable_hooks = changed_hooks and changed_hooks[PAIR(components.unreliable, component_id)]
609
+ local unreliable_hooks = changed_hooks[PAIR(components.unreliable, component_id)]
641
610
  network_entity_set(client, entity, component_id, value, unreliable_hooks)
642
611
  end
643
612
  else
@@ -711,7 +680,7 @@ local function init(client: Client, _world: World?)
711
680
  client.server_ids[server_id] = nil
712
681
  client.client_ids[entity] = nil
713
682
  end
714
- client.entity_hooks[entity] = nil
683
+ client.network_hooks.deleted[entity] = nil
715
684
  end)
716
685
  table.insert(client.hooked, alive_unhook)
717
686
 
@@ -745,24 +714,11 @@ local function added(client: Client, callback: (entity: Entity) -> ())
745
714
  end
746
715
  end
747
716
 
748
- local function get_or_create_entity_hooks(client: Client, entity: Entity)
749
- local entity_hooks = client.entity_hooks[entity]
750
- if not entity_hooks then
751
- entity_hooks = {
752
- changed = {},
753
- removed = {},
754
- deleted = nil :: DeletedHookEntry?,
755
- }
756
- client.entity_hooks[entity] = entity_hooks
757
- end
758
- return entity_hooks
759
- end
760
-
761
- local function add_hook_entry(client: Client, entity: Entity, action: string, ...): ({ overrides: boolean }, () -> ())
717
+ local function add_hook_entry(client: Client, action: string, ...): ({ overrides: boolean }, () -> ())
762
718
  if action == "changed" or action == "removed" then
763
719
  local relation = select(1, ...) :: Entity
764
720
  local callback = select(2, ...) :: (entity: Entity, id: number, value: any) -> ()
765
- local hooks = get_or_create_entity_hooks(client, entity)[action]
721
+ local hooks = action == "changed" and client.network_hooks.changed or client.network_hooks.removed
766
722
  local entries = hooks[relation] :: ChangedHooksEntry
767
723
 
768
724
  if not entries then
@@ -786,16 +742,17 @@ local function add_hook_entry(client: Client, entity: Entity, action: string, ..
786
742
  end
787
743
  return entries, disconnect
788
744
  elseif action == "deleted" then
789
- local callback = select(1, ...) :: (entity: Entity) -> ()
790
- local hooks = get_or_create_entity_hooks(client, entity)
791
- local entries = hooks.deleted :: DeletedHookEntry
745
+ local entity = select(1, ...) :: Entity
746
+ local callback = select(2, ...) :: (entity: Entity) -> ()
747
+ local hooks = client.network_hooks.deleted
748
+ local entries = hooks[entity]
792
749
 
793
750
  if not entries then
794
751
  entries = {
795
752
  overrides = false,
796
753
  callbacks = {},
797
754
  }
798
- hooks.deleted = entries
755
+ hooks[entity] = entries
799
756
  end
800
757
  table.insert(entries.callbacks, callback)
801
758
 
@@ -805,7 +762,7 @@ local function add_hook_entry(client: Client, entity: Entity, action: string, ..
805
762
  if index then
806
763
  table.remove(callbacks, index)
807
764
  if #callbacks == 0 then
808
- hooks.deleted = nil
765
+ hooks[entity] = nil
809
766
  end
810
767
  end
811
768
  end
@@ -815,13 +772,13 @@ local function add_hook_entry(client: Client, entity: Entity, action: string, ..
815
772
  end
816
773
  end
817
774
 
818
- local function hook(client: Client, entity: Entity, action: string, ...)
819
- local entry, disconnect = add_hook_entry(client, entity, action, ...)
775
+ local function hook(client: Client, action: string, ...)
776
+ local entry, disconnect = add_hook_entry(client, action, ...)
820
777
  entry.overrides = false
821
778
  return disconnect
822
779
  end
823
- local function override(client: Client, entity: Entity, action: string, ...)
824
- local entry, disconnect = add_hook_entry(client, entity, action, ...)
780
+ local function override(client: Client, action: string, ...)
781
+ local entry, disconnect = add_hook_entry(client, action, ...)
825
782
  entry.overrides = true
826
783
  return disconnect
827
784
  end
@@ -887,7 +844,11 @@ local function create(world: World?, components: common.Components): Client
887
844
  self.hooked = {}
888
845
 
889
846
  self.addition_hooks = {}
890
- self.entity_hooks = {}
847
+ self.network_hooks = {
848
+ deleted = {},
849
+ changed = {},
850
+ removed = {},
851
+ }
891
852
  self.after_replication_callbacks = {}
892
853
 
893
854
  return setmetatable(self, client) :: any
@@ -1,4 +1,4 @@
1
- import type { Entity, Pair, Tag, World } from "@rbxts/jecs";
1
+ import type { Entity, Id, Pair, Tag, World } from "@rbxts/jecs";
2
2
 
3
3
  declare namespace Replecs {
4
4
  export type SerdesTable =
@@ -62,38 +62,34 @@ declare namespace Replecs {
62
62
  after_replication(callback: () => void): void;
63
63
  added(callback: (entity: Entity) => void): () => void;
64
64
  hook<T>(
65
- entity: Entity,
66
65
  action: "changed",
67
66
  relation: Pair<MemberFilter, T>,
68
- callback: (entity: Entity, id: Entity<T>, value: T) => void
67
+ callback: (entity: Entity, id: Id<T>, value: T) => void
69
68
  ): () => void;
70
69
  hook<T>(
71
- entity: Entity,
72
70
  action: "removed",
73
71
  relation: Pair<MemberFilter, T>,
74
- callback: (entity: Entity, id: Entity<T>) => void
72
+ callback: (entity: Entity, id: Id<T>) => void
75
73
  ): () => void;
76
74
  hook(
77
- entity: Entity,
78
75
  action: "deleted",
76
+ entity: Entity,
79
77
  callback: (entity: Entity) => void
80
78
  ): () => void;
81
79
 
82
80
  override<T>(
83
- entity: Entity,
84
81
  action: "changed",
85
82
  relation: Pair<MemberFilter, T>,
86
- callback: (entity: Entity, id: Entity<T>, value: any) => void
83
+ callback: (entity: Entity, id: Id<T>, value: any) => void
87
84
  ): () => void;
88
85
  override<T>(
89
- entity: Entity,
90
86
  action: "removed",
91
87
  relation: Pair<MemberFilter, T>,
92
- callback: (entity: Entity, id: Entity<T>) => void
88
+ callback: (entity: Entity, id: Id<T>) => void
93
89
  ): () => void;
94
90
  override(
95
- entity: Entity,
96
91
  action: "deleted",
92
+ entity: Entity,
97
93
  callback: (entity: Entity) => void
98
94
  ): () => void;
99
95
 
@@ -945,7 +945,6 @@ function masking_controller.update_entity_filter(
945
945
  if not lookup then
946
946
  lookup = masking.lookups.entities[entity]
947
947
  end
948
- local generator = generator :: MaskGenerator
949
948
  local current_storage = lookup.storage_group
950
949
 
951
950
  local new_storage = masking:move_entity_storage(entity, current_storage, generator.result)
@@ -1313,6 +1312,8 @@ function masking_controller.allocate_pair_value_removal(
1313
1312
  removed = {}
1314
1313
  changes.pairs_values.removed[relation] = removed
1315
1314
  end
1315
+ removed[target] = true
1316
+
1316
1317
  local values = changes.pairs_values.changed[relation]
1317
1318
  if values ~= nil then
1318
1319
  values[target] = nil
@@ -629,12 +629,10 @@ local function append_packet(
629
629
  member_packets.total_size += len
630
630
  else
631
631
  member_packets = {
632
- packets = {
633
- {
634
- buffer = output,
635
- variants = variants,
636
- },
637
- },
632
+ packets = { {
633
+ buffer = output,
634
+ variants = variants,
635
+ } },
638
636
  total_size = len,
639
637
  }
640
638
  packets[member] = member_packets :: MemberPackets
@@ -885,9 +883,11 @@ local function collect_updates(server: Server)
885
883
  end
886
884
  changed_mask = write_vlq_bitmask(c, total_tagged, changed_mask, 0)
887
885
 
888
- cursor.writeu8(c, changed_mask)
889
- write_entity_id(server, c, entity, variants)
890
- changed += 1
886
+ if changed_mask ~= 0 then
887
+ cursor.writeu8(c, changed_mask)
888
+ write_entity_id(server, c, entity, variants)
889
+ changed += 1
890
+ end
891
891
  end
892
892
  table.clear(storage_changes.changed)
893
893
  storage_mask = write_vlq_bitmask(c, changed, storage_mask, 2)
@@ -932,9 +932,11 @@ local function collect_updates(server: Server)
932
932
  end
933
933
  added_mask = write_vlq_bitmask(c, total_tags, added_mask, 0)
934
934
 
935
- cursor.writeu8(c, added_mask)
936
- write_entity_id(server, c, entity, variants)
937
- total_components_added += 1
935
+ if added_mask ~= 0 then
936
+ cursor.writeu8(c, added_mask)
937
+ write_entity_id(server, c, entity, variants)
938
+ total_components_added += 1
939
+ end
938
940
  end
939
941
  table.clear(storage_changes.added_components)
940
942
  storage_mask = write_vlq_bitmask(c, total_components_added, storage_mask, 1)
@@ -952,9 +954,11 @@ local function collect_updates(server: Server)
952
954
  table.clear(storage_changes.added)
953
955
  storage_mask = write_vlq_bitmask(c, total_added, storage_mask, 0)
954
956
 
955
- cursor.writeu8(c, storage_mask)
956
- local output = cursor.close(c)
957
- append_packet(packets, storage.mask.members, output, variants)
957
+ if storage_mask ~= 0 then
958
+ cursor.writeu8(c, storage_mask)
959
+ local output = cursor.close(c)
960
+ append_packet(packets, storage.mask.members, output, variants)
961
+ end
958
962
  end
959
963
  table.clear(server.additions)
960
964
  return create_packet_iterator(packets, PACKET_TYPES.reliable)
@@ -531,10 +531,14 @@ local function tobinary(n: number): string
531
531
  return string.rep("0", 8 - #result) .. result
532
532
  end
533
533
 
534
+ local BYTES = table.create(6)
535
+
534
536
  function bitmask.tostring(self: Bitmask): string
537
+ local buf = self.buffer
538
+
535
539
  local highest_entry = -1
536
540
  for i = self.entries - 1, 0, -1 do
537
- local value = bitmask.read(self, i)
541
+ local value = buffer.readu32(buf, i * BYTES_PER_ENTRY)
538
542
  if value ~= 0 then
539
543
  highest_entry = i
540
544
  break
@@ -545,12 +549,12 @@ function bitmask.tostring(self: Bitmask): string
545
549
  return ""
546
550
  end
547
551
 
548
- local str = ""
552
+ table.clear(BYTES)
549
553
  for i = 0, highest_entry do
550
- local value = bitmask.read(self, i)
551
- str ..= tobinary(value)
554
+ table.insert(BYTES, buffer.readu32(buf, i * BYTES_PER_ENTRY))
552
555
  end
553
- return str
556
+
557
+ return table.concat(BYTES, "-")
554
558
  end
555
559
 
556
560
  utils.bitmask = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/replecs",
3
- "version": "0.1.0-alpha9-test5",
3
+ "version": "0.1.0-alpha9",
4
4
  "description": "Replication library for Jecs",
5
5
  "main": "out/init.lua",
6
6
  "types": "out/index.d.ts",