fixes for sp2, part 2

This commit is contained in:
lax1dude 2024-12-08 16:22:36 -08:00
parent 49e51c5883
commit 93772d96c7
10 changed files with 164 additions and 59 deletions

View File

@ -492,6 +492,18 @@ performance.max=Max FPS
performance.balanced=Balanced performance.balanced=Balanced
performance.powersaver=Power saver performance.powersaver=Power saver
options.vsyncWarning.title=Issues Detected
options.vsyncWarning.0=Some of your video settings may be causing
options.vsyncWarning.1=the game to lag excessively
options.vsyncWarning.2=VSync is disabled, some browsers require
options.vsyncWarning.3=VSync to be enabled to hint when the
options.vsyncWarning.4=framebuffer has updated. If the game feels
options.vsyncWarning.5=significantly slower than is indicated by
options.vsyncWarning.6=the FPS counter, you should enable VSync.
options.vsyncWarning.fixSettings=Fix Settings
options.vsyncWarning.continueAnyway=Continue Anyway
options.vsyncWarning.doNotShowAgain=Do Not Show Again
controls.title=Controls controls.title=Controls
key.forward=Forward key.forward=Forward

View File

@ -2,6 +2,7 @@ package net.lax1dude.eaglercraft.sp;
import java.io.IOException; import java.io.IOException;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket14StringList;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.src.EnumGameType; import net.minecraft.src.EnumGameType;
import net.minecraft.src.ILogAgent; import net.minecraft.src.ILogAgent;
@ -15,6 +16,9 @@ public class EAGMinecraftServer extends MinecraftServer {
protected WorkerListenThread listenThreadImpl; protected WorkerListenThread listenThreadImpl;
protected WorldSettings newWorldSettings; protected WorldSettings newWorldSettings;
protected boolean paused; protected boolean paused;
private int tpsCounter = 0;
private int tpsMeasure = 0;
private long tpsTimer = 0l;
public EAGMinecraftServer(String world, String owner, WorldSettings currentWorldSettings) { public EAGMinecraftServer(String world, String owner, WorldSettings currentWorldSettings) {
super(world); super(world);
@ -36,12 +40,21 @@ public class EAGMinecraftServer extends MinecraftServer {
} }
public void mainLoop() { public void mainLoop() {
long ctm = SysUtil.steadyTimeMillis();
long elapsed = ctm - tpsTimer;
if(elapsed >= 1000l) {
tpsTimer = ctm;
tpsMeasure = tpsCounter;
IntegratedServer.sendIPCPacket(new IPCPacket14StringList(IPCPacket14StringList.SERVER_TPS, getTPSAndChunkBuffer(tpsMeasure)));
tpsCounter = 0;
}
if(paused && this.playersOnline.size() <= 1) { if(paused && this.playersOnline.size() <= 1) {
lastTick = SysUtil.steadyTimeMillis(); lastTick = ctm;
return; return;
} }
long ctm = SysUtil.steadyTimeMillis();
long delta = ctm - lastTick; long delta = ctm - lastTick;
if (delta > 2000L && ctm - this.timeOfLastWarning >= 15000L) { if (delta > 2000L && ctm - this.timeOfLastWarning >= 15000L) {
@ -57,12 +70,14 @@ public class EAGMinecraftServer extends MinecraftServer {
if (this.worldServers[0].areAllPlayersAsleep()) { if (this.worldServers[0].areAllPlayersAsleep()) {
this.tick(); this.tick();
++tpsCounter;
lastTick = SysUtil.steadyTimeMillis(); lastTick = SysUtil.steadyTimeMillis();
} else { } else {
if (delta >= 50l) { if (delta > 50l) {
delta -= 50L; delta -= 50L;
lastTick += 50l; lastTick += 50l;
this.tick(); this.tick();
++tpsCounter;
} }
} }

View File

@ -52,7 +52,6 @@ public class SysUtil {
private static boolean hasCheckedImmediateContinue = false; private static boolean hasCheckedImmediateContinue = false;
private static MessageChannel immediateContinueChannel = null; private static MessageChannel immediateContinueChannel = null;
private static Runnable currentContinueHack = null; private static Runnable currentContinueHack = null;
private static final Object immediateContLock = new Object();
private static final JSString emptyJSString = JSString.valueOf(""); private static final JSString emptyJSString = JSString.valueOf("");
public static void immediateContinue() { public static void immediateContinue() {
@ -71,20 +70,18 @@ public class SysUtil {
private static native void immediateContinueTeaVM(); private static native void immediateContinueTeaVM();
private static void immediateContinueTeaVM(final AsyncCallback<Void> cb) { private static void immediateContinueTeaVM(final AsyncCallback<Void> cb) {
synchronized(immediateContLock) { if(currentContinueHack != null) {
if(currentContinueHack != null) { cb.error(new IllegalStateException("Worker thread is already waiting for an immediate continue callback!"));
cb.error(new IllegalStateException("Worker thread is already waiting for an immediate continue callback!")); return;
return; }
} currentContinueHack = () -> {
currentContinueHack = () -> { cb.complete(null);
cb.complete(null); };
}; try {
try { immediateContinueChannel.getPort2().postMessage(emptyJSString);
immediateContinueChannel.getPort2().postMessage(emptyJSString); }catch(Throwable t) {
}catch(Throwable t) { System.err.println("Caught error posting immediate continue, using setTimeout instead");
System.err.println("Caught error posting immediate continue, using setTimeout instead"); Window.setTimeout(() -> cb.complete(null), 0);
Window.setTimeout(() -> cb.complete(null), 0);
}
} }
} }
@ -99,11 +96,8 @@ public class SysUtil {
immediateContinueChannel.getPort1().addEventListener("message", new EventListener<MessageEvent>() { immediateContinueChannel.getPort1().addEventListener("message", new EventListener<MessageEvent>() {
@Override @Override
public void handleEvent(MessageEvent evt) { public void handleEvent(MessageEvent evt) {
Runnable toRun; Runnable toRun = currentContinueHack;
synchronized(immediateContLock) { currentContinueHack = null;
toRun = currentContinueHack;
currentContinueHack = null;
}
if(toRun != null) { if(toRun != null) {
toRun.run(); toRun.run();
} }

View File

@ -126,10 +126,6 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
protected boolean startProfiling; protected boolean startProfiling;
protected boolean field_104057_T = false; protected boolean field_104057_T = false;
private int tpsCounter = 0;
private int tpsMeasure = 0;
private long tpsTimer = 0l;
public MinecraftServer(String folder) { public MinecraftServer(String folder) {
mcServer = this; mcServer = this;
this.folderName = folder; this.folderName = folder;
@ -455,19 +451,9 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
this.lastReceivedSize = Packet.receivedSize; this.lastReceivedSize = Packet.receivedSize;
this.theProfiler.endSection(); this.theProfiler.endSection();
this.theProfiler.endSection(); this.theProfiler.endSection();
++tpsCounter;
long millis = SysUtil.steadyTimeMillis();
long elapsed = millis - tpsTimer;
if(elapsed >= 1000l) {
tpsTimer = millis;
tpsMeasure = (int)(tpsCounter * 1000l / elapsed);
IntegratedServer.sendIPCPacket(new IPCPacket14StringList(IPCPacket14StringList.SERVER_TPS, getTPSAndChunkBuffer()));
tpsCounter = 0;
}
} }
public List<String> getTPSAndChunkBuffer() { public List<String> getTPSAndChunkBuffer(int tpsCounter) {
ArrayList<String> strs = new ArrayList(); ArrayList<String> strs = new ArrayList();
strs.add("Ticks/Second: " + tpsCounter + "/20"); strs.add("Ticks/Second: " + tpsCounter + "/20");

View File

@ -0,0 +1,78 @@
package net.lax1dude.eaglercraft;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.src.EnumChatFormatting;
import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.StatCollector;
public class GuiScreenVSyncWarning extends GuiScreen {
private final GuiScreen cont;
private final List<String> messages = new ArrayList<>();
private int top = 0;
public GuiScreenVSyncWarning(GuiScreen cont) {
this.cont = cont;
}
public void initGui() {
messages.clear();
messages.add(EnumChatFormatting.RED + StatCollector.translateToLocal("options.vsyncWarning.title"));
messages.add(null);
messages.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("options.vsyncWarning.0"));
messages.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("options.vsyncWarning.1"));
messages.add(null);
messages.add(StatCollector.translateToLocal("options.vsyncWarning.2"));
messages.add(StatCollector.translateToLocal("options.vsyncWarning.3"));
messages.add(StatCollector.translateToLocal("options.vsyncWarning.4"));
messages.add(StatCollector.translateToLocal("options.vsyncWarning.5"));
messages.add(StatCollector.translateToLocal("options.vsyncWarning.6"));
int j = 0;
for(int i = 0, l = messages.size(); i < l; ++i) {
if(messages.get(i) != null) {
j += 9;
}else {
j += 5;
}
}
top = this.height / 6 + j / -12;
j += top;
buttonList.clear();
buttonList.add(new GuiButton(0, this.width / 2 - 100, j + 16, StatCollector.translateToLocal("options.vsyncWarning.fixSettings")));
buttonList.add(new GuiButton(1, this.width / 2 - 100, j + 40, StatCollector.translateToLocal("options.vsyncWarning.continueAnyway")));
buttonList.add(new GuiButton(2, this.width / 2 - 100, j + 64, StatCollector.translateToLocal("options.vsyncWarning.doNotShowAgain")));
}
public void drawScreen(int par1, int par2, float par3) {
this.drawDefaultBackground();
int j = 0;
for(int i = 0, l = messages.size(); i < l; ++i) {
String str = messages.get(i);
if(str != null) {
this.drawCenteredString(fontRenderer, str, this.width / 2, top + j, 16777215);
j += 9;
}else {
j += 5;
}
}
super.drawScreen(par1, par2, par3);
}
protected void actionPerformed(GuiButton par1GuiButton) {
if(par1GuiButton.id == 0) {
mc.gameSettings.enableVsync = true;
mc.gameSettings.saveOptions();
mc.displayGuiScreen(cont);
}else if(par1GuiButton.id == 1) {
mc.displayGuiScreen(cont);
}else if(par1GuiButton.id == 2) {
mc.gameSettings.hideVsyncWarning = true;
mc.gameSettings.saveOptions();
mc.displayGuiScreen(cont);
}
}
}

View File

@ -13,6 +13,7 @@ import net.lax1dude.eaglercraft.EaglerProfile;
import net.lax1dude.eaglercraft.GuiScreenEditProfile; import net.lax1dude.eaglercraft.GuiScreenEditProfile;
import net.lax1dude.eaglercraft.GuiScreenSingleplayerConnecting; import net.lax1dude.eaglercraft.GuiScreenSingleplayerConnecting;
import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading; import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading;
import net.lax1dude.eaglercraft.GuiScreenVSyncWarning;
import net.lax1dude.eaglercraft.GuiVoiceOverlay; import net.lax1dude.eaglercraft.GuiVoiceOverlay;
import net.lax1dude.eaglercraft.IntegratedServer; import net.lax1dude.eaglercraft.IntegratedServer;
import net.lax1dude.eaglercraft.IntegratedServerLAN; import net.lax1dude.eaglercraft.IntegratedServerLAN;
@ -353,6 +354,10 @@ public class Minecraft implements Runnable {
scr = new GuiScreenEditProfile(new GuiMainMenu()); scr = new GuiScreenEditProfile(new GuiMainMenu());
} }
if(!gameSettings.enableVsync && !gameSettings.hideVsyncWarning) {
scr = new GuiScreenVSyncWarning(scr);
}
displayGuiScreen(scr); displayGuiScreen(scr);
this.loadingScreen = new LoadingScreenRenderer(this); this.loadingScreen = new LoadingScreenRenderer(this);
@ -1102,8 +1107,12 @@ public class Minecraft implements Runnable {
} }
public void updateDisplay() { public void updateDisplay() {
int i = this.func_90020_K(); if(gameSettings.enableVsync) {
EaglerAdapter.updateDisplay(i > 0 ? EntityRenderer.performanceToFps(i) : 0, false); EaglerAdapter.updateDisplay(0, true);
}else {
int i = this.func_90020_K();
EaglerAdapter.updateDisplay(i > 0 ? EntityRenderer.performanceToFps(i) : 0, false);
}
} }
private boolean wasPaused = false; private boolean wasPaused = false;

View File

@ -8,7 +8,8 @@ public enum EnumOptions {
CHAT_VISIBILITY("options.chat.visibility", false, false), CHAT_COLOR("options.chat.color", false, true), CHAT_LINKS("options.chat.links", false, true), CHAT_OPACITY("options.chat.opacity", true, false), CHAT_VISIBILITY("options.chat.visibility", false, false), CHAT_COLOR("options.chat.color", false, true), CHAT_LINKS("options.chat.links", false, true), CHAT_OPACITY("options.chat.opacity", true, false),
CHAT_LINKS_PROMPT("options.chat.links.prompt", false, true), USE_SERVER_TEXTURES("options.serverTextures", false, true), SNOOPER_ENABLED("options.snooper", false, true), USE_FULLSCREEN("options.fullscreen", false, true), CHAT_LINKS_PROMPT("options.chat.links.prompt", false, true), USE_SERVER_TEXTURES("options.serverTextures", false, true), SNOOPER_ENABLED("options.snooper", false, true), USE_FULLSCREEN("options.fullscreen", false, true),
ENABLE_FOG("options.fog", false, true), SHOW_CAPE("options.showCape", false, true), ANTIALIASING("options.framebufferAntialias", false, false), CHAT_SCALE("options.chat.scale", true, false), CHAT_WIDTH("options.chat.width", true, false), ENABLE_FOG("options.fog", false, true), SHOW_CAPE("options.showCape", false, true), ANTIALIASING("options.framebufferAntialias", false, false), CHAT_SCALE("options.chat.scale", true, false), CHAT_WIDTH("options.chat.width", true, false),
CHAT_HEIGHT_FOCUSED("options.chat.height.focused", true, false), CHAT_HEIGHT_UNFOCUSED("options.chat.height.unfocused", true, false), CHUNK_UPDATES("options.chunkUpdates", false, false), ADDERALL("options.adderall", false, true); CHAT_HEIGHT_FOCUSED("options.chat.height.focused", true, false), CHAT_HEIGHT_UNFOCUSED("options.chat.height.unfocused", true, false), CHUNK_UPDATES("options.chunkUpdates", false, false), ADDERALL("options.adderall", false, true),
VSYNC("options.vsync", false, true);
private final boolean enumFloat; private final boolean enumFloat;
private final boolean enumBoolean; private final boolean enumBoolean;

View File

@ -22,6 +22,12 @@ class EnumOptionsHelper {
; ;
} }
try {
enumOptionsMappingHelperArray[EnumOptions.VSYNC.ordinal()] = 4;
} catch (NoSuchFieldError var10) {
;
}
try { try {
enumOptionsMappingHelperArray[EnumOptions.RENDER_CLOUDS.ordinal()] = 5; enumOptionsMappingHelperArray[EnumOptions.RENDER_CLOUDS.ordinal()] = 5;
} catch (NoSuchFieldError var10) { } catch (NoSuchFieldError var10) {

View File

@ -49,6 +49,7 @@ public class GameSettings {
public boolean snooperEnabled = false; public boolean snooperEnabled = false;
public boolean fullScreen = false; public boolean fullScreen = false;
public boolean enableVsync = true; public boolean enableVsync = true;
public boolean hideVsyncWarning = false;
public boolean hideServerAddress = false; public boolean hideServerAddress = false;
/** /**
@ -367,6 +368,10 @@ public class GameSettings {
this.mc.sndManager.stopAllSounds(); this.mc.sndManager.stopAllSounds();
} }
if (par1EnumOptions == EnumOptions.VSYNC) {
this.enableVsync = !this.enableVsync;
}
this.saveOptions(); this.saveOptions();
} }
@ -394,7 +399,7 @@ public class GameSettings {
return this.anaglyph; return this.anaglyph;
case 4: case 4:
return this.advancedOpengl; return this.enableVsync;
case 5: case 5:
return this.clouds; return this.clouds;
@ -546,6 +551,8 @@ public class GameSettings {
if(yee.hasKey("relayTimeout")) relayTimeout = yee.getByte("relayTimeout"); if(yee.hasKey("relayTimeout")) relayTimeout = yee.getByte("relayTimeout");
if(yee.hasKey("adderall")) adderall = yee.getBoolean("adderall"); if(yee.hasKey("adderall")) adderall = yee.getBoolean("adderall");
if(yee.hasKey("skin")) skin = yee.getString("skin"); if(yee.hasKey("skin")) skin = yee.getString("skin");
if(yee.hasKey("enableVsync")) enableVsync = yee.getBoolean("enableVsync");
if(yee.hasKey("hideVsyncWarning")) hideVsyncWarning = yee.getBoolean("hideVsyncWarning");
if(voiceListenRadius < 5) voiceListenRadius = 5; if(voiceListenRadius < 5) voiceListenRadius = 5;
else if(voiceListenRadius > 22) voiceListenRadius = 22; else if(voiceListenRadius > 22) voiceListenRadius = 22;
@ -628,6 +635,8 @@ public class GameSettings {
yee.setByte("relayTimeout", (byte)relayTimeout); yee.setByte("relayTimeout", (byte)relayTimeout);
yee.setBoolean("adderall", adderall); yee.setBoolean("adderall", adderall);
yee.setString("skin", skin); yee.setString("skin", skin);
yee.setBoolean("enableVsync", enableVsync);
yee.setBoolean("hideVsyncWarning", hideVsyncWarning);
for (int var4 = 0; var4 < this.keyBindings.length; ++var4) { for (int var4 = 0; var4 < this.keyBindings.length; ++var4) {
yee.setInteger(keyBindings[var4].keyDescription, keyBindings[var4].keyCode); yee.setInteger(keyBindings[var4].keyDescription, keyBindings[var4].keyCode);

View File

@ -1,5 +1,7 @@
package net.minecraft.src; package net.minecraft.src;
import net.lax1dude.eaglercraft.GuiScreenVSyncWarning;
public class GuiVideoSettings extends GuiScreen { public class GuiVideoSettings extends GuiScreen {
private GuiScreen parentGuiScreen; private GuiScreen parentGuiScreen;
@ -9,15 +11,11 @@ public class GuiVideoSettings extends GuiScreen {
/** GUI game settings */ /** GUI game settings */
private GameSettings guiGameSettings; private GameSettings guiGameSettings;
/**
* True if the system is 64-bit (using a simple indexOf test on a system
* property)
*/
private boolean is64bit = false;
/** An array of all of EnumOption's video options. */ /** An array of all of EnumOption's video options. */
private static EnumOptions[] videoOptions = new EnumOptions[] { EnumOptions.GRAPHICS, EnumOptions.RENDER_DISTANCE, EnumOptions.AMBIENT_OCCLUSION, EnumOptions.FRAMERATE_LIMIT, EnumOptions.ANAGLYPH, EnumOptions.VIEW_BOBBING, private static EnumOptions[] videoOptions = new EnumOptions[] { EnumOptions.GRAPHICS, EnumOptions.RENDER_DISTANCE,
EnumOptions.GUI_SCALE, EnumOptions.GAMMA, EnumOptions.RENDER_CLOUDS, EnumOptions.ENABLE_FOG, EnumOptions.PARTICLES, EnumOptions.CHUNK_UPDATES, EnumOptions.ADDERALL }; EnumOptions.AMBIENT_OCCLUSION, EnumOptions.FRAMERATE_LIMIT, EnumOptions.VSYNC, EnumOptions.ANAGLYPH,
EnumOptions.VIEW_BOBBING, EnumOptions.GUI_SCALE, EnumOptions.GAMMA, EnumOptions.RENDER_CLOUDS,
EnumOptions.ENABLE_FOG, EnumOptions.PARTICLES, EnumOptions.CHUNK_UPDATES, EnumOptions.ADDERALL };
public GuiVideoSettings(GuiScreen par1GuiScreen, GameSettings par2GameSettings) { public GuiVideoSettings(GuiScreen par1GuiScreen, GameSettings par2GameSettings) {
this.parentGuiScreen = par1GuiScreen; this.parentGuiScreen = par1GuiScreen;
@ -32,7 +30,6 @@ public class GuiVideoSettings extends GuiScreen {
this.screenTitle = var1.translateKey("options.videoTitle"); this.screenTitle = var1.translateKey("options.videoTitle");
this.buttonList.clear(); this.buttonList.clear();
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 178, var1.translateKey("gui.done"))); this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 178, var1.translateKey("gui.done")));
this.is64bit = true;
/* /*
String[] var2 = new String[] { "sun.arch.data.model", "com.ibm.vm.bitmode", "os.arch" }; String[] var2 = new String[] { "sun.arch.data.model", "com.ibm.vm.bitmode", "os.arch" };
String[] var3 = var2; String[] var3 = var2;
@ -83,7 +80,11 @@ public class GuiVideoSettings extends GuiScreen {
if (par1GuiButton.id == 200) { if (par1GuiButton.id == 200) {
this.mc.gameSettings.saveOptions(); this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(this.parentGuiScreen); if(!this.mc.gameSettings.enableVsync && !this.mc.gameSettings.hideVsyncWarning) {
this.mc.displayGuiScreen(new GuiScreenVSyncWarning(this.parentGuiScreen));
}else {
this.mc.displayGuiScreen(this.parentGuiScreen);
}
} }
if (this.guiGameSettings.guiScale != var2) { if (this.guiGameSettings.guiScale != var2) {
@ -101,13 +102,7 @@ public class GuiVideoSettings extends GuiScreen {
*/ */
public void drawScreen(int par1, int par2, float par3) { public void drawScreen(int par1, int par2, float par3) {
this.drawDefaultBackground(); this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, this.is64bit ? 20 : 5, 16777215); this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 20, 16777215);
if (!this.is64bit && this.guiGameSettings.renderDistance == 0) {
this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("options.farWarning1"), this.width / 2, this.height / 6 + 144 + 1, 11468800);
this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("options.farWarning2"), this.width / 2, this.height / 6 + 144 + 13, 11468800);
}
super.drawScreen(par1, par2, par3); super.drawScreen(par1, par2, par3);
} }
} }