Skip to content

Commit

Permalink
Fix various bugs and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
limbonaut committed Jan 10, 2024
1 parent 0e37d3d commit e6c87be
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 21 deletions.
9 changes: 3 additions & 6 deletions blackboard/bb_param/bb_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
#ifndef BB_PARAM_H
#define BB_PARAM_H

#ifdef LIMBOAI_MODULE
#include "modules/limboai/blackboard/blackboard.h"
#include "modules/limboai/util/limbo_utility.h"
#include "../../blackboard/blackboard.h"
#include "../../util/limbo_utility.h"

#ifdef LIMBOAI_MODULE
#include "core/io/resource.h"
#include "core/object/object.h"
#include "core/typedefs.h"
#include "core/variant/variant.h"
#endif // LIMBOAI_MODULE

#ifdef LIMBOAI_GDEXTENSION
#include "blackboard/blackboard.h"
#include "util/limbo_utility.h"

#include <godot_cpp/classes/object.hpp>
#include <godot_cpp/classes/resource.hpp>
#include <godot_cpp/core/type_info.hpp>
Expand Down
2 changes: 1 addition & 1 deletion bt/tasks/blackboard/bt_check_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "../bt_condition.h"

#include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../limboai/util/limbo_utility.h"
#include "../../../util/limbo_utility.h"

