This commit is contained in:
Anuken 2020-03-13 22:33:37 -04:00
parent 06e94b1800
commit 808615a77c
19 changed files with 102 additions and 27 deletions

View File

@ -115,13 +115,13 @@ public class BlockIndexer{
if(structQuadrants == null) return;
//go through every tile... ouch
for(Tile tile : world.tiles){
world.tiles.each(tile -> {
if(tile.team() == team){
int quadrantX = tile.x / quadrantSize;
int quadrantY = tile.y / quadrantSize;
structQuadrant(team).set(quadrantX, quadrantY);
}
}
});
}
/** @return whether this item is present on this map.*/

View File

@ -19,6 +19,7 @@ import mindustry.world.blocks.defense.*;
import mindustry.world.blocks.defense.turrets.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.blocks.environment.*;
import mindustry.world.blocks.legacy.*;
import mindustry.world.blocks.liquid.*;
import mindustry.world.blocks.logic.*;
import mindustry.world.blocks.power.*;
@ -1863,6 +1864,12 @@ public class Blocks implements ContentList{
consumes.power(0.05f);
}};
//endregion
//region legacy
//looked up by name, no ref needed
new LegacyMechPad("legacy-mech-pad");
//endregion
}
}

View File

@ -19,6 +19,7 @@ import mindustry.maps.filters.*;
import mindustry.maps.filters.GenerateFilter.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.legacy.*;
import static mindustry.Vars.*;
@ -172,6 +173,12 @@ public class World{
prepareTiles(tiles);
for(Tile tile : tiles){
//remove legacy blocks; they need to stop existing
if(tile.block() instanceof LegacyBlock){
tile.remove();
continue;
}
tile.updateOcclusion();
if(tile.entity != null){
@ -447,8 +454,8 @@ public class World{
private class Context implements WorldContext{
@Override
public Tile tile(int x, int y){
return tiles.get(x, y);
public Tile tile(int index){
return tiles.geti(index);
}
@Override

View File

@ -292,8 +292,8 @@ public class MapEditor{
class Context implements WorldContext{
@Override
public Tile tile(int x, int y){
return world.tile(x, y);
public Tile tile(int index){
return world.tiles.geti(index);
}
@Override

View File

@ -126,7 +126,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
if(tile != null){
//unit block update
if(tile.entity != null){
if(tile.entity != null && isGrounded()){
tile.entity.unitOn(this);
}

View File

@ -104,9 +104,9 @@ public class MapIO{
@Override public void end(){}
@Override
public Tile tile(int x, int y){
tile.x = (short)x;
tile.y = (short)y;
public Tile tile(int index){
tile.x = (short)(index % map.width);
tile.y = (short)(index / map.width);
return tile;
}

View File

@ -13,7 +13,15 @@ public abstract class SaveFileReader{
protected final ReusableByteOutStream byteOutputSmall = new ReusableByteOutStream();
protected final DataOutputStream dataBytesSmall = new DataOutputStream(byteOutputSmall);
protected final ObjectMap<String, String> fallback = ObjectMap.of(
"dart-mech-pad", "dart-ship-pad"
"dart-mech-pad", "legacy-mech-pad",
"dart-ship-pad", "legacy-mech-pad",
"javelin-ship-pad", "legacy-mech-pad",
"trident-ship-pad", "legacy-mech-pad",
"glaive-ship-pad", "legacy-mech-pad",
"alpha-mech-pad", "legacy-mech-pad",
"tau-mech-pad", "legacy-mech-pad",
"omega-mech-pad", "legacy-mech-pad",
"delta-mech-pad", "legacy-mech-pad"
);
protected void region(String name, DataInput stream, CounterInputStream counter, IORunner<DataInput> cons) throws IOException{

View File

@ -186,7 +186,7 @@ public abstract class SaveVersion extends SaveFileReader{
for(int i = 0; i < width * height; i++){
int x = i % width, y = i / width;
Block block = content.block(stream.readShort());
Tile tile = context.tile(x, y);
Tile tile = context.tile(i);
if(block == null) block = Blocks.air;
boolean isCenter = true;
@ -214,8 +214,7 @@ public abstract class SaveVersion extends SaveFileReader{
int consecutives = stream.readUnsignedByte();
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
context.tile(newx, newy).setBlock(block);
context.tile(j).setBlock(block);
}
i += consecutives;

View File

@ -49,13 +49,12 @@ public abstract class LegacySaveVersion extends SaveVersion{
//read blocks
for(int i = 0; i < width * height; i++){
int x = i % width, y = i / width;
Block block = content.block(stream.readShort());
Tile tile = context.tile(x, y);
Tile tile = context.tile(i);
if(block == null) block = Blocks.air;
//occupied by multiblock part
boolean occupied = tile.entity != null && !tile.isCenter();
boolean occupied = tile.entity != null && !tile.isCenter() && (tile.entity.block() == block || block == Blocks.air);
//do not override occupied cells
if(!occupied){
@ -92,8 +91,7 @@ public abstract class LegacySaveVersion extends SaveVersion{
//air is a waste of time and may mess up multiblocks
if(block != Blocks.air){
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
context.tile(newx, newy).setBlock(block);
context.tile(j).setBlock(block);
}
}

View File

@ -8,6 +8,7 @@ import java.io.*;
import static mindustry.Vars.content;
public class Save3 extends LegacySaveVersion{
public Save3(){
super(3);
}

View File

@ -173,6 +173,8 @@ public class Tile implements Position{
if(block.isMultiblock()){
int offsetx = -(block.size - 1) / 2;
int offsety = -(block.size - 1) / 2;
Tilec entity = this.entity;
Block block = this.block;
//two passes: first one clears, second one sets
for(int pass = 0; pass < 2; pass++){
@ -198,6 +200,9 @@ public class Tile implements Position{
}
}
}
this.entity = entity;
this.block = block;
}
}

View File

@ -65,8 +65,18 @@ public class Tiles implements Iterable<Tile>{
return get(Point2.x(pos), Point2.y(pos));
}
public void each(Cons<Tile> cons){
for(Tile tile : array){
cons.get(tile);
}
}
@Override
public Iterator<Tile> iterator(){
if(iterator.index != 0 && iterator.index != array.length){
iterator.index = 0;
throw new IllegalArgumentException("Double iteration. " + iterator.index + " != " + array.length);
}
iterator.index = 0;
return iterator;
}

View File

@ -3,7 +3,7 @@ package mindustry.world;
public interface WorldContext{
/** Return a tile in the tile array.*/
Tile tile(int x, int y);
Tile tile(int index);
/** Create the tile array.*/
void resize(int width, int height);

View File

@ -118,11 +118,15 @@ public class Conveyor extends Block implements Autotiler{
int blendbits;
int blendsclx, blendscly;
boolean everupdated = false;
float clogHeat = 0f;
@Override
public void draw(){
if(!everupdated){
Log.info("--DID NOT UPDATE {0}", tile);
}
byte rotation = tile.rotation();
int frame = clogHeat <= 0.5f ? (int)(((Time.time() * speed * 8f * timeScale())) % 4) : 0;
Draw.rect(regions[Mathf.clamp(blendbits, 0, regions.length - 1)][Mathf.clamp(frame, 0, regions[0].length - 1)], x, y,
@ -142,6 +146,7 @@ public class Conveyor extends Block implements Autotiler{
blendbits = bits[0];
blendsclx = bits[1];
blendscly = bits[2];
everupdated = true;
if(tile.front() != null && tile.front() != null){
next = tile.front();

View File

@ -0,0 +1,11 @@
package mindustry.world.blocks.legacy;
import mindustry.world.*;
/** Any subclass of this will be removed upon world load. */
public class LegacyBlock extends Block{
public LegacyBlock(String name){
super(name);
}
}

View File

@ -0,0 +1,25 @@
package mindustry.world.blocks.legacy;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.world.*;
public class LegacyMechPad extends Block{
public LegacyMechPad(String name){
super(name);
update = true;
}
public class LegacyMechPadEntity extends TileEntity{
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
//read 3 floats for pad data, and discard them
read.f();
read.f();
read.f();
}
}
}

View File

@ -204,7 +204,7 @@ public class Drill extends Block{
float progress;
int index;
float warmup;
float drillTime;
float timeDrilled;
float lastDrillSpeed;
int dominantItems;
@ -249,7 +249,7 @@ public class Drill extends Block{
dump(dominantItem);
}
drillTime += warmup * delta();
timeDrilled += warmup * delta();
if(items.total() < itemCapacity && dominantItems > 0 && consValid()){
@ -263,8 +263,7 @@ public class Drill extends Block{
lastDrillSpeed = (speed * dominantItems * warmup) / (drillTime + hardnessDrillMultiplier * dominantItem.hardness);
warmup = Mathf.lerpDelta(warmup, speed, warmupSpeed);
progress += delta()
* dominantItems * speed * warmup;
progress += delta() * dominantItems * speed * warmup;
if(Mathf.chance(Time.delta() * updateEffectChance * warmup))
updateEffect.at(getX() + Mathf.range(size * 2f), getY() + Mathf.range(size * 2f));
@ -305,7 +304,7 @@ public class Drill extends Block{
Draw.color();
}
Draw.rect(rotatorRegion, x, y, drillTime * rotateSpeed);
Draw.rect(rotatorRegion, x, y, timeDrilled * rotateSpeed);
Draw.rect(topRegion, x, y);

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=3c2fae9b66b6affc1ba6701cce19ca9625c5e1b1
archash=3a72937157113d8a5cd44bcc0b296c50e316c941

View File

@ -36,7 +36,7 @@ task debug(dependsOn: classes, type: JavaExec){
task dist(type: Jar){
from files(sourceSets.main.output.classesDirs)
from files(sourceSets.main.output.resourcesDir)
from{ configurations.compile.collect{ zipTree(it) } }
from {configurations.compile.collect{ it.isDirectory() ? it : zipTree(it) }}
from files(project.assetsDir)
exclude("sprites/**")
exclude("music/**")