Added visual interpolation for slow tickrates
This commit is contained in:
@@ -14,6 +14,7 @@ import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.net.ClientDebug;
|
||||
import io.anuke.mindustry.net.ServerDebug;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.entities.EffectEntity;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
@@ -134,4 +135,5 @@ public class Vars{
|
||||
public static final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||
public static final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
|
||||
public static final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class);
|
||||
public static final EntityGroup<EffectEntity> effectGroup = Entities.addGroup(EffectEntity.class);
|
||||
}
|
||||
|
||||
@@ -352,6 +352,7 @@ public class Control extends Module{
|
||||
}
|
||||
|
||||
if(!state.is(State.paused) || Net.active()){
|
||||
Entities.update(effectGroup);
|
||||
|
||||
if(respawntime > 0){
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.badlogic.gdx.utils.FloatArray;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.game.SpawnPoint;
|
||||
import io.anuke.mindustry.graphics.BlockRenderer;
|
||||
@@ -24,7 +25,6 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.EffectEntity;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
@@ -63,7 +63,7 @@ public class Renderer extends RendererModule{
|
||||
.setCenter(camera.position.x, camera.position.y);
|
||||
Rectangle pos = rect2.setSize(name.size).setCenter(x, y);
|
||||
if(view.overlaps(pos)){
|
||||
new EffectEntity(name, color, rotation).set(x, y).add();
|
||||
new EffectEntity(name, color, rotation).set(x, y).add(effectGroup);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -191,6 +191,7 @@ public class Renderer extends RendererModule{
|
||||
Graphics.shader();
|
||||
|
||||
Entities.draw(bulletGroup);
|
||||
Entities.draw(effectGroup);
|
||||
|
||||
drawShield();
|
||||
|
||||
@@ -448,11 +449,13 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
}
|
||||
|
||||
void drawHealth(DestructibleEntity dest){
|
||||
void drawHealth(SyncEntity dest){
|
||||
float x = dest.getDrawPosition().x;
|
||||
float y = dest.getDrawPosition().y;
|
||||
if(dest instanceof Player && snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")){
|
||||
drawHealth((int) dest.x, (int) dest.y - 7f, dest.health, dest.maxhealth);
|
||||
drawHealth((int) x, (int) y - 7f, dest.health, dest.maxhealth);
|
||||
}else{
|
||||
drawHealth(dest.x, dest.y - 7f, dest.health, dest.maxhealth);
|
||||
drawHealth(x, y - 7f, dest.health, dest.maxhealth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import static io.anuke.mindustry.Vars.logic;
|
||||
public class ThreadHandler {
|
||||
private final ThreadProvider impl;
|
||||
private float delta = 1f;
|
||||
private long frame = 0;
|
||||
private boolean enabled;
|
||||
|
||||
private final Object updateLock = new Object();
|
||||
@@ -21,6 +22,14 @@ public class ThreadHandler {
|
||||
Timers.setDeltaProvider(() -> impl.isOnThread() ? delta : Gdx.graphics.getDeltaTime()*60f);
|
||||
}
|
||||
|
||||
public int getFPS(){
|
||||
return (int)(60/delta);
|
||||
}
|
||||
|
||||
public long getFrameID(){
|
||||
return frame;
|
||||
}
|
||||
|
||||
public void handleRender(){
|
||||
if(!enabled) return;
|
||||
|
||||
@@ -55,6 +64,7 @@ public class ThreadHandler {
|
||||
while (true) {
|
||||
long time = TimeUtils.millis();
|
||||
logic.update();
|
||||
//impl.sleep(130);
|
||||
|
||||
long elapsed = TimeUtils.timeSinceMillis(time);
|
||||
long target = (long) (1000 / 60f);
|
||||
@@ -71,6 +81,8 @@ public class ThreadHandler {
|
||||
}
|
||||
rendered = false;
|
||||
}
|
||||
|
||||
frame ++;
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Log.info("Stopping logic thread.");
|
||||
|
||||
@@ -35,7 +35,6 @@ public class Player extends SyncEntity{
|
||||
public Weapon weaponRight = Weapon.blaster;
|
||||
public Mech mech = Mech.standard;
|
||||
|
||||
public float angle;
|
||||
public float targetAngle = 0f;
|
||||
public float stucktime = 0f;
|
||||
public boolean dashing = false;
|
||||
@@ -106,7 +105,7 @@ public class Player extends SyncEntity{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
public void drawSmooth(){
|
||||
if(isAndroid && isLocal){
|
||||
angle = Mathf.lerpAngDelta(angle, targetAngle, 0.2f);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.threads;
|
||||
|
||||
public abstract class SyncEntity extends DestructibleEntity{
|
||||
private static ObjectIntMap<Class<? extends SyncEntity>> writeSizes = new ObjectIntMap<>();
|
||||
|
||||
protected transient Interpolator interpolator = new Interpolator();
|
||||
|
||||
//for interpolating at low tick speeds.
|
||||
private transient Vector2 tpos = new Vector2(-999, -999);
|
||||
private transient float tang = 0f;
|
||||
|
||||
public float angle;
|
||||
|
||||
static{
|
||||
setWriteSize(Enemy.class, 4 + 4 + 2 + 2);
|
||||
setWriteSize(Player.class, 4 + 4 + 4 + 2 + 1);
|
||||
@@ -24,6 +34,40 @@ public abstract class SyncEntity extends DestructibleEntity{
|
||||
public abstract void read(ByteBuffer data, long time);
|
||||
public abstract void interpolate();
|
||||
|
||||
@Override
|
||||
public final void draw(){
|
||||
float x = this.x, y = this.y, angle = this.angle;
|
||||
|
||||
//interpolates data at low tick speeds.
|
||||
if(isSmoothing()){
|
||||
if(tpos.dst(x, y) > 100){
|
||||
tpos.set(x, y);
|
||||
}
|
||||
tpos.x = Mathf.lerpDelta(tpos.x, x, 0.3f);
|
||||
tpos.y = Mathf.lerpDelta(tpos.y, y, 0.3f);
|
||||
tang = Mathf.lerpAngDelta(tang, angle, 0.3f);
|
||||
this.x = tpos.x;
|
||||
this.y = tpos.y;
|
||||
this.angle = tang;
|
||||
}
|
||||
|
||||
drawSmooth();
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
private boolean isSmoothing(){
|
||||
return threads.isEnabled() && threads.getFPS() <= Gdx.graphics.getFramesPerSecond() / 2f;
|
||||
}
|
||||
|
||||
public Vector2 getDrawPosition(){
|
||||
return isSmoothing() ? tpos : tpos.set(x, y);
|
||||
}
|
||||
|
||||
public void drawSmooth(){}
|
||||
|
||||
public int getWriteSize(){
|
||||
return getWriteSize(getClass());
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@ public class Enemy extends SyncEntity {
|
||||
public Enemy spawner;
|
||||
public int spawned;
|
||||
|
||||
public float angle;
|
||||
public Vector2 velocity = new Vector2();
|
||||
public Vector2 totalMove = new Vector2();
|
||||
public Vector2 tpos = new Vector2(-999, -999);
|
||||
public Entity target;
|
||||
public float hitTime;
|
||||
public int tier = 1;
|
||||
public Vector2 totalMove = new Vector2();
|
||||
|
||||
public TextureRegion region;
|
||||
public Translator tr = new Translator();
|
||||
@@ -52,7 +52,7 @@ public class Enemy extends SyncEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
public void drawSmooth(){
|
||||
type.draw(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class HudFragment implements Fragment{
|
||||
visible(() -> !state.is(State.menu));
|
||||
|
||||
Label fps = new Label(() -> (Settings.getBool("fps") ? (Gdx.graphics.getFramesPerSecond() + " FPS") +
|
||||
(Net.client() && !gwt ? " / Ping: " + Net.getPing() : "") : ""));
|
||||
(threads.isEnabled() ? " / " + threads.getFPS() + " TPS" : "") + (Net.client() && !gwt ? " / Ping: " + Net.getPing() : "") : ""));
|
||||
row();
|
||||
add(fps).size(-1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user