Planet sector metadata

This commit is contained in:
Anuken 2020-02-14 20:08:07 -05:00
parent 7f56cdc1e9
commit 024f2d62e2
12 changed files with 173 additions and 15 deletions

View File

@ -114,11 +114,11 @@ public class AssetsProcess extends BaseProcessor{
dispose.addStatement("arc.Core.assets.unload(" + filename + ")"); dispose.addStatement("arc.Core.assets.unload(" + filename + ")");
dispose.addStatement(name + " = null"); 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")){ 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()); type.addMethod(loadBegin.build());

View File

@ -298,7 +298,7 @@ project(":tools"){
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "org.reflections:reflections:0.9.12" compile "org.reflections:reflections:0.9.12"
compile arcModule("backends:backend-sdl") compile arcModule("backends:backend-headless")
} }
} }

Binary file not shown.

View File

@ -39,7 +39,7 @@ public class Stats{
//weigh used fractions //weigh used fractions
float frac = 0f; float frac = 0f;
Array<Item> obtainable = Array.with(zone.resources).select(i -> i instanceof Item && ((Item)i).type == ItemType.material).as(Item.class); Array<Item> obtainable = Array.with(zone.data.resources).select(i -> i instanceof Item && ((Item)i).type == ItemType.material).as(Item.class);
for(Item item : obtainable){ for(Item item : obtainable){
frac += Mathf.clamp((float)itemsDelivered.get(item, 0) / capacity) / (float)obtainable.size; frac += Mathf.clamp((float)itemsDelivered.get(item, 0) / capacity) / (float)obtainable.size;
} }

View File

@ -49,7 +49,7 @@ public class MapGenerator extends Generator{
for(Tile tile : tiles){ for(Tile tile : tiles){
if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && world.getSector() != null){ 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)){ if(content instanceof Item && Mathf.chance(0.3)){
tile.entity.items().add((Item)content, Math.min(Mathf.random(500), tile.block().itemCapacity)); tile.entity.items().add((Item)content, Math.min(Mathf.random(500), tile.block().itemCapacity));
} }

View File

@ -65,7 +65,6 @@ public class TestPlanetGenerator implements PlanetGenerator{
height *= 1.2f; height *= 1.2f;
height = Mathf.clamp(height); 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)]; return arr[Mathf.clamp((int)(temp * arr.length), 0, arr.length - 1)][Mathf.clamp((int)(height * arr[0].length), 0, arr[0].length - 1)];
} }
} }

View File

@ -3,10 +3,10 @@ package mindustry.mod;
import arc.*; import arc.*;
import arc.assets.*; import arc.assets.*;
import arc.audio.*; import arc.audio.*;
import arc.audio.mock.*;
import arc.files.*; import arc.files.*;
import arc.func.*; import arc.func.*;
import arc.graphics.*; import arc.graphics.*;
import arc.mock.MockSound;
import arc.struct.Array; import arc.struct.Array;
import arc.struct.*; import arc.struct.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;

View File

@ -1,8 +1,8 @@
package mindustry.mod; package mindustry.mod;
import arc.audio.*; import arc.audio.*;
import arc.audio.mock.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.mock.MockSound;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
public class ModLoadingSound implements Sound{ public class ModLoadingSound implements Sound{

View File

@ -1,14 +1,18 @@
package mindustry.type; package mindustry.type;
import arc.files.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import arc.struct.*; import arc.struct.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*; import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.graphics.PlanetGrid.*; import mindustry.graphics.PlanetGrid.*;
import mindustry.maps.planet.*; import mindustry.maps.planet.*;
import mindustry.type.Sector.*;
public class Planet extends UnlockableContent{ public class Planet extends UnlockableContent{
/** Mesh used for rendering. Created on load() - will be null on the server! */ /** 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; this.size = 3;
grid = PlanetGrid.newGrid(size); grid = PlanetGrid.newGrid(size);
sectors = new Array<>(grid.tiles.length); sectors = new Array<>(grid.tiles.length);
for(int i = 0; i < grid.tiles.length; i++){ 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.");
} }
} }

View File

@ -2,10 +2,11 @@ package mindustry.type;
import arc.math.geom.*; import arc.math.geom.*;
import arc.util.*; import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.graphics.PlanetGrid.*; import mindustry.graphics.PlanetGrid.*;
import mindustry.world.*;
import static mindustry.Vars.state;
/** A small section of a planet. */ /** A small section of a planet. */
public class Sector{ public class Sector{
@ -14,16 +15,16 @@ public class Sector{
public final Ptile tile; public final Ptile tile;
public final int id; public final int id;
//TODO generate a class file with 2D arrays of resources for each sector for each planet public final SectorData data;
public final Content[] resources = {};
//TODO implement a dynamic (?) launch period //TODO implement a dynamic (?) launch period
public int launchPeriod = 10; public int launchPeriod = 10;
public Sector(Planet planet, Ptile tile){ public Sector(Planet planet, Ptile tile, SectorData data){
this.planet = planet; this.planet = planet;
this.tile = tile; this.tile = tile;
this.rect = makeRect(); this.rect = makeRect();
this.id = tile.id; this.id = tile.id;
this.data = data;
} }
//TODO implement //TODO implement
@ -31,7 +32,6 @@ public class Sector{
return metCondition() && wave % launchPeriod == 0; return metCondition() && wave % launchPeriod == 0;
} }
public boolean metCondition(){ public boolean metCondition(){
//TODO implement //TODO implement
return false; return false;
@ -83,4 +83,43 @@ public class Sector{
return result.set(center).add(right, nx).add(top, ny); 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();
}
}
}
} }

View File

@ -344,6 +344,13 @@ task genSprites(dependsOn: classes, type: JavaExec){
workingDir = genFolder 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){ task updateBundles(dependsOn: classes, type: JavaExec){
file(genFolder).mkdirs() file(genFolder).mkdirs()

View File

@ -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.<Planet>getBy(ContentType.planet)){
int[] count = {0};
Fi fi = Fi.get("planets").child(planet.name + ".dat");
Array<SectorData> list = planet.sectors.map(sector -> {
SectorData data = new SectorData();
ObjectIntMap<Block> floors = new ObjectIntMap<>();
ObjectSet<Content> 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<ObjectIntMap.Entry<Block>> 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));
}
}
}
}