2022-09-28 10:48:45 +00:00
|
|
|
/* limbo_state.h */
|
|
|
|
|
|
|
|
#ifndef LIMBO_STATE_H
|
|
|
|
#define LIMBO_STATE_H
|
|
|
|
|
2023-07-20 16:35:36 +00:00
|
|
|
#include "modules/limboai/blackboard/blackboard.h"
|
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/object/class_db.h"
|
|
|
|
#include "core/object/gdvirtual.gen.inc"
|
|
|
|
#include "core/object/object.h"
|
|
|
|
#include "core/string/string_name.h"
|
|
|
|
#include "core/string/ustring.h"
|
|
|
|
#include "core/templates/hash_map.h"
|
2022-12-16 10:56:41 +00:00
|
|
|
#include "core/variant/callable.h"
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/variant/variant.h"
|
2022-09-28 10:48:45 +00:00
|
|
|
#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-12-16 10:56:41 +00:00
|
|
|
Node *agent;
|
2022-09-28 10:48:45 +00:00
|
|
|
Ref<Blackboard> blackboard;
|
2022-12-16 10:56:41 +00:00
|
|
|
HashMap<String, Callable> handlers;
|
|
|
|
Callable guard_callable;
|
2022-09-28 10:48:45 +00:00
|
|
|
|
|
|
|
protected:
|
2022-09-29 10:54:07 +00:00
|
|
|
friend LimboHSM;
|
2022-12-16 10:56:41 +00:00
|
|
|
|
2022-09-29 10:54:07 +00:00
|
|
|
bool active;
|
|
|
|
|
2022-09-28 10:48:45 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
2022-10-31 20:53:33 +00:00
|
|
|
void _set_blackboard_data(Dictionary p_value) { blackboard->set_data(p_value.duplicate()); }
|
|
|
|
Dictionary _get_blackboard_data() const { return blackboard->get_data(); }
|
|
|
|
|
2022-12-16 10:56:41 +00:00
|
|
|
virtual void _initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard);
|
2022-12-15 07:26:52 +00:00
|
|
|
|
2022-09-28 10:48:45 +00:00
|
|
|
virtual void _setup();
|
|
|
|
virtual void _enter();
|
|
|
|
virtual void _exit();
|
2023-04-10 08:08:11 +00:00
|
|
|
virtual void _update(double p_delta);
|
2022-09-28 10:48:45 +00:00
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
GDVIRTUAL0(_setup);
|
|
|
|
GDVIRTUAL0(_enter);
|
|
|
|
GDVIRTUAL0(_exit);
|
2023-04-10 08:08:11 +00:00
|
|
|
GDVIRTUAL1(_update, double);
|
2022-12-15 07:26:52 +00:00
|
|
|
|
2022-12-16 10:56:41 +00:00
|
|
|
void add_event_handler(const String &p_event, const Callable &p_handler);
|
2022-09-28 10:48:45 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static const String EVENT_FINISHED;
|
|
|
|
|
2022-10-19 21:39:27 +00:00
|
|
|
Ref<Blackboard> get_blackboard() const { return blackboard; }
|
2022-10-26 21:12:29 +00:00
|
|
|
|
2022-12-16 10:56:41 +00:00
|
|
|
Node *get_agent() const { return agent; }
|
|
|
|
void set_agent(Node *p_agent) { agent = p_agent; }
|
2022-10-19 21:39:27 +00:00
|
|
|
|
2022-09-28 10:48:45 +00:00
|
|
|
virtual bool dispatch(const String &p_event, const Variant &p_cargo);
|
|
|
|
|
|
|
|
LimboState *named(String p_name);
|
2023-03-30 21:37:21 +00:00
|
|
|
LimboState *call_on_enter(const Callable &p_callable);
|
|
|
|
LimboState *call_on_exit(const Callable &p_callable);
|
|
|
|
LimboState *call_on_update(const Callable &p_callable);
|
2022-09-28 10:48:45 +00:00
|
|
|
|
2022-12-16 10:56:41 +00:00
|
|
|
_FORCE_INLINE_ String event_finished() const { return EVENT_FINISHED; }
|
2022-09-28 10:48:45 +00:00
|
|
|
LimboState *get_root() const;
|
|
|
|
bool is_active() const { return active; }
|
2022-09-29 20:44:51 +00:00
|
|
|
|
2022-12-16 10:56:41 +00:00
|
|
|
void set_guard(const Callable &p_guard_callable);
|
|
|
|
void clear_guard();
|
2022-09-28 10:48:45 +00:00
|
|
|
|
|
|
|
LimboState();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LIMBO_STATE_H
|