Compare commits

..
Author SHA1 Message Date
Mathias-Boulay a7bc7dab21 cleanup(tools): remove unused code 2024-12-25 19:45:33 +01:00
Mathias-Boulay d12d214c12 cleanup(tools): remove unused code related to fullscreen 2024-12-25 19:40:20 +01:00
Mathias-Boulay 9840632527 refactor(seekbars):migrate range values into xml files 2024-12-25 18:56:57 +01:00
Mathias-Boulay 736ee68a50 Fix(quick-setting): improper placement
This was due to an issue that only happens within older android versions.
2024-12-23 22:05:55 +01:00
Mathias-Boulay d8098c95e9 refactor(customseekbar): implement seekBarIncrement attribute 2024-12-23 09:36:59 +01:00
Mathias-Boulay 0bc6e783c2 Fix,refactor(profiles): prefer nameless profiles
Also refactored the use of a constant across the code
2024-12-23 00:57:16 +01:00
Mathias-Boulay 3feb6927c9 Tweak(jvm arg): take control of -XX:ActiveProcessorCount
Setting it ourselves guarantee a better experience by default
2024-12-20 22:35:13 +01:00
Mathias-Boulay b57a0cdab7 Tweak(pref-detection): Verify all cores aren't the same frequency 2024-12-19 21:40:01 +01:00
Mathias-Boulay f205209613 Qol(settings): use energy saving settings for powerful devices
Less boiling pocket heaters.
May contain a small few refactor
2024-12-16 20:12:56 +01:00
9 changed files with 43 additions and 195 deletions

No files matched your search

