@@ -640,8 +640,8 @@ export type Query = typeof(EmptyQuery)
640
640
641
641
type CompatibleArchetype = { archetype : Archetype , indices : { number } }
642
642
643
- local function PreparedQuery (
644
- compatibleArchetypes : { Archetype } , components : { i53 }, indices : { [ number ]: number })
643
+ local function preparedQuery ( compatibleArchetypes : { Archetype },
644
+ components : { i53 ? }, indices : { { number } })
645
645
646
646
local queryLength = # components
647
647
@@ -652,7 +652,6 @@ local function PreparedQuery(
652
652
return EmptyQuery
653
653
end
654
654
655
-
656
655
local queryOutput = {}
657
656
658
657
local i = 1
@@ -746,48 +745,47 @@ local function PreparedQuery(
746
745
end
747
746
end
748
747
749
- lastArchetype , archetype = next (compatibleArchetypes )
750
- if not lastArchetype then
751
- return EmptyQuery
752
- end
753
-
754
748
return self
755
749
end
756
750
757
- local preparedQuery = {
751
+ local query = {
758
752
__iter = function ()
753
+ i = 1
754
+ lastArchetype = 1
755
+ archetype = compatibleArchetypes [1 ]
756
+
759
757
return queryNext
760
758
end ,
761
759
next = queryNext ,
762
760
without = without
763
761
}
764
762
765
- return ( setmetatable (preparedQuery , preparedQuery ) :: any ) :: Query
763
+ return setmetatable (query , query ) :: any
766
764
end
767
765
768
- function World .query (world : World , ... : any ): Query
766
+ function World .query (world : World , ... : number ? ): Query
769
767
-- breaking?
770
768
if (... ) == nil then
771
769
error ("Missing components" )
772
770
end
773
771
774
- local columns = {}
775
- local compatibleArchetypes : { CompatibleArchetype } = {}
772
+ local indices : { { number } } = {}
773
+ local compatibleArchetypes : { Archetype } = {}
776
774
local length = 0
777
775
778
- local components = { ... } :: any
779
- local archetypes = world .archetypes
776
+ local components : { number ? } = { ... }
777
+ local archetypes : { Archetype } = world .archetypes :: any
780
778
781
779
local firstArchetypeMap : ArchetypeMap
782
780
local componentIndex = world .componentIndex
783
781
784
782
for _ , componentId in components do
785
- local map = componentIndex [componentId ]
783
+ local map : ArchetypeMap = componentIndex [componentId ] :: any
786
784
if not map then
787
785
return EmptyQuery
788
786
end
789
787
790
- if firstArchetypeMap == nil or map .size < firstArchetypeMap .size then
788
+ if ( firstArchetypeMap :: any ) == nil or firstArchetypeMap .size < map .size then
791
789
firstArchetypeMap = map
792
790
end
793
791
end
@@ -796,7 +794,7 @@ function World.query(world: World, ...: any): Query
796
794
local archetype = archetypes [id ]
797
795
local archetypeRecords = archetype .records
798
796
799
- local records = {}
797
+ local records : { number } = {}
800
798
local skip = false
801
799
802
800
for i , componentId in components do
@@ -815,25 +813,27 @@ function World.query(world: World, ...: any): Query
815
813
816
814
length += 1
817
815
compatibleArchetypes [length ] = archetype
818
- columns [length ] = records
816
+ indices [length ] = records
819
817
end
820
818
821
- return PreparedQuery (compatibleArchetypes , components , columns )
819
+ return preparedQuery (compatibleArchetypes , components , indices )
822
820
end
823
821
824
822
type WorldIterator = (() -> (i53 , { [unknown ]: unknown ? })) & (() -> ()) & (() -> i53 )
825
823
826
824
function World .__iter (world : World ): WorldIterator
827
- local dense = world .entityIndex .dense
828
- local sparse = world .entityIndex .sparse
825
+ local entityIndex = world .entityIndex
826
+ local dense = entityIndex .dense
827
+ local sparse = entityIndex .sparse
829
828
local last
830
829
831
830
-- new solver doesnt like the world iterator type even tho its correct
832
831
-- so any cast here i come
832
+ local i = 0
833
833
local function iterator ()
834
- local lastEntity : number ? , entityId : number = next ( dense , last )
835
- if not lastEntity then
836
- -- ignore type error
834
+ i += 1
835
+ local entityId = dense [ i ]
836
+ if not entityId then
837
837
return
838
838
end
839
839
0 commit comments