mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Mapping
This commit is contained in:
parent
31bd6a0c0d
commit
a1d6431348
@ -23,9 +23,12 @@ import javax.swing.JLayeredPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JViewport;
|
||||
|
||||
import com.volmit.iris.gen.IrisChunkGenerator;
|
||||
import com.volmit.iris.noise.CNG;
|
||||
import com.volmit.iris.object.NoiseStyle;
|
||||
import com.volmit.iris.util.Function2;
|
||||
import com.volmit.iris.util.GroupedExecutor;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.M;
|
||||
import com.volmit.iris.util.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.RNG;
|
||||
@ -35,8 +38,8 @@ public class NoiseView extends JPanel implements MouseWheelListener {
|
||||
|
||||
private static final long serialVersionUID = 2094606939770332040L;
|
||||
|
||||
static JComboBox<NoiseStyle> combo;
|
||||
RollingSequence r = new RollingSequence(60);
|
||||
static JComboBox<String> combo;
|
||||
RollingSequence r = new RollingSequence(20);
|
||||
boolean colorMode = true;
|
||||
double scale = 1;
|
||||
static boolean hd = false;
|
||||
@ -48,6 +51,7 @@ public class NoiseView extends JPanel implements MouseWheelListener {
|
||||
int[][] co;
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
static Function2<Double, Double, Color> renderer;
|
||||
double oxp = 0;
|
||||
double ozp = 0;
|
||||
double ox = 0;
|
||||
@ -131,7 +135,9 @@ public class NoiseView extends JPanel implements MouseWheelListener {
|
||||
}
|
||||
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
int accuracy = hd ? 1 : M.clip((r.getAverage() / 13D) + 1, 1D, 128D).intValue();
|
||||
int accuracy = hd ? 1 : M.clip((r.getAverage() / 8D) + 1, 1D, 128D).intValue();
|
||||
accuracy = down ? accuracy * 4 : accuracy;
|
||||
int v = 150;
|
||||
|
||||
if (g instanceof Graphics2D) {
|
||||
Graphics2D gg = (Graphics2D) g;
|
||||
@ -148,25 +154,44 @@ public class NoiseView extends JPanel implements MouseWheelListener {
|
||||
|
||||
for (int x = 0; x < getParent().getWidth(); x += accuracy) {
|
||||
int xx = x;
|
||||
gx.queue("a", () -> {
|
||||
for (int z = 0; z < getParent().getHeight(); z += accuracy) {
|
||||
double n = cng.noise((xx * ascale) + oxp, tz, (z * ascale) + ozp);
|
||||
|
||||
if (n > 1 || n < 0) {
|
||||
System.out.println("EXCEEDED " + n);
|
||||
break;
|
||||
for (int z = 0; z < getParent().getHeight(); z += accuracy) {
|
||||
int zz = z;
|
||||
gx.queue("a", () -> {
|
||||
if (renderer != null) {
|
||||
co[xx][zz] = renderer.apply((xx * ascale) + oxp, (zz * ascale) + ozp).getRGB();
|
||||
}
|
||||
|
||||
Color color = colorMode
|
||||
? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), 1f - (float) n)
|
||||
: Color.getHSBColor(0f, 0f, (float) n);
|
||||
int rgb = color.getRGB();
|
||||
co[xx][z] = rgb;
|
||||
}
|
||||
});
|
||||
else {
|
||||
double n = cng.noise((xx * ascale) + oxp, tz, (zz * ascale) + ozp);
|
||||
|
||||
if (n > 1 || n < 0) {
|
||||
System.out.println("EXCEEDED " + n);
|
||||
return;
|
||||
}
|
||||
|
||||
Color color = colorMode
|
||||
? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n),
|
||||
1f - (float) n)
|
||||
: Color.getHSBColor(0f, 0f, (float) n);
|
||||
int rgb = color.getRGB();
|
||||
co[xx][zz] = rgb;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
gx.waitFor("a");
|
||||
|
||||
if (p.getMilliseconds() > v) {
|
||||
v += 50;
|
||||
accuracy++;
|
||||
}
|
||||
}
|
||||
|
||||
gx.waitFor("a");
|
||||
if (down && renderer != null) {
|
||||
Iris.proj.getCurrentProject().getCache().targetChunk(0, 0);
|
||||
}
|
||||
|
||||
for (int x = 0; x < getParent().getWidth(); x += accuracy) {
|
||||
for (int z = 0; z < getParent().getHeight(); z += accuracy) {
|
||||
@ -180,22 +205,46 @@ public class NoiseView extends JPanel implements MouseWheelListener {
|
||||
|
||||
t += 1D;
|
||||
r.put(p.getMilliseconds());
|
||||
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getParent().isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getParent().getParent().isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EventQueue.invokeLater(() -> {
|
||||
repaint();
|
||||
});
|
||||
}
|
||||
|
||||
private static void createAndShowGUI() {
|
||||
private static void createAndShowGUI(IrisChunkGenerator g) {
|
||||
JFrame frame = new JFrame("Iris");
|
||||
NoiseView nv = new NoiseView();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
combo = new JComboBox<NoiseStyle>(NoiseStyle.values());
|
||||
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
KList<String> li = new KList<NoiseStyle>(NoiseStyle.values()).toStringList().qadd("PROJECT");
|
||||
combo = new JComboBox<String>(li.toArray(new String[li.size()]));
|
||||
combo.setSelectedItem(g != null ? "PROJECT" : "STATIC");
|
||||
|
||||
if (g != null) {
|
||||
renderer = Iris.proj.getCurrentProject().createRenderer();
|
||||
}
|
||||
|
||||
combo.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
NoiseStyle s = (NoiseStyle) (((JComboBox<NoiseStyle>) e.getSource()).getSelectedItem());
|
||||
String b = (String) (((JComboBox<String>) e.getSource()).getSelectedItem());
|
||||
if (b.equals("PROJECT")) {
|
||||
renderer = Iris.proj.getCurrentProject().createRenderer();
|
||||
return;
|
||||
}
|
||||
renderer = null;
|
||||
NoiseStyle s = NoiseStyle.valueOf(b);
|
||||
nv.cng = s.create(RNG.r.nextParallelRNG(RNG.r.imax()));
|
||||
}
|
||||
});
|
||||
@ -210,10 +259,10 @@ public class NoiseView extends JPanel implements MouseWheelListener {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void launch(IrisChunkGenerator g) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
createAndShowGUI();
|
||||
createAndShowGUI(g);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
29
src/main/java/com/volmit/iris/command/CommandIrisMap.java
Normal file
29
src/main/java/com/volmit/iris/command/CommandIrisMap.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.NoiseView;
|
||||
import com.volmit.iris.gen.IrisChunkGenerator;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisMap extends MortarCommand {
|
||||
public CommandIrisMap() {
|
||||
super("map", "render");
|
||||
setDescription("Render a map (gui outside of mc)");
|
||||
requiresPermission(Iris.perm.studio);
|
||||
setCategory("World");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(MortarSender sender, String[] args) {
|
||||
IrisChunkGenerator g = Iris.proj.getCurrentProject();
|
||||
NoiseView.launch(g);
|
||||
sender.sendMessage("Opening Map!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage() {
|
||||
return "";
|
||||
}
|
||||
}
|
@ -24,6 +24,9 @@ public class CommandIrisStudio extends MortarCommand {
|
||||
@Command
|
||||
private CommandIrisStudioUpdate update;
|
||||
|
||||
@Command
|
||||
private CommandIrisMap map;
|
||||
|
||||
@Command
|
||||
private CommandIrisStudioList list;
|
||||
|
||||
|
@ -51,6 +51,7 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator {
|
||||
public void onHotload() {
|
||||
super.onHotload();
|
||||
loadGenerators();
|
||||
glBiome = new GenLayerBiome(this, masterRandom.nextParallelRNG(1));
|
||||
}
|
||||
|
||||
public void registerGenerator(IrisGenerator g, IrisDimension dim) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.volmit.iris.gen;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@ -16,6 +17,7 @@ import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisEffect;
|
||||
import com.volmit.iris.object.IrisRegion;
|
||||
import com.volmit.iris.util.BiomeResult;
|
||||
import com.volmit.iris.util.Function2;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.RNG;
|
||||
@ -203,4 +205,23 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
|
||||
|
||||
return getDimension().isVanillaStructures();
|
||||
}
|
||||
|
||||
public Function2<Double, Double, Color> createRenderer() {
|
||||
return (x, z) -> render(x, z);
|
||||
}
|
||||
|
||||
private Color render(double x, double z) {
|
||||
int ix = (int) x;
|
||||
int iz = (int) z;
|
||||
double height = getTerrainHeight(ix, iz);
|
||||
IrisRegion region = sampleRegion(ix, iz);
|
||||
IrisBiome biome = sampleTrueBiome(ix, iz, height).getBiome();
|
||||
|
||||
float shift = (biome.hashCode() % 32)/32f/14f;
|
||||
float shift2 = (region.hashCode() % 9)/9f/14f;
|
||||
shift-= shift2;
|
||||
|
||||
return Color.getHSBColor((biome.isLand() ? 0.233f : 0.644f)-shift, 0.25f+shift,
|
||||
(float) (Math.max(0, Math.min(height + getFluidHeight(), 255)) / 255));
|
||||
}
|
||||
}
|
||||
|
@ -131,14 +131,7 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
|
||||
|
||||
@Override
|
||||
public void updateHeight(int x, int z, int h) {
|
||||
if (x >> 4 == currentPostX && z >> 4 == currentPostZ) {
|
||||
//cacheHeight(x, z, h);
|
||||
}
|
||||
|
||||
else {
|
||||
Iris.error("Invalid Heightmap set! Chunk Currently at " + currentPostX + "," + currentPostZ
|
||||
+ ". Attempted to place at " + (x >> 4) + " " + (z >> 4) + " which is bad.");
|
||||
}
|
||||
getCache().updateHeight(x, z, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,10 +3,8 @@ package com.volmit.iris.gen.atomics;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.object.IrisRegion;
|
||||
import com.volmit.iris.util.BiomeResult;
|
||||
import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.KMap;
|
||||
|
||||
public class AtomicMulticache {
|
||||
@ -32,12 +30,10 @@ public class AtomicMulticache {
|
||||
public void targetChunk(int x, int z) {
|
||||
this.x.set(x);
|
||||
this.z.set(z);
|
||||
|
||||
Iris.info("R: " + Form.f(r) + " W: " + Form.f(w) + " M: " + Form.f(m) + " (" + Form.pc(r / (double) (r + m), 1)
|
||||
+ "), SIZE: " + Form.f(height.size() + biome.size() + region.size()));
|
||||
height.clear();
|
||||
region.size();
|
||||
biome.size();
|
||||
region.clear();
|
||||
biome.clear();
|
||||
rawBiome.clear();
|
||||
r = 0;
|
||||
w = 0;
|
||||
m = 0;
|
||||
@ -102,4 +98,8 @@ public class AtomicMulticache {
|
||||
private long pos(int x, int z) {
|
||||
return (((long) x) << 32) | (z & 0xffffffffL);
|
||||
}
|
||||
|
||||
public void updateHeight(int x, int z, int h) {
|
||||
height.put(pos(x, z), (double) h);
|
||||
}
|
||||
}
|
||||
|
@ -184,45 +184,47 @@ public class CNG {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends IRare> T fitRarity(List<T> l, double... dim) {
|
||||
if (l.isEmpty()) {
|
||||
public <T extends IRare> T fitRarity(KList<T> b, double... dim) {
|
||||
if (b.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (l.size() == 1) {
|
||||
return l.get(0);
|
||||
if (b.size() == 1) {
|
||||
return b.get(0);
|
||||
}
|
||||
|
||||
int total = 0;
|
||||
boolean allOne = true;
|
||||
|
||||
for (T i : l) {
|
||||
int r = i.getRarity();
|
||||
|
||||
if (r > 1) {
|
||||
allOne = false;
|
||||
KList<T> rarityMapped = new KList<>();
|
||||
boolean o = false;
|
||||
int max = 1;
|
||||
for (T i : b) {
|
||||
if (i.getRarity() > max) {
|
||||
max = i.getRarity();
|
||||
}
|
||||
|
||||
total += r;
|
||||
}
|
||||
|
||||
int m = fit(0, total - 1, dim);
|
||||
max++;
|
||||
|
||||
if (m == 0) {
|
||||
return l.get(0);
|
||||
for (T i : b) {
|
||||
for (int j = 0; j < max - i.getRarity(); j++) {
|
||||
if (o = !o) {
|
||||
rarityMapped.add(i);
|
||||
}
|
||||
|
||||
else {
|
||||
rarityMapped.add(0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allOne) {
|
||||
return l.get(m);
|
||||
if (rarityMapped.size() == 1) {
|
||||
return rarityMapped.get(0);
|
||||
}
|
||||
|
||||
T c = l.get(0);
|
||||
|
||||
while (m > 0) {
|
||||
m -= c.getRarity();
|
||||
if (rarityMapped.isEmpty()) {
|
||||
throw new RuntimeException("BAD RARITY MAP! RELATED TO: " + b.toString(", or possibly "));
|
||||
}
|
||||
|
||||
return c;
|
||||
return fit(rarityMapped, dim);
|
||||
}
|
||||
|
||||
public <T> T fit(T[] v, double... dim) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public interface IRare
|
||||
{
|
||||
public interface IRare {
|
||||
public int getRarity();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user