Optimize PortMaster low-memory profile
This commit is contained in:
parent
b27883d115
commit
021de5aca4
16 changed files with 327 additions and 31 deletions
|
|
@ -12,10 +12,24 @@ const SILENT_VOLUME_DB: float = -60.0
|
|||
var _weather_service: WorldWeatherService
|
||||
var _fade_tween: Tween
|
||||
var _is_active: bool = false
|
||||
var _audio_enabled: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
bus = &"Environment"
|
||||
volume_db = SILENT_VOLUME_DB
|
||||
|
||||
|
||||
func set_audio_enabled(enabled: bool) -> void:
|
||||
if _audio_enabled == enabled:
|
||||
return
|
||||
_audio_enabled = enabled
|
||||
if not _audio_enabled:
|
||||
_silence_immediately()
|
||||
stream = null
|
||||
return
|
||||
if not ResourceLoader.exists(RAIN_STREAM_PATH, "AudioStreamOggVorbis"):
|
||||
return
|
||||
var rain_stream := load(RAIN_STREAM_PATH) as AudioStreamOggVorbis
|
||||
var runtime_stream := (
|
||||
rain_stream.duplicate() as AudioStreamOggVorbis
|
||||
|
|
@ -25,7 +39,10 @@ func _ready() -> void:
|
|||
if runtime_stream != null:
|
||||
runtime_stream.loop = true
|
||||
stream = runtime_stream
|
||||
volume_db = SILENT_VOLUME_DB
|
||||
if _is_active:
|
||||
_transition_to_rain(
|
||||
_weather_service != null and _weather_service.is_raining()
|
||||
)
|
||||
|
||||
|
||||
func configure(weather_service: WorldWeatherService) -> void:
|
||||
|
|
@ -53,6 +70,8 @@ func set_active(active: bool) -> void:
|
|||
if not active:
|
||||
_silence_immediately()
|
||||
return
|
||||
if not _audio_enabled:
|
||||
return
|
||||
_transition_to_rain(
|
||||
_weather_service != null and _weather_service.is_raining()
|
||||
)
|
||||
|
|
@ -66,7 +85,7 @@ func _on_weather_changed(
|
|||
|
||||
|
||||
func _transition_to_rain(is_raining: bool) -> void:
|
||||
if not _is_active:
|
||||
if not _is_active or not _audio_enabled:
|
||||
return
|
||||
_stop_fade()
|
||||
if is_raining:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
class_name ShorelineAmbience
|
||||
extends Node
|
||||
|
||||
const WAVES_STREAM_PATH: String = "res://audio/ambience/waves.wav"
|
||||
|
||||
@export_range(0.0, 20.0, 0.1) var near_distance: float = 2.0
|
||||
@export_range(1.0, 100.0, 0.5) var far_distance: float = 24.0
|
||||
@export_range(-40.0, 12.0, 0.5) var near_volume_db: float = 1.0
|
||||
|
|
@ -15,15 +17,37 @@ var _shoreline_segments: Array[PackedVector2Array] = []
|
|||
var _distance_update_remaining: float = 0.0
|
||||
var _target_volume_db: float = -80.0
|
||||
var _is_active := false
|
||||
var _audio_enabled: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_waves_audio.bus = &"Environment"
|
||||
_configure_audio_loop(_waves_audio.stream)
|
||||
_waves_audio.stream = null
|
||||
_waves_audio.volume_db = -80.0
|
||||
set_process(false)
|
||||
|
||||
|
||||
func set_audio_enabled(enabled: bool) -> void:
|
||||
if _audio_enabled == enabled:
|
||||
return
|
||||
_audio_enabled = enabled
|
||||
if not _audio_enabled:
|
||||
_waves_audio.stop()
|
||||
_waves_audio.stream = null
|
||||
set_process(false)
|
||||
return
|
||||
if not ResourceLoader.exists(WAVES_STREAM_PATH, "AudioStream"):
|
||||
return
|
||||
_waves_audio.stream = load(WAVES_STREAM_PATH) as AudioStream
|
||||
_configure_audio_loop(_waves_audio.stream)
|
||||
if _is_active:
|
||||
set_process(true)
|
||||
_update_target_volume()
|
||||
_waves_audio.volume_db = _target_volume_db
|
||||
if _waves_audio.stream != null:
|
||||
_waves_audio.play()
|
||||
|
||||
|
||||
func configure(listener: Node3D, shoreline_mesh: MeshInstance3D) -> void:
|
||||
_listener = listener
|
||||
_shoreline_segments = _extract_shoreline_segments(shoreline_mesh)
|
||||
|
|
@ -34,8 +58,10 @@ func configure(listener: Node3D, shoreline_mesh: MeshInstance3D) -> void:
|
|||
|
||||
func set_active(active: bool) -> void:
|
||||
_is_active = active
|
||||
set_process(active)
|
||||
set_process(active and _audio_enabled)
|
||||
if active:
|
||||
if not _audio_enabled:
|
||||
return
|
||||
_distance_update_remaining = 0.0
|
||||
_update_target_volume()
|
||||
_waves_audio.volume_db = _target_volume_db
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ const RAIN_VISIBILITY_AABB := AABB(
|
|||
Vector3(27.0, 12.0, 27.0),
|
||||
)
|
||||
const RAIN_PARTICLE_AMOUNT: int = 2240
|
||||
const LIGHT_RAIN_PARTICLE_AMOUNT: int = 128
|
||||
const LIGHT_RAIN_FIXED_FPS: int = 12
|
||||
const LIGHT_RAIN_PARTICLE_AMOUNT: int = 48
|
||||
const LIGHT_RAIN_FIXED_FPS: int = 8
|
||||
const RAIN_VELOCITY_MIN: float = 16.0
|
||||
const RAIN_VELOCITY_MAX: float = 20.0
|
||||
const RAIN_DROP_SIZE := Vector3(0.014, 0.34, 0.014)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue