Skip to content

Commit

Permalink
Update to Alpha 8.1
Browse files Browse the repository at this point in the history
- Control Bytes (@pancake)
- Playback Interpolation (@pancake)
- Fixes a softlock
- Changing savestate loading behaviour
- Bug Fixes
  • Loading branch information
Scribble authored and Scribble committed May 8, 2022
2 parents 9f2b6e3 + c1d747e commit 04f9469
Show file tree
Hide file tree
Showing 24 changed files with 428 additions and 120 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'org.spongepowered.mixin'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "Alpha8"
version = "Alpha8.1"
group = "de.scribble.lp.tastools" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "TASmod-1.12.2"

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/de/pfannekuchen/infogui/gui/InfoHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import com.mojang.realmsclient.gui.ChatFormatting;

import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
import de.pfannekuchen.tasmod.events.CameraInterpolationEvents;
import de.pfannekuchen.tasmod.utils.PlayerPositionCalculator;
import de.pfannekuchen.tasmod.utils.TrajectoriesCalculator;
import de.scribble.lp.killtherng.KillTheRNG;
Expand Down Expand Up @@ -197,7 +199,6 @@ private void saveConfig() {
*/
public void tick() {
if (checkInit()) return;
for (InfoLabel label : lists) label.tick();
}

public boolean checkInit() {
Expand Down Expand Up @@ -268,7 +269,7 @@ public boolean checkInit() {
if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y);
lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
if (Minecraft.getMinecraft().currentScreen == this) return "Facing";
return String.format("%.2f %.2f", Minecraft.getMinecraft().player.rotationYaw, Minecraft.getMinecraft().player.rotationPitch);
return String.format("%.2f %.2f", CameraInterpolationEvents.rotationYaw, CameraInterpolationEvents.rotationPitch);
}));

