From 5dbc4cfad641d278bc85c288c2a90b06d388c5e3 Mon Sep 17 00:00:00 2001 From: AShiningRay Date: Sat, 19 Oct 2024 14:00:01 -0300 Subject: [PATCH] Drop the Media Cache. As noted in the previous commit, this has outlived its usefulness, DOOM II RPG doesn't leak memory on players anymore (probably true for other jars as well), and midi load/play performance has been improved to not need caching of any kind anymore. --- src/javax/microedition/media/Manager.java | 73 +----- src/libretro/freej2me_libretro.c | 101 ++++----- src/libretro/freej2me_libretro.h | 42 ---- src/org/recompile/freej2me/AWTGUI.java | 224 ------------------- src/org/recompile/freej2me/Config.java | 8 - src/org/recompile/freej2me/FreeJ2ME.java | 2 - src/org/recompile/freej2me/Libretro.java | 26 +-- src/org/recompile/mobile/PlatformPlayer.java | 12 - 8 files changed, 49 insertions(+), 439 deletions(-) diff --git a/src/javax/microedition/media/Manager.java b/src/javax/microedition/media/Manager.java index ed331f7c..b9bedfce 100644 --- a/src/javax/microedition/media/Manager.java +++ b/src/javax/microedition/media/Manager.java @@ -45,14 +45,6 @@ public final class Manager public static File soundfontDir = new File("freej2me_system" + File.separatorChar + "customMIDI" + File.separatorChar); private static Soundbank customSoundfont; public static Synthesizer customSynth; - - - /* Default max amount of players in FreeJ2ME's config */ - public static PlatformPlayer mediaPlayers[] = new PlatformPlayer[32]; - public static byte mediaPlayersIndex = 0; - - /* Midi Caching for better performance on certain VMs like OpenJDK 8 with jars that constantly load a similar set of streams. */ - private static Map mediaCache = new HashMap<>(); public static boolean dumpAudioStreams = false; @@ -60,12 +52,12 @@ public static Player createPlayer(InputStream stream, String type) throws IOExce { checkCustomMidi(); - stream.mark(1024); - String streamMD5 = generateMD5Hash(stream, 1024); - stream.reset(); - if(dumpAudioStreams) { + stream.mark(1024); + String streamMD5 = generateMD5Hash(stream, 1024); + stream.reset(); + // Copy the stream contents into a temporary stream to be saved as file final ByteArrayOutputStream streamCopy = new ByteArrayOutputStream(); final byte[] copyBuffer = new byte[1024]; @@ -94,61 +86,9 @@ public static Player createPlayer(InputStream stream, String type) throws IOExce streamCopy.writeTo(outStream); } - // return checkMediaCache(streamMD5, stream, type); - return new PlatformPlayer(stream, type); } - private static Player checkMediaCache(String streamMD5, InputStream stream, String type) - { - /* If we currently have this stream's player cached, return it instantly to avoid creating a new player and its overhead */ - if (mediaCache.containsKey(streamMD5)) - { - /* - * We're basically "loading up" a new player as far as the MIDlet is concerned, - * so make it seem as such by doing the following steps before returning it to the MIDlet: - * 1 - Stopping the player if it's not stopped (this will probably be removed once media playback loop is more mature) - * 2 - Setting the media playback time back to the start. - * 3 - Setting its state to PREFETCHED for good measure. - */ - mediaPlayers[mediaCache.get(streamMD5)].cacheDeallocate(); - mediaPlayers[mediaCache.get(streamMD5)].setMediaTime(0); - return mediaPlayers[mediaCache.get(streamMD5)]; - } - - // Otherwise, let's create and cache a new one. - - // If the index is out of bounds, we reached the end of our cache, go back to the start to find a position to free - if(mediaPlayersIndex >= mediaPlayers.length) { mediaPlayersIndex = 0; } - - // Run through the entire cache index to find a suitable position to slot the new player in. - for(; mediaPlayersIndex < mediaPlayers.length; mediaPlayersIndex++) - { - if(mediaPlayers[mediaPlayersIndex] == null) { break; } /* A null position means we can use it right away */ - - /* Otherwise, we prefer deallocating a position if it is not playing (running). */ - else if(mediaPlayers[mediaPlayersIndex] != null && mediaPlayers[mediaPlayersIndex].getState() == Player.PREFETCHED) - { - mediaPlayers[mediaPlayersIndex].cacheDeallocate(); - mediaCache.values().remove(mediaPlayersIndex); - break; - } - /* If we ever reach this one, it's because all the other slots are used, and are playing. Deallocate the last cache position as a last resort. */ - else if(mediaPlayersIndex == mediaPlayers.length-1) - { - mediaPlayers[mediaPlayersIndex].cacheDeallocate(); - mediaCache.values().remove(mediaPlayersIndex); - break; - } - } - - mediaPlayers[mediaPlayersIndex] = new PlatformPlayer(stream, type); - mediaCache.put(streamMD5, mediaPlayersIndex); - mediaPlayersIndex++; - - return mediaPlayers[mediaCache.get(streamMD5)]; - } - public static Player createPlayer(String locator) throws MediaException { checkCustomMidi(); @@ -174,11 +114,6 @@ public static void playTone(int note, int duration, int volume) System.out.println("Play Tone"); } - public static void updatePlayerNum(byte num) - { - mediaPlayers = new PlatformPlayer[num]; - } - private static String generateMD5Hash(InputStream stream, int byteCount) { try diff --git a/src/libretro/freej2me_libretro.c b/src/libretro/freej2me_libretro.c index a47fa063..fbea1230 100755 --- a/src/libretro/freej2me_libretro.c +++ b/src/libretro/freej2me_libretro.c @@ -150,7 +150,6 @@ int phoneType; /* 0=standard, 1=nokia, 2=siemens, 3=motorola, 4=sonyEricsson */ int gameFPS; /* Auto(0), 60, 30, 15 */ int soundEnabled; /* also acts as a boolean */ int customMidi; /* Also acts as a boolean */ -int midiCacheSize; /* Maximum amount of MIDI Players allowed on FreeJ2ME at any given time */ int dumpAudioStreams; /* Variables used to manage the pointer speed when controlled from an analog stick */ int pointerXSpeed = 8; @@ -287,12 +286,12 @@ int read_from_pipe(void* pipe, void *data, int datasize) /* Function to check the core's config states in the libretro frontend */ static void check_variables(bool first_time_startup) { - struct retro_variable var = {0}; + struct retro_variable var = {0}; - var.key = "freej2me_resolution"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + var.key = "freej2me_resolution"; + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { char *resChar; char str[100]; snprintf(str, sizeof(str), "%s", var.value); @@ -301,83 +300,69 @@ static void check_variables(bool first_time_startup) if (resChar) { screenRes[0] = strtoul(resChar, NULL, 0); } resChar = strtok(NULL, "x"); if (resChar) { screenRes[1] = strtoul(resChar, NULL, 0); } - } + } - var.key = "freej2me_halvecanvasres"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + var.key = "freej2me_halvecanvasres"; + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { if (!strcmp(var.value, "off")) { halveCanvasRes = 0; } else if (!strcmp(var.value, "on")) { halveCanvasRes = 1; } - } + } - var.key = "freej2me_rotate"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + var.key = "freej2me_rotate"; + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { if (!strcmp(var.value, "off")) { rotateScreen = 0; } else if (!strcmp(var.value, "on")) { rotateScreen = 1; } - } + } - var.key = "freej2me_phone"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + var.key = "freej2me_phone"; + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { if (!strcmp(var.value, "Standard")) { phoneType = 0; } else if (!strcmp(var.value, "Nokia")) { phoneType = 1; } else if (!strcmp(var.value, "Siemens")) { phoneType = 2; } else if (!strcmp(var.value, "Motorola")) { phoneType = 3; } else if (!strcmp(var.value, "SonyEricsson")) { phoneType = 4; } - } + } - var.key = "freej2me_fps"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + var.key = "freej2me_fps"; + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { if (!strcmp(var.value, "Auto")) { gameFPS = 0; } else if (!strcmp(var.value, "60")) { gameFPS = 60; } else if (!strcmp(var.value, "30")) { gameFPS = 30; } else if (!strcmp(var.value, "15")) { gameFPS = 15; } - } + } - var.key = "freej2me_sound"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + var.key = "freej2me_sound"; + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { if (!strcmp(var.value, "off")) { soundEnabled = 0; } else if (!strcmp(var.value, "on")) { soundEnabled = 1; } - } + } - var.key = "freej2me_midifont"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { - if (!strcmp(var.value, "off")) { customMidi = 0; } - else if (!strcmp(var.value, "on")) { customMidi = 1; } - } - - var.key = "freej2me_mediacachesize"; + var.key = "freej2me_midifont"; if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (!strcmp(var.value, "48")) { midiCacheSize = 48; } - else if (!strcmp(var.value, "1")) { midiCacheSize = 1; } - else if (!strcmp(var.value, "2")) { midiCacheSize = 2; } - else if (!strcmp(var.value, "4")) { midiCacheSize = 4; } - else if (!strcmp(var.value, "8")) { midiCacheSize = 8; } - else if (!strcmp(var.value, "16")) { midiCacheSize = 16; } - else if (!strcmp(var.value, "32")) { midiCacheSize = 32; } - else if (!strcmp(var.value, "64")) { midiCacheSize = 64; } - else if (!strcmp(var.value, "96")) { midiCacheSize = 96; } + if (!strcmp(var.value, "off")) { customMidi = 0; } + else if (!strcmp(var.value, "on")) { customMidi = 1; } } var.key = "freej2me_dumpaudiostreams"; - if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { if (!strcmp(var.value, "off")) { dumpAudioStreams = 0; } else if (!strcmp(var.value, "on")) { dumpAudioStreams = 1; } - } + } - var.key = "freej2me_pointertype"; + var.key = "freej2me_pointertype"; if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (!strcmp(var.value, "Mouse")) @@ -457,7 +442,7 @@ static void check_variables(bool first_time_startup) /* Prepare a string to pass those core options to the Java app */ options_update = malloc(sizeof(char) * PIPE_MAX_LEN); - snprintf(options_update, PIPE_MAX_LEN, "FJ2ME_LR_OPTS:|%lux%lu|%d|%d|%d|%d|%d|%d|%d|%d", screenRes[0], screenRes[1], halveCanvasRes, rotateScreen, phoneType, gameFPS, soundEnabled, customMidi, midiCacheSize, dumpAudioStreams); + snprintf(options_update, PIPE_MAX_LEN, "FJ2ME_LR_OPTS:|%lux%lu|%d|%d|%d|%d|%d|%d|%d", screenRes[0], screenRes[1], halveCanvasRes, rotateScreen, phoneType, gameFPS, soundEnabled, customMidi, dumpAudioStreams); optstrlen = strlen(options_update); /* 0xD = 13, which is the special case where the java app will receive the updated configs */ @@ -516,7 +501,7 @@ void retro_init(void) */ check_variables(true); - char resArg[2][4], halveCanvas[2], rotateArg[2], phoneArg[2], fpsArg[3], soundArg[2], midiArg[2], mediaCacheArg[3], dumpAudioArg[2]; + char resArg[2][4], halveCanvas[2], rotateArg[2], phoneArg[2], fpsArg[3], soundArg[2], midiArg[2], dumpAudioArg[2]; sprintf(resArg[0], "%lu", screenRes[0]); /* Libretro config Width */ sprintf(resArg[1], "%lu", screenRes[1]); /* Libretro config Height */ sprintf(halveCanvas, "%d", halveCanvasRes); @@ -525,7 +510,6 @@ void retro_init(void) sprintf(fpsArg, "%d", gameFPS); sprintf(soundArg, "%d", soundEnabled); sprintf(midiArg, "%d", customMidi); - sprintf(mediaCacheArg,"%d", midiCacheSize); sprintf(dumpAudioArg, "%d", dumpAudioStreams); /* start java process */ @@ -551,12 +535,11 @@ void retro_init(void) params[8] = strdup(fpsArg); params[9] = strdup(soundArg); params[10] = strdup(midiArg); - params[11] = strdup(mediaCacheArg); - params[12] = strdup(dumpAudioArg); - params[13] = NULL; // Null-terminate the array + params[11] = strdup(dumpAudioArg); + params[12] = NULL; // Null-terminate the array log_fn(RETRO_LOG_INFO, "Passing params: %s | %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3), - *(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11), *(params+12)); + *(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11)); } log_fn(RETRO_LOG_INFO, "Preparing to open FreeJ2ME-Plus' Java app (make sure freej2me-lr.jar is inside system/).\n"); @@ -1052,8 +1035,8 @@ pid_t javaOpen(char *cmd, char **params) log_fn(RETRO_LOG_INFO, "Setting up java app's process and pipes...\n"); log_fn(RETRO_LOG_INFO, "Opening: %s %s %s ...\n", *(params+0), *(params+1), *(params+2)); - log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3), - *(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11), *(params+12)); + log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3), + *(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11)); } else { log_fn(RETRO_LOG_INFO, "\n\nRESTARTING!!!\n\n"); restarting = false; } @@ -1182,7 +1165,7 @@ void javaOpen(char *cmd, char **params) sprintf(cmdWin, "javaw -jar %s", cmd); log_fn(RETRO_LOG_INFO, "Opening: %s \n", cmd); - for (int i = 3; i <= 12; i++) /* There are 10 cmd arguments for now */ + for (int i = 3; i <= 11; i++) { //log_fn(RETRO_LOG_INFO, "Processing arg %d: %s \n", i, *(params+i)); sprintf(cmdWin, "%s %s", cmdWin, *(params+i)); @@ -1195,8 +1178,8 @@ void javaOpen(char *cmd, char **params) log_fn(RETRO_LOG_INFO, "Setting up java app's process and pipes...\n"); log_fn(RETRO_LOG_INFO, "Opening: %s %s %s ...\n", *(params+0), *(params+1), *(params+2)); - log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3), - *(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11), *(params+12)); + log_fn(RETRO_LOG_INFO, "Params: %s | %s | %s | %s | %s | %s | %s | %s | %s\n", *(params+3), + *(params+4), *(params+5), *(params+6), *(params+7), *(params+8), *(params+9), *(params+10), *(params+11)); } else { log_fn(RETRO_LOG_INFO, "\n\nRESTARTING!!!\n\n"); restarting = false; } diff --git a/src/libretro/freej2me_libretro.h b/src/libretro/freej2me_libretro.h index bb697e4d..2ecda9d4 100644 --- a/src/libretro/freej2me_libretro.h +++ b/src/libretro/freej2me_libretro.h @@ -197,27 +197,6 @@ struct retro_core_option_v2_definition core_options[] = }, "Default" }, - { - "freej2me_mediacachesize", - "Virtual Phone Settings > Media Cache Size", - "Media Cache Size", - "FreeJ2ME uses a media caching system to improve performance on certain VMs like OpenJDK 8 with apps that constantly allocate a similar set of media streams instead of keeping them allocated all the time (often to save precious memory). Most modern platforms should be able to hold the default of 48 unique streams in memory at once, which is also more than most J2ME apps would realistically load on real hardware. Feel free to adjust if your platform is starved for memory and/or you know the jar you're running only really uses a few slots of media but cycles the data it loads there.", - "FreeJ2ME uses a media caching system to improve performance on certain VMs like OpenJDK 8 with apps that constantly allocate a similar set of media streams instead of keeping them allocated all the time (often to save precious memory). Most modern platforms should be able to hold the default of 48 unique streams in memory at once, which is also more than most J2ME apps would realistically load on real hardware. Feel free to adjust if your platform is starved for memory and/or you know the jar you're running only really uses a few slots of media but cycles the data it loads there.", - "vphone_settings", - { - { "1", "1" }, - { "2", "2" }, - { "4", "4" }, - { "8", "8" }, - { "16", "16" }, - { "32", "32" }, - { "48", "48" }, - { "64", "64" }, - { "96", "96" }, - { NULL, NULL }, - }, - "48" - }, { "freej2me_dumpaudiostreams", "Advanced Settings > Dump Audio Streams", @@ -460,23 +439,6 @@ struct retro_core_option_definition core_options_v1 [] = }, "Default" }, - { - "freej2me_mediacachesize", - "Media Cache Size", - "FreeJ2ME uses a media caching system to improve performance on certain VMs like OpenJDK 8 with apps that constantly allocate a similar set of media streams instead of keeping them allocated all the time (often to save precious memory). Most modern platforms should be able to hold the default of 48 unique streams in memory at once, which is also more than most J2ME apps would realistically load on real hardware. Feel free to adjust if your platform is starved for memory and/or you know the jar you're running only really uses a few slots of media but cycles the data it loads there.", { - { "1", "1" }, - { "2", "2" }, - { "4", "4" }, - { "8", "8" }, - { "16", "16" }, - { "32", "32" }, - { "48", "48" }, - { "64", "64" }, - { "96", "96" }, - { NULL, NULL }, - }, - "48" - }, { "freej2me_dumpaudiostreams", "Dump Audio Streams", @@ -614,10 +576,6 @@ static const struct retro_variable vars[] = "freej2me_midifont", "MIDI Soundfont; off|on" }, - { /* Max MIDI Players */ - "freej2me_mediacachesize", - "Media Cache Size: 48|1|2|4|8|16|32|64|96" - }, { /* Dump Audio Streams */ "freej2me_dumpaudiostreams", "Dump Audio Streams: off|on" diff --git a/src/org/recompile/freej2me/AWTGUI.java b/src/org/recompile/freej2me/AWTGUI.java index 42158f7c..59143831 100644 --- a/src/org/recompile/freej2me/AWTGUI.java +++ b/src/org/recompile/freej2me/AWTGUI.java @@ -54,7 +54,6 @@ public final class AWTGUI /* Sub menus (for now, all of them are located in "Settings") */ final Menu fpsCap = new Menu("FPS Limit"); final Menu phoneType = new Menu("Phone Key Layout"); - final Menu midiStreamNum = new Menu("Media Cache Size"); /* Dialogs for resolution changes, restart notifications, MemStats and info about FreeJ2ME */ final Dialog resDialog = new Dialog(main , "Set LCD Resolution", true); @@ -162,13 +161,6 @@ public final class AWTGUI final CheckboxMenuItem fpsCap30 = new CheckboxMenuItem("30 FPS", false); final CheckboxMenuItem fpsCap15 = new CheckboxMenuItem("15 FPS", false); - final CheckboxMenuItem mediaCacheSize[] = new CheckboxMenuItem[] {new CheckboxMenuItem("1 Slot", false), new CheckboxMenuItem("2 Slots", false), - new CheckboxMenuItem("4 Slots", false), new CheckboxMenuItem("8 Slots", false), new CheckboxMenuItem("16 Slots", false), - new CheckboxMenuItem("32 Slots", false), new CheckboxMenuItem("48 Slots", false), new CheckboxMenuItem("64 Slots", false), - new CheckboxMenuItem("96 Slots", false)}; - - final byte[] numPlayers = new byte[] {1, 2, 4 ,8, 16, 32, 48, 64, 96}; /* Used to simplify the UpdateOptions() method below */ - final CheckboxMenuItem dumpAudioData = new CheckboxMenuItem("Dump Audio Streams"); final CheckboxMenuItem dumpGraphicsData = new CheckboxMenuItem("Dump Graphics Objects"); final CheckboxMenuItem showMemoryUsage = new CheckboxMenuItem("Show VM Memory Usage"); @@ -409,214 +401,6 @@ public void itemStateChanged(ItemEvent e) } }); - mediaCacheSize[0].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[0].getState()) - { - config.updateMediaCacheSize(""+numPlayers[0]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[0])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[1].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[1].getState()) - { - config.updateMediaCacheSize(""+numPlayers[1]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[1])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[2].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[2].getState()) - { - config.updateMediaCacheSize(""+numPlayers[2]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[2])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[3].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[3].getState()) - { - config.updateMediaCacheSize(""+numPlayers[3]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[3])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[4].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[4].getState()) - { - config.updateMediaCacheSize(""+numPlayers[4]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[4])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[5].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[5].getState()) - { - config.updateMediaCacheSize(""+numPlayers[5]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[5])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[6].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[6].getState()) - { - config.updateMediaCacheSize(""+numPlayers[6]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[6])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[7].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[7].getState()) - { - config.updateMediaCacheSize(""+numPlayers[7]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[7])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - mediaCacheSize[8].addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(mediaCacheSize[8].getState()) - { - config.updateMediaCacheSize(""+numPlayers[8]); - hasPendingChange = true; - - // Uncheck all other checkboxes for midi players - for(int i = 0; i < mediaCacheSize.length; i++) - { - if(mediaCacheSize[i].equals(mediaCacheSize[8])) { continue; } - mediaCacheSize[i].setState(false); - } - - } - - restartRequiredDialog.setLocationRelativeTo(main); - restartRequiredDialog.setVisible(true); - } - }); - - stdLayout.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) @@ -811,7 +595,6 @@ private void buildMenuBar() optionMenu.add(halveCanvasRes); optionMenu.add(phoneType); optionMenu.add(fpsCap); - optionMenu.add(midiStreamNum); optionMenu.add(mapInputs); debugMenu.add(dumpAudioData); @@ -829,8 +612,6 @@ private void buildMenuBar() fpsCap.add(fpsCap60); fpsCap.add(fpsCap30); fpsCap.add(fpsCap15); - - for(int i = 0; i < mediaCacheSize.length; i++) { midiStreamNum.add(mediaCacheSize[i]); } // add menus to menubar menuBar.add(fileMenu); @@ -855,11 +636,6 @@ public void updateOptions() motorolaLayout.setState(config.settings.get("phone").equals("Motorola")); resChoice.select(""+ Integer.parseInt(config.settings.get("width")) + "x" + ""+ Integer.parseInt(config.settings.get("height"))); - - for(int i = 0; i < mediaCacheSize.length; i++) - { - mediaCacheSize[i].setState(config.settings.get("mediaCacheSize").equals(""+numPlayers[i])); - } /* We only need to do this call once, when the jar first loads */ firstLoad = false; diff --git a/src/org/recompile/freej2me/Config.java b/src/org/recompile/freej2me/Config.java index 569342ab..061b528b 100644 --- a/src/org/recompile/freej2me/Config.java +++ b/src/org/recompile/freej2me/Config.java @@ -138,7 +138,6 @@ public void init() if(!settings.containsKey("rotate")) { settings.put("rotate", "off"); } if(!settings.containsKey("fps")) { settings.put("fps", "0"); } if(!settings.containsKey("soundfont")) { settings.put("soundfont", "Default"); } - if(!settings.containsKey("mediaCacheSize")) { settings.put("mediaCacheSize", "48"); } } catch (Exception e) @@ -229,11 +228,4 @@ public void updateSoundfont(String value) onChange.run(); } - public void updateMediaCacheSize(String value) - { - System.out.println("Config: mediaCacheSize "+value); - settings.put("mediaCacheSize", value); - saveConfig(); - onChange.run(); - } } diff --git a/src/org/recompile/freej2me/FreeJ2ME.java b/src/org/recompile/freej2me/FreeJ2ME.java index 856e5d4b..1d283835 100644 --- a/src/org/recompile/freej2me/FreeJ2ME.java +++ b/src/org/recompile/freej2me/FreeJ2ME.java @@ -437,8 +437,6 @@ private void settingsChanged() main.setSize(lcdWidth*scaleFactor+xborder , lcdHeight*scaleFactor+yborder); } - Manager.updatePlayerNum((byte) Integer.parseInt(config.settings.get("mediaCacheSize"))); - if (Mobile.nokia) { System.setProperty("microedition.platform", "Nokia6233/05.10"); } else if (Mobile.sonyEricsson) { diff --git a/src/org/recompile/freej2me/Libretro.java b/src/org/recompile/freej2me/Libretro.java index 52147144..4d374f42 100644 --- a/src/org/recompile/freej2me/Libretro.java +++ b/src/org/recompile/freej2me/Libretro.java @@ -59,8 +59,6 @@ public class Libretro private long elapsedTime = 0; private long sleepTime = 0; - private int maxmidistreams = 32; - private boolean[] pressedKeys = new boolean[128]; private byte[] frameBuffer = new byte[800*800*3]; @@ -135,12 +133,9 @@ public Libretro(String args[]) if(Integer.parseInt(args[6]) == 0) { soundEnabled = false; } if(Integer.parseInt(args[7]) == 1) { Manager.useCustomMidi = true; } - - maxmidistreams = Integer.parseInt(args[8]); - Manager.updatePlayerNum((byte) maxmidistreams); /* Dump Audio Streams will not be a per-game FreeJ2ME config, so it will have to be set every time for now */ - if(Integer.parseInt(args[9]) == 1) { Manager.dumpAudioStreams = true; } + if(Integer.parseInt(args[8]) == 1) { Manager.dumpAudioStreams = true; } /* Once it finishes parsing all arguments, it's time to set up freej2me-lr */ @@ -329,10 +324,7 @@ public void run() if(!Manager.useCustomMidi) { config.settings.put("soundfont", "Default"); } else { config.settings.put("soundfont", "Custom"); } - - config.settings.put("maxmidistreams", ""+maxmidistreams); - config.saveConfig(); settingsChanged(); @@ -394,18 +386,8 @@ public void run() if(Integer.parseInt(cfgtokens[8])==0) { config.settings.put("soundfont", "Default"); } if(Integer.parseInt(cfgtokens[8])==1) { config.settings.put("soundfont", "Custom"); } - if(Integer.parseInt(cfgtokens[9])==0) { config.settings.put("maxmidistreams", "1");} - if(Integer.parseInt(cfgtokens[9])==1) { config.settings.put("maxmidistreams", "2");} - if(Integer.parseInt(cfgtokens[9])==2) { config.settings.put("maxmidistreams", "4");} - if(Integer.parseInt(cfgtokens[9])==3) { config.settings.put("maxmidistreams", "8");} - if(Integer.parseInt(cfgtokens[9])==4) { config.settings.put("maxmidistreams", "16");} - if(Integer.parseInt(cfgtokens[9])==5) { config.settings.put("maxmidistreams", "32");} - if(Integer.parseInt(cfgtokens[9])==6) { config.settings.put("maxmidistreams", "48");} - if(Integer.parseInt(cfgtokens[9])==7) { config.settings.put("maxmidistreams", "64");} - if(Integer.parseInt(cfgtokens[9])==8) { config.settings.put("maxmidistreams", "96");} - - if(Integer.parseInt(cfgtokens[10])==1) { Manager.dumpAudioStreams = true; } - if(Integer.parseInt(cfgtokens[10])==0) { Manager.dumpAudioStreams = false; } + if(Integer.parseInt(cfgtokens[9])==1) { Manager.dumpAudioStreams = true; } + if(Integer.parseInt(cfgtokens[9])==0) { Manager.dumpAudioStreams = false; } config.saveConfig(); settingsChanged(); @@ -511,8 +493,6 @@ private void settingsChanged() gc = (Graphics2D)surface.getGraphics(); } - Manager.updatePlayerNum((byte) Integer.parseInt(config.settings.get("maxmidistreams"))); - if (Mobile.nokia) { System.setProperty("microedition.platform", "Nokia6233/05.10"); } else if (Mobile.sonyEricsson) { diff --git a/src/org/recompile/mobile/PlatformPlayer.java b/src/org/recompile/mobile/PlatformPlayer.java index d243a016..d1fbe607 100644 --- a/src/org/recompile/mobile/PlatformPlayer.java +++ b/src/org/recompile/mobile/PlatformPlayer.java @@ -223,18 +223,6 @@ public void deallocate() if(state > Player.UNREALIZED) {state = Player.REALIZED;} } - /* - * This is where we do the actual deallocations, otherwise the cache could break audio in games like Sonic Jump (Nokia 240x320), - * as it would return a deallocated player due to the call above. So in short, only Manager itself should deallocate players. */ - public void cacheDeallocate() - { - if(getState() == Player.CLOSED) { throw new IllegalStateException("Cannot deallocate player, it is already CLOSED."); } - - stop(); - player.deallocate(); - state = Player.REALIZED; - } - public String getContentType() { if(getState() == Player.UNREALIZED || getState() == Player.CLOSED) { throw new IllegalStateException("Cannot get content type. Player is either CLOSED or UNREALIZED."); }