GC retention fixes
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package mindustry.entities;
|
package mindustry.entities;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.math.geom.*;
|
|
||||||
import arc.struct.*;
|
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
@@ -14,13 +12,12 @@ import static mindustry.Vars.*;
|
|||||||
|
|
||||||
public class Fires{
|
public class Fires{
|
||||||
private static final float baseLifetime = 1000f;
|
private static final float baseLifetime = 1000f;
|
||||||
private static final IntMap<Fire> map = new IntMap<>();
|
|
||||||
|
|
||||||
/** Start a fire on the tile. If there already is a fire there, refreshes its lifetime. */
|
/** Start a fire on the tile. If there already is a fire there, refreshes its lifetime. */
|
||||||
public static void create(Tile tile){
|
public static void create(Tile tile){
|
||||||
if(net.client() || tile == null || !state.rules.fire || !state.rules.hasEnv(Env.oxygen)) return; //not clientside.
|
if(net.client() || tile == null || !state.rules.fire || !state.rules.hasEnv(Env.oxygen)) return; //not clientside.
|
||||||
|
|
||||||
Fire fire = map.get(tile.pos());
|
Fire fire = get(tile);
|
||||||
|
|
||||||
if(fire == null){
|
if(fire == null){
|
||||||
fire = Fire.create();
|
fire = Fire.create();
|
||||||
@@ -28,31 +25,40 @@ public class Fires{
|
|||||||
fire.lifetime = baseLifetime;
|
fire.lifetime = baseLifetime;
|
||||||
fire.set(tile.worldx(), tile.worldy());
|
fire.set(tile.worldx(), tile.worldy());
|
||||||
fire.add();
|
fire.add();
|
||||||
map.put(tile.pos(), fire);
|
set(tile, fire);
|
||||||
}else{
|
}else{
|
||||||
fire.lifetime = baseLifetime;
|
fire.lifetime = baseLifetime;
|
||||||
fire.time = 0f;
|
fire.time = 0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Fire get(int x, int y){
|
public static @Nullable Fire get(Tile tile){
|
||||||
return map.get(Point2.pack(x, y));
|
return world.tiles.getFire(tile.array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable Fire get(int x, int y){
|
||||||
|
return world.tiles.getFire(world.packArray(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void set(Tile tile, Fire fire){
|
||||||
|
world.tiles.setFire(tile.array(), fire);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean has(int x, int y){
|
public static boolean has(int x, int y){
|
||||||
if(!Structs.inBounds(x, y, world.width(), world.height()) || !map.containsKey(Point2.pack(x, y))){
|
if(!Structs.inBounds(x, y, world.width(), world.height())){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Fire fire = map.get(Point2.pack(x, y));
|
Fire fire = get(x, y);
|
||||||
return fire.isAdded() && fire.fin() < 1f && fire.tile() != null && fire.tile().x == x && fire.tile().y == y;
|
return fire != null && fire.isAdded() && fire.fin() < 1f && fire.tile != null && fire.tile.x == x && fire.tile.y == y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to extinguish a fire by shortening its life. If there is no fire here, does nothing.
|
* Attempts to extinguish a fire by shortening its life. If there is no fire here, does nothing.
|
||||||
*/
|
*/
|
||||||
public static void extinguish(Tile tile, float intensity){
|
public static void extinguish(Tile tile, float intensity){
|
||||||
if(tile != null && map.containsKey(tile.pos())){
|
if(tile != null){
|
||||||
Fire fire = map.get(tile.pos());
|
Fire fire = get(tile);
|
||||||
|
if(fire != null){
|
||||||
fire.time(fire.time + intensity * Time.delta);
|
fire.time(fire.time + intensity * Time.delta);
|
||||||
Fx.steam.at(fire);
|
Fx.steam.at(fire);
|
||||||
if(fire.time >= fire.lifetime){
|
if(fire.time >= fire.lifetime){
|
||||||
@@ -60,16 +66,17 @@ public class Fires{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void remove(Tile tile){
|
public static void remove(Tile tile){
|
||||||
if(tile != null){
|
if(tile != null){
|
||||||
map.remove(tile.pos());
|
set(tile, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(Fire fire){
|
public static void register(Fire fire){
|
||||||
if(fire.tile != null){
|
if(fire.tile != null){
|
||||||
map.put(fire.tile.pos(), fire);
|
set(fire.tile, fire);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ public class Puddles{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the Puddle on the specified tile. May return null. */
|
/** Returns the Puddle on the specified tile. May return null. */
|
||||||
public static Puddle get(Tile tile){
|
public static @Nullable Puddle get(Tile tile){
|
||||||
return world.tiles.puddle(tile.array());
|
return world.tiles.getPuddle(tile.array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deposit(Tile tile, Tile source, Liquid liquid, float amount, boolean initial){
|
public static void deposit(Tile tile, Tile source, Liquid liquid, float amount, boolean initial){
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
|||||||
if(!unit.isNull()){
|
if(!unit.isNull()){
|
||||||
clearUnit();
|
clearUnit();
|
||||||
}
|
}
|
||||||
|
lastReadUnit = justSwitchTo = justSwitchFrom = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void team(Team team){
|
public void team(Team team){
|
||||||
|
|||||||
@@ -14,15 +14,17 @@ public class Tiles implements Iterable<Tile>{
|
|||||||
|
|
||||||
final Tile[] array;
|
final Tile[] array;
|
||||||
final Puddle[] puddles;
|
final Puddle[] puddles;
|
||||||
|
final Fire[] fires;
|
||||||
|
|
||||||
public Tiles(int width, int height){
|
public Tiles(int width, int height){
|
||||||
this.array = new Tile[width * height];
|
this.array = new Tile[width * height];
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.puddles = new Puddle[width * height];
|
this.puddles = new Puddle[width * height];
|
||||||
|
this.fires = new Fire[width * height];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Puddle puddle(int pos){
|
public Puddle getPuddle(int pos){
|
||||||
return puddles[pos];
|
return puddles[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +32,15 @@ public class Tiles implements Iterable<Tile>{
|
|||||||
puddles[pos] = p;
|
puddles[pos] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Fire getFire(int pos){
|
||||||
|
return fires[pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFire(int pos, Fire f){
|
||||||
|
fires[pos] = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void each(Intc2 cons){
|
public void each(Intc2 cons){
|
||||||
for(int x = 0; x < width; x++){
|
for(int x = 0; x < width; x++){
|
||||||
for(int y = 0; y < height; y++){
|
for(int y = 0; y < height; y++){
|
||||||
|
|||||||
Reference in New Issue
Block a user