Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

added System.mainLoop() #55

Closed
wants to merge 3 commits into from
Closed

added System.mainLoop() #55

wants to merge 3 commits into from

Conversation

SaturnSH2x2
Copy link

This adds System.mainLoop() to the System module, thereby adding support for sleep mode in LPP-3DS.

@Rinnegatamante
Copy link
Owner

aptMainLoop is already used in the Interpreter main loop: https://github.com/Rinnegatamante/lpp-3ds/blob/master/source/main.cpp#L142 . I suppose 3DS is not expecting this to be called twice. Have you already tried replacing it with a for (;;) loop?

@asiekierka
Copy link

asiekierka commented Apr 17, 2017

@Rinnegatamante aptMainLoop only performs a series of checks and reacts to them if necessary (whether the console wants to enter sleep mode, whether the power button or home button have been pressed, whether the application has been ordered to close by the HOME Menu); therefore, it can be run as many times as you wish, though obviously calling it more than once every X is redundant.

@Rinnegatamante
Copy link
Owner

Yep, that's why i'm suggesting to replace the loop in main.cpp with a standard for (;;) and performing some tests. Don't have a 3DS till 20th of April so can't test personally if the solution works as intended.

@asiekierka
Copy link

asiekierka commented Apr 17, 2017

@Rinnegatamante On first glance, that will work fine as aptMainLoop() is not called anyway during interpreter execution, though you might want to call it manually in the "while (restore==0){" loop where it doesn't seem to be called?

Doing this and adding a System.mainLoop() function should work fine.

@Rinnegatamante
Copy link
Owner

@asiekierka You're right, while restore==0 needs an extra flag to check for main loop but it's not that important for hbs support to sleep mode. the restore part is meant to be executed only when an interpreter error gets on the lua stack (so a critical error in the code or a error() call in the script).

@asiekierka
Copy link

@Rinnegatamante True, but:

(a) I feel supporting sleep mode in every possible part of the application is a good idea, because after all it's a handheld,
(b) Someone might want to try closing the application after an interpreter error using the HOME Menu, especially if the application is a .CIA - not handling aptMainLoop will prevent that from working!

@Rinnegatamante
Copy link
Owner

On an unreleted note:
Something must be done also for audio threads on both luaSound and luaVideo probably. (Quite sure if you resume a multithread application that perform checks only on main thread will cause strange behaviours).

This would require extra tests, probably the best solution is to look into multithread applications that already 100% support sleeping mode (FBI (?)).

@asiekierka
Copy link

asiekierka commented Apr 17, 2017

@Rinnegatamante It did cause strange behaviours for me when I tried to move rendering into a separate thread on the application core in my own homebrew, yes. I haven't looked into them further yet, however.

Sadly, I'm not able to look into this for LPP-3DS - I already have enough homebrew (mostly ports for the time being) on my own plate.

@Rinnegatamante
Copy link
Owner

If rendering code was using GPU (citro3D or similars), it could be related to not properly resetting GPU state. (At least sf2dlib performed such checks by itself iirc, dunno for citro3d).

About audio code, resuming EasyRPG caused audio file handles to become invalid (like if any opened file handle is automatically closed when a sleep is invoked). Since audio code uses a file handle similarly to EasyRPG, probably a solution is to keep track of when a sleep is invoked, keep track of filepath of currently streamed files, add a state on audio threads so that they enter in a infinite loop till a resume is called, when the resume is called, reopen the file handles and properly reset old state for the streams (so libogg pointer, wav pointer, etc...).

@SaturnSH2x2
Copy link
Author

I admittedly hadn't considered multithreading when creating System.mainLoop(). I'll run some tests on it sometime, and see if I can get multithreaded apps (mainly luaVideo and luaSound) to work using this function.

@Rinnegatamante
Copy link
Owner

doesFileExist won't be changed in syntax due to retrocompatibility with original Lua Player, Lua Player HM, lpp-vita, lpp-c++, lpp-plugin.
doesDirExist should be provided for directories checking.
Btw this commit doesn't have nothing to do with this pull so please open a new pull for it.

@SaturnSH2x2
Copy link
Author

Sorry about that; still getting acquainted to GitHub, didn't think future commits would be added to the Pull Request.

I'll revert the syntax when I get the time and add the doesDirExist() function in place of it; might also apply this to RomFS checking.

@Rinnegatamante
Copy link
Owner

You should commit to a different branch everytime you push something to not automatically push it into the pull request too.

@SaturnSH2x2
Copy link
Author

There. Thanks for the suggestion; I'll be developing these things in branches from now on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants