Removed unused graph classes
This commit is contained in:
@@ -62,7 +62,6 @@ public class UI extends SceneModule{
|
||||
public ContentInfoDialog content;
|
||||
public SectorsDialog sectors;
|
||||
public MissionDialog missions;
|
||||
public UnlockGraphDialog graph;
|
||||
|
||||
private Locale lastLocale;
|
||||
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.SafeArray;
|
||||
|
||||
public class GraphSimulation<T>{
|
||||
public Array<Vertex<T>> vertices = new SafeArray<>();
|
||||
public Array<Edge<T>> edges = new SafeArray<>();
|
||||
public int frameWidth;
|
||||
public int frameHeight;
|
||||
public boolean equi = false;
|
||||
public float criterion = 1000;
|
||||
public float coolingRate = 0.065f;
|
||||
|
||||
private static final float C = 1f;
|
||||
|
||||
private int iteration = 0;
|
||||
private float k;
|
||||
private float t;
|
||||
private boolean equilibriumReached = false;
|
||||
|
||||
private Vector2 deltaPos = new Vector2();
|
||||
|
||||
public int startSimulation() {
|
||||
|
||||
iteration = 0;
|
||||
equilibriumReached = false;
|
||||
|
||||
int area = Math.min(frameWidth * frameWidth, frameHeight * frameHeight);
|
||||
k = C * Mathf.sqrt(area / vertices.size);
|
||||
t = frameWidth / 10;
|
||||
|
||||
if (equi) {
|
||||
while (!equilibriumReached && iteration < 10000) {
|
||||
simulateStep();
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < criterion; i++) {
|
||||
simulateStep();
|
||||
}
|
||||
}
|
||||
return iteration;
|
||||
}
|
||||
|
||||
private void simulateStep() {
|
||||
for (Vertex<T> v : vertices) {
|
||||
v.disp.set(0, 0);
|
||||
for (Vertex<T> u : vertices) {
|
||||
if (v != u) {
|
||||
deltaPos.set(v.pos).sub(u.pos);
|
||||
float length = deltaPos.len();
|
||||
deltaPos.setLength(forceRepulsive(length, k));
|
||||
v.disp.add(deltaPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Edge<T> e : edges) {
|
||||
deltaPos.set(e.v.pos).sub(e.u.pos);
|
||||
float length = deltaPos.len();
|
||||
deltaPos.setLength(forceAttractive(length, k));
|
||||
|
||||
e.v.disp.sub(deltaPos);
|
||||
e.u.disp.add(deltaPos);
|
||||
}
|
||||
|
||||
equilibriumReached = true;
|
||||
|
||||
for (Vertex<T> v : vertices) {
|
||||
|
||||
deltaPos.set(v.disp);
|
||||
float length = deltaPos.len();
|
||||
|
||||
if (length > criterion) {
|
||||
equilibriumReached = false;
|
||||
}
|
||||
|
||||
deltaPos.setLength(Math.min(length, t));
|
||||
|
||||
v.pos.add(deltaPos);
|
||||
v.pos.x = Mathf.clamp(v.pos.x, 0, frameWidth);
|
||||
v.pos.y = Mathf.clamp(v.pos.y, 0, frameHeight);
|
||||
}
|
||||
|
||||
t = Math.max(t * (1 - coolingRate), 1);
|
||||
iteration++;
|
||||
}
|
||||
|
||||
private float forceAttractive(float d, float k) {
|
||||
return d * d / k;
|
||||
}
|
||||
|
||||
private float forceRepulsive(float d, float k) {
|
||||
return k * k /d;
|
||||
}
|
||||
|
||||
public static class Vertex<T>{
|
||||
public Vector2 pos = new Vector2();
|
||||
public final T value;
|
||||
|
||||
private Vector2 disp = new Vector2();
|
||||
|
||||
public Vertex(T value){
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Edge<T> {
|
||||
public final Vertex<T> v;
|
||||
public final Vertex<T> u;
|
||||
|
||||
public Edge(Vertex<T> v, Vertex<T> u) {
|
||||
this.v = v;
|
||||
this.u = u;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.ItemType;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.ui.GraphSimulation;
|
||||
import io.anuke.mindustry.ui.GraphSimulation.Edge;
|
||||
import io.anuke.mindustry.ui.GraphSimulation.Vertex;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class UnlockGraphDialog extends FloatingDialog{
|
||||
int frameSize = 1000;
|
||||
ObjectMap<UnlockableContent, Vertex<UnlockableContent>> map = new ObjectMap<>();
|
||||
Array<Vertex<UnlockableContent>> vertices;
|
||||
Array<Edge<UnlockableContent>> edges;
|
||||
|
||||
public UnlockGraphDialog(){
|
||||
super("$text.unlocks");
|
||||
|
||||
rebuild();
|
||||
}
|
||||
|
||||
public void rebuild(){
|
||||
content().clear();
|
||||
|
||||
GraphSimulation<UnlockableContent> sim = new GraphSimulation<>();
|
||||
sim.frameWidth = frameSize;
|
||||
sim.frameHeight = frameSize;
|
||||
vertices = sim.vertices;
|
||||
edges = sim.edges;
|
||||
|
||||
for(Item item : Vars.content.items()){
|
||||
if(item.type != ItemType.material) continue;
|
||||
put(item);
|
||||
}
|
||||
|
||||
for(Recipe recipe : Vars.content.recipes()){
|
||||
if(recipe.requirements.length == 0) continue;
|
||||
put(recipe);
|
||||
|
||||
for(Item item : Vars.content.items()){
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
if(stack.item == item){
|
||||
link(item, recipe);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sim.startSimulation();
|
||||
|
||||
content().addRect((x, y, w, h) -> {
|
||||
float cx = x + w/2f, cy = y + h/2f;
|
||||
float ox = cx - frameSize/2f, oy = cy - frameSize/2f;
|
||||
|
||||
Draw.color(Color.DARK_GRAY);
|
||||
Lines.stroke(4f);
|
||||
|
||||
for(Edge<UnlockableContent> e : edges){
|
||||
if(e.v.value instanceof Item){
|
||||
Draw.color(((Item) e.v.value).color);
|
||||
}
|
||||
Lines.line(e.u.pos.x + ox, e.u.pos.y + oy, e.v.pos.x + ox, e.v.pos.y + oy);
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
|
||||
for(Vertex<UnlockableContent> v : vertices){
|
||||
Draw.rect(v.value.getContentIcon(), v.pos.x + ox, v.pos.y + oy, 16*2f, 16*2f);
|
||||
}
|
||||
}).grow();
|
||||
}
|
||||
|
||||
private Vertex<UnlockableContent> get(UnlockableContent c){
|
||||
return map.get(c);
|
||||
}
|
||||
|
||||
private void put(UnlockableContent c){
|
||||
Vertex<UnlockableContent> v = new Vertex<>(c);
|
||||
v.pos.set(frameSize/2f + Mathf.range(frameSize/2f), frameSize/2f + Mathf.range(frameSize/2f));
|
||||
map.put(c, v);
|
||||
vertices.add(v);
|
||||
}
|
||||
|
||||
private void link(UnlockableContent a, UnlockableContent b){
|
||||
edges.add(new Edge<>(get(a), get(b)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user