Skip to content

Commit ccb8c70

Browse files
committed
replace string ptr by byte arrays (new annotation FixedString)
1 parent 24c9068 commit ccb8c70

18 files changed

Lines changed: 133 additions & 62 deletions

File tree

examples/src/main/java/com/github/elebras1/flecs/examples/AdvancedSystemExample.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.elebras1.flecs.*;
44
import com.github.elebras1.flecs.examples.components.*;
5+
import com.github.elebras1.flecs.util.FlecsConstants;
56

67
import java.lang.System;
78

@@ -45,7 +46,7 @@ public static void main(String[] args) {
4546
FlecsSystem everyOtherFrame = world.system("EveryOtherFrame")
4647
.with(posId)
4748
.rate(2)
48-
.kind(FlecsConstants.EcsOnUpdate)
49+
.kind(com.github.elebras1.flecs.util.FlecsConstants.EcsOnUpdate)
4950
.iter(it -> {
5051
System.out.println(" [Rate Filter] Running every 2nd frame (matched: " + it.count() + " entities)");
5152
});
@@ -60,7 +61,7 @@ public static void main(String[] args) {
6061
FlecsSystem mtMoveSystem = world.system("MultiThreadedMove")
6162
.with(posId)
6263
.with(velId)
63-
.kind(FlecsConstants.EcsOnUpdate)
64+
.kind(com.github.elebras1.flecs.util.FlecsConstants.EcsOnUpdate)
6465
.multiThreaded(true)
6566
.iter(it -> {
6667
Field<Position> positions = it.field(Position.class, 0);
@@ -80,7 +81,7 @@ public static void main(String[] args) {
8081

8182
// Create an immediate system that can see operations immediately
8283
FlecsSystem immediateSystem = world.system("ImmediateSystem")
83-
.kind(FlecsConstants.EcsPreUpdate)
84+
.kind(com.github.elebras1.flecs.util.FlecsConstants.EcsPreUpdate)
8485
.immediate(true)
8586
.run(it -> {
8687
System.out.println(" [Immediate] Running in non-readonly mode");
@@ -112,7 +113,7 @@ public static void main(String[] args) {
112113

113114
// Pause the timer
114115
System.out.println("Stopping one-second timer...");
115-
timerOneSecond.add(FlecsConstants.EcsDisabled);
116+
timerOneSecond.add(com.github.elebras1.flecs.util.FlecsConstants.EcsDisabled);
116117

117118
System.out.println("Running 3 more frames with timer stopped:");
118119
for (int frame = 0; frame < 3; frame++) {
@@ -122,7 +123,7 @@ public static void main(String[] args) {
122123

123124
// Resume the timer
124125
System.out.println("\nRestarting one-second timer...");
125-
timerOneSecond.remove(FlecsConstants.EcsDisabled);
126+
timerOneSecond.remove(com.github.elebras1.flecs.util.FlecsConstants.EcsDisabled);
126127

127128
System.out.println("Running 3 more frames with timer restarted:");
128129
for (int frame = 0; frame < 3; frame++) {
@@ -134,11 +135,11 @@ public static void main(String[] args) {
134135

135136
// Create systems in different phases
136137
FlecsSystem preUpdateSys = world.system("PreUpdatePhase")
137-
.kind(FlecsConstants.EcsPreUpdate)
138+
.kind(com.github.elebras1.flecs.util.FlecsConstants.EcsPreUpdate)
138139
.run(it -> System.out.println(" [PreUpdate] Running"));
139140

140141
FlecsSystem onUpdateSys = world.system("OnUpdatePhase")
141-
.kind(FlecsConstants.EcsOnUpdate)
142+
.kind(com.github.elebras1.flecs.util.FlecsConstants.EcsOnUpdate)
142143
.run(it -> System.out.println(" [OnUpdate] Running"));
143144

144145
FlecsSystem postUpdateSys = world.system("PostUpdatePhase")

examples/src/main/java/com/github/elebras1/flecs/examples/ObserverExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.github.elebras1.flecs.examples.components.Position;
77
import com.github.elebras1.flecs.examples.components.Velocity;
88

9-
import static com.github.elebras1.flecs.FlecsConstants.*;
9+
import static com.github.elebras1.flecs.util.FlecsConstants.*;
1010

1111
public class ObserverExample {
1212

examples/src/main/java/com/github/elebras1/flecs/examples/SystemExample.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.elebras1.flecs.*;
44
import com.github.elebras1.flecs.examples.components.*;
5+
import com.github.elebras1.flecs.util.FlecsConstants;
56

67
import java.lang.System;
78

@@ -31,7 +32,7 @@ public static void main(String[] args) {
3132
FlecsSystem moveSystem = world.system("MoveSystem")
3233
.with(Position.class)
3334
.with(Velocity.class)
34-
.kind(FlecsConstants.EcsOnUpdate)
35+
.kind(com.github.elebras1.flecs.util.FlecsConstants.EcsOnUpdate)
3536
.iter(it -> {
3637
System.out.println("MoveSystem running (delta_time: " + it.deltaTime() + "s)");
3738

@@ -55,7 +56,7 @@ public static void main(String[] args) {
5556
// Create a debug system using the each pattern
5657
FlecsSystem debugSystem = world.system("DebugSystem")
5758
.with(posId)
58-
.kind(FlecsConstants.EcsPostUpdate)
59+
.kind(com.github.elebras1.flecs.util.FlecsConstants.EcsPostUpdate)
5960
.each(entityId -> {
6061
Entity entity = world.obtainEntity(entityId);
6162
Position pos = entity.get(Position.class);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.github.elebras1.flecs.examples.components;
22

33
import com.github.elebras1.flecs.annotation.Component;
4+
import com.github.elebras1.flecs.annotation.FixedString;
45

56
@Component
6-
public record Minister(String name, String imageFileName, float loyalty, int startDate, int deathDate) {
7+
public record Minister(String name, @FixedString(size = 128) String imageFileName, float loyalty, int startDate, int deathDate) {
78
}

src/main/java/com/github/elebras1/flecs/Component.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.github.elebras1.flecs;
22

3-
import java.lang.foreign.Arena;
43
import java.lang.foreign.MemoryLayout;
54
import java.lang.foreign.MemorySegment;
65

76
public interface Component<T> {
87

98
MemoryLayout layout();
109

11-
void write(MemorySegment segment, T data, Arena arena);
10+
void write(MemorySegment segment, T data);
1211

1312
T read(MemorySegment segment);
1413

src/main/java/com/github/elebras1/flecs/ComponentHooks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private void writeComponentArray(MemorySegment ptr, T[] components, int count) {
263263
for (int i = 0; i < count; i++) {
264264
if (components[i] != null) {
265265
MemorySegment componentSegment = buffer.asSlice(i * size, size);
266-
this.component.write(componentSegment, components[i], this.world.arena());
266+
this.component.write(componentSegment, components[i]);
267267
}
268268
}
269269
}

src/main/java/com/github/elebras1/flecs/Entity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.elebras1.flecs;
22

3+
import com.github.elebras1.flecs.util.FlecsConstants;
4+
35
import java.lang.foreign.Arena;
46
import java.lang.foreign.MemorySegment;
57
import java.lang.foreign.ValueLayout;
@@ -115,7 +117,7 @@ public <T> Entity set(T data) {
115117
Component<T> component = this.world.componentRegistry().getComponent(componentClass);
116118

117119
MemorySegment dataSegment = this.world.getComponentBuffer(component.size());
118-
component.write(dataSegment, data, this.world.arena());
120+
component.write(dataSegment, data);
119121
flecs_h.ecs_set_id(this.world.nativeHandle(), this.id, componentId, component.size(), dataSegment);
120122

121123
return this;
@@ -130,7 +132,7 @@ public <T> Entity set(long relation, T data) {
130132

131133
Component<T> component = this.world.componentRegistry().getComponent(componentClass);
132134
MemorySegment dataSegment = this.world.getComponentBuffer(component.size());
133-
component.write(dataSegment, data, this.world.arena());
135+
component.write(dataSegment, data);
134136

135137
flecs_h.ecs_set_id(this.world.nativeHandle(), this.id, pairId, component.size(), dataSegment);
136138

src/main/java/com/github/elebras1/flecs/Field.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void set(int i, T componentData) {
4848
long elementOffset = i * this.component.size();
4949
MemorySegment elementSegment = this.memorySegment.asSlice(elementOffset, this.component.size());
5050

51-
this.component.write(elementSegment, componentData, tempArena);
51+
this.component.write(elementSegment, componentData);
5252
}
5353
}
5454
}

src/main/java/com/github/elebras1/flecs/FlecsSystem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.elebras1.flecs;
22

3+
import com.github.elebras1.flecs.util.FlecsConstants;
4+
35
import java.lang.foreign.Arena;
46
import java.lang.foreign.MemorySegment;
57

src/main/java/com/github/elebras1/flecs/ObserverBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.lang.foreign.MemorySegment;
55
import java.lang.foreign.ValueLayout;
66

7-
import static com.github.elebras1.flecs.FlecsConstants.*;
7+
import static com.github.elebras1.flecs.util.FlecsConstants.*;
88

99
public class ObserverBuilder {
1010

0 commit comments

Comments
 (0)