Use double instead of float when dealing with time
This commit is contained in:
parent
6fc97c43cd
commit
348aa4f750
|
@ -17,7 +17,7 @@ String BTConsolePrint::_generate_name() const {
|
||||||
return vformat("ConsolePrint \"%s\"", tx);
|
return vformat("ConsolePrint \"%s\"", tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTConsolePrint::_tick(float p_delta) {
|
int BTConsolePrint::_tick(double p_delta) {
|
||||||
switch (bb_format_parameters.size()) {
|
switch (bb_format_parameters.size()) {
|
||||||
case 0: {
|
case 0: {
|
||||||
print_line(text);
|
print_line(text);
|
||||||
|
|
|
@ -18,7 +18,7 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_text(String p_value) {
|
void set_text(String p_value) {
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
#include "bt_fail.h"
|
#include "bt_fail.h"
|
||||||
|
|
||||||
int BTFail::_tick(float p_delta) {
|
int BTFail::_tick(double p_delta) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class BTFail : public BTAction {
|
||||||
GDCLASS(BTFail, BTAction);
|
GDCLASS(BTFail, BTAction);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_FAIL_H
|
#endif // BT_FAIL_H
|
|
@ -5,16 +5,16 @@
|
||||||
|
|
||||||
String BTRandomWait::_generate_name() const {
|
String BTRandomWait::_generate_name() const {
|
||||||
return vformat("Wait %s to %s sec",
|
return vformat("Wait %s to %s sec",
|
||||||
Math::snapped(duration_min_max.x, 0.001),
|
Math::snapped(min_duration, 0.001),
|
||||||
Math::snapped(duration_min_max.y, 0.001));
|
Math::snapped(max_duration, 0.001));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTRandomWait::_enter() {
|
void BTRandomWait::_enter() {
|
||||||
time_passed = 0.0;
|
time_passed = 0.0;
|
||||||
duration = Math::random(duration_min_max.x, duration_min_max.y);
|
duration = Math::random(min_duration, max_duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTRandomWait::_tick(float p_delta) {
|
int BTRandomWait::_tick(double p_delta) {
|
||||||
time_passed += p_delta;
|
time_passed += p_delta;
|
||||||
if (time_passed < duration) {
|
if (time_passed < duration) {
|
||||||
return RUNNING;
|
return RUNNING;
|
||||||
|
@ -23,9 +23,28 @@ int BTRandomWait::_tick(float p_delta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTRandomWait::_bind_methods() {
|
void BTRandomWait::set_min_duration(double p_max_duration) {
|
||||||
ClassDB::bind_method(D_METHOD("set_duration_min_max", "p_value"), &BTRandomWait::set_duration_min_max);
|
min_duration = p_max_duration;
|
||||||
ClassDB::bind_method(D_METHOD("get_duration_min_max"), &BTRandomWait::get_duration_min_max);
|
if (max_duration < min_duration) {
|
||||||
|
set_max_duration(min_duration);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "duration_min_max"), "set_duration_min_max", "get_duration_min_max");
|
}
|
||||||
|
emit_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BTRandomWait::set_max_duration(double p_max_duration) {
|
||||||
|
max_duration = p_max_duration;
|
||||||
|
if (min_duration > max_duration) {
|
||||||
|
set_min_duration(max_duration);
|
||||||
|
}
|
||||||
|
emit_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BTRandomWait::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("set_min_duration"), &BTRandomWait::set_min_duration);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_min_duration"), &BTRandomWait::get_min_duration);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_max_duration"), &BTRandomWait::set_max_duration);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_max_duration"), &BTRandomWait::get_max_duration);
|
||||||
|
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_duration"), "set_min_duration", "get_min_duration");
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_duration"), "set_max_duration", "get_max_duration");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,24 +10,25 @@ class BTRandomWait : public BTAction {
|
||||||
GDCLASS(BTRandomWait, BTAction);
|
GDCLASS(BTRandomWait, BTAction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector2 duration_min_max = Vector2(1.0, 2.0);
|
double min_duration = 1.0;
|
||||||
|
double max_duration = 2.0;
|
||||||
|
|
||||||
float time_passed = 0.0;
|
double time_passed = 0.0;
|
||||||
float duration = 0.0;
|
double duration = 0.0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_duration_min_max(Vector2 p_value) {
|
void set_min_duration(double p_max_duration);
|
||||||
duration_min_max = p_value;
|
double get_min_duration() const { return min_duration; }
|
||||||
emit_changed();
|
|
||||||
}
|
void set_max_duration(double p_max_duration);
|
||||||
Vector2 get_duration_min_max() const { return duration_min_max; }
|
double get_max_duration() const { return max_duration; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_RANDOM_WAIT_H
|
#endif // BT_RANDOM_WAIT_H
|
|
@ -14,7 +14,7 @@ void BTWait::_enter() {
|
||||||
time_passed = 0.0;
|
time_passed = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTWait::_tick(float p_delta) {
|
int BTWait::_tick(double p_delta) {
|
||||||
time_passed += p_delta;
|
time_passed += p_delta;
|
||||||
if (time_passed < duration) {
|
if (time_passed < duration) {
|
||||||
return RUNNING;
|
return RUNNING;
|
||||||
|
|
|
@ -10,23 +10,23 @@ class BTWait : public BTAction {
|
||||||
GDCLASS(BTWait, BTAction);
|
GDCLASS(BTWait, BTAction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float duration = 1.0;
|
double duration = 1.0;
|
||||||
|
|
||||||
float time_passed = 0.0;
|
double time_passed = 0.0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_duration(float p_value) {
|
void set_duration(double p_value) {
|
||||||
duration = p_value;
|
duration = p_value;
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
float get_duration() const { return duration; }
|
double get_duration() const { return duration; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_WAIT_H
|
#endif // BT_WAIT_H
|
|
@ -13,7 +13,7 @@ void BTWaitTicks::_enter() {
|
||||||
num_passed = 0;
|
num_passed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTWaitTicks::_tick(float p_delta) {
|
int BTWaitTicks::_tick(double p_delta) {
|
||||||
num_passed += 1;
|
num_passed += 1;
|
||||||
if (num_passed < num_ticks) {
|
if (num_passed < num_ticks) {
|
||||||
return RUNNING;
|
return RUNNING;
|
||||||
|
|
|
@ -19,7 +19,7 @@ protected:
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_num_ticks(int p_value) {
|
void set_num_ticks(int p_value) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ void BTPlayer::set_active(bool p_active) {
|
||||||
set_process_input(active && is_not_editor);
|
set_process_input(active && is_not_editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTPlayer::update(float p_delta) {
|
void BTPlayer::update(double p_delta) {
|
||||||
if (!tree_instance.is_valid()) {
|
if (!tree_instance.is_valid()) {
|
||||||
ERR_PRINT_ONCE(vformat("BTPlayer doesn't have a behavior tree with a valid root task to execute (owner: %s)", get_owner()));
|
ERR_PRINT_ONCE(vformat("BTPlayer doesn't have a behavior tree with a valid root task to execute (owner: %s)", get_owner()));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
void set_prefetch_nodepath_vars(bool p_value) { prefetch_nodepath_vars = p_value; }
|
void set_prefetch_nodepath_vars(bool p_value) { prefetch_nodepath_vars = p_value; }
|
||||||
bool get_prefetch_nodepath_vars() const { return prefetch_nodepath_vars; }
|
bool get_prefetch_nodepath_vars() const { return prefetch_nodepath_vars; }
|
||||||
|
|
||||||
void update(float p_delta);
|
void update(double p_delta);
|
||||||
void restart();
|
void restart();
|
||||||
int get_last_status() const { return last_status; }
|
int get_last_status() const { return last_status; }
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ void BTState::_exit() {
|
||||||
tree_instance->cancel();
|
tree_instance->cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTState::_update(float p_delta) {
|
void BTState::_update(double p_delta) {
|
||||||
ERR_FAIL_COND(tree_instance == nullptr);
|
ERR_FAIL_COND(tree_instance == nullptr);
|
||||||
int status = tree_instance->execute(p_delta);
|
int status = tree_instance->execute(p_delta);
|
||||||
if (status == BTTask::SUCCESS) {
|
if (status == BTTask::SUCCESS) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ protected:
|
||||||
virtual void _setup() override;
|
virtual void _setup() override;
|
||||||
// virtual void _enter() override {}
|
// virtual void _enter() override {}
|
||||||
virtual void _exit() override;
|
virtual void _exit() override;
|
||||||
virtual void _update(float p_delta) override;
|
virtual void _update(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_behavior_tree(const Ref<BehaviorTree> &p_value) { behavior_tree = p_value; }
|
void set_behavior_tree(const Ref<BehaviorTree> &p_value) { behavior_tree = p_value; }
|
||||||
|
|
|
@ -130,7 +130,7 @@ Ref<BTTask> BTTask::clone() const {
|
||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTTask::execute(float p_delta) {
|
int BTTask::execute(double p_delta) {
|
||||||
if (status != RUNNING) {
|
if (status != RUNNING) {
|
||||||
if (!GDVIRTUAL_CALL(_enter)) {
|
if (!GDVIRTUAL_CALL(_enter)) {
|
||||||
_enter();
|
_enter();
|
||||||
|
|
|
@ -44,13 +44,13 @@ protected:
|
||||||
virtual void _setup() {}
|
virtual void _setup() {}
|
||||||
virtual void _enter() {}
|
virtual void _enter() {}
|
||||||
virtual void _exit() {}
|
virtual void _exit() {}
|
||||||
virtual int _tick(float p_delta) { return FAILURE; }
|
virtual int _tick(double p_delta) { return FAILURE; }
|
||||||
|
|
||||||
GDVIRTUAL0RC(String, _generate_name);
|
GDVIRTUAL0RC(String, _generate_name);
|
||||||
GDVIRTUAL0(_setup);
|
GDVIRTUAL0(_setup);
|
||||||
GDVIRTUAL0(_enter);
|
GDVIRTUAL0(_enter);
|
||||||
GDVIRTUAL0(_exit);
|
GDVIRTUAL0(_exit);
|
||||||
GDVIRTUAL1R(int, _tick, float);
|
GDVIRTUAL1R(int, _tick, double);
|
||||||
GDVIRTUAL0RC(String, _get_configuration_warning);
|
GDVIRTUAL0RC(String, _get_configuration_warning);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -72,7 +72,7 @@ public:
|
||||||
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard);
|
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard);
|
||||||
virtual String get_configuration_warning() const;
|
virtual String get_configuration_warning() const;
|
||||||
|
|
||||||
int execute(float p_delta);
|
int execute(double p_delta);
|
||||||
void cancel();
|
void cancel();
|
||||||
int get_status() const { return status; }
|
int get_status() const { return status; }
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ void BTDynamicSelector::_enter() {
|
||||||
last_running_idx = 0;
|
last_running_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTDynamicSelector::_tick(float p_delta) {
|
int BTDynamicSelector::_tick(double p_delta) {
|
||||||
int status = SUCCESS;
|
int status = SUCCESS;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < get_child_count(); i++) {
|
for (i = 0; i < get_child_count(); i++) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_DYNAMIC_SELECTOR_H
|
#endif // BT_DYNAMIC_SELECTOR_H
|
|
@ -6,7 +6,7 @@ void BTDynamicSequence::_enter() {
|
||||||
last_running_idx = 0;
|
last_running_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTDynamicSequence::_tick(float p_delta) {
|
int BTDynamicSequence::_tick(double p_delta) {
|
||||||
int status = SUCCESS;
|
int status = SUCCESS;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < get_child_count(); i++) {
|
for (i = 0; i < get_child_count(); i++) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_DYNAMIC_SEQUENCE_H
|
#endif // BT_DYNAMIC_SEQUENCE_H
|
|
@ -9,7 +9,7 @@ void BTParallel::_enter() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTParallel::_tick(float p_delta) {
|
int BTParallel::_tick(double p_delta) {
|
||||||
int num_succeeded = 0;
|
int num_succeeded = 0;
|
||||||
int num_failed = 0;
|
int num_failed = 0;
|
||||||
int return_status = RUNNING;
|
int return_status = RUNNING;
|
||||||
|
|
|
@ -18,7 +18,7 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int get_num_successes_required() const { return num_successes_required; }
|
int get_num_successes_required() const { return num_successes_required; }
|
||||||
|
|
|
@ -13,7 +13,7 @@ void BTRandomSelector::_enter() {
|
||||||
indicies.shuffle();
|
indicies.shuffle();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTRandomSelector::_tick(float p_delta) {
|
int BTRandomSelector::_tick(double p_delta) {
|
||||||
int status = FAILURE;
|
int status = FAILURE;
|
||||||
for (int i = last_running_idx; i < get_child_count(); i++) {
|
for (int i = last_running_idx; i < get_child_count(); i++) {
|
||||||
status = get_child(indicies[i])->execute(p_delta);
|
status = get_child(indicies[i])->execute(p_delta);
|
||||||
|
|
|
@ -15,6 +15,6 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
#endif // BT_RANDOM_SELECTOR_H
|
#endif // BT_RANDOM_SELECTOR_H
|
|
@ -13,7 +13,7 @@ void BTRandomSequence::_enter() {
|
||||||
indicies.shuffle();
|
indicies.shuffle();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTRandomSequence::_tick(float p_delta) {
|
int BTRandomSequence::_tick(double p_delta) {
|
||||||
int status = SUCCESS;
|
int status = SUCCESS;
|
||||||
for (int i = last_running_idx; i < get_child_count(); i++) {
|
for (int i = last_running_idx; i < get_child_count(); i++) {
|
||||||
status = get_child(indicies[i])->execute(p_delta);
|
status = get_child(indicies[i])->execute(p_delta);
|
||||||
|
|
|
@ -15,6 +15,6 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
#endif // BT_RANDOM_SEQUENCE_H
|
#endif // BT_RANDOM_SEQUENCE_H
|
|
@ -6,7 +6,7 @@ void BTSelector::_enter() {
|
||||||
last_running_idx = 0;
|
last_running_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTSelector::_tick(float p_delta) {
|
int BTSelector::_tick(double p_delta) {
|
||||||
int status = FAILURE;
|
int status = FAILURE;
|
||||||
for (int i = last_running_idx; i < get_child_count(); i++) {
|
for (int i = last_running_idx; i < get_child_count(); i++) {
|
||||||
status = get_child(i)->execute(p_delta);
|
status = get_child(i)->execute(p_delta);
|
||||||
|
|
|
@ -13,6 +13,6 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
#endif // BT_SELECTOR_H
|
#endif // BT_SELECTOR_H
|
|
@ -6,7 +6,7 @@ void BTSequence::_enter() {
|
||||||
last_running_idx = 0;
|
last_running_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTSequence::_tick(float p_delta) {
|
int BTSequence::_tick(double p_delta) {
|
||||||
int status = SUCCESS;
|
int status = SUCCESS;
|
||||||
for (int i = last_running_idx; i < get_child_count(); i++) {
|
for (int i = last_running_idx; i < get_child_count(); i++) {
|
||||||
status = get_child(i)->execute(p_delta);
|
status = get_child(i)->execute(p_delta);
|
||||||
|
|
|
@ -14,7 +14,7 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_SEQUENCE_H
|
#endif // BT_SEQUENCE_H
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "bt_always_fail.h"
|
#include "bt_always_fail.h"
|
||||||
|
|
||||||
int BTAlwaysFail::_tick(float p_delta) {
|
int BTAlwaysFail::_tick(double p_delta) {
|
||||||
if (get_child_count() > 0 && get_child(0)->execute(p_delta) == RUNNING) {
|
if (get_child_count() > 0 && get_child(0)->execute(p_delta) == RUNNING) {
|
||||||
return RUNNING;
|
return RUNNING;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class BTAlwaysFail : public BTDecorator {
|
||||||
GDCLASS(BTAlwaysFail, BTDecorator);
|
GDCLASS(BTAlwaysFail, BTDecorator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_ALWAYS_FAIL_H
|
#endif // BT_ALWAYS_FAIL_H
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "bt_always_succeed.h"
|
#include "bt_always_succeed.h"
|
||||||
|
|
||||||
int BTAlwaysSucceed::_tick(float p_delta) {
|
int BTAlwaysSucceed::_tick(double p_delta) {
|
||||||
if (get_child_count() > 0 && get_child(0)->execute(p_delta) == RUNNING) {
|
if (get_child_count() > 0 && get_child(0)->execute(p_delta) == RUNNING) {
|
||||||
return RUNNING;
|
return RUNNING;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class BTAlwaysSucceed : public BTDecorator {
|
||||||
GDCLASS(BTAlwaysSucceed, BTDecorator);
|
GDCLASS(BTAlwaysSucceed, BTDecorator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_ALWAYS_SUCCEED_H
|
#endif // BT_ALWAYS_SUCCEED_H
|
|
@ -20,7 +20,7 @@ void BTCooldown::_setup() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTCooldown::_tick(float p_delta) {
|
int BTCooldown::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
if (get_blackboard()->get_var(cooldown_state_var, true)) {
|
if (get_blackboard()->get_var(cooldown_state_var, true)) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
|
|
|
@ -11,7 +11,7 @@ class BTCooldown : public BTDecorator {
|
||||||
GDCLASS(BTCooldown, BTDecorator);
|
GDCLASS(BTCooldown, BTDecorator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float duration = 10.0;
|
double duration = 10.0;
|
||||||
bool process_pause = false;
|
bool process_pause = false;
|
||||||
bool start_cooled = false;
|
bool start_cooled = false;
|
||||||
bool trigger_on_failure = false;
|
bool trigger_on_failure = false;
|
||||||
|
@ -27,14 +27,14 @@ protected:
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _setup() override;
|
virtual void _setup() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_duration(float p_value) {
|
void set_duration(double p_value) {
|
||||||
duration = p_value;
|
duration = p_value;
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
float get_duration() const { return duration; }
|
double get_duration() const { return duration; }
|
||||||
void set_process_pause(bool p_value) {
|
void set_process_pause(bool p_value) {
|
||||||
process_pause = p_value;
|
process_pause = p_value;
|
||||||
emit_changed();
|
emit_changed();
|
||||||
|
|
|
@ -16,7 +16,7 @@ void BTDelay::_enter() {
|
||||||
time_passed = 0.0;
|
time_passed = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTDelay::_tick(float p_delta) {
|
int BTDelay::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
time_passed += p_delta;
|
time_passed += p_delta;
|
||||||
if (time_passed <= seconds) {
|
if (time_passed <= seconds) {
|
||||||
|
|
|
@ -10,22 +10,22 @@ class BTDelay : public BTDecorator {
|
||||||
GDCLASS(BTDelay, BTDecorator);
|
GDCLASS(BTDelay, BTDecorator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float seconds = 1.0;
|
double seconds = 1.0;
|
||||||
float time_passed = 0.0;
|
double time_passed = 0.0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_seconds(float p_value) {
|
void set_seconds(double p_value) {
|
||||||
seconds = p_value;
|
seconds = p_value;
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
float get_seconds() const { return seconds; }
|
double get_seconds() const { return seconds; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_DELAY_H
|
#endif // BT_DELAY_H
|
|
@ -17,7 +17,7 @@ void BTForEach::_enter() {
|
||||||
current_idx = 0;
|
current_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTForEach::_tick(float p_delta) {
|
int BTForEach::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "ForEach decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "ForEach decorator has no child.");
|
||||||
ERR_FAIL_COND_V_MSG(save_var.is_empty(), FAILURE, "ForEach save variable is not set.");
|
ERR_FAIL_COND_V_MSG(save_var.is_empty(), FAILURE, "ForEach save variable is not set.");
|
||||||
ERR_FAIL_COND_V_MSG(array_var.is_empty(), FAILURE, "ForEach array variable is not set.");
|
ERR_FAIL_COND_V_MSG(array_var.is_empty(), FAILURE, "ForEach array variable is not set.");
|
||||||
|
|
|
@ -20,7 +20,7 @@ protected:
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_array_var(String p_value) {
|
void set_array_var(String p_value) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "bt_invert.h"
|
#include "bt_invert.h"
|
||||||
|
|
||||||
int BTInvert::_tick(float p_delta) {
|
int BTInvert::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
int status = get_child(0)->execute(p_delta);
|
int status = get_child(0)->execute(p_delta);
|
||||||
if (status == SUCCESS) {
|
if (status == SUCCESS) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ class BTInvert : public BTDecorator {
|
||||||
GDCLASS(BTInvert, BTDecorator);
|
GDCLASS(BTInvert, BTDecorator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_INVERT_H
|
#endif // BT_INVERT_H
|
|
@ -18,7 +18,7 @@ void BTNewScope::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard)
|
||||||
BTDecorator::initialize(p_agent, bb);
|
BTDecorator::initialize(p_agent, bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTNewScope::_tick(float p_delta) {
|
int BTNewScope::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
return get_child(0)->execute(p_delta);
|
return get_child(0)->execute(p_delta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ protected:
|
||||||
void _set_blackboard_data(const Dictionary &p_value) { blackboard_data = p_value; }
|
void _set_blackboard_data(const Dictionary &p_value) { blackboard_data = p_value; }
|
||||||
Dictionary _get_blackboard_data() const { return blackboard_data; }
|
Dictionary _get_blackboard_data() const { return blackboard_data; }
|
||||||
|
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) override;
|
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) override;
|
||||||
|
|
|
@ -7,7 +7,7 @@ String BTProbability::_generate_name() const {
|
||||||
return vformat("Probability %.1f%%", run_chance);
|
return vformat("Probability %.1f%%", run_chance);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTProbability::_tick(float p_delta) {
|
int BTProbability::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
if (get_child(0)->get_status() == RUNNING or Math::randf() <= run_chance) {
|
if (get_child(0)->get_status() == RUNNING or Math::randf() <= run_chance) {
|
||||||
return get_child(0)->execute(p_delta);
|
return get_child(0)->execute(p_delta);
|
||||||
|
|
|
@ -16,7 +16,7 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_run_chance(float p_value) {
|
void set_run_chance(float p_value) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ void BTRepeat::_enter() {
|
||||||
cur_iteration = 1;
|
cur_iteration = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTRepeat::_tick(float p_delta) {
|
int BTRepeat::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
int status = get_child(0)->execute(p_delta);
|
int status = get_child(0)->execute(p_delta);
|
||||||
if (status == RUNNING) {
|
if (status == RUNNING) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ protected:
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_times(int p_value) {
|
void set_times(int p_value) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "bt_repeat_until_failure.h"
|
#include "bt_repeat_until_failure.h"
|
||||||
|
|
||||||
int BTRepeatUntilFailure::_tick(float p_delta) {
|
int BTRepeatUntilFailure::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
if (get_child(0)->execute(p_delta) == FAILURE) {
|
if (get_child(0)->execute(p_delta) == FAILURE) {
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
|
@ -10,7 +10,7 @@ class BTRepeatUntilFailure : public BTDecorator {
|
||||||
GDCLASS(BTRepeatUntilFailure, BTDecorator);
|
GDCLASS(BTRepeatUntilFailure, BTDecorator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_REPEAT_UNTIL_FAILURE_H
|
#endif // BT_REPEAT_UNTIL_FAILURE_H
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "bt_repeat_until_success.h"
|
#include "bt_repeat_until_success.h"
|
||||||
|
|
||||||
int BTRepeatUntilSuccess::_tick(float p_delta) {
|
int BTRepeatUntilSuccess::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
if (get_child(0)->execute(p_delta) == SUCCESS) {
|
if (get_child(0)->execute(p_delta) == SUCCESS) {
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
|
@ -10,7 +10,7 @@ class BTRepeatUntilSuccess : public BTDecorator {
|
||||||
GDCLASS(BTRepeatUntilSuccess, BTDecorator);
|
GDCLASS(BTRepeatUntilSuccess, BTDecorator);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_REPEAT_UNTIL_SUCCESS_H
|
#endif // BT_REPEAT_UNTIL_SUCCESS_H
|
|
@ -6,7 +6,7 @@ String BTRunLimit::_generate_name() const {
|
||||||
return vformat("RunLimit x%d", run_limit);
|
return vformat("RunLimit x%d", run_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTRunLimit::_tick(float p_delta) {
|
int BTRunLimit::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
if (get_child(0)->get_status() != RUNNING) {
|
if (get_child(0)->get_status() != RUNNING) {
|
||||||
if (num_runs >= run_limit) {
|
if (num_runs >= run_limit) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_run_limit(int p_value) {
|
void set_run_limit(int p_value) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ void BTSubtree::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) {
|
||||||
BTNewScope::initialize(p_agent, p_blackboard);
|
BTNewScope::initialize(p_agent, p_blackboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTSubtree::_tick(float p_delta) {
|
int BTSubtree::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator doesn't have a child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator doesn't have a child.");
|
||||||
return get_child(0)->execute(p_delta);
|
return get_child(0)->execute(p_delta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_subtree(const Ref<BehaviorTree> &p_value) {
|
void set_subtree(const Ref<BehaviorTree> &p_value) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ void BTTimeLimit::_enter() {
|
||||||
time_passed = 0.0;
|
time_passed = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BTTimeLimit::_tick(float p_delta) {
|
int BTTimeLimit::_tick(double p_delta) {
|
||||||
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
||||||
time_passed += p_delta;
|
time_passed += p_delta;
|
||||||
int status = get_child(0)->execute(p_delta);
|
int status = get_child(0)->execute(p_delta);
|
||||||
|
|
|
@ -10,22 +10,22 @@ class BTTimeLimit : public BTDecorator {
|
||||||
GDCLASS(BTTimeLimit, BTDecorator);
|
GDCLASS(BTTimeLimit, BTDecorator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float time_limit = 5.0;
|
double time_limit = 5.0;
|
||||||
float time_passed = 0.0;
|
double time_passed = 0.0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
virtual String _generate_name() const override;
|
virtual String _generate_name() const override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual int _tick(float p_delta) override;
|
virtual int _tick(double p_delta) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_time_limit(float p_value) {
|
void set_time_limit(double p_value) {
|
||||||
time_limit = p_value;
|
time_limit = p_value;
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
float get_time_limit() const { return time_limit; }
|
double get_time_limit() const { return time_limit; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BT_TIME_LIMIT_H
|
#endif // BT_TIME_LIMIT_H
|
|
@ -83,7 +83,7 @@ void LimboHSM::_exit() {
|
||||||
LimboState::_exit();
|
LimboState::_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LimboHSM::_update(float p_delta) {
|
void LimboHSM::_update(double p_delta) {
|
||||||
if (active) {
|
if (active) {
|
||||||
ERR_FAIL_COND(active_state == nullptr);
|
ERR_FAIL_COND(active_state == nullptr);
|
||||||
LimboState::_update(p_delta);
|
LimboState::_update(p_delta);
|
||||||
|
@ -211,18 +211,10 @@ void LimboHSM::_notification(int p_what) {
|
||||||
case NOTIFICATION_POST_ENTER_TREE: {
|
case NOTIFICATION_POST_ENTER_TREE: {
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_PROCESS: {
|
case NOTIFICATION_PROCESS: {
|
||||||
// if (!Engine::get_singleton()->is_editor_hint()) {
|
|
||||||
// if (update_mode == UpdateMode::IDLE) {
|
|
||||||
_update(get_process_delta_time());
|
_update(get_process_delta_time());
|
||||||
// }
|
|
||||||
// }
|
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_PHYSICS_PROCESS: {
|
case NOTIFICATION_PHYSICS_PROCESS: {
|
||||||
// if (!Engine::get_singleton()->is_editor_hint()) {
|
|
||||||
// if (update_mode == UpdateMode::PHYSICS) {
|
|
||||||
_update(get_physics_process_delta_time());
|
_update(get_physics_process_delta_time());
|
||||||
// }
|
|
||||||
// }
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ protected:
|
||||||
virtual void _initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) override;
|
virtual void _initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) override;
|
||||||
virtual void _enter() override;
|
virtual void _enter() override;
|
||||||
virtual void _exit() override;
|
virtual void _exit() override;
|
||||||
virtual void _update(float p_delta) override;
|
virtual void _update(double p_delta) override;
|
||||||
|
|
||||||
void _change_state(LimboState *p_state);
|
void _change_state(LimboState *p_state);
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_parent_scope = nullptr);
|
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_parent_scope = nullptr);
|
||||||
virtual bool dispatch(const String &p_event, const Variant &p_cargo) override;
|
virtual bool dispatch(const String &p_event, const Variant &p_cargo) override;
|
||||||
|
|
||||||
void update(float p_delta) { _update(p_delta); }
|
void update(double p_delta) { _update(p_delta); }
|
||||||
void add_transition(Node *p_from_state, Node *p_to_state, const String &p_event);
|
void add_transition(Node *p_from_state, Node *p_to_state, const String &p_event);
|
||||||
// void add_transition_from_any_state(Node *p_to_state, const String &p_event);
|
// void add_transition_from_any_state(Node *p_to_state, const String &p_event);
|
||||||
LimboState *anystate() const { return nullptr; };
|
LimboState *anystate() const { return nullptr; };
|
||||||
|
|
|
@ -45,7 +45,7 @@ void LimboState::_exit() {
|
||||||
active = false;
|
active = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
void LimboState::_update(float p_delta) {
|
void LimboState::_update(double p_delta) {
|
||||||
GDVIRTUAL_CALL(_update, p_delta);
|
GDVIRTUAL_CALL(_update, p_delta);
|
||||||
emit_signal(LimboStringNames::get_singleton()->updated, p_delta);
|
emit_signal(LimboStringNames::get_singleton()->updated, p_delta);
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,12 +42,12 @@ protected:
|
||||||
virtual void _setup();
|
virtual void _setup();
|
||||||
virtual void _enter();
|
virtual void _enter();
|
||||||
virtual void _exit();
|
virtual void _exit();
|
||||||
virtual void _update(float p_delta);
|
virtual void _update(double p_delta);
|
||||||
|
|
||||||
GDVIRTUAL0(_setup);
|
GDVIRTUAL0(_setup);
|
||||||
GDVIRTUAL0(_enter);
|
GDVIRTUAL0(_enter);
|
||||||
GDVIRTUAL0(_exit);
|
GDVIRTUAL0(_exit);
|
||||||
GDVIRTUAL1(_update, float);
|
GDVIRTUAL1(_update, double);
|
||||||
|
|
||||||
void add_event_handler(const String &p_event, const Callable &p_handler);
|
void add_event_handler(const String &p_event, const Callable &p_handler);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue