Fixed multiple bugs, made multithreading work more properly
This commit is contained in:
@@ -172,7 +172,7 @@ public class Control extends Module{
|
||||
|
||||
int last = Settings.getInt("hiscore" + world.getMap().name);
|
||||
|
||||
if(state.wave > last && !state.mode.infiniteResources && !state.mode.toggleWaves){
|
||||
if(state.wave > last && !state.mode.infiniteResources && !state.mode.disableWaveTimer){
|
||||
Settings.putInt("hiscore" + world.getMap().name, state.wave);
|
||||
Settings.save();
|
||||
hiscore = true;
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.anuke.mindustry.game.EnemySpawn;
|
||||
import io.anuke.mindustry.game.EventType.GameOverEvent;
|
||||
import io.anuke.mindustry.game.EventType.PlayEvent;
|
||||
import io.anuke.mindustry.game.EventType.ResetEvent;
|
||||
import io.anuke.mindustry.game.EventType.WaveEvent;
|
||||
import io.anuke.mindustry.game.SpawnPoint;
|
||||
import io.anuke.mindustry.game.WaveCreator;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
@@ -102,6 +103,8 @@ public class Logic extends Module {
|
||||
state.wave ++;
|
||||
state.wavetime = wavespace * state.difficulty.timeScaling;
|
||||
state.extrawavetime = maxwavespace * state.difficulty.maxTimeScaling;
|
||||
|
||||
Events.fire(WaveEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,7 +119,7 @@ public class Logic extends Module {
|
||||
if(!Net.client())
|
||||
world.pathfinder().update();
|
||||
|
||||
if(world.getCore().block() != ProductionBlocks.core && !state.gameOver){
|
||||
if(world.getCore() != null && world.getCore().block() != ProductionBlocks.core && !state.gameOver){
|
||||
state.gameOver = true;
|
||||
NetEvents.handleGameOver();
|
||||
Events.fire(GameOverEvent.class);
|
||||
@@ -124,7 +127,7 @@ public class Logic extends Module {
|
||||
|
||||
if(!state.is(State.paused) || Net.active()){
|
||||
|
||||
if(!state.mode.toggleWaves){
|
||||
if(!state.mode.disableWaveTimer){
|
||||
|
||||
if(state.enemies <= 0){
|
||||
state.wavetime -= delta();
|
||||
|
||||
@@ -9,11 +9,12 @@ import static io.anuke.mindustry.Vars.logic;
|
||||
|
||||
public class ThreadHandler {
|
||||
private final ThreadProvider impl;
|
||||
private final Object lock = new Object();
|
||||
private float delta = 1f;
|
||||
private boolean finished;
|
||||
private boolean enabled;
|
||||
|
||||
private final Object updateLock = new Object();
|
||||
private boolean rendered = true;
|
||||
|
||||
public ThreadHandler(ThreadProvider impl){
|
||||
this.impl = impl;
|
||||
|
||||
@@ -21,21 +22,28 @@ public class ThreadHandler {
|
||||
}
|
||||
|
||||
public void handleRender(){
|
||||
synchronized(lock) {
|
||||
finished = true;
|
||||
lock.notify();
|
||||
if(!enabled) return;
|
||||
|
||||
synchronized (updateLock) {
|
||||
rendered = true;
|
||||
updateLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled){
|
||||
if(enabled){
|
||||
logic.doUpdate = false;
|
||||
Timers.runTask(2f, () -> impl.start(this::runLogic));
|
||||
Timers.runTask(2f, () -> {
|
||||
impl.start(this::runLogic);
|
||||
this.enabled = true;
|
||||
});
|
||||
}else{
|
||||
this.enabled = false;
|
||||
impl.stop();
|
||||
Timers.runTask(2f, () -> logic.doUpdate = true);
|
||||
Timers.runTask(2f, () -> {
|
||||
logic.doUpdate = true;
|
||||
});
|
||||
}
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isEnabled(){
|
||||
@@ -57,11 +65,11 @@ public class ThreadHandler {
|
||||
impl.sleep(target - elapsed);
|
||||
}
|
||||
|
||||
synchronized(lock) {
|
||||
while(!finished) {
|
||||
lock.wait();
|
||||
synchronized(updateLock) {
|
||||
while(!rendered) {
|
||||
updateLock.wait();
|
||||
}
|
||||
finished = false;
|
||||
rendered = false;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
|
||||
@@ -7,16 +7,16 @@ public enum GameMode{
|
||||
sandbox{
|
||||
{
|
||||
infiniteResources = true;
|
||||
toggleWaves = true;
|
||||
disableWaveTimer = true;
|
||||
}
|
||||
},
|
||||
freebuild{
|
||||
{
|
||||
toggleWaves = true;
|
||||
disableWaveTimer = true;
|
||||
}
|
||||
};
|
||||
public boolean infiniteResources;
|
||||
public boolean toggleWaves;
|
||||
public boolean disableWaveTimer;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
|
||||
@@ -139,14 +139,14 @@ public abstract class InputHandler extends InputAdapter{
|
||||
for(int dx = 0; dx < type.width; dx ++){
|
||||
for(int dy = 0; dy < type.height; dy ++){
|
||||
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
|
||||
if(other == null || other.block() != Blocks.air || isSpawnPoint(other)){
|
||||
if(other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) || isSpawnPoint(other)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
if(tile.block() != type && type.canReplace(tile.block()) && tile.block().isMultiblock() == type.isMultiblock()){
|
||||
if(tile.block() != type && (type.canReplace(tile.block()) || tile.block().alwaysReplace) && tile.block().isMultiblock() == type.isMultiblock()){
|
||||
return true;
|
||||
}
|
||||
return tile.block() == Blocks.air;
|
||||
|
||||
@@ -179,7 +179,7 @@ public class HudFragment implements Fragment{
|
||||
|
||||
new label(()-> state.enemies > 0 ?
|
||||
getEnemiesRemaining() :
|
||||
(control.tutorial().active() || state.mode.toggleWaves) ? "$text.waiting"
|
||||
(control.tutorial().active() || state.mode.disableWaveTimer) ? "$text.waiting"
|
||||
: Bundles.format("text.wave.waiting", (int) (state.wavetime / 60f)))
|
||||
.minWidth(126).padLeft(-6).padRight(-12).left();
|
||||
|
||||
|
||||
@@ -87,6 +87,8 @@ public class Block{
|
||||
public Layer layer2 = null;
|
||||
/**list of displayed block status bars. Defaults to health bar.*/
|
||||
public Array<BlockBar> bars = Array.with(new BlockBar(Color.RED, false, tile -> tile.entity.health / (float)tile.block().health));
|
||||
/**whether this block can be replaced in all cases*/
|
||||
public boolean alwaysReplace = false;
|
||||
|
||||
public Block(String name) {
|
||||
this.name = name;
|
||||
|
||||
@@ -9,5 +9,6 @@ public class Rock extends Block {
|
||||
shadow = name+"shadow";
|
||||
breakable = true;
|
||||
breaktime = 10;
|
||||
alwaysReplace = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public class Conveyor extends Block{
|
||||
private static ItemPos drawpos = new ItemPos();
|
||||
private static ItemPos pos1 = new ItemPos();
|
||||
private static ItemPos pos2 = new ItemPos();
|
||||
private static LongArray removals = new LongArray();
|
||||
private static final float itemSpace = 0.135f;
|
||||
private static final float offsetScl = 128f*3f;
|
||||
private static final float itemSize = 4f;
|
||||
@@ -93,9 +92,8 @@ public class Conveyor extends Block{
|
||||
ConveyorEntity entity = tile.entity();
|
||||
entity.minitem = 1f;
|
||||
|
||||
removals.clear();
|
||||
|
||||
float shift = entity.elapsed * speed;
|
||||
int minremove = Integer.MAX_VALUE;
|
||||
|
||||
for(int i = 0; i < entity.convey.size; i ++){
|
||||
long value = entity.convey.get(i);
|
||||
@@ -103,9 +101,10 @@ public class Conveyor extends Block{
|
||||
|
||||
pos.y += shift;
|
||||
|
||||
//..this should never happen, but in case it does, remove it and stop here
|
||||
if(pos.item == null){
|
||||
removals.add(value);
|
||||
continue;
|
||||
entity.convey.removeValue(value);
|
||||
break;
|
||||
}
|
||||
|
||||
float nextpos = (i == entity.convey.size - 1 ? 100f : pos2.set(entity.convey.get(i + 1)).y) - itemSpace;
|
||||
@@ -121,7 +120,7 @@ public class Conveyor extends Block{
|
||||
pos.y = Mathf.clamp(pos.y);
|
||||
|
||||
if(pos.y >= 0.9999f && offloadDir(tile, pos.item)){
|
||||
removals.add(value);
|
||||
minremove = Math.min(i, minremove);
|
||||
}else{
|
||||
value = pos.pack();
|
||||
|
||||
@@ -133,7 +132,7 @@ public class Conveyor extends Block{
|
||||
}
|
||||
|
||||
entity.elapsed = 0f;
|
||||
entity.convey.removeAll(removals);
|
||||
if(minremove != Integer.MAX_VALUE) entity.convey.truncate(minremove);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,7 +155,6 @@ public class Conveyor extends Block{
|
||||
int ch = Math.abs(source.relativeTo(tile.x, tile.y) - rotation);
|
||||
int ang = ((source.relativeTo(tile.x, tile.y) - rotation));
|
||||
|
||||
|
||||
float pos = ch == 0 ? 0 : ch % 2 == 1 ? 0.5f : 1f;
|
||||
float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user