Skip to content

Commit

Permalink
Merge pull request #193 from limbonaut/fix-monitor-performance
Browse files Browse the repository at this point in the history
Fix `monitor_performance` screwing C# exports
  • Loading branch information
limbonaut authored Aug 11, 2024
2 parents 6ada9ce + 314fcfd commit f8ab80d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 38 deletions.
18 changes: 7 additions & 11 deletions bt/bt_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,16 @@ void BTPlayer::restart() {
set_active(true);
}

#ifdef DEBUG_ENABLED

void BTPlayer::_set_monitor_performance(bool p_monitor_performance) {
void BTPlayer::set_monitor_performance(bool p_monitor_performance) {
monitor_performance = p_monitor_performance;

#ifdef DEBUG_ENABLED
if (bt_instance.is_valid()) {
bt_instance->set_monitor_performance(monitor_performance);
}
#endif
}

#endif // ! DEBUG_ENABLED

void BTPlayer::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_PROCESS: {
Expand Down Expand Up @@ -235,6 +233,9 @@ void BTPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_blackboard_plan", "plan"), &BTPlayer::set_blackboard_plan);
ClassDB::bind_method(D_METHOD("get_blackboard_plan"), &BTPlayer::get_blackboard_plan);

ClassDB::bind_method(D_METHOD("set_monitor_performance", "enable"), &BTPlayer::set_monitor_performance);
ClassDB::bind_method(D_METHOD("get_monitor_performance"), &BTPlayer::get_monitor_performance);

ClassDB::bind_method(D_METHOD("update", "delta"), &BTPlayer::update);
ClassDB::bind_method(D_METHOD("restart"), &BTPlayer::restart);

Expand All @@ -249,6 +250,7 @@ void BTPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "get_active");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard", PROPERTY_HINT_NONE, "Blackboard", 0), "set_blackboard", "get_blackboard");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard_plan", PROPERTY_HINT_RESOURCE_TYPE, "BlackboardPlan", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT | PROPERTY_USAGE_ALWAYS_DUPLICATE), "set_blackboard_plan", "get_blackboard_plan");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitor_performance"), "set_monitor_performance", "get_monitor_performance");

BIND_ENUM_CONSTANT(IDLE);
BIND_ENUM_CONSTANT(PHYSICS);
Expand All @@ -259,12 +261,6 @@ void BTPlayer::_bind_methods() {
#ifndef DISABLE_DEPRECATED
ADD_SIGNAL(MethodInfo("behavior_tree_finished", PropertyInfo(Variant::INT, "status")));
#endif

#ifdef DEBUG_ENABLED
ClassDB::bind_method(D_METHOD("_set_monitor_performance", "enable"), &BTPlayer::_set_monitor_performance);
ClassDB::bind_method(D_METHOD("_get_monitor_performance"), &BTPlayer::_get_monitor_performance);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitor_performance"), "_set_monitor_performance", "_get_monitor_performance");
#endif // DEBUG_ENABLED
}

BTPlayer::BTPlayer() {
Expand Down
14 changes: 4 additions & 10 deletions bt/bt_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BTPlayer : public Node {
bool active = true;
Ref<Blackboard> blackboard;
Node *scene_root_hint = nullptr;
bool monitor_performance = false;

Ref<BTInstance> bt_instance;

Expand Down Expand Up @@ -74,6 +75,9 @@ class BTPlayer : public Node {
Ref<Blackboard> get_blackboard() const { return blackboard; }
void set_blackboard(const Ref<Blackboard> &p_blackboard) { blackboard = p_blackboard; }

void set_monitor_performance(bool p_monitor_performance);
bool get_monitor_performance() const { return monitor_performance; }

void update(double p_delta);
void restart();

Expand All @@ -84,16 +88,6 @@ class BTPlayer : public Node {

BTPlayer();
~BTPlayer();

#ifdef DEBUG_ENABLED // Performance monitoring

private:
bool monitor_performance = false;

void _set_monitor_performance(bool p_monitor_performance);
bool _get_monitor_performance() const { return monitor_performance; }

#endif // * DEBUG_ENABLED
};

#endif // BT_PLAYER_H
16 changes: 7 additions & 9 deletions bt/bt_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ void BTState::set_scene_root_hint(Node *p_scene_root) {
scene_root_hint = p_scene_root;
}

#ifdef DEBUG_ENABLED
void BTState::_set_monitor_performance(bool p_monitor) {
void BTState::set_monitor_performance(bool p_monitor) {
monitor_performance = p_monitor;

#ifdef DEBUG_ENABLED
if (bt_instance.is_valid()) {
bt_instance->set_monitor_performance(monitor_performance);
}
#endif
}
#endif // DEBUG_ENABLED

void BTState::_update_blackboard_plan() {
if (get_blackboard_plan().is_null()) {
Expand Down Expand Up @@ -144,17 +144,15 @@ void BTState::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_failure_event", "event"), &BTState::set_failure_event);
ClassDB::bind_method(D_METHOD("get_failure_event"), &BTState::get_failure_event);

ClassDB::bind_method(D_METHOD("set_monitor_performance", "enable"), &BTState::set_monitor_performance);
ClassDB::bind_method(D_METHOD("get_monitor_performance"), &BTState::get_monitor_performance);

ClassDB::bind_method(D_METHOD("set_scene_root_hint", "scene_root"), &BTState::set_scene_root_hint);

ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "behavior_tree", PROPERTY_HINT_RESOURCE_TYPE, "BehaviorTree"), "set_behavior_tree", "get_behavior_tree");
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "success_event"), "set_success_event", "get_success_event");
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "failure_event"), "set_failure_event", "get_failure_event");

#ifdef DEBUG_ENABLED
ClassDB::bind_method(D_METHOD("_set_monitor_performance", "enable"), &BTState::_set_monitor_performance);
ClassDB::bind_method(D_METHOD("_get_monitor_performance"), &BTState::_get_monitor_performance);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitor_performance"), "_set_monitor_performance", "_get_monitor_performance");
#endif // DEBUG_ENABLED
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitor_performance"), "set_monitor_performance", "get_monitor_performance");
}

BTState::BTState() {
Expand Down
12 changes: 4 additions & 8 deletions bt/bt_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BTState : public LimboState {
StringName success_event;
StringName failure_event;
Node *scene_root_hint = nullptr;
bool monitor_performance = false;

protected:
static void _bind_methods();
Expand All @@ -51,17 +52,12 @@ class BTState : public LimboState {
void set_failure_event(const StringName &p_failure_event) { failure_event = p_failure_event; }
StringName get_failure_event() const { return failure_event; }

void set_monitor_performance(bool p_monitor);
bool get_monitor_performance() const { return monitor_performance; }

void set_scene_root_hint(Node *p_node);

BTState();

#ifdef DEBUG_ENABLED
private:
bool monitor_performance = false;

void _set_monitor_performance(bool p_monitor);
bool _get_monitor_performance() const { return monitor_performance; }
#endif
};

#endif // BT_STATE_H

0 comments on commit f8ab80d

Please sign in to comment.