Merge branch 'stable' into develop
This commit is contained in:
@@ -476,6 +476,14 @@ public class ReplayMod implements
|
||||
String name = path.getFileName().toString();
|
||||
if (name.endsWith(".mcpr.tmp") && Files.isDirectory(path)) {
|
||||
Path original = path.resolveSibling(FilenameUtils.getBaseName(name));
|
||||
Path noRecoverMarker = original.resolveSibling(original.getFileName() + ".no_recover");
|
||||
if (Files.exists(noRecoverMarker)) {
|
||||
// This file, when its markers are processed, doesn't actually result in any replays.
|
||||
// So we don't really need to recover it either, let's just get rid of it.
|
||||
FileUtils.deleteDirectory(path.toFile());
|
||||
Files.delete(noRecoverMarker);
|
||||
continue;
|
||||
}
|
||||
new RestoreReplayGui(this, GuiScreen.wrap(mc.currentScreen), original.toFile()).display();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +80,16 @@ import org.lwjgl.glfw.GLFW;
|
||||
//$$ import java.io.IOException;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11400
|
||||
import net.minecraft.client.sound.PositionedSoundInstance;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10904
|
||||
import com.replaymod.render.blend.mixin.ParticleAccessor;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
//#endif
|
||||
|
||||
@@ -758,6 +765,20 @@ public class MCVer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void playSound(Identifier sound) {
|
||||
getMinecraft().getSoundManager().play(
|
||||
//#if MC>=11400
|
||||
PositionedSoundInstance.master(new SoundEvent(sound), 1.0F)
|
||||
//#elseif MC>=10904
|
||||
//$$ PositionedSoundRecord.getMasterRecord(new SoundEvent(sound), 1.0F)
|
||||
//#elseif MC>=10800
|
||||
//$$ PositionedSoundRecord.create(sound, 1.0F)
|
||||
//#else
|
||||
//$$ PositionedSoundRecord.createPositionedSoundRecord(sound, 1.0F)
|
||||
//#endif
|
||||
);
|
||||
}
|
||||
|
||||
//#if MC>=11400
|
||||
private static Boolean hasOptifine;
|
||||
public static boolean hasOptifine() {
|
||||
|
||||
@@ -272,6 +272,10 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
// Immediately close the saving popup, the user doesn't care about it
|
||||
core.runLater(guiSavingReplay::close);
|
||||
|
||||
// If we crash right here, on the next start we'll prompt the user for recovery
|
||||
// but we don't really want that, so drop a marker file to skip recovery for this replay.
|
||||
Files.createFile(outputPath.resolveSibling(outputPath.getFileName() + ".no_recover"));
|
||||
|
||||
// We still have the replay, so we just save it (at least for a few weeks) in case they change their mind
|
||||
String replayName = FilenameUtils.getBaseName(outputPath.getFileName().toString());
|
||||
Path rawFolder = ReplayMod.instance.getRawReplayFolder();
|
||||
|
||||
@@ -443,4 +443,32 @@ public class RenderSettings {
|
||||
public boolean isHighPerformance() {
|
||||
return highPerformance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RenderSettings{" +
|
||||
"renderMethod=" + renderMethod +
|
||||
", encodingPreset=" + encodingPreset +
|
||||
", videoWidth=" + videoWidth +
|
||||
", videoHeight=" + videoHeight +
|
||||
", framesPerSecond=" + framesPerSecond +
|
||||
", bitRate=" + bitRate +
|
||||
", outputFile=" + outputFile +
|
||||
", renderNameTags=" + renderNameTags +
|
||||
", stabilizeYaw=" + stabilizeYaw +
|
||||
", stabilizePitch=" + stabilizePitch +
|
||||
", stabilizeRoll=" + stabilizeRoll +
|
||||
", chromaKeyingColor=" + chromaKeyingColor +
|
||||
", sphericalFovX=" + sphericalFovX +
|
||||
", sphericalFovY=" + sphericalFovY +
|
||||
", injectSphericalMetadata=" + injectSphericalMetadata +
|
||||
", depthMap=" + depthMap +
|
||||
", cameraPathExport=" + cameraPathExport +
|
||||
", antiAliasing=" + antiAliasing +
|
||||
", exportCommand='" + exportCommand + '\'' +
|
||||
", exportArgumentsPreBgra='" + exportArgumentsPreBgra + '\'' +
|
||||
", exportArguments='" + exportArguments + '\'' +
|
||||
", highPerformance=" + highPerformance +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.replaymod.render.ReplayModRender.LOGGER;
|
||||
|
||||
@@ -148,8 +149,15 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements
|
||||
renderButton.onClick(() -> {
|
||||
LOGGER.trace("Render button clicked");
|
||||
List<RenderJob> renderQueue = new ArrayList<>();
|
||||
for (Entry entry : selectedEntries) {
|
||||
renderQueue.add(entry.job);
|
||||
if (selectedEntries.isEmpty()) {
|
||||
renderQueue.addAll(jobs);
|
||||
} else {
|
||||
Set<RenderJob> selectedJobs = selectedEntries.stream().map(it -> it.job).collect(Collectors.toSet());
|
||||
for (RenderJob job : jobs) {
|
||||
if (selectedJobs.contains(job)) {
|
||||
renderQueue.add(job);
|
||||
}
|
||||
}
|
||||
}
|
||||
ReplayMod.instance.runLaterWithoutLock(() -> processQueue(container, replayHandler, renderQueue, () -> {}));
|
||||
});
|
||||
@@ -337,7 +345,7 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> implements
|
||||
addButton.setEnabled(timelineSupplier != null);
|
||||
editButton.setEnabled(selected == 1);
|
||||
removeButton.setEnabled(selected >= 1);
|
||||
renderButton.setEnabled(selected > 0);
|
||||
renderButton.setEnabled(jobs.size() > 0);
|
||||
renderButton.setI18nLabel("replaymod.gui.renderqueue.render" + (selected > 0 ? "selected" : "all"));
|
||||
|
||||
String[] compatError = VideoRenderer.checkCompat();
|
||||
|
||||
@@ -126,7 +126,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
public void run() {
|
||||
GuiFileChooserPopup popup = GuiFileChooserPopup.openSaveGui(GuiRenderSettings.this, "replaymod.gui.save",
|
||||
encodingPresetDropdown.getSelectedValue().getFileExtension());
|
||||
popup.setFolder(outputFile.getParentFile());
|
||||
popup.setFolder(getParentFile(outputFile));
|
||||
popup.setFileName(outputFile.getName());
|
||||
popup.onAccept(file -> {
|
||||
if (!file.getName().equals(outputFile.getName())) {
|
||||
@@ -523,13 +523,13 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
bitRateUnit.setSelected(0);
|
||||
}
|
||||
File savedOutputFile = settings.getOutputFile();
|
||||
if (savedOutputFile == null || !savedOutputFile.getParentFile().exists()) {
|
||||
if (savedOutputFile == null || !getParentFile(savedOutputFile).exists()) {
|
||||
this.outputFile = generateOutputFile(encodingPreset);
|
||||
userDefinedOutputFileName = false;
|
||||
} else if (savedOutputFile.exists()) {
|
||||
String name = generateOutputFile(encodingPreset).getName();
|
||||
boolean isFolder = savedOutputFile.isDirectory() && !savedOutputFile.getName().endsWith(".exr");
|
||||
this.outputFile = new File(isFolder ? savedOutputFile : savedOutputFile.getParentFile(), name);
|
||||
this.outputFile = new File(isFolder ? savedOutputFile : getParentFile(savedOutputFile), name);
|
||||
userDefinedOutputFileName = false;
|
||||
} else {
|
||||
this.outputFile = conformExtension(savedOutputFile, encodingPreset);
|
||||
@@ -573,7 +573,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
videoHeight.getInteger(),
|
||||
frameRateSlider.getValue() + 10,
|
||||
bitRateField.getInteger() << (10 * bitRateUnit.getSelected()),
|
||||
serialize && !userDefinedOutputFileName ? outputFile.getParentFile() : outputFile,
|
||||
serialize && !userDefinedOutputFileName ? getParentFile(outputFile) : outputFile,
|
||||
nametagCheckbox.isChecked(),
|
||||
stabilizeYaw.isChecked() && (serialize || stabilizeYaw.isEnabled()),
|
||||
stabilizePitch.isChecked() && (serialize || stabilizePitch.isEnabled()),
|
||||
@@ -602,7 +602,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
|
||||
public void setOutputFileBaseName(String base) {
|
||||
RenderSettings.EncodingPreset preset = encodingPresetDropdown.getSelectedValue();
|
||||
File file = new File(outputFile.getParentFile(), base + "." + preset.getFileExtension());
|
||||
File file = new File(getParentFile(outputFile), base + "." + preset.getFileExtension());
|
||||
// Ensure the file name is valid
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
@@ -619,7 +619,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
if (name.contains(".")) {
|
||||
name = name.substring(0, name.lastIndexOf('.'));
|
||||
}
|
||||
return new File(file.getParentFile(), name + "." + preset.getFileExtension());
|
||||
return new File(getParentFile(file), name + "." + preset.getFileExtension());
|
||||
}
|
||||
|
||||
protected Path getSettingsPath() {
|
||||
@@ -662,4 +662,10 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
screen.setBackground(AbstractGuiScreen.Background.NONE);
|
||||
return screen;
|
||||
}
|
||||
|
||||
private static File getParentFile(File file) {
|
||||
File parent = file.getParentFile();
|
||||
// parent this can be null if file is just a name (i.e. in CWD)
|
||||
return parent == null ? new File(".") : parent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.replaymod.render.gui.GuiRenderingDone;
|
||||
import com.replaymod.render.gui.GuiVideoRenderer;
|
||||
import com.replaymod.render.metadata.MetadataInjector;
|
||||
import com.replaymod.render.mixin.WorldRendererAccessor;
|
||||
import com.replaymod.render.utils.SoundHandler;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
@@ -29,6 +28,7 @@ import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import com.mojang.blaze3d.platform.GLX;
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
@@ -422,7 +422,7 @@ public class VideoRenderer implements RenderInfo {
|
||||
}
|
||||
}
|
||||
|
||||
new SoundHandler().playRenderSuccessSound();
|
||||
MCVer.playSound(new Identifier("replaymod", "render_success"));
|
||||
|
||||
try {
|
||||
if (!hasFailed() && ffmpegWriter != null) {
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.replaymod.render.utils;
|
||||
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SoundHandler {
|
||||
|
||||
private final Identifier successSoundLocation = new Identifier("replaymod", "render_success.wav");
|
||||
|
||||
public void playRenderSuccessSound() {
|
||||
playSound(successSoundLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a <b>.wav</b> Sound from a ResourceLocation. This method does <b>not</b> respect Game Settings like Audio Volume.
|
||||
* @param loc The Sound File's ResourceLocation
|
||||
*/
|
||||
public void playSound(Identifier loc) {
|
||||
try {
|
||||
InputStream is = MCVer.getMinecraft().getResourceManager().getResource(loc).getInputStream();
|
||||
byte[] bytes = IOUtils.toByteArray(is);
|
||||
is.close();
|
||||
AudioInputStream ais = AudioSystem.getAudioInputStream(new ByteArrayInputStream(bytes));
|
||||
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(ais);
|
||||
clip.start();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -339,9 +339,8 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
*/
|
||||
@Override
|
||||
public int currentTimeStamp() {
|
||||
if (asyncMode) {
|
||||
int timePassed = (int) (System.currentTimeMillis() - lastPacketSent);
|
||||
return lastTimeStamp + (int) (timePassed * getReplaySpeed());
|
||||
if (asyncMode && !paused()) {
|
||||
return (int) ((System.currentTimeMillis() - realTimeStart) * realTimeStartSpeed);
|
||||
} else {
|
||||
return lastTimeStamp;
|
||||
}
|
||||
@@ -864,7 +863,11 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
*/
|
||||
@Override
|
||||
public void setReplaySpeed(final double d) {
|
||||
if(d != 0) this.replaySpeed = d;
|
||||
if (d != 0) {
|
||||
this.replaySpeed = d;
|
||||
this.realTimeStartSpeed = d;
|
||||
this.realTimeStart = System.currentTimeMillis() - (long) (lastTimeStamp / d);
|
||||
}
|
||||
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
|
||||
//#if MC>=11200
|
||||
timer.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK / (float) d);
|
||||
@@ -878,9 +881,18 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* The real time at which the last packet was sent in milliseconds.
|
||||
* Timestamp in milliseconds of when we started (or would have started when taking pauses and speed into account)
|
||||
* the playback of the replay.
|
||||
* Updated only when replay speed changes or on pause/unpause but definitely not on every packet to prevent gradual
|
||||
* drifting.
|
||||
*/
|
||||
private long lastPacketSent;
|
||||
private long realTimeStart;
|
||||
|
||||
/**
|
||||
* The replay speed used for {@link #realTimeStart}.
|
||||
* If the target speed differs from this one, the timestamp is recalculated.
|
||||
*/
|
||||
private double realTimeStartSpeed;
|
||||
|
||||
/**
|
||||
* There is no waiting performed until a packet with at least this timestamp is reached (but not yet sent).
|
||||
@@ -936,15 +948,13 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
// If we aren't jumping and the world has already been loaded (no dirt-screens) then wait
|
||||
// the required amount to get proper packet timing
|
||||
if (!isHurrying() && hasWorldLoaded) {
|
||||
// How much time should have passed
|
||||
int timeWait = (int) Math.round((nextTimeStamp - lastTimeStamp) / replaySpeed);
|
||||
// How much time did pass
|
||||
long timeDiff = System.currentTimeMillis() - lastPacketSent;
|
||||
// How much time we need to wait to make up for the difference
|
||||
long timeToSleep = Math.max(0, timeWait - timeDiff);
|
||||
|
||||
Thread.sleep(timeToSleep);
|
||||
lastPacketSent = System.currentTimeMillis();
|
||||
// Timestamp of when the next packet should be sent
|
||||
long expectedTime = realTimeStart + (long) (nextTimeStamp / replaySpeed);
|
||||
long now = System.currentTimeMillis();
|
||||
// If the packet should not yet be sent, wait a bit
|
||||
if (expectedTime > now) {
|
||||
Thread.sleep(expectedTime - now);
|
||||
}
|
||||
}
|
||||
|
||||
// Process packet
|
||||
@@ -961,7 +971,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
|
||||
replayHandler.moveCameraToTargetPosition();
|
||||
|
||||
// Pause after jumping
|
||||
// Pause after jumping (this will also reset realTimeStart accordingly)
|
||||
setReplaySpeed(0);
|
||||
}
|
||||
} catch (EOFException eof) {
|
||||
@@ -988,7 +998,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
loginPhase = true;
|
||||
startFromBeginning = false;
|
||||
nextPacket = null;
|
||||
lastPacketSent = System.currentTimeMillis();
|
||||
realTimeStart = System.currentTimeMillis();
|
||||
if (replayIn != null) {
|
||||
replayIn.close();
|
||||
replayIn = null;
|
||||
@@ -1133,7 +1143,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
}
|
||||
|
||||
// This might be required if we change to async mode anytime soon
|
||||
lastPacketSent = System.currentTimeMillis();
|
||||
realTimeStart = System.currentTimeMillis() - (long) (timestamp / replaySpeed);
|
||||
lastTimeStamp = timestamp;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -51,6 +51,7 @@ import net.minecraft.util.hit.HitResult;
|
||||
//$$ import net.minecraft.util.math.RayTraceResult;
|
||||
//$$ import net.minecraft.util.text.ITextComponent;
|
||||
//$$ import net.minecraft.world.World;
|
||||
//$$ import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
//$$
|
||||
//#if MC>=11400
|
||||
//$$ import net.minecraft.util.math.RayTraceFluidMode;
|
||||
@@ -637,12 +638,11 @@ public class CameraEntity
|
||||
}
|
||||
|
||||
public boolean canSpectate(Entity e) {
|
||||
return e != null && !e.isInvisible()
|
||||
//#if MC>=10800
|
||||
&& (e instanceof PlayerEntity || e instanceof MobEntity || e instanceof ItemFrameEntity);
|
||||
//#else
|
||||
//$$ && e instanceof EntityPlayer; // cannot be more generic since 1.7.10 has no concept of eye height
|
||||
return e != null
|
||||
//#if MC<10800
|
||||
//$$ && e instanceof EntityPlayer // cannot be more generic since 1.7.10 has no concept of eye height
|
||||
//#endif
|
||||
&& !e.isInvisible();
|
||||
}
|
||||
|
||||
//#if MC<11400
|
||||
@@ -695,6 +695,16 @@ public class CameraEntity
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(KeyBindingEventCallback.EVENT, CameraEntity.this::handleInputEvents); }
|
||||
//#elseif MC<11400
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onKeyEvent(InputEvent.KeyInputEvent event) {
|
||||
//$$ handleInputEvents();
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onMouseInput(InputEvent.MouseInputEvent event) {
|
||||
//$$ handleInputEvents();
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
//#if FABRIC>=1
|
||||
|
||||
@@ -67,6 +67,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.replaymod.core.utils.Utils.error;
|
||||
@@ -287,7 +288,9 @@ public class GuiPathing {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
t.printStackTrace();
|
||||
if (!(t instanceof CancellationException)) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
overlay.setCloseable(true);
|
||||
}
|
||||
});
|
||||
|
||||
Binary file not shown.
5
src/main/resources/assets/replaymod/sounds.json
Normal file
5
src/main/resources/assets/replaymod/sounds.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"render_success": {
|
||||
"sounds": [{ "name": "replaymod:render_success" }]
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/replaymod/sounds/render_success.ogg
Normal file
BIN
src/main/resources/assets/replaymod/sounds/render_success.ogg
Normal file
Binary file not shown.
Reference in New Issue
Block a user