Skip to content

Commit

Permalink
factored out SimOptions, set webgl:false for mobile safari, #289
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jul 23, 2024
1 parent 4ea7154 commit e4545a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 15 additions & 1 deletion js/common/GasPropertiesConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { PanelOptions } from '../../../sun/js/Panel.js';
import gasProperties from '../gasProperties.js';
import GasPropertiesColors from './GasPropertiesColors.js';
import { ScreenOptions } from '../../../joist/js/Screen.js';
import { SimOptions } from '../../../joist/js/Sim.js';
import platform from '../../../phet-core/js/platform.js';

// for all panel-like containers
const PANEL_CORNER_RADIUS = 5;
Expand All @@ -32,6 +34,18 @@ const CREDITS: CreditsData = {
qualityAssurance: 'Jaspe Arias, Jaron Droder, Clifford Hardin, Matthew Moore, Liam Mulhall, Jacob Romero, Nancy Salpepi, Luisa Vargas, Kathryn Woessner'
};

const SIM_OPTIONS: SimOptions = {
phetioDesigned: true,
credits: CREDITS,

// WebGL is typically enabled for high-performance scenery.Sprites, which are used heavily by this sim.
// On iPadOS, the sim consistently crashed when WebGL was enabled, and we were unable to determine why.
// Disabling WebGL uses Canvas as the fallback for Sprites. The problem was not present on iOS, but we
// have no way to differentiate between Safari on iPadOS vs iOS, so WebGL is disabled on both platforms.
// See https://github.com/phetsims/gas-properties/issues/289.
webgl: !platform.mobileSafari
};

const ACCORDION_BOX_OPTIONS: AccordionBoxOptions = {
cornerRadius: PANEL_CORNER_RADIUS,
contentXMargin: PANEL_X_MARGIN,
Expand Down Expand Up @@ -94,7 +108,7 @@ const SCREEN_OPTIONS: Partial<ScreenOptions> = {

const GasPropertiesConstants = {

CREDITS: CREDITS,
SIM_OPTIONS: SIM_OPTIONS,

// margins for all ScreenView instances
SCREEN_VIEW_X_MARGIN: 20,
Expand Down
12 changes: 7 additions & 5 deletions js/gas-properties-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import PreferencesModel from '../../joist/js/preferences/PreferencesModel.js';
import Sim from '../../joist/js/Sim.js';
import Sim, { SimOptions } from '../../joist/js/Sim.js';
import simLauncher from '../../joist/js/simLauncher.js';
import { Utils } from '../../scenery/js/imports.js';
import Tandem from '../../tandem/js/Tandem.js';
Expand All @@ -18,20 +18,20 @@ import EnergyScreen from './energy/EnergyScreen.js';
import ExploreScreen from './explore/ExploreScreen.js';
import GasPropertiesStrings from './GasPropertiesStrings.js';
import IdealScreen from './ideal/IdealScreen.js';
import { combineOptions } from '../../phet-core/js/optionize.js';

simLauncher.launch( () => {

const titleStringProperty = GasPropertiesStrings[ 'gas-properties' ].titleStringProperty;

const screens = [
new IdealScreen( Tandem.ROOT.createTandem( 'idealScreen' ) ),
new ExploreScreen( Tandem.ROOT.createTandem( 'exploreScreen' ) ),
new EnergyScreen( Tandem.ROOT.createTandem( 'energyScreen' ) ),
new DiffusionScreen( Tandem.ROOT.createTandem( 'diffusionScreen' ) )
];

const sim = new Sim( GasPropertiesStrings[ 'gas-properties' ].titleStringProperty, screens, {
phetioDesigned: true,
webgl: true, // Enabled for high-performance Sprites
credits: GasPropertiesConstants.CREDITS,
const options = combineOptions<SimOptions>( {}, GasPropertiesConstants.SIM_OPTIONS, {
preferencesModel: new PreferencesModel( {
visualOptions: {
supportsProjectorMode: true
Expand All @@ -44,6 +44,8 @@ simLauncher.launch( () => {
} )
} );

const sim = new Sim( titleStringProperty, screens, options );

// Log whether we're using WebGL, which is the preferred rendering option for Sprites
phet.log && phet.log( `using WebGL = ${phet.chipper.queryParameters.webgl && Utils.isWebGLSupported}` );

Expand Down

0 comments on commit e4545a3

Please sign in to comment.