Update #40 - FPS boost and fixed IndexOutOfBoundsException

This commit is contained in:
lax1dude
2024-10-19 16:52:27 -07:00
parent 85f4db5ac6
commit bcd575e87e
79 changed files with 1054 additions and 448 deletions

View File

@ -75,18 +75,43 @@ public class Display {
PlatformInput.update();
}
public static void update(int limitFramerate) {
PlatformInput.update(limitFramerate);
}
private static final long[] defaultSyncPtr = new long[1];
public static void sync(int limitFramerate) {
sync(limitFramerate, defaultSyncPtr);
}
public static boolean sync(int limitFramerate, long[] timerPtr) {
boolean limitFPS = limitFramerate > 0 && limitFramerate < 1000;
boolean blocked = false;
if(limitFPS) {
long millis = EagRuntime.steadyTimeMillis();
long frameMillis = (1000l / limitFramerate) - (millis - lastSwap);
if(frameMillis > 0l) {
EagUtils.sleep(frameMillis);
if(timerPtr[0] == 0l) {
timerPtr[0] = EagRuntime.steadyTimeMillis();
}else {
long millis = EagRuntime.steadyTimeMillis();
long frameMillis = (1000l / limitFramerate);
long frameTime = millis - timerPtr[0];
if(frameTime > 2000l || frameTime < 0l) {
frameTime = frameMillis;
timerPtr[0] = millis;
}else {
timerPtr[0] += frameMillis;
}
if(frameTime >= 0l && frameTime < frameMillis) {
EagUtils.sleep(frameMillis - frameTime);
blocked = true;
}
}
}else {
timerPtr[0] = 0l;
}
lastSwap = EagRuntime.steadyTimeMillis();
return blocked;
}
public static boolean contextLost() {

View File

@ -5,6 +5,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
/**
* Copyright (c) 2022-2023 lax1dude, ayunami2000. All Rights Reserved.
*
@ -57,11 +59,14 @@ public class EagUtils {
return str.length() < off + 2 ? decodeHex(str.subSequence(off, 2)) : 0;
}
public static void sleep(int millis) {
PlatformRuntime.sleep(millis);
}
public static void sleep(long millis) {
try {
Thread.sleep(millis);
}catch(InterruptedException ex) {
}
int reduced = (int)millis;
if(reduced != millis) throw new IllegalArgumentException();
PlatformRuntime.sleep(reduced);
}
public static String toASCIIEagler(String str) {

View File

@ -5,6 +5,7 @@ import java.util.LinkedList;
import java.util.List;
import net.lax1dude.eaglercraft.v1_8.internal.EnumPlatformType;
import net.lax1dude.eaglercraft.v1_8.internal.IAudioCacheLoader;
import net.lax1dude.eaglercraft.v1_8.internal.IAudioHandle;
import net.lax1dude.eaglercraft.v1_8.internal.IAudioResource;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformAudio;
@ -286,7 +287,7 @@ public class EaglercraftSoundManager {
}
}
private final PlatformAudio.IAudioCacheLoader browserResourcePackLoader = filename -> {
private final IAudioCacheLoader browserResourcePackLoader = filename -> {
try {
return EaglerInputStream.inputStreamToBytesQuiet(Minecraft.getMinecraft().getResourceManager()
.getResource(new ResourceLocation(filename)).getInputStream());

View File

@ -10,7 +10,7 @@ public class EaglercraftVersion {
/// Customize these to fit your fork:
public static final String projectForkName = "EaglercraftX";
public static final String projectForkVersion = "u39";
public static final String projectForkVersion = "u40";
public static final String projectForkVendor = "lax1dude";
public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";
@ -20,20 +20,20 @@ public class EaglercraftVersion {
public static final String projectOriginName = "EaglercraftX";
public static final String projectOriginAuthor = "lax1dude";
public static final String projectOriginRevision = "1.8";
public static final String projectOriginVersion = "u39";
public static final String projectOriginVersion = "u40";
public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace
// EPK Version Identifier
public static final String EPKVersionIdentifier = "u39"; // Set to null to disable EPK version check
public static final String EPKVersionIdentifier = "u40"; // Set to null to disable EPK version check
// Updating configuration
public static final boolean enableUpdateService = true;
public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client";
public static final int updateBundlePackageVersionInt = 39;
public static final int updateBundlePackageVersionInt = 40;
public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName;

View File

@ -65,4 +65,8 @@ public class Keyboard {
PlatformInput.keyboardFireEvent(eventType, eagKey, keyChar);
}
public static boolean areKeysLocked() {
return PlatformInput.keyboardAreKeysLocked();
}
}

View File

@ -0,0 +1,22 @@
package net.lax1dude.eaglercraft.v1_8.internal;
/**
* Copyright (c) 2024 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public interface IAudioCacheLoader {
byte[] loadFile(String filename);
}

View File

@ -50,6 +50,8 @@ public interface IClientConfigAdapter {
List<RelayEntry> getRelays();
boolean isCheckGLErrors();
boolean isCheckShaderGLErrors();
boolean isDemo();

View File

@ -3,6 +3,7 @@ package net.lax1dude.eaglercraft.v1_8.internal;
import org.json.JSONObject;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.EagUtils;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
@ -79,10 +80,7 @@ public interface IServerQuery {
default boolean awaitResponseAvailable(long timeout) {
long start = EagRuntime.steadyTimeMillis();
while(isOpen() && responsesAvailable() <= 0 && (timeout <= 0l || EagRuntime.steadyTimeMillis() - start < timeout)) {
try {
Thread.sleep(0l, 250000);
} catch (InterruptedException e) {
}
EagUtils.sleep(5);
}
return responsesAvailable() > 0;
}
@ -94,10 +92,7 @@ public interface IServerQuery {
default boolean awaitResponseBinaryAvailable(long timeout) {
long start = EagRuntime.steadyTimeMillis();
while(isOpen() && binaryResponsesAvailable() <= 0 && (timeout <= 0l || EagRuntime.steadyTimeMillis() - start < timeout)) {
try {
Thread.sleep(0l, 250000);
} catch (InterruptedException e) {
}
EagUtils.sleep(5);
}
return binaryResponsesAvailable() > 0;
}

View File

@ -4065,6 +4065,6 @@ public class EaglerDeferredPipeline {
GlStateManager.popMatrix();
GlStateManager.matrixMode(GL_MODELVIEW);
GlStateManager.popMatrix();
EagUtils.sleep(10l);
EagUtils.sleep(10);
}
}

View File

@ -55,7 +55,7 @@ public class GuiScreenImportExportProfile extends GuiScreen {
waitingForFile = false;
FileChooserResult result = EagRuntime.getFileChooserResult();
if(result != null) {
mc.loadingScreen.eaglerShow(I18n.format("settingsBackup.importing.1"), "settingsBackup.importing.2");
mc.loadingScreen.eaglerShow(I18n.format("settingsBackup.importing.1"), I18n.format("settingsBackup.importing.2"));
ProfileImporter importer = new ProfileImporter(result.fileData);
try {
importer.readHeader();

View File

@ -12,6 +12,7 @@ import java.util.Map.Entry;
import net.lax1dude.eaglercraft.v1_8.ArrayUtils;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.EagUtils;
import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
import net.lax1dude.eaglercraft.v1_8.EaglerOutputStream;
import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
@ -441,10 +442,7 @@ public class ConnectionHandshake {
if(client.getState().isClosed()) {
return null;
}
try {
Thread.sleep(50l);
} catch (InterruptedException e) {
}
EagUtils.sleep(50);
if(EagRuntime.steadyTimeMillis() - millis > timeout) {
client.close();
return null;

View File

@ -144,9 +144,11 @@ public class GameProtocolMessageController {
pkt = sendQueueV4.remove(0);
sendFunction.sendPluginMessage(GamePluginMessageConstants.V4_CHANNEL, pkt);
}else {
int i, j, sendCount = 0, totalLen = 0;
int i, j, sendCount, totalLen;
PacketBuffer sendBuffer;
while(sendQueueV4.size() > 0) {
sendCount = 0;
totalLen = 0;
do {
i = sendQueueV4.get(sendCount++).readableBytes();
totalLen += GamePacketOutputBuffer.getVarIntSize(i) + i;

View File

@ -126,7 +126,7 @@ public class LANClientNetworkManager extends EaglercraftNetworkManager {
connectState = SENT_DESCRIPTION;
continue mainLoop;
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - lm < 5000l);
// no description was sent
@ -163,7 +163,7 @@ public class LANClientNetworkManager extends EaglercraftNetworkManager {
return new LANClientNetworkManager(displayCode, displayRelay);
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - lm < 5000l);
// no channel was opened
@ -202,7 +202,7 @@ public class LANClientNetworkManager extends EaglercraftNetworkManager {
connectState = SENT_ICE_CANDIDATE;
continue mainLoop;
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - lm < 5000l);
// no ice candidates were sent
@ -237,7 +237,7 @@ public class LANClientNetworkManager extends EaglercraftNetworkManager {
return null;
}
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}
return null;
}

View File

@ -64,7 +64,7 @@ class LANClientPeer {
disconnect();
return;
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server ICE candidates for '{}' timed out!", clientId);
disconnect();
@ -92,7 +92,7 @@ class LANClientPeer {
disconnect();
return;
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server description for '{}' timed out!", clientId);
disconnect();
@ -122,7 +122,7 @@ class LANClientPeer {
disconnect();
return;
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server description for '{}' timed out!", clientId);
disconnect();

View File

@ -81,7 +81,7 @@ public class LANServerController {
return null;
}
}
EagUtils.sleep(50l);
EagUtils.sleep(50);
}while(EagRuntime.steadyTimeMillis() - millis < 1000l);
logger.info("Relay [{}] relay provide ICE servers timeout", sock.getURI());
closeLAN();

View File

@ -298,10 +298,10 @@ public class RelayManager {
return null;
}
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}
}
EagUtils.sleep(20l);
EagUtils.sleep(20);
}
logger.error("Relay [{}] connection failed!", relay.address);
Throwable t;

View File

@ -81,7 +81,7 @@ public class RelayServer {
public void pingBlocking() {
ping();
while(getPing() < 0l) {
EagUtils.sleep(250l);
EagUtils.sleep(250);
update();
}
}

View File

@ -468,7 +468,7 @@ public class EaglerIntegratedServerWorker {
}
}else {
if(!singleThreadMode) {
EagUtils.sleep(50l);
EagUtils.sleep(50);
}
}
}

View File

@ -23,7 +23,7 @@ import net.minecraft.util.ResourceLocation;
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public class GuiScreenPhishingWaring extends GuiScreen {
public class GuiScreenPhishingWarning extends GuiScreen {
public static boolean hasShownMessage = false;
@ -33,7 +33,7 @@ public class GuiScreenPhishingWaring extends GuiScreen {
private boolean mouseOverCheck;
private boolean hasCheckedBox;
public GuiScreenPhishingWaring(GuiScreen cont) {
public GuiScreenPhishingWarning(GuiScreen cont) {
this.cont = cont;
}