Skip to content

Commit

Permalink
improved tilemapper creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ImplementsLegend committed Dec 18, 2024
1 parent dec2968 commit 28c4a8b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package implementslegend.mod.vaultfaster.interfaces

import implementslegend.mod.vaultfaster.TileMapper
import java.util.concurrent.CompletableFuture

/*
* for flattening purposes
* */
interface TileMapperContainer {
val tileMapper: TileMapper
val futureTileMapper: CompletableFuture<TileMapper>
var hasTileMapperCreationStarted: Boolean
fun resetTileMapper()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;


/*
Expand All @@ -31,40 +33,90 @@ public class MixinPlacementSettings implements ExtendedPlacementSettings {
protected List<TileProcessor> tileProcessors;
private TileMapper mapper = new TileMapper();

CompletableFuture<TileMapper> futureTileMapper = new CompletableFuture();
private AtomicBoolean tileMapperCreationStarted = new AtomicBoolean();

@NotNull
@Override
public TileMapper getTileMapper() {
return mapper;
TileMapper privateMapper;
if(!tileMapperCreationStarted.getPlain() && tileMapperCreationStarted.compareAndSet(false,true)){
privateMapper=new TileMapper();
tileProcessors.forEach(processor -> {
privateMapper.addProcessor(processor);
});
futureTileMapper.complete(privateMapper);
}else {
try {
privateMapper=futureTileMapper.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}

return privateMapper;
}

@Override
public void resetTileMapper(){
if(getHasTileMapperCreationStarted()){
try {
futureTileMapper.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}

futureTileMapper=new CompletableFuture();
setHasTileMapperCreationStarted(false);
}
/*
var privateMapper = new TileMapper();
tileProcessors.forEach(processor -> {
privateMapper.addProcessor(processor);
});
mapper=privateMapper;
mapper=privateMapper;*/

}


@Inject(method = "addProcessor(Liskallia/vault/core/world/processor/Processor;)Liskallia/vault/core/world/template/PlacementSettings;",at = @At("HEAD"),remap = false)
private void registerProcessor(Processor processor, CallbackInfoReturnable<Palette> cir){
if(processor instanceof TileProcessor) mapper.addProcessor((TileProcessor) processor);
if(processor instanceof TileProcessor) resetTileMapper();//mapper.addProcessor((TileProcessor) processor);
}
@Inject(method = "copy",locals = LocalCapture.CAPTURE_FAILHARD,at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Liskallia/vault/core/world/template/PlacementSettings;flags:I"/*,target = "Liskallia/vault/core/world/template/PlacementSettings;<init>(Liskallia/vault/core/world/processor/ProcessorContext;)V"*/),remap = false)
private void copyMapper(CallbackInfoReturnable<PlacementSettings> cir, PlacementSettings nw){

if (getHasTileMapperCreationStarted()) {
((TileMapperContainer) nw).getFutureTileMapper().complete(getTileMapper());
((TileMapperContainer) nw).setHasTileMapperCreationStarted(true);
}
/*
var tileMapper = ((TileMapperContainer) nw).getTileMapper();
tileProcessors.forEach(processor -> {
tileMapper.addProcessor(processor);
});
});*/

}

@Override
public void addProcessorAtBegining(@NotNull TileProcessor tileProcessor) {
resetTileMapper();
tileProcessors.add(0,tileProcessor);
mapper.addProcessor( tileProcessor, true);
//mapper.addProcessor( tileProcessor, true);*
}

@NotNull
@Override
public CompletableFuture<TileMapper> getFutureTileMapper() {
return futureTileMapper;
}

@Override
public boolean getHasTileMapperCreationStarted() {
return tileMapperCreationStarted.getPlain() || tileMapperCreationStarted.get();
}

@Override
public void setHasTileMapperCreationStarted(boolean b) {
tileMapperCreationStarted.set(b);
}
}

0 comments on commit 28c4a8b

Please sign in to comment.