乏しい知識でスケルトンコードを書いてみた。まだ未完成だけれど。とりあえずこんな感じでいいのかな。要するにイベントや状態を型で表現するのだね。遷移テーブルは20個がデフォルト(mpl::vectorのデフォルト)らしい。遷移はまだ全然足りないので拡張しないといけないな。でも遷移テーブルが増えるとコンパイル時間がかかるみたいなことが書いてあった。やだなぁ。
#pragma once
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
namespace ShootingGame
{
namespace Event
{
struct Init {};
struct PushStart {};
struct PushSoundEdit {};
struct TimeOut {};
struct Escape {};
}
namespace State
{
struct Init : boost::msm::front::state<>
{
template <class Event, class Fsm>
void on_entry(Event const&, Fsm& ) {};
template <class Event, class Fsm>
void on_exit(Event const&, Fsm& ) {};
};
struct Title : boost::msm::front::state<>
{
template <class Event, class Fsm>
void on_entry(Event const&, Fsm& ) {};
template <class Event, class Fsm>
void on_exit(Event const&, Fsm& ) {};
};
struct Demo : boost::msm::front::state<>
{
template <class Event, class Fsm>
void on_entry(Event const&, Fsm& ) {};
template <class Event, class Fsm>
void on_exit(Event const&, Fsm& ) {};
};
struct Menu : boost::msm::front::state<>
{
template <class Event, class Fsm>
void on_entry(Event const&, Fsm& ) {};
template <class Event, class Fsm>
void on_exit(Event const&, Fsm& ) {};
};
struct Running : boost::msm::front::state<>
{
template <class Event, class Fsm>
void on_entry(Event const&, Fsm& ) {};
template <class Event, class Fsm>
void on_exit(Event const&, Fsm& ) {};
};
struct SoundEdit : boost::msm::front::state<>
{
template <class Event, class Fsm>
void on_entry(Event const&, Fsm& ) {};
template <class Event, class Fsm>
void on_exit(Event const&, Fsm& ) {};
};
struct Exit : boost::msm::front::state<>
{
template <class Event, class Fsm>
void on_entry(Event const&, Fsm& ) {};
template <class Event, class Fsm>
void on_exit(Event const&, Fsm& ) {};
};
}
struct GameState : boost::msm::front::state_machine_def<GameState>
{
typedef State::Init initial_state;
struct trasition_table
: boost::mpl::vector<
_row<State::Init,Event::Init,State::Menu>,
_row<State::Menu,Event::PushStart,State::Running>,
_row<State::Menu,Event::PushSoundEdit,State::SoundEdit>,
_row<State::Menu,Event::TimeOut,State::Demo>,
_row<State::Running,Event::Escape,State::Menu>,
_row<State::SoundEdit,Event::Escape,State::Menu>
>{};
GameState();
~GameState();
private:
};
typedef boost::msm::back::state_machine<GameState> GameStateMachine;
}
このまま続けて大丈夫なのかという不安がよぎる。Boost.MSMって実用的なのだろうか..。