feat: add Android host weather runtime facade

This commit is contained in:
OpenAI Codex
2026-09-07 10:43:11 +08:00
parent faf7548220
commit a81b464d9b
26 changed files with 614 additions and 46 deletions

View File

@@ -14,6 +14,7 @@ import org.maplibre.android.geometry.LatLngBounds
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.Style
import org.maplibre.android.maps.WeatherRuntime
import org.maplibre.android.style.layers.PaintPropertyValue
import org.maplibre.android.testapp.R
@@ -47,6 +48,7 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
// Display mirror only; Core remains the playback state authority.
private var timelineState = "NOT READY"
private var timelineSpeed = "1x"
private var weatherRuntime: WeatherRuntime? = null
override fun onCreate(savedInstanceState: Bundle?) {
active = savedInstanceState?.getBoolean(STATE_ACTIVE, true) ?: true
@@ -355,7 +357,14 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
private fun controlTimeline(command: Int, value: Float) {
if (!styleReady || !enabled || !timeWindowMode) { Log.i(TAG, "ParticleTimeline: event=REJECTED reason=STYLE_NOT_READY"); return }
if (!maplibreMap.controlRasterArraySourceTimeline(PARTICLE_SOURCE_ID, command, value)) {
val runtime = weatherRuntime
val accepted = when (command) {
0 -> runtime?.setPlaybackState(WeatherRuntime.PlaybackState.PLAY)
1 -> runtime?.setPlaybackState(WeatherRuntime.PlaybackState.PAUSE)
2 -> when (value) { 0.5f -> runtime?.setPlaybackSpeed(WeatherRuntime.PlaybackSpeed.HALF); 1.0f -> runtime?.setPlaybackSpeed(WeatherRuntime.PlaybackSpeed.NORMAL); 2.0f -> runtime?.setPlaybackSpeed(WeatherRuntime.PlaybackSpeed.DOUBLE); else -> null }
else -> null // Existing fixture-only diagnostic commands remain outside the REAL WEATHER Host facade.
}
if (accepted != WeatherRuntime.CommandResult.ACCEPTED && (runtime == null || !maplibreMap.controlRasterArraySourceTimeline(PARTICLE_SOURCE_ID, command, value))) {
Log.i(TAG, "ParticleTimeline: event=REJECTED command=$command")
} else {
timelineState = when (command) { 0 -> "PLAY"; 1 -> "PAUSE"; 6 -> "WAIT"; 7 -> "INVALID"; 8 -> "PAUSE"; else -> timelineState }
@@ -417,6 +426,11 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
Log.i(TAG, "ParticleGPU: event=STYLE_LOAD epoch=$styleLoadEpoch reason=$reason")
maplibreMap.setStyle(Style.Builder().fromJson(validationStyle(active, enabled, reason))) {
styleReady = true
if (realWeatherMode) {
weatherRuntime = WeatherRuntime(maplibreMap, WeatherRuntime.Config(PARTICLE_SOURCE_ID, WEATHER_COLOR_LAYER_ID, PARTICLE_LAYER_ID))
} else {
weatherRuntime = null
}
if (hostSubmissionMode) {
if (realWeatherMode) submitRealWeatherDataset() else submitHostValidationDataset()
} else if (timeWindowMode) {
@@ -461,7 +475,7 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
return
}
Log.i(TAG, "ParticleGPU: event=MIX_PROPERTY_REQUEST value=$requestedTimeMix styleEpoch=$styleLoadEpoch")
if (!maplibreMap.setStyleLayerFloatProperty(PARTICLE_LAYER_ID, "raster-particle-time-mix", requestedTimeMix)) {
if (!setParticleFloat("raster-particle-time-mix", requestedTimeMix)) {
Log.i(TAG, "ParticleGPU: event=MIX_REJECTED reason=CORE_LAYER_NOT_FOUND styleEpoch=$styleLoadEpoch")
return
}
@@ -480,12 +494,7 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
return
}
Log.i(TAG, "ParticleGPU: event=PARTICLE_COUNT_REQUEST requestedParticleCount=$requestedParticleCount styleEpoch=$styleLoadEpoch")
if (!maplibreMap.setStyleLayerFloatProperty(
PARTICLE_LAYER_ID,
"raster-particle-particle-count",
requestedParticleCount.toFloat()
)
) {
if (!setParticleFloat("raster-particle-particle-count", requestedParticleCount.toFloat())) {
Log.i(TAG, "ParticleGPU: event=PARTICLE_COUNT_REJECTED reason=CORE_PROPERTY_REJECTED requestedParticleCount=$requestedParticleCount styleEpoch=$styleLoadEpoch")
return
}
@@ -500,7 +509,7 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
return
}
Log.i(TAG, "ParticleGPU: event=VISUAL_PROPERTY_REQUEST property=$property value=$requested styleEpoch=$styleLoadEpoch")
if (!maplibreMap.setStyleLayerFloatProperty(PARTICLE_LAYER_ID, property, requested)) {
if (!setParticleFloat(property, requested)) {
Log.i(TAG, "ParticleGPU: event=VISUAL_PROPERTY_REJECTED reason=CORE_PROPERTY_REJECTED property=$property styleEpoch=$styleLoadEpoch")
return
}
@@ -515,7 +524,7 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
return
}
val value = if (requested) 1.0f else 0.0f
if (!maplibreMap.setStyleLayerFloatProperty(PARTICLE_LAYER_ID, "raster-particle-speed-color-enabled", value)) {
if (!setParticleFloat("raster-particle-speed-color-enabled", value)) {
Log.i(TAG, "ParticleGPU: event=VISUAL_PROPERTY_REJECTED reason=CORE_PROPERTY_REJECTED property=raster-particle-speed-color-enabled styleEpoch=$styleLoadEpoch")
return
}
@@ -524,6 +533,11 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
Log.i(TAG, "ParticleGPU: event=VISUAL_PROPERTY_ONLY property=raster-particle-speed-color-enabled value=$value styleEpoch=$styleLoadEpoch")
}
private fun setParticleFloat(property: String, value: Float): Boolean {
return weatherRuntime?.setParticleVisual(property, value) == WeatherRuntime.CommandResult.ACCEPTED ||
(weatherRuntime == null && maplibreMap.setStyleLayerFloatProperty(PARTICLE_LAYER_ID, property, value))
}
private fun resetVisualDefaults() {
setVisualFloat("raster-particle-line-width", DEFAULT_LINE_WIDTH) { lineWidth = DEFAULT_LINE_WIDTH }
setVisualFloat("raster-particle-particle-length", DEFAULT_PARTICLE_LENGTH) { particleLength = DEFAULT_PARTICLE_LENGTH }
@@ -589,7 +603,7 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
val metadata = assets.open(metadataPath).bufferedReader().use { it.readText() }
val payload = assets.open(payloadPath).use { it.readBytes() }
Log.i(TAG, "ParticleField: event=REAL_WEATHER_DATASET_LOAD index=$index metadata=$metadataPath payloadBytes=${payload.size}")
maplibreMap.submitRasterArraySourceHostField(PARTICLE_SOURCE_ID, metadata, payload)
weatherRuntime?.submitWindField(metadata, payload)?.getCode() ?: MapLibreMap.HOST_FIELD_REJECTED_SOURCE_MODE
} catch (error: Exception) {
Log.e(TAG, "ParticleField: event=REAL_WEATHER_SUBMIT_REJECTED index=$index reason=ASSET_READ_FAILED", error)
MapLibreMap.HOST_FIELD_REJECTED_ADAPTER
@@ -806,6 +820,7 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
private const val STATE_HOST_SUBMISSION = "particle_validation.host_submission"
private const val STATE_REAL_WEATHER = "particle_validation.real_weather"
private const val PARTICLE_LAYER_ID = "particle-raster-core"
private const val WEATHER_COLOR_LAYER_ID = "weather-color-real"
private const val PARTICLE_SOURCE_ID = "particle-fixture"
private const val MASK_GLOBAL = 0
private const val MASK_OCEAN_A = 1