limboai/limbo_state.h

71 lines
1.7 KiB
C
Raw Normal View History

2022-09-28 10:48:45 +00:00
/* limbo_state.h */
#ifndef LIMBO_STATE_H
#define LIMBO_STATE_H
#include "blackboard.h"
2022-09-29 20:44:51 +00:00
#include "core/class_db.h"
#include "core/object.h"
2022-09-28 10:48:45 +00:00
#include "core/string_name.h"
#include "core/ustring.h"
#include "core/variant.h"
#include "scene/main/node.h"
2022-09-29 10:54:07 +00:00
class LimboHSM;
2022-09-28 10:48:45 +00:00
class LimboState : public Node {
GDCLASS(LimboState, Node);
private:
2022-09-29 20:44:51 +00:00
struct GuardCallback {
Object *obj = nullptr;
StringName func;
Array binds;
};
2022-09-28 10:48:45 +00:00
Object *agent;
Ref<Blackboard> blackboard;
Map<String, StringName> handlers;
2022-09-29 20:44:51 +00:00
GuardCallback guard;
2022-09-28 10:48:45 +00:00
protected:
2022-09-29 10:54:07 +00:00
friend LimboHSM;
bool active;
2022-09-28 10:48:45 +00:00
static void _bind_methods();
void _notification(int p_what);
virtual void _setup();
virtual void _enter();
virtual void _exit();
virtual void _update(float p_delta);
void add_event_handler(const String &p_event, const StringName &p_method);
public:
static const String EVENT_FINISHED;
2022-10-19 21:39:27 +00:00
Ref<Blackboard> get_blackboard() const { return blackboard; }
Object *get_agent() const { return agent; }
2022-09-28 10:48:45 +00:00
virtual void initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
virtual bool dispatch(const String &p_event, const Variant &p_cargo);
LimboState *named(String p_name);
// LimboState *call_on_setup(Object *p_object, const StringName &p_method) {}
LimboState *call_on_enter(Object *p_object, const StringName &p_method);
LimboState *call_on_exit(Object *p_object, const StringName &p_method);
LimboState *call_on_update(Object *p_object, const StringName &p_method);
String event_finished() const { return EVENT_FINISHED; }
LimboState *get_root() const;
bool is_active() const { return active; }
2022-09-29 20:44:51 +00:00
void set_guard_func(Object *p_object, const StringName &p_func, const Array &p_binds = Array());
void clear_guard_func();
2022-09-28 10:48:45 +00:00
LimboState();
};
#endif // LIMBO_STATE_H