mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fix command and sync parallax
This commit is contained in:
parent
c6aad25ef2
commit
18e203f007
@ -11,6 +11,9 @@ public class CommandIris extends MortarCommand
|
|||||||
@Command
|
@Command
|
||||||
private CommandIrisCreate create;
|
private CommandIrisCreate create;
|
||||||
|
|
||||||
|
@Command
|
||||||
|
private CommandIrisFix fix;
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
private CommandIrisStudio studio;
|
private CommandIrisStudio studio;
|
||||||
|
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.volmit.iris.manager.command;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.scaffold.IrisWorlds;
|
||||||
|
import com.volmit.iris.scaffold.engine.IrisAccess;
|
||||||
|
import com.volmit.iris.util.*;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
public class CommandIrisFix extends MortarCommand
|
||||||
|
{
|
||||||
|
public CommandIrisFix()
|
||||||
|
{
|
||||||
|
super("fix");
|
||||||
|
requiresPermission(Iris.perm.studio);
|
||||||
|
setDescription("Fix nearby chunks");
|
||||||
|
setCategory("Studio");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handle(MortarSender sender, String[] args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IrisAccess a = IrisWorlds.access(sender.player().getWorld());
|
||||||
|
if(a.getCompound().getSize() > 1)
|
||||||
|
{
|
||||||
|
sender.sendMessage("Cant fix engine composite worlds!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int viewDistance = args.length > 0 ? Integer.valueOf(args[0]) : -1;
|
||||||
|
if(viewDistance <=1)
|
||||||
|
{
|
||||||
|
J.a(() -> {
|
||||||
|
int fixed = a.getCompound().getDefaultEngine().getFramework().getEngineParallax().repairChunk(sender.player().getLocation().getChunk());
|
||||||
|
sender.sendMessage("Fixed " + Form.f(fixed) + " blocks!");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AtomicInteger v = new AtomicInteger();
|
||||||
|
J.a(() -> {
|
||||||
|
new Spiraler(viewDistance, viewDistance, (x,z) -> v.set(v.get() + a.getCompound().getDefaultEngine().getFramework().getEngineParallax().repairChunk(sender.player().getWorld().getChunkAt(x, z)))).drain();
|
||||||
|
sender.sendMessage("Fixed " + Form.f(v.get()) + " blocks in " + (viewDistance * viewDistance) + " chunks!");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
sender.sendMessage("Not a valid Iris World (or bad argument)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getArgsUsage()
|
||||||
|
{
|
||||||
|
return "[view-distance]";
|
||||||
|
}
|
||||||
|
}
|
@ -12,9 +12,6 @@ public class CommandIrisStudio extends MortarCommand
|
|||||||
@Command
|
@Command
|
||||||
private CommandIrisStudioCreate create;
|
private CommandIrisStudioCreate create;
|
||||||
|
|
||||||
@Command
|
|
||||||
private CommandIrisStudioFix fix;
|
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
private CommandIrisStudioOpen open;
|
private CommandIrisStudioOpen open;
|
||||||
|
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
package com.volmit.iris.manager.command;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.IrisSettings;
|
|
||||||
import com.volmit.iris.scaffold.hunk.Hunk;
|
|
||||||
import com.volmit.iris.util.KList;
|
|
||||||
import com.volmit.iris.util.MortarCommand;
|
|
||||||
import com.volmit.iris.util.MortarSender;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
|
|
||||||
public class CommandIrisStudioFix extends MortarCommand
|
|
||||||
{
|
|
||||||
public CommandIrisStudioFix()
|
|
||||||
{
|
|
||||||
super("fix");
|
|
||||||
requiresPermission(Iris.perm.studio);
|
|
||||||
setDescription("Go to the spawn of the currently open studio world.");
|
|
||||||
setCategory("Studio");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(MortarSender sender, String[] args)
|
|
||||||
{
|
|
||||||
if(!IrisSettings.get().isStudio())
|
|
||||||
{
|
|
||||||
sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Iris.proj.isProjectOpen())
|
|
||||||
{
|
|
||||||
sender.sendMessage("There is not a studio currently loaded.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Chunk c = sender.player().getLocation().getChunk();
|
|
||||||
int cx = c.getX() * 16;
|
|
||||||
int cz = c.getZ() * 16;
|
|
||||||
Hunk<BlockData> bd = Hunk.viewBlocks(c);
|
|
||||||
Iris.proj.getActiveProject().getActiveProvider().getCompound().getDefaultEngine().getFramework().getEngineParallax().insertParallax(cx, cz, bd);
|
|
||||||
sender.sendMessage("Done!");
|
|
||||||
}
|
|
||||||
|
|
||||||
catch(Throwable e)
|
|
||||||
{
|
|
||||||
sender.sendMessage("Failed to teleport to the studio world. Try re-opening the project.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getArgsUsage()
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,6 +12,8 @@ import com.volmit.iris.scaffold.parallax.ParallaxChunkMeta;
|
|||||||
import com.volmit.iris.scaffold.parallel.BurstExecutor;
|
import com.volmit.iris.scaffold.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.*;
|
import com.volmit.iris.util.*;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.ChunkSnapshot;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
import org.bukkit.util.Consumer;
|
import org.bukkit.util.Consumer;
|
||||||
@ -72,6 +74,51 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies the chunk correctly has all the parallax objects it should.
|
||||||
|
* This method should not have to be written but why not.
|
||||||
|
* Thread Safe, Designed to run async
|
||||||
|
* @param c the bukkit chunk
|
||||||
|
*/
|
||||||
|
default int repairChunk(Chunk c)
|
||||||
|
{
|
||||||
|
ParallaxChunkMeta m = getParallaxAccess().getMetaR(c.getX(), c.getZ());
|
||||||
|
Hunk<String> o = getParallaxAccess().getObjectsR(c.getX(), c.getZ());
|
||||||
|
Hunk<BlockData> b = getParallaxAccess().getBlocksR(c.getX(), c.getZ());
|
||||||
|
ChunkSnapshot snapshot = c.getChunkSnapshot(false, false, false);
|
||||||
|
KList<Runnable> queue = new KList<>();
|
||||||
|
|
||||||
|
o.iterateSync((x,y,z,s) -> {
|
||||||
|
if(s != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
BlockData bd = b.get(x,y,z);
|
||||||
|
if(bd != null)
|
||||||
|
{
|
||||||
|
BlockData bdx = snapshot.getBlockData(x,y,z);
|
||||||
|
|
||||||
|
if(!bdx.getMaterial().equals(bd.getMaterial()))
|
||||||
|
{
|
||||||
|
queue.add(() -> c.getBlock(x,y,z).setBlockData(bd, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AtomicBoolean bx = new AtomicBoolean(false);
|
||||||
|
J.s(() -> {
|
||||||
|
queue.forEach(Runnable::run);
|
||||||
|
bx.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
while(!bx.get())
|
||||||
|
{
|
||||||
|
J.sleep(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
return queue.size();
|
||||||
|
}
|
||||||
|
|
||||||
default void insertParallax(int x, int z, Hunk<BlockData> data) {
|
default void insertParallax(int x, int z, Hunk<BlockData> data) {
|
||||||
try {
|
try {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
@ -113,7 +160,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default void generateParallaxAreaFeatures(int x, int z, BurstExecutor b) {
|
default void generateParallaxAreaFeatures(int x, int z) {
|
||||||
try {
|
try {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
int s = (int) Math.ceil(getParallaxSize() / 2D);
|
int s = (int) Math.ceil(getParallaxSize() / 2D);
|
||||||
@ -133,13 +180,12 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
|||||||
RNG rng = new RNG(Cache.key(xx, zz)).nextParallelRNG(getEngine().getTarget().getWorld().getSeed());
|
RNG rng = new RNG(Cache.key(xx, zz)).nextParallelRNG(getEngine().getTarget().getWorld().getSeed());
|
||||||
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
|
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
|
||||||
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
|
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
|
||||||
b.queue(() -> generateParallaxFeatures(rng, xx, zz, region, biome));
|
generateParallaxFeatures(rng, xx, zz, region, biome);
|
||||||
getParallaxAccess().setFeatureGenerated(xx, zz);
|
getParallaxAccess().setFeatureGenerated(xx, zz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.complete();
|
|
||||||
p.end();
|
p.end();
|
||||||
getEngine().getMetrics().getParallax().put(p.getMilliseconds());
|
getEngine().getMetrics().getParallax().put(p.getMilliseconds());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -189,9 +235,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
|||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
int s = (int) Math.ceil(getParallaxSize() / 2D);
|
int s = (int) Math.ceil(getParallaxSize() / 2D);
|
||||||
int i,j;
|
int i,j;
|
||||||
BurstExecutor b = MultiBurst.burst.burst(((s * 2) * (s * 2)));
|
generateParallaxAreaFeatures(x, z);
|
||||||
BurstExecutor b2 = MultiBurst.burst.burst(((s * 2) * (s * 2)));
|
|
||||||
generateParallaxAreaFeatures(x, z, b2);
|
|
||||||
|
|
||||||
for(i = -s; i <= s; i++)
|
for(i = -s; i <= s; i++)
|
||||||
{
|
{
|
||||||
@ -199,12 +243,10 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
|||||||
for(j = -s; j <= s; j++)
|
for(j = -s; j <= s; j++)
|
||||||
{
|
{
|
||||||
int jj = j;
|
int jj = j;
|
||||||
b.queue(() -> generateParallaxLayer((ii*16)+x, (jj*16)+z));
|
generateParallaxLayer((ii*16)+x, (jj*16)+z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b2.complete();
|
|
||||||
b.complete();
|
|
||||||
getParallaxAccess().setChunkGenerated(x>>4, z>>4);
|
getParallaxAccess().setChunkGenerated(x>>4, z>>4);
|
||||||
p.end();
|
p.end();
|
||||||
getEngine().getMetrics().getParallax().put(p.getMilliseconds());
|
getEngine().getMetrics().getParallax().put(p.getMilliseconds());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user