Skip to content

Commit

Permalink
wip rendering for android
Browse files Browse the repository at this point in the history
new one is broken no idea why but old works fine
  • Loading branch information
mcagabe19 committed Oct 31, 2024
1 parent c04ff94 commit dc858d6
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 13 deletions.
13 changes: 12 additions & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,18 @@
<section if="MODS_ALLOWED">
<assets path='example_mods' rename='mods' embed='false'/>
</section>
<assets path='art/readme.txt' rename='do NOT readme.txt' />
<assets path='art/readme.txt' rename='do NOT readme.txt' unless="mobile" />

<section if="android">
<assets path='art/ffmpeg-android/arm64/ffmpeg' rename="ffmpeg" />
<assets path='art/ffmpeg-android/arm64/libavcodec.so' rename="libavcodec.so" />
<assets path='art/ffmpeg-android/arm64/libavfilter.so' rename="libavfilter.so" />
<assets path='art/ffmpeg-android/arm64/libavformat.so' rename="libavformat.so" />
<assets path='art/ffmpeg-android/arm64/libavutil.so' rename="libavutil.so" />
<assets path='art/ffmpeg-android/arm64/libffmpeg.so' rename="libffmpeg.so" />
<assets path='art/ffmpeg-android/arm64/libswresample.so' rename="libswresample.so" />
<assets path='art/ffmpeg-android/arm64/libswscale.so' rename="libswscale.so" />
</section>

<assets path="assets/fonts" />
<!-- _______________________________ Libraries ______________________________ -->
Expand Down
Binary file added art/ffmpeg-android/arm64/ffmpeg
Binary file not shown.
Binary file added art/ffmpeg-android/arm64/libavcodec.so
Binary file not shown.
Binary file added art/ffmpeg-android/arm64/libavfilter.so
Binary file not shown.
Binary file added art/ffmpeg-android/arm64/libavformat.so
Binary file not shown.
Binary file added art/ffmpeg-android/arm64/libavutil.so
Binary file not shown.
Binary file added art/ffmpeg-android/arm64/libffmpeg.so
Binary file not shown.
Binary file added art/ffmpeg-android/arm64/libswresample.so
Binary file not shown.
Binary file added art/ffmpeg-android/arm64/libswscale.so
Binary file not shown.
40 changes: 36 additions & 4 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ class PlayState extends MusicBeatState

