From cd7ed5ed5012dc85bd7c70f6b6dfe6382c525393 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Wed, 3 Feb 2021 05:57:42 +0700 Subject: [PATCH] Try download assets on 30 threads Also, fix native build error --- .../java/net/kdt/pojavlaunch/PLaunchApp.java | 23 +++++++++++++++++-- Natives/ios_uikit_bridge.h | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java index ccad0a2d..ee986b4d 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java @@ -17,6 +17,8 @@ public class PLaunchApp { public static MinecraftAccount mAccount; public static JMinecraftVersionList.Version mVersion; public static boolean mIsAssetsProcessing = false; + public static Thread[] assetThreads = new Thread[30]; + public static int assetThrIndex = -1; public static void main(String[] args) throws Throwable { // User might remove the minecraft folder, this can cause crashes, safety re-create it @@ -173,7 +175,7 @@ public class PLaunchApp { }).start(); } - public static void downloadAssets(JAssets assets, String assetsVersion, File outputDir) throws IOException { + public static void downloadAssets(final JAssets assets, String assetsVersion, final File outputDir) throws IOException { File hasDownloadedFile = new File(outputDir, "downloaded/" + assetsVersion + ".downloaded"); if (!hasDownloadedFile.exists()) { System.out.println("Assets begin time: " + System.currentTimeMillis()); @@ -181,7 +183,8 @@ public class PLaunchApp { File objectsDir = new File(outputDir, "objects"); int downloadedSs = 0; for (JAssetInfo asset : assetsObjects.values()) { - currProgress++; + assetThread[assetThrIndex++] = new Thread(() -> { + mIsAssetsProcessing = !UIKit.updateProgressSafe(currProgress / maxProgress, "Downloading " + assetsObjects.keySet().toArray(new String[0])[downloadedSs]); if (!mIsAssetsProcessing) { @@ -190,7 +193,23 @@ public class PLaunchApp { if(!assets.map_to_resources) downloadAsset(asset, objectsDir); else downloadAssetMapped(asset,(assetsObjects.keySet().toArray(new String[0])[downloadedSs]),outputDir); + currProgress++; downloadedSs++; + + }); + + boolean isAllThreadsDone = false; + while (!isAllThreadsDone) { + isAllThreadsDone = true; + for (int i = 0; i < assetThreads.length; i++) { + Thread thr = assetThread[i]; + isAllThreadsDone &= thr == null || !thr.isAlive(); + + if (thr != null && !thr.isAlive()) { + assetThread[i] = null; + } + } + } } hasDownloadedFile.getParentFile().mkdirs(); hasDownloadedFile.createNewFile(); diff --git a/Natives/ios_uikit_bridge.h b/Natives/ios_uikit_bridge.h index 2245bc80..e9e04c48 100644 --- a/Natives/ios_uikit_bridge.h +++ b/Natives/ios_uikit_bridge.h @@ -1,6 +1,6 @@ #pragma once #include "jni.h" -void UIKit_updateProgress(float progress, char* message); +jboolean UIKit_updateProgress(float progress, char* message); void UIKit_launchMinecraftSurfaceVC(); void UIKit_setButtonSkippable();