This commit is contained in:
Anuken
2020-02-07 11:46:10 -05:00
parent 007a1bd1d2
commit 861b3ac3f4
9 changed files with 114 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package mindustry.annotations;
import arc.files.*; import arc.files.*;
import arc.struct.Array; import arc.struct.Array;
import arc.util.*; import arc.util.*;
import arc.util.Log.*;
import com.squareup.javapoet.*; import com.squareup.javapoet.*;
import com.sun.source.util.*; import com.sun.source.util.*;
import mindustry.annotations.util.*; import mindustry.annotations.util.*;
@ -160,8 +161,10 @@ public abstract class BaseProcessor extends AbstractProcessor{
filer = env.getFiler(); filer = env.getFiler();
messager = env.getMessager(); messager = env.getMessager();
//System.setProperty("debug", "true");
if(System.getProperty("debug") == null){ if(System.getProperty("debug") == null){
//Log.setLogLevel(LogLevel.err); Log.setLogLevel(LogLevel.err);
} }
} }

View File

@ -355,13 +355,19 @@ public class EntityProcess extends BaseProcessor{
.addParameter(TypeName.FLOAT, "x").addParameter(TypeName.FLOAT, "y").addParameter(TypeName.FLOAT, "w").addParameter(TypeName.FLOAT, "h") .addParameter(TypeName.FLOAT, "x").addParameter(TypeName.FLOAT, "y").addParameter(TypeName.FLOAT, "w").addParameter(TypeName.FLOAT, "h")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC); .addModifiers(Modifier.PUBLIC, Modifier.STATIC);
MethodSpec.Builder groupUpdate = MethodSpec.methodBuilder("update")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
//method resize //method resize
for(GroupDefinition group : groupDefs){ for(GroupDefinition group : groupDefs){
if(group.spatial){ if(group.spatial){
groupResize.addStatement("$L.resize(x, y, w, h)", group.name); groupResize.addStatement("$L.resize(x, y, w, h)", group.name);
groupUpdate.addStatement("$L.updatePhysics()", group.name);
} }
} }
groupUpdate.addStatement("all.update()");
for(DrawLayer layer : DrawLayer.values()){ for(DrawLayer layer : DrawLayer.values()){
MethodSpec.Builder groupDraw = MethodSpec.methodBuilder("draw" + Strings.capitalize(layer.name())) MethodSpec.Builder groupDraw = MethodSpec.methodBuilder("draw" + Strings.capitalize(layer.name()))
.addModifiers(Modifier.PUBLIC, Modifier.STATIC); .addModifiers(Modifier.PUBLIC, Modifier.STATIC);
@ -370,6 +376,7 @@ public class EntityProcess extends BaseProcessor{
} }
groupsBuilder.addMethod(groupResize.build()); groupsBuilder.addMethod(groupResize.build());
groupsBuilder.addMethod(groupUpdate.build());
write(groupsBuilder); write(groupsBuilder);

View File

@ -221,7 +221,7 @@ public class Logic implements ApplicationListener{
runWave(); runWave();
} }
Groups.all.update(); Groups.update();
//TODO update groups //TODO update groups
/* /*

View File

@ -45,12 +45,11 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
array.sort(comp); array.sort(comp);
} }
public void updatePhysics(){
collisions.updatePhysics((EntityGroup<? extends Hitboxc>)this);
}
public void update(){ public void update(){
if(useTree()){
collisions.updatePhysics((EntityGroup<? extends Hitboxc>)this);
}
each(Entityc::update); each(Entityc::update);
} }

View File

@ -9,7 +9,7 @@ import mindustry.gen.*;
abstract class HealthComp implements Entityc{ abstract class HealthComp implements Entityc{
static final float hitDuration = 9f; static final float hitDuration = 9f;
float health, maxHealth, hitTime; float health, maxHealth = 1f, hitTime;
boolean dead; boolean dead;
boolean isValid(){ boolean isValid(){

View File

@ -99,6 +99,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
this.unit = unit; this.unit = unit;
if(unit != Nulls.unit){ if(unit != Nulls.unit){
unit.team(team); unit.team(team);
unit.controller(this);
} }
} }

View File

@ -41,7 +41,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
@Override @Override
public void controller(UnitController controller){ public void controller(UnitController controller){
this.controller = controller; this.controller = controller;
controller.unit(this); if(controller.unit() != this) controller.unit(this);
} }
@Override @Override
@ -58,6 +58,10 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
@Override @Override
public void type(UnitDef type){ public void type(UnitDef type){
this.type = type; this.type = type;
maxHealth(type.health);
heal();
drag(type.drag);
hitSize(type.hitsize);
controller(type.createController()); controller(type.createController());
setupWeapons(type); setupWeapons(type);
} }

View File

@ -13,6 +13,7 @@ import arc.util.ArcAnnotate.*;
import arc.util.*; import arc.util.*;
import mindustry.*; import mindustry.*;
import mindustry.core.GameState.*; import mindustry.core.GameState.*;
import mindustry.entities.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.*; import mindustry.game.*;
@ -138,7 +139,7 @@ public class DesktopInput extends InputHandler{
ui.listfrag.toggle(); ui.listfrag.toggle();
} }
if(((player.dead()) || state.isPaused()) && !ui.chatfrag.shown()){ if((player.dead() || state.isPaused()) && !ui.chatfrag.shown()){
//move camera around //move camera around
float camSpeed = !Core.input.keyDown(Binding.dash) ? 3f : 8f; float camSpeed = !Core.input.keyDown(Binding.dash) ? 3f : 8f;
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(Time.delta() * camSpeed)); Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(Time.delta() * camSpeed));
@ -147,6 +148,24 @@ public class DesktopInput extends InputHandler{
Core.camera.position.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * camSpeed; Core.camera.position.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * camSpeed;
Core.camera.position.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * camSpeed; Core.camera.position.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * camSpeed;
} }
}else if(!player.dead()){
Core.camera.position.lerpDelta(player, 0.08f);
}
//TODO remove: debug unit possession
if(player.dead() && Core.input.keyTap(Binding.select)){
Unitc unit = Units.closest(state.rules.defaultTeam, Core.input.mouseWorld().x, Core.input.mouseWorld().y, 40f, u -> true);
if(unit != null){
unit.hitbox(Tmp.r1);
if(Tmp.r1.contains(Core.input.mouseWorld())){
player.unit(unit);
}
}
}
//TODO implement
if(!player.dead()){
updateKeyboard(player.unit());
} }
if(Core.input.keyRelease(Binding.select)){ if(Core.input.keyRelease(Binding.select)){
@ -474,4 +493,75 @@ public class DesktopInput extends InputHandler{
selectRequests.clear(); selectRequests.clear();
} }
} }
protected void updateKeyboard(Unitc unit){
boolean canMove = !(Core.scene.getKeyboardFocus() instanceof TextField);
float speed = unit.type().speed;
float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y);
unit.vel().add(speed * xa, speed * ya);
/*
Tile tile = unit.tileOn();
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
//TODO implement
boolean isBoosting = Core.input.keyDown(Binding.dash) && !mech.flying;
//if player is in solid block
if(tile != null && tile.solid()){
isBoosting = true;
}
float speed = isBoosting && unit.type().flying ? mech.boostSpeed : mech.speed;
if(mech.flying){
//prevent strafing backwards, have a penalty for doing so
float penalty = 0.2f; //when going 180 degrees backwards, reduce speed to 0.2x
speed *= Mathf.lerp(1f, penalty, Angles.angleDist(rotation, velocity.angle()) / 180f);
}
movement.setZero();
float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y);
if(!(Core.scene.getKeyboardFocus() instanceof TextField)){
movement.y += ya * speed;
movement.x += xa * speed;
}
if(Core.input.keyDown(Binding.mouse_move)){
movement.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * speed;
movement.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * speed;
}
Vec2 vec = Core.input.mouseWorld(control.input.getMouseX(), control.input.getMouseY());
pointerX = vec.x;
pointerY = vec.y;
updateShooting();
movement.limit(speed).scl(Time.delta());
if(canMove){
velocity.add(movement.x, movement.y);
}else{
isShooting = false;
}
float prex = x, prey = y;
updateVelocityStatus();
moved = dst(prex, prey) > 0.001f;
if(canMove){
float baseLerp = mech.getRotationAlpha(this);
if(!isShooting() || !mech.faceTarget){
if(!movement.isZero()){
rotation = Mathf.slerpDelta(rotation, mech.flying ? velocity.angle() : movement.angle(), 0.13f * baseLerp);
}
}else{
float angle = control.input.mouseAngle(x, y);
this.rotation = Mathf.slerpDelta(this.rotation, angle, 0.1f * baseLerp);
}
}*/
}
} }

View File

@ -184,8 +184,6 @@ public class UnitDef extends UnlockableContent{
} }
public void drawCell(Unitc unit){ public void drawCell(Unitc unit){
if(!drawCell) return;
Draw.color(Color.black, unit.team().color, unit.healthf() + Mathf.absin(Time.time(), Math.max(unit.healthf() * 5f, 1f), 1f - unit.healthf())); Draw.color(Color.black, unit.team().color, unit.healthf() + Mathf.absin(Time.time(), Math.max(unit.healthf() * 5f, 1f), 1f - unit.healthf()));
Draw.rect(cellRegion, unit, unit.rotation() - 90); Draw.rect(cellRegion, unit, unit.rotation() - 90);
Draw.color(); Draw.color();