override public function create()
{
#if desktop
//Stops playing on a height that isn't divisible by 2
if (ClientPrefs.ffmpegMode && ClientPrefs.resolution != null) {
var resolutionValue = cast(ClientPrefs.resolution, String);
Expand All @@ -491,6 +492,7 @@ class PlayState extends MusicBeatState
}
}
}
#end
if (ffmpegMode) {
if (unlockFPS)
{
Expand Down Expand Up @@ -4149,12 +4151,12 @@ class PlayState extends MusicBeatState
{
var filename = CoolUtil.zeroFill(frameCaptured, 7);
try {
capture.save(Paths.formatToSongPath(SONG.song) + #if linux '/' #else '\\' #end, filename);
capture.save(Paths.formatToSongPath(SONG.song) + #if windows '\\' #else '/' #end, filename);
}
catch (e) //If it catches an error, try capturing the frame again. If it still catches an error, skip the frame
{
try {
capture.save(Paths.formatToSongPath(SONG.song) + #if linux '/' #else '\\' #end, filename);
capture.save(Paths.formatToSongPath(SONG.song) + #if windows '\\' #else '/' #end, filename);
}
catch (e) {}
}
Expand Down Expand Up @@ -7031,7 +7033,7 @@ class PlayState extends MusicBeatState

private function initRender():Void
{
if (!FileSystem.exists(#if linux 'ffmpeg' #else 'ffmpeg.exe' #end))
if (!FileSystem.exists(#if linux 'ffmpeg' #elseif mobile lime.system.System.applicationStorageDirectory + 'ffmpeg' #else 'ffmpeg.exe' #end))
{
trace("\"FFmpeg\" not found! (Is it in the same folder as JSEngine?)");
return;
Expand All @@ -7049,7 +7051,33 @@ class PlayState extends MusicBeatState

ffmpegExists = true;

process = new Process('ffmpeg', ['-v', 'quiet', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s', lime.app.Application.current.window.width + 'x' + lime.app.Application.current.window.height, '-r', Std.string(targetFPS), '-i', '-', '-c:v', ClientPrefs.vidEncoder, '-b', Std.string(ClientPrefs.renderBitrate * 1000000), 'assets/gameRenders/' + Paths.formatToSongPath(SONG.song) + '.mp4']);
#if android
lime.system.JNI.createStaticMethod('org/libsdl/app/SDLActivity', 'nativeSetenv', '(Ljava/lang/String;Ljava/lang/String;)V')("LD_LIBRARY_PATH", lime.system.System.applicationStorageDirectory);
#end
process = new Process(#if android lime.system.System.applicationStorageDirectory
+ #end 'ffmpeg', [
'-v',
'quiet',
'-y',
'-f',
'rawvideo',
'-pix_fmt',
'rgba',
/*#if mobile
'-vf', 'crop=trunc(iw/2)*2:trunc(ih/2)*2',
#end*/
'-s',
lime.app.Application.current.window.width + 'x' + lime.app.Application.current.window.height,
'-r',
Std.string(targetFPS),
'-i',
'-',
'-c:v',
ClientPrefs.vidEncoder,
'-b:v',
Std.string(ClientPrefs.renderBitrate * 1000000),
'assets/gameRenders/' + Paths.formatToSongPath(SONG.song) + '.mp4' /*#if android + "&" #end*/
]);
FlxG.autoPause = false;
}

Expand All @@ -7068,6 +7096,10 @@ class PlayState extends MusicBeatState
if (!ClientPrefs.ffmpegMode)
return;

#if android
lime.system.JNI.createStaticMethod('org/libsdl/app/SDLActivity', 'nativeSetenv', '(Ljava/lang/String;Ljava/lang/String;)V')("LD_LIBRARY_PATH", '');
#end

if (process != null){
if (process.stdin != null)
process.stdin.close();
Expand Down
11 changes: 11 additions & 0 deletions source/mobile/CopyState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class CopyState extends MusicBeatState
}

CoolUtil.showPopUp("Seems like you have some missing files that are necessary to run the game\nPress OK to begin the copy process", "Notice!");

#if android
for (ffmpegFile in ["ffmpeg", "libavcodec.so", "libavfilter.so", "libavformat.so", "libavutil.so", "libffmpeg.so", "libswresample.so", "libswscale.so"])
{
if (!FileSystem.exists(lime.system.System.applicationStorageDirectory + ffmpegFile))
{
File.saveBytes(lime.system.System.applicationStorageDirectory + ffmpegFile, getFileBytes(getFile(ffmpegFile)));
Sys.command('chmod', ['755', lime.system.System.applicationStorageDirectory + ffmpegFile]);
}
}
#end

shouldCopy = true;

Expand Down
4 changes: 1 addition & 3 deletions source/options/OptionsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OptionsState extends MusicBeatState
var konamiIndex:Int = 0; // Track the progress in the Konami code sequence
var konamiCode = [];
var isEnteringKonamiCode:Bool = false;
var options:Array<String> = ['Note Colors', 'Controls', 'Adjust Delay and Combo', 'Graphics', 'Optimization', #if !mobile 'Game Rendering', #end 'Visuals and UI', 'Gameplay', 'Misc', 'Mobile Options'];
var options:Array<String> = ['Note Colors', 'Controls', 'Adjust Delay and Combo', 'Graphics', 'Optimization', 'Game Rendering', 'Visuals and UI', 'Gameplay', 'Misc', 'Mobile Options'];
private var grpOptions:FlxTypedGroup<Alphabet>;
private static var curSelected:Int = 0;
public static var menuBG:FlxSprite;
Expand Down Expand Up @@ -62,10 +62,8 @@ class OptionsState extends MusicBeatState
openSubState(new options.GameplaySettingsSubState());
case 'Optimization':
openSubState(new options.OptimizationSubState());
#if !mobile
case 'Game Rendering':
openSubState(new options.GameRendererSettingsSubState());
#end
case 'Adjust Delay and Combo':
LoadingState.loadAndSwitchState(() -> new options.NoteOffsetState());
case 'Misc':
Expand Down
6 changes: 1 addition & 5 deletions source/options/VisualsUISubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,14 @@ class VisualsUISubState extends BaseOptionsMenu
option.changeValue = 0.1;
option.decimals = 1;
addOption(option);

#if !mobile

var option:Option = new Option('FPS Counter',
'If unchecked, hides FPS Counter.',
'showFPS',
'bool',
true);
addOption(option);
option.onChange = onChangeFPSCounter;
#end

var option:Option = new Option('Random Botplay Text',
"Uncheck this if you don't want to be insulted when\nyou use Botplay.",
Expand Down Expand Up @@ -642,11 +640,9 @@ class VisualsUISubState extends BaseOptionsMenu
super.destroy();
}

#if !mobile
function onChangeFPSCounter()
{
if(Main.fpsVar != null)
Main.fpsVar.visible = ClientPrefs.showFPS;
}
#end
}

0 comments on commit dc858d6

Please sign in to comment.