Skip to content

Commit 073fa06

Browse files
authored
Merge pull request #23 from LDGerrits/sin-the-developer-main
Improve types for both solvers
2 parents c53cb2e + a7e81a6 commit 073fa06

8 files changed

Lines changed: 56 additions & 57 deletions

File tree

src/Classes/Group.luau

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ end
8989
@return Group
9090
]=]
9191
function Group.fromTag(tag: string): Types.Group<Types.Entity>
92-
local group = Group.new({ autoClean = false }) :: Types.InternalGroup<Types.Entity>
92+
local group = Group.new({ autoClean = false, entities = nil }) :: Types.InternalGroup<Types.Entity>
9393
group.isManaged = true
9494

9595
local watchingInstances = {} :: { [Instance]: RBXScriptConnection }
@@ -166,7 +166,7 @@ end
166166
@return Group
167167
]=]
168168
function Group.players(): Types.Group<Player>
169-
local group = Group.new({ autoClean = false }) :: Types.InternalGroup<Player>
169+
local group = Group.new({ autoClean = false, entities = nil }) :: Types.InternalGroup<Player>
170170
group.isManaged = true
171171

172172
local conn = Players.PlayerAdded:Connect(function(player)
@@ -202,7 +202,7 @@ function Group.localPlayer(): Types.Group<Player>
202202
Log.fatal('Group.localPlayer() can only be called on the Client.', nil)
203203
end
204204

205-
local group = Group.new({ autoClean = false }) :: Types.InternalGroup<Player>
205+
local group = Group.new({ autoClean = false, entities = nil }) :: Types.InternalGroup<Player>
206206
group.isManaged = true
207207

208208
group:_add(Players.LocalPlayer)

src/Classes/Observer.luau

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ function Observer.observeGroup(
742742
return self:observe(function(_, zone, entity: any)
743743
local groups = State.entityToGroups[entity]
744744
if not groups then
745-
return
745+
return nil
746746
end
747747

748748
for groupId, _ in groups do
@@ -808,7 +808,7 @@ function Observer.onGroupEnter(
808808
return self:observe(function(_, zone, entity: any)
809809
local groups = State.entityToGroups[entity]
810810
if not groups then
811-
return
811+
return nil
812812
end
813813

814814
for groupId, _ in groups do
@@ -865,7 +865,7 @@ function Observer.onGroupExit(
865865
return self:observe(function(_, zone, entity: any)
866866
local groups = State.entityToGroups[entity]
867867
if not groups then
868-
return
868+
return nil
869869
end
870870

871871
for groupId, _ in groups do
@@ -1385,8 +1385,8 @@ end
13851385
@return () -> Zone?
13861386
]=]
13871387
function Observer.iterZones(self: Types.InternalObserver): () -> Types.Zone?
1388-
local zoneId = nil
1389-
local attachedList = nil
1388+
local zoneId: number?
1389+
local attachedList: { number }
13901390
local observerId = self.id
13911391

13921392
return function(): Types.Zone?
@@ -1397,11 +1397,11 @@ function Observer.iterZones(self: Types.InternalObserver): () -> Types.Zone?
13971397
return nil
13981398
end
13991399

1400-
if not table.find(attachedList, observerId) then
1400+
if not table.find(attachedList :: { number }, observerId) then
14011401
continue
14021402
end
14031403

1404-
local zone = State.zoneIdToZoneObj[zoneId]
1404+
local zone = State.zoneIdToZoneObj[zoneId :: number]
14051405
if zone then
14061406
return zone
14071407
end
@@ -1417,8 +1417,8 @@ end
14171417
@return () -> Group?
14181418
]=]
14191419
function Observer.iterGroups(self: Types.InternalObserver): () -> Types.Group?
1420-
local groupId = nil
1421-
local observersMap = nil
1420+
local groupId: number?
1421+
local observersMap: { [number]: boolean }
14221422
local observerId = self.id
14231423

14241424
return function(): Types.Group?
@@ -1433,7 +1433,7 @@ function Observer.iterGroups(self: Types.InternalObserver): () -> Types.Group?
14331433
continue
14341434
end
14351435

1436-
local group = State.groups[groupId]
1436+
local group = State.groups[groupId :: number]
14371437
if group then
14381438
return group
14391439
end
@@ -1450,18 +1450,18 @@ end
14501450
@return () -> (Entity?, Zone?)
14511451
]=]
14521452
function Observer.iterEntitiesInside(self: Types.InternalObserver): () -> (any?, Types.Zone?)
1453-
local entities = State.observerTrackingEntities[self.id]
1454-
local entity = nil
1453+
local entities = (State.observerTrackingEntities[self.id] or {}) :: { [Types.Entity]: boolean }
1454+
local entity: Types.Entity?
14551455
local observerId = self.id
14561456

14571457
return function()
14581458
while true do
1459-
entity = next(entities, entity)
1459+
entity = next(entities :: any, entity)
14601460
if not entity then
14611461
return nil
14621462
end
14631463

1464-
local data = State.entityData[entity]
1464+
local data = State.entityData[entity :: Types.Entity]
14651465
if not data then
14661466
continue
14671467
end
@@ -1471,7 +1471,7 @@ function Observer.iterEntitiesInside(self: Types.InternalObserver): () -> (any?,
14711471
continue
14721472
end
14731473

1474-
local ref = State.entityToReference[entity] or entity
1474+
local ref = State.entityToReference[entity :: Types.Entity] or entity
14751475
return ref, State.zoneIdToZoneObj[zoneId]
14761476
end
14771477
end
@@ -1486,18 +1486,18 @@ end
14861486
@return () -> (Player?, Zone?)
14871487
]=]
14881488
function Observer.iterPlayersInside(self: Types.InternalObserver): () -> (Player?, Types.Zone?)
1489-
local entities = State.observerTrackingEntities[self.id]
1490-
local entity = nil
1489+
local entities = (State.observerTrackingEntities[self.id] or {}) :: { [Types.Entity]: boolean }
1490+
local entity: Types.Entity?
14911491
local observerId = self.id
14921492

