Minor allocation optimization

This commit is contained in:
Anuken
2020-09-24 18:24:43 -04:00
parent 9e0b29b3dd
commit bc705aa7a0

View File

@@ -1,6 +1,5 @@
package mindustry.annotations.entity;
import arc.*;
import arc.files.*;
import arc.func.*;
import arc.struct.*;
@@ -520,7 +519,7 @@ public class EntityProcess extends BaseProcessor{
//add free code to remove methods - always at the end
//this only gets called next frame.
if(first.name().equals("remove") && ann.pooled()){
mbuilder.addStatement("$T.app.post(() -> $T.free(this))", Core.class, Pools.class);
mbuilder.addStatement("mindustry.gen.Groups.queueFree(($T)this)", Poolable.class);
}
builder.addMethod(mbuilder.build());
@@ -587,6 +586,17 @@ public class EntityProcess extends BaseProcessor{
//write clear
groupsBuilder.addMethod(groupClear.build());
//add method for pool storage
groupsBuilder.addField(FieldSpec.builder(ParameterizedTypeName.get(Seq.class, Poolable.class), "freeQueue", Modifier.PRIVATE, Modifier.STATIC).initializer("new Seq<>()").build());
//method for freeing things
MethodSpec.Builder groupFreeQueue = MethodSpec.methodBuilder("queueFree")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addParameter(Poolable.class, "obj")
.addStatement("freeQueue.add(obj)");
groupsBuilder.addMethod(groupFreeQueue.build());
//add method for resizing all necessary groups
MethodSpec.Builder groupResize = MethodSpec.methodBuilder("resize")
.addParameter(TypeName.FLOAT, "x").addParameter(TypeName.FLOAT, "y").addParameter(TypeName.FLOAT, "w").addParameter(TypeName.FLOAT, "h")
@@ -595,6 +605,11 @@ public class EntityProcess extends BaseProcessor{
MethodSpec.Builder groupUpdate = MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
//free everything pooled at the start of each updaet
groupUpdate
.addStatement("for($T p : freeQueue) $T.free(p)", Poolable.class, Pools.class)
.addStatement("freeQueue.clear()");
//method resize
for(GroupDefinition group : groupDefs){
if(group.spatial){