@@ -19,6 +19,36 @@ public boolean isValid() {
1919 return this .nativeTable != null && this .nativeTable .address () != 0 ;
2020 }
2121
22+ public String str () {
23+ if (!this .isValid ()) {
24+ return "" ;
25+ }
26+ MemorySegment strPtr = flecs_h .ecs_table_str (this .world .nativeHandle (), this .nativeTable );
27+ if (strPtr == null || strPtr .address () == 0 ) {
28+ return "" ;
29+ }
30+ return strPtr .reinterpret (Long .MAX_VALUE ).getString (0 );
31+ }
32+
33+ public EcsLongList type () {
34+ if (!this .isValid ()) {
35+ return new EcsLongList ();
36+ }
37+ MemorySegment typePtr = flecs_h .ecs_table_get_type (this .nativeTable );
38+ if (typePtr == null || typePtr .address () == 0 ) {
39+ return new EcsLongList ();
40+ }
41+ MemorySegment arrayPtr = ecs_type_t .array (typePtr );
42+ int count = ecs_type_t .count (typePtr );
43+ if (arrayPtr == null || arrayPtr .address () == 0 || count == 0 ) {
44+ return new EcsLongList ();
45+ }
46+ EcsLongList ids = new EcsLongList (count );
47+ MemorySegment idsArray = arrayPtr .reinterpret ((long ) count * Long .BYTES );
48+ ids .addAll (idsArray .toArray (ValueLayout .JAVA_LONG ));
49+ return ids ;
50+ }
51+
2252 public int count () {
2353 if (!this .isValid ()) {
2454 return 0 ;
@@ -85,6 +115,50 @@ public long getColumnSize(int columnIndex) {
85115 return flecs_h .ecs_table_get_column_size (this .nativeTable , columnIndex );
86116 }
87117
118+ public MemorySegment getColumn (int columnIndex ) {
119+ if (!this .isValid ()) {
120+ return MemorySegment .NULL ;
121+ }
122+ return flecs_h .ecs_table_get_column (this .nativeTable , columnIndex , 0 );
123+ }
124+
125+ public MemorySegment getColumn (int columnIndex , int offset ) {
126+ if (!this .isValid ()) {
127+ return MemorySegment .NULL ;
128+ }
129+ return flecs_h .ecs_table_get_column (this .nativeTable , columnIndex , offset );
130+ }
131+
132+ public <T > T get (Class <T > componentClass , int row ) {
133+ int colIndex = this .columnIndex (componentClass );
134+ if (colIndex == -1 ) {
135+ throw new IllegalArgumentException ("Component " + componentClass .getSimpleName () + " not found in table" );
136+ }
137+ Component <T > component = this .world .componentRegistry ().getComponent (componentClass );
138+ MemorySegment columnPtr = this .getColumn (colIndex );
139+ if (columnPtr == null || columnPtr .address () == 0 ) {
140+ throw new IllegalStateException ("Failed to get column data" );
141+ }
142+ long elementOffset = (long ) row * component .size ();
143+ MemorySegment elementSegment = columnPtr .reinterpret (component .size () * this .count ()).asSlice (elementOffset , component .size ());
144+ return component .read (elementSegment );
145+ }
146+
147+ public <T > T tryGet (Class <T > componentClass , int row ) {
148+ int colIndex = this .columnIndex (componentClass );
149+ if (colIndex == -1 ) {
150+ return null ;
151+ }
152+ Component <T > component = this .world .componentRegistry ().getComponent (componentClass );
153+ MemorySegment columnPtr = this .getColumn (colIndex );
154+ if (columnPtr == null || columnPtr .address () == 0 ) {
155+ return null ;
156+ }
157+ long elementOffset = (long ) row * component .size ();
158+ MemorySegment elementSegment = columnPtr .reinterpret (component .size () * this .count ()).asSlice (elementOffset , component .size ());
159+ return component .read (elementSegment );
160+ }
161+
88162 public EcsLongList entities () {
89163 if (!this .isValid ()) {
90164 return new EcsLongList ();
0 commit comments