1
This commit is contained in:
parent
07e56b7e59
commit
884c978019
@ -7,8 +7,8 @@
|
||||
#define MAKE_BTCONTEXT(...) \
|
||||
[] (CreatureWeakPtr owner, BaseAgent* agent) \
|
||||
{ \
|
||||
struct Context : public BtContext \
|
||||
{ \
|
||||
class Context : public BtContext \
|
||||
{public: \
|
||||
__VA_ARGS__; \
|
||||
std::function<void()> _destory_cb; \
|
||||
~Context() { if (_destory_cb) { _destory_cb(); };}; \
|
||||
|
@ -6,12 +6,12 @@
|
||||
|
||||
void BtContext::AddHandler(CreatureWeakPtr target, std::weak_ptr<EventHandlerPtr> handler)
|
||||
{
|
||||
handlers.push_back(std::make_tuple(target, handler));
|
||||
handlers_.push_back(std::make_tuple(target, handler));
|
||||
}
|
||||
|
||||
BtContext::~BtContext()
|
||||
{
|
||||
for (auto& tuple : handlers) {
|
||||
for (auto& tuple : handlers_) {
|
||||
if (std::get<0>(tuple).Get() && !std::get<1>(tuple).expired()) {
|
||||
std::get<0>(tuple).Get()->GetTrigger()->RemoveEventHandler(std::get<1>(tuple));
|
||||
}
|
||||
|
@ -3,16 +3,16 @@
|
||||
class BaseAgent;
|
||||
class BtEvent;
|
||||
struct EventHandlerPtr;
|
||||
struct BtContext : public std::enable_shared_from_this<BtContext>
|
||||
class BtContext : public std::enable_shared_from_this<BtContext>
|
||||
{
|
||||
public:
|
||||
|
||||
CreatureWeakPtr owner;
|
||||
std::vector<std::shared_ptr<BtEvent>> events;
|
||||
std::vector<std::tuple<CreatureWeakPtr, std::weak_ptr<EventHandlerPtr>>> handlers;
|
||||
|
||||
virtual ~BtContext();
|
||||
void AddHandler(CreatureWeakPtr target, std::weak_ptr<EventHandlerPtr> handler);
|
||||
private:
|
||||
|
||||
private:
|
||||
std::vector<std::tuple<CreatureWeakPtr, std::weak_ptr<EventHandlerPtr>>> handlers_;
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "behaviac/behaviac.h"
|
||||
#include "behaviac_customized_types.h"
|
||||
|
||||
struct BtContext;
|
||||
class BtContext;
|
||||
class BaseAgent;
|
||||
class BtCoroutine
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user