+1 -1
View File
@@ -112,7 +112,7 @@ Then, run these commands ~~or build using Android Studio~~.
- Probably more, that's why we have a bug tracker ;)
## License
- PojavLauncher is licensed under [GNU LGPLv3](https://github.com/PojavLauncherTeam/PojavLauncher/blob/v3_openjdk/LICENSE).
- PojavLauncher is licensed under [GNU GPLv3](https://github.com/khanhduytran0/PojavLauncher/blob/master/LICENSE).
## Contributing
Contributions are welcome! We welcome any type of contribution, not only code. For example, you can help the wiki shape up. You can help the [translation](https://crowdin.com/project/pojavlauncher) too!
@@ -43,7 +43,7 @@ public class DownloadMirror {
return;
}catch (FileNotFoundException e) {
Log.w("DownloadMirror", "Cannot find the file on the mirror", e);
Log.i("DownloadMirror", "Falling back to default source");
Log.i("DownloadMirror", "Failling back to default source");
}
DownloadUtils.downloadFileMonitored(urlInput, outputFile, buffer, monitor);
}
@@ -63,30 +63,11 @@ public class DownloadMirror {
return;
}catch (FileNotFoundException e) {
Log.w("DownloadMirror", "Cannot find the file on the mirror", e);
Log.i("DownloadMirror", "Falling back to default source");
Log.i("DownloadMirror", "Failling back to default source");
}
DownloadUtils.downloadFile(urlInput, outputFile);
}
/**
* Get the content length of a file on the current mirror. If the file is missing on the mirror,
* or the mirror does not give out the length, request the length from the original source
* @param downloadClass Class of the download. Can either be DOWNLOAD_CLASS_LIBRARIES,
* DOWNLOAD_CLASS_METADATA or DOWNLOAD_CLASS_ASSETS
* @param urlInput The original (Mojang) URL for the download
* @return the length of the file denoted by the URL in bytes, or -1 if not available
*/
public static long getContentLengthMirrored(int downloadClass, String urlInput) throws IOException {
long length = DownloadUtils.getContentLength(getMirrorMapping(downloadClass, urlInput));
if(length < 1) {
Log.w("DownloadMirror", "Unable to get content length from mirror");
Log.i("DownloadMirror", "Falling back to default source");
return DownloadUtils.getContentLength(urlInput);
}else {
return length;
}
}
/**
* Check if the current download source is a mirror and not an official source.
* @return true if the source is a mirror, false otherwise
@@ -37,18 +37,14 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
public class MinecraftDownloader {
private static final double ONE_MEGABYTE = (1024d * 1024d);
public static final String MINECRAFT_RES = "https://resources.download.minecraft.net/";
private AtomicReference<Exception> mDownloaderThreadException;
private ArrayList<DownloaderTask> mScheduledDownloadTasks;
private AtomicLong mProcessedFileCounter;
private AtomicLong mProcessedSizeCounter; // Total bytes of processed files (passed SHA1 or downloaded)
private AtomicLong mInternetUsageCounter; // How many bytes downloaded over Internet
private long mTotalFileCount;
private long mTotalSize;
private AtomicLong mDownloadFileCounter;
private AtomicLong mDownloadSizeCounter;
private long mDownloadFileCount;
private File mSourceJarFile; // The source client JAR picked during the inheritance process
private File mTargetJarFile; // The destination client JAR to which the source will be copied to.
private boolean mUseFileCounter; // Whether a file counter or a size counter should be used for progress
private static final ThreadLocal<byte[]> sThreadLocalDownloadBuffer = new ThreadLocal<>();
@@ -84,15 +80,12 @@ public class MinecraftDownloader {
// Put up a dummy progress line, for the activity to start the service and do all the other necessary
// work to keep the launcher alive. We will replace this line when we will start downloading stuff.
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, 0, R.string.newdl_starting);
SpeedCalculator speedCalculator = new SpeedCalculator();
mTargetJarFile = createGameJarPath(versionName);
mScheduledDownloadTasks = new ArrayList<>();
mProcessedFileCounter = new AtomicLong(0);
mProcessedSizeCounter = new AtomicLong(0);
mInternetUsageCounter = new AtomicLong(0);
mDownloadFileCounter = new AtomicLong(0);
mDownloadSizeCounter = new AtomicLong(0);
mDownloaderThreadException = new AtomicReference<>(null);
mUseFileCounter = false;
if(!downloadAndProcessMetadata(activity, verInfo, versionName)) {
throw new RuntimeException(activity.getString(R.string.exception_failed_to_unpack_jre17));
@@ -111,9 +104,11 @@ public class MinecraftDownloader {
try {
while (mDownloaderThreadException.get() == null &&
!downloaderPool.awaitTermination(33, TimeUnit.MILLISECONDS)) {
double speed = speedCalculator.feed(mInternetUsageCounter.get()) / ONE_MEGABYTE;
if(mUseFileCounter) reportProgressFileCounter(speed);
else reportProgressSizeCounter(speed);
long dlFileCounter = mDownloadFileCounter.get();
int progress = (int)((dlFileCounter * 100L) / mDownloadFileCount);
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, progress,
R.string.newdl_downloading_game_files, dlFileCounter,
mDownloadFileCount, (double)mDownloadSizeCounter.get() / (1024d * 1024d));
}
Exception thrownException = mDownloaderThreadException.get();
if(thrownException != null) {
@@ -128,23 +123,6 @@ public class MinecraftDownloader {
}
}
private void reportProgressFileCounter(double speed) {
long dlFileCounter = mProcessedFileCounter.get();
int progress = (int)((dlFileCounter * 100L) / mTotalFileCount);
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, progress,
R.string.newdl_downloading_game_files, dlFileCounter,
mTotalFileCount, speed);
}
private void reportProgressSizeCounter(double speed) {
long dlFileSize = mProcessedSizeCounter.get();
double dlSizeMegabytes = (double) dlFileSize / ONE_MEGABYTE;
double dlTotalMegabytes = (double) mTotalSize / ONE_MEGABYTE;
int progress = (int)((dlFileSize * 100L) / mTotalSize);
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, progress,
R.string.newdl_downloading_game_files_size, dlSizeMegabytes, dlTotalMegabytes, speed);
}
private File createGameJsonPath(String versionId) {
return new File(Tools.DIR_HOME_VERSION, versionId + File.separator + versionId + ".json");
}
@@ -255,19 +233,7 @@ public class MinecraftDownloader {
private void scheduleDownload(File targetFile, int downloadClass, String url, String sha1,
long size, boolean skipIfFailed) throws IOException {
FileUtils.ensureParentDirectory(targetFile);
mTotalFileCount++;
if(size < 0) {
size = DownloadMirror.getContentLengthMirrored(downloadClass, url);
}
if(size < 0) {
// If we were unable to get the content length ourselves, we automatically fall back
// to tracking the progress using the file counter.
size = 0;
mUseFileCounter = true;
Log.i("MinecraftDownloader", "Failed to determine size of "+targetFile.getName()+", switching to file counter");
}else {
mTotalSize += size;
}
mDownloadFileCount++;
mScheduledDownloadTasks.add(
new DownloaderTask(targetFile, downloadClass, url, sha1, size, skipIfFailed)
);
@@ -435,20 +401,18 @@ public class MinecraftDownloader {
}catch (Exception e) {
if(!mSkipIfFailed) throw e;
}
mProcessedFileCounter.incrementAndGet();
mDownloadFileCounter.incrementAndGet();
}
private void finishWithoutDownloading() {
mProcessedFileCounter.incrementAndGet();
mProcessedSizeCounter.addAndGet(mDownloadSize);
mDownloadFileCounter.incrementAndGet();
mDownloadSizeCounter.addAndGet(mDownloadSize);
}
@Override
public void updateProgress(int curr, int max) {
int delta = curr - mLastCurr;
mProcessedSizeCounter.addAndGet(delta);
mInternetUsageCounter.addAndGet(delta);
mLastCurr = curr;
mDownloadSizeCounter.addAndGet(curr - mLastCurr);
mLastCurr = curr;
}
}
}
@@ -1,44 +0,0 @@
package net.kdt.pojavlaunch.tasks;
/**
* A simple class to calculate the average Internet speed using a simple moving average.
*/
public class SpeedCalculator {
private long mLastMillis;
private long mLastBytes;
private int mIndex;
private final double[] mPreviousInputs;
private double mSum;
public SpeedCalculator() {
this(64);
}
public SpeedCalculator(int averageDepth) {
mPreviousInputs = new double[averageDepth];
}
private double addToAverage(double speed) {
mSum -= mPreviousInputs[mIndex];
mSum += speed;
mPreviousInputs[mIndex] = speed;
if(++mIndex == mPreviousInputs.length) mIndex = 0;
double dLength = mPreviousInputs.length;
return (mSum + (dLength / 2d)) / dLength;
}
/**
* Update the current amount of bytes downloaded.
* @param bytes the new amount of bytes downloaded
* @return the current download speed in bytes per second
*/
public double feed(long bytes) {
long millis = System.currentTimeMillis();
long deltaBytes = bytes - mLastBytes;
long deltaMillis = millis - mLastMillis;
mLastBytes = bytes;
mLastMillis = millis;
double speed = (double)deltaBytes / ((double)deltaMillis / 1000d);
return addToAverage(speed);
}
}
@@ -155,23 +155,6 @@ public class DownloadUtils {
return result;
}
/**
* Get the content length for a given URL.
* @param url the URL to get the length for
* @return the length in bytes or -1 if not available
* @throws IOException if an I/O error occurs.
*/
public static long getContentLength(String url) throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
urlConnection.setRequestMethod("HEAD");
urlConnection.setDoInput(false);
urlConnection.setDoOutput(false);
urlConnection.connect();
int responseCode = urlConnection.getResponseCode();
if(responseCode >= 200 && responseCode <= 299) return urlConnection.getContentLength();
return -1;
}
public interface ParseCallback<T> {
T process(String input) throws ParseException;
}
@@ -55,6 +55,25 @@ static void gl4esi_get_display_dimensions(int* width, int* height) {
*height = 0;
}
static bool already_initialized = false;
static void gl_init_gl4es_internals() {
if(already_initialized) return;
already_initialized = true;
void* gl4es = dlopen("libgl4es_114.so", RTLD_NOLOAD);
if(gl4es == NULL) return;
void (*set_getmainfbsize)(void (*new_getMainFBSize)(int* width, int* height));
set_getmainfbsize = dlsym(gl4es, "set_getmainfbsize");
if(set_getmainfbsize == NULL) goto warn;
set_getmainfbsize(gl4esi_get_display_dimensions);
goto cleanup;
warn:
printf("gl4esinternals warning: gl4es was found but internals not initialized. expect rendering issues.\n");
cleanup:
// dlclose just decreases a ref counter, so this is fine
dlclose(gl4es);
}
gl_render_window_t* gl_init_context(gl_render_window_t *share) {
gl_render_window_t* bundle = malloc(sizeof(gl_render_window_t));
memset(bundle, 0, sizeof(gl_render_window_t));
@@ -126,6 +145,10 @@ void gl_swap_surface(gl_render_window_t* bundle) {
}
void gl_make_current(gl_render_window_t* bundle) {
// Perform initialization here as the renderer may not be loaded when gl_init or gl_init_context is called.
// Yes, even though it is dlopened on MC startup by Pojav, due to linker namespacing weirdness
// on API 29/MIUI it may not be loaded at the point of the gl_init call in the current namespace.
gl_init_gl4es_internals();
if(bundle == NULL) {
if(eglMakeCurrent_p(g_EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
@@ -188,20 +211,3 @@ void gl_swap_interval(int swapInterval) {
eglSwapInterval_p(g_EglDisplay, swapInterval);
}
JNIEXPORT void JNICALL
Java_org_lwjgl_opengl_PojavRendererInit_nativeInitGl4esInternals(JNIEnv *env, jclass clazz,
jobject function_provider) {
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "GL4ES internals initializing...");
jclass funcProviderClass = (*env)->GetObjectClass(env, function_provider);
jmethodID method_getFunctionAddress = (*env)->GetMethodID(env, funcProviderClass, "getFunctionAddress", "(Ljava/lang/CharSequence;)J");
#define GETSYM(N) ((*env)->CallLongMethod(env, function_provider, method_getFunctionAddress, (*env)->NewStringUTF(env, N)));
void (*set_getmainfbsize)(void (*new_getMainFBSize)(int* width, int* height)) = (void*)GETSYM("set_getmainfbsize");
if(set_getmainfbsize != NULL) {
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "GL4ES internals initialized dimension callback");
set_getmainfbsize(gl4esi_get_display_dimensions);
}
#undef GETSYM
}
@@ -374,8 +374,7 @@
<string name="exception_failed_to_unpack_jre17">Failed to install JRE 17</string>
<string name="newdl_starting">Reading game metadata…</string>
<string name="newdl_downloading_metadata">Downloading game metadata (%s)</string>
<string name="newdl_downloading_game_files">Downloading game… (%d/%d, %.2f MB/s)</string>
<string name="newdl_downloading_game_files_size">Downloading game… (%.2f/%.2f MB, %.2f MB/s)</string>
<string name="newdl_downloading_game_files">Downloading game files… (%d/%d, %.2f MB)</string>
<string name="cropper_title">Select image region</string>
<string name="cropper_lock_vertical">V. lock</string>
<string name="cropper_lock_horizontal">H. lock</string>
@@ -4792,8 +4792,6 @@ public final class GLCapabilities {
GLCapabilities(FunctionProvider provider, Set<String> ext, boolean fc, IntFunction<PointerBuffer> bufferFactory) {
forwardCompatible = fc;
PojavRendererInit.onCreateCapabilities(provider);
PointerBuffer caps = bufferFactory.apply(ADDRESS_BUFFER_SIZE);
OpenGL11 = check_GL11(provider, caps, ext, fc);
@@ -1,39 +0,0 @@
package org.lwjgl.opengl;
import org.lwjgl.system.FunctionProvider;
import org.lwjgl.system.SharedLibrary;
import javax.annotation.Nullable;
/**
* Class for initializing renderer-specific callbacks. Allows to reliably initialize
* any callbacks needed for renderers by using the same FunctionProvider as used for loading
* GL symbols.
* */
public class PojavRendererInit {
public static void onCreateCapabilities(FunctionProvider functionProvider) {
String rendererName = null;
if(functionProvider instanceof SharedLibrary) {
SharedLibrary rendererLibrary = (SharedLibrary) functionProvider;
rendererName = rendererLibrary.getName();
}
if(!isValidString(rendererName)) {
rendererName = System.getProperty("org.lwjgl.opengl.libname");
}
if(!isValidString(rendererName)) {
System.out.println("PojavRendererInit: Failed to find Pojav renderer name! " +
"Renderer-specific initialization may not work properly");
}
// NOTE: hardcoded gl4es libname
if(rendererName.endsWith("libgl4es_114.so")) {
nativeInitGl4esInternals(functionProvider);
}
}
private static boolean isValidString(@Nullable String s) {
return s != null && !s.isEmpty();
}
public static native void nativeInitGl4esInternals(FunctionProvider functionProvider);
}