Skip to content

Commit

Permalink
tweaks for enabling / disabling 3d mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedowns committed May 11, 2023
1 parent f580ce2 commit 898ed43
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ public final class EmulationActivity extends AppCompatActivity {
private String mPath;

// LitByLeia
private Boolean mPrevDesiredBacklightState = null;
private Boolean mPrevDesiredBacklightState = false;
private static LeiaSDK mLeiaSDK;

static void InitLeia(Context context) throws Exception {
void InitLeia(Context context) throws Exception {
LeiaSDK.InitArgs initArgs = new LeiaSDK.InitArgs();
initArgs.platform.context = context.getApplicationContext();
initArgs.enableFaceTracking = true;
Expand Down Expand Up @@ -235,17 +235,30 @@ protected void onCreate(Bundle savedInstanceState) {
getWindowManager().getDefaultDisplay().getRotation());
}

void Enable3D(){
public void Enable3D(){
if(mLeiaSDK == null) return;
if(!mLeiaSDK.isInitialized()) return;
mLeiaSDK.enableBacklight(true);
mLeiaSDK.enableFaceTracking(true);
}

void Disable3D(){
public void Disable3D(){
if(mLeiaSDK == null) return;
if(!mLeiaSDK.isInitialized()) return;
mLeiaSDK.enableBacklight(false);
mLeiaSDK.enableFaceTracking(false);
}

void checkShouldToggle3D(Boolean desired_state) {
public void CheckResume3D()
{
if(mPrevDesiredBacklightState){
Enable3D();
} else {
Disable3D();
}
}

public void CheckResume3D(Boolean desired_state) {
if (desired_state) {
Enable3D();
} else {
Expand All @@ -267,12 +280,15 @@ protected void restoreState(Bundle savedInstanceState) {

// If an alert prompt was in progress when state was restored, retry displaying it
NativeLibrary.retryDisplayAlertPrompt();

CheckResume3D();
}

@Override
public void onRestart() {
super.onRestart();
NativeLibrary.ReloadCameraDevices();
CheckResume3D();
}

@Override
Expand All @@ -283,6 +299,7 @@ public void onBackPressed() {
updateSavestateMenuOptions(popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(this::onOptionsItemSelected);
popupMenu.show();
Disable3D();
}

@Override
Expand Down Expand Up @@ -318,6 +335,9 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis

public void onEmulationStarted() {
Toast.makeText(this, getString(R.string.emulation_menu_help), Toast.LENGTH_LONG).show();

mPrevDesiredBacklightState = true;
CheckResume3D();
}

private void enableFullscreenImmersive() {
Expand Down Expand Up @@ -503,6 +523,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

case MENU_ACTION_EXIT:
mEmulationFragment.stopEmulation();
Disable3D();
finish();
break;

Expand Down Expand Up @@ -542,10 +563,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
.setPositiveButton(android.R.string.yes, (dialogInterface, i) ->
{
mEmulationFragment.stopEmulation();
Disable3D();
finish();
})
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> NativeLibrary.UnPauseEmulation())
.setOnCancelListener(dialogInterface -> NativeLibrary.UnPauseEmulation())
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> {
NativeLibrary.UnPauseEmulation();
CheckResume3D();
})
.setOnCancelListener((dialogInterface) -> {
NativeLibrary.UnPauseEmulation();
CheckResume3D();
})
.show();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C

private static SurfaceTexture mPrerenderSurfaceTexture;
private static Surface mPrerenderSurface;
private static LeiaSurfaceView mLeiaSurfaceView;

public static EmulationFragment newInstance(String gamePath) {
Bundle args = new Bundle();
Expand All @@ -64,7 +65,7 @@ public static EmulationFragment newInstance(String gamePath) {
EmulationFragment fragment = new EmulationFragment();
fragment.setArguments(args);

mPrerenderSurfaceTexture = new SurfaceTexture(0);
mPrerenderSurfaceTexture = new SurfaceTexture(false);
mPrerenderSurface = new Surface(mPrerenderSurfaceTexture);

return fragment;
Expand Down Expand Up @@ -106,15 +107,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View contents = inflater.inflate(R.layout.fragment_emulation, container, false);

// Leia Stuff
LeiaSurfaceView surfaceView = contents.findViewById(R.id.surface_emulation);
surfaceView.getHolder().addCallback(this);
mLeiaSurfaceView = contents.findViewById(R.id.surface_emulation);
mLeiaSurfaceView.getHolder().addCallback(this);

float[] identity = new float[16];
Matrix.setIdentityM(identity, 0);

// if i call this i get the following error:
//
surfaceView.addTexture(mPrerenderSurfaceTexture, identity);
mLeiaSurfaceView.addTexture(mPrerenderSurfaceTexture, identity);

mInputOverlay = contents.findViewById(R.id.surface_input_overlay);
mPerfStats = contents.findViewById(R.id.show_fps_text);
Expand All @@ -134,6 +132,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onResume() {
super.onResume();
mLeiaSurfaceView.onResume();
activity.CheckResume3D();


Choreographer.getInstance().postFrameCallback(this);
if (DirectoryInitialization.areCitraDirectoriesReady()) {
mEmulationState.run(activity.isActivityRecreated());
Expand All @@ -144,6 +146,8 @@ public void onResume() {

@Override
public void onPause() {
mLeiaSurfaceView.onPause();
activity.Disable3D();
if (directoryStateReceiver != null) {
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(directoryStateReceiver);
directoryStateReceiver = null;
Expand Down Expand Up @@ -238,6 +242,8 @@ public void updateShowFpsOverlay() {
public void surfaceCreated(SurfaceHolder holder) {
// We purposely don't do anything here.
// All work is done in surfaceChanged, which we are guaranteed to get even for surface creation.

// what do i call here?
}

@Override
Expand All @@ -254,8 +260,8 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// clean up mPreRenderSurface && mPreRenderSurfaceTexture
mPrerenderSurface.release();
mPrerenderSurfaceTexture.release();
//mPrerenderSurface.release();
//mPrerenderSurfaceTexture.release();

mEmulationState.clearSurface();
}
Expand Down

0 comments on commit 898ed43

Please sign in to comment.