From 024f2d62e2b15aa68ae4d8ca9572f75cebfc5922 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 14 Feb 2020 20:08:07 -0500 Subject: [PATCH] Planet sector metadata --- .../annotations/impl/AssetsProcess.java | 4 +- build.gradle | 2 +- core/assets/planets/TODO.dat | Bin 0 -> 13821 bytes core/src/mindustry/game/Stats.java | 2 +- .../maps/generators/MapGenerator.java | 2 +- .../maps/planet/TestPlanetGenerator.java | 1 - core/src/mindustry/mod/ContentParser.java | 2 +- core/src/mindustry/mod/ModLoadingSound.java | 2 +- core/src/mindustry/type/Planet.java | 22 ++++- core/src/mindustry/type/Sector.java | 51 ++++++++-- tools/build.gradle | 7 ++ .../mindustry/tools/SectorDataGenerator.java | 93 ++++++++++++++++++ 12 files changed, 173 insertions(+), 15 deletions(-) create mode 100644 core/assets/planets/TODO.dat create mode 100644 tools/src/mindustry/tools/SectorDataGenerator.java diff --git a/annotations/src/main/java/mindustry/annotations/impl/AssetsProcess.java b/annotations/src/main/java/mindustry/annotations/impl/AssetsProcess.java index 2ace8d96b9..fc83ce3e3b 100644 --- a/annotations/src/main/java/mindustry/annotations/impl/AssetsProcess.java +++ b/annotations/src/main/java/mindustry/annotations/impl/AssetsProcess.java @@ -114,11 +114,11 @@ public class AssetsProcess extends BaseProcessor{ dispose.addStatement("arc.Core.assets.unload(" + filename + ")"); dispose.addStatement(name + " = null"); - type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), name, Modifier.STATIC, Modifier.PUBLIC).initializer("new arc.audio.mock.Mock" + rtype.substring(rtype.lastIndexOf(".") + 1)+ "()").build()); + type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), name, Modifier.STATIC, Modifier.PUBLIC).initializer("new arc.mock.Mock" + rtype.substring(rtype.lastIndexOf(".") + 1)+ "()").build()); }); if(classname.equals("Sounds")){ - type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), "none", Modifier.STATIC, Modifier.PUBLIC).initializer("new arc.audio.mock.Mock" + rtype.substring(rtype.lastIndexOf(".") + 1)+ "()").build()); + type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), "none", Modifier.STATIC, Modifier.PUBLIC).initializer("new arc.mock.Mock" + rtype.substring(rtype.lastIndexOf(".") + 1)+ "()").build()); } type.addMethod(loadBegin.build()); diff --git a/build.gradle b/build.gradle index 8aa9762606..2b00a2ab94 100644 --- a/build.gradle +++ b/build.gradle @@ -298,7 +298,7 @@ project(":tools"){ compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" compile "org.reflections:reflections:0.9.12" - compile arcModule("backends:backend-sdl") + compile arcModule("backends:backend-headless") } } diff --git a/core/assets/planets/TODO.dat b/core/assets/planets/TODO.dat new file mode 100644 index 0000000000000000000000000000000000000000..143e63ffb97c223f9a9f970122311c710bd0811c GIT binary patch literal 13821 zcmZXbcYIY)fzUxjdIv!u2+~1{0*a_ew*V6?pnwGw z6mbNe^S};{1A>ZRL2)eOSa6(i^zHBB&4hi)UwrOfYyH;mxA)oY9Naj^<2XK_bNSEb zjC7o_7o1^^)8V)?$#Gh_&QQnkPO(rPTF%6R4J24CK3ZjG+h8?dn&2gUn+^Ke) z%x9cC94B(s)%=IEX=xIUO60w$xDzc@fZrypC05rP(a#Bo5q&M{&U5gb{1Ar0F76Df z;2@}!I8gD+P>SwB)}G1`hQZ$V8Zq*phLN!kY*>MFv+>i444e%X!w>eZg~Z6bgsaro zVZ=X4q=;4)R&`o2A8gT4)aySEHm-FDYLer&yobtX&p|!zFj`SH7Ag$px6Oz+rYorQ zm(dLyiLSey+??I2$$}7`!7g}+-W~7-sJ4CJWj#%9>9?a=uN4}JDHbn4`#JSw#ou7G zUIRN$qavmnp8JEvpfYaBKfzYa2OIV>C~qg!o$oBH)K_jKkKT2`_B;YF`+gYplC$WJ%d`bo&=*HnI|H18~NAUhmz;(5VrYkriao}iP~@vsQ3}E;|GBa3x^$;i?(;2a0CD_*2!7lldETjB#Yxjx9w=;sw&JczTAu%7QWQL9k7VK=~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h$o~E}LeJNY=Z?NWUXn4Lt?76e9!a7?X12stPT{mL6^GKq4?B`WwS*KI+^oAr^ z*a^h~owGvTVrX0Pmj2UFuk&Dgv;-UbAg;syjvv3hj;N2OyhPl|FN3N`1=U>dZ-TlC zGDGRgXIC$~Jk;{AP literal 0 HcmV?d00001 diff --git a/core/src/mindustry/game/Stats.java b/core/src/mindustry/game/Stats.java index 2cb2a4e430..bd0ae219c1 100644 --- a/core/src/mindustry/game/Stats.java +++ b/core/src/mindustry/game/Stats.java @@ -39,7 +39,7 @@ public class Stats{ //weigh used fractions float frac = 0f; - Array obtainable = Array.with(zone.resources).select(i -> i instanceof Item && ((Item)i).type == ItemType.material).as(Item.class); + Array obtainable = Array.with(zone.data.resources).select(i -> i instanceof Item && ((Item)i).type == ItemType.material).as(Item.class); for(Item item : obtainable){ frac += Mathf.clamp((float)itemsDelivered.get(item, 0) / capacity) / (float)obtainable.size; } diff --git a/core/src/mindustry/maps/generators/MapGenerator.java b/core/src/mindustry/maps/generators/MapGenerator.java index d85501faf6..54e5469bc1 100644 --- a/core/src/mindustry/maps/generators/MapGenerator.java +++ b/core/src/mindustry/maps/generators/MapGenerator.java @@ -49,7 +49,7 @@ public class MapGenerator extends Generator{ for(Tile tile : tiles){ if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && world.getSector() != null){ - for(Content content : world.getSector().resources){ + for(Content content : world.getSector().data.resources){ if(content instanceof Item && Mathf.chance(0.3)){ tile.entity.items().add((Item)content, Math.min(Mathf.random(500), tile.block().itemCapacity)); } diff --git a/core/src/mindustry/maps/planet/TestPlanetGenerator.java b/core/src/mindustry/maps/planet/TestPlanetGenerator.java index 3bd9d3293d..0e307c107b 100644 --- a/core/src/mindustry/maps/planet/TestPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/TestPlanetGenerator.java @@ -65,7 +65,6 @@ public class TestPlanetGenerator implements PlanetGenerator{ height *= 1.2f; height = Mathf.clamp(height); - return arr[Mathf.clamp((int)(temp * arr.length), 0, arr.length - 1)][Mathf.clamp((int)(height * arr[0].length), 0, arr[0].length - 1)]; } } diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index fc11b1ba59..1b7a179a48 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -3,10 +3,10 @@ package mindustry.mod; import arc.*; import arc.assets.*; import arc.audio.*; -import arc.audio.mock.*; import arc.files.*; import arc.func.*; import arc.graphics.*; +import arc.mock.MockSound; import arc.struct.Array; import arc.struct.*; import arc.util.ArcAnnotate.*; diff --git a/core/src/mindustry/mod/ModLoadingSound.java b/core/src/mindustry/mod/ModLoadingSound.java index 558b29ce28..0b1197eb02 100644 --- a/core/src/mindustry/mod/ModLoadingSound.java +++ b/core/src/mindustry/mod/ModLoadingSound.java @@ -1,8 +1,8 @@ package mindustry.mod; import arc.audio.*; -import arc.audio.mock.*; import arc.math.geom.*; +import arc.mock.MockSound; import arc.util.ArcAnnotate.*; public class ModLoadingSound implements Sound{ diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index f81af07d6a..0fb7698674 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -1,14 +1,18 @@ package mindustry.type; +import arc.files.*; import arc.math.geom.*; import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.ArcAnnotate.*; import arc.util.*; +import arc.util.io.*; +import mindustry.*; import mindustry.ctype.*; import mindustry.graphics.*; import mindustry.graphics.PlanetGrid.*; import mindustry.maps.planet.*; +import mindustry.type.Sector.*; public class Planet extends UnlockableContent{ /** Mesh used for rendering. Created on load() - will be null on the server! */ @@ -32,9 +36,25 @@ public class Planet extends UnlockableContent{ this.size = 3; grid = PlanetGrid.newGrid(size); + sectors = new Array<>(grid.tiles.length); for(int i = 0; i < grid.tiles.length; i++){ - sectors.add(new Sector(this, grid.tiles[i])); + //TODO load sector data + sectors.add(new Sector(this, grid.tiles[i], new SectorData())); + } + + //read data + Fi data = Vars.tree.get("planets/" + name + ".dat"); + if(data.exists()){ + try(Reads read = data.reads()){ + short dsize = read.s(); + for(int i = 0; i < dsize; i++){ + sectors.get(i).data.read(read); + } + } + }else{ + //TODO crash instead - this is a critical error! + Log.err("Planet {0} is missing its data file."); } } diff --git a/core/src/mindustry/type/Sector.java b/core/src/mindustry/type/Sector.java index 91401c859e..2bb9169a3d 100644 --- a/core/src/mindustry/type/Sector.java +++ b/core/src/mindustry/type/Sector.java @@ -2,10 +2,11 @@ package mindustry.type; import arc.math.geom.*; import arc.util.*; +import arc.util.io.*; +import mindustry.*; import mindustry.ctype.*; import mindustry.graphics.PlanetGrid.*; - -import static mindustry.Vars.state; +import mindustry.world.*; /** A small section of a planet. */ public class Sector{ @@ -14,16 +15,16 @@ public class Sector{ public final Ptile tile; public final int id; - //TODO generate a class file with 2D arrays of resources for each sector for each planet - public final Content[] resources = {}; + public final SectorData data; //TODO implement a dynamic (?) launch period public int launchPeriod = 10; - public Sector(Planet planet, Ptile tile){ + public Sector(Planet planet, Ptile tile, SectorData data){ this.planet = planet; this.tile = tile; this.rect = makeRect(); this.id = tile.id; + this.data = data; } //TODO implement @@ -31,7 +32,6 @@ public class Sector{ return metCondition() && wave % launchPeriod == 0; } - public boolean metCondition(){ //TODO implement return false; @@ -83,4 +83,43 @@ public class Sector{ return result.set(center).add(right, nx).add(top, ny); } } + + /** Cached data about a sector. */ + public static class SectorData{ + public Content[] resources = {}; + public int spawnX, spawnY; + + public Block[] floors = {}; + public int[] floorCounts = {}; + + public void write(Writes write){ + write.s(resources.length); + for(Content resource : resources){ + write.b(resource.getContentType().ordinal()); + write.s(resource.id); + } + write.s(spawnX); + write.s(spawnY); + write.s(floors.length); + for(int i = 0; i < floors.length; i++){ + write.s(floors[i].id); + write.i(floorCounts[i]); + } + } + + public void read(Reads read){ + resources = new Content[read.s()]; + for(int i = 0; i < resources.length; i++){ + resources[i] = Vars.content.getByID(ContentType.all[read.b()], read.s()); + } + spawnX = read.s(); + spawnY = read.s(); + floors = new Block[read.s()]; + floorCounts = new int[floors.length]; + for(int i = 0; i < floors.length; i++){ + floors[i] = Vars.content.block(read.s()); + floorCounts[i] = read.i(); + } + } + } } diff --git a/tools/build.gradle b/tools/build.gradle index e527ef1e10..726a7acfb2 100644 --- a/tools/build.gradle +++ b/tools/build.gradle @@ -344,6 +344,13 @@ task genSprites(dependsOn: classes, type: JavaExec){ workingDir = genFolder } +task genSectorData(dependsOn: classes, type: JavaExec){ + main = "mindustry.tools.SectorDataGenerator" + classpath = sourceSets.main.runtimeClasspath + standardInput = System.in + workingDir = "../core/assets/" +} + task updateBundles(dependsOn: classes, type: JavaExec){ file(genFolder).mkdirs() diff --git a/tools/src/mindustry/tools/SectorDataGenerator.java b/tools/src/mindustry/tools/SectorDataGenerator.java new file mode 100644 index 0000000000..9d21679415 --- /dev/null +++ b/tools/src/mindustry/tools/SectorDataGenerator.java @@ -0,0 +1,93 @@ +package mindustry.tools; + +import arc.*; +import arc.files.*; +import arc.mock.*; +import arc.struct.*; +import arc.util.*; +import arc.util.io.*; +import mindustry.*; +import mindustry.core.*; +import mindustry.ctype.*; +import mindustry.net.Net; +import mindustry.type.*; +import mindustry.type.Sector.*; +import mindustry.world.*; + +import static mindustry.Vars.*; + +public class SectorDataGenerator{ + + public static void main(String[] args){ + ArcNativesLoader.load(); + + Core.files = new MockFiles(); + Core.app = new MockApplication(); + Core.settings = new MockSettings(); + + headless = true; + net = new Net(null); + tree = new FileTree(); + Vars.init(); + content.createBaseContent(); + + logic = new Logic(); + netServer = new NetServer(); + world = new World(); + + content.init(); + + for(Planet planet : content.getBy(ContentType.planet)){ + int[] count = {0}; + + Fi fi = Fi.get("planets").child(planet.name + ".dat"); + + Array list = planet.sectors.map(sector -> { + SectorData data = new SectorData(); + + ObjectIntMap floors = new ObjectIntMap<>(); + ObjectSet content = new ObjectSet<>(); + + world.loadSector(sector); + + for(Tile tile : world.tiles){ + Item item = tile.floor().itemDrop; + Liquid liquid = tile.floor().liquidDrop; + if(item != null) content.add(item); + if(liquid != null) content.add(liquid); + + if(!tile.block().isStatic()){ + floors.increment(tile.floor()); + } + } + + //sort counts in descending order + Array> entries = floors.entries().toArray(); + entries.sort(e -> -e.value); + //remove all blocks occuring < 30 times - unimportant + entries.removeAll(e -> e.value < 30); + + data.floors = new Block[entries.size]; + data.floorCounts = new int[entries.size]; + for(int i = 0; i < entries.size; i++){ + data.floorCounts[i] = entries.get(i).value; + data.floors[i] = entries.get(i).key; + } + + data.resources = content.asArray().sort(Structs.comps(Structs.comparing(Content::getContentType), Structs.comparingInt(c -> c.id))).toArray(Content.class); + + if(count[0]++ % 5 == 0){ + Log.info("&lyDone with sector &lm{0}/{1}", count[0], planet.sectors.size); + } + + return data; + }); + + //write data + try(Writes write = fi.writes()){ + write.s(list.size); + list.each(s -> s.write(write)); + } + } + } +}