title = "cticks";
Expand Down Expand Up @@ -386,9 +387,16 @@ public boolean checkInit() {
* Render the Info Hud only
*/
public void drawHud() {
// render custom info box if control byte is set
if (!ControlByteHandler.hideInfoBox && ClientProxy.virtual.getContainer().isPlayingback())
drawRectWithText(ControlByteHandler.text, 10, 10, true);
// skip rendering of control byte is set
if (!ControlByteHandler.shouldRenderHud && ClientProxy.virtual.getContainer().isPlayingback())
return;
int xpos=40;
int ypos=190;
for (InfoLabel label : lists) {
label.tick();
if (label.visible) {
drawRectWithText(label.renderText, label.x, label.y, label.renderRect);
} else if (Minecraft.getMinecraft().currentScreen != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.pfannekuchen.tasmod.controlbytes;

/**
* Handles playback control bytes
* @author Pancake
*/
public class ControlByteHandler {

/**
* Resets all control-byte-controlled settings
*/
public static void reset() {
ControlByteHandler.shouldInterpolate = false;
ControlByteHandler.shouldRenderHud = true;
ControlByteHandler.text = "";
ControlByteHandler.hideInfoBox = true;
}

/**
* Reacts to control bytes
* @param command Control Command
* @param args Arguments
*/
public static void onControlByte(String command, String[] args) {
switch (command.toLowerCase()) {
case "interpolation":
interpolation(args);
break;
case "hud":
hud(args);
break;
case "info":
info(args);
default:
break;
}
}

private static void info(String[] args) {
ControlByteHandler.hideInfoBox = "off".equals(args[0].trim()) || "false".equals(args[0].trim()) || "no".equals(args[0].trim()) || "0".equals(args[0].trim());
// Parse array as text
ControlByteHandler.text = "";
for (String string : args) {
ControlByteHandler.text += " " + string;
}
ControlByteHandler.text = ControlByteHandler.text.trim();
}

public static void interpolation(String[] args) {
ControlByteHandler.shouldInterpolate = "on".equals(args[0].trim()) || "true".equals(args[0].trim()) || "yes".equals(args[0].trim()) || "1".equals(args[0].trim());
}

public static void hud(String[] args) {
ControlByteHandler.shouldRenderHud = "on".equals(args[0].trim()) || "true".equals(args[0].trim()) || "yes".equals(args[0].trim()) || "1".equals(args[0].trim());
}

public static boolean hideInfoBox = true;
public static String text = "";
public static boolean shouldInterpolate = false;
public static boolean shouldRenderHud = true;

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
package de.pfannekuchen.tasmod.events;

import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
import de.scribble.lp.tasmod.ClientProxy;
import de.scribble.lp.tasmod.inputcontainer.TickInputContainer;
import de.scribble.lp.tasmod.mixin.accessors.AccessorRunStuff;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class CameraInterpolationEvents {

public static float rotationPitch = 0f;
public static float rotationYaw = 0f;

@SubscribeEvent
public void inter(CameraSetup ev) {
ev.setPitch(rotationPitch);
ev.setYaw(rotationYaw);
if (ClientProxy.virtual.getContainer().isPlayingback() && ControlByteHandler.shouldInterpolate) {
TickInputContainer input = ClientProxy.virtual.getContainer().get(ClientProxy.virtual.getContainer().index());
if (input == null) return;
float nextPitch = input.getSubticks().getPitch();
float nextYaw = input.getSubticks().getYaw();
ev.setPitch((float) MathHelper.clampedLerp(rotationPitch, nextPitch, ((AccessorRunStuff) Minecraft.getMinecraft()).timer().renderPartialTicks));
ev.setYaw((float) MathHelper.clampedLerp(rotationYaw, nextYaw+180, ((AccessorRunStuff) Minecraft.getMinecraft()).timer().renderPartialTicks));
} else {
ev.setPitch(rotationPitch);
ev.setYaw(rotationYaw);
}
}

}
4 changes: 4 additions & 0 deletions src/main/java/de/scribble/lp/tasmod/InfoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.mojang.realmsclient.gui.ChatFormatting;

import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
Expand All @@ -26,6 +27,9 @@ public void drawStuff(RenderGameOverlayEvent.Post event) {
if (event.isCancelable() || event.getType() != ElementType.HOTBAR) {
return;
}
// skip rendering control byte hide hud is set
if (!ControlByteHandler.shouldRenderHud && ClientProxy.virtual.getContainer().isPlayingback())
return;
ScaledResolution scaled = new ScaledResolution(mc);
int width = scaled.getScaledWidth();
int height = scaled.getScaledHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String getUsage(ICommandSender sender) {
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
try {
TASmod.savestateHandler.loadState(0, false);
TASmod.savestateHandler.loadState(0, false, false);
} catch (LoadstateException e) {
sender.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to load a savestate: "+e.getMessage()));
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.scribble.lp.tasmod.commands.fullrecord;

import de.scribble.lp.tasmod.ClientProxy;
import de.scribble.lp.tasmod.events.OpenGuiEvents;
import de.scribble.lp.tasmod.util.TASstate;
import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -43,6 +44,7 @@ public IMessage onMessage(FullRecordPacket message, MessageContext ctx) {
@SideOnly(Side.CLIENT)
private void workaround(Minecraft mc) {
OpenGuiEvents.stateWhenOpened = TASstate.RECORDING;
ClientProxy.virtual.getContainer().clear();
mc.world.sendQuittingDisconnectingPacket();
mc.loadWorld((WorldClient) null);
mc.displayGuiScreen(new net.minecraft.client.gui.GuiMainMenu());
Expand Down
37 changes: 24 additions & 13 deletions src/main/java/de/scribble/lp/tasmod/events/LoadWorldEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
public class LoadWorldEvents {

public static boolean waszero = false;
public static int cd = -1;
private static boolean isLoading =false;

/**
* Delay after the loading screen is finished before firing "doneWithLoadingScreen"
*/
private static int loadingScreenDelay = -1;

/**
* Executed when an integrated server is launched
Expand All @@ -20,20 +25,19 @@ public static void startLaunchServer() {
if (TickrateChangerClient.ticksPerSecond == 0 || TickrateChangerClient.advanceTick) {
waszero = true;
}
isLoading = true;
}

/**
* Executed when the server is initialising
* Side: Integrated Server
*
* @see de.scribble.lp.tasmod.mixin.events.MixinMinecraftServer#inject_run(org.spongepowered.asm.mixin.injection.callback.CallbackInfo)
* @see de.scribble.lp.tasmod.mixin.events.MixinIntegratedServer#inject_init(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable)
*/
public static void initServer() {
if (!TASmod.getServerInstance().isDedicatedServer()) {
TASmod.logger.info("Integrated server initialised");
TickrateChangerClient.pauseClientGame(true);
TickrateChangerServer.pauseServerGame(true);
}
TASmod.logger.info("Integrated server initialised");
TickrateChangerClient.pauseClientGame(true);
TickrateChangerServer.pauseServerGame(true);
}

/* The following code is for integrated and dedicated server! */
Expand Down Expand Up @@ -63,26 +67,33 @@ public static void doneShuttingDown() {
*/
public static void doneLoadingClientWorld() {
TASmod.logger.info("Finished loading the world on the client");
if(TASmod.getServerInstance()!=null) {
cd = 1;
if(TASmod.getServerInstance()!=null) { //Check if a server is running and if it's an integrated server
loadingScreenDelay = 1;
}
}

/**
* Executed a frame after the world is done loading
*/
public static void doneWithLoadingScreen() {
if (cd > -1) {
if (cd == 0) {
if (loadingScreenDelay > -1) {
if (loadingScreenDelay == 0) {
TASmod.logger.info("Finished loading screen on the client");
if (!waszero) {
TickrateChangerClient.pauseGame(false);
if(TASmod.getServerInstance()!=null) { //Check if a server is running and if it's an integrated server
TickrateChangerClient.pauseClientGame(false);
TickrateChangerServer.pauseServerGame(false);
}
} else {
waszero = false;
}
isLoading=false;
}
cd--;
loadingScreenDelay--;
}
}

public static boolean isLoading() {
return isLoading;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package de.scribble.lp.tasmod.inputcontainer;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.lwjgl.opengl.Display;

import com.dselent.bigarraylist.BigArrayList;
import com.mojang.realmsclient.gui.ChatFormatting;
import com.mojang.realmsclient.util.Pair;

import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
import de.scribble.lp.tasmod.ClientProxy;
import de.scribble.lp.tasmod.CommonProxy;
import de.scribble.lp.tasmod.monitoring.DesyncMonitoring;
Expand Down Expand Up @@ -69,6 +74,9 @@ public class InputContainer {
*/
private BigArrayList<TickInputContainer> inputs = new BigArrayList<TickInputContainer>(directory + File.separator + "temp");

// All control characters
private Map<Integer, List<Pair<String, String[]>>> controls = new HashMap<Integer, List<Pair<String, String[]>>>();

public DesyncMonitoring dMonitor = new DesyncMonitoring();

// =====================================================================================================
Expand Down Expand Up @@ -105,6 +113,7 @@ public String setTASState(TASstate stateIn) {
* @return The message printed in the chat
*/
public String setTASState(TASstate stateIn, boolean verbose) {
ControlByteHandler.reset();
if (state == stateIn) {
switch (stateIn) {
case PLAYBACK:
Expand Down Expand Up @@ -360,6 +369,11 @@ private void playbackNextTick() {
this.keyboard = tickcontainer.getKeyboard().clone();
this.mouse = tickcontainer.getMouse().clone();
this.subticks = tickcontainer.getSubticks().clone();
// check for control bytes
List<Pair<String, String[]>> controlbyte = controls.get(index);
if (controlbyte != null)
for (Pair<String, String[]> pair : controlbyte)
ControlByteHandler.onControlByte(pair.first(), pair.second());
}
}
// =====================================================================================================
Expand All @@ -381,13 +395,21 @@ public BigArrayList<TickInputContainer> getInputs() {
return inputs;
}

public void setIndex(int index) {
this.index = index;
if (state == TASstate.PLAYBACK) {
TickInputContainer tickcontainer = inputs.get(index);
this.keyboard = tickcontainer.getKeyboard();
this.mouse = tickcontainer.getMouse();
this.subticks = tickcontainer.getSubticks();
public Map<Integer, List<Pair<String, String[]>>> getControlBytes() {
return controls;
}

public void setIndex(int index) throws IndexOutOfBoundsException{
if(index<=size()) {
this.index = index;
if (state == TASstate.PLAYBACK) {
TickInputContainer tickcontainer = inputs.get(index);
this.keyboard = tickcontainer.getKeyboard();
this.mouse = tickcontainer.getMouse();
this.subticks = tickcontainer.getSubticks();
}
}else {
throw new IndexOutOfBoundsException("Index is bigger than the container");
}
}

Expand All @@ -403,6 +425,7 @@ public TickInputContainer get(int index) {

public void clear() {
inputs = new BigArrayList<TickInputContainer>(directory + File.separator + "temp");
controls.clear();
index = 0;
dMonitor.getPos().clear();
clearCredits();
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,28 @@ public void redirectThreadSleep(long msToTick) {
if (TickrateChangerServer.ticksPerSecond == 0) {
currentTime = System.currentTimeMillis();
faketick++;
if (faketick >= 20) {
if (faketick >= 50) {
faketick = 0;
networkSystem.networkTick();
if (((MinecraftServer) (Object) this).isDedicatedServer()) {
runPendingCommands();
}
synchronized (this.futureTaskQueue) {
while (!this.futureTaskQueue.isEmpty()) {
try {
((FutureTask<?>) this.futureTaskQueue.poll()).run();
} catch (Throwable var9) {
var9.printStackTrace();
}
}
}
}
}
if (TickrateChangerServer.interrupt) {
currentTime = System.currentTimeMillis();
msToTick = 1L;
TickrateChangerServer.interrupt = false;
}
synchronized (this.futureTaskQueue) {
while (!this.futureTaskQueue.isEmpty()) {
try {
((FutureTask<?>) this.futureTaskQueue.poll()).run();
} catch (Throwable var9) {
var9.printStackTrace();
}
}
}

try {
Thread.sleep(1L);
Expand Down
Loading

0 comments on commit 04f9469

Please sign in to comment.