14931493
return function()
14941494
while true do
1495-
entity = next(entities, entity)
1495+
entity = next(entities :: any, entity)
14961496
if not entity then
1497-
return nil
1497+
return nil, nil
14981498
end
14991499

1500-
local data = State.entityData[entity]
1500+
local data = State.entityData[entity :: Types.Entity]
15011501
if not data then
15021502
continue
15031503
end
@@ -1507,7 +1507,7 @@ function Observer.iterPlayersInside(self: Types.InternalObserver): () -> (Player
15071507
continue
15081508
end
15091509

1510-
local ref = State.entityToReference[entity] or entity
1510+
local ref = State.entityToReference[entity :: Types.Entity] or entity
15111511
if typeof(ref) == 'Instance' and ref:IsA('Player') then
15121512
return ref, State.zoneIdToZoneObj[zoneId]
15131513
end
@@ -1532,24 +1532,24 @@ function Observer.iterEntitiesInZone(self: Types.InternalObserver, zone: Types.Z
15321532
end
15331533
end
15341534

1535-
local entity = nil
1535+
local entity: Types.Entity?
15361536
local targetZoneId = zone:getId()
15371537
local observerId = self.id
15381538

15391539
return function(): Types.Entity?
15401540
while true do
1541-
entity = next(entities, entity)
1541+
entity = next(entities :: any, entity)
15421542
if not entity then
15431543
return nil
15441544
end
15451545

1546-
local data = State.entityData[entity]
1546+
local data = State.entityData[entity :: Types.Entity]
15471547

15481548
if not data or data.activeObserverMemberships[observerId] ~= targetZoneId then
15491549
continue
15501550
end
15511551

1552-
return State.entityToReference[entity] or entity
1552+
return State.entityToReference[entity :: Types.Entity] or entity
15531553
end
15541554
end
15551555
end
@@ -1571,24 +1571,24 @@ function Observer.iterPlayersInZone(self: Types.InternalObserver, zone: Types.Zo
15711571
end
15721572
end
15731573

1574-
local entity = nil
1574+
local entity: Types.Entity?
15751575
local targetZoneId = zone:getId()
15761576
local observerId = self.id
15771577

15781578
return function(): Player?
15791579
while true do
1580-
entity = next(entities, entity)
1580+
entity = next(entities :: any, entity)
15811581
if not entity then
15821582
return nil
15831583
end
15841584

1585-
local data = State.entityData[entity]
1585+
local data = State.entityData[entity :: Types.Entity]
15861586

15871587
if not data or data.activeObserverMemberships[observerId] ~= targetZoneId then
15881588
continue
15891589
end
15901590

1591-
local ref = State.entityToReference[entity] or entity
1591+
local ref = State.entityToReference[entity :: Types.Entity] or entity
15921592
if typeof(ref) == 'Instance' and ref:IsA('Player') then
15931593
return ref
15941594
end

src/Classes/Zones.luau

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,16 @@ end
279279
@return () -> ((BasePart | Attachment | Bone)?, Zone?)
280280
]=]
281281
function Zones.iterReferences(self: Types.InternalZones): () -> ((BasePart | Attachment | Bone)?, Types.Zone?)
282-
local currentZone = nil
282+
local currentZone: Types.Zone?
283283

284284
return function()
285285
while true do
286286
currentZone = next(self.zones, currentZone)
287287
if not currentZone then
288-
return nil
288+
return nil, nil
289289
end
290290

291-
local ref = currentZone:getReference()
291+
local ref = (currentZone :: Types.Zone):getReference()
292292
if ref then
293293
return ref, currentZone
294294
end

src/Core/Scheduler.luau

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ local dynamicTree = State.dynamicTree
5050
local ctx_pos: Vector3
5151
local ctx_cCount: number = 0
5252
local ctx_highestWin: number
53-
local ctx_candidatePriority: { [number]: number } = table.create(16)
54-
local ctx_candidateIndex: { [number]: number } = table.create(16)
55-
local ctx_candidateList: { [number]: number } = table.create(16)
53+
local ctx_candidatePriority = table.create(16) :: { [number]: number }
54+
local ctx_candidateIndex = table.create(16) :: { [number]: number }
55+
local ctx_candidateList = table.create(16) :: { [number]: number }
5656
local ctx_linkedObservers: { [number]: boolean }
5757
local ctx_currentMemberships: { [number]: number }
5858

@@ -150,7 +150,7 @@ local function processProfileChange(entity: Types.Entity)
150150
if not buckets[maxRate] then
151151
buckets[maxRate] = {}
152152
table.insert(bucketList, maxRate)
153-
table.sort(bucketList, function(a, b)
153+
table.sort(bucketList, function(a: number, b: number)
154154
return a > b
155155
end)
156156
end
@@ -388,11 +388,10 @@ function Scheduler.update(dt: number)
388388
local needsDynamic = data.needsDynamic
389389

390390
local shouldCheck = false
391-
if data.logicVersion ~= logicVersion then
392-
shouldCheck = true
393-
elseif data.needsDynamic and data.dynamicVersion ~= dynamicVersion then
394-
shouldCheck = true
395-
elseif data.needsStatic and data.staticVersion ~= staticVersion then
391+
if data.logicVersion ~= logicVersion
392+
or (needsDynamic and data.dynamicVersion ~= dynamicVersion)
393+
or (needsStatic and data.staticVersion ~= staticVersion)
394+
then
396395
shouldCheck = true
397396
else
398397
local lastPosition = data.lastPosition

src/Utils/Geometry.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local MORTON_SHIFT8_MASK = 0xF00F00F
1313
local MORTON_SHIFT4_MASK = 0x30C30C3
1414
local MORTON_SHIFT2_MASK = 0x9249249
1515

16-
local expandLUT = table.create(1024)
16+
local expandLUT = table.create(1024) :: { number }
1717
for i = 0, 1023 do
1818
local value = i
1919
value = bit32.bor(bit32.lshift(value, 16), value)

src/Utils/LinearBVH.luau

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
local Geometry = require(script.Parent.Geometry)
66
local Types = require(script.Parent.Parent.Types)
77

8-
local HUGE_VECTOR = Vector3.one * math.huge
8+
local HUGE_VECTOR = vector.one * math.huge
99
local NEGATIVE_HUGE_VECTOR = -HUGE_VECTOR
1010

1111
local unionBounds = Geometry.unionBounds
@@ -160,7 +160,7 @@ function LinearBVH.build(tree: Types.Tree, cframes: { [number]: CFrame }, halfSi
160160
entry.mortonCode = positionToMortonCode(pos, sceneMin, scaleX, scaleY, scaleZ)
161161
end
162162

163-
table.sort(listCache, function(a, b)
163+
table.sort(listCache, function(a: ListEntity, b: ListEntity)
164164
return a.mortonCode < b.mortonCode
165165
end)
166166

src/Utils/Log.luau

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local function formatLog(messageTemplate: string, trace: string?, ...: any): str
1313
messageText ..= ` \n---- Stack trace ----\n{finalTrace}`
1414
end
1515

16-
return messageText:gsub('\n', '\n ')
16+
return (messageText:gsub('\n', '\n '))
1717
end
1818

1919
function Log.info(message: string, trace: string?, ...: any)
@@ -30,7 +30,7 @@ end
3030

3131
function Log.nonFatal(message: string, trace: string?, ...: any)
3232
local formattedString = formatLog(message, trace, ...)
33-
task.spawn(error, formattedString, 0)
33+
task.spawn(error :: any, formattedString, 0)
3434
end
3535

3636
return Log

src/init.luau

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ end
462462
@return () -> Group?
463463
]=]
464464
function QuickZone:iterGroups(): () -> Types.Group?
465-
local groupId = nil
465+
local groupId: number? = nil
466466
return function(): Types.Group?
467467
groupId = next(groups, groupId)
468468
return groupId and groups[groupId] or nil
@@ -477,7 +477,7 @@ end
477477
@return () -> Zone?
478478
]=]
479479
function QuickZone:iterZones(): () -> Types.Zone?
480-
local zoneId = nil
480+
local zoneId: number? = nil
481481

