Skip to content

Commit

Permalink
last timing remake with new format
Browse files Browse the repository at this point in the history
  • Loading branch information
kurrycat committed Apr 23, 2023
1 parent 35f0492 commit a152671
Show file tree
Hide file tree
Showing 13 changed files with 567 additions and 499 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.github.kurrycat.mpkmod.gui.screens.options_gui.OptionsGuiScreen;
import io.github.kurrycat.mpkmod.landingblock.LandingBlock;
import io.github.kurrycat.mpkmod.save.Serializer;
import io.github.kurrycat.mpkmod.ticks.InputPatternStorage;
import io.github.kurrycat.mpkmod.ticks.TimingStorage;
import io.github.kurrycat.mpkmod.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -69,7 +69,8 @@ public static void preInit(Class<?> callerClass) {
optionsMap = Option.createOptionMap();
Option.updateOptionMapFromJSON(true);

InputPatternStorage.init();
//InputPatternStorage.init();
TimingStorage.init();

mainGUI = new MainGuiScreen();
registerGUIScreen("main_gui", mainGUI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import io.github.kurrycat.mpkmod.gui.screens.LandingBlockGuiScreen;
import io.github.kurrycat.mpkmod.landingblock.LandingBlock;
import io.github.kurrycat.mpkmod.ticks.InputPatternStorage;
import io.github.kurrycat.mpkmod.ticks.TickInput;
import io.github.kurrycat.mpkmod.ticks.TimingInput;
import io.github.kurrycat.mpkmod.ticks.TimingStorage;
import io.github.kurrycat.mpkmod.util.BoundingBox3D;
import io.github.kurrycat.mpkmod.util.Copyable;
import io.github.kurrycat.mpkmod.util.Tuple;
import io.github.kurrycat.mpkmod.util.Vector3D;

Expand All @@ -21,7 +22,7 @@ public class Player {
public static ArrayList<Player> tickHistory = new ArrayList<>();
public static int maxSavedTicks = 20;
public static Player displayInstance = new Player();
public TickInput tickInput = null;
public TimingInput timingInput = new TimingInput("");
public KeyInput keyInput = null;
private Vector3D pos = null;
private Vector3D lastPos = null;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static void updateDisplayInstance() {
if (o instanceof Float && (Float) o == 0F) continue;

if (o instanceof Vector3D) f.set(displayInstance, ((Vector3D) o).copy());
else if (o instanceof TickInput) f.set(displayInstance, ((TickInput) o).copy());
else if (o instanceof Copyable) f.set(displayInstance, ((Copyable<?>) o).copy());
else f.set(displayInstance, o);
}
} catch (IllegalAccessException ignored) {
Expand Down Expand Up @@ -92,25 +93,17 @@ public static Player getLatest() {
return tickHistory.get(tickHistory.size() - 1);
}

public static String getHexHistory() {
StringBuilder sb = new StringBuilder();
for (Player p : tickHistory) {
sb.append(p.tickInput.hex());
}
return sb.toString();
}

public static List<TickInput> getInputHistory() {
return tickHistory.stream().map(p -> p.tickInput).collect(Collectors.toList());
public static List<TimingInput> getInputHistory() {
return tickHistory.stream().map(p -> p.timingInput).collect(Collectors.toList());
}

public static List<String> getInputList() {
ArrayList<Tuple<TickInput, Integer>> inputList = new ArrayList<>();
for (TickInput p : getInputHistory()) {
ArrayList<Tuple<TimingInput, Integer>> inputList = new ArrayList<>();
for (TimingInput p : getInputHistory()) {
if (inputList.isEmpty())
inputList.add(new Tuple<>(p, 1));

Tuple<TickInput, Integer> last = inputList.get(inputList.size() - 1);
Tuple<TimingInput, Integer> last = inputList.get(inputList.size() - 1);
if (last.getFirst().equals(p))
last.setSecond(last.getSecond() + 1);
else inputList.add(new Tuple<>(p, 1));
Expand Down Expand Up @@ -151,7 +144,6 @@ public Player getPrevious() {

public Player constructKeyInput() {
keyInput = KeyInput.construct();
tickInput = new TickInput(keyInput);
return this;
}

Expand Down Expand Up @@ -285,14 +277,26 @@ public Player buildAndSave() {
deltaYaw = trueYaw - prev.trueYaw;
deltaPitch = truePitch - prev.truePitch;

tickInput.updateToMovement(jumpTick);

if (prev.jumpTick && !prev.tickInput.isMovingSideways() && tickInput.isMovingSideways()) {
//TODO: use mc inputs instead of keys (e.g. player not being able to sprint because of hunger but it still saving sprint when button is pressed)
timingInput = new TimingInput(
keyInput.forward,
keyInput.left,
keyInput.back,
keyInput.right,
keyInput.sprint,
keyInput.sneak,
jumpTick,
onGround
);

if (prev.jumpTick && !prev.keyInput.isMovingSideways() && keyInput.isMovingSideways()) {
last45 = prev.deltaYaw;
}

lastTiming = TimingStorage.match(getInputHistory());
}

lastTiming = InputPatternStorage.match(getInputHistory());
//lastTiming = InputPatternStorage.match(getInputHistory());

Player.updateDisplayInstance();
return this;
Expand Down Expand Up @@ -342,5 +346,9 @@ public static KeyInput construct() {
public String toString() {
return "{W:" + forward + ", A:" + left + ", S:" + back + ", D:" + right + ", N:" + sneak + ", P:" + sprint + ", J:" + jump + "}";
}

public boolean isMovingSideways() {
return left ^ right;
}
}
}
4 changes: 0 additions & 4 deletions src/main/java/io/github/kurrycat/mpkmod/test/CodeTesting.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package io.github.kurrycat.mpkmod.test;

import io.github.kurrycat.mpkmod.ticks.InputPattern;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.util.Arrays;


public class CodeTesting {
public static boolean test = false;
Expand Down
216 changes: 0 additions & 216 deletions src/main/java/io/github/kurrycat/mpkmod/ticks/InputPattern.java

This file was deleted.

Loading

0 comments on commit a152671

Please sign in to comment.