public GameState CreateSubState(string state_name, string sink_name, string parent_name) { GameStateMachine.GameStateSink sink = this.FindSink(sink_name); GameState result; if (sink == null) { result = null; } else { GameState parent_state = this.FindState(parent_name); if (parent_state == null) { result = null; } else { if (this.m_free_state_id_list.Count != 0) { uint id = this.m_free_state_id_list[0]; result = this.CreateStateImpl(id, state_name, sink.id, StateComposeType.SCT_SUB, parent_state.GetId()); } else { result = null; } } } return(result); }
private GameState CreateStateImpl(uint state_id, string state_name, ushort sink_id, StateComposeType com_type, uint parent_id) { GameState state = null; GameStateMachine.GameStateSink sink = FindSink(sink_id); if (sink != null && state_id < STATE_ID_CAPACITY && m_state_array[(int)state_id] == null) { if (com_type == StateComposeType.SCT_COMPOSE || com_type == StateComposeType.SCT_NORMAL) { state = new GameState(this, state_id, state_name, sink_id, com_type); sink.contain_state_id_list.Add(state_id); } else if (com_type == StateComposeType.SCT_SUB) { GameState parent_state = this.FindState(parent_id); if (parent_state != null && parent_state.GetComposeType() == StateComposeType.SCT_COMPOSE && parent_state.GetSinkId() == sink_id) { state = new GameState(this, state_id, state_name, sink_id, com_type); state.m_parent_state_id = parent_id; parent_state.m_sub_state_id_list.Add(state_id); } } if (state != null) { this.m_state_array[(int)state_id] = state; this.m_free_state_id_list.Remove(state_id); } } return(state); }
public ushort GetSinkIdFromName(string name) { GameStateMachine.GameStateSink sink = FindSink(name); ushort result = ushort.MaxValue; if (sink != null) { result = sink.id; } return(result); }
public string GetSinkNameFromId(ushort sink_id) { string tmp_name = ""; GameStateMachine.GameStateSink sink = this.FindSink(sink_id); if (sink != null) { tmp_name = sink.sink_name; } return(tmp_name); }
public uint GetSinkRunState(ushort sink_id) { uint find_id = ushort.MaxValue; GameStateMachine.GameStateSink sink = this.FindSink(sink_id); if (sink != null) { find_id = sink.cur_state_id; } return(find_id); }
private GameStateMachine.GameStateSink FindSink(ushort sink_id) { GameStateMachine.GameStateSink sink = null; if (sink_id != ushort.MaxValue) { if (this.m_state_sink_array.Count >= 0) { sink = this.m_state_sink_array[(int)sink_id]; } } return(sink); }
private GameStateMachine.GameStateSink FindSink(string name) { GameStateMachine.GameStateSink sink = null; for (int i = 0; i < this.m_state_sink_array.Count; i++) { if (this.m_state_sink_array[i] != null && this.m_state_sink_array[i].sink_name == name) { sink = this.m_state_sink_array[i]; break; } } return(sink); }
public GameState CreateNormalState(string state_name, string sink_name) { GameStateMachine.GameStateSink sink = FindSink(sink_name); if (sink != null) { if (m_free_state_id_list.Count > 0) { uint state_id = m_free_state_id_list[0]; return(this.CreateStateImpl(state_id, state_name, sink.id, StateComposeType.SCT_NORMAL, ushort.MaxValue)); } } return(null); }
public void SinkToNullState(ushort sink_id) { GameStateMachine.GameStateSink sink = this.FindSink(sink_id); if (sink != null) { sink.previous_state_id = sink.cur_state_id; GameState state = this.FindState(sink.cur_state_id); if (state != null) { state.Exit(); } sink.cur_state_id = ushort.MaxValue; } }
public void UpdateNow(float elapse_time) { for (int i = 0; i < m_state_sink_array.Count; i++) { GameStateMachine.GameStateSink sink = m_state_sink_array[i]; if (sink != null) { GameState state = FindState(sink.cur_state_id); if (state != null) { state.Excute(elapse_time); } } } }
public GameState CreateComposeState(string state_name, string sink_name) { GameStateMachine.GameStateSink sink = FindSink(sink_name); GameState result = null; if (sink != null) { if (m_free_state_id_list.Count > 0) { uint id = m_free_state_id_list[0]; result = CreateStateImpl(id, state_name, sink.id, StateComposeType.SCT_COMPOSE, ushort.MaxValue); } } return(result); }
private bool CreateSinkImpl(ushort sink_id, string sink_name) { if (sink_id < SINK_ID_CAPACITY && this.m_state_sink_array[(int)sink_id] == null) { GameStateMachine.GameStateSink sink = new GameStateMachine.GameStateSink(); sink.id = sink_id; sink.sink_name = sink_name; sink.cur_state_id = ushort.MaxValue; sink.previous_state_id = ushort.MaxValue; this.m_state_sink_array[(int)sink_id] = sink; this.m_free_sink_id_list.Remove(sink_id); return(true); } return(false); }
public bool ChangeStateTest(uint state_id, bool ignore_state_lock) { GameState state = this.FindState(state_id); if (state != null) { if (this.IsInState(state_id)) { return(state.IsStateReEnter()); } GameStateMachine.GameStateSink sink = this.FindSink(state.GetSinkId()); GameState cur_sink_state = this.FindState(sink.cur_state_id); if (cur_sink_state != null && cur_sink_state.IsStateLock() && !ignore_state_lock) { return(false); } if (state.GetComposeType() == StateComposeType.SCT_SUB) { GameState parent_state = this.FindState(state.m_parent_state_id); if (this.IsInState(parent_state.GetId())) { if (state.CanChangeFromState(parent_state.m_cur_run_sub)) { return(true); } } else { if (parent_state.CanChangeFromState(sink.cur_state_id)) { return(true); } } } else { if (state.CanChangeFromState(sink.cur_state_id)) { return(true); } } } return(false); }
public void DestroyState(uint state_id) { GameState state = this.FindState(state_id); if (state != null) { GameStateMachine.GameStateSink sink = this.FindSink(state.GetSinkId()); uint cur_run_state_id = sink.cur_state_id; sink.contain_state_id_list.Remove(state_id); bool need_cancel_cur_state = false; if (this.IsInState(state_id)) { state.Exit(); need_cancel_cur_state = true; } if (state.GetComposeType() == StateComposeType.SCT_SUB) { GameState parent_state = this.FindState(state.m_parent_state_id); if (need_cancel_cur_state) { parent_state.m_cur_run_sub = ushort.MaxValue; parent_state.m_previous_sub = ushort.MaxValue; } parent_state.m_sub_state_id_list.Remove(state_id); } else { sink.contain_state_id_list.Remove(state_id); if (need_cancel_cur_state) { sink.cur_state_id = ushort.MaxValue; sink.previous_state_id = ushort.MaxValue; } if (state.GetComposeType() == StateComposeType.SCT_COMPOSE) { state.DestroyAllSubStates(); } } state.Dispose(); this.m_state_array[(int)state_id] = null; this.m_free_state_id_list.Add(state_id); } }
public bool IsInState(uint state_id) { bool is_in_state = false; GameState state = FindState(state_id); if (state != null) { GameStateMachine.GameStateSink sink = FindSink(state.GetSinkId()); if (state.GetComposeType() == StateComposeType.SCT_SUB) { GameState parent_state = FindState(state.m_parent_state_id); if (parent_state != null && parent_state.GetId() == sink.cur_state_id) { is_in_state = (parent_state.m_cur_run_sub == state_id); } } else { is_in_state = (sink.cur_state_id == state_id); } } return(is_in_state); }
public bool ChangeStateForce(uint state_id) { GameState state = this.FindState(state_id); bool result = true; if (state != null) { if (IsInState(state_id)) { if (state.IsStateReEnter()) { state.Exit(); state.Enter(); } else { result = false; } } else { GameStateMachine.GameStateSink sink = FindSink(state.GetSinkId()); GameState cur_sink_state = FindState(sink.cur_state_id); if (state.GetComposeType() == StateComposeType.SCT_SUB) { GameState parent_state = this.FindState(state.m_parent_state_id); if (this.IsInState(parent_state.GetId())) { GameState cur_run_state = this.FindState(parent_state.m_cur_run_sub); if (cur_run_state != null) { cur_run_state.Exit(); } parent_state.m_previous_sub = parent_state.m_cur_run_sub; parent_state.m_cur_run_sub = state_id; state.Enter(); } else { parent_state.m_previous_sub = parent_state.m_cur_run_sub; parent_state.m_cur_run_sub = state_id; sink.previous_state_id = sink.cur_state_id; sink.cur_state_id = parent_state.GetId(); if (cur_sink_state != null) { cur_sink_state.Exit(); } if (parent_state != null) { parent_state.Enter(); } } } else { sink.previous_state_id = sink.cur_state_id; sink.cur_state_id = state_id; if (cur_sink_state != null) { cur_sink_state.Exit(); } state.Enter(); } } } else { result = false; } return(result); }