482482
return function(): Types.Zone?
483483
zoneId = next(zoneIdToZoneObj, zoneId)
@@ -493,7 +493,7 @@ end
493493
@return () -> any?
494494
]=]
495495
function QuickZone:iterEntities(): () -> any?
496-
local entity = nil
496+
local entity: Types.Entity? = nil
497497

498498
return function(): any?
499499
entity = next(entityData, entity)
@@ -512,7 +512,7 @@ end
512512
@return () -> Observer?
513513
]=]
514514
function QuickZone:iterObservers(): () -> Types.Observer<any>?
515-
local observerId = nil
515+
local observerId: number? = nil
516516

517517
return function(): Types.Observer<any>?
518518
observerId = next(observerIdToObserverObj, observerId)
@@ -538,7 +538,7 @@ function QuickZone:iterGroupsOfEntity(entity: any): () -> Types.Group?
538538
end
539539
end
540540

541-
local groupId = nil
541+
local groupId: number? = nil
542542
return function(): Types.Group?
543543
groupId = next(groupIds, groupId)
544544
return groupId and groups[groupId] or nil
@@ -564,8 +564,8 @@ function QuickZone:iterZonesOfEntity(entity: any): () -> Types.Zone?
564564
end
565565

566566
local memberships = data.activeObserverMemberships
567-
local seenZones = {}
568-
local observerId = nil
567+
local seenZones: { [number]: boolean } = {}
568+
local observerId: number?
569569

570570
return function(): Types.Zone?
571571
while true do
@@ -574,7 +574,7 @@ function QuickZone:iterZonesOfEntity(entity: any): () -> Types.Zone?
574574
return nil
575575
end
576576

577-
local zoneId = memberships[observerId]
577+
local zoneId = memberships[observerId :: number]
578578
if seenZones[zoneId] then
579579
continue
580580
end

0 commit comments

Comments
 (0)