Synced puddles, updated uCore
This commit is contained in:
@@ -149,9 +149,9 @@ public class Vars{
|
||||
shieldGroup = Entities.addGroup(Shield.class, false);
|
||||
effectGroup = Entities.addGroup(EffectEntity.class, false);
|
||||
groundEffectGroup = Entities.addGroup(DrawTrait.class, false);
|
||||
puddleGroup = Entities.addGroup(Puddle.class, false);
|
||||
puddleGroup = Entities.addGroup(Puddle.class, false).enableMapping();
|
||||
itemGroup = Entities.addGroup(ItemDrop.class).enableMapping();
|
||||
fireGroup = Entities.addGroup(Fire.class, false);
|
||||
fireGroup = Entities.addGroup(Fire.class, false).enableMapping();
|
||||
unitGroups = new EntityGroup[Team.values().length];
|
||||
|
||||
threads = new ThreadHandler(Platform.instance.getThreadProvider());
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.entities.traits.*;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -224,7 +225,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
public void applyEffect(StatusEffect effect, float intensity){
|
||||
if(dead) return;
|
||||
if(dead || Net.client()) return; //effects are synced and thus not applied through clients
|
||||
status.handleApply(this, effect, intensity);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable
|
||||
|
||||
/**Start a fire on the tile. If there already is a file there, refreshes its lifetime.*/
|
||||
public static void create(Tile tile){
|
||||
if(Net.client()) return; //not clientside.
|
||||
|
||||
Fire fire = map.get(tile.packedPosition());
|
||||
|
||||
if(fire == null){
|
||||
@@ -59,8 +61,8 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable
|
||||
}
|
||||
|
||||
/**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){
|
||||
if(map.containsKey(tile.packedPosition())){
|
||||
public static void extinguish(Tile tile, float intensity) {
|
||||
if (map.containsKey(tile.packedPosition())) {
|
||||
map.get(tile.packedPosition()).time += intensity * Timers.delta();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.content.bullets.TurretBullets;
|
||||
@@ -14,6 +16,8 @@ import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.net.In;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -32,8 +36,7 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.puddleGroup;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait {
|
||||
private static final IntMap<Puddle> map = new IntMap<>();
|
||||
@@ -45,10 +48,11 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
private static int seeds;
|
||||
|
||||
private int loadedPosition = -1;
|
||||
|
||||
private Tile tile;
|
||||
private Liquid liquid;
|
||||
private float amount;
|
||||
private int generation;
|
||||
private byte generation;
|
||||
private float accepting;
|
||||
|
||||
/**Deposists a puddle between tile and source.*/
|
||||
@@ -80,11 +84,13 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
|
||||
Puddle p = map.get(tile.packedPosition());
|
||||
if(p == null){
|
||||
if(Net.client()) return; //not clientside.
|
||||
|
||||
Puddle puddle = Pools.obtain(Puddle.class);
|
||||
puddle.tile = tile;
|
||||
puddle.liquid = liquid;
|
||||
puddle.amount = amount;
|
||||
puddle.generation = generation;
|
||||
puddle.generation = (byte)generation;
|
||||
puddle.set((tile.worldx() + source.worldx())/2f, (tile.worldy() + source.worldy())/2f);
|
||||
puddle.add();
|
||||
map.put(tile.packedPosition(), puddle);
|
||||
@@ -136,6 +142,26 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if(amount >= maxLiquid/2f && Timers.get(this, "update", 20)){
|
||||
Units.getNearby(rect.setSize(Mathf.clamp(amount/(maxLiquid/1.5f))*10f).setCenter(tile.worldx(), tile.worldy()), unit -> {
|
||||
unit.getHitbox(rect2);
|
||||
if(!rect.overlaps(rect2)) return;
|
||||
|
||||
unit.applyEffect(liquid.effect, 0.5f);
|
||||
|
||||
if(unit.getVelocity().len() > 0.4) {
|
||||
Effects.effect(BlockFx.ripple, liquid.color, unit.x, unit.y);
|
||||
}
|
||||
});
|
||||
|
||||
if(liquid.temperature > 0.7f && tile.entity != null && Mathf.chance(0.3 * Timers.delta())){
|
||||
Fire.create(tile);
|
||||
}
|
||||
}
|
||||
|
||||
//no updating happens clientside
|
||||
if(Net.client()) return;
|
||||
|
||||
float addSpeed = accepting > 0 ? 3f : 0f;
|
||||
|
||||
amount -= Timers.delta() * (1f - liquid.viscosity) /(5f+addSpeed);
|
||||
@@ -154,26 +180,10 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
}
|
||||
}
|
||||
|
||||
if(amount >= maxLiquid/2f && Timers.get(this, "update", 20)){
|
||||
Units.getNearby(rect.setSize(Mathf.clamp(amount/(maxLiquid/1.5f))*10f).setCenter(tile.worldx(), tile.worldy()), unit -> {
|
||||
unit.getHitbox(rect2);
|
||||
if(!rect.overlaps(rect2)) return;
|
||||
|
||||
unit.applyEffect(liquid.effect, 0.5f);
|
||||
if(unit.getVelocity().len() > 0.4) {
|
||||
Effects.effect(BlockFx.ripple, liquid.color, unit.x, unit.y);
|
||||
}
|
||||
});
|
||||
|
||||
if(liquid.temperature > 0.7f && tile.entity != null && Mathf.chance(0.3 * Timers.delta())){
|
||||
Fire.create(tile);
|
||||
}
|
||||
}
|
||||
|
||||
amount = Mathf.clamp(amount, 0, maxLiquid);
|
||||
|
||||
if(amount <= 0f){
|
||||
remove();
|
||||
CallEntity.onPuddleRemoved(getID());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,4 +259,9 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
public EntityGroup targetGroup() {
|
||||
return puddleGroup;
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, in = In.entities)
|
||||
public static void onPuddleRemoved(int puddleid){
|
||||
puddleGroup.removeByID(puddleid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user