Removed all tmps, multithreading now functional
This commit is contained in:
@@ -25,7 +25,6 @@ public class Mindustry extends ModuleCore {
|
|||||||
BundleLoader.load();
|
BundleLoader.load();
|
||||||
BlockLoader.load();
|
BlockLoader.load();
|
||||||
|
|
||||||
|
|
||||||
logic = new Logic();
|
logic = new Logic();
|
||||||
|
|
||||||
if(!multithread) module(logic);
|
if(!multithread) module(logic);
|
||||||
|
|||||||
@@ -79,8 +79,8 @@ public class Pathfind{
|
|||||||
if(projectLen < 8 || !onLine(projection, prev.worldx(), prev.worldy(), target.worldx(), target.worldy())){
|
if(projectLen < 8 || !onLine(projection, prev.worldx(), prev.worldy(), target.worldx(), target.worldy())){
|
||||||
canProject = false;
|
canProject = false;
|
||||||
}else{
|
}else{
|
||||||
projection.add(v1.set(Angles.angle(prev.worldx(), prev.worldy(),
|
projection.add(v1.set(projectLen, 0).rotate(Angles.angle(prev.worldx(), prev.worldy(),
|
||||||
target.worldx(), target.worldy()), projectLen));
|
target.worldx(), target.worldy())));
|
||||||
}
|
}
|
||||||
|
|
||||||
float dst = Vector2.dst(enemy.x, enemy.y, target.worldx(), target.worldy());
|
float dst = Vector2.dst(enemy.x, enemy.y, target.worldx(), target.worldy());
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ package io.anuke.mindustry.ai;
|
|||||||
import com.badlogic.gdx.ai.pfa.DefaultGraphPath;
|
import com.badlogic.gdx.ai.pfa.DefaultGraphPath;
|
||||||
import com.badlogic.gdx.ai.pfa.SmoothableGraphPath;
|
import com.badlogic.gdx.ai.pfa.SmoothableGraphPath;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
public class SmoothGraphPath extends DefaultGraphPath<Tile> implements SmoothableGraphPath<Tile, Vector2>{
|
public class SmoothGraphPath extends DefaultGraphPath<Tile> implements SmoothableGraphPath<Tile, Vector2>{
|
||||||
|
private Vector2 vector = new Vector2();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2 getNodePosition(int index){
|
public Vector2 getNodePosition(int index){
|
||||||
Tile tile = nodes.get(index);
|
Tile tile = nodes.get(index);
|
||||||
return Tmp.v3.set(tile.worldx(), tile.worldy());
|
return vector.set(tile.worldx(), tile.worldy());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class Renderer extends RendererModule{
|
|||||||
private int targetscale = baseCameraScale;
|
private int targetscale = baseCameraScale;
|
||||||
private FloatArray shieldHits = new FloatArray();
|
private FloatArray shieldHits = new FloatArray();
|
||||||
private Array<Callable> shieldDraws = new Array<>();
|
private Array<Callable> shieldDraws = new Array<>();
|
||||||
|
private Rectangle rect = new Rectangle(), rect2 = new Rectangle();
|
||||||
private BlockRenderer blocks = new BlockRenderer();
|
private BlockRenderer blocks = new BlockRenderer();
|
||||||
|
|
||||||
public Renderer() {
|
public Renderer() {
|
||||||
@@ -58,9 +59,9 @@ public class Renderer extends RendererModule{
|
|||||||
Core.cameraScale = baseCameraScale;
|
Core.cameraScale = baseCameraScale;
|
||||||
Effects.setEffectProvider((name, color, x, y, rotation) -> {
|
Effects.setEffectProvider((name, color, x, y, rotation) -> {
|
||||||
if(Settings.getBool("effects")){
|
if(Settings.getBool("effects")){
|
||||||
Rectangle view = Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight)
|
Rectangle view = rect.setSize(camera.viewportWidth, camera.viewportHeight)
|
||||||
.setCenter(camera.position.x, camera.position.y);
|
.setCenter(camera.position.x, camera.position.y);
|
||||||
Rectangle pos = Tmp.r2.setSize(name.size).setCenter(x, y);
|
Rectangle pos = rect2.setSize(name.size).setCenter(x, y);
|
||||||
if(view.overlaps(pos)){
|
if(view.overlaps(pos)){
|
||||||
new EffectEntity(name, color, rotation).set(x, y).add();
|
new EffectEntity(name, color, rotation).set(x, y).add();
|
||||||
}
|
}
|
||||||
@@ -242,7 +243,8 @@ public class Renderer extends RendererModule{
|
|||||||
Draw.color(Color.RED);
|
Draw.color(Color.RED);
|
||||||
for(Enemy enemy : enemyGroup.all()) {
|
for(Enemy enemy : enemyGroup.all()) {
|
||||||
|
|
||||||
if (Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight).setCenter(camera.position.x, camera.position.y).overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))) {
|
if (rect.setSize(camera.viewportWidth, camera.viewportHeight).setCenter(camera.position.x, camera.position.y)
|
||||||
|
.overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import io.anuke.ucore.entities.SolidEntity;
|
|||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
import io.anuke.ucore.util.Translator;
|
import io.anuke.ucore.util.Translator;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -290,10 +289,10 @@ public class Player extends SyncEntity{
|
|||||||
|
|
||||||
i.time += 1f / i.spacing * Timers.delta();
|
i.time += 1f / i.spacing * Timers.delta();
|
||||||
|
|
||||||
Mathf.lerp2(Tmp.v2.set(i.last), i.target, i.time);
|
Mathf.lerp2(movement.set(i.last), i.target, i.time);
|
||||||
|
|
||||||
x = Tmp.v2.x;
|
x = movement.x;
|
||||||
y = Tmp.v2.y;
|
y = movement.y;
|
||||||
|
|
||||||
if(i.target.dst(x, y) > 128){
|
if(i.target.dst(x, y) > 128){
|
||||||
set(i.target.x, i.target.y);
|
set(i.target.x, i.target.y);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public abstract class SyncEntity extends DestructibleEntity{
|
|||||||
public class Interpolator {
|
public class Interpolator {
|
||||||
public Vector2 target = new Vector2();
|
public Vector2 target = new Vector2();
|
||||||
public Vector2 last = new Vector2();
|
public Vector2 last = new Vector2();
|
||||||
|
public Vector2 vec = new Vector2();
|
||||||
public float targetrot;
|
public float targetrot;
|
||||||
public float spacing = 1f;
|
public float spacing = 1f;
|
||||||
public float time;
|
public float time;
|
||||||
|
|||||||
@@ -4,19 +4,18 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
|
||||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||||
import io.anuke.mindustry.graphics.Fx;
|
import io.anuke.mindustry.graphics.Fx;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.Effects;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.entities.Entity;
|
import io.anuke.ucore.entities.Entity;
|
||||||
import io.anuke.ucore.entities.SolidEntity;
|
import io.anuke.ucore.entities.SolidEntity;
|
||||||
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.graphics.Lines;
|
import io.anuke.ucore.graphics.Lines;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
import static io.anuke.mindustry.Vars.enemyGroup;
|
||||||
|
|
||||||
public class TeslaOrb extends Entity{
|
public class TeslaOrb extends Entity{
|
||||||
private Array<Vector2> points = new Array<>();
|
private Array<Vector2> points = new Array<>();
|
||||||
@@ -25,6 +24,7 @@ public class TeslaOrb extends Entity{
|
|||||||
private float range = 0;
|
private float range = 0;
|
||||||
private float lifetime = 30f;
|
private float lifetime = 30f;
|
||||||
private float life = 0f;
|
private float life = 0f;
|
||||||
|
private Vector2 vector = new Vector2();
|
||||||
|
|
||||||
public TeslaOrb(float x, float y, float range, int damage){
|
public TeslaOrb(float x, float y, float range, int damage){
|
||||||
set(x, y);
|
set(x, y);
|
||||||
@@ -83,7 +83,7 @@ public class TeslaOrb extends Entity{
|
|||||||
|
|
||||||
float range = 1f;
|
float range = 1f;
|
||||||
|
|
||||||
Vector2 previous = Tmp.v1.set(x, y);
|
Vector2 previous = vector.set(x, y);
|
||||||
|
|
||||||
for(Vector2 enemy : points){
|
for(Vector2 enemy : points){
|
||||||
|
|
||||||
|
|||||||
@@ -154,10 +154,10 @@ public class Enemy extends SyncEntity {
|
|||||||
|
|
||||||
i.time += 1f / i.spacing * Timers.delta();
|
i.time += 1f / i.spacing * Timers.delta();
|
||||||
|
|
||||||
Mathf.lerp2(Tmp.v2.set(i.last), i.target, i.time);
|
Mathf.lerp2(i.vec.set(i.last), i.target, i.time);
|
||||||
|
|
||||||
x = Tmp.v2.x;
|
x = i.vec.x;
|
||||||
y = Tmp.v2.y;
|
y = i.vec.y;
|
||||||
|
|
||||||
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
|
angle = Mathf.lerpAngDelta(angle, i.targetrot, 0.6f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import io.anuke.ucore.entities.Entities;
|
|||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Strings;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -60,6 +59,10 @@ public class EnemyType {
|
|||||||
protected final int timerReload = timeid ++;
|
protected final int timerReload = timeid ++;
|
||||||
protected final int timerReset = timeid ++;
|
protected final int timerReset = timeid ++;
|
||||||
|
|
||||||
|
protected final Vector2 shift = new Vector2();
|
||||||
|
protected final Vector2 move = new Vector2();
|
||||||
|
protected final Vector2 calc = new Vector2();
|
||||||
|
|
||||||
public EnemyType(String name){
|
public EnemyType(String name){
|
||||||
this.id = lastid++;
|
this.id = lastid++;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -158,14 +161,14 @@ public class EnemyType {
|
|||||||
Vector2 vec;
|
Vector2 vec;
|
||||||
|
|
||||||
if(nearCore){
|
if(nearCore){
|
||||||
vec = Tmp.v1.setZero();
|
vec = move.setZero();
|
||||||
if(targetCore) enemy.target = core.entity;
|
if(targetCore) enemy.target = core.entity;
|
||||||
}else{
|
}else{
|
||||||
vec = world.pathfinder().find(enemy);
|
vec = world.pathfinder().find(enemy);
|
||||||
vec.sub(enemy.x, enemy.y).limit(speed);
|
vec.sub(enemy.x, enemy.y).limit(speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 shift = Tmp.v3.setZero();
|
shift.setZero();
|
||||||
float shiftRange = enemy.hitbox.width + 2f;
|
float shiftRange = enemy.hitbox.width + 2f;
|
||||||
float avoidRange = shiftRange + 4f;
|
float avoidRange = shiftRange + 4f;
|
||||||
float attractRange = avoidRange + 7f;
|
float attractRange = avoidRange + 7f;
|
||||||
@@ -180,11 +183,11 @@ public class EnemyType {
|
|||||||
float scl = Mathf.clamp(1.4f - dst / shiftRange) * mass * 1f/mass;
|
float scl = Mathf.clamp(1.4f - dst / shiftRange) * mass * 1f/mass;
|
||||||
shift.add((enemy.x - other.x) * scl, (enemy.y - other.y) * scl);
|
shift.add((enemy.x - other.x) * scl, (enemy.y - other.y) * scl);
|
||||||
}else if(dst < avoidRange){
|
}else if(dst < avoidRange){
|
||||||
Tmp.v2.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
|
calc.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
|
||||||
shift.add(Tmp.v2.scl(1.1f));
|
shift.add(calc.scl(1.1f));
|
||||||
}else if(dst < attractRange && !nearCore){
|
}else if(dst < attractRange && !nearCore){
|
||||||
Tmp.v2.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
|
calc.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
|
||||||
shift.add(Tmp.v2.scl(-1));
|
shift.add(calc.scl(-1));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package io.anuke.mindustry.entities.enemies.types;
|
package io.anuke.mindustry.entities.enemies.types;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
|
||||||
import io.anuke.mindustry.entities.Bullet;
|
import io.anuke.mindustry.entities.Bullet;
|
||||||
import io.anuke.mindustry.entities.BulletType;
|
import io.anuke.mindustry.entities.BulletType;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||||
import io.anuke.mindustry.entities.enemies.EnemyType;
|
import io.anuke.mindustry.entities.enemies.EnemyType;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
@@ -26,15 +24,16 @@ public class BlastType extends EnemyType {
|
|||||||
public void behavior(Enemy enemy){
|
public void behavior(Enemy enemy){
|
||||||
|
|
||||||
float range = 10f;
|
float range = 10f;
|
||||||
Vector2 offset = Tmp.v3.setZero();
|
float ox = 0, oy = 0;
|
||||||
|
|
||||||
if(enemy.target instanceof TileEntity){
|
if(enemy.target instanceof TileEntity){
|
||||||
TileEntity e = (TileEntity)enemy.target;
|
TileEntity e = (TileEntity)enemy.target;
|
||||||
range = (e.tile.block().width * tilesize) /2f + 8f;
|
range = (e.tile.block().width * tilesize) /2f + 8f;
|
||||||
offset.set(e.tile.block().getPlaceOffset());
|
ox = e.tile.block().getPlaceOffset().x;
|
||||||
|
oy = e.tile.block().getPlaceOffset().y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(enemy.target != null && enemy.target.distanceTo(enemy.x - offset.x, enemy.y - offset.y) < range){
|
if(enemy.target != null && enemy.target.distanceTo(enemy.x - ox, enemy.y - oy) < range){
|
||||||
explode(enemy);
|
explode(enemy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
package io.anuke.mindustry.graphics;
|
package io.anuke.mindustry.graphics;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.FloatArray;
|
import com.badlogic.gdx.utils.FloatArray;
|
||||||
|
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Shader;
|
import io.anuke.ucore.graphics.Shader;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
public class Shaders{
|
public class Shaders{
|
||||||
public static final Outline outline = new Outline();
|
public static final Outline outline = new Outline();
|
||||||
public static final Shield shield = new Shield();
|
public static final Shield shield = new Shield();
|
||||||
|
|
||||||
|
private static final Vector2 vec = new Vector2();
|
||||||
|
|
||||||
public static class Outline extends Shader{
|
public static class Outline extends Shader{
|
||||||
public Color color = new Color();
|
public Color color = new Color();
|
||||||
public float lighten = 0f;
|
public float lighten = 0f;
|
||||||
@@ -26,7 +27,7 @@ public class Shaders{
|
|||||||
public void apply(){
|
public void apply(){
|
||||||
shader.setUniformf("u_color", color);
|
shader.setUniformf("u_color", color);
|
||||||
shader.setUniformf("u_lighten", lighten);
|
shader.setUniformf("u_lighten", lighten);
|
||||||
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth(), region.getTexture().getHeight()));
|
shader.setUniformf("u_texsize", vec.set(region.getTexture().getWidth(), region.getTexture().getHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -52,8 +53,8 @@ public class Shaders{
|
|||||||
shader.setUniformf("u_color", color);
|
shader.setUniformf("u_color", color);
|
||||||
shader.setUniformf("u_time", Timers.time() / Unit.dp.scl(1f));
|
shader.setUniformf("u_time", Timers.time() / Unit.dp.scl(1f));
|
||||||
shader.setUniformf("u_scaling", scaling);
|
shader.setUniformf("u_scaling", scaling);
|
||||||
shader.setUniformf("u_offset", Tmp.v1.set(Core.camera.position.x, Core.camera.position.y));
|
shader.setUniformf("u_offset", vec.set(Core.camera.position.x, Core.camera.position.y));
|
||||||
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth() / scale,
|
shader.setUniformf("u_texsize", vec.set(region.getTexture().getWidth() / scale,
|
||||||
region.getTexture().getHeight() / scale));
|
region.getTexture().getHeight() / scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import io.anuke.ucore.core.Sounds;
|
|||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.entities.SolidEntity;
|
import io.anuke.ucore.entities.SolidEntity;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -36,6 +35,8 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
public PlaceMode lastPlaceMode = placeMode;
|
public PlaceMode lastPlaceMode = placeMode;
|
||||||
public PlaceMode lastBreakMode = breakMode;
|
public PlaceMode lastBreakMode = breakMode;
|
||||||
|
|
||||||
|
private Rectangle rect = new Rectangle();
|
||||||
|
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
public abstract float getCursorX();
|
public abstract float getCursorX();
|
||||||
public abstract float getCursorY();
|
public abstract float getCursorY();
|
||||||
@@ -93,21 +94,21 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Tmp.r2.setSize(type.width * tilesize, type.height * tilesize);
|
rect.setSize(type.width * tilesize, type.height * tilesize);
|
||||||
Vector2 offset = type.getPlaceOffset();
|
Vector2 offset = type.getPlaceOffset();
|
||||||
Tmp.r2.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
|
rect.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
|
||||||
|
|
||||||
for(SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
for(SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
||||||
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
||||||
|
|
||||||
if(Tmp.r2.overlaps(rect)){
|
if(this.rect.overlaps(rect)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type.solid || type.solidifes) {
|
if(type.solid || type.solidifes) {
|
||||||
for (Player player : playerGroup.all()) {
|
for (Player player : playerGroup.all()) {
|
||||||
if (!player.isAndroid && Tmp.r2.overlaps(player.hitbox.getRect(player.x, player.y))) {
|
if (!player.isAndroid && rect.overlaps(player.hitbox.getRect(player.x, player.y))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import io.anuke.ucore.graphics.Draw;
|
|||||||
import io.anuke.ucore.graphics.Lines;
|
import io.anuke.ucore.graphics.Lines;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
import io.anuke.ucore.util.Translator;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ public enum PlaceMode{
|
|||||||
|
|
||||||
if(control.input().recipe.result.rotate){
|
if(control.input().recipe.result.rotate){
|
||||||
Draw.color(Colors.get("placeRotate"));
|
Draw.color(Colors.get("placeRotate"));
|
||||||
Tmp.v1.set(7, 0).rotate(control.input().rotation * 90);
|
tr.trns(control.input().rotation * 90, 7, 0);
|
||||||
Lines.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
|
Lines.line(x, y, x + tr.x, y + tr.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,8 +293,8 @@ public enum PlaceMode{
|
|||||||
if(control.input().recipe.result.rotate){
|
if(control.input().recipe.result.rotate){
|
||||||
float cx = tx * t, cy = ty * t;
|
float cx = tx * t, cy = ty * t;
|
||||||
Draw.color(Colors.get("placeRotate"));
|
Draw.color(Colors.get("placeRotate"));
|
||||||
Tmp.v1.set(7, 0).rotate(rotation * 90);
|
tr.trns(rotation * 90, 7, 0);
|
||||||
Lines.line(cx, cy, cx + Tmp.v1.x, cy + Tmp.v1.y);
|
Lines.line(cx, cy, cx + tr.x, cy + tr.y);
|
||||||
}
|
}
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
@@ -369,6 +369,8 @@ public enum PlaceMode{
|
|||||||
public boolean delete = false;
|
public boolean delete = false;
|
||||||
public boolean both = false;
|
public boolean both = false;
|
||||||
|
|
||||||
|
private static final Translator tr = new Translator();
|
||||||
|
|
||||||
public void draw(int tilex, int tiley, int endx, int endy){
|
public void draw(int tilex, int tiley, int endx, int endy){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.badlogic.gdx.input.GestureDetector;
|
|||||||
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
||||||
import com.badlogic.gdx.math.Bresenham2;
|
import com.badlogic.gdx.math.Bresenham2;
|
||||||
import com.badlogic.gdx.math.GridPoint2;
|
import com.badlogic.gdx.math.GridPoint2;
|
||||||
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
|
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
@@ -43,6 +44,8 @@ public class MapView extends Element implements GestureListener{
|
|||||||
private float zoom = 1f;
|
private float zoom = 1f;
|
||||||
private boolean grid = false;
|
private boolean grid = false;
|
||||||
private GridImage image = new GridImage(0, 0);
|
private GridImage image = new GridImage(0, 0);
|
||||||
|
private Vector2 vec = new Vector2();
|
||||||
|
private Rectangle rect = new Rectangle();
|
||||||
|
|
||||||
private boolean drawing;
|
private boolean drawing;
|
||||||
private int lastx, lasty;
|
private int lastx, lasty;
|
||||||
@@ -214,7 +217,7 @@ public class MapView extends Element implements GestureListener{
|
|||||||
float px = ((float)x / editor.texture().getWidth()) * sclwidth + offsetx*zoom - sclwidth/2 + getWidth()/2;
|
float px = ((float)x / editor.texture().getWidth()) * sclwidth + offsetx*zoom - sclwidth/2 + getWidth()/2;
|
||||||
float py = (float)((float)(editor.texture().getHeight() - 1 - y) / editor.texture().getHeight()) * sclheight
|
float py = (float)((float)(editor.texture().getHeight() - 1 - y) / editor.texture().getHeight()) * sclheight
|
||||||
+ offsety*zoom - sclheight/2 + getHeight()/2;
|
+ offsety*zoom - sclheight/2 + getHeight()/2;
|
||||||
return Tmp.v1.set(px, py);
|
return vec.set(px, py);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -229,7 +232,7 @@ public class MapView extends Element implements GestureListener{
|
|||||||
image.setImageSize(editor.pixmap().getWidth(), editor.pixmap().getHeight());
|
image.setImageSize(editor.pixmap().getWidth(), editor.pixmap().getHeight());
|
||||||
|
|
||||||
batch.flush();
|
batch.flush();
|
||||||
boolean pop = ScissorStack.pushScissors(Tmp.r1.set(x + width/2 - size/2, y + height/2 - size/2, size, size));
|
boolean pop = ScissorStack.pushScissors(rect.set(x + width/2 - size/2, y + height/2 - size/2, size, size));
|
||||||
|
|
||||||
batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.ui.dialogs;
|
package io.anuke.mindustry.ui.dialogs;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import io.anuke.mindustry.game.Difficulty;
|
import io.anuke.mindustry.game.Difficulty;
|
||||||
import io.anuke.mindustry.game.GameMode;
|
import io.anuke.mindustry.game.GameMode;
|
||||||
import io.anuke.mindustry.world.Map;
|
import io.anuke.mindustry.world.Map;
|
||||||
@@ -16,7 +17,6 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
|||||||
import io.anuke.ucore.scene.utils.Elements;
|
import io.anuke.ucore.scene.utils.Elements;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -134,12 +134,14 @@ public class LevelDialog extends FloatingDialog{
|
|||||||
}).width(images+16).padBottom(-10f).grow().get();
|
}).width(images+16).padBottom(-10f).grow().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 hit = new Vector2();
|
||||||
|
|
||||||
image.addListener(new ClickListener(){
|
image.addListener(new ClickListener(){
|
||||||
public void clicked(InputEvent event, float x, float y){
|
public void clicked(InputEvent event, float x, float y){
|
||||||
image.localToStageCoordinates(Tmp.v1.set(x, y));
|
image.localToStageCoordinates(hit.set(x, y));
|
||||||
if(delete[0] != null && (delete[0].getClickListener().isOver() || delete[0].getClickListener().isPressed()
|
if(delete[0] != null && (delete[0].getClickListener().isOver() || delete[0].getClickListener().isPressed()
|
||||||
|| (Core.scene.hit(Tmp.v1.x, Tmp.v1.y, true) != null &&
|
|| (Core.scene.hit(hit.x, hit.y, true) != null &&
|
||||||
Core.scene.hit(Tmp.v1.x, Tmp.v1.y, true).isDescendantOf(delete[0])))){
|
Core.scene.hit(hit.x, hit.y, true).isDescendantOf(delete[0])))){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.ui.fragments;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import io.anuke.mindustry.Vars;
|
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.scene.builders.button;
|
import io.anuke.ucore.scene.builders.button;
|
||||||
@@ -50,7 +49,7 @@ public class DebugFragment implements Fragment {
|
|||||||
row();
|
row();
|
||||||
new button("infammo", "toggle", () -> infiniteAmmo = !infiniteAmmo);
|
new button("infammo", "toggle", () -> infiniteAmmo = !infiniteAmmo);
|
||||||
row();
|
row();
|
||||||
new button("wave", () -> logic.runWave());
|
new button("wave", () -> state.wavetime = 0f);
|
||||||
row();
|
row();
|
||||||
new button("clear", () -> {
|
new button("clear", () -> {
|
||||||
enemyGroup.clear();
|
enemyGroup.clear();
|
||||||
@@ -58,9 +57,7 @@ public class DebugFragment implements Fragment {
|
|||||||
netClient.clearRecieved();
|
netClient.clearRecieved();
|
||||||
});
|
});
|
||||||
row();
|
row();
|
||||||
new button("spawn", () -> {try{ Net.connect("localhost", Vars.port); }catch (Exception e){e.printStackTrace();}});
|
new button("spawn", () -> {});
|
||||||
row();
|
|
||||||
new button("stuff", () -> netClient.test());
|
|
||||||
row();
|
row();
|
||||||
}}.end();
|
}}.end();
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ public class HudFragment implements Fragment{
|
|||||||
|
|
||||||
private void playButton(float uheight){
|
private void playButton(float uheight){
|
||||||
new imagebutton("icon-play", 30f, () -> {
|
new imagebutton("icon-play", 30f, () -> {
|
||||||
logic.runWave();
|
state.wavetime = 0f;
|
||||||
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padRight(-36).width(40f).update(l->{
|
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padRight(-36).width(40f).update(l->{
|
||||||
boolean vis = state.enemies <= 0 && (Net.server() || !Net.active());
|
boolean vis = state.enemies <= 0 && (Net.server() || !Net.active());
|
||||||
boolean paused = state.is(State.paused) || !vis;
|
boolean paused = state.is(State.paused) || !vis;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import io.anuke.ucore.graphics.Draw;
|
|||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.state;
|
import static io.anuke.mindustry.Vars.state;
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
@@ -30,6 +29,7 @@ public class Block{
|
|||||||
private static ObjectMap<String, Block> map = new ObjectMap<>();
|
private static ObjectMap<String, Block> map = new ObjectMap<>();
|
||||||
|
|
||||||
protected static TextureRegion temp = new TextureRegion();
|
protected static TextureRegion temp = new TextureRegion();
|
||||||
|
protected Vector2 offset = new Vector2();
|
||||||
|
|
||||||
/**internal name*/
|
/**internal name*/
|
||||||
public final String name;
|
public final String name;
|
||||||
@@ -272,7 +272,7 @@ public class Block{
|
|||||||
|
|
||||||
/**Offset for placing and drawing multiblocks.*/
|
/**Offset for placing and drawing multiblocks.*/
|
||||||
public Vector2 getPlaceOffset(){
|
public Vector2 getPlaceOffset(){
|
||||||
return Tmp.v3.set(((width + 1) % 2) * tilesize/2, ((height + 1) % 2) * tilesize/2);
|
return offset.set(((width + 1) % 2) * tilesize/2, ((height + 1) % 2) * tilesize/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMultiblock(){
|
public boolean isMultiblock(){
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import io.anuke.ucore.core.Effects.Effect;
|
|||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.entities.SolidEntity;
|
import io.anuke.ucore.entities.SolidEntity;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -20,6 +19,8 @@ import java.io.IOException;
|
|||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class Door extends Wall{
|
public class Door extends Wall{
|
||||||
|
protected final Rectangle rect = new Rectangle();
|
||||||
|
|
||||||
protected Effect openfx = Fx.dooropen;
|
protected Effect openfx = Fx.dooropen;
|
||||||
protected Effect closefx = Fx.doorclose;
|
protected Effect closefx = Fx.doorclose;
|
||||||
|
|
||||||
@@ -65,13 +66,13 @@ public class Door extends Wall{
|
|||||||
boolean anyEntities(Tile tile){
|
boolean anyEntities(Tile tile){
|
||||||
int x = tile.x, y = tile.y;
|
int x = tile.x, y = tile.y;
|
||||||
Block type = tile.block();
|
Block type = tile.block();
|
||||||
Tmp.r2.setSize(type.width * tilesize, type.height * tilesize);
|
rect.setSize(type.width * tilesize, type.height * tilesize);
|
||||||
Tmp.r2.setCenter(tile.drawx(), tile.drawy());
|
rect.setCenter(tile.drawx(), tile.drawy());
|
||||||
|
|
||||||
for(SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
for(SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
||||||
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
||||||
|
|
||||||
if(Tmp.r2.overlaps(rect)){
|
if(rect.overlaps(rect)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +80,7 @@ public class Door extends Wall{
|
|||||||
for(SolidEntity e : Entities.getNearby(playerGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
for(SolidEntity e : Entities.getNearby(playerGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
||||||
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
||||||
|
|
||||||
if(Tmp.r2.overlaps(rect)){
|
if(rect.overlaps(rect)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import io.anuke.mindustry.world.Layer;
|
|||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Bits;
|
import io.anuke.ucore.util.*;
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
import io.anuke.ucore.util.Strings;
|
|
||||||
import io.anuke.ucore.util.Tmp;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -32,6 +29,9 @@ public class Conveyor extends Block{
|
|||||||
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;
|
||||||
|
|
||||||
|
private final Translator tr1 = new Translator();
|
||||||
|
private final Translator tr2 = new Translator();
|
||||||
|
|
||||||
public float speed = 0.02f;
|
public float speed = 0.02f;
|
||||||
|
|
||||||
protected Conveyor(String name) {
|
protected Conveyor(String name) {
|
||||||
@@ -77,12 +77,12 @@ public class Conveyor extends Block{
|
|||||||
|
|
||||||
if(pos.item == null) continue;
|
if(pos.item == null) continue;
|
||||||
|
|
||||||
Tmp.v1.set(tilesize, 0).rotate(rotation * 90);
|
tr1.trns(rotation * 90, tilesize, 0);
|
||||||
Tmp.v2.set(-tilesize / 2, pos.x*tilesize/2).rotate(rotation * 90);
|
tr2.trns(rotation * 90, -tilesize / 2, pos.x*tilesize/2);
|
||||||
|
|
||||||
Draw.rect(pos.item.region,
|
Draw.rect(pos.item.region,
|
||||||
tile.x * tilesize + Tmp.v1.x * pos.y + Tmp.v2.x,
|
tile.x * tilesize + tr1.x * pos.y + tr2.x,
|
||||||
tile.y * tilesize + Tmp.v1.y * pos.y + Tmp.v2.y, itemSize, itemSize);
|
tile.y * tilesize + tr1.y * pos.y + tr2.y, itemSize, itemSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import io.anuke.ucore.core.Timers;
|
|||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Strings;
|
||||||
import io.anuke.ucore.util.Tmp;
|
import io.anuke.ucore.util.Translator;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -25,6 +25,8 @@ import static io.anuke.mindustry.Vars.tilesize;
|
|||||||
public class NuclearReactor extends LiquidPowerGenerator{
|
public class NuclearReactor extends LiquidPowerGenerator{
|
||||||
protected final int timerFuel = timers++;
|
protected final int timerFuel = timers++;
|
||||||
|
|
||||||
|
protected final Translator tr = new Translator();
|
||||||
|
|
||||||
protected Item generateItem;
|
protected Item generateItem;
|
||||||
protected int itemCapacity = 30;
|
protected int itemCapacity = 30;
|
||||||
protected Color coolColor = new Color(1, 1, 1, 0f);
|
protected Color coolColor = new Color(1, 1, 1, 0f);
|
||||||
@@ -137,15 +139,15 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
|||||||
|
|
||||||
for(int i = 0; i < 20; i ++){
|
for(int i = 0; i < 20; i ++){
|
||||||
Timers.run(Mathf.random(50), ()->{
|
Timers.run(Mathf.random(50), ()->{
|
||||||
Tmp.v1.setToRandomDirection().setLength(Mathf.random(40f));
|
tr.rnd(Mathf.random(40f));
|
||||||
Effects.effect(Fx.explosion, Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
|
Effects.effect(Fx.explosion, tr.x + tile.worldx(), tr.y + tile.worldy());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 70; i ++){
|
for(int i = 0; i < 70; i ++){
|
||||||
Timers.run(Mathf.random(80), ()->{
|
Timers.run(Mathf.random(80), ()->{
|
||||||
Tmp.v1.setToRandomDirection().setLength(Mathf.random(120f));
|
tr.rnd(Mathf.random(120f));
|
||||||
Effects.effect(Fx.nuclearsmoke, Tmp.v1.x + tile.worldx(), Tmp.v1.y + tile.worldy());
|
Effects.effect(Fx.nuclearsmoke, tr.x + tile.worldx(), tr.y + tile.worldy());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user