mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-04-26 01:04:58 +02:00
Cleaned up GSAIRadiusProximity and GSAIInfiniteProximity aswell.
This commit is contained in:
parent
65aa1c4084
commit
caf3f1210b
@ -16,6 +16,9 @@ sources = [
|
|||||||
"gsai_group_behavior.cpp",
|
"gsai_group_behavior.cpp",
|
||||||
"gsai_agent_location.cpp",
|
"gsai_agent_location.cpp",
|
||||||
"proximities/gsai_proximity.cpp",
|
"proximities/gsai_proximity.cpp",
|
||||||
|
|
||||||
|
"proximities/gsai_radius_proximity.cpp",
|
||||||
|
"proximities/gsai_infinite_proximity.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@ def get_doc_classes():
|
|||||||
"GSAIGroupBehavior",
|
"GSAIGroupBehavior",
|
||||||
"GSAIAgentLocation",
|
"GSAIAgentLocation",
|
||||||
"GSAIProximity",
|
"GSAIProximity",
|
||||||
|
|
||||||
|
"GSAIRadiusProximity",
|
||||||
|
"GSAIInfiniteProximity",
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_doc_path():
|
def get_doc_path():
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
#include "gsai_infinite_proximity.h"
|
#include "gsai_infinite_proximity.h"
|
||||||
|
|
||||||
// Determines any agent that is in the specified list as being neighbors with the;
|
#include "../gsai_steering_agent.h"
|
||||||
// owner agent, regardless of distance.;
|
#include "scene/main/scene_tree.h"
|
||||||
// @category - Proximities;
|
|
||||||
// Returns a number of neighbors based on a `callback` function.;
|
|
||||||
//;
|
|
||||||
// `_find_neighbors` calls `callback` for each agent in the `agents` array and;
|
|
||||||
// adds one to the count if its `callback` returns true.;
|
|
||||||
// @tags - virtual;
|
|
||||||
|
|
||||||
int GSAIInfiniteProximity::_find_neighbors(const FuncRef &callback) {
|
int GSAIInfiniteProximity::_find_neighbors(Ref<FuncRef> callback) {
|
||||||
int neighbor_count = 0;
|
int neighbor_count = 0;
|
||||||
int agent_count = agents.size();
|
int agent_count = agents.size();
|
||||||
|
Variant arg;
|
||||||
|
const Variant *argptr[1];
|
||||||
|
argptr[0] = &arg;
|
||||||
|
Variant::CallError err;
|
||||||
|
|
||||||
for (int i = 0; i < agent_count; ++i) { //i in range(agent_count)
|
for (int i = 0; i < agent_count; ++i) {
|
||||||
GSAISteeringAgent *current_agent = agents[i] as GSAISteeringAgent;
|
Ref<GSAISteeringAgent> current_agent = agents[i];
|
||||||
|
|
||||||
|
ERR_CONTINUE(!current_agent.is_valid());
|
||||||
|
|
||||||
if (current_agent != agent) {
|
if (current_agent != agent) {
|
||||||
if (callback.call_func(current_agent)) {
|
if (callback->call_func(argptr, 1, err)) {
|
||||||
neighbor_count += 1;
|
neighbor_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,7 +26,6 @@ int GSAIInfiniteProximity::_find_neighbors(const FuncRef &callback) {
|
|||||||
|
|
||||||
return neighbor_count;
|
return neighbor_count;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GSAIInfiniteProximity::GSAIInfiniteProximity() {
|
GSAIInfiniteProximity::GSAIInfiniteProximity() {
|
||||||
}
|
}
|
||||||
@ -34,6 +33,5 @@ GSAIInfiniteProximity::GSAIInfiniteProximity() {
|
|||||||
GSAIInfiniteProximity::~GSAIInfiniteProximity() {
|
GSAIInfiniteProximity::~GSAIInfiniteProximity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GSAIInfiniteProximity::_bind_methods() {
|
void GSAIInfiniteProximity::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("_find_neighbors", "callback"), &GSAIInfiniteProximity::_find_neighbors);
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
#ifndef GSAI_INFINITE_PROXIMITY_H
|
#ifndef GSAI_INFINITE_PROXIMITY_H
|
||||||
#define GSAI_INFINITE_PROXIMITY_H
|
#define GSAI_INFINITE_PROXIMITY_H
|
||||||
|
|
||||||
|
#include "core/object/func_ref.h"
|
||||||
|
#include "core/object/reference.h"
|
||||||
|
|
||||||
|
#include "gsai_proximity.h"
|
||||||
|
|
||||||
class GSAIInfiniteProximity : public GSAIProximity {
|
class GSAIInfiniteProximity : public GSAIProximity {
|
||||||
GDCLASS(GSAIInfiniteProximity, GSAIProximity);
|
GDCLASS(GSAIInfiniteProximity, GSAIProximity);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int _find_neighbors(const FuncRef &callback);
|
int _find_neighbors(Ref<FuncRef> callback);
|
||||||
|
|
||||||
GSAIInfiniteProximity();
|
GSAIInfiniteProximity();
|
||||||
~GSAIInfiniteProximity();
|
~GSAIInfiniteProximity();
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
#include "gsai_radius_proximity.h"
|
#include "gsai_radius_proximity.h"
|
||||||
|
|
||||||
|
#include "../gsai_steering_agent.h"
|
||||||
|
#include "scene/main/scene_tree.h"
|
||||||
|
|
||||||
float GSAIRadiusProximity::get_radius() const {
|
float GSAIRadiusProximity::get_radius() const {
|
||||||
return radius;
|
return radius;
|
||||||
}
|
}
|
||||||
@ -9,84 +12,62 @@ void GSAIRadiusProximity::set_radius(const float val) {
|
|||||||
radius = val;
|
radius = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GSAIRadiusProximity::get__last_frame() const {
|
int GSAIRadiusProximity::_find_neighbors(Ref<FuncRef> callback) {
|
||||||
return _last_frame;
|
ERR_FAIL_COND_V(!agent.is_valid(), 0);
|
||||||
}
|
|
||||||
|
|
||||||
void GSAIRadiusProximity::set__last_frame(const int val) {
|
|
||||||
_last_frame = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneTree GSAIRadiusProximity::get_ *_scene_tree() {
|
|
||||||
return *_scene_tree;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GSAIRadiusProximity::set_ *_scene_tree(const SceneTree &val) {
|
|
||||||
*_scene_tree = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines any agent that is in the specified list as being neighbors with the owner agent if;
|
|
||||||
// they lie within the specified radius.;
|
|
||||||
// @category - Proximities;
|
|
||||||
// The radius around the owning agent to find neighbors in;
|
|
||||||
float radius = 0.0;
|
|
||||||
int _last_frame = 0;
|
|
||||||
SceneTree *_scene_tree;
|
|
||||||
|
|
||||||
void GSAIRadiusProximity::_init() {
|
|
||||||
_scene_tree = Engine.get_main_loop();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a number of neighbors based on a `callback` function.;
|
|
||||||
//;
|
|
||||||
// `_find_neighbors` calls `callback` for each agent in the `agents` array that lie within;
|
|
||||||
// the radius around the owning agent and adds one to the count if its `callback` returns true.;
|
|
||||||
// @tags - virtual;
|
|
||||||
|
|
||||||
int GSAIRadiusProximity::_find_neighbors(const FuncRef &callback) {
|
|
||||||
int agent_count = agents.size();
|
int agent_count = agents.size();
|
||||||
int neighbor_count = 0;
|
int neighbor_count = 0;
|
||||||
int current_frame = ;
|
int current_frame;
|
||||||
|
Variant arg;
|
||||||
|
const Variant *argptr[1];
|
||||||
|
argptr[0] = &arg;
|
||||||
|
Variant::CallError err;
|
||||||
|
|
||||||
if (_scene_tree) {
|
SceneTree *scene_tree = SceneTree::get_singleton();
|
||||||
current_frame = _scene_tree.get_frame();
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
if (scene_tree) {
|
||||||
|
current_frame = scene_tree->get_frame();
|
||||||
|
} else {
|
||||||
current_frame = -_last_frame;
|
current_frame = -_last_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_frame != _last_frame) {
|
if (current_frame != _last_frame) {
|
||||||
_last_frame = current_frame;
|
_last_frame = current_frame;
|
||||||
Vector3 owner_position = agent.position;
|
Vector3 owner_position = agent->get_position();
|
||||||
|
|
||||||
for (int i = 0; i < agent_count; ++i) { //i in range(agent_count)
|
for (int i = 0; i < agent_count; ++i) {
|
||||||
GSAISteeringAgent *current_agent = agents[i] as GSAISteeringAgent;
|
Ref<GSAISteeringAgent> current_agent = agents[i];
|
||||||
|
|
||||||
|
ERR_CONTINUE(!current_agent.is_valid());
|
||||||
|
|
||||||
if (current_agent != agent) {
|
if (current_agent != agent) {
|
||||||
float distance_squared = owner_position.distance_squared_to(current_agent.position);
|
float distance_squared = owner_position.distance_squared_to(current_agent->get_position());
|
||||||
float range_to = radius + current_agent.bounding_radius;
|
float range_to = radius + current_agent->get_bounding_radius();
|
||||||
|
|
||||||
|
arg = current_agent.get_ref_ptr();
|
||||||
|
|
||||||
if (distance_squared < range_to * range_to) {
|
if (distance_squared < range_to * range_to) {
|
||||||
if (callback.call_func(current_agent)) {
|
if (callback->call_func(argptr, 1, err)) {
|
||||||
current_agent.is_tagged = true;
|
current_agent->set_is_tagged(true);
|
||||||
neighbor_count += 1;
|
neighbor_count += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current_agent.is_tagged = false;
|
current_agent->set_is_tagged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
|
for (int i = 0; i < agent_count; ++i) {
|
||||||
|
Ref<GSAISteeringAgent> current_agent = agents[i];
|
||||||
|
|
||||||
else {
|
ERR_CONTINUE(!current_agent.is_valid());
|
||||||
for (int i = 0; i < agent_count; ++i) { //i in range(agent_count)
|
|
||||||
GSAISteeringAgent *current_agent = agents[i] as GSAISteeringAgent;
|
|
||||||
|
|
||||||
if (current_agent != agent && current_agent.is_tagged) {
|
if (current_agent != agent && current_agent->get_is_tagged()) {
|
||||||
if (callback.call_func(current_agent)) {
|
arg = current_agent.get_ref_ptr();
|
||||||
|
|
||||||
|
if (callback->call_func(argptr, 1, err)) {
|
||||||
neighbor_count += 1;
|
neighbor_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,30 +76,17 @@ int GSAIRadiusProximity::_find_neighbors(const FuncRef &callback) {
|
|||||||
|
|
||||||
return neighbor_count;
|
return neighbor_count;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GSAIRadiusProximity::GSAIRadiusProximity() {
|
GSAIRadiusProximity::GSAIRadiusProximity() {
|
||||||
radius = 0.0;
|
radius = 0.0;
|
||||||
_last_frame = 0;
|
_last_frame = 0;
|
||||||
*_scene_tree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GSAIRadiusProximity::~GSAIRadiusProximity() {
|
GSAIRadiusProximity::~GSAIRadiusProximity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GSAIRadiusProximity::_bind_methods() {
|
void GSAIRadiusProximity::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_radius"), &GSAIRadiusProximity::get_radius);
|
ClassDB::bind_method(D_METHOD("get_radius"), &GSAIRadiusProximity::get_radius);
|
||||||
ClassDB::bind_method(D_METHOD("set_radius", "value"), &GSAIRadiusProximity::set_radius);
|
ClassDB::bind_method(D_METHOD("set_radius", "value"), &GSAIRadiusProximity::set_radius);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get__last_frame"), &GSAIRadiusProximity::get__last_frame);
|
|
||||||
ClassDB::bind_method(D_METHOD("set__last_frame", "value"), &GSAIRadiusProximity::set__last_frame);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "_last_frame"), "set__last_frame", "get__last_frame");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_*_scene_tree"), &GSAIRadiusProximity::get_ * _scene_tree);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_*_scene_tree", "value"), &GSAIRadiusProximity::set_ * _scene_tree);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "*_scene_tree", PROPERTY_HINT_RESOURCE_TYPE, "SceneTree"), "set_*_scene_tree", "get_*_scene_tree");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_init"), &GSAIRadiusProximity::_init);
|
|
||||||
ClassDB::bind_method(D_METHOD("_find_neighbors", "callback"), &GSAIRadiusProximity::_find_neighbors);
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
#ifndef GSAI_RADIUS_PROXIMITY_H
|
#ifndef GSAI_RADIUS_PROXIMITY_H
|
||||||
#define GSAI_RADIUS_PROXIMITY_H
|
#define GSAI_RADIUS_PROXIMITY_H
|
||||||
|
|
||||||
|
#include "core/object/func_ref.h"
|
||||||
|
#include "core/object/reference.h"
|
||||||
|
|
||||||
|
#include "gsai_proximity.h"
|
||||||
|
|
||||||
|
class SceneTree;
|
||||||
|
|
||||||
class GSAIRadiusProximity : public GSAIProximity {
|
class GSAIRadiusProximity : public GSAIProximity {
|
||||||
GDCLASS(GSAIRadiusProximity, GSAIProximity);
|
GDCLASS(GSAIRadiusProximity, GSAIProximity);
|
||||||
|
|
||||||
@ -8,14 +15,7 @@ public:
|
|||||||
float get_radius() const;
|
float get_radius() const;
|
||||||
void set_radius(const float val);
|
void set_radius(const float val);
|
||||||
|
|
||||||
int get__last_frame() const;
|
int _find_neighbors(Ref<FuncRef> callback);
|
||||||
void set__last_frame(const int val);
|
|
||||||
|
|
||||||
SceneTree get_ *_scene_tree();
|
|
||||||
void set_ *_scene_tree(const SceneTree &val);
|
|
||||||
|
|
||||||
void _init();
|
|
||||||
int _find_neighbors(const FuncRef &callback);
|
|
||||||
|
|
||||||
GSAIRadiusProximity();
|
GSAIRadiusProximity();
|
||||||
~GSAIRadiusProximity();
|
~GSAIRadiusProximity();
|
||||||
@ -27,9 +27,8 @@ protected:
|
|||||||
// they lie within the specified radius.
|
// they lie within the specified radius.
|
||||||
// @category - Proximities
|
// @category - Proximities
|
||||||
// The radius around the owning agent to find neighbors in
|
// The radius around the owning agent to find neighbors in
|
||||||
float radius = 0.0;
|
float radius;
|
||||||
int _last_frame = 0;
|
int _last_frame;
|
||||||
SceneTree *_scene_tree;
|
|
||||||
// Returns a number of neighbors based on a `callback` function.
|
// Returns a number of neighbors based on a `callback` function.
|
||||||
//
|
//
|
||||||
// `_find_neighbors` calls `callback` for each agent in the `agents` array that lie within
|
// `_find_neighbors` calls `callback` for each agent in the `agents` array that lie within
|
||||||
|
@ -35,6 +35,9 @@ SOFTWARE.
|
|||||||
#include "gsai_target_acceleration.h"
|
#include "gsai_target_acceleration.h"
|
||||||
#include "proximities/gsai_proximity.h"
|
#include "proximities/gsai_proximity.h"
|
||||||
|
|
||||||
|
#include "proximities/gsai_radius_proximity.h"
|
||||||
|
#include "proximities/gsai_infinite_proximity.h"
|
||||||
|
|
||||||
static GSAIUtils *gs_ai_utils = NULL;
|
static GSAIUtils *gs_ai_utils = NULL;
|
||||||
|
|
||||||
void register_steering_ai_types() {
|
void register_steering_ai_types() {
|
||||||
@ -49,6 +52,9 @@ void register_steering_ai_types() {
|
|||||||
ClassDB::register_class<GSAIGroupBehavior>();
|
ClassDB::register_class<GSAIGroupBehavior>();
|
||||||
ClassDB::register_class<GSAIAgentLocation>();
|
ClassDB::register_class<GSAIAgentLocation>();
|
||||||
ClassDB::register_class<GSAIProximity>();
|
ClassDB::register_class<GSAIProximity>();
|
||||||
|
|
||||||
|
ClassDB::register_class<GSAIRadiusProximity>();
|
||||||
|
ClassDB::register_class<GSAIInfiniteProximity>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_steering_ai_types() {
|
void unregister_steering_ai_types() {
|
||||||
|
Loading…
Reference in New Issue
Block a user