Merge pull request #55666 from KoBeWi/reduce_ProximityGroup3D_to_atoms
This commit is contained in:
commit
e11baf90d1
5 changed files with 0 additions and 313 deletions
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="ProximityGroup3D" inherits="Node3D" version="4.0">
|
||||
<brief_description>
|
||||
General-purpose proximity detection node.
|
||||
</brief_description>
|
||||
<description>
|
||||
General-purpose proximity detection node.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="broadcast">
|
||||
<return type="void" />
|
||||
<argument index="0" name="method" type="String" />
|
||||
<argument index="1" name="parameters" type="Variant" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="dispatch_mode" type="int" setter="set_dispatch_mode" getter="get_dispatch_mode" enum="ProximityGroup3D.DispatchMode" default="0">
|
||||
</member>
|
||||
<member name="grid_radius" type="Vector3" setter="set_grid_radius" getter="get_grid_radius" default="Vector3(1, 1, 1)">
|
||||
</member>
|
||||
<member name="group_name" type="String" setter="set_group_name" getter="get_group_name" default="""">
|
||||
</member>
|
||||
</members>
|
||||
<signals>
|
||||
<signal name="broadcast">
|
||||
<argument index="0" name="method" type="String" />
|
||||
<argument index="1" name="parameters" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
</signals>
|
||||
<constants>
|
||||
<constant name="MODE_PROXY" value="0" enum="DispatchMode">
|
||||
</constant>
|
||||
<constant name="MODE_SIGNAL" value="1" enum="DispatchMode">
|
||||
</constant>
|
||||
</constants>
|
||||
</class>
|
|
@ -1 +0,0 @@
|
|||
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m1 1v14h14v-14zm2 2h10v10h-10zm7.5 1c-.82843.0000048-1.5.67157-1.5 1.5.0000048.82843.67157 1.5 1.5 1.5.82842-.0000048 1.5-.67157 1.5-1.5-.000005-.82843-.67158-1.5-1.5-1.5zm-5 5c-.82843-.0000048-1.5.67157-1.5 1.5-.0000048.82843.67157 1.5 1.5 1.5.82843.000005 1.5-.67157 1.5-1.5.0000048-.82843-.67157-1.5-1.5-1.5zm5 0c-.82843.0000048-1.5.67157-1.5 1.5.0000048.82842.67157 1.5 1.5 1.5.82842-.000005 1.5-.67158 1.5-1.5-.000005-.82843-.67158-1.5-1.5-1.5z" fill="#fc7f7f" fill-opacity=".99608"/></svg>
|
Before Width: | Height: | Size: 588 B |
|
@ -1,182 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* proximity_group_3d.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "proximity_group_3d.h"
|
||||
|
||||
#include "core/math/math_funcs.h"
|
||||
|
||||
void ProximityGroup3D::_clear_groups() {
|
||||
Map<StringName, uint32_t>::Element *E;
|
||||
const int size = 16;
|
||||
|
||||
do {
|
||||
StringName remove_list[size];
|
||||
E = groups.front();
|
||||
int num = 0;
|
||||
while (E && num < size) {
|
||||
if (E->get() != group_version) {
|
||||
remove_list[num++] = E->key();
|
||||
}
|
||||
|
||||
E = E->next();
|
||||
}
|
||||
for (int i = 0; i < num; i++) {
|
||||
groups.erase(remove_list[i]);
|
||||
}
|
||||
} while (E);
|
||||
}
|
||||
|
||||
void ProximityGroup3D::_update_groups() {
|
||||
if (grid_radius == Vector3(0, 0, 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
++group_version;
|
||||
|
||||
Vector3 pos = get_global_transform().get_origin();
|
||||
Vector3 vcell = pos / cell_size;
|
||||
int cell[3] = { Math::fast_ftoi(vcell.x), Math::fast_ftoi(vcell.y), Math::fast_ftoi(vcell.z) };
|
||||
|
||||
_add_groups(cell, group_name, 0);
|
||||
|
||||
_clear_groups();
|
||||
}
|
||||
|
||||
void ProximityGroup3D::_add_groups(int *p_cell, String p_base, int p_depth) {
|
||||
p_base = p_base + "|";
|
||||
if (grid_radius[p_depth] == 0) {
|
||||
if (p_depth == 2) {
|
||||
_new_group(p_base);
|
||||
} else {
|
||||
_add_groups(p_cell, p_base, p_depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int start = p_cell[p_depth] - grid_radius[p_depth];
|
||||
int end = p_cell[p_depth] + grid_radius[p_depth];
|
||||
|
||||
for (int i = start; i <= end; i++) {
|
||||
String gname = p_base + itos(i);
|
||||
if (p_depth == 2) {
|
||||
_new_group(gname);
|
||||
} else {
|
||||
_add_groups(p_cell, gname, p_depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProximityGroup3D::_new_group(StringName p_name) {
|
||||
const Map<StringName, uint32_t>::Element *E = groups.find(p_name);
|
||||
if (!E) {
|
||||
add_to_group(p_name);
|
||||
}
|
||||
|
||||
groups[p_name] = group_version;
|
||||
}
|
||||
|
||||
void ProximityGroup3D::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
++group_version;
|
||||
_clear_groups();
|
||||
break;
|
||||
case NOTIFICATION_TRANSFORM_CHANGED:
|
||||
_update_groups();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProximityGroup3D::broadcast(String p_method, Variant p_parameters) {
|
||||
Map<StringName, uint32_t>::Element *E;
|
||||
E = groups.front();
|
||||
while (E) {
|
||||
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFAULT, E->key(), "_proximity_group_broadcast", p_method, p_parameters);
|
||||
E = E->next();
|
||||
}
|
||||
}
|
||||
|
||||
void ProximityGroup3D::_proximity_group_broadcast(String p_method, Variant p_parameters) {
|
||||
if (dispatch_mode == MODE_PROXY) {
|
||||
ERR_FAIL_COND(!is_inside_tree());
|
||||
get_parent()->call(p_method, p_parameters);
|
||||
} else {
|
||||
emit_signal(SNAME("broadcast"), p_method, p_parameters);
|
||||
}
|
||||
}
|
||||
|
||||
void ProximityGroup3D::set_group_name(const String &p_group_name) {
|
||||
group_name = p_group_name;
|
||||
}
|
||||
|
||||
String ProximityGroup3D::get_group_name() const {
|
||||
return group_name;
|
||||
}
|
||||
|
||||
void ProximityGroup3D::set_dispatch_mode(DispatchMode p_mode) {
|
||||
dispatch_mode = p_mode;
|
||||
}
|
||||
|
||||
ProximityGroup3D::DispatchMode ProximityGroup3D::get_dispatch_mode() const {
|
||||
return dispatch_mode;
|
||||
}
|
||||
|
||||
void ProximityGroup3D::set_grid_radius(const Vector3 &p_radius) {
|
||||
grid_radius = p_radius;
|
||||
}
|
||||
|
||||
Vector3 ProximityGroup3D::get_grid_radius() const {
|
||||
return grid_radius;
|
||||
}
|
||||
|
||||
void ProximityGroup3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_group_name", "name"), &ProximityGroup3D::set_group_name);
|
||||
ClassDB::bind_method(D_METHOD("get_group_name"), &ProximityGroup3D::get_group_name);
|
||||
ClassDB::bind_method(D_METHOD("set_dispatch_mode", "mode"), &ProximityGroup3D::set_dispatch_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_dispatch_mode"), &ProximityGroup3D::get_dispatch_mode);
|
||||
ClassDB::bind_method(D_METHOD("set_grid_radius", "radius"), &ProximityGroup3D::set_grid_radius);
|
||||
ClassDB::bind_method(D_METHOD("get_grid_radius"), &ProximityGroup3D::get_grid_radius);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("broadcast", "method", "parameters"), &ProximityGroup3D::broadcast);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_proximity_group_broadcast", "method", "parameters"), &ProximityGroup3D::_proximity_group_broadcast);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "group_name"), "set_group_name", "get_group_name");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "dispatch_mode", PROPERTY_HINT_ENUM, "Proxy,Signal"), "set_dispatch_mode", "get_dispatch_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "grid_radius"), "set_grid_radius", "get_grid_radius");
|
||||
|
||||
ADD_SIGNAL(MethodInfo("broadcast", PropertyInfo(Variant::STRING, "method"), PropertyInfo(Variant::ARRAY, "parameters")));
|
||||
|
||||
BIND_ENUM_CONSTANT(MODE_PROXY);
|
||||
BIND_ENUM_CONSTANT(MODE_SIGNAL);
|
||||
}
|
||||
|
||||
ProximityGroup3D::ProximityGroup3D() {
|
||||
set_notify_transform(true);
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* proximity_group_3d.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef PROXIMITY_GROUP_H
|
||||
#define PROXIMITY_GROUP_H
|
||||
|
||||
#include "node_3d.h"
|
||||
|
||||
class ProximityGroup3D : public Node3D {
|
||||
GDCLASS(ProximityGroup3D, Node3D);
|
||||
|
||||
public:
|
||||
enum DispatchMode {
|
||||
MODE_PROXY,
|
||||
MODE_SIGNAL,
|
||||
};
|
||||
|
||||
private:
|
||||
Map<StringName, uint32_t> groups;
|
||||
|
||||
String group_name;
|
||||
DispatchMode dispatch_mode = MODE_PROXY;
|
||||
Vector3 grid_radius = Vector3(1, 1, 1);
|
||||
|
||||
real_t cell_size = 1.0;
|
||||
uint32_t group_version = 0;
|
||||
|
||||
void _clear_groups();
|
||||
void _update_groups();
|
||||
void _add_groups(int *p_cell, String p_base, int p_depth);
|
||||
void _new_group(StringName p_name);
|
||||
|
||||
void _proximity_group_broadcast(String p_method, Variant p_parameters);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_group_name(const String &p_group_name);
|
||||
String get_group_name() const;
|
||||
|
||||
void set_dispatch_mode(DispatchMode p_mode);
|
||||
DispatchMode get_dispatch_mode() const;
|
||||
|
||||
void set_grid_radius(const Vector3 &p_radius);
|
||||
Vector3 get_grid_radius() const;
|
||||
|
||||
void broadcast(String p_method, Variant p_parameters);
|
||||
|
||||
ProximityGroup3D();
|
||||
~ProximityGroup3D() {}
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(ProximityGroup3D::DispatchMode);
|
||||
|
||||
#endif // PROXIMITY_GROUP_H
|
|
@ -232,7 +232,6 @@
|
|||
#include "scene/3d/path_3d.h"
|
||||
#include "scene/3d/physics_body_3d.h"
|
||||
#include "scene/3d/position_3d.h"
|
||||
#include "scene/3d/proximity_group_3d.h"
|
||||
#include "scene/3d/ray_cast_3d.h"
|
||||
#include "scene/3d/reflection_probe.h"
|
||||
#include "scene/3d/remote_transform_3d.h"
|
||||
|
@ -511,7 +510,6 @@ void register_scene_types() {
|
|||
GDREGISTER_CLASS(VehicleBody3D);
|
||||
GDREGISTER_CLASS(VehicleWheel3D);
|
||||
GDREGISTER_CLASS(Area3D);
|
||||
GDREGISTER_CLASS(ProximityGroup3D);
|
||||
GDREGISTER_CLASS(CollisionShape3D);
|
||||
GDREGISTER_CLASS(CollisionPolygon3D);
|
||||
GDREGISTER_CLASS(RayCast3D);
|
||||
|
@ -964,7 +962,6 @@ void register_scene_types() {
|
|||
ClassDB::add_compatibility_class("PinJoint", "PinJoint3D");
|
||||
ClassDB::add_compatibility_class("PlaneShape", "WorldBoundaryShape3D");
|
||||
ClassDB::add_compatibility_class("ProceduralSky", "Sky");
|
||||
ClassDB::add_compatibility_class("ProximityGroup", "ProximityGroup3D");
|
||||
ClassDB::add_compatibility_class("RayCast", "RayCast3D");
|
||||
ClassDB::add_compatibility_class("RayShape", "SeparationRayShape3D");
|
||||
ClassDB::add_compatibility_class("RayShape2D", "SeparationRayShape2D");
|
||||
|
|
Loading…
Reference in a new issue