Skip to content

Commit

Permalink
Massive amount of refactoring for local multiplayer, annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed May 12, 2018
1 parent 959f756 commit 00e70cb
Show file tree
Hide file tree
Showing 47 changed files with 592 additions and 492 deletions.
4 changes: 4 additions & 0 deletions annotations/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apply plugin: "java"

sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
Binary file added annotations/build/libs/annotations-release.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions annotations/build/tmp/jar/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

40 changes: 40 additions & 0 deletions annotations/src/io/anuke/annotations/AnnotationProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.anuke.annotations;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic.Kind;
import java.util.Set;

@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes({
"java.lang.Override"
})
public class AnnotationProcessor extends AbstractProcessor {
private Types typeUtils;
private Elements elementUtils;
private Filer filer;
private Messager messager;

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
typeUtils = processingEnv.getTypeUtils();
elementUtils = processingEnv.getElementUtils();
filer = processingEnv.getFiler();
messager = processingEnv.getMessager();
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Override.class)) {
messager.printMessage(Kind.ERROR, "an element has the override class: ", annotatedElement);
}
return false;
}


}
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ project(":core") {
apply plugin: "java"

dependencies {
compile project(":annotations")

boolean comp = System.properties["release"] == null || System.properties["release"] == "false"

if(!comp){
Expand All @@ -165,10 +167,16 @@ project(":core") {
if(new File('../GDXGifRecorder').exists() && comp) {
compile project(":GDXGifRecorder")
}

compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
}

compileJava.options.compilerArgs = [
"-proc:only",
"-processor", "io.anuke.annotations.AnnotationProcessor"
]
}

project(":server") {
Expand All @@ -182,6 +190,12 @@ project(":server") {
}
}

project(":annotations") {
apply plugin: "java"

dependencies {}
}

project(":kryonet") {
apply plugin: "java"

Expand Down
4 changes: 3 additions & 1 deletion core/src/io/anuke/mindustry/Vars.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class Vars{
//whether to show block debug
public static boolean showBlockDebug = false;

public static final int maxTextLength = 150;

public static boolean headless = false;

public static float controllerMin = 0.25f;
Expand Down Expand Up @@ -143,7 +145,7 @@ public class Vars{
public static NetServer netServer;
public static NetClient netClient;

public static Player[] players;
public static Player[] players = {};

public static final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
public static final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
Expand Down
148 changes: 53 additions & 95 deletions core/src/io/anuke/mindustry/core/Control.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.anuke.mindustry.core;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.content.Mechs;
Expand All @@ -25,10 +26,7 @@
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Atlas;
import io.anuke.ucore.util.Input;
import io.anuke.ucore.util.InputProxy;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.*;

import static io.anuke.mindustry.Vars.*;

Expand All @@ -37,19 +35,14 @@
* Should <i>not</i> handle any logic-critical state.
* This class is not created in the headless server.*/
public class Control extends Module{
private Tutorial tutorial = new Tutorial();
private boolean hiscore = false;

private boolean wasPaused = false;

private Saves saves;
private InputHandler[] inputs = {};

private InputHandler[] inputs;

private InputProxy proxy;
private float controlx, controly;
private boolean controlling;
private Throwable error;
private InputProxy proxy;
private Input gdxInput;

public Control(){
saves = new Saves();
Expand All @@ -58,35 +51,39 @@ public Control(){

Gdx.input.setCatchBackKey(true);

proxy = new InputProxy(Gdx.input){
Effects.setShakeFalloff(10000f);

Core.atlas = new Atlas("sprites.atlas");

for(Item item : Item.getAllItems()){
item.init();
}

gdxInput = Gdx.input;

proxy = new InputProxy(Gdx.input){
@Override
public int getY() {
return controlling ? (int)controly : input.getY();
public int getX(int pointer) {
return pointer >= inputs.length ? super.getX(pointer) : (int)inputs[pointer].getMouseX();
}

@Override
public int getX() {
return controlling ? (int)controlx : input.getX();
public int getY(int pointer) {
return pointer >= inputs.length ? super.getY(pointer) : (int)inputs[pointer].getMouseY();
}

@Override
public int getY(int pointer) {
return pointer == 0 ? getY() : super.getY(pointer);
}
@Override
public int getX() {
return (int)inputs[0].getMouseX();
}

@Override
public int getX(int pointer) {
return pointer == 0 ? getX() : super.getX(pointer);
}
@Override
public int getY() {
return (int)inputs[0].getMouseY();
}
};

Effects.setShakeFalloff(10000f);

Core.atlas = new Atlas("sprites.atlas");

for(Item item : Item.getAllItems()){
item.init();
}
Gdx.input = proxy;

Sounds.load("shoot.mp3", "place.mp3", "explosion.mp3", "enemyshoot.mp3",
"corexplode.mp3", "break.mp3", "spawn.mp3", "flame.mp3", "die.mp3",
Expand All @@ -102,8 +99,11 @@ public int getX(int pointer) {
Settings.defaultList(
"ip", "localhost",
"port", port+"",
"servers", "",
"color", Color.rgba8888(playerColors[8]),
"color-0", Color.rgba8888(playerColors[8]),
"color-1", Color.rgba8888(playerColors[11]),
"color-2", Color.rgba8888(playerColors[13]),
"color-3", Color.rgba8888(playerColors[9]),
"name", "player",
"lastBuild", 0
);

Expand Down Expand Up @@ -156,7 +156,6 @@ public int getX(int pointer) {
Events.on(GameOverEvent.class, () -> {
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);


//TODO game over effect
ui.restart.show();

Expand All @@ -166,10 +165,20 @@ public int getX(int pointer) {

//TODO drop player method
public void addPlayer(int index){
if(players.length < index + 1){
Player[] old = players;
players = new Player[index + 1];
System.arraycopy(old, 0, players, 0, old.length);

InputHandler[] oldi = inputs;
inputs = new InputHandler[index + 1];
System.arraycopy(old, 0, inputs, 0, oldi.length);
}

Player player = new Player();
player.name = Settings.getString("name-" + index, "player");
player.name = Settings.getString("name");
player.mech = mobile ? Mechs.standardShip : Mechs.standard;
player.color.set(Settings.getInt("color"));
player.color.set(Settings.getInt("color-" + index));
player.isLocal = true;
player.playerIndex = index;
players[index] = player;
Expand All @@ -186,10 +195,9 @@ public void addPlayer(int index){
Inputs.addProcessor(input);
}

//FIXME figure out what's causing this problem in the first place
public void triggerInputUpdate(){
Gdx.input = proxy;
}
public Input gdxInput(){
return gdxInput;
}

public void setError(Throwable error){
this.error = error;
Expand All @@ -199,14 +207,14 @@ public Saves getSaves(){
return saves;
}

public boolean showCursor(){
return controlling;
}

public InputHandler input(int index){
return inputs[index];
}

public void triggerUpdateInput(){
Gdx.input = proxy;
}

public void playMap(Map map){
ui.loadfrag.show();
saves.resetSave();
Expand All @@ -224,10 +232,6 @@ public boolean isHighScore(){
return hiscore;
}

public Tutorial tutorial(){
return tutorial;
}

@Override
public void dispose(){
Platform.instance.onGameExit();
Expand Down Expand Up @@ -261,52 +265,10 @@ public void update(){
throw new RuntimeException(error);
}

Gdx.input = proxy;

if(Inputs.keyTap("console")){
console = !console;
}

if(KeyBinds.getSection("default").device.type == DeviceType.controller){
if(Inputs.keyTap("select")){
Inputs.getProcessor().touchDown(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
}

if(Inputs.keyRelease("select")){
Inputs.getProcessor().touchUp(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
}

float xa = Inputs.getAxis("cursor_x");
float ya = Inputs.getAxis("cursor_y");

if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
controlx += xa*baseControllerSpeed*scl;
controly -= ya*baseControllerSpeed*scl;
controlling = true;

Gdx.input.setCursorCatched(true);

Inputs.getProcessor().touchDragged(Gdx.input.getX(), Gdx.input.getY(), 0);
}

controlx = Mathf.clamp(controlx, 0, Gdx.graphics.getWidth());
controly = Mathf.clamp(controly, 0, Gdx.graphics.getHeight());

if(Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1) {
controlling = false;
Gdx.input.setCursorCatched(false);
}
}else{
controlling = false;
Gdx.input.setCursorCatched(false);
}

if(!controlling){
controlx = Gdx.input.getX();
controly = Gdx.input.getY();
}

saves.update();

if(!state.is(State.menu)){
Expand Down Expand Up @@ -335,10 +297,6 @@ public void update(){
if(!state.is(State.paused) || Net.active()){
Entities.update(effectGroup);
Entities.update(groundEffectGroup);

if(tutorial.active()){
tutorial.update();
}
}
}else{
if(!state.is(State.paused) || Net.active()){
Expand Down
2 changes: 1 addition & 1 deletion core/src/io/anuke/mindustry/core/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void update(){

if(!state.is(State.menu)){

if(control != null) control.triggerInputUpdate();
if(control != null) control.triggerUpdateInput();

if(!state.is(State.paused) || Net.active()){
Timers.update();
Expand Down
Loading

0 comments on commit 00e70cb

Please sign in to comment.