Fix various bugs and unit tests

This commit is contained in:
Serhii Snitsaruk 2024-01-10 23:26:24 +01:00
parent 0e37d3dfa3
commit e6c87be723
14 changed files with 36 additions and 21 deletions

View File

@ -12,10 +12,10 @@
#ifndef BB_PARAM_H #ifndef BB_PARAM_H
#define BB_PARAM_H #define BB_PARAM_H
#ifdef LIMBOAI_MODULE #include "../../blackboard/blackboard.h"
#include "modules/limboai/blackboard/blackboard.h" #include "../../util/limbo_utility.h"
#include "modules/limboai/util/limbo_utility.h"
#ifdef LIMBOAI_MODULE
#include "core/io/resource.h" #include "core/io/resource.h"
#include "core/object/object.h" #include "core/object/object.h"
#include "core/typedefs.h" #include "core/typedefs.h"
@ -23,9 +23,6 @@
#endif // LIMBOAI_MODULE #endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION #ifdef LIMBOAI_GDEXTENSION
#include "blackboard/blackboard.h"
#include "util/limbo_utility.h"
#include <godot_cpp/classes/object.hpp> #include <godot_cpp/classes/object.hpp>
#include <godot_cpp/classes/resource.hpp> #include <godot_cpp/classes/resource.hpp>
#include <godot_cpp/core/type_info.hpp> #include <godot_cpp/core/type_info.hpp>

View File