class BTCheckVar : public BTCondition {
GDCLASS(BTCheckVar, BTCondition);
Expand Down
2 changes: 1 addition & 1 deletion bt/tasks/blackboard/bt_set_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "../bt_action.h"

#include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../limboai/util/limbo_utility.h"
#include "../../../util/limbo_utility.h"

class BTSetVar : public BTAction {
GDCLASS(BTSetVar, BTAction);
Expand Down
2 changes: 1 addition & 1 deletion bt/tasks/utility/bt_call_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "../bt_action.h"

#include "../../../limboai/blackboard/bb_param/bb_node.h"
#include "../../../blackboard/bb_param/bb_node.h"

class BTCallMethod : public BTAction {
GDCLASS(BTCallMethod, BTAction);
Expand Down
3 changes: 3 additions & 0 deletions editor/debugger/limbo_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ void LimboDebugger::deinitialize() {
}

void LimboDebugger::_bind_methods() {
#ifdef DEBUG_ENABLED

#ifdef LIMBOAI_GDEXTENSION
ClassDB::bind_method(D_METHOD("parse_message_gdext"), &LimboDebugger::parse_message_gdext);
#endif
ClassDB::bind_method(D_METHOD("_on_bt_updated", "p_status", "p_path"), &LimboDebugger::_on_bt_updated);
ClassDB::bind_method(D_METHOD("_on_state_updated", "p_delta", "p_path"), &LimboDebugger::_on_state_updated);
#endif // ! DEBUG_ENABLED
}

#ifdef DEBUG_ENABLED
Expand Down
4 changes: 2 additions & 2 deletions editor/debugger/limbo_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ class LimboDebugger : public Object {
void register_bt_instance(Ref<BTTask> p_instance, NodePath p_player_path);
void unregister_bt_instance(Ref<BTTask> p_instance, NodePath p_player_path);

#endif // DEBUG_ENABLED
#endif // ! DEBUG_ENABLED
};
#endif // LIMBO_DEBUGGER
#endif // ! LIMBO_DEBUGGER
2 changes: 2 additions & 0 deletions hsm/limbo_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class LimboState : public Node {
void add_event_handler(const String &p_event, const Callable &p_handler);

public:
static String EVENT_FINISHED() { return LW_NAME(EVENT_FINISHED); }

Ref<Blackboard> get_blackboard() const { return blackboard; }

Node *get_agent() const { return agent; }
Expand Down
2 changes: 2 additions & 0 deletions tests/limbo_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef LIMBO_TEST_H
#define LIMBO_TEST_H

#define LIMBOAI_MODULE

#include "core/object/ref_counted.h"
#include "tests/test_macros.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_await_animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#ifndef TEST_AWAIT_ANIMATION_H
#define TEST_AWAIT_ANIMATION_H

#include "core/os/memory.h"
#include "limbo_test.h"

#include "modules/limboai/blackboard/blackboard.h"
#include "modules/limboai/bt/tasks/bt_task.h"
#include "modules/limboai/bt/tasks/scene/bt_await_animation.h"

#include "core/os/memory.h"
#include "scene/animation/animation_player.h"
#include "scene/main/window.h"
#include "scene/resources/animation.h"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bb_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#ifndef TEST_BB_PARAM_H
#define TEST_BB_PARAM_H

#include "limbo_test.h"

#include "core/object/ref_counted.h"
#include "core/string/node_path.h"
#include "core/variant/variant.h"
#include "limbo_test.h"

#include "modules/limboai/blackboard/bb_param/bb_node.h"
#include "modules/limboai/blackboard/bb_param/bb_param.h"
#include "modules/limboai/blackboard/blackboard.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TEST_CASE("[Modules][LimboAI] HSM") {
CHECK(beta_updates->num_callbacks == 2);
CHECK(beta_exits->num_callbacks == 1);

hsm->dispatch(LimboState::EVENT_FINISHED);
hsm->dispatch(LimboState::EVENT_FINISHED());
CHECK(alpha_entries->num_callbacks == 2);
CHECK(alpha_updates->num_callbacks == 3);
CHECK(alpha_exits->num_callbacks == 2); // * exited
Expand Down
9 changes: 6 additions & 3 deletions util/limbo_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

#ifdef LIMBOAI_MODULE

#ifdef TOOLS_ENABLED
#include "core/io/resource.h"
#include "editor/editor_node.h"
#include "editor/plugins/script_editor_plugin.h"
#endif // ! TOOLS_ENABLED

#endif // ! LIMBOAI_MODULE

Expand Down Expand Up @@ -48,9 +50,6 @@ String TTR(const String &p_text, const String &p_context) {
return p_text;
}

void EDIT_SCRIPT(const String &p_path) {
}

Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
Variant ret;
if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
Expand Down Expand Up @@ -86,6 +85,8 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p

// **** Shared

#ifdef TOOLS_ENABLED

void SHOW_DOC(const String &p_topic) {
#ifdef LIMBOAI_MODULE
ScriptEditor::get_singleton()->goto_help(p_topic);
Expand Down Expand Up @@ -113,3 +114,5 @@ void EDIT_SCRIPT(const String &p_path) {
EditorInterface::get_singleton()->set_main_screen_editor("Script");
#endif // LIMBOAI_GDEXTENSION
}

#endif // ! TOOLS_ENABLED
4 changes: 4 additions & 0 deletions util/limbo_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ inline void VARIANT_DELETE_IF_OBJECT(Variant m_variant) {
#define PROJECT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("limbo_ai.cfg")
#define IS_RESOURCE_FILE(m_path) (m_path.begins_with("res://") && m_path.find("::") == -1)

#ifdef TOOLS_ENABLED

void SHOW_DOC(const String &p_topic);
void EDIT_SCRIPT(const String &p_path);

#endif // ! TOOLS_ENABLED

#endif // LIMBO_COMPAT_H
10 changes: 7 additions & 3 deletions util/limbo_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,13 @@ Variant LimboUtility::perform_operation(Operation p_operation, const Variant &le
VARIANT_EVALUATE(Variant::OP_MODULE, left_value, right_value, ret);
} break;
case OPERATION_POWER: {
// TODO: Fix when godot-cpp https://github.com/godotengine/godot-cpp/issues/1348 is resolved.
// Variant::evaluate(Variant::OP_POWER, left_value, right_value, ret, valid);
// TODO: Fix when godot-cpp https://github.com/godotengine/godot-cpp/issues/1348 is resolved.
#ifdef LIMBOAI_MODULE
VARIANT_EVALUATE(Variant::OP_POWER, left_value, right_value, ret);
#else // LIMBOAI_GDEXTENSION
ERR_PRINT("LimboUtility: Operation POWER is not available due to https://github.com/godotengine/godot-cpp/issues/1348");
ret = left_value;
#endif // LIMBOAI_MODULE
} break;
case OPERATION_BIT_SHIFT_LEFT: {
VARIANT_EVALUATE(Variant::OP_SHIFT_LEFT, left_value, right_value, ret);
Expand All @@ -282,7 +286,7 @@ Variant LimboUtility::perform_operation(Operation p_operation, const Variant &le
VARIANT_EVALUATE(Variant::OP_BIT_XOR, left_value, right_value, ret);
} break;
}
return Variant();
return ret;
}

Ref<Shortcut> LimboUtility::add_shortcut(const String &p_path, const String &p_name, Key p_keycode) {
Expand Down

0 comments on commit e6c87be

Please sign in to comment.