Added toggleable syncing
This commit is contained in:
@@ -147,7 +147,7 @@ public class Vars{
|
|||||||
|
|
||||||
playerGroup = Entities.addGroup(Player.class).enableMapping();
|
playerGroup = Entities.addGroup(Player.class).enableMapping();
|
||||||
tileGroup = Entities.addGroup(TileEntity.class, false);
|
tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||||
bulletGroup = Entities.addGroup(Bullet.class);
|
bulletGroup = Entities.addGroup(Bullet.class).enableMapping();
|
||||||
shieldGroup = Entities.addGroup(Shield.class, false);
|
shieldGroup = Entities.addGroup(Shield.class, false);
|
||||||
effectGroup = Entities.addGroup(EffectEntity.class, false);
|
effectGroup = Entities.addGroup(EffectEntity.class, false);
|
||||||
groundEffectGroup = Entities.addGroup(DrawTrait.class, false);
|
groundEffectGroup = Entities.addGroup(DrawTrait.class, false);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import io.anuke.mindustry.content.blocks.*;
|
|||||||
import io.anuke.mindustry.content.bullets.*;
|
import io.anuke.mindustry.content.bullets.*;
|
||||||
import io.anuke.mindustry.content.fx.*;
|
import io.anuke.mindustry.content.fx.*;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
|
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||||
import io.anuke.mindustry.entities.effect.Fire;
|
import io.anuke.mindustry.entities.effect.Fire;
|
||||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||||
@@ -136,5 +137,6 @@ public class ContentLoader {
|
|||||||
ItemDrop.typeID = TypeTrait.registerType(ItemDrop::new);
|
ItemDrop.typeID = TypeTrait.registerType(ItemDrop::new);
|
||||||
Fire.typeID = TypeTrait.registerType(Fire::new);
|
Fire.typeID = TypeTrait.registerType(Fire::new);
|
||||||
Puddle.typeID = TypeTrait.registerType(Puddle::new);
|
Puddle.typeID = TypeTrait.registerType(Puddle::new);
|
||||||
|
Bullet.typeID = TypeTrait.registerType(Bullet::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,11 +351,21 @@ public class NetServer extends Module{
|
|||||||
throw new RuntimeException("Entity group '" + group.getType() + "' contains SyncTrait entities, yet mapping is not enabled. In order for syncing to work, you must enable mapping for this group.");
|
throw new RuntimeException("Entity group '" + group.getType() + "' contains SyncTrait entities, yet mapping is not enabled. In order for syncing to work, you must enable mapping for this group.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//write group ID + group size
|
int amount = 0;
|
||||||
dataStream.writeByte(group.getID());
|
|
||||||
dataStream.writeShort(group.size());
|
|
||||||
|
|
||||||
for(Entity entity : group.all()){
|
for(Entity entity : group.all()){
|
||||||
|
if(((SyncTrait)entity).isSyncing()){
|
||||||
|
amount ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//write group ID + group sizeif(((SyncTrait)entity).isSyncing())
|
||||||
|
dataStream.writeByte(group.getID());
|
||||||
|
dataStream.writeShort(amount);
|
||||||
|
|
||||||
|
for(Entity entity : group.all()){
|
||||||
|
if(!((SyncTrait)entity).isSyncing()) continue;;
|
||||||
|
|
||||||
int position = syncStream.position();
|
int position = syncStream.position();
|
||||||
//write all entities now
|
//write all entities now
|
||||||
dataStream.writeInt(entity.getID()); //write id
|
dataStream.writeInt(entity.getID()); //write id
|
||||||
|
|||||||
@@ -200,7 +200,6 @@ public class Renderer extends RendererModule{
|
|||||||
EntityDraw.draw(groundEffectGroup, e -> e instanceof BelowLiquidTrait);
|
EntityDraw.draw(groundEffectGroup, e -> e instanceof BelowLiquidTrait);
|
||||||
EntityDraw.draw(puddleGroup);
|
EntityDraw.draw(puddleGroup);
|
||||||
EntityDraw.draw(groundEffectGroup, e -> !(e instanceof BelowLiquidTrait));
|
EntityDraw.draw(groundEffectGroup, e -> !(e instanceof BelowLiquidTrait));
|
||||||
EntityDraw.draw(itemGroup);
|
|
||||||
|
|
||||||
blocks.processBlocks();
|
blocks.processBlocks();
|
||||||
blocks.drawBlocks(Layer.block);
|
blocks.drawBlocks(Layer.block);
|
||||||
@@ -211,6 +210,14 @@ public class Renderer extends RendererModule{
|
|||||||
|
|
||||||
blocks.drawBlocks(Layer.overlay);
|
blocks.drawBlocks(Layer.overlay);
|
||||||
|
|
||||||
|
if(itemGroup.size() > 0){
|
||||||
|
Shaders.outline.color.set(Team.none.color);
|
||||||
|
|
||||||
|
Graphics.beginShaders(Shaders.outline);
|
||||||
|
EntityDraw.draw(itemGroup);
|
||||||
|
Graphics.endShaders();
|
||||||
|
}
|
||||||
|
|
||||||
drawAllTeams(false);
|
drawAllTeams(false);
|
||||||
|
|
||||||
blocks.skipLayer(Layer.turret);
|
blocks.skipLayer(Layer.turret);
|
||||||
@@ -240,6 +247,7 @@ public class Renderer extends RendererModule{
|
|||||||
private void drawAllTeams(boolean flying){
|
private void drawAllTeams(boolean flying){
|
||||||
for(Team team : Team.values()){
|
for(Team team : Team.values()){
|
||||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||||
|
|
||||||
if(group.count(p -> p.isFlying() == flying) +
|
if(group.count(p -> p.isFlying() == flying) +
|
||||||
playerGroup.count(p -> p.isFlying() == flying && p.getTeam() == team) == 0 && flying) continue;
|
playerGroup.count(p -> p.isFlying() == flying && p.getTeam() == team) == 0 && flying) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.Pools;
|
|||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
import io.anuke.mindustry.entities.traits.TeamTrait;
|
import io.anuke.mindustry.entities.traits.TeamTrait;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.net.In;
|
import io.anuke.mindustry.net.In;
|
||||||
@@ -16,10 +17,16 @@ import io.anuke.ucore.entities.trait.SolidTrait;
|
|||||||
import io.anuke.ucore.entities.trait.VelocityTrait;
|
import io.anuke.ucore.entities.trait.VelocityTrait;
|
||||||
import io.anuke.ucore.util.Timer;
|
import io.anuke.ucore.util.Timer;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||||
import static io.anuke.mindustry.Vars.world;
|
import static io.anuke.mindustry.Vars.world;
|
||||||
|
|
||||||
public class Bullet extends BulletEntity<BulletType> implements TeamTrait{
|
public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncTrait{
|
||||||
|
public static int typeID = -1;
|
||||||
|
|
||||||
private static Vector2 vector = new Vector2();
|
private static Vector2 vector = new Vector2();
|
||||||
|
|
||||||
//private Interpolator interpolator = new Interpolator();
|
//private Interpolator interpolator = new Interpolator();
|
||||||
@@ -69,21 +76,23 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait{
|
|||||||
public boolean collidesTiles(){
|
public boolean collidesTiles(){
|
||||||
return true; //TODO make artillery and such not do this
|
return true; //TODO make artillery and such not do this
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doSync(){
|
public int getTypeID() {
|
||||||
|
return typeID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSyncing(){
|
||||||
return type.syncable;
|
return type.syncable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Interpolator getInterpolator() {
|
public void write(DataOutput data) throws IOException {
|
||||||
return interpolator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(DataOutput data) throws IOException{
|
|
||||||
data.writeFloat(x);
|
data.writeFloat(x);
|
||||||
data.writeFloat(y);
|
data.writeFloat(y);
|
||||||
|
data.writeFloat(velocity.x);
|
||||||
|
data.writeFloat(velocity.y);
|
||||||
data.writeByte(team.ordinal());
|
data.writeByte(team.ordinal());
|
||||||
data.writeByte(type.id);
|
data.writeByte(type.id);
|
||||||
}
|
}
|
||||||
@@ -92,9 +101,11 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait{
|
|||||||
public void read(DataInput data, long time) throws IOException{
|
public void read(DataInput data, long time) throws IOException{
|
||||||
x = data.readFloat();
|
x = data.readFloat();
|
||||||
y = data.readFloat();
|
y = data.readFloat();
|
||||||
|
velocity.x = data.readFloat();
|
||||||
|
velocity.y = data.readFloat();
|
||||||
team = Team.values()[data.readByte()];
|
team = Team.values()[data.readByte()];
|
||||||
type = BulletType.getByID(data.readByte());
|
type = BulletType.getByID(data.readByte());
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Team getTeam() {
|
public Team getTeam() {
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package io.anuke.mindustry.entities.traits;
|
||||||
|
|
||||||
|
import io.anuke.ucore.entities.trait.HealthTrait;
|
||||||
|
|
||||||
|
//TODO implement
|
||||||
|
public interface RepairTrait extends TeamTrait {
|
||||||
|
|
||||||
|
HealthTrait getRepairing();
|
||||||
|
|
||||||
|
void setRepairing(HealthTrait trait);
|
||||||
|
|
||||||
|
default void drawRepair(){
|
||||||
|
if(getRepairing() == null) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
default void updateRepair(){
|
||||||
|
if(getRepairing() == null) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,6 +44,11 @@ public interface SyncTrait extends Entity, TypeTrait {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Whether syncing is enabled for this entity; true by default.*/
|
||||||
|
default boolean isSyncing(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//Read and write sync data, usually position
|
//Read and write sync data, usually position
|
||||||
void write(DataOutput data) throws IOException;
|
void write(DataOutput data) throws IOException;
|
||||||
void read(DataInput data, long time) throws IOException;
|
void read(DataInput data, long time) throws IOException;
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ public class WorldGenerator {
|
|||||||
final RidgedPerlin ridge;
|
final RidgedPerlin ridge;
|
||||||
final int index;
|
final int index;
|
||||||
|
|
||||||
int used;
|
|
||||||
|
|
||||||
OreEntry(Block block, float frequency, int seed) {
|
OreEntry(Block block, float frequency, int seed) {
|
||||||
this.frequency = frequency;
|
this.frequency = frequency;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
|
|||||||
Reference in New Issue
Block a user