在对应的.Build.cs文件中加入:
PublicSystemIncludePaths.AddRange(new string[] { @"D:\DevTools\boost_1_72_0" });
PublicSystemLibraryPaths.AddRange(new string[] { @"D:\DevTools\boost_1_72_0\stage\lib" });
然后在需要使用THIRD_PARTY_INCLUDES_START、THIRD_PARTY_INCLUDES_END这一对宏包围Boost头文件。根据需要可能需要#undef check宏。以下以使用boost元状态机为例:
THIRD_PARTY_INCLUDES_START
#pragma push_macro("check")
#undef check
// back-end
#include
//front-end
#include
#pragma pop_macro("check")
THIRD_PARTY_INCLUDES_END
最后把样例中与控制台相关的输出改成虚幻的UE_LOG即可:
namespace msm = boost::msm;
namespace mpl = boost::mpl;
namespace
{
// events
struct play {};
struct end_pause {};
struct stop {};
struct pause {};
struct open_close {};
// A "complicated" event type that carries some data.
enum DiskTypeEnum
{
DISK_CD = 0,
DISK_DVD = 1
};
struct cd_detected
{
cd_detected(FString name, DiskTypeEnum diskType)
: name(name),
disc_type(diskType)
{}
FString name;
DiskTypeEnum disc_type;
};
// front-end: define the FSM structure
struct player_ : public msm::front::state_machine_def
{
template
void on_entry(Event const&, FSM&)
{
UE_LOG(LogTemp, Warning, TEXT("entering: Player"));
}
template
void on_exit(Event const&, FSM&)
{
UE_LOG(LogTemp, Warning, TEXT("leaving: Player"));
}
// The list of FSM states
struct Empty : public msm::front::state<>
{
// every (optional) entry/exit methods get the event passed.
template
void on_entry(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("entering: Empty")); }
template
void on_exit(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("leaving: Empty")); }
};
struct Open : public msm::front::state<>
{
template
void on_entry(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("entering: Open")); }
template
void on_exit(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("leaving: Open")); }
};
// sm_ptr still supported but deprecated as functors are a much better way to do the same thing
struct Stopped : public msm::front::state
{
template
void on_entry(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("entering: Stopped")); }
template
void on_exit(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("leaving: Stopped")); }
void set_sm_ptr(player_* pl)
{
m_player = pl;
}
player_* m_player;
};
struct Playing : public msm::front::state<>
{
template
void on_entry(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("entering: Playing")); }
template
void on_exit(Event const&, FSM&) { UE_LOG(LogTemp, Warning,TEXT("leaving: Playing")); }
};
// state not defining any entry or exit
struct Paused : public msm::front::state<>
{
};
// the initial state of the player SM. Must be defined
typedef Empty initial_state;
// transition actions
void start_playback(play const&) { UE_LOG(LogTemp, Warning,TEXT("player::start_playback")); }
void open_drawer(open_close const&) { UE_LOG(LogTemp, Warning,TEXT("player::open_drawer")); }
void close_drawer(open_close const&) { UE_LOG(LogTemp, Warning,TEXT("player::close_drawer")); }
void store_cd_info(cd_detected const&) { UE_LOG(LogTemp, Warning,TEXT("player::store_cd_info")); }
void stop_playback(stop const&) { UE_LOG(LogTemp, Warning,TEXT("player::stop_playback")); }
void pause_playback(pause const&) { UE_LOG(LogTemp, Warning,TEXT("player::pause_playback")); }
void resume_playback(end_pause const&) { UE_LOG(LogTemp, Warning,TEXT("player::resume_playback")); }
void stop_and_open(open_close const&) { UE_LOG(LogTemp, Warning,TEXT("player::stop_and_open")); }
void stopped_again(stop const&) { UE_LOG(LogTemp, Warning,TEXT("player::stopped_again")); }
// guard conditions
bool good_disk_format(cd_detected const& evt)
{
// to test a guard condition, let's say we understand only CDs, not DVD
if (evt.disc_type != DISK_CD)
{
UE_LOG(LogTemp, Warning,TEXT("wrong disk, sorry"));
return false;
}
return true;
}
// used to show a transition conflict. This guard will simply deactivate one transition and thus
// solve the conflict
bool auto_start(cd_detected const&)
{
return false;
}
typedef player_ p; // makes transition table cleaner
// Transition table for player
struct transition_table : mpl::vector<
// Start Event Next Action Guard
// +---------+-------------+---------+---------------------+----------------------+
a_row < Stopped, play, Playing, &p::start_playback >,
a_row < Stopped, open_close, Open, &p::open_drawer >,
_row < Stopped, stop, Stopped >,
// +---------+-------------+---------+---------------------+----------------------+
a_row < Open, open_close, Empty, &p::close_drawer >,
// +---------+-------------+---------+---------------------+----------------------+
a_row < Empty, open_close, Open, &p::open_drawer >,
row < Empty, cd_detected, Stopped, &p::store_cd_info, &p::good_disk_format >,
row < Empty, cd_detected, Playing, &p::store_cd_info, &p::auto_start >,
// +---------+-------------+---------+---------------------+----------------------+
a_row < Playing, stop, Stopped, &p::stop_playback >,
a_row < Playing, pause, Paused, &p::pause_playback >,
a_row < Playing, open_close, Open, &p::stop_and_open >,
// +---------+-------------+---------+---------------------+----------------------+
a_row < Paused, end_pause, Playing, &p::resume_playback >,
a_row < Paused, stop, Stopped, &p::stop_playback >,
a_row < Paused, open_close, Open, &p::stop_and_open >
// +---------+-------------+---------+---------------------+----------------------+
> {};
// Replaces the default no-transition response.
template
void no_transition(Event const& e, FSM&, int state)
{
//UE_LOG(LogTemp, Warning,TEXT("no transition from state %d on event %s") ,e, typeid(e).name());
}
};
// Pick a back-end
typedef msm::back::state_machine player;
//
// Testing utilities.
//
static char const* const state_names[] = { "Stopped", "Open", "Empty", "Playing", "Paused" };
void pstate(player const& p)
{
UE_LOG(LogTemp, Warning, TEXT(" -> %s"), state_names[p.current_state()[0]]);
}
void test()
{
player p;
// needed to start the highest-level SM. This will call on_entry and mark the start of the SM
p.start();
// go to Open, call on_exit on Empty, then action, then on_entry on Open
p.process_event(open_close()); pstate(p);
p.process_event(open_close()); pstate(p);
// will be rejected, wrong disk type
p.process_event(
cd_detected("louie, louie", DISK_DVD)); pstate(p);
p.process_event(
cd_detected("louie, louie", DISK_CD)); pstate(p);
p.process_event(play());
// at this point, Play is active
p.process_event(pause()); pstate(p);
// go back to Playing
p.process_event(end_pause()); pstate(p);
p.process_event(pause()); pstate(p);
p.process_event(stop()); pstate(p);
// event leading to the same state
// no action method called as it is not present in the transition table
p.process_event(stop()); pstate(p);
UE_LOG(LogTemp, Warning,TEXT("stop fsm"));
p.stop();
}
}
编译,无warning,测试如预期工作。