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