rnd(M03): add rendered ground query facade
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
class_name RenderedGroundSample
|
||||
extends RefCounted
|
||||
|
||||
## Immutable result of sampling currently loaded render terrain in Godot world units.
|
||||
## This diagnostic value is renderer-owned and is not authoritative gameplay collision.
|
||||
|
||||
var is_available: bool:
|
||||
get:
|
||||
return _is_available
|
||||
|
||||
var height_units: float:
|
||||
get:
|
||||
return _height_units
|
||||
|
||||
var failure_code: StringName:
|
||||
get:
|
||||
return _failure_code
|
||||
|
||||
var _is_available: bool
|
||||
var _height_units: float
|
||||
var _failure_code: StringName
|
||||
|
||||
|
||||
## Creates an available finite rendered-ground sample in Godot world units.
|
||||
static func available(height_units_value: float) -> RenderedGroundSample:
|
||||
return RenderedGroundSample.new(true, height_units_value, &"")
|
||||
|
||||
|
||||
## Creates an unavailable rendered-ground sample with a stable failure code.
|
||||
static func unavailable(failure_code_value: StringName) -> RenderedGroundSample:
|
||||
return RenderedGroundSample.new(false, 0.0, failure_code_value)
|
||||
|
||||
|
||||
func _init(
|
||||
is_available_value: bool,
|
||||
height_units_value: float,
|
||||
failure_code_value: StringName
|
||||
) -> void:
|
||||
_is_available = is_available_value and is_finite(height_units_value)
|
||||
_height_units = height_units_value if _is_available else 0.0
|
||||
if _is_available:
|
||||
_failure_code = &""
|
||||
elif not is_finite(height_units_value):
|
||||
_failure_code = &"render_terrain_height_not_finite"
|
||||
else:
|
||||
_failure_code = (
|
||||
failure_code_value
|
||||
if not failure_code_value.is_empty()
|
||||
else &"render_terrain_unavailable"
|
||||
)
|
||||
Reference in New Issue
Block a user