Skip to content

Commit 991fa63

Browse files
committed
remove autocloseable of system
1 parent 9875c66 commit 991fa63

4 files changed

Lines changed: 8 additions & 46 deletions

File tree

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,6 @@ public static void main(String[] args) {
149149
System.out.println("\nRunning one frame to show phase order:");
150150
world.progress(0.016f);
151151

152-
// Clean up
153-
oneSecondSystem.close();
154-
everyOtherFrame.close();
155-
mtMoveSystem.close();
156-
immediateSystem.close();
157-
preUpdateSys.close();
158-
onUpdateSys.close();
159-
postUpdateSys.close();
160-
161152
System.out.println("\n=== Advanced Systems Example Complete ===");
162153
}
163154
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ public static void main(String[] args) {
117117
});
118118
}
119119

120-
// Clean up systems
121-
moveSystem.close();
122-
debugSystem.close();
123-
taskSystem.close();
124-
125120
System.out.println("\n=== Systems Example Complete ===");
126121
}
127122
}

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,44 @@
55
import java.lang.foreign.Arena;
66
import java.lang.foreign.MemorySegment;
77

8-
public class FlecsSystem implements AutoCloseable {
8+
public class FlecsSystem {
99

1010
private final World world;
1111
private final long entityId;
1212
private final Entity entity;
13-
private final Arena arena;
14-
private boolean closed = false;
1513

1614
FlecsSystem(World world, long entityId) {
1715
this.world = world;
1816
this.entityId = entityId;
1917
this.entity = world.obtainEntity(entityId);
20-
this.arena = Arena.ofConfined();
2118
}
2219

2320
public void run() {
24-
this.checkClosed();
2521
flecs_h.ecs_run(this.world.nativeHandle(), this.entityId, 0.0f, MemorySegment.NULL);
2622
}
2723

2824
public void run(float deltaTime) {
29-
this.checkClosed();
3025
flecs_h.ecs_run(this.world.nativeHandle(), this.entityId, deltaTime, MemorySegment.NULL);
3126
}
3227

3328
public long id() {
34-
this.checkClosed();
3529
return this.entityId;
3630
}
3731

3832
public Entity entity() {
39-
this.checkClosed();
4033
return this.entity;
4134
}
4235

4336
public void enable() {
44-
this.checkClosed();
4537
this.entity.remove(FlecsConstants.EcsDisabled);
4638
}
4739

4840
public void disable() {
49-
this.checkClosed();
5041
this.entity.add(FlecsConstants.EcsDisabled);
5142
}
5243

5344
public boolean isEnabled() {
54-
this.checkClosed();
5545
return !this.entity.has(FlecsConstants.EcsDisabled);
5646
}
57-
58-
private void checkClosed() {
59-
if (this.closed) {
60-
throw new IllegalStateException("System has been closed");
61-
}
62-
}
63-
64-
@Override
65-
public void close() {
66-
if (!this.closed) {
67-
this.arena.close();
68-
this.closed = true;
69-
}
70-
}
7147
}
7248

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
public class SystemBuilder {
1010

1111
private final World world;
12-
private final Arena arena;
1312
private final MemorySegment desc;
13+
private final Arena arena;
1414
private int termCount = 0;
1515
private static final long TERM_SIZE = ecs_term_t.layout().byteSize();
1616
private Query.IterCallback iterCallback;
@@ -27,12 +27,10 @@ public SystemBuilder(World world) {
2727
public SystemBuilder(World world, String name) {
2828
this(world);
2929
MemorySegment nameSegment = this.arena.allocateFrom(name);
30-
31-
try (Arena tempArena = Arena.ofConfined()) {
32-
MemorySegment entityDescTemp = ecs_entity_desc_t.allocate(tempArena);
33-
ecs_entity_desc_t.name(entityDescTemp, nameSegment);
34-
ecs_system_desc_t.entity(this.desc, flecs_h.ecs_entity_init(world.nativeHandle(), entityDescTemp));
35-
}
30+
31+
MemorySegment entityDescTemp = ecs_entity_desc_t.allocate(this.arena);
32+
ecs_entity_desc_t.name(entityDescTemp, nameSegment);
33+
ecs_system_desc_t.entity(this.desc, flecs_h.ecs_entity_init(world.nativeHandle(), entityDescTemp));
3634
}
3735

3836
public SystemBuilder kind(long phase) {
@@ -243,6 +241,8 @@ private FlecsSystem build() {
243241

244242
this.world.registerSystemCallbacks(systemId, this.iterCallback, this.runCallback, this.entityCallback);
245243

244+
this.arena.close();
245+
246246
return new FlecsSystem(this.world, systemId);
247247
}
248248
}

0 commit comments

Comments
 (0)