Update #24 - 1000s of optimizations, shared worlds on desktop

This commit is contained in:
lax1dude
2024-03-02 20:51:44 -08:00
parent a50c93cb75
commit 8ab65942c5
624 changed files with 8091 additions and 3620 deletions

View File

@ -21,6 +21,7 @@ import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.lwjgl.MainMenuCreditsDialog;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
@ -204,8 +205,15 @@ public class PlatformApplication {
fileChooserResultObject = null;
}
private static MainMenuCreditsDialog creditsDialog = null;
public static void openCreditsPopup(String text) {
if(creditsDialog == null) {
creditsDialog = new MainMenuCreditsDialog();
}
creditsDialog.setCreditsText(text);
creditsDialog.setLocationRelativeTo(null);
creditsDialog.setVisible(true);
}
private static final File downloadsDirectory = new File("downloads");
@ -239,6 +247,11 @@ public class PlatformApplication {
}
downloadsLogger.info("Saved {} byte file to: {}", fileContents.length, f.getAbsolutePath());
try {
Desktop.getDesktop().open(downloadsDirectory);
}catch(Throwable t) {
}
}
public static void addLogMessage(String logMessage, boolean isError) {

View File

@ -2,7 +2,6 @@ package net.lax1dude.eaglercraft.v1_8.internal;
import java.net.URL;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformAudio.IAudioCacheLoader;
import net.lax1dude.eaglercraft.v1_8.internal.paulscode.lwjgl3.LibraryLWJGLOpenAL;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;

View File

@ -6,12 +6,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.lwjgl.LWJGLEntryPoint;
import net.lax1dude.eaglercraft.v1_8.internal.vfs2.EaglerFileSystemException;
import net.lax1dude.eaglercraft.v1_8.internal.vfs2.VFSIterator2.BreakLoop;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.sp.server.internal.lwjgl.DesktopIntegratedServer;
/**
* Copyright (c) 2022-2024 lax1dude. All Rights Reserved.
@ -35,20 +33,12 @@ public class PlatformFilesystem {
public static final File filesystemRoot = (new File("filesystem/sp")).getAbsoluteFile();
public static void initialize() {
assertThread();
if(!filesystemRoot.isDirectory() && !filesystemRoot.mkdirs()) {
throw new EaglerFileSystemException("Could not create directory for virtual filesystem: " + filesystemRoot.getAbsolutePath());
}
}
private static void assertThread() {
if(Thread.currentThread() != DesktopIntegratedServer.serverThread) {
throw new UnsupportedOperationException("[DEBUG CHECK] VFS2 is currently only initialized for server contexts!");
}
}
public static boolean eaglerDelete(String pathName) {
assertThread();
File f = getJREFile(pathName);
if(!f.exists()) {
logger.warn("Tried to delete file that doesn't exist: \"{}\"", pathName);
@ -62,7 +52,6 @@ public class PlatformFilesystem {
}
public static ByteBuffer eaglerRead(String pathName) {
assertThread();
File f = getJREFile(pathName);
if(f.isFile()) {
long fileSize = f.length();
@ -96,7 +85,6 @@ public class PlatformFilesystem {
}
public static void eaglerWrite(String pathName, ByteBuffer data) {
assertThread();
File f = getJREFile(pathName);
File p = f.getParentFile();
if(!p.isDirectory()) {
@ -105,7 +93,7 @@ public class PlatformFilesystem {
}
}
try(FileOutputStream fos = new FileOutputStream(f)) {
byte[] copyBuffer = new byte[4096];
byte[] copyBuffer = new byte[Math.min(4096, data.remaining())];
int i;
while((i = data.remaining()) > 0) {
if(i > copyBuffer.length) {
@ -120,12 +108,10 @@ public class PlatformFilesystem {
}
public static boolean eaglerExists(String pathName) {
assertThread();
return getJREFile(pathName).isFile();
}
public static boolean eaglerMove(String pathNameOld, String pathNameNew) {
assertThread();
File f1 = getJREFile(pathNameOld);
File f2 = getJREFile(pathNameNew);
if(f2.exists()) {
@ -142,7 +128,6 @@ public class PlatformFilesystem {
}
public static int eaglerCopy(String pathNameOld, String pathNameNew) {
assertThread();
File f1 = getJREFile(pathNameOld);
File f2 = getJREFile(pathNameNew);
if(!f1.isFile()) {
@ -174,7 +159,6 @@ public class PlatformFilesystem {
}
public static int eaglerSize(String pathName) {
assertThread();
File f = getJREFile(pathName);
if(f.isFile()) {
long fileSize = f.length();
@ -186,7 +170,6 @@ public class PlatformFilesystem {
}
public static void eaglerIterate(String pathName, VFSFilenameIterator itr, boolean recursive) {
assertThread();
try {
iterateFile(pathName, getJREFile(pathName), itr, recursive);
}catch(BreakLoop ex) {

View File

@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.system.MemoryStack;
/**
@ -129,6 +130,9 @@ public class PlatformInput {
});
glfwSetKeyCallback(glfwWindow, (window, key, scancode, action, mods) -> {
if (key == GLFW_KEY_F11 && action == GLFW_PRESS) {
toggleFullscreen();
}
if(glfwGetKey(glfwWindow, functionKeyModifier) == GLFW_PRESS) {
if(key >= GLFW_KEY_1 && key <= GLFW_KEY_9) {
key = key - GLFW_KEY_1 + GLFW_KEY_F1;
@ -381,12 +385,64 @@ public class PlatformInput {
functionKeyModifier = KeyboardConstants.getGLFWKeyFromEagler(key);
}
private static boolean fullscreen = false;
private static int[] lastPos = new int[4];
public static void toggleFullscreen() {
//
long win = PlatformRuntime.getWindowHandle();
long mon = getCurrentMonitor(win);
GLFWVidMode mode = glfwGetVideoMode(mon);
if (fullscreen) {
glfwSetWindowMonitor(win, 0, lastPos[0], lastPos[1], lastPos[2], lastPos[3], mode.refreshRate());
} else {
int[] x = new int[1], y = new int[1];
glfwGetWindowPos(win, x, y);
lastPos[0] = x[0];
lastPos[1] = y[0];
glfwGetWindowSize(win, x, y);
lastPos[2] = x[0];
lastPos[3] = y[0];
glfwSetWindowMonitor(win, mon, 0, 0, mode.width(), mode.height(), mode.refreshRate());
}
fullscreen = !fullscreen;
}
// https://stackoverflow.com/a/31526753
private static long getCurrentMonitor(long window) {
int nmonitors, i;
int[] wx = new int[1], wy = new int[1], ww = new int[1], wh = new int[1];
int[] mx = new int[1], my = new int[1], mw = new int[1], mh = new int[1];
int overlap, bestoverlap = 0;
long bestmonitor = 0;
PointerBuffer monitors;
GLFWVidMode mode;
glfwGetWindowPos(window, wx, wy);
glfwGetWindowSize(window, ww, wh);
monitors = glfwGetMonitors();
nmonitors = monitors.remaining();
for (i = 0; i < nmonitors; ++i) {
mode = glfwGetVideoMode(monitors.get(i));
glfwGetMonitorPos(monitors.get(i), mx, my);
mw[0] = mode.width();
mh[0] = mode.height();
overlap =
Math.max(0, Math.min(wx[0] + ww[0], mx[0] + mw[0]) - Math.max(wx[0], mx[0])) *
Math.max(0, Math.min(wy[0] + wh[0], my[0] + mh[0]) - Math.max(wy[0], my[0]));
if (bestoverlap < overlap) {
bestoverlap = overlap;
bestmonitor = monitors.get(i);
}
}
return bestmonitor;
}
public static boolean isFullscreen() {
return false;
return fullscreen;
}
public static void showCursor(EnumCursorType cursor) {

View File

@ -10,6 +10,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -36,12 +37,14 @@ import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.jemalloc.JEmalloc;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.EaglerLWJGLAllocator;
import net.lax1dude.eaglercraft.v1_8.EaglerOutputStream;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.IntBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.lwjgl.DesktopClientConfigAdapter;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerFolderResourcePack;
/**
* Copyright (c) 2022-2023 lax1dude, ayunami2000. All Rights Reserved.
@ -71,6 +74,8 @@ public class PlatformRuntime {
public static void create() {
logger.info("Starting Desktop Runtime...");
PlatformFilesystem.initialize();
EaglerFolderResourcePack.setSupported(true);
if(requestedANGLEPlatform != EnumPlatformANGLE.DEFAULT) {
logger.info("Setting ANGLE Platform: {}", requestedANGLEPlatform.name);
@ -295,7 +300,31 @@ public class PlatformRuntime {
public static FloatBuffer allocateFloatBuffer(int length) {
return EaglerLWJGLAllocator.allocFloatBuffer(length);
}
public static ByteBuffer castPrimitiveByteArray(byte[] array) {
return null;
}
public static IntBuffer castPrimitiveIntArray(int[] array) {
return null;
}
public static FloatBuffer castPrimitiveFloatArray(float[] array) {
return null;
}
public static byte[] castNativeByteBuffer(ByteBuffer buffer) {
return null;
}
public static int[] castNativeIntBuffer(IntBuffer buffer) {
return null;
}
public static float[] castNativeFloatBuffer(FloatBuffer buffer) {
return null;
}
public static void freeByteBuffer(ByteBuffer byteBuffer) {
EaglerLWJGLAllocator.freeByteBuffer(byteBuffer);
}
@ -429,6 +458,22 @@ public class PlatformRuntime {
return new GZIPInputStream(is);
}
public static void downloadRemoteURIByteArray(String assetPackageURI, final Consumer<byte[]> cb) {
logger.info("Downloading: {}");
try(InputStream is = (new URL(assetPackageURI)).openStream()) {
EaglerOutputStream bao = new EaglerOutputStream();
byte[] copyBuffer = new byte[16384];
int i;
while((i = is.read(copyBuffer, 0, copyBuffer.length)) != -1) {
bao.write(copyBuffer, 0, i);
}
cb.accept(bao.toByteArray());
}catch(IOException ex) {
logger.error("Failed to download file!");
logger.error(ex);
}
}
public static boolean requireSSL() {
return false;
}
@ -468,4 +513,8 @@ public class PlatformRuntime {
public static String currentThreadName() {
return Thread.currentThread().getName();
}
public static long getWindowHandle() {
return windowHandle;
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.json.JSONObject;
import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom;
import net.lax1dude.eaglercraft.v1_8.EaglercraftVersion;
import net.lax1dude.eaglercraft.v1_8.internal.IClientConfigAdapter;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayEntry;
@ -50,18 +51,31 @@ public class DesktopClientConfigAdapter implements IClientConfigAdapter {
return "desktop";
}
@Override
public String getResourcePacksDB() {
return "desktop";
}
@Override
public JSONObject dumpConfig() {
return new JSONObject("{\"container\":null,\"worldsDB\":\"desktop\"}");
}
private final List<RelayEntry> relays = new ArrayList<>();
@Override
public List<RelayEntry> getRelays() {
throw new UnsupportedOperationException("TODO");
if (relays.isEmpty()) {
int relayId = (new EaglercraftRandom()).nextInt(3);
relays.add(new RelayEntry("wss://relay.deev.is/", "lax1dude relay #1", relayId == 0));
relays.add(new RelayEntry("wss://relay.lax1dude.net/", "lax1dude relay #2", relayId == 1));
relays.add(new RelayEntry("wss://relay.shhnowisnottheti.me/", "ayunami relay #1", relayId == 2));
}
return relays;
}
@Override
public boolean checkShaderGLErrors() {
public boolean isCheckShaderGLErrors() {
return true;
}

View File

@ -8,6 +8,7 @@ import net.lax1dude.eaglercraft.v1_8.EagUtils;
import net.lax1dude.eaglercraft.v1_8.internal.EnumPlatformANGLE;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.ShaderSource;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager;
import net.minecraft.client.main.Main;
/**
@ -57,6 +58,13 @@ public class LWJGLEntryPoint {
}
}
RelayManager.relayManager.load(EagRuntime.getStorage("r"));
if (RelayManager.relayManager.count() <= 0) {
RelayManager.relayManager.loadDefaults();
RelayManager.relayManager.save();
}
EagRuntime.create();
Main.appMain(new String[0]);

View File

@ -0,0 +1,76 @@
package net.lax1dude.eaglercraft.v1_8.internal.lwjgl;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import javax.swing.ScrollPaneConstants;
/**
* 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 class MainMenuCreditsDialog extends JFrame {
private static final long serialVersionUID = 696969696L;
private JPanel contentPane;
private JTextArea textArea;
/**
* Create the frame.
*/
public MainMenuCreditsDialog() {
setIconImage(Toolkit.getDefaultToolkit().getImage("icon32.png"));
setTitle("EaglercraftX 1.8 Credits");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds(100, 100, 850, 700);
setLocationByPlatform(true);
setAlwaysOnTop(true);
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
contentPane.add(scrollPane, BorderLayout.CENTER);
textArea = new JTextArea();
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
Font daFont = null;
for(int i = 0; i < fonts.length; ++i) {
if(fonts[i].equalsIgnoreCase("consolas")) {
daFont = new Font(fonts[i], Font.PLAIN, 15);
break;
}
}
if(daFont == null) {
daFont = new Font(Font.MONOSPACED, Font.PLAIN, 15);
}
textArea.setFont(daFont);
scrollPane.setViewportView(textArea);
}
public void setCreditsText(String str) {
textArea.setText(str);
}
}

