Skip to content

Commit

Permalink
Add mobile-optimized settings and controls
Browse files Browse the repository at this point in the history
The TPS demo can now run on mobile devices. Basic touch controls are provided.

When running on a mobile device, the settings menu no longer lists options
that have no effect when using the Mobile rendering method. Default settings
have also been optimized for mobile if running on a mobile device.
  • Loading branch information
Calinou committed Dec 6, 2023
1 parent 241b450 commit 0901fc0
Show file tree
Hide file tree
Showing 3 changed files with 342 additions and 250 deletions.
11 changes: 11 additions & 0 deletions menu/menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ func _ready():
]:
_make_button_group(menu)

if Settings.is_mobile:
# Hide settings that are not effective or relevant on mobile platforms.
for menu in [
display_mode_menu, vsync_menu, scale_filter_menu, taa_menu, gi_type_menu, gi_quality_menu,
ssao_menu, ssil_menu, volumetric_fog_menu,
]:
menu.visible = false

# Mobile GPUs only support MSAA up to 4×.
msaa_8x.visible = false

func _process(_delta):
if loading.visible:
var progress = []
Expand Down
25 changes: 13 additions & 12 deletions menu/settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,32 @@ enum GIQuality {

const CONFIG_FILE_PATH = "user://settings.ini"

const DEFAULTS = {
var is_mobile := OS.has_feature("mobile")

var defaults := {
video = {
display_mode = Window.MODE_EXCLUSIVE_FULLSCREEN,
vsync = DisplayServer.VSYNC_ENABLED,
max_fps = 0,
resolution_scale = 1.0,
scale_filter = Viewport.SCALING_3D_MODE_FSR2,
max_fps = 0 if not is_mobile else 30, # Cap to 30 FPS on mobile to ensure consistency and reduce power consumption
resolution_scale = 1.0 if not is_mobile else 0.5, # Native on desktop, Performance on mobile
scale_filter = Viewport.SCALING_3D_MODE_FSR2 if not is_mobile else Viewport.SCALING_3D_MODE_BILINEAR,
},
rendering = {
taa = false,
msaa = Viewport.MSAA_DISABLED,
fxaa = false,
fxaa = is_mobile,
shadow_mapping = true,
gi_type = GIType.VOXEL_GI,
gi_quality = GIQuality.LOW,
ssao_quality = RenderingServer.ENV_SSAO_QUALITY_MEDIUM,
gi_quality = GIQuality.LOW if not is_mobile else GIQuality.DISABLED,
ssao_quality = RenderingServer.ENV_SSAO_QUALITY_MEDIUM if not is_mobile else -1, # Disabled on mobile
ssil_quality = -1, # Disabled
bloom = true,
volumetric_fog = true,
volumetric_fog = not is_mobile,
},
}

var config_file := ConfigFile.new()


func _ready():
load_settings()

Expand All @@ -53,10 +54,10 @@ func load_settings():
config_file.load(CONFIG_FILE_PATH)
# Initialize defaults for values not found in the existing configuration file,
# so we don't have to specify them every time we use `ConfigFile.get_value()`.
for section in DEFAULTS:
for key in DEFAULTS[section]:
for section in defaults:
for key in defaults[section]:
if not config_file.has_section_key(section, key):
config_file.set_value(section, key, DEFAULTS[section][key])
config_file.set_value(section, key, defaults[section][key])


func save_settings():
Expand Down
Loading

0 comments on commit 0901fc0

Please sign in to comment.