Autogenerated interpolation

This commit is contained in:
Anuken
2020-05-24 14:00:53 -04:00
parent 1acb5fc56c
commit 7c06ba94c1
36 changed files with 252 additions and 183 deletions

View File

@@ -7,9 +7,7 @@ import mindustry.gen.*;
@Component
abstract class LegsComp implements Posc, Flyingc, Hitboxc, Unitc, Legsc, ElevationMovec{
@Import float x, y;
float baseRotation;
@SyncField(false) float baseRotation;
transient float walkTime;
@Override

View File

@@ -1,5 +1,6 @@
package mindustry.entities.comp;
import arc.math.*;
import mindustry.annotations.Annotations.*;
import mindustry.async.PhysicsProcess.*;
import mindustry.gen.*;
@@ -9,10 +10,17 @@ import mindustry.gen.*;
* Has mass.*/
@Component
abstract class PhysicsComp implements Velc, Hitboxc, Flyingc{
transient PhysicRef physref;
transient float mass = 1f;
@Import float hitSize;
public void impulse(float x, float y){
transient PhysicRef physref;
//mass is simply the area of this object
float mass(){
return hitSize * hitSize * Mathf.pi;
}
void impulse(float x, float y){
float mass = mass();
vel().add(x / mass, y / mass);
}
}

View File

@@ -12,7 +12,7 @@ import static mindustry.Vars.world;
@Component
abstract class PosComp implements Position{
float x, y;
@SyncField(true) float x, y;
void set(float x, float y){
this.x = x;

View File

@@ -5,13 +5,5 @@ import mindustry.gen.*;
@Component
abstract class RotComp implements Entityc{
float rotation;
void interpolate(){
Syncc sync = as(Syncc.class);
if(sync.interpolator().values.length > 0){
rotation = sync.interpolator().values[0];
}
}
@SyncField(false) float rotation;
}

View File

@@ -1,26 +1,23 @@
package mindustry.entities.comp;
import arc.util.io.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.net.*;
import java.nio.*;
@Component
abstract class SyncComp implements Posc{
@Import float x, y;
abstract class SyncComp implements Entityc{
transient long lastUpdated, updateSpacing;
transient Interpolator interpolator = new Interpolator();
void setNet(float x, float y){
set(x, y);
//TODO change interpolator API
interpolator.target.set(x, y);
interpolator.last.set(x, y);
interpolator.pos.set(0, 0);
interpolator.updateSpacing = 16;
interpolator.lastUpdated = 0;
}
//all these method bodies are internally generated
void snapSync(){}
void readSync(Reads read){}
void writeSync(Writes write){}
void readSyncManual(FloatBuffer buffer){}
void writeSyncManual(FloatBuffer buffer){}
void interpolate(){}
@Override
public void update(){
@@ -28,10 +25,4 @@ abstract class SyncComp implements Posc{
interpolate();
}
}
void interpolate(){
interpolator.update();
x = interpolator.pos.x;
y = interpolator.pos.y;
}
}