View File

@ -1,42 +0,0 @@
package net.lax1dude.eaglercraft.v1_8.internal.vfs;
import com.google.common.collect.Sets;
import net.minecraft.client.resources.AbstractResourcePack;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Set;
/**
* Copyright (c) 2022-2023 lax1dude, ayunami2000. 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 class FolderResourcePack extends AbstractResourcePack {
public FolderResourcePack(String resourcePackFileIn, String prefix) {
super(resourcePackFileIn);
}
protected InputStream getInputStreamByName(String name) {
return new BufferedInputStream(new ByteArrayInputStream(new byte[0]));
}
protected boolean hasResourceName(String name) {
return false;
}
public Set<String> getResourceDomains() {
return Sets.<String>newHashSet();
}
}

View File

@ -1,42 +0,0 @@
package net.lax1dude.eaglercraft.v1_8.internal.vfs;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/**
* Copyright (c) 2022-2023 lax1dude, ayunami2000. 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 class SYS {
public static final Object VFS = null;
public static final void loadRemoteResourcePack(String url, String hash, Consumer<String> cb, Consumer<Runnable> ast, Runnable loading) {
return;
}
public static final boolean loadResourcePack(String name, InputStream data, String hash) {
return false;
}
public static final List<String> getResourcePackNames() {
return new ArrayList<>();
}
public static final void deleteResourcePack(String packName) {
//
}
}

View File

@ -3,7 +3,6 @@ package net.lax1dude.eaglercraft.v1_8.sp.internal;
import java.util.ArrayList;
import java.util.List;
import net.lax1dude.eaglercraft.v1_8.internal.IClientConfigAdapter;
import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.sp.server.internal.lwjgl.CrashScreenPopup;

View File

@ -9,7 +9,6 @@ import javax.swing.ScrollPaneConstants;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.Color;
import java.awt.Window.Type;
/**
* Copyright (c) 2022-2024 lax1dude. All Rights Reserved.