Skip to content

Commit

Permalink
add "step" method as an alternative to state_processing and state_phy…
Browse files Browse the repository at this point in the history
…sics_processing
  • Loading branch information
uzkbwza authored and derkork committed Sep 27, 2023
1 parent 748a100 commit 868489e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions addons/godot_state_charts/compound_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func _state_enter(expect_transition:bool = false):
else:
push_error("No initial state set for state '" + name + "'.")

func _state_step():
super._state_step()
if _active_state != null:
_active_state._state_step()

func _state_save(saved_state:SavedState, child_levels:int = -1):
super._state_save(saved_state, child_levels)
Expand Down
6 changes: 5 additions & 1 deletion addons/godot_state_charts/parallel_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func _state_exit():
child._state_exit()

super._state_exit()


func _state_step():
super._state_step()
for child in _sub_states:
child._state_step()

func _state_event(event:StringName) -> bool:
if not active:
Expand Down
6 changes: 6 additions & 0 deletions addons/godot_state_charts/state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ signal state_processing(delta:float)
## Called when the state is physics processing.
signal state_physics_processing(delta:float)

## Called when the state chart step function is called.
signal state_stepped()

## Called when the state is receiving input.
signal state_input(event:InputEvent)

Expand Down Expand Up @@ -218,6 +221,9 @@ func _physics_process(delta:float):
return
state_physics_processing.emit(delta)

## Called when the state chart step function is called.
func _state_step():
state_stepped.emit()

func _input(event:InputEvent):
state_input.emit(event)
Expand Down
4 changes: 4 additions & 0 deletions addons/godot_state_charts/state_chart.gd
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func _warn_not_active(transition:Transition, source:State):
func set_expression_property(name:StringName, value) -> void:
_expression_properties[name] = value

## Calls the `step` function in all active states. Used for situations where `state_processing` and
## `state_physics_processing` don't make sense (e.g. turn-based games, or games with a fixed timestep).
func step():
_state._state_step()

func _get_configuration_warnings() -> PackedStringArray:
var warnings = []
Expand Down

0 comments on commit 868489e

Please sign in to comment.