Refactoring

This commit is contained in:
Anuken
2020-05-13 22:29:27 -04:00
parent 6e62936458
commit a06f6f0b2d
22 changed files with 76 additions and 91 deletions

View File

@@ -12,6 +12,7 @@ import arc.util.Log.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.ai.*; import mindustry.ai.*;
import mindustry.async.*; import mindustry.async.*;
import mindustry.audio.LoopControl;
import mindustry.core.*; import mindustry.core.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.game.*; import mindustry.game.*;
@@ -167,7 +168,7 @@ public class Vars implements Loadable{
public static GlobalData data; public static GlobalData data;
public static EntityCollisions collisions; public static EntityCollisions collisions;
public static DefaultWaves defaultWaves; public static DefaultWaves defaultWaves;
public static LoopControl loops; public static mindustry.audio.LoopControl loops;
public static Platform platform = new Platform(){}; public static Platform platform = new Platform(){};
public static Mods mods; public static Mods mods;
public static Schematics schematics; public static Schematics schematics;

View File

@@ -1,4 +1,4 @@
package mindustry.game; package mindustry.audio;
import arc.*; import arc.*;
import arc.audio.*; import arc.audio.*;

View File

@@ -1,4 +1,4 @@
package mindustry.game; package mindustry.audio;
import arc.*; import arc.*;
import arc.audio.*; import arc.audio.*;

View File

@@ -1,4 +1,4 @@
package mindustry.game; package mindustry.audio;
import arc.audio.*; import arc.audio.*;
import arc.math.*; import arc.math.*;

View File

@@ -9,6 +9,7 @@ import arc.math.*;
import arc.scene.ui.*; import arc.scene.ui.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.audio.MusicControl;
import mindustry.content.*; import mindustry.content.*;
import mindustry.core.GameState.*; import mindustry.core.GameState.*;
import mindustry.entities.*; import mindustry.entities.*;
@@ -39,7 +40,7 @@ import static mindustry.Vars.*;
*/ */
public class Control implements ApplicationListener, Loadable{ public class Control implements ApplicationListener, Loadable{
public Saves saves; public Saves saves;
public MusicControl music; public mindustry.audio.MusicControl music;
public Tutorial tutorial; public Tutorial tutorial;
public InputHandler input; public InputHandler input;

View File

@@ -41,7 +41,7 @@ public class GameState{
/** Note that being in a campaign does not necessarily mean having a sector. */ /** Note that being in a campaign does not necessarily mean having a sector. */
public boolean isCampaign(){ public boolean isCampaign(){
return rules.sector != null || rules.region != null; return rules.sector != null;
} }
public boolean hasSector(){ public boolean hasSector(){

View File

@@ -15,6 +15,7 @@ import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.audio.SoundLoop;
import mindustry.content.*; import mindustry.content.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.entities.*; import mindustry.entities.*;
@@ -59,7 +60,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
private transient float timeScale = 1f, timeScaleDuration; private transient float timeScale = 1f, timeScaleDuration;
private transient @Nullable SoundLoop sound; private transient @Nullable mindustry.audio.SoundLoop sound;
private transient boolean sleeping; private transient boolean sleeping;
private transient float sleepTime; private transient float sleepTime;

View File

@@ -90,9 +90,9 @@ public class EventType{
/** Called when a zone's requirements are met. */ /** Called when a zone's requirements are met. */
public static class ZoneRequireCompleteEvent{ public static class ZoneRequireCompleteEvent{
public final SectorPreset zoneMet, zoneForMet; public final SectorPreset zoneMet, zoneForMet;
public final Objective objective; public final Objectives.Objective objective;
public ZoneRequireCompleteEvent(SectorPreset zoneMet, SectorPreset zoneForMet, Objective objective){ public ZoneRequireCompleteEvent(SectorPreset zoneMet, SectorPreset zoneForMet, Objectives.Objective objective){
this.zoneMet = zoneMet; this.zoneMet = zoneMet;
this.zoneForMet = zoneForMet; this.zoneForMet = zoneForMet;
this.objective = objective; this.objective = objective;

View File

@@ -1,10 +1,9 @@
package mindustry.game; package mindustry.game;
import arc.*; import arc.*;
import arc.files.*;
import arc.math.*; import arc.math.*;
import arc.struct.*; import arc.struct.*;
import arc.files.*;
import arc.util.ArcAnnotate.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.*; import mindustry.*;
import mindustry.content.*; import mindustry.content.*;
@@ -22,7 +21,6 @@ public class GlobalData{
private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>(); private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>();
private ObjectIntMap<Item> items = new ObjectIntMap<>(); private ObjectIntMap<Item> items = new ObjectIntMap<>();
private Array<Satellite> satellites = new Array<>(); private Array<Satellite> satellites = new Array<>();
private ObjectMap<String, MapRegion> regions = new ObjectMap<>();
private boolean modified; private boolean modified;
public GlobalData(){ public GlobalData(){
@@ -39,10 +37,6 @@ public class GlobalData{
}); });
} }
public @Nullable MapRegion getRegion(String name){
return regions.get(name);
}
public void exportData(Fi file) throws IOException{ public void exportData(Fi file) throws IOException{
Array<Fi> files = new Array<>(); Array<Fi> files = new Array<>();
files.add(Core.settings.getSettingsFile()); files.add(Core.settings.getSettingsFile());

View File

@@ -1,12 +0,0 @@
package mindustry.game;
/** Defines a special map that can be visited, loaded, and saved. */
public abstract class MapRegion{
/** Name of the region. Used for lookup and save names. */
public abstract String name();
public void load(){
}
}

View File

@@ -1,27 +0,0 @@
package mindustry.game;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import mindustry.game.Objectives.*;
import mindustry.type.*;
/** Defines a specific objective for a game. */
public interface Objective{
/** @return whether this objective is met. */
boolean complete();
/** @return the string displayed when this objective is completed, in imperative form.
* e.g. when the objective is 'complete 10 waves', this would display "complete 10 waves".
* If this objective should not be displayed, should return null.*/
@Nullable String display();
/** Build a display for this zone requirement.*/
default void build(Table table){
}
default SectorPreset zone(){
return this instanceof ZoneObjective ? ((ZoneObjective)this).zone : null;
}
}

View File

@@ -1,6 +1,7 @@
package mindustry.game; package mindustry.game;
import arc.*; import arc.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
@@ -93,4 +94,25 @@ public class Objectives{
public abstract static class ZoneObjective implements Objective{ public abstract static class ZoneObjective implements Objective{
public @NonNull SectorPreset zone; public @NonNull SectorPreset zone;
} }
/** Defines a specific objective for a game. */
public static interface Objective{
/** @return whether this objective is met. */
boolean complete();
/** @return the string displayed when this objective is completed, in imperative form.
* e.g. when the objective is 'complete 10 waves', this would display "complete 10 waves".
* If this objective should not be displayed, should return null.*/
@Nullable String display();
/** Build a display for this zone requirement.*/
default void build(Table table){
}
default SectorPreset zone(){
return this instanceof ZoneObjective ? ((ZoneObjective)this).zone : null;
}
}
} }

View File

@@ -62,8 +62,6 @@ public class Rules{
public int unitCap = 0; public int unitCap = 0;
/** Sector for saves that have them.*/ /** Sector for saves that have them.*/
public @Nullable Sector sector; public @Nullable Sector sector;
/** Region that save is on. Indicates campaign. TODO not implemented. */
public @Nullable MapRegion region;
/** Spawn layout. */ /** Spawn layout. */
public Array<SpawnGroup> spawns = new Array<>(); public Array<SpawnGroup> spawns = new Array<>();
/** Determines if there should be limited respawns. */ /** Determines if there should be limited respawns. */

View File

@@ -16,8 +16,7 @@ public class Schematic implements Publishable, Comparable<Schematic>{
public final Array<Stile> tiles; public final Array<Stile> tiles;
public StringMap tags; public StringMap tags;
public int width, height; public int width, height;
public @Nullable public @Nullable Fi file;
Fi file;
/** Associated mod. If null, no mod is associated with this schematic. */ /** Associated mod. If null, no mod is associated with this schematic. */
public @Nullable LoadedMod mod; public @Nullable LoadedMod mod;

View File

@@ -0,0 +1,4 @@
package mindustry.game;
public class Turns{
}

View File

@@ -69,8 +69,7 @@ public class Universe{
} }
private void save(){ private void save(){
Core.settings.put("utime", seconds); Core.settings.putSave("utime", seconds);
Core.settings.save();
} }
private void load(){ private void load(){

View File

@@ -86,10 +86,10 @@ public class ContentParser{
desc.errored = Throwable::printStackTrace; desc.errored = Throwable::printStackTrace;
return sound; return sound;
}); });
put(Objective.class, (type, data) -> { put(Objectives.Objective.class, (type, data) -> {
Class<? extends Objective> oc = data.has("type") ? resolve(data.getString("type"), "mindustry.game.Objectives") : ZoneWave.class; Class<? extends Objectives.Objective> oc = data.has("type") ? resolve(data.getString("type"), "mindustry.game.Objectives") : ZoneWave.class;
data.remove("type"); data.remove("type");
Objective obj = make(oc); Objectives.Objective obj = make(oc);
readFields(obj, data); readFields(obj, data);
return obj; return obj;
}); });

View File

@@ -17,9 +17,9 @@ import static mindustry.Vars.*;
//TODO ? remove ? //TODO ? remove ?
public class SectorPreset extends UnlockableContent{ public class SectorPreset extends UnlockableContent{
public @NonNull WorldGenerator generator; public @NonNull WorldGenerator generator;
public @NonNull Objective configureObjective = new ZoneWave(this, 15); public @NonNull Objectives.Objective configureObjective = new ZoneWave(this, 15);
public @NonNull Planet planet; public @NonNull Planet planet;
public Array<Objective> requirements = new Array<>(); public Array<Objectives.Objective> requirements = new Array<>();
//TODO autogenerate //TODO autogenerate
public Array<Item> resources = new Array<>(); public Array<Item> resources = new Array<>();

View File

@@ -273,7 +273,11 @@ public class PlanetDialog extends FloatingDialog{
} }
if(sec.hostility >= 0.02f){ if(sec.hostility >= 0.02f){
drawSelection(sec, Color.scarlet, 0.11f * sec.hostility); drawSelection(sec, Color.scarlet, 0.11f * sec.hostility, 0.0001f);
}
if(sec.save != null){
drawSelection(sec, Color.lime, 0.03f, 0.0009f);
} }
} }
@@ -402,11 +406,11 @@ public class PlanetDialog extends FloatingDialog{
} }
private void drawSelection(Sector sector){ private void drawSelection(Sector sector){
drawSelection(sector, Pal.accent, 0.04f); drawSelection(sector, Pal.accent, 0.04f, 0.001f);
} }
private void drawSelection(Sector sector, Color color, float length){ private void drawSelection(Sector sector, Color color, float stroke, float length){
float arad = outlineRad + 0.0001f; float arad = outlineRad + length;
for(int i = 0; i < sector.tile.corners.length; i++){ for(int i = 0; i < sector.tile.corners.length; i++){
Corner next = sector.tile.corners[(i + 1) % sector.tile.corners.length]; Corner next = sector.tile.corners[(i + 1) % sector.tile.corners.length];
@@ -416,8 +420,8 @@ public class PlanetDialog extends FloatingDialog{
curr.v.scl(arad); curr.v.scl(arad);
sector.tile.v.scl(arad); sector.tile.v.scl(arad);
Tmp.v31.set(curr.v).sub(sector.tile.v).setLength(curr.v.dst(sector.tile.v) - length).add(sector.tile.v); Tmp.v31.set(curr.v).sub(sector.tile.v).setLength(curr.v.dst(sector.tile.v) - stroke).add(sector.tile.v);
Tmp.v32.set(next.v).sub(sector.tile.v).setLength(next.v.dst(sector.tile.v) - length).add(sector.tile.v); Tmp.v32.set(next.v).sub(sector.tile.v).setLength(next.v.dst(sector.tile.v) - stroke).add(sector.tile.v);
batch.tri(curr.v, next.v, Tmp.v31, color); batch.tri(curr.v, next.v, Tmp.v31, color);
batch.tri(Tmp.v31, next.v, Tmp.v32, color); batch.tri(Tmp.v31, next.v, Tmp.v32, color);

View File

@@ -63,13 +63,13 @@ public class ZoneInfoDialog extends FloatingDialog{
cont.table(req -> { cont.table(req -> {
req.defaults().left(); req.defaults().left();
Array<Objective> zones = zone.requirements.select(o -> !(o instanceof Unlock)); Array<Objectives.Objective> zones = zone.requirements.select(o -> !(o instanceof Unlock));
if(!zones.isEmpty()){ if(!zones.isEmpty()){
req.table(r -> { req.table(r -> {
r.add("$complete").colspan(2).left(); r.add("$complete").colspan(2).left();
r.row(); r.row();
for(Objective o : zones){ for(Objectives.Objective o : zones){
r.image(Icon.terrain).padRight(4); r.image(Icon.terrain).padRight(4);
r.add(o.display()).color(Color.lightGray); r.add(o.display()).color(Color.lightGray);
r.image(o.complete() ? Icon.ok : Icon.cancel, o.complete() ? Color.lightGray : Color.scarlet).padLeft(3); r.image(o.complete() ? Icon.ok : Icon.cancel, o.complete() ? Color.lightGray : Color.scarlet).padLeft(3);

View File

@@ -1,11 +1,12 @@
package mindustry.world.blocks.experimental; package mindustry.world.blocks.experimental;
import arc.math.*;
import mindustry.gen.*; import mindustry.gen.*;
import java.nio.*;
public class LogicExecutor{ public class LogicExecutor{
Instruction[] instructions; Instruction[] instructions;
int[] registers = new int[256]; ByteBuffer memory = ByteBuffer.allocate(1024 * 512);
int counter; int counter;
void step(){ void step(){
@@ -29,16 +30,16 @@ public class LogicExecutor{
class RegisterI implements Instruction{ class RegisterI implements Instruction{
/** operation to perform */ /** operation to perform */
Op op; Op op;
/** destination register */ /** destination memory */
short dest; int dest;
/** registers to take data from. -1 for no register. */ /** memory to take data from. -1 for immediate values. */
short left, right; int left, right;
/** left/right immediate values, only used if no registers are present. */ /** left/right immediate values, only used if no registers are present. */
int ileft, iright; double ileft, iright;
@Override @Override
public void exec(){ public void exec(){
registers[dest] = op.function.get(left == -1 ? ileft : registers[left], right == -1 ? iright : registers[right]); //memory.putDouble(dest, op.function.get(left == -1 ? ileft : registers[left], right == -1 ? iright : registers[right]));
} }
} }
@@ -54,7 +55,7 @@ public class LogicExecutor{
@Override @Override
public void exec(){ public void exec(){
registers[dest] = op.function.get(device(device), parameter); //registers[dest] = op.function.get(device(device), parameter);
} }
} }
@@ -89,12 +90,12 @@ public class LogicExecutor{
mul("*", (a, b) -> a * b), mul("*", (a, b) -> a * b),
div("/", (a, b) -> a / b), div("/", (a, b) -> a / b),
mod("%", (a, b) -> a % b), mod("%", (a, b) -> a % b),
pow("^", Mathf::pow), pow("^", Math::pow),
shl(">>", (a, b) -> a >> b), shl(">>", (a, b) -> (int)a >> (int)b),
shr("<<", (a, b) -> a << b), shr("<<", (a, b) -> (int)a << (int)b),
or("or", (a, b) -> a | b), or("or", (a, b) -> (int)a | (int)b),
and("and", (a, b) -> a & b), and("and", (a, b) -> (int)a & (int)b),
xor("xor", (a, b) -> a ^ b); xor("xor", (a, b) -> (int)a ^ (int)b);
final OpLambda function; final OpLambda function;
final String symbol; final String symbol;
@@ -105,7 +106,7 @@ public class LogicExecutor{
} }
interface OpLambda{ interface OpLambda{
int get(int a, int b); double get(double a, double b);
} }
} }

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=6164484526b4e0a9dce4c59b11bef3448e363cee archash=1ccdb62216c9e6e0d85a85aa120f4dfc59b76e63