-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from limbonaut/blackboard-improvements
Rework `Blackboard` API and introduce `BlackboardPlan` resource and editor. - `BBVariable` object holds the value of a blackboard variable and its metadata (not exposed to the API). - `BlackboardPlan` resource stores and manages a collection of variables, and is used to construct new `Blackboard` instances. - Each `BehaviorTree` resource has its own `BlackboardPlan` resource that acts as a blueprint. - `BTPlayer` also has its own `BlackboardPlan` which extends the behavior tree `BlackboardPlan` resource, i.e. variables from BehaviorTree are overridden in the BTPlayer node. - Editor for the `BlackboardPlan` resources - Accessed with "Manage" button in the inspector. - Rename, reposition, and change type and hint of the blackboard variables. - Edit default variable values directly in the inspector. - Define variables in the `BehaviorTree` blackboard plan and override those variables in the `BTPlayer`'s plan. - Fully compatible with both module and GDExtension builds!
- Loading branch information
Showing
51 changed files
with
1,905 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/** | ||
* bb_variable.cpp | ||
* ============================================================================= | ||
* Copyright 2021-2024 Serhii Snitsaruk | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
* ============================================================================= | ||
*/ | ||
|
||
#include "bb_variable.h" | ||
|
||
#include "../util/limbo_compat.h" | ||
|
||
void BBVariable::unref() { | ||
if (data && data->refcount.unref()) { | ||
memdelete(data); | ||
} | ||
data = nullptr; | ||
} | ||
|
||
// void BBVariable::init_ref() { | ||
// if (data) { | ||
// unref(); | ||
// } | ||
// data = memnew(Data); | ||
// data->refcount.init(); | ||
// } | ||
|
||
void BBVariable::set_value(const Variant &p_value) { | ||
data->value = p_value; | ||
} | ||
|
||
Variant BBVariable::get_value() const { | ||
return data->value; | ||
} | ||
|
||
void BBVariable::set_type(Variant::Type p_type) { | ||
data->type = p_type; | ||
data->value = VARIANT_DEFAULT(p_type); | ||
} | ||
|
||
Variant::Type BBVariable::get_type() const { | ||
return data->type; | ||
} | ||
|
||
void BBVariable::set_hint(PropertyHint p_hint) { | ||
data->hint = p_hint; | ||
} | ||
|
||
PropertyHint BBVariable::get_hint() const { | ||
return data->hint; | ||
} | ||
|
||
void BBVariable::set_hint_string(const String &p_hint_string) { | ||
data->hint_string = p_hint_string; | ||
} | ||
|
||
String BBVariable::get_hint_string() const { | ||
return data->hint_string; | ||
} | ||
|
||
BBVariable BBVariable::duplicate() const { | ||
BBVariable var; | ||
var.data->hint = data->hint; | ||
var.data->hint_string = data->hint_string; | ||
var.data->type = data->type; | ||
var.data->value = data->value; | ||
return var; | ||
} | ||
|
||
bool BBVariable::is_same_prop_info(const BBVariable &p_other) const { | ||
if (data->type != p_other.data->type) { | ||
return false; | ||
} | ||
if (data->hint != p_other.data->hint) { | ||
return false; | ||
} | ||
if (data->hint_string != p_other.data->hint_string) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void BBVariable::copy_prop_info(const BBVariable &p_other) { | ||
data->type = p_other.data->type; | ||
data->hint = p_other.data->hint; | ||
data->hint_string = p_other.data->hint_string; | ||
} | ||
|
||
bool BBVariable::operator==(const BBVariable &p_var) const { | ||
if (data == p_var.data) { | ||
return true; | ||
} | ||
|
||
if (!data || !p_var.data) { | ||
return false; | ||
} | ||
|
||
if (data->type != p_var.data->type) { | ||
return false; | ||
} | ||
|
||
if (data->hint != p_var.data->hint) { | ||
return false; | ||
} | ||
|
||
if (data->value != p_var.data->value) { | ||
return false; | ||
} | ||
|
||
if (data->hint_string != p_var.data->hint_string) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool BBVariable::operator!=(const BBVariable &p_var) const { | ||
return !(*this == p_var); | ||
} | ||
|
||
void BBVariable::operator=(const BBVariable &p_var) { | ||
if (this == &p_var) { | ||
return; | ||
} | ||
|
||
unref(); | ||
|
||
if (p_var.data && p_var.data->refcount.ref()) { | ||
data = p_var.data; | ||
} | ||
} | ||
|
||
BBVariable::BBVariable(const BBVariable &p_var) { | ||
if (p_var.data && p_var.data->refcount.ref()) { | ||
data = p_var.data; | ||
} | ||
} | ||
|
||
BBVariable::BBVariable(Variant::Type p_type, PropertyHint p_hint, const String &p_hint_string) { | ||
data = memnew(Data); | ||
data->refcount.init(); | ||
|
||
set_type(p_type); | ||
data->hint = p_hint; | ||
data->hint_string = p_hint_string; | ||
} | ||
|
||
BBVariable::~BBVariable() { | ||
unref(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* bb_variable.h | ||
* ============================================================================= | ||
* Copyright 2021-2024 Serhii Snitsaruk | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
* ============================================================================= | ||
*/ | ||
|
||
#ifndef BB_VARIABLE_H | ||
#define BB_VARIABLE_H | ||
|
||
#ifdef LIMBOAI_MODULE | ||
#include "core/object/object.h" | ||
#include "core/templates/safe_refcount.h" | ||
#include "core/variant/variant.h" | ||
#endif // LIMBOAI_MODULE | ||
|
||
#ifdef LIMBOAI_GDEXTENSION | ||
#include "godot_cpp/core/defs.hpp" | ||
#include "godot_cpp/templates/safe_refcount.hpp" | ||
#include "godot_cpp/variant/variant.hpp" | ||
using namespace godot; | ||
#endif // LIMBOAI_GDEXTENSION | ||
|
||
class BBVariable { | ||
private: | ||
struct Data { | ||
SafeRefCount refcount; | ||
Variant value; | ||
Variant::Type type = Variant::NIL; | ||
PropertyHint hint = PropertyHint::PROPERTY_HINT_NONE; | ||
String hint_string; | ||
// bool bound = false; | ||
// uint64_t bound_object = 0; | ||
// StringName bound_property; | ||
}; | ||
|
||
Data *data = nullptr; | ||
void unref(); | ||
// void init_ref(); | ||
|
||
public: | ||
void set_value(const Variant &p_value); | ||
Variant get_value() const; | ||
|
||
void set_type(Variant::Type p_type); | ||
Variant::Type get_type() const; | ||
|
||
void set_hint(PropertyHint p_hint); | ||
PropertyHint get_hint() const; | ||
|
||
void set_hint_string(const String &p_hint_string); | ||
String get_hint_string() const; | ||
|
||
BBVariable duplicate() const; | ||
|
||
bool is_same_prop_info(const BBVariable &p_other) const; | ||
void copy_prop_info(const BBVariable &p_other); | ||
|
||
// bool is_bound() { return bound; } | ||
|
||
// void bind(Node *p_root, NodePath p_path); | ||
// void unbind(); | ||
|
||
bool operator==(const BBVariable &p_var) const; | ||
bool operator!=(const BBVariable &p_var) const; | ||
void operator=(const BBVariable &p_var); | ||
|
||
BBVariable(const BBVariable &p_var); | ||
BBVariable(Variant::Type p_type = Variant::Type::NIL, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = ""); | ||
~BBVariable(); | ||
}; | ||
|
||
#endif // BB_VARIABLE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.