Fixed some android memory errors and weapon factory bugs

This commit is contained in:
Anuken 2018-01-09 20:11:56 -05:00
parent e4c755621c
commit 09333b60d4
15 changed files with 48 additions and 62 deletions

View File

@ -293,6 +293,7 @@ item.steel.name=steel
item.titanium.name=titanium
item.dirium.name=dirium
item.uranium.name=uranium
item.sand.name=sand
liquid.water.name=water
liquid.plasma.name=plasma
liquid.lava.name=lava

View File

@ -356,7 +356,7 @@ public class Control extends Module{
for(int i = 0; i < spawnamount; i ++){
float range = 12f;
Timers.run(i*5f, ()->{
Timers.run(i*5f, () -> {
Enemy enemy = new Enemy(spawn.type);
enemy.set(tile.worldx() + Mathf.range(range), tile.worldy() + Mathf.range(range));

View File

@ -2,7 +2,6 @@ package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.TimeUtils;
import com.badlogic.gdx.utils.compression.Lzma;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Bullet;
@ -28,8 +27,6 @@ import io.anuke.ucore.entities.BaseBulletType;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.modules.Module;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;
@ -82,16 +79,8 @@ public class NetClient extends Module {
Net.handle(WorldData.class, data -> {
Gdx.app.postRunnable(() -> {
ByteArrayOutputStream outc = new ByteArrayOutputStream();
try {
Lzma.decompress(data.stream, outc);
}catch (IOException e){
throw new RuntimeException(e);
}
UCore.log("Recieved world data: " + data.stream.available() + " bytes.");
NetworkIO.load(new ByteArrayInputStream(outc.toByteArray()));
NetworkIO.load(data.stream);
Vars.player.set(Vars.control.core.worldx(), Vars.control.core.worldy() - Vars.tilesize*2);
GameState.set(State.playing);

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.TimeUtils;
import com.badlogic.gdx.utils.compression.Lzma;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.BulletType;
@ -50,19 +49,7 @@ public class NetServer extends Module{
NetworkIO.write(stream);
UCore.log("Packed " + stream.size() + " uncompressed bytes of data.");
ByteArrayInputStream inc = new ByteArrayInputStream(stream.toByteArray());
ByteArrayOutputStream outc = new ByteArrayOutputStream();
try {
Lzma.compress(inc, outc);
}catch (IOException e){
throw new RuntimeException(e);
}
UCore.log("Packed " + outc.size() + " COMPRESSED bytes of data.");
data.stream = new ByteArrayInputStream(outc.toByteArray());
data.stream = new ByteArrayInputStream(stream.toByteArray());
Net.sendStream(id, data);

View File

@ -448,7 +448,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
}
public void init(Bullet b) {
DamageArea.damageLine(true, Fx.beamhit, b.x, b.y, b.angle(), length, damage);
DamageArea.damageLine(b.owner, Fx.beamhit, b.x, b.y, b.angle(), length, damage);
}
public void draw(Bullet b) {

View File

@ -50,7 +50,7 @@ public class Player extends DestructibleEntity implements Syncable{
@Override
public void damage(int amount){
if(!Vars.debug)
if(!Vars.debug && !isAndroid)
super.damage(amount);
}

View File

@ -8,14 +8,20 @@ import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.util.*;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Physics;
public class DamageArea{
private static Rectangle rect = new Rectangle();
//only for entities, not tiles (yet!)
public static void damageLine(boolean enemies, Effect effect, float x, float y, float angle, float length, int damage){
public static void damageLine(Entity owner, Effect effect, float x, float y, float angle, float length, int damage){
Angles.translation(angle, length);
rect.setPosition(x, y).setSize(Angles.x(), Angles.y());
float x2 = Angles.x() + x, y2 = Angles.y() + y;
@ -37,23 +43,25 @@ public class DamageArea{
rect.width += expand*2;
rect.height += expand*2;
if(enemies){
Entities.getNearby(Vars.control.enemyGroup, rect, e -> {
Enemy enemy = (Enemy)e;
Rectangle other = enemy.hitbox.getRect(enemy.x, enemy.y);
other.y -= expand;
other.x -= expand;
other.width += expand*2;
other.height += expand*2;
Consumer<SolidEntity> cons = e -> {
if(e == owner || (e instanceof Player && ((Player)e).isAndroid)) return;
DestructibleEntity enemy = (DestructibleEntity) e;
Rectangle other = enemy.hitbox.getRect(enemy.x, enemy.y);
other.y -= expand;
other.x -= expand;
other.width += expand * 2;
other.height += expand * 2;
Vector2 vec = Physics.raycastRect(x, y, x2, y2, other);
Vector2 vec = Physics.raycastRect(x, y, x2, y2, other);
if(vec != null){
Effects.effect(effect, vec.x, vec.y);
enemy.damage(damage);
}
});
}//TODO else damage players and blocks?
if (vec != null) {
Effects.effect(effect, vec.x, vec.y);
enemy.damage(damage);
}
};
Entities.getNearby(Vars.control.enemyGroup, rect, cons);
Entities.getNearby(Vars.control.playerGroup, rect, cons);
}
public static void damageEntities(float x, float y, float radius, int damage){

View File

@ -4,18 +4,19 @@ import io.anuke.mindustry.Vars;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.ui.Dialog;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Strings;
import java.io.IOException;
//TODO add port specification
public class HostDialog extends Dialog{
public class HostDialog extends FloatingDialog{
float w = 300;
public HostDialog(){
super("$text.hostserver", "dialog");
super("$text.hostserver");
addCloseButton();
content().table(t -> {
t.add("$text.name").padRight(10);

View File

@ -44,7 +44,7 @@ public class BlocksFragment implements Fragment{
blocks = new table(){{
itemtable = new Table("button");
itemtable.setVisible(() -> input.recipe == null);
itemtable.setVisible(() -> input.recipe == null && !Vars.control.getMode().infiniteResources);
desctable = new Table("button");
desctable.setVisible(() -> input.recipe != null);

View File

@ -79,8 +79,9 @@ public class ChatFragment extends Table implements Fragment{
bottom().left().marginBottom(offsety).marginLeft(offsetx*2).add(fieldlabel).padBottom(4f);
add(chatfield).padBottom(offsety).padLeft(offsetx).growX().padRight(offsetx).height(28);
if(Vars.android) {
addImageButton("icon-chat", 14 * 2, this::toggle).size(30f).visible(() -> chatOpen);
addImageButton("icon-arrow-right", 14 * 2, this::toggle).size(50f, 55f).visible(() -> chatOpen);
}
}

View File

@ -22,7 +22,7 @@ import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*;
public class HudFragment implements Fragment{
private ImageButton menu, flip, pause;
private ImageButton menu, flip;
private Table respawntable;
private Table wavetable;
private boolean shown = true;
@ -43,7 +43,7 @@ public class HudFragment implements Fragment{
menu = new imagebutton("icon-menu", isize, ui.paused::show).get();
flip = new imagebutton("icon-arrow-up", isize, ()->{
flip = new imagebutton("icon-arrow-up", isize, () -> {
if(wavetable.getActions().size != 0) return;
float dur = 0.3f;
@ -62,7 +62,7 @@ public class HudFragment implements Fragment{
}).get();
pause = new imagebutton("icon-pause", isize, ()->{
new imagebutton("icon-pause", isize, () -> {
if(Net.active() && Vars.android){
if(ui.chatfrag.chatOpen()){
ui.chatfrag.hide();
@ -72,7 +72,7 @@ public class HudFragment implements Fragment{
}else {
GameState.set(GameState.is(State.paused) ? State.playing : State.paused);
}
}).update(i ->{
}).update(i -> {
if(Net.active() && Vars.android){
i.getStyle().imageUp = Core.skin.getDrawable("icon-chat");
}else {
@ -194,7 +194,7 @@ public class HudFragment implements Fragment{
getEnemiesRemaining() :
(control.getTutorial().active() || Vars.control.getMode().toggleWaves) ? "$text.waiting"
: Bundles.format("text.wave.waiting", (int) (control.getWaveCountdown() / 60f)))
.minWidth(140).padLeft(-6).padRight(-12).left();
.minWidth(126).padLeft(-6).padRight(-12).left();
margin(10f);
get().marginLeft(6);
@ -208,8 +208,7 @@ public class HudFragment implements Fragment{
private void playButton(float uheight){
new imagebutton("icon-play", 30f, ()->{
Vars.control.runWave();
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padRight(-36)
.padLeft(-10f).width(40f).update(l->{
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padRight(-36).width(40f).update(l->{
boolean vis = Vars.control.getMode().toggleWaves && Vars.control.getEnemiesRemaining() <= 0;
boolean paused = GameState.is(State.paused) || !vis;

View File

@ -24,7 +24,7 @@ public class TunnelConveyor extends Block{
@Override
public void handleItem(Item item, Tile tile, Tile source){
Tile tunnel = getDestTunnel(tile, item);
if(tunnel == null) return; //TODO how is this possible? HOW DID THEY ACHIEVE SUCH A FEAT?!
if(tunnel == null) return;
Tile to = tunnel.getNearby()[tunnel.getRotation()];
Timers.run(25, ()->{

View File

@ -99,7 +99,7 @@ public class WeaponFactory extends Block{
}
}).size(49f, 54f).padBottom(-5).get();
button.setDisabled(() -> control.hasWeapon(weapon));
button.setDisabled(() -> control.hasWeapon(weapon) || !control.hasItems(requirements));
button.getStyle().imageUp = new TextureRegionDrawable(Draw.region(weapon.name));
button.addListener(tip);

View File

@ -118,7 +118,7 @@ public class KryoClient implements ClientProvider{
@Override
public Array<Address> discover(){
List<InetAddress> list = client.discoverHosts(Vars.port, 5000);
List<InetAddress> list = client.discoverHosts(Vars.port, 3000);
ObjectSet<String> hostnames = new ObjectSet<>();
Array<Address> result = new Array<>();

View File

@ -29,7 +29,7 @@ public class KryoServer implements ServerProvider {
IntArray connections = new IntArray();
public KryoServer(){
server = new Server();
server = new Server(4096, 1024); //TODO tweak
server.setDiscoveryHandler(new ServerDiscoveryHandler() {
private ByteBuffer buffer = ByteBuffer.allocate(4);