@ -15,7 +15,7 @@
#include "../bt_condition.h" #include "../bt_condition.h"
#include "../../../blackboard/bb_param/bb_variant.h" #include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../limboai/util/limbo_utility.h" #include "../../../util/limbo_utility.h"
class BTCheckVar : public BTCondition { class BTCheckVar : public BTCondition {
GDCLASS(BTCheckVar, BTCondition); GDCLASS(BTCheckVar, BTCondition);

View File

@ -15,7 +15,7 @@
#include "../bt_action.h" #include "../bt_action.h"
#include "../../../blackboard/bb_param/bb_variant.h" #include "../../../blackboard/bb_param/bb_variant.h"
#include "../../../limboai/util/limbo_utility.h" #include "../../../util/limbo_utility.h"
class BTSetVar : public BTAction { class BTSetVar : public BTAction {
GDCLASS(BTSetVar, BTAction); GDCLASS(BTSetVar, BTAction);

View File

@ -14,7 +14,7 @@
#include "../bt_action.h" #include "../bt_action.h"
#include "../../../limboai/blackboard/bb_param/bb_node.h" #include "../../../blackboard/bb_param/bb_node.h"
class BTCallMethod : public BTAction { class BTCallMethod : public BTAction {
GDCLASS(BTCallMethod, BTAction); GDCLASS(BTCallMethod, BTAction);

View File

@ -64,11 +64,14 @@ void LimboDebugger::deinitialize() {
} }
void LimboDebugger::_bind_methods() { void LimboDebugger::_bind_methods() {
#ifdef DEBUG_ENABLED
#ifdef LIMBOAI_GDEXTENSION #ifdef LIMBOAI_GDEXTENSION
ClassDB::bind_method(D_METHOD("parse_message_gdext"), &LimboDebugger::parse_message_gdext); ClassDB::bind_method(D_METHOD("parse_message_gdext"), &LimboDebugger::parse_message_gdext);
#endif #endif
ClassDB::bind_method(D_METHOD("_on_bt_updated", "p_status", "p_path"), &LimboDebugger::_on_bt_updated); 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); ClassDB::bind_method(D_METHOD("_on_state_updated", "p_delta", "p_path"), &LimboDebugger::_on_state_updated);
#endif // ! DEBUG_ENABLED
} }
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED

View File

@ -67,6 +67,6 @@ public:
void register_bt_instance(Ref<BTTask> p_instance, NodePath p_player_path); void register_bt_instance(Ref<BTTask> p_instance, NodePath p_player_path);
void unregister_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

View File

@ -71,6 +71,8 @@ protected:
void add_event_handler(const String &p_event, const Callable &p_handler); void add_event_handler(const String &p_event, const Callable &p_handler);
public: public:
static String EVENT_FINISHED() { return LW_NAME(EVENT_FINISHED); }
Ref<Blackboard> get_blackboard() const { return blackboard; } Ref<Blackboard> get_blackboard() const { return blackboard; }
Node *get_agent() const { return agent; } Node *get_agent() const { return agent; }

View File

@ -12,6 +12,8 @@
#ifndef LIMBO_TEST_H #ifndef LIMBO_TEST_H
#define LIMBO_TEST_H #define LIMBO_TEST_H
#define LIMBOAI_MODULE
#include "core/object/ref_counted.h" #include "core/object/ref_counted.h"
#include "tests/test_macros.h" #include "tests/test_macros.h"

View File

@ -12,13 +12,13 @@
#ifndef TEST_AWAIT_ANIMATION_H #ifndef TEST_AWAIT_ANIMATION_H
#define TEST_AWAIT_ANIMATION_H #define TEST_AWAIT_ANIMATION_H
#include "core/os/memory.h"
#include "limbo_test.h" #include "limbo_test.h"
#include "modules/limboai/blackboard/blackboard.h" #include "modules/limboai/blackboard/blackboard.h"
#include "modules/limboai/bt/tasks/bt_task.h" #include "modules/limboai/bt/tasks/bt_task.h"
#include "modules/limboai/bt/tasks/scene/bt_await_animation.h" #include "modules/limboai/bt/tasks/scene/bt_await_animation.h"
#include "core/os/memory.h"
#include "scene/animation/animation_player.h" #include "scene/animation/animation_player.h"
#include "scene/main/window.h" #include "scene/main/window.h"
#include "scene/resources/animation.h" #include "scene/resources/animation.h"

View File

@ -12,11 +12,11 @@
#ifndef TEST_BB_PARAM_H #ifndef TEST_BB_PARAM_H
#define TEST_BB_PARAM_H #define TEST_BB_PARAM_H
#include "limbo_test.h"
#include "core/object/ref_counted.h" #include "core/object/ref_counted.h"
#include "core/string/node_path.h" #include "core/string/node_path.h"
#include "core/variant/variant.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_node.h"
#include "modules/limboai/blackboard/bb_param/bb_param.h" #include "modules/limboai/blackboard/bb_param/bb_param.h"
#include "modules/limboai/blackboard/blackboard.h" #include "modules/limboai/blackboard/blackboard.h"

View File

@ -136,7 +136,7 @@ TEST_CASE("[Modules][LimboAI] HSM") {
CHECK(beta_updates->num_callbacks == 2); CHECK(beta_updates->num_callbacks == 2);
CHECK(beta_exits->num_callbacks == 1); CHECK(beta_exits->num_callbacks == 1);
hsm->dispatch(LimboState::EVENT_FINISHED); hsm->dispatch(LimboState::EVENT_FINISHED());
CHECK(alpha_entries->num_callbacks == 2); CHECK(alpha_entries->num_callbacks == 2);
CHECK(alpha_updates->num_callbacks == 3); CHECK(alpha_updates->num_callbacks == 3);
CHECK(alpha_exits->num_callbacks == 2); // * exited CHECK(alpha_exits->num_callbacks == 2); // * exited

View File

@ -13,9 +13,11 @@
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
#ifdef TOOLS_ENABLED
#include "core/io/resource.h" #include "core/io/resource.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/plugins/script_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h"
#endif // ! TOOLS_ENABLED
#endif // ! LIMBOAI_MODULE #endif // ! LIMBOAI_MODULE
@ -48,9 +50,6 @@ String TTR(const String &p_text, const String &p_context) {
return p_text; 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 _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; Variant ret;
if (!ProjectSettings::get_singleton()->has_setting(p_var)) { if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
@ -86,6 +85,8 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p
// **** Shared // **** Shared
#ifdef TOOLS_ENABLED
void SHOW_DOC(const String &p_topic) { void SHOW_DOC(const String &p_topic) {
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
ScriptEditor::get_singleton()->goto_help(p_topic); ScriptEditor::get_singleton()->goto_help(p_topic);
@ -113,3 +114,5 @@ void EDIT_SCRIPT(const String &p_path) {
EditorInterface::get_singleton()->set_main_screen_editor("Script"); EditorInterface::get_singleton()->set_main_screen_editor("Script");
#endif // LIMBOAI_GDEXTENSION #endif // LIMBOAI_GDEXTENSION
} }
#endif // ! TOOLS_ENABLED

View File

@ -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 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) #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 SHOW_DOC(const String &p_topic);
void EDIT_SCRIPT(const String &p_path); void EDIT_SCRIPT(const String &p_path);
#endif // ! TOOLS_ENABLED
#endif // LIMBO_COMPAT_H #endif // LIMBO_COMPAT_H

View File

@ -262,9 +262,13 @@ Variant LimboUtility::perform_operation(Operation p_operation, const Variant &le
VARIANT_EVALUATE(Variant::OP_MODULE, left_value, right_value, ret); VARIANT_EVALUATE(Variant::OP_MODULE, left_value, right_value, ret);
} break; } break;
case OPERATION_POWER: { case OPERATION_POWER: {
// TODO: Fix when godot-cpp https://github.com/godotengine/godot-cpp/issues/1348 is resolved. // 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); #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"); 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; } break;
case OPERATION_BIT_SHIFT_LEFT: { case OPERATION_BIT_SHIFT_LEFT: {
VARIANT_EVALUATE(Variant::OP_SHIFT_LEFT, left_value, right_value, ret); VARIANT_EVALUATE(Variant::OP_SHIFT_LEFT, left_value, right_value, ret);
@ -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); VARIANT_EVALUATE(Variant::OP_BIT_XOR, left_value, right_value, ret);
} break; } break;
} }
return Variant(); return ret;
} }
Ref<Shortcut> LimboUtility::add_shortcut(const String &p_path, const String &p_name, Key p_keycode) { Ref<Shortcut> LimboUtility::add_shortcut(const String &p_path, const String &p_name, Key